import type { TranslationFunction } from '../i18n/types.ts'; import type { ValidationIssue } from './types.ts'; /** * The wire shape that goes out via `res.json({ errors: err.message })`. * * Each key is a field path. Each value is either a single message string * or an array of messages. Both forms are preserved as-given — no * normalization — so consumers see the same response bytes regardless * of which validator produced the error. */ export type ValidationErrorPayload = Record; /** * `Error` at runtime, typed without `message`, so `ValidationError` can widen * `message` to its payload in a declaration that checks under * `skipLibCheck: false` (a `@ts-expect-error` would not reach the `.d.ts`). */ declare const ErrorWithPayloadMessage: new (message?: string) => Omit; /** * Framework-owned validation error. Replaces yup's `ValidationError` at the * framework layer. * * Wire compatibility note — `.message` is the path-keyed payload object, * NOT a string. This mirrors yup's hack: `res.json({ errors: err.message })` * in `controllers/index.ts` (the validation wrapper) serializes the object directly to produce * `{ "errors": { "fieldName": [...] | "...", ... } }`. Existing user * catch-blocks that read `err.message` keep working unchanged. * * `.issues` is the canonical list (one entry per field/message pair) that * non-wire consumers (logging, observability) should iterate. */ export declare class ValidationError extends ErrorWithPayloadMessage { issues: ValidationIssue[]; message: ValidationErrorPayload; constructor(payload: ValidationErrorPayload | ReadonlyArray); /** * Cross-realm-safe duck check. Mirrors `yup.ValidationError.isError`. * Use this in framework code instead of `instanceof` when the error * may have crossed a module-graph boundary. * * The name alone is not enough: Mongoose's `ValidationError` (and yup's) share * it, and their `.message` is a string that embeds the rejected value. The * framework error is the only one carrying a structured `issues` array. */ static isValidationError(err: unknown): err is ValidationError; } export declare function issuesToPayload(issues: ReadonlyArray): ValidationErrorPayload; /** * Translate messages that are i18n keys; pass everything else * through untouched. This is deliberately a KEY allow-list, not a fallback to * `t(msg, msg, …)`: i18next runs nesting (`$t(...)`) and interpolation * (`{{...}}`) over its key/defaultValue, so feeding a user-influenced driver * message into it turns an error response into a reflected injection that can * resolve arbitrary keys out of the loaded translation bundle. */ export declare function translateIssues(issues: ReadonlyArray, t: TranslationFunction): ValidationIssue[]; export {};