archetype-js
Advanced tools
Comparing version
{ | ||
"name": "archetype-js", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"author": "Valeri Karpov <val@boosterfuels.com>", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -34,2 +34,3 @@ 'use strict'; | ||
projection = _.cloneDeep(projection); | ||
projection.$hasExclusiveChild = {}; | ||
let inclusive = null; | ||
@@ -44,3 +45,3 @@ for (const key of Object.keys(projection)) { | ||
} | ||
markSubpaths(projection, key, projection[key]); | ||
markSubpaths(projection.$hasExclusiveChild, key, projection[key]); | ||
inclusive = false; | ||
@@ -59,2 +60,3 @@ } else { | ||
projection.$inclusive = inclusive; | ||
return projection; | ||
@@ -162,2 +164,3 @@ } | ||
if (!schema._paths[newPath] || shouldSkipPath(projection, newPath)) { | ||
debug('delete', key, shouldSkipPath(projection, newPath)); | ||
delete obj[key]; | ||
@@ -164,0 +167,0 @@ return; |
@@ -7,4 +7,12 @@ 'use strict'; | ||
} else { | ||
return projection[path] == null; | ||
const parts = path.split('.'); | ||
let cur = parts[0]; | ||
for (let i = 0; i < parts.length - 1; ++i) { | ||
if (projection[cur] != null) { | ||
return false; | ||
} | ||
cur += '.' + parts[i + 1]; | ||
} | ||
return projection[path] == null && projection.$hasExclusiveChild[path] == null; | ||
} | ||
} |
@@ -622,2 +622,25 @@ 'use strict'; | ||
}); | ||
it('required underneath array', function() { | ||
const Test = new Archetype({ | ||
products: [{ name: { $type: 'string', $required: true } }] | ||
}).compile('Test'); | ||
assert.throws(function() { | ||
new Test({ products: [{ name: null }] }); | ||
}, /required/); | ||
}); | ||
it('object array under projection', function() { | ||
const Test = new Archetype({ | ||
name: 'string', | ||
arr: { | ||
$type: [{ el: { $type: 'string' } }], | ||
$required: true | ||
} | ||
}).compile('Test'); | ||
assert.deepEqual(new Test({ name: '1', arr: [{ el: '2' }]}, { arr: 1 }), { | ||
arr: [{ el: '2' }] | ||
}); | ||
}); | ||
}); | ||
@@ -624,0 +647,0 @@ |
1188
2.59%48782
-45.03%15
-6.25%