simpl-schema
Advanced tools
Comparing version 1.5.4 to 1.5.5
@@ -35,2 +35,6 @@ 'use strict'; | ||
var _typeValidator = require('./validation/typeValidator'); | ||
var _typeValidator2 = _interopRequireDefault(_typeValidator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -108,11 +112,23 @@ | ||
var outerDef = ss.schema(gKey); | ||
var def = outerDef && outerDef.type.definitions[0]; | ||
var defs = outerDef && outerDef.type.definitions; | ||
var def = defs && defs[0]; | ||
// Autoconvert values if requested and if possible | ||
if (options.autoConvert && def) { | ||
var newVal = (0, _convertToProperType2.default)(val, def.type); | ||
if (newVal !== undefined && newVal !== val) { | ||
_SimpleSchema.SimpleSchema.debug && console.info('SimpleSchema.clean: autoconverted value ' + val + ' from ' + (typeof val === 'undefined' ? 'undefined' : _typeof(val)) + ' to ' + (typeof newVal === 'undefined' ? 'undefined' : _typeof(newVal)) + ' for ' + gKey); | ||
val = newVal; | ||
this.updateValue(newVal); | ||
var isValidType = defs.some(function (definition) { | ||
var errors = _typeValidator2.default.call({ | ||
valueShouldBeChecked: true, | ||
definition: definition, | ||
value: val | ||
}); | ||
return errors === undefined; | ||
}); | ||
if (!isValidType) { | ||
var newVal = (0, _convertToProperType2.default)(val, def.type); | ||
if (newVal !== undefined && newVal !== val) { | ||
_SimpleSchema.SimpleSchema.debug && console.info('SimpleSchema.clean: autoconverted value ' + val + ' from ' + (typeof val === 'undefined' ? 'undefined' : _typeof(val)) + ' to ' + (typeof newVal === 'undefined' ? 'undefined' : _typeof(newVal)) + ' for ' + gKey); | ||
val = newVal; | ||
this.updateValue(newVal); | ||
} | ||
} | ||
@@ -119,0 +135,0 @@ } |
{ | ||
"name": "simpl-schema", | ||
"version": "1.5.4", | ||
"version": "1.5.5", | ||
"description": "A schema validation package that supports direct validation of MongoDB update modifier objects.", | ||
@@ -5,0 +5,0 @@ "author": "Eric Dobbertin <aldeed@gmail.com>", |
176520
2652