/** * Enhanced Validation Plugin for OpenSpeed * Supports multiple validators via Standard Schema (Zod, Valibot, ArkType, Effect, etc.) */ import type { Context } from '../context.js'; export interface StandardSchemaV1 { readonly '~standard': { readonly version: 1; readonly vendor: string; readonly validate: (value: unknown) => StandardSchemaV1Result; }; } export interface StandardSchemaV1Result { readonly value?: Output; readonly issues?: ReadonlyArray; } export interface StandardSchemaV1Issue { readonly message: string; readonly path?: ReadonlyArray; } export type Validator = StandardSchemaV1 | { parse: (value: unknown) => T; } | { safeParse: (value: unknown) => { success: boolean; data?: T; error?: any; }; }; export interface ValidationOptions { body?: Validator; params?: Validator; query?: Validator; headers?: Validator; response?: Validator; onError?: (error: ValidationError, ctx: Context) => void; } export interface ValidationError { type: 'body' | 'params' | 'query' | 'headers' | 'response'; issues: Array<{ message: string; path?: Array; }>; } /** * Main validation middleware */ export declare function validate(options: ValidationOptions): (ctx: Context, next: () => Promise) => Promise; /** * Helper for creating typed route handlers with validation */ export declare function createValidatedHandler(schema: { body?: Validator; params?: Validator; query?: Validator; }, handler: (ctx: Context & { body: TBody; params: TParams; query: TQuery; }) => any): (((ctx: Context, next: () => Promise) => Promise) | ((ctx: Context) => Promise))[]; /** * Example usage: * * // With Zod * import { z } from 'zod'; * import { validate } from 'openspeed/plugins/validate'; * * app.post('/user', validate({ * body: z.object({ * name: z.string(), * age: z.number() * }) * }), (ctx) => { * const { name, age } = ctx.getBody(); // Type-safe! * return ctx.json({ name, age }); * }); * * // With Valibot * import * as v from 'valibot'; * * app.post('/user', validate({ * body: v.object({ * name: v.string(), * age: v.number() * }) * }), (ctx) => { * return ctx.json(ctx.getBody()); * }); * * // With ArkType * import { type } from 'arktype'; * * app.post('/user', validate({ * body: type({ * name: 'string', * age: 'number' * }) * }), (ctx) => { * return ctx.json(ctx.getBody()); * }); */ //# sourceMappingURL=validate.d.ts.map