import type { Handler, NextFunction } from "../types"; import type { BunRequest } from "../core/request"; import type { BunResponse } from "../core/response"; export type ValidationSource = "body" | "query" | "params"; export interface FieldRule { /** Mark field as required. Default: false */ required?: boolean; /** Field type: "string", "number", "boolean", "email", "url", "uuid", "integer" */ type?: string; /** Minimum length (strings) or minimum value (numbers) */ min?: number; /** Maximum length (strings) or maximum value (numbers) */ max?: number; /** Regex pattern the value must match */ pattern?: RegExp; /** Enumeration of allowed values */ enum?: unknown[]; /** Custom validator function. Return true if valid, false or string (error message) if invalid. */ custom?: (value: unknown, req: BunRequest) => boolean | string | Promise; /** Custom error message for this field */ message?: string; /** Trim whitespace before validation (strings only). Default: false */ trim?: boolean; /** Convert to lowercase before validation (strings only). Default: false */ toLowerCase?: boolean; /** Convert to number before validation. Default: false */ toNumber?: boolean; } export interface ValidationSchema { body?: Record; query?: Record; params?: Record; } export interface ValidationError { field: string; source: ValidationSource; message: string; value?: unknown; } export interface ValidationOptions { /** * If true, abort on first error. If false, collect all errors. * Default: false (collect all) */ abortEarly?: boolean; /** * HTTP status code for validation errors. Default: 422. */ statusCode?: number; /** * Custom error formatter. Receives the array of errors and returns the response body. * Default: returns `{ errors: [...] }` */ errorFormatter?: (errors: ValidationError[]) => unknown; /** * Custom error handler. If provided, called instead of sending automatic response. * Allows full control over error handling (e.g., pass to next(err)). */ onError?: (errors: ValidationError[], req: BunRequest, res: BunResponse, next: NextFunction) => void; } export declare function validate(schema: ValidationSchema, options?: ValidationOptions): Handler; //# sourceMappingURL=validation.d.ts.map