Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.10
@@ -0,1 +1,6 @@ | ||
# 1.0.0-alpha.10 | ||
* [FIX] reject invalid dates in date validator | ||
* [FIX] deserialize ISO strings into Date objects | ||
# 1.0.0-alpha.9 | ||
@@ -2,0 +7,0 @@ |
@@ -179,3 +179,3 @@ "use strict"; | ||
return __generator(this, function (_a) { | ||
if (!_.isDate(value)) { | ||
if (!_.isDate(value) || isNaN(value.getTime())) { | ||
throw new validation_1.PropertyValidationError('attribute.time', 'Not a time'); | ||
@@ -193,3 +193,3 @@ } | ||
return __generator(this, function (_a) { | ||
if (!_.isDate(value)) { | ||
if (!_.isDate(value) || isNaN(value.getTime())) { | ||
throw new validation_1.PropertyValidationError('attribute.date', 'Not a date'); | ||
@@ -196,0 +196,0 @@ } |
@@ -58,2 +58,3 @@ "use strict"; | ||
var _ = require("lodash"); | ||
var attribute_1 = require("./attribute"); | ||
var association_1 = require("./association"); | ||
@@ -135,2 +136,8 @@ var metadata_1 = require("./metadata"); | ||
instance = new this(_.pick(data, Object.keys(attrs)), { defaults: false }); | ||
// Convert date ISO string into Date object | ||
Object.keys(attrs).forEach(function (key) { | ||
if (attrs[key].type.type === attribute_1.DATE.type && typeof (instance[key]) === 'string') { | ||
instance[key] = new Date(instance[key]); | ||
} | ||
}); | ||
if (!assocOptions.associations) return [3 /*break*/, 4]; | ||
@@ -137,0 +144,0 @@ _loop_1 = function (key) { |
{ | ||
"name": "modelsafe", | ||
"version": "1.0.0-alpha.9", | ||
"version": "1.0.0-alpha.10", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/creativecuriositystudio/modelsafe/issues", |
@@ -167,3 +167,3 @@ /** Contains the attribute types. */ | ||
export const TIME = buildAttributeType(InternalAttributeType.TIME, async (_path: string, value: any) => { | ||
if (!_.isDate(value)) { | ||
if (!_.isDate(value) || isNaN(value.getTime())) { | ||
throw new PropertyValidationError('attribute.time', 'Not a time'); | ||
@@ -179,3 +179,3 @@ } | ||
export const DATE = buildAttributeType(InternalAttributeType.DATE, async (_path: string, value: any) => { | ||
if (!_.isDate(value)) { | ||
if (!_.isDate(value) || isNaN(value.getTime())) { | ||
throw new PropertyValidationError('attribute.date', 'Not a date'); | ||
@@ -182,0 +182,0 @@ } |
/** Contains the model classes and decorators. */ | ||
import * as _ from 'lodash'; | ||
import { DATE } from './attribute'; | ||
import { isLazyLoad, HAS_MANY, BELONGS_TO_MANY } from './association'; | ||
@@ -138,2 +139,9 @@ import { getAttributes, getAttributeValidations, getAssociations } from './metadata'; | ||
// Convert date ISO string into Date object | ||
Object.keys(attrs).forEach(key => { | ||
if (attrs[key].type.type === DATE.type && typeof (instance[key]) === 'string') { | ||
instance[key] = new Date(instance[key]); | ||
} | ||
}); | ||
if (assocOptions.associations) { | ||
@@ -140,0 +148,0 @@ // Call deserialization methods for associations to populate deserialized association data |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
343335
5271