Comparing version 0.8.3 to 0.8.4
@@ -34,2 +34,18 @@ ## [Unreleased] | ||
## [0.8.4] - 2018-01-28 | ||
### Added | ||
* Normalization of Mongo Ids | ||
* New aggregation pipeline stages ( $replaceRoot, $facet, $unwind, $group) | ||
### Removed | ||
* Validation on update Documents | ||
### Fixed | ||
* Bug validating empty (null) values | ||
* Bug validating enum array values | ||
## [0.8.3] - 2018-01-23 | ||
@@ -398,2 +414,3 @@ | ||
[0.8.4]: https://github.com/Yonirt/moltyjs/compare/v0.8.3...v0.8.4 | ||
[0.8.3]: https://github.com/Yonirt/moltyjs/compare/v0.8.2...v0.8.3 | ||
@@ -400,0 +417,0 @@ [0.8.2]: https://github.com/Yonirt/moltyjs/compare/v0.8.1...v0.8.2 |
@@ -42,3 +42,7 @@ 'use strict'; | ||
$lookup: ['from', 'localField', 'foreignField', 'as', 'let', 'pipeline'], | ||
$project: [] | ||
$project: [], | ||
$replaceRoot: [], | ||
$facet: [], | ||
$unwind: [], | ||
$group: [] | ||
}; | ||
@@ -219,16 +223,2 @@ | ||
/** | ||
* _validateUpdatePayload(): Validate update payload | ||
*/ | ||
_validateUpdatePayload(payload, model) { | ||
return _asyncToGenerator(function* () { | ||
let validations = []; | ||
Object.keys(payload).forEach(function (operator) { | ||
validations.push(model.validatePayloadFieldValues(payload[operator], model._schemaNormalized, payload[operator], operator)); | ||
}); | ||
validations = yield Promise.all(validations); | ||
})(); | ||
} | ||
/** | ||
* _validateAggregateOperators(): Check if the aggregate operators | ||
@@ -767,10 +757,2 @@ * are correct and supported | ||
// Validate the payload | ||
yield _this4._validateUpdatePayload(payload, model); | ||
/*await model.validatePayloadFieldValues( | ||
payload, | ||
model._schemaNormalized, | ||
payload, | ||
);*/ | ||
// Ensure index are created | ||
@@ -777,0 +759,0 @@ if (_this4._indexes[collection] && _this4._indexes[collection].length > 0) { |
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
@@ -239,3 +241,3 @@ | ||
// Array | ||
if (isArray(schema[key]) && payload[key] && !schema[key].type) { | ||
if (!schema[key].type && isArray(schema[key]) && payload[key]) { | ||
var _iteratorNormalCompletion2 = true; | ||
@@ -273,3 +275,3 @@ var _didIteratorError2 = false; | ||
// Objects nested | ||
if (isObject(schema[key]) && !isArray(schema[key]) && payload[key] && !schema[key].type) { | ||
if (!schema[key].type && isObject(schema[key]) && !isArray(schema[key]) && payload[key]) { | ||
try { | ||
@@ -284,3 +286,3 @@ yield _this2.validatePayloadFieldValues(payload[key], schema[key], parentPayload, operator); | ||
// No required values | ||
if ((!payload || payload[key] === undefined) && (!schema[key].requiredn || operator)) continue; | ||
if ((!payload || payload[key] === undefined) && (!schema[key].required || operator)) continue; | ||
@@ -396,11 +398,20 @@ // Is required validation | ||
// If we don't have the ref Id on the payload let set as null or empty [] | ||
// to keep record of it in the database | ||
if (schema[key].ref && (!payload || isEmptyValue(payload[key]))) { | ||
const refNormalValue = isArray(schema[key].type) ? [] : null; | ||
if (!payload) payload = { | ||
[key]: refNormalValue | ||
};else payload[key] = refNormalValue; | ||
return; | ||
// Ref values (Ids) | ||
if (schema[key].ref) { | ||
if (!payload || isEmptyValue(payload[key])) { | ||
const refNormalValue = isArray(schema[key].type) ? [] : null; | ||
payload = _extends({}, payload, { | ||
[key]: refNormalValue | ||
}); | ||
return; | ||
} else if (payload[key]) { | ||
const Schema = require('./schema'); | ||
if (isArray(schema[key].type)) { | ||
payload[key].forEach(value => { | ||
payload[key] = Schema.types().ObjectId(value); | ||
}); | ||
} else { | ||
payload[key] = Schema.types().ObjectId(payload[key]); | ||
} | ||
} | ||
} | ||
@@ -407,0 +418,0 @@ |
@@ -112,2 +112,32 @@ 'use strict'; | ||
} | ||
if (isArray(choice)) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = choice[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
let choiceItem = _step.value; | ||
if (choices.indexOf(choiceItem) < 0) return false; | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
return choices.indexOf(choice) > -1; | ||
@@ -117,3 +147,3 @@ }; | ||
const isEmptyValue = function isEmptyValue(value) { | ||
return typeof value === 'undefined' || !(typeof value === 'number' || value instanceof Date || typeof value === 'boolean') && 0 === Object.keys(value).length; | ||
return value === null || typeof value === 'undefined' || !(typeof value === 'number' || value instanceof Date || typeof value === 'boolean') && 0 === Object.keys(value).length; | ||
}; | ||
@@ -120,0 +150,0 @@ |
{ | ||
"name": "moltyjs", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "A tiny ODM for MongoDB with multy tenancy support.", | ||
@@ -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
118651
2169