-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return all CanDecide errors simultaneously (#421)
* refactor validate * test: adjust to split function * feat: add mergeResults * test: mergeResults * refactor: wording * refactor: simplify recursion --------- Co-authored-by: Julian König <[email protected]>
- Loading branch information
1 parent
4821dcc
commit 8685910
Showing
6 changed files
with
447 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./flattenObject"; | ||
export * from "./mergeResults"; | ||
export * from "./ValidationResult"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ValidationResult } from "./ValidationResult"; | ||
|
||
export function mergeResults(result1: ValidationResult, result2: ValidationResult): ValidationResult { | ||
if (result1.items.length !== result2.items.length) throw new Error("The dimensions of the ValidationResults do not match."); | ||
|
||
if (result1.items.length === 0) return result1.isError() ? result1 : result2; | ||
|
||
const mergedValidationResults = result1.items.map((item, index) => mergeResults(item, result2.items[index])); | ||
return ValidationResult.fromItems(mergedValidationResults); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.