From 9a31868883797fe7621be03abcd75dff408e354e Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 1 Jul 2020 11:26:49 +0200 Subject: [PATCH] Improve error processing with syncpipe --- src/api/validate-arguments/index.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/api/validate-arguments/index.js b/src/api/validate-arguments/index.js index 3c1f569..6ce74ed 100644 --- a/src/api/validate-arguments/index.js +++ b/src/api/validate-arguments/index.js @@ -3,6 +3,7 @@ const isArguments = require("is-arguments"); const flatten = require("flatten"); const asExpression = require("as-expression"); +const syncpipe = require("syncpipe"); const ValidationError = require("@validatem/error"); const annotateErrors = require("@validatem/annotate-errors"); @@ -63,15 +64,12 @@ function applyDefinitions(args, definitions, remainingArgumentsIndex) { }; }); - // FIXME: Investigate syncpipe usage here - let combinedErrors = results.map((result) => result.errors); - let flattenedErrors = flatten(combinedErrors); // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021) - - let newValues = results.map((result) => result.newValue); - return { - errors: flattenedErrors, - newValue: newValues + errors: syncpipe(results, [ + (_) => _.map((result) => result.errors), + (_) => flatten(_) // TODO: Switch to `Array#flat` once Node 10.x goes EOL (April 2021) + ]), + newValue: results.map((result) => result.newValue) }; }