|
|
|
@ -4,6 +4,7 @@ const combinator = require("@validatem/combinator");
|
|
|
|
|
const validationResult = require("@validatem/validation-result");
|
|
|
|
|
const annotateErrors = require("@validatem/annotate-errors");
|
|
|
|
|
const isArray = require("@validatem/is-array");
|
|
|
|
|
const withContext = require("@validatem/with-context");
|
|
|
|
|
|
|
|
|
|
module.exports = function (rules) {
|
|
|
|
|
let validator = combinator((value, applyValidators) => {
|
|
|
|
@ -11,7 +12,8 @@ module.exports = function (rules) {
|
|
|
|
|
let allErrors = [];
|
|
|
|
|
|
|
|
|
|
value.forEach((item, i) => {
|
|
|
|
|
let { errors, newValue } = applyValidators(item, rules);
|
|
|
|
|
let itemRules = withContext(rules, { arrayIndex: i, arrayLength: value.length });
|
|
|
|
|
let { errors, newValue } = applyValidators(item, itemRules);
|
|
|
|
|
|
|
|
|
|
let annotatedErrors = annotateErrors({
|
|
|
|
|
pathSegments: [ i ],
|
|
|
|
|