import Base from '../../modules/Base.ts'; import type { IApp } from '../../server.ts'; import type { TranslationFunction } from '../i18n/types.ts'; import type { ValidatorDriver } from './types.ts'; /** * Per-route validator dispatcher. Resolves a `ValidatorDriver` once at * construction (cheap sync property check) and delegates per-request * validation to it. Drivers are vendor-aware — see `./drivers/`. * * User-extension API: `ValidateService.register(myDriver)` prepends * a custom driver, giving it priority over the built-ins. Drivers * are matched in order via `canHandle(body)`; first match wins. * Routes build their validators at boot, so register before `startServer()` * (module scope) — not in the `bootHttp` hook, which runs after routes wrap. * * Built-in resolution order (most specific first): * 1. yupDriver — Standard Schema with `vendor: 'yup'` (strip-unknown) * 2. standardSchemaDriver — any other `~standard`-conformant lib * * Schemas that match no driver throw at construction with a migration * message — including legacy `{validate, cast}` plain objects (removed * in 5.0; wrap as Standard Schema, ~10 lines). */ declare class ValidateService extends Base { schema: unknown; driver: ValidatorDriver | null; static drivers: ValidatorDriver[]; constructor(app: IApp, schema: unknown | null); /** * Find the first registered driver whose `canHandle(schema)` returns true. */ static resolve(schema: unknown): ValidatorDriver | null; /** * Register a custom driver. By default prepends so user drivers take * priority over the built-ins (e.g., to override yup-strip behavior * or to add a non-Standard-Schema lib like raw Joi). */ static register(driver: ValidatorDriver, position?: 'first' | 'last'): void; /** * Validate `data` against the route's schema. Returns the cast value * on success; throws `ValidationError` on failure. If no schema was * provided, returns `data` unchanged. * * If `i18n` is supplied, error messages are translated through `i18n.t` * before the error is re-thrown — both `.message` (wire-shape) and * `.issues` (structured). Skip the argument and consumers that don't * need translation (workers, RPC, tests) get raw keys back. The HTTP * controller path passes `req.appInfo.i18n` so users never have to * remember a translation step. */ validate(data: unknown, i18n?: { t: TranslationFunction; } | null): Promise; static get loggerGroup(): string; } export default ValidateService;