loopback-datasource-juggler/lib/types.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-02-14 07:42:21 +00:00
var Types = {};
/**
* Schema types
*/
Types.Text = function Text(value) {
if (!(this instanceof Text)) {
return value;
}
this.value = value;
}; // Text type
2013-07-25 14:48:31 +00:00
2014-02-14 07:42:21 +00:00
Types.Text.prototype.toObject = Types.Text.prototype.toJSON = function () {
return this.value;
};
2014-01-24 17:09:53 +00:00
2014-02-14 07:42:21 +00:00
Types.JSON = function JSON(value) {
if (!(this instanceof JSON)) {
return value;
}
this.value = value;
}; // JSON Object
Types.JSON.prototype.toObject = Types.JSON.prototype.toJSON = function () {
return this.value;
};
2014-01-24 17:09:53 +00:00
2014-02-14 07:42:21 +00:00
Types.Any = function Any(value) {
if (!(this instanceof Any)) {
return value;
}
this.value = value;
}; // Any Type
Types.Any.prototype.toObject = Types.Any.prototype.toJSON = function () {
return this.value;
};
2014-01-24 17:09:53 +00:00
2014-02-14 07:42:21 +00:00
module.exports = function (modelTypes) {
2014-01-24 17:09:53 +00:00
2014-02-14 07:42:21 +00:00
var GeoPoint = require('./geo').GeoPoint;
for(var t in Types) {
modelTypes[t] = Types[t];
}
2014-01-24 17:09:53 +00:00
2014-02-14 07:42:21 +00:00
modelTypes.schemaTypes = {};
modelTypes.registerType = function (type, names) {
2014-01-24 17:09:53 +00:00
names = names || [];
names = names.concat([type.name]);
for (var n = 0; n < names.length; n++) {
this.schemaTypes[names[n].toLowerCase()] = type;
}
};
2014-02-14 07:42:21 +00:00
modelTypes.registerType(Types.Text);
modelTypes.registerType(Types.JSON);
modelTypes.registerType(Types.Any);
modelTypes.registerType(String);
modelTypes.registerType(Number);
modelTypes.registerType(Boolean);
modelTypes.registerType(Date);
modelTypes.registerType(Buffer, ['Binary']);
modelTypes.registerType(Array);
modelTypes.registerType(GeoPoint);
modelTypes.registerType(Object);
};
module.exports.Types = Types;