model-types
Advanced tools
Comparing version 1.9.0 to 1.10.0
@@ -164,12 +164,12 @@ 'use strict'; | ||
var StringType = function (_DataType) { | ||
inherits(StringType, _DataType); | ||
var ObjectId = function (_DataType) { | ||
inherits(ObjectId, _DataType); | ||
function StringType() { | ||
function ObjectId() { | ||
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
classCallCheck(this, StringType); | ||
classCallCheck(this, ObjectId); | ||
var _this = possibleConstructorReturn(this, (StringType.__proto__ || Object.getPrototypeOf(StringType)).call(this, args)); | ||
var _this = possibleConstructorReturn(this, (ObjectId.__proto__ || Object.getPrototypeOf(ObjectId)).call(this, args)); | ||
_this._name = 'String'; | ||
_this._name = 'ObjectId'; | ||
_this._default = _this._null ? null : ''; | ||
@@ -180,3 +180,3 @@ _this._value = _this._default; | ||
if (args.default !== undefined) { | ||
if (typeof args.default === 'string' || args.default === null) { | ||
if (_this.validate(args.default)) { | ||
_this._default = args.default; | ||
@@ -192,2 +192,51 @@ } else { | ||
createClass(ObjectId, [{ | ||
key: 'parse', | ||
value: function parse(unparsed) { | ||
unparsed = get(ObjectId.prototype.__proto__ || Object.getPrototypeOf(ObjectId.prototype), 'parse', this).call(this, unparsed); | ||
if (unparsed === undefined) { | ||
return this._default; | ||
} else { | ||
if (typeof unparsed === 'number') { | ||
return unparsed; | ||
} else { | ||
return String(unparsed); | ||
} | ||
} | ||
} | ||
}, { | ||
key: 'validate', | ||
value: function validate(value) { | ||
return get(ObjectId.prototype.__proto__ || Object.getPrototypeOf(ObjectId.prototype), 'validate', this).call(this, value) ? value === null || typeof value === 'string' || typeof value === 'number' ? true : false : false; | ||
} | ||
}]); | ||
return ObjectId; | ||
}(DataType); | ||
var StringType = function (_DataType2) { | ||
inherits(StringType, _DataType2); | ||
function StringType() { | ||
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
classCallCheck(this, StringType); | ||
var _this2 = possibleConstructorReturn(this, (StringType.__proto__ || Object.getPrototypeOf(StringType)).call(this, args)); | ||
_this2._name = 'String'; | ||
_this2._default = _this2._null ? null : ''; | ||
_this2._value = _this2._default; | ||
if (args.default !== undefined) { | ||
if (_this2.validate(args.default)) { | ||
_this2._default = args.default; | ||
} else { | ||
throw new Error('Invalid default value for StringType. Expected string, but got ' + _typeof(args.default)); | ||
} | ||
} | ||
_this2._value = _this2._default; | ||
return _this2; | ||
} | ||
createClass(StringType, [{ | ||
@@ -212,4 +261,4 @@ key: 'parse', | ||
var NumberType = function (_DataType2) { | ||
inherits(NumberType, _DataType2); | ||
var NumberType = function (_DataType3) { | ||
inherits(NumberType, _DataType3); | ||
@@ -220,7 +269,7 @@ function NumberType() { | ||
var _this2 = possibleConstructorReturn(this, (NumberType.__proto__ || Object.getPrototypeOf(NumberType)).call(this, args)); | ||
var _this3 = possibleConstructorReturn(this, (NumberType.__proto__ || Object.getPrototypeOf(NumberType)).call(this, args)); | ||
_this2._name = 'Number'; | ||
_this2._default = _this2._null ? null : 0; | ||
_this2._value = _this2._default; | ||
_this3._name = 'Number'; | ||
_this3._default = _this3._null ? null : 0; | ||
_this3._value = _this3._default; | ||
@@ -230,3 +279,3 @@ | ||
if (typeof args.default === 'number' || args.default === null) { | ||
_this2._default = args.default; | ||
_this3._default = args.default; | ||
} else { | ||
@@ -237,4 +286,4 @@ throw new Error('Invalid default value for NumberType. Expected number (or null, if notnull), but got ' + _typeof(args.default)); | ||
_this2._value = _this2._default; | ||
return _this2; | ||
_this3._value = _this3._default; | ||
return _this3; | ||
} | ||
@@ -263,4 +312,4 @@ | ||
var BooleanType = function (_DataType3) { | ||
inherits(BooleanType, _DataType3); | ||
var BooleanType = function (_DataType4) { | ||
inherits(BooleanType, _DataType4); | ||
@@ -271,7 +320,7 @@ function BooleanType() { | ||
var _this3 = possibleConstructorReturn(this, (BooleanType.__proto__ || Object.getPrototypeOf(BooleanType)).call(this, args)); | ||
var _this4 = possibleConstructorReturn(this, (BooleanType.__proto__ || Object.getPrototypeOf(BooleanType)).call(this, args)); | ||
_this3._name = 'Boolean'; | ||
_this3._default = _this3._null ? null : false; | ||
_this3._value = _this3._default; | ||
_this4._name = 'Boolean'; | ||
_this4._default = _this4._null ? null : false; | ||
_this4._value = _this4._default; | ||
@@ -281,3 +330,3 @@ | ||
if (args.default === null || args.default === false || args.default === true) { | ||
_this3._default = args.default; | ||
_this4._default = args.default; | ||
} else { | ||
@@ -288,4 +337,4 @@ throw new Error('Invalid default value for BooleanType. Expected boolean (or null, if notnull), but got ' + _typeof(args.default)); | ||
_this3._value = _this3._default; | ||
return _this3; | ||
_this4._value = _this4._default; | ||
return _this4; | ||
} | ||
@@ -312,4 +361,4 @@ | ||
var ArrayType = function (_DataType4) { | ||
inherits(ArrayType, _DataType4); | ||
var ArrayType = function (_DataType5) { | ||
inherits(ArrayType, _DataType5); | ||
@@ -320,6 +369,6 @@ function ArrayType() { | ||
var _this4 = possibleConstructorReturn(this, (ArrayType.__proto__ || Object.getPrototypeOf(ArrayType)).call(this, args)); | ||
var _this5 = possibleConstructorReturn(this, (ArrayType.__proto__ || Object.getPrototypeOf(ArrayType)).call(this, args)); | ||
_this4._name = 'Array'; | ||
_this4._arraytype = null; | ||
_this5._name = 'Array'; | ||
_this5._arraytype = null; | ||
@@ -330,5 +379,5 @@ | ||
var type = args.arraytype.toLowerCase(); | ||
if (type === 'string') _this4._arraytype = new StringType();else if (type === 'number') _this4._arraytype = new NumberType();else if (type === 'boolean' || type === 'bool') _this4._arraytype = new BooleanType();else if (type === 'date') _this4._arraytype = new DateType();else if (type === 'mixed' || type === 'any') _this4._arraytype = new MixedType();else throw new Error('Invalid string used as arraytype'); | ||
if (type === 'string') _this5._arraytype = new StringType();else if (type === 'number') _this5._arraytype = new NumberType();else if (type === 'boolean' || type === 'bool') _this5._arraytype = new BooleanType();else if (type === 'date') _this5._arraytype = new DateType();else if (type === 'mixed' || type === 'any') _this5._arraytype = new MixedType();else throw new Error('Invalid string used as arraytype'); | ||
} else if (typeof args.arraytype === 'function') { | ||
if (args.arraytype.name === 'String') _this4._arraytype = new StringType();else if (args.arraytype.name === 'Number') _this4._arraytype = new NumberType();else if (args.arraytype.name === 'Date') _this4._arraytype = new DateType();else if (args.arraytype.name === 'Boolean') _this4._arraytype = new BooleanType();else throw new Error('Invalid function used as arraytype'); | ||
if (args.arraytype.name === 'String') _this5._arraytype = new StringType();else if (args.arraytype.name === 'Number') _this5._arraytype = new NumberType();else if (args.arraytype.name === 'Date') _this5._arraytype = new DateType();else if (args.arraytype.name === 'Boolean') _this5._arraytype = new BooleanType();else throw new Error('Invalid function used as arraytype'); | ||
} else { | ||
@@ -338,3 +387,3 @@ throw new Error('Invalid arraytype passed to ArrayType arguments. Expected function (String, Number, Date or Boolean), string or DataType, but got ' + args.arraytype); | ||
} else { | ||
_this4._arraytype = new MixedType(); | ||
_this5._arraytype = new MixedType(); | ||
} | ||
@@ -344,3 +393,3 @@ | ||
if (args.default instanceof Array || args.default === null) { | ||
_this4._default = _this4.parse(args.default); | ||
_this5._default = _this5.parse(args.default); | ||
} else { | ||
@@ -351,4 +400,4 @@ throw new Error('Invalid default value for ArrayType. Expected array (or null, if notnull), but got ' + _typeof(args.default)); | ||
_this4._value = _this4._default; | ||
return _this4; | ||
_this5._value = _this5._default; | ||
return _this5; | ||
} | ||
@@ -376,4 +425,4 @@ | ||
var DateType = function (_DataType5) { | ||
inherits(DateType, _DataType5); | ||
var DateType = function (_DataType6) { | ||
inherits(DateType, _DataType6); | ||
@@ -384,14 +433,14 @@ function DateType() { | ||
var _this5 = possibleConstructorReturn(this, (DateType.__proto__ || Object.getPrototypeOf(DateType)).call(this, args)); | ||
var _this6 = possibleConstructorReturn(this, (DateType.__proto__ || Object.getPrototypeOf(DateType)).call(this, args)); | ||
_this5._name = 'Date'; | ||
_this5._default = _this5._null ? null : new Date(); | ||
_this6._name = 'Date'; | ||
_this6._default = _this6._null ? null : new Date(); | ||
if (args.default !== undefined) { | ||
_this5._default = _this5.parse(args.default); | ||
_this6._default = _this6.parse(args.default); | ||
} | ||
_this5._value = _this5._default; | ||
return _this5; | ||
_this6._value = _this6._default; | ||
return _this6; | ||
} | ||
@@ -426,4 +475,4 @@ | ||
var MixedType = function (_DataType6) { | ||
inherits(MixedType, _DataType6); | ||
var MixedType = function (_DataType7) { | ||
inherits(MixedType, _DataType7); | ||
@@ -434,14 +483,14 @@ function MixedType() { | ||
var _this6 = possibleConstructorReturn(this, (MixedType.__proto__ || Object.getPrototypeOf(MixedType)).call(this, args)); | ||
var _this7 = possibleConstructorReturn(this, (MixedType.__proto__ || Object.getPrototypeOf(MixedType)).call(this, args)); | ||
_this6._name = 'Mixed'; | ||
_this6._default = _this6._null ? null : {}; | ||
_this7._name = 'Mixed'; | ||
_this7._default = _this7._null ? null : {}; | ||
if (args.default !== undefined) { | ||
_this6._default = _this6.parse(args.default); | ||
_this7._default = _this7.parse(args.default); | ||
} | ||
_this6._value = _this6._default; | ||
return _this6; | ||
_this7._value = _this7._default; | ||
return _this7; | ||
} | ||
@@ -464,4 +513,4 @@ | ||
var EnumType = function (_DataType7) { | ||
inherits(EnumType, _DataType7); | ||
var EnumType = function (_DataType8) { | ||
inherits(EnumType, _DataType8); | ||
@@ -472,6 +521,6 @@ function EnumType() { | ||
var _this7 = possibleConstructorReturn(this, (EnumType.__proto__ || Object.getPrototypeOf(EnumType)).call(this, args)); | ||
var _this8 = possibleConstructorReturn(this, (EnumType.__proto__ || Object.getPrototypeOf(EnumType)).call(this, args)); | ||
_this7._name = 'enum'; | ||
_this7._enums = []; | ||
_this8._name = 'enum'; | ||
_this8._enums = []; | ||
@@ -490,10 +539,10 @@ | ||
}); | ||
_this7._enums = enums; | ||
_this8._enums = enums; | ||
if (args.default !== undefined) { | ||
_this7._default = _this7.parse(args.default); | ||
_this8._default = _this8.parse(args.default); | ||
} | ||
_this7._value = _this7._default; | ||
return _this7; | ||
_this8._value = _this8._default; | ||
return _this8; | ||
} | ||
@@ -527,2 +576,3 @@ | ||
var Types = { | ||
ObjectId: ObjectId, | ||
String: StringType, | ||
@@ -529,0 +579,0 @@ Number: NumberType, |
{ | ||
"name": "model-types", | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"description": "Javascript library for typed object modeling.", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29642
671