import { C as MiddlewareInput, F as RouteMeta, I as RouteOptions, N as Route, P as RouteMatch, R as RouteSchema, S as MiddlewareEntry, a as MiddlewareResponseDeclaration, f as ContextFromMiddlewareInput, g as HandlerResult, h as HandlerContext, l as AddedContextFromMiddlewareInput, n as DeclaredMiddleware, r as DefineMiddlewareOptions, t as Router, u as AnyContext } from "./router-Cwb7ak0J.mjs"; import { n as RoutekitResponse } from "./core-CzUCxvGk.mjs"; import { a as ValibotRouteHandler, c as ValibotSchemaMiddlewareOptions, d as ValibotValidationErrorHandler, f as createValibotRouteBuilder, i as ValibotRouteBuilder, l as ValibotValidationError, m as valibotSchemaMiddleware, n as ValibotHandlerContext, o as ValibotRouteHelperDefaults, p as defineValibotMiddleware, r as ValibotHandlerParams, s as ValibotRouteSchemaInput, t as DefineValibotMiddlewareOptions, u as ValibotValidationErrorBody } from "./valibot-2MepBTEi.mjs"; import { z } from "zod"; //#region src/router/routes/zod/zod.d.ts /** * Validation error component identifiers for Zod-backed routes. */ declare const enum ValidationError { REQUEST_BODY = 0, URL_PATH = 1, QUERY_PARAMETERS = 2 } type ErrorTree = ReturnType; type ZodSchema = z.ZodTypeAny | undefined; type AnyZodResponseBodySchemas = Partial>; type ZodResponseBodySchemas = AnyZodResponseBodySchemas | undefined; type ResponseValidationMode = false | 'strict' | 'parse'; type ResponseValidationOption = boolean | ResponseValidationMode; type ZodRouteContext = Ctx & AddedContextFromMiddlewareInput & AddedContextFromMiddlewareInput; type ZodBuilderMiddlewareInput, RouteMiddleware extends MiddlewareInput> = [BuilderMiddleware] extends [undefined] ? RouteMiddleware : [RouteMiddleware] extends [undefined] ? BuilderMiddleware : MiddlewareInput; /** * Default validation error payload returned by Zod-backed routes. */ type ZodValidationErrorBody = { component: 'request_body' | 'url_path' | 'query_parameters'; errorTree: ErrorTree; message: string; }; /** * Zod schema input that mirrors the core route `schema` shape. */ type ZodRouteSchemaInput = { request?: { query?: QuerySchema; path?: PathSchema; body?: BodySchema; }; response?: { body?: ResponseBodySchemas; }; }; type InferSchema = Schema extends z.ZodTypeAny ? z.infer : unknown; type InferResponseBodySchemaInputUnion = [keyof ResponseBodySchemas] extends [never] ? unknown : { [Status in keyof ResponseBodySchemas]: NonNullable extends z.ZodTypeAny ? z.input> : never }[keyof ResponseBodySchemas]; type InferResponseBodySchemaOutputUnion = [keyof ResponseBodySchemas] extends [never] ? unknown : { [Status in keyof ResponseBodySchemas]: NonNullable extends z.ZodTypeAny ? z.output> : never }[keyof ResponseBodySchemas]; type InferResponseBodyInput = ResponseBodySchemas extends AnyZodResponseBodySchemas ? 200 extends keyof ResponseBodySchemas ? InferResponseBodySchemaInputUnion : 'default' extends keyof ResponseBodySchemas ? InferResponseBodySchemaInputUnion : unknown : unknown; type InferResponseBodyOutput = ResponseBodySchemas extends AnyZodResponseBodySchemas ? 200 extends keyof ResponseBodySchemas ? InferResponseBodySchemaOutputUnion : 'default' extends keyof ResponseBodySchemas ? InferResponseBodySchemaOutputUnion : unknown : unknown; type InferResponseBodyAccepted = InferResponseBodyInput | InferResponseBodyOutput; type NormalizeSchema = Schema extends ZodRouteSchemaInput ? Schema : ZodRouteSchemaInput; type ExtractBodySchema | undefined> = NormalizeSchema extends ZodRouteSchemaInput ? BodySchema : undefined; type ExtractPathSchema | undefined> = NormalizeSchema extends ZodRouteSchemaInput ? PathSchema : undefined; type ExtractQuerySchema | undefined> = NormalizeSchema extends ZodRouteSchemaInput ? QuerySchema : undefined; type ExtractResponseBodySchemas | undefined> = NormalizeSchema extends ZodRouteSchemaInput ? ResponseBodySchemas : undefined; type ZodMiddlewareDeclarations = { [Status in keyof Schemas]: NonNullable extends z.ZodTypeAny ? MiddlewareResponseDeclaration>> : never }; type ZodDeclaredResponse = { [Status in keyof Schemas]-?: NonNullable extends z.ZodTypeAny ? RoutekitResponse>, Status extends number ? Status : number> : never }[keyof Schemas]; type ZodSchemaMiddlewareContext | undefined> = { params: ZodHandlerParams, ExtractPathSchema, ExtractQuerySchema>; }; /** * Validated request inputs exposed to a Zod-backed handler. */ type ZodHandlerParams = { path: InferSchema; query: InferSchema; body: InferSchema; }; /** * Context object exposed to a Zod-backed handler. */ type ZodHandlerContext = Omit, 'path'> & { params: ZodHandlerParams; }; /** * Validation error handler used when request parsing fails. * * @param component - Request component that failed validation. * @param error - The Zod validation error. * @returns A handler result that should be returned to the client. */ type ValidationErrorHandler = (component: ValidationError, error: z.ZodError) => ZodDeclaredResponse; /** * Shared defaults that can be applied to Zod handler helpers. */ type ZodHandlerDefaults = { /** * Route schema fragments that should be merged into every factory-built route. * Route-level schemas override matching request fields and response status codes. */ schema?: ZodRouteSchemaInput; /** * Whether and how to apply `schema.response.body` to handler responses. * `false` disables response validation, `true` and `'strict'` validate without changing the * response body, and `'parse'` returns the parsed response body. Defaults to `'parse'`. */ validateResponse?: ResponseValidationOption; } & ({ onRequestValidationError?: undefined; validationResponses?: undefined; } | { /** * Override the default request validation error response. */ onRequestValidationError: ValidationErrorHandler; /** * Response schemas returned by `onRequestValidationError`. */ validationResponses: AnyZodResponseBodySchemas; }); /** * Shared defaults that can be applied to Zod route helpers. */ type ZodRouteHelperDefaults = undefined> = ZodHandlerDefaults & { /** * Middleware applied to every route built by the helper. */ middleware?: BuilderMiddleware; }; /** * Handler signature used by Zod schema boundaries and route builders. */ type ZodRouteHandler = (this: Router, ctx: ZodHandlerContext) => HandlerResult>; /** * Shared options used by Zod route builders. */ type ZodHandlerOptions | undefined, Ctx extends object = AnyContext> = ZodHandlerDefaults & { schema?: Schema; handler: ZodRouteHandler, ExtractPathSchema, ExtractQuerySchema, ExtractResponseBodySchemas, Ctx>; }; /** * Full route options used by Zod route builders. */ type ZodRouteOptions | undefined, Ctx extends object = AnyContext, BuilderMiddleware extends MiddlewareInput = undefined, RouteMiddleware extends MiddlewareInput = undefined> = Omit>, 'handler' | 'schema' | 'middleware'> & ZodHandlerOptions> & { middleware?: RouteMiddleware; }; /** * Method-specific route options used by Zod route builders. */ type WithZodOptions | undefined, Ctx extends object = AnyContext, BuilderMiddleware extends MiddlewareInput = undefined, RouteMiddleware extends MiddlewareInput = undefined> = Omit>, 'handler' | 'schema' | 'middleware'> & ZodHandlerOptions> & { middleware?: RouteMiddleware; }; /** * Zod route builder created by [`createZodRouteBuilder`]{@link createZodRouteBuilder}. * * @example * ```ts * const route = createZodRouteBuilder() * * router.get('/users/:id', route({ * schema: { * request: { * path: z.object({id: z.string()}), * }, * }, * handler: ({params}) => ({id: params.path.id}), * })) * * router.add(route({ * method: HttpMethod.GET, * path: '/health', * handler: () => ({ok: true}), * })) * ``` */ type ZodRouteBuilder = undefined> = { /** * Build a full route definition that includes its own path. * * @param options - Full route options including `path`. * @returns A full route definition compatible with [`Router.add`]{@link Router#add}. */ | undefined, RouteMiddleware extends MiddlewareInput = undefined>(options: ZodRouteOptions): Route, ZodRouteContext>; /** * Build method-specific route options that leave the path to the registering router. * * @param options - Method route options without a route path. * @returns Route options compatible with helpers like [`Router.get`]{@link Router#get}. */ | undefined, RouteMiddleware extends MiddlewareInput = undefined>(options: WithZodOptions): RouteOptions, ZodRouteContext>; }; /** * Options for [`defineZodMiddleware`]{@link defineZodMiddleware}. * * @typeParam AddedCtx - Context made available to downstream handlers. * @typeParam Ctx - Context required by the middleware. * @typeParam Responses - Status-keyed Zod schemas for locally originated responses. */ type DefineZodMiddlewareOptions = { responses: Responses; run: DefineMiddlewareOptions>['run']; }; /** * Create response-declaring middleware backed by Zod response schemas. * * @example * ```ts * const requireAuth = defineZodMiddleware({ * responses: { 401: z.object({ message: z.string() }) }, * run: (_ctx, { respond }) => respond(response({ message: 'Sign in' }, { status: 401 })), * }) * ``` * * @param options - Locally originated response schemas and middleware implementation. * @returns Declared middleware with inferred, runtime-validated terminal responses. * @typeParam AddedCtx - Context made available to downstream handlers. * @typeParam Ctx - Context required by the middleware. * @typeParam Responses - Status-keyed Zod schemas for locally originated responses. */ declare function defineZodMiddleware(options: DefineZodMiddlewareOptions): DeclaredMiddleware; /** * Options for [`zodSchemaMiddleware`]{@link zodSchemaMiddleware}. * * @typeParam Schema - Zod request and downstream response schema declaration. */ type ZodSchemaMiddlewareBaseOptions | undefined> = { schema?: Schema; validateResponse?: ResponseValidationOption; }; /** * Options for a Zod request/response schema boundary. * * A custom request-validation callback must declare the response schemas it can originate. * * @typeParam Schema - Zod request and downstream response schema declaration. * @typeParam ValidationResponses - Schemas owned by a custom validation-error callback. */ type ZodSchemaMiddlewareOptions | undefined, ValidationResponses extends AnyZodResponseBodySchemas | undefined = undefined> = ZodSchemaMiddlewareBaseOptions & ([ValidationResponses] extends [undefined] ? { onRequestValidationError?: undefined; validationResponses?: undefined; } : { onRequestValidationError: ValidationErrorHandler>; validationResponses: ValidationResponses; }); /** * Create Zod middleware that parses request inputs and validates downstream responses. * * @example * ```ts * const parseUserId = zodSchemaMiddleware({ * schema: { request: { path: z.object({ id: z.string() }) } }, * }) * ``` * * @param options - Request, response, and validation-error schema behavior. * @returns Declared middleware exposing parsed request values to downstream handlers. * @typeParam Schema - Zod request and downstream response schema declaration. * @typeParam Ctx - Context required before this middleware executes. */ declare function zodSchemaMiddleware | undefined, const ValidationResponses extends AnyZodResponseBodySchemas | undefined = undefined, Ctx extends object = AnyContext>(options: ZodSchemaMiddlewareOptions): DeclaredMiddleware, Ctx>; /** * Create a Zod route builder with shared defaults. * * @example * ```ts * const route = createZodRouteBuilder({ * validateResponse: false, * schema: { * response: { * body: { * 400: z.object({message: z.string()}), * }, * }, * }, * }) * * router.post('/users/:id', route({ * name: 'user.update', * schema: { * request: { * path: z.object({id: z.string()}), * }, * }, * handler: ({params}) => ({id: params.path.id}), * })) * ``` * * @param defaults - Default schema fragments, response validation, and request validation error handling. * @returns A route builder compatible with method-specific router helpers and full route definitions. */ declare function createZodRouteBuilder, BuilderCtx extends object = ContextFromMiddlewareInput>(defaults: ZodRouteHelperDefaults & { middleware: BuilderMiddleware; }): ZodRouteBuilder; declare function createZodRouteBuilder = undefined>(defaults?: ZodRouteHelperDefaults): ZodRouteBuilder; //#endregion export { type AddedContextFromMiddlewareInput, type ContextFromMiddlewareInput, type DefineValibotMiddlewareOptions, type DefineZodMiddlewareOptions, type MiddlewareEntry, type Route, type RouteMatch, type RouteMeta, type RouteOptions, type RouteSchema, type ValibotHandlerContext, type ValibotHandlerParams, type ValibotRouteBuilder, type ValibotRouteHandler, type ValibotRouteHelperDefaults, type ValibotRouteSchemaInput, type ValibotSchemaMiddlewareOptions, ValibotValidationError, type ValibotValidationErrorBody, type ValibotValidationErrorHandler, ValidationError, type ValidationErrorHandler, type ZodHandlerContext, type ZodHandlerParams, type ZodRouteBuilder, type ZodRouteHandler, type ZodRouteHelperDefaults, type ZodRouteSchemaInput, type ZodSchemaMiddlewareOptions, type ZodValidationErrorBody, createValibotRouteBuilder, createZodRouteBuilder, defineValibotMiddleware, defineZodMiddleware, valibotSchemaMiddleware, zodSchemaMiddleware };