// lib/util/result.mjs // Validation result shape used by every validator and parser. /** * @typedef {{ code: string, message: string, hint?: string, location?: string }} Issue * @typedef {{ valid: boolean, errors: Issue[], warnings: Issue[], parsed?: any }} Result */ /** @returns {Result} */ export function ok(parsed) { return { valid: true, errors: [], warnings: [], parsed }; } /** @returns {Result} */ export function fail(errors, parsed) { return { valid: false, errors: Array.isArray(errors) ? errors : [errors], warnings: [], parsed }; } /** @returns {Result} */ export function combine(results) { const errors = []; const warnings = []; let parsed; for (const r of results) { if (r.errors) errors.push(...r.errors); if (r.warnings) warnings.push(...r.warnings); if (r.parsed !== undefined && parsed === undefined) parsed = r.parsed; } return { valid: errors.length === 0, errors, warnings, parsed }; } /** @returns {Issue} */ export function issue(code, message, hint, location) { return { code, message, hint, location }; }