validateMany currently returns an array of results ([null]), even if all subvalidations successfully pass. null should be returned directly to be consistent with validate and allow nesting of validate and validateMany calls.
validate({
foo: [isRequired]
})({
foo: 'bar'
}); // === null
validateMany({
foo: [isRequired]
})([{
foo: 'bar'
}]) // === [null], expected to be null
validate({
arr: [
validateMany({
foo: [isRequired]
})
]
})({
arr: [{
foo: 'bar'
}]
}) // === {arr: [null]}, expected to be null
Of course when at least one validation fails, the structure should be kept as is to know which index is wrong.
Proposed fix:
const fixedValidateMany = validations => o(when(all(isNil), always(null)), validateMany(validations));
validateManycurrently returns an array of results ([null]), even if all subvalidations successfully pass.nullshould be returned directly to be consistent withvalidateand allow nesting ofvalidateandvalidateManycalls.Of course when at least one validation fails, the structure should be kept as is to know which index is wrong.
Proposed fix: