{"version":3,"file":"_validateReport.mjs","names":[],"sources":["../../src/internal/_validateReport.ts"],"sourcesContent":["import { IValidation } from \"@typia/interface\";\n\n/**\n * Create the reporter that validation functions use to collect errors.\n *\n * The returned function keeps an error only when it is exceptionable and its\n * path is neither an ancestor nor a descendant of the last kept path, so a\n * failing leaf is not also reported as every enclosing value. An undefined\n * value gets a default description when none was supplied. Kept errors retain\n * their original references, and filling that description updates the error. It\n * always returns false so emitted code can return it directly.\n *\n * @evidence contracts/common.md#principled-implementation The reporter pushes the original error onto the list only when it is exceptionable and its path is neither an ancestor nor a descendant of the last pushed one, so a failing leaf is not also reported as every enclosing value. For an undefined value it fills a missing description while preserving supplied text; it always returns false so emitted code can return it directly.\n * @evidence contracts/common.md#clear-and-simple-design One closure with two private predicates.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The suppression is path-based and general.\n * @evidence contracts/common.md#meaningful-documentation A comment states the suppression and the false result.\n */\nexport const _validateReport = (array: IValidation.IError[]) => {\n  const isAncestor = (ancestor: string, descendant: string): boolean =>\n    descendant === ancestor ||\n    descendant.startsWith(`${ancestor}.`) ||\n    descendant.startsWith(`${ancestor}[`);\n  const reportable = (path: string): boolean => {\n    if (array.length === 0) return true;\n    const last: string = array[array.length - 1]!.path;\n    return isAncestor(path, last) === false && isAncestor(last, path) === false;\n  };\n  return (exceptable: boolean, error: IValidation.IError): false => {\n    if (exceptable && reportable(error.path)) {\n      if (error.value === undefined)\n        error.description ??= [\n          \"The value at this path is `undefined`.\",\n          \"\",\n          `Please fill the \\`${error.expected}\\` typed value next time.`,\n        ].join(\"\\n\");\n      array.push(error);\n    }\n    return false;\n  };\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,mBAAmB,UAAgC;CAC9D,MAAM,cAAc,UAAkB,eACpC,eAAe,YACf,WAAW,WAAW,GAAG,SAAS,EAAE,KACpC,WAAW,WAAW,GAAG,SAAS,EAAE;CACtC,MAAM,cAAc,SAA0B;EAC5C,IAAI,MAAM,WAAW,GAAG,OAAO;EAC/B,MAAM,OAAe,MAAM,MAAM,SAAS,EAAE,CAAE;EAC9C,OAAO,WAAW,MAAM,IAAI,MAAM,SAAS,WAAW,MAAM,IAAI,MAAM;CACxE;CACA,QAAQ,YAAqB,UAAqC;EAChE,IAAI,cAAc,WAAW,MAAM,IAAI,GAAG;GACxC,IAAI,MAAM,UAAU,KAAA,GAClB,MAAM,gBAAgB;IACpB;IACA;IACA,qBAAqB,MAAM,SAAS;GACtC,CAAC,CAAC,KAAK,IAAI;GACb,MAAM,KAAK,KAAK;EAClB;EACA,OAAO;CACT;AACF"}