2016-04-06 14:51:49 +00:00
|
|
|
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
|
|
|
|
// Node module: loopback-datasource-juggler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
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
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
Types.Text.prototype.toObject = Types.Text.prototype.toJSON = function() {
|
2014-02-14 07:42:21 +00:00
|
|
|
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
|
2016-04-14 14:41:19 +00:00
|
|
|
Types.JSON.prototype.toObject = Types.JSON.prototype.toJSON = function() {
|
2014-02-14 07:42:21 +00:00
|
|
|
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
|
2016-04-14 14:41:19 +00:00
|
|
|
Types.Any.prototype.toObject = Types.Any.prototype.toJSON = function() {
|
2014-02-14 07:42:21 +00:00
|
|
|
return this.value;
|
|
|
|
};
|
2014-01-24 17:09:53 +00:00
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
module.exports = function(modelTypes) {
|
2014-02-14 07:42:21 +00:00
|
|
|
var GeoPoint = require('./geo').GeoPoint;
|
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
for (var t in Types) {
|
2014-02-14 07:42:21 +00:00
|
|
|
modelTypes[t] = Types[t];
|
|
|
|
}
|
2014-01-24 17:09:53 +00:00
|
|
|
|
2014-02-14 07:42:21 +00:00
|
|
|
modelTypes.schemaTypes = {};
|
2016-04-14 14:41:19 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2016-04-14 14:41:19 +00:00
|
|
|
module.exports.Types = Types;
|