export { compileMessageTemplate, compileMessageCatalog, } from '@jarenjs/core/message'; /** * The built-in English catalog: one entry per message key the validator * produces, rendering the exact strings of the historical `#convertErrors` * if/else chain. Keywords without an entry (`const`, `enum`, * `dependentRequired`, ...) fall back to the generic * `validation failed for keyword ''` - as before. * @type {Record string)>} */ export declare const messagesEn: Record string)>; /** * JSON Schema Validation Error * Represents a validation error according to the JSON Schema specification. * @see https://json-schema.org/draft/2020-12/json-schema-core.html#output */ export declare class ValidationError { keyword: string; instancePath: string; schemaPath: string; params: object; msgid: string; message: string; /** * @param {object} options - Error options * @param {string} options.keyword - The keyword that failed validation * @param {string} options.instancePath - JSON Pointer to the data location * @param {string} options.schemaPath - JSON Pointer to the schema location * @param {object} options.params - Keyword-specific parameters * @param {string} [options.msgid] - Stable message key resolving this error in a catalog * @param {string} [options.message] - Human-readable error message */ constructor(options: { keyword: string; instancePath: string; schemaPath: string; params: object; msgid?: string; message?: string; }); /** * Convert error to a plain object * @returns {object} Plain object representation */ toJSON(): object; } /** * Render the message of an error through a catalog - the tail of the * resolution precedence chain (no `errorMessage` registry involvement): * catalog[msgid], built-in English[msgid], catalog[keyword], * built-in English[keyword], then the generic fallback text. * @param {ValidationError | {keyword: string, msgid?: string, params?: object}} error - The error to render * @param {Readonly string>>} [catalog] - A compiled catalog (see {@link compileMessageCatalog}) * @returns {string} The rendered message */ export declare function renderErrorMessage(error: ValidationError | { keyword: string; msgid?: string; params?: object; }, catalog?: Readonly string>>): string; /** * Re-render the `message` of every error from its `msgid` + `params` * through the given catalog, with built-in English fallback. This is the * whole post-hoc i18n story: * `localizeErrors(validate(data).errors, compileMessageCatalog(nl))`. * * Inline schema-authored messages (a MessageSpec without `$msgid`) are * single-language by definition and are NOT re-rendered - that is why * `$msgid` exists. An error whose `msgid` resolves in no catalog keeps * its current message (e.g. the spec's inline fallback text). * @param {ValidationError[]} errors - Errors from a collect-mode validation * @param {Readonly string>>} catalog - A compiled catalog (see {@link compileMessageCatalog}) * @returns {ValidationError[]} The same array, messages re-rendered */ export declare function localizeErrors(errors: ValidationError[], catalog: Readonly string>>): ValidationError[]; export type CompiledMessageSpec = { /** * - Catalog key to resolve at render time */ msgid: string | null; /** * - Compiled inline template */ render: ((params: object, error?: object) => string) | null; /** * - Author params, merged OVER the error's params */ params: object | null; }; export type CompiledErrorMessageNode = { /** * - String-form spec: covers this node AND its subtree */ all: CompiledMessageSpec | null; /** * - Map-form per-keyword specs (this node only) */ keywords: Map; fallback: CompiledMessageSpec | null; }> | null; /** * - The '_' entry (this node only) */ catchAll: CompiledMessageSpec | null; }; /** * A compiled 'errorMessage' node registered on the ValidationRoot. * @typedef {object} CompiledErrorMessageNode * @property {CompiledMessageSpec|null} all - String-form spec: covers this node AND its subtree * @property {Map, fallback: CompiledMessageSpec|null}>|null} keywords - Map-form per-keyword specs (this node only) * @property {CompiledMessageSpec|null} catchAll - The '_' entry (this node only) */ /** * Compile the value of an 'errorMessage' keyword into a registry node. * Grammar (validated here, at schema compile time): * - MessageSpec (string / `$msgid` object): covers the whole subtree; * - map form: per-keyword MessageSpecs for this node, where `required` * also accepts a per-missing-property map, `$query` a per-runtime-code * map (with `default` for the EBV-false failure), and `_` is the * node-level catch-all. * @param {unknown} errorMessage - The keyword's value * @param {string} path - The schema path, for compile error messages * @returns {CompiledErrorMessageNode} The compiled node */ export declare function compileErrorMessageSpec(errorMessage: unknown, path: string): CompiledErrorMessageNode; /** * Convert internal validation errors to the public ValidationError format. * Params extraction is table-driven off the failed keyword; message text * goes through the errorMessage registry (if any) and the built-in * English catalog. With `options.messages === false` no message is * rendered at all (`message: ''`, params and msgid still set). * @param {Array<{object: any, key: string|string[], expected: any, dataKey: any, value: any, rest: any[]}>} internalErrors - The root's internal error records * @returns {ValidationError[]} The public errors */ export declare function convertInternalErrors(internalErrors: Array<{ object: any; key: string | string[]; expected: any; dataKey: any; value: any; rest: any[]; }>): ValidationError[];