guardz
Version:
A simple and lightweight TypeScript type guard library for runtime type validation.
31 lines (30 loc) • 1.15 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.combineResults = void 0;
const createValidationResult_1 = require("./createValidationResult");
/**
* Combine multiple validation results into a single result
* @param results - Array of validation results to combine
* @param parentPath - Optional parent path for the combined result
* @returns A combined ValidationResult
*/
const combineResults = (results, parentPath) => {
const allValid = results.every(r => r.valid);
const allErrors = results.flatMap(r => r.errors);
// Create a simple flat structure
const combinedTree = {
valid: allValid,
path: parentPath || 'root',
children: {},
errors: allErrors
};
// Add individual property trees as children
results.forEach(result => {
if (result.tree) {
const key = result.tree.path.split('.').pop() || 'unknown';
combinedTree.children[key] = result.tree;
}
});
return (0, createValidationResult_1.createValidationResult)(allValid, allErrors, combinedTree);
};
exports.combineResults = combineResults;