2013-07-25 14:48:31 +00:00
|
|
|
module.exports = function (Types) {
|
|
|
|
|
|
|
|
var List = require('./list.js');
|
|
|
|
var GeoPoint = require('./geo').GeoPoint;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schema types
|
|
|
|
*/
|
|
|
|
Types.Text = function Text(value) {
|
|
|
|
if (!(this instanceof Text)) {
|
|
|
|
return new Text(value);
|
|
|
|
}
|
|
|
|
this.value = value;
|
|
|
|
}; // Text type
|
|
|
|
|
|
|
|
Types.Text.prototype.toObject = Types.Text.prototype.toJSON = function () {
|
|
|
|
return this.value;
|
|
|
|
};
|
|
|
|
|
2013-07-26 05:39:16 +00:00
|
|
|
Types.JSON = function JSON(value) {
|
2013-07-25 14:48:31 +00:00
|
|
|
if (!(this instanceof JSON)) {
|
|
|
|
return new JSON(value);
|
|
|
|
}
|
|
|
|
this.value = value;
|
|
|
|
}; // JSON Object
|
|
|
|
Types.JSON.prototype.toObject = Types.JSON.prototype.toJSON = function () {
|
|
|
|
return this.value;
|
|
|
|
};
|
|
|
|
|
2013-07-26 05:39:16 +00:00
|
|
|
Types.Any = function Any(value) {
|
2013-07-25 14:48:31 +00:00
|
|
|
if (!(this instanceof Any)) {
|
|
|
|
return new Any(value);
|
|
|
|
}
|
|
|
|
this.value = value;
|
|
|
|
}; // Any Type
|
|
|
|
Types.Any.prototype.toObject = Types.Any.prototype.toJSON = function () {
|
|
|
|
return this.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
Types.schemaTypes = {};
|
|
|
|
Types.registerType = function (type, names) {
|
|
|
|
names = names || [];
|
|
|
|
names = names.concat([type.name]);
|
|
|
|
for (var n = 0; n < names.length; n++) {
|
|
|
|
this.schemaTypes[names[n].toLowerCase()] = type;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Types.registerType(Types.Text);
|
|
|
|
Types.registerType(Types.JSON);
|
|
|
|
Types.registerType(Types.Any);
|
|
|
|
|
|
|
|
Types.registerType(String);
|
|
|
|
Types.registerType(Number);
|
|
|
|
Types.registerType(Boolean);
|
|
|
|
Types.registerType(Date);
|
|
|
|
Types.registerType(Buffer, ['Binary']);
|
|
|
|
Types.registerType(Array);
|
|
|
|
Types.registerType(GeoPoint);
|
|
|
|
Types.registerType(Object);
|
|
|
|
}
|