Compare commits

..

2 commits

Author SHA1 Message Date
f0x e1618bacda flatten with infinite depth 2022-10-29 16:56:32 +02:00
f0x a8fc604f4f change flatten to Array#flat (Node 10.x EOL) 2022-08-22 20:41:06 +02:00
2 changed files with 3 additions and 6 deletions

View file

@ -2,8 +2,6 @@
// TODO: Rename this to something more appropriate, like any/anyOf? How to make sure that doesn't cause confusion with `oneOf`?
const flatten = require("flatten");
const ValidationError = require("@validatem/error");
const combinator = require("@validatem/combinator");
const validationResult = require("@validatem/validation-result");
@ -14,13 +12,13 @@ const areErrorsFromSameOrigin = require("./src/are-errors-from-same-origin");
function unpackNestedEithers(errors) {
// NOTE: We only unpack `either` errors that occurred *at the same level* as this error, ie. where there's directly a case of `either(either(...), ...)`, without any kind of data nesting (like `arrayOf` or `hasShape`) inbetween. Nested-data failures should still be shown separately, as their resolution strategy is actually different; unlike same-level nested `either` errors, where the nesting is purely an implementation detail that allows composing sets of alternatives together.
return flatten(errors.map((error) => {
return (errors.map((error) => {
if (error.path.length === 0 && error.__isValidatemEitherError) {
return error.subErrors;
} else {
return error;
}
}));
})).flat(Infinity);
}
function hasNestedPaths(error) {

View file

@ -20,7 +20,6 @@
"@validatem/combinator": "^0.1.1",
"@validatem/error": "^1.0.0",
"@validatem/match-validation-error": "^0.1.0",
"@validatem/validation-result": "^0.1.2",
"flatten": "^1.0.3"
"@validatem/validation-result": "^0.1.2"
}
}