import type { StandardSchema } from './standard-schema.types.js'; export interface ValidationResult { success: boolean; data?: T; errors?: Array<{ message: string; path?: Array; }>; } export interface ValidationSource { body?: unknown; query?: Record; headers?: Record; params?: Record; } export interface ValidationSchemas { body?: StandardSchema; query?: StandardSchema; headers?: StandardSchema; params?: StandardSchema; } export interface ValidatedData { body?: unknown; query?: unknown; headers?: unknown; params?: unknown; } /** * Service for validating request data using Standard Schema compliant validators. * * This service provides a unified interface for validating HTTP request data (body, query parameters, headers) * using any validation library that implements the Standard Schema specification. * * @example Using with Zod * ```typescript * import { z } from 'zod'; * import { SchemaValidationService } from './schema-validation-service.js'; * * const service = new SchemaValidationService(); * const result = await service.validateRequest( * { body: { title: 'Hello', count: 42 } }, * { body: z.object({ title: z.string(), count: z.number() }) } * ); * * if (result.success) { * console.log(result.data.body); * } * ``` * * @example Using with Valibot * ```typescript * import * as v from 'valibot'; * * const result = await service.validateRequest( * { query: { page: '1' } }, * { query: v.object({ page: v.string() }) } * ); * ``` * * @example Using with ArkType * ```typescript * import { type } from 'arktype'; * * const result = await service.validateRequest( * { headers: { 'authorization': 'Bearer token' } }, * { headers: type({ authorization: 'string' }) } * ); * ``` * * @example Multiple sources * ```typescript * const result = await service.validateRequest( * { * body: { title: 'Post' }, * query: { format: 'json' }, * headers: { 'content-type': 'application/json' } * }, * { * body: z.object({ title: z.string() }), * query: v.object({ format: v.string() }), * headers: type({ 'content-type': 'string' }) * } * ); * ``` * * Supported libraries: Zod, Valibot, ArkType, Effect Schema (with standardSchemaV1 wrapper) */ export declare class SchemaValidationService { /** * Validates request data against provided schemas. * * Validates body, query parameters, and headers against their respective schemas. * All validations are performed, and errors are aggregated from all sources. * * @param source - The data to validate (body, query, headers) * @param schemas - The Standard Schema validators for each source * @returns Validation result with validated data or aggregated errors * * @example * ```typescript * const result = await service.validateRequest( * { body: { name: 'John', age: 30 } }, * { body: z.object({ name: z.string(), age: z.number() }) } * ); * * if (result.success) { * const validated = result.data.body; * } else { * console.error(result.errors); * } * ``` */ validateRequest(source: ValidationSource, schemas: ValidationSchemas): Promise>; /** * Validates a single value against a Standard Schema. */ private mapSchemaIssue; private validateWithSchema; }