Comparing version 4.2.1 to 4.3.0
@@ -0,1 +1,5 @@ | ||
## 4.3.0/2018-05-21 | ||
- fix: `_formatSetOrSetOnInsert` | ||
## 4.2.1/2018-05-14 | ||
@@ -2,0 +6,0 @@ |
@@ -338,8 +338,9 @@ const _ = require('lodash') | ||
function _formatSetOrSetOnInsert (doc, schemaPath = '', parentDoc, parentKey) { | ||
if (_.isPlainObject(doc)) { | ||
function _formatSetOrSetOnInsert (doc, schemaPath = '', parentDoc, parentKey, subSchema = compiledSchema) { | ||
if (_.isPlainObject(doc) && !subSchema._leaf) { | ||
for (let key in doc) { | ||
const subDoc = doc[key] | ||
const subSchemaPath = `${schemaPath ? schemaPath + '.' : ''}${key}` | ||
doc[key] = _formatSetOrSetOnInsert(subDoc, subSchemaPath, doc, key) | ||
const subSchema = getSchema(compiledSchema, subSchemaPath) | ||
doc[key] = _formatSetOrSetOnInsert(subDoc, subSchemaPath, doc, key, subSchema) | ||
} | ||
@@ -349,24 +350,21 @@ } else { | ||
// only leaf & only check type & ignoreNodeType | ||
/* istanbul ignore else */ | ||
if (schema._leaf) { | ||
// try format, if false then pass | ||
if (_.isArray(doc)) { | ||
const result = schema.validate(doc) | ||
if (!result.valid) { | ||
throw result.error | ||
} | ||
doc = result.result | ||
} else { | ||
// eg: 'posts.comments' -> 'comments' | ||
let key = parentKey.split('.').slice(-1)[0] | ||
const result = schema._parent.validate({ [key]: doc }, { | ||
ignoreNodeType: true, | ||
required: false, | ||
default: false | ||
}) | ||
if (!result.valid) { | ||
throw result.error | ||
} | ||
doc = result.result[key] | ||
// try format, if false then pass | ||
if (_.isArray(doc)) { | ||
const result = schema.validate(doc) | ||
if (!result.valid) { | ||
throw result.error | ||
} | ||
doc = result.result | ||
} else { | ||
// eg: 'posts.comments' -> 'comments' | ||
let key = parentKey.split('.').slice(-1)[0] | ||
const result = schema._parent.validate({ [key]: doc }, { | ||
ignoreNodeType: true, | ||
required: false, | ||
default: false | ||
}) | ||
if (!result.valid) { | ||
throw result.error | ||
} | ||
doc = result.result[key] | ||
} | ||
@@ -373,0 +371,0 @@ } |
{ | ||
"name": "mongolass", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "Elegant MongoDB driver for Node.js.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
93396
2336