|
|
|
@ -6,28 +6,32 @@ const annotateErrors = require("@validatem/annotate-errors");
|
|
|
|
|
const isArray = require("@validatem/is-array");
|
|
|
|
|
|
|
|
|
|
module.exports = function (rules) {
|
|
|
|
|
let validator = combinator((value, applyValidators) => {
|
|
|
|
|
let newArray = [];
|
|
|
|
|
let allErrors = [];
|
|
|
|
|
|
|
|
|
|
value.forEach((item, i) => {
|
|
|
|
|
let { errors, newValue } = applyValidators(item, rules);
|
|
|
|
|
|
|
|
|
|
let annotatedErrors = annotateErrors({
|
|
|
|
|
pathSegments: [ i ],
|
|
|
|
|
errors: errors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
newArray.push(newValue);
|
|
|
|
|
allErrors.push(...annotatedErrors);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return validationResult({
|
|
|
|
|
errors: allErrors,
|
|
|
|
|
newValue: newArray
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
validator.callIfNull = false;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
isArray,
|
|
|
|
|
combinator((value, applyValidators) => {
|
|
|
|
|
let newArray = [];
|
|
|
|
|
let allErrors = [];
|
|
|
|
|
|
|
|
|
|
value.forEach((item, i) => {
|
|
|
|
|
let { errors, newValue } = applyValidators(item, rules);
|
|
|
|
|
|
|
|
|
|
let annotatedErrors = annotateErrors({
|
|
|
|
|
pathSegments: [ i ],
|
|
|
|
|
errors: errors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
newArray.push(newValue);
|
|
|
|
|
allErrors.push(...annotatedErrors);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return validationResult({
|
|
|
|
|
errors: allErrors,
|
|
|
|
|
newValue: newArray
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
validator
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|