mongo-schema
Advanced tools
Comparing version 0.1.14 to 0.1.16
{ | ||
"name": "tiny-webrtc", | ||
"version": "0.1.14", | ||
"version": "0.1.16", | ||
"homepage": "https://github.com/paul-em/tiny-webrtc", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -37,7 +37,7 @@ var MongoSchema = function () { | ||
if (isArray(properties)) { | ||
if(isObject(value) && !isArray(value)){ | ||
if(isObject(value) && !isArray(value) && isNaN(parseInt(key))){ | ||
re = self.check(value, properties[0], update); | ||
newData[key] = re.data; | ||
errors = errors.concat(re.errors); | ||
} else if (isArray(value)) { | ||
} else if (isArray(value) || (isObject(value) && isNaN(parseInt(key)))) { | ||
newData[key] = []; | ||
@@ -206,2 +206,5 @@ for (var i in value) { | ||
this.defaults = function (schema) { | ||
if(isArray(schema) && schema.length === 1) { | ||
schema = schema[0]; | ||
} | ||
var defaults = {}; | ||
@@ -208,0 +211,0 @@ for (var key in schema) { |
@@ -1,1 +0,1 @@ | ||
var MongoSchema=function(){function e(e){return!i(e)||d(e)||f(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!d(e)&&!r(e)&&!f(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function d(e){return null===e}function f(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)null===v[b]&&l?g[p][b]=null:(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||d(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),d(v)&&l&&!x.required){g[p]=null;continue}if(f(v)&&l)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!f(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!f(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!f(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}f(v)||(g[p]=v);continue;case"number":if((r(v)||d(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!f(v)&&!f(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!f(v)&&!f(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"boolean":if(x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}if(f(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}f(v)||(g[p]=v);continue}}else f(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||d(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&f(e(s))||f(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||d(e)||f(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!d(e)&&!r(e)&&!f(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function d(e){return null===e}function f(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)null===v[b]&&l||(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||d(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),d(v)&&l&&!x.required){g[p]=null;continue}if(f(v)&&l)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!f(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!f(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!f(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}f(v)||(g[p]=v);continue;case"number":if((r(v)||d(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!f(v)&&!f(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!f(v)&&!f(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"boolean":if(x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}if(f(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}f(v)||(g[p]=v);continue}}else f(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||d(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&f(e(s))||f(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||d(e)||f(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!d(e)&&!r(e)&&!f(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function d(e){return null===e}function f(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s)if(s.hasOwnProperty(p)){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)v.hasOwnProperty(b)&&(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||d(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),d(v)&&l&&!x.required){g[p]=null;continue}if(f(v)&&l&&!x.required)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!f(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!f(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!f(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}f(v)||(g[p]=v);continue;case"number":if((r(v)||d(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!f(v)&&!f(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!f(v)&&!f(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"boolean":if(x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}if(f(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}f(v)||(g[p]=v);continue}}else f(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o)if(o.hasOwnProperty(a)){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||d(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&f(e(s))||f(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||d(e)||f(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!d(e)&&!r(e)&&!f(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function d(e){return null===e}function f(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s)if(s.hasOwnProperty(p)){var v=e[p],x=s[p];if(r(x)){if(g[p]=[],r(v))for(var b in v)v.hasOwnProperty(b)&&(h=c.check(v[b],x[0]),g[p][b]=h.data,m=m.concat(h.errors))}else if(!i(x)||d(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),d(v)&&l&&!x.required){g[p]=void 0;continue}var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!f(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!f(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!f(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}f(v)||(g[p]=v);continue;case"number":if((r(v)||d(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!f(v)&&!f(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!f(v)&&!f(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"boolean":if(x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}if(f(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&f(v)){m.push(p+" - required not set on '"+v+"'");continue}f(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&f(v)){m.push(p+" - required not set '"+v+"'");continue}f(v)||(g[p]=v);continue}}else f(v)||(h=c.check(v,x),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o)if(o.hasOwnProperty(a)){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||d(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&f(e(s))||f(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var has_require="undefined"!=typeof require;if("undefined"==typeof _){if(!has_require)throw new Error("mymodule requires underscore, see http://underscorejs.org");_=require("underscore")._}var MongoSchema=function(){function e(e){return _.isObject(e)&&e.name?(e=e.name.toLowerCase(),-1!==r.indexOf(e)?e:!1):_.isString(e)?(e=e.toLowerCase(),-1!==r.indexOf(e)?e:!1):!1}function n(e){return _.isObject(e)&&!_.isNull(e)&&!_.isArray(e)&&!_.isUndefined(e.type)}var t=this,r=["string","number","boolean","objectid","date"];this.check=function(r,i,o){var u=[];return _.each(i,function(i,d){var f=r[d];if(_.isArray(i)){if(!_.isArray(f))return void delete r[d];_.each(f,function(e){u=u.concat(t.check(e,i[0]))})}else if(!_.isObject(i)||_.isNull(i)||n(i)||e(i)){var a;if(n(i)?a=i.type:(a=i,i={}),_.isNull(f)&&o&&!i.required)return void(r[d]=void 0);var c=e(a);if(!c)throw new Error("type "+a+" not available");switch(c){case"string":if(!_.isString(f)&&!_.isNumber(f)||_.isNaN(f))f=void 0,i.required&&u.push(d+" - required not set on '"+f+"'");else{if(f+="",!_.isUndefined(i.minLength)&&f.length<i.minLength)return u.push(d+" - minLength "+i.minLength+" not fulfilled on '"+f+"'"),void delete r[d];if(!_.isUndefined(i.maxLength)&&f.length>i.maxLength&&(u.push(d+" - maxLength "+i.regex+" not fulfilled on '"+f+"'"),f=f.substr(0,i.maxLength)),!_.isUndefined(i.regex)&&!i.regex.test(f))return u.push(d+" - regex "+i.regex+" not fulfilled '"+f+"'"),void delete r[d]}void 0===f?delete r[d]:r[d]=f;break;case"number":if((_.isArray(f)||_.isNull(f))&&(f=void 0),f=1*f,_.isNaN(f)&&(f=void 0),i.required&&_.isUndefined(f))return u.push(d+" - required not set on '"+f+"'"),void delete r[d];if(!_.isUndefined(f)&&!_.isUndefined(i.min)&&f<i.min)return u.push(d+" - min "+i.min+" not fulfilled '"+f+"'"),void delete r[d];if(!_.isUndefined(f)&&!_.isUndefined(i.max)&&f>i.max)return u.push(d+" - max "+i.max+" not fulfilled on '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f;break;case"boolean":if(i.required&&_.isUndefined(f))return u.push(d+" - required not set '"+f+"'"),void delete r[d];if(_.isUndefined(f))return void delete r[d];r[d]=!!f;break;case"date":if(f instanceof Date&&(f=Math.floor(f.getTime()/1e3)),f=1*f,_.isNaN(f)?f=void 0:(13===f.toString().length&&(f=Math.floor(f/1e3)),10!==f.toString().length&&(f=void 0)),i.required&&_.isUndefined(f))return u.push(d+" - required not set on '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f;break;case"objectid":if(("string"!=typeof f||"string"==typeof f&&24!==f.length)&&(delete r[d],f=void 0),i.required&&_.isUndefined(f))return u.push(d+" - required not set '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f}}else{var s=t.check(f,i);u=u.concat(s)}}),u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports=module.exports=function(e,n,t){return mongoSchema.check(e,n,t)}}var has_require="undefined"!=typeof require;if("undefined"==typeof _){if(!has_require)throw new Error("mymodule requires underscore, see http://underscorejs.org");_=require("underscore")._}var MongoSchema=function(){function e(e){return _.isObject(e)&&e.name?(e=e.name.toLowerCase(),-1!==r.indexOf(e)?e:!1):_.isString(e)?(e=e.toLowerCase(),-1!==r.indexOf(e)?e:!1):!1}function n(e){return _.isObject(e)&&!_.isNull(e)&&!_.isArray(e)&&!_.isUndefined(e.type)}var t=this,r=["string","number","boolean","objectid","date"];this.check=function(r,i,o){var u=[];return _.each(i,function(i,d){var f=r[d];if(_.isArray(i)){if(!_.isArray(f))return void delete r[d];_.each(f,function(e){u=u.concat(t.check(e,i[0]))})}else if(!_.isObject(i)||_.isNull(i)||n(i)||e(i)){var a;if(n(i)?a=i.type:(a=i,i={}),_.isNull(f)&&o&&!i.required)return void(r[d]=void 0);var c=e(a);if(!c)throw new Error("type "+a+" not available");switch(c){case"string":if(!_.isString(f)&&!_.isNumber(f)||_.isNaN(f))f=void 0,i.required&&u.push(d+" - required not set on '"+f+"'");else{if(f+="",!_.isUndefined(i.minLength)&&f.length<i.minLength)return u.push(d+" - minLength "+i.minLength+" not fulfilled on '"+f+"'"),void delete r[d];if(!_.isUndefined(i.maxLength)&&f.length>i.maxLength&&(u.push(d+" - maxLength "+i.regex+" not fulfilled on '"+f+"'"),f=f.substr(0,i.maxLength)),!_.isUndefined(i.regex)&&!i.regex.test(f))return u.push(d+" - regex "+i.regex+" not fulfilled '"+f+"'"),void delete r[d]}void 0===f?delete r[d]:r[d]=f;break;case"number":if((_.isArray(f)||_.isNull(f))&&(f=void 0),f=1*f,_.isNaN(f)&&(f=void 0),i.required&&_.isUndefined(f))return u.push(d+" - required not set on '"+f+"'"),void delete r[d];if(!_.isUndefined(f)&&!_.isUndefined(i.min)&&f<i.min)return u.push(d+" - min "+i.min+" not fulfilled '"+f+"'"),void delete r[d];if(!_.isUndefined(f)&&!_.isUndefined(i.max)&&f>i.max)return u.push(d+" - max "+i.max+" not fulfilled on '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f;break;case"boolean":if(i.required&&_.isUndefined(f))return u.push(d+" - required not set '"+f+"'"),void delete r[d];if(_.isUndefined(f))return void delete r[d];r[d]=!!f;break;case"date":if(f instanceof Date&&(f=Math.floor(f.getTime()/1e3)),f=1*f,_.isNaN(f)?f=void 0:(13===f.toString().length&&(f=Math.floor(f/1e3)),10!==f.toString().length&&(f=void 0)),i.required&&_.isUndefined(f))return u.push(d+" - required not set on '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f;break;case"objectid":if(("string"!=typeof f||"string"==typeof f&&24!==f.length)&&(delete r[d],f=void 0),i.required&&_.isUndefined(f))return u.push(d+" - required not set '"+f+"'"),void delete r[d];void 0===f?delete r[d]:r[d]=f}}else{var s=t.check(f,i);u=u.concat(s)}}),u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports=module.exports=function(e,n,t){return mongoSchema.check(e,n,t)}} | ||
var MongoSchema=function(){function e(e){return!i(e)||f(e)||d(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!f(e)&&!r(e)&&!d(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function f(e){return null===e}function d(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)null===v[b]&&l?g[p][b]=null:(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||f(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),f(v)&&l&&!x.required){g[p]=null;continue}if(d(v)&&l)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!d(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!d(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!d(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}d(v)||(g[p]=v);continue;case"number":if((r(v)||f(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!d(v)&&!d(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!d(v)&&!d(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"boolean":if(x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}if(d(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}d(v)||(g[p]=v);continue}}else d(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){r(o)&&1===o.length&&(o=o[0]);var u={};for(var a in o){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||f(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&d(e(s))||d(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||f(e)||d(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!f(e)&&!r(e)&&!d(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function f(e){return null===e}function d(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)null===v[b]&&l?g[p][b]=null:(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||f(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),f(v)&&l&&!x.required){g[p]=null;continue}if(d(v)&&l)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!d(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!d(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!d(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}d(v)||(g[p]=v);continue;case"number":if((r(v)||f(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!d(v)&&!d(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!d(v)&&!d(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"boolean":if(x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}if(d(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}d(v)||(g[p]=v);continue}}else d(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||f(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&d(e(s))||d(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||f(e)||d(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!f(e)&&!r(e)&&!d(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function f(e){return null===e}function d(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)null===v[b]&&l||(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||f(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),f(v)&&l&&!x.required){g[p]=null;continue}if(d(v)&&l)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!d(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!d(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!d(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}d(v)||(g[p]=v);continue;case"number":if((r(v)||f(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!d(v)&&!d(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!d(v)&&!d(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"boolean":if(x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}if(d(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}d(v)||(g[p]=v);continue}}else d(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||f(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&d(e(s))||d(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||f(e)||d(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!f(e)&&!r(e)&&!d(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function f(e){return null===e}function d(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s)if(s.hasOwnProperty(p)){var v=e[p],x=s[p];if(r(x))if(i(v)&&!r(v))h=c.check(v,x[0],l),g[p]=h.data,m=m.concat(h.errors);else if(r(v)){g[p]=[];for(var b in v)v.hasOwnProperty(b)&&(h=c.check(v[b],x[0],l),g[p][b]=h.data,m=m.concat(h.errors))}else l||(g[p]=[]);else if(!i(x)||f(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),f(v)&&l&&!x.required){g[p]=null;continue}if(d(v)&&l&&!x.required)continue;var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!d(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!d(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!d(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}d(v)||(g[p]=v);continue;case"number":if((r(v)||f(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!d(v)&&!d(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!d(v)&&!d(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"boolean":if(x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}if(d(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}d(v)||(g[p]=v);continue}}else d(v)||(h=c.check(v,x,l),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o)if(o.hasOwnProperty(a)){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||f(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&d(e(s))||d(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var MongoSchema=function(){function e(e){return!i(e)||f(e)||d(e.default)?void 0:e.default}function n(e){return i(e)&&e.name?(e=e.name.toLowerCase(),-1!==s.indexOf(e)?e:!1):a(e)?(e=e.toLowerCase(),-1!==s.indexOf(e)?e:!1):!1}function t(e){return i(e)&&!f(e)&&!r(e)&&!d(e.type)}function r(e){return"[object Array]"===Object.prototype.toString.call(e)}function i(e){return e===Object(e)}function o(e){return"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e)}function u(e){return o(e)&&e!=+e}function f(e){return null===e}function d(e){return void 0===e}function a(e){return"string"==typeof e||"[object String]"==Object.prototype.toString.call(e)}var c=this,s=["string","number","boolean","objectid","date"],l={string:function(){return""},number:function(){return 0},"boolean":function(){return!0},objectid:function(){return""},date:function(){return Math.floor(+new Date/1e3)}};this.check=function(e,s,l){var h,g={},m=[];for(var p in s)if(s.hasOwnProperty(p)){var v=e[p],x=s[p];if(r(x)){if(g[p]=[],r(v))for(var b in v)v.hasOwnProperty(b)&&(h=c.check(v[b],x[0]),g[p][b]=h.data,m=m.concat(h.errors))}else if(!i(x)||f(x)||t(x)||n(x)){var q;if(t(x)?q=x.type:(q=x,x={}),f(v)&&l&&!x.required){g[p]=void 0;continue}var y=n(q);if(!y)throw new Error("type "+q+" not available");switch(y){case"string":if(!a(v)&&!o(v)||u(v))v=void 0,x.required&&m.push(p+" - required not set on '"+v+"'");else{if(v+="",!d(x.minLength)&&v.length<x.minLength){x.required&&m.push(p+" - minLength "+x.minLength+" not fulfilled on '"+v+"'");continue}if(!d(x.maxLength)&&v.length>x.maxLength&&(x.required&&m.push(p+" - maxLength "+x.regex+" not fulfilled on '"+v+"'"),v=v.substr(0,x.maxLength)),!d(x.regex)&&!x.regex.test(v)){x.required&&m.push(p+" - regex "+x.regex+" not fulfilled '"+v+"'");continue}}d(v)||(g[p]=v);continue;case"number":if((r(v)||f(v))&&(v=void 0),v=1*v,u(v)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}if(!d(v)&&!d(x.min)&&v<x.min){x.required&&m.push(p+" - min "+x.min+" not fulfilled '"+v+"'");continue}if(!d(v)&&!d(x.max)&&v>x.max){x.required&&m.push(p+" - max "+x.max+" not fulfilled on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"boolean":if(x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}if(d(v))continue;g[p]=!!v;continue;case"date":if(v instanceof Date&&(v=Math.floor(v.getTime()/1e3)),v=1*v,u(v)?v=void 0:(13===v.toString().length&&(v=Math.floor(v/1e3)),10!==v.toString().length&&(v=void 0)),x.required&&d(v)){m.push(p+" - required not set on '"+v+"'");continue}d(v)||(g[p]=v);continue;case"objectid":if(("string"!=typeof v||"string"==typeof v&&24!==v.length)&&(v=void 0),x.required&&d(v)){m.push(p+" - required not set '"+v+"'");continue}d(v)||(g[p]=v);continue}}else d(v)||(h=c.check(v,x),g[p]=h.data,m=m.concat(h.errors))}return{errors:m,data:g}},this.defaults=function(o){var u={};for(var a in o)if(o.hasOwnProperty(a)){var s=o[a];if(r(s))u[a]=[];else if(!i(s)||f(s)||t(s)||n(s)){if(s){var h;t(s)?h=s.type:(h=s,s={}),h=n(h),u[a]=!s.required&&d(e(s))||d(l[h])?void 0:e(s)||l[h]()}}else u[a]=c.defaults(s)}return u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports.check=mongoSchema.check,exports.defaults=mongoSchema.defaults}var has_require="undefined"!=typeof require;if("undefined"==typeof _){if(!has_require)throw new Error("mymodule requires underscore, see http://underscorejs.org");_=require("underscore")._}var MongoSchema=function(){function e(e){return _.isObject(e)&&e.name?(e=e.name.toLowerCase(),-1!==r.indexOf(e)?e:!1):_.isString(e)?(e=e.toLowerCase(),-1!==r.indexOf(e)?e:!1):!1}function n(e){return _.isObject(e)&&!_.isNull(e)&&!_.isArray(e)&&!_.isUndefined(e.type)}var t=this,r=["string","number","boolean","objectid","date"];this.check=function(r,i,o){var u=[];return _.each(i,function(i,f){var d=r[f];if(_.isArray(i)){if(!_.isArray(d))return void delete r[f];_.each(d,function(e){u=u.concat(t.check(e,i[0]))})}else if(!_.isObject(i)||_.isNull(i)||n(i)||e(i)){var a;if(n(i)?a=i.type:(a=i,i={}),_.isNull(d)&&o&&!i.required)return void(r[f]=void 0);var c=e(a);if(!c)throw new Error("type "+a+" not available");switch(c){case"string":if(!_.isString(d)&&!_.isNumber(d)||_.isNaN(d))d=void 0,i.required&&u.push(f+" - required not set on '"+d+"'");else{if(d+="",!_.isUndefined(i.minLength)&&d.length<i.minLength)return u.push(f+" - minLength "+i.minLength+" not fulfilled on '"+d+"'"),void delete r[f];if(!_.isUndefined(i.maxLength)&&d.length>i.maxLength&&(u.push(f+" - maxLength "+i.regex+" not fulfilled on '"+d+"'"),d=d.substr(0,i.maxLength)),!_.isUndefined(i.regex)&&!i.regex.test(d))return u.push(f+" - regex "+i.regex+" not fulfilled '"+d+"'"),void delete r[f]}void 0===d?delete r[f]:r[f]=d;break;case"number":if((_.isArray(d)||_.isNull(d))&&(d=void 0),d=1*d,_.isNaN(d)&&(d=void 0),i.required&&_.isUndefined(d))return u.push(f+" - required not set on '"+d+"'"),void delete r[f];if(!_.isUndefined(d)&&!_.isUndefined(i.min)&&d<i.min)return u.push(f+" - min "+i.min+" not fulfilled '"+d+"'"),void delete r[f];if(!_.isUndefined(d)&&!_.isUndefined(i.max)&&d>i.max)return u.push(f+" - max "+i.max+" not fulfilled on '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d;break;case"boolean":if(i.required&&_.isUndefined(d))return u.push(f+" - required not set '"+d+"'"),void delete r[f];if(_.isUndefined(d))return void delete r[f];r[f]=!!d;break;case"date":if(d instanceof Date&&(d=Math.floor(d.getTime()/1e3)),d=1*d,_.isNaN(d)?d=void 0:(13===d.toString().length&&(d=Math.floor(d/1e3)),10!==d.toString().length&&(d=void 0)),i.required&&_.isUndefined(d))return u.push(f+" - required not set on '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d;break;case"objectid":if(("string"!=typeof d||"string"==typeof d&&24!==d.length)&&(delete r[f],d=void 0),i.required&&_.isUndefined(d))return u.push(f+" - required not set '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d}}else{var s=t.check(d,i);u=u.concat(s)}}),u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports=module.exports=function(e,n,t){return mongoSchema.check(e,n,t)}}var has_require="undefined"!=typeof require;if("undefined"==typeof _){if(!has_require)throw new Error("mymodule requires underscore, see http://underscorejs.org");_=require("underscore")._}var MongoSchema=function(){function e(e){return _.isObject(e)&&e.name?(e=e.name.toLowerCase(),-1!==r.indexOf(e)?e:!1):_.isString(e)?(e=e.toLowerCase(),-1!==r.indexOf(e)?e:!1):!1}function n(e){return _.isObject(e)&&!_.isNull(e)&&!_.isArray(e)&&!_.isUndefined(e.type)}var t=this,r=["string","number","boolean","objectid","date"];this.check=function(r,i,o){var u=[];return _.each(i,function(i,f){var d=r[f];if(_.isArray(i)){if(!_.isArray(d))return void delete r[f];_.each(d,function(e){u=u.concat(t.check(e,i[0]))})}else if(!_.isObject(i)||_.isNull(i)||n(i)||e(i)){var a;if(n(i)?a=i.type:(a=i,i={}),_.isNull(d)&&o&&!i.required)return void(r[f]=void 0);var c=e(a);if(!c)throw new Error("type "+a+" not available");switch(c){case"string":if(!_.isString(d)&&!_.isNumber(d)||_.isNaN(d))d=void 0,i.required&&u.push(f+" - required not set on '"+d+"'");else{if(d+="",!_.isUndefined(i.minLength)&&d.length<i.minLength)return u.push(f+" - minLength "+i.minLength+" not fulfilled on '"+d+"'"),void delete r[f];if(!_.isUndefined(i.maxLength)&&d.length>i.maxLength&&(u.push(f+" - maxLength "+i.regex+" not fulfilled on '"+d+"'"),d=d.substr(0,i.maxLength)),!_.isUndefined(i.regex)&&!i.regex.test(d))return u.push(f+" - regex "+i.regex+" not fulfilled '"+d+"'"),void delete r[f]}void 0===d?delete r[f]:r[f]=d;break;case"number":if((_.isArray(d)||_.isNull(d))&&(d=void 0),d=1*d,_.isNaN(d)&&(d=void 0),i.required&&_.isUndefined(d))return u.push(f+" - required not set on '"+d+"'"),void delete r[f];if(!_.isUndefined(d)&&!_.isUndefined(i.min)&&d<i.min)return u.push(f+" - min "+i.min+" not fulfilled '"+d+"'"),void delete r[f];if(!_.isUndefined(d)&&!_.isUndefined(i.max)&&d>i.max)return u.push(f+" - max "+i.max+" not fulfilled on '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d;break;case"boolean":if(i.required&&_.isUndefined(d))return u.push(f+" - required not set '"+d+"'"),void delete r[f];if(_.isUndefined(d))return void delete r[f];r[f]=!!d;break;case"date":if(d instanceof Date&&(d=Math.floor(d.getTime()/1e3)),d=1*d,_.isNaN(d)?d=void 0:(13===d.toString().length&&(d=Math.floor(d/1e3)),10!==d.toString().length&&(d=void 0)),i.required&&_.isUndefined(d))return u.push(f+" - required not set on '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d;break;case"objectid":if(("string"!=typeof d||"string"==typeof d&&24!==d.length)&&(delete r[f],d=void 0),i.required&&_.isUndefined(d))return u.push(f+" - required not set '"+d+"'"),void delete r[f];void 0===d?delete r[f]:r[f]=d}}else{var s=t.check(d,i);u=u.concat(s)}}),u}};if("undefined"!=typeof exports&&"undefined"!=typeof module&&module.exports){var mongoSchema=new MongoSchema;exports=module.exports=function(e,n,t){return mongoSchema.check(e,n,t)}} |
{ | ||
"name": "mongo-schema", | ||
"version": "0.1.14", | ||
"version": "0.1.16", | ||
"main": "lib/mongo-schema.js", | ||
@@ -5,0 +5,0 @@ "description": "Basic schema for mongodb", |
70842
1073