import type { BaseSchema, Infer } from "anyvali"; import type { RawRouteHandler, RouteHandlerContext, RouteHandler } from "../contracts/route.js"; /** * Schema configuration for a route handler. * `response` is required; `params`, `query`, `headers`, and `request` are optional. */ export interface HandlerSchemas, TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TParamsSchema extends BaseSchema | undefined = undefined> { readonly response: TResponse; readonly params?: TParamsSchema; readonly query?: TQuery; readonly headers?: THeaders; readonly request?: TRequest; } /** Resolve a schema to its inferred output type, or fall back to a default. */ type SchemaOutput | undefined, TDefault> = T extends BaseSchema ? Infer : TDefault; /** Fully-typed handler context derived from schema configuration. */ type TypedHandlerContext, any, any, any, any>, TParams = Record, TPlugin = unknown, TServiceConfig = Record> = RouteHandlerContext, SchemaOutput>, SchemaOutput>, SchemaOutput>, TPlugin, TServiceConfig>; /** * Create a type-safe route handler with framework-enforced validation. * * - TypeScript enforces the return type matches `Infer` at compile time. * - At runtime, the response is validated through `schemas.response.parse()` as a safety net. * - The handler's `ctx` is fully typed from the provided schemas - no manual `.parse()` needed. * * @example * ```ts * export const handleGet = createHandler( * { response: ResponseSchema, query: QuerySchema }, * (ctx) => ({ * greeting: `Hello, ${ctx.query.name}`, * themeHint: "bootstrap1", * supports: ["application/json", "text/html"] * }) * ); * ``` */ export declare function createHandler, TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TParams = Record, TPlugin = unknown, TServiceConfig = Record, TParamsSchema extends BaseSchema | undefined = undefined>(schemas: HandlerSchemas, handler: (ctx: TypedHandlerContext, TParams, TPlugin, TServiceConfig>) => Infer | Promise>): RouteHandler, SchemaOutput>, SchemaOutput>, SchemaOutput>, Infer, TPlugin, TServiceConfig>; export declare namespace createHandler { function forContext>(): , TQuery extends BaseSchema | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TParams = Record, TParamsSchema extends BaseSchema | undefined = undefined>(schemas: HandlerSchemas, handler: (ctx: TypedHandlerContext, TParams, TPlugin, TServiceConfig>) => Infer | Promise>) => RouteHandler, SchemaOutput>, SchemaOutput>, SchemaOutput>, Infer, TPlugin, TServiceConfig>; } export type RawHandlerSchemas | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TMultipart extends BaseSchema | undefined = undefined, TParamsSchema extends BaseSchema | undefined = undefined> = { readonly params?: TParamsSchema; readonly query?: TQuery; readonly headers?: THeaders; readonly request?: TRequest; readonly multipart?: TMultipart; }; export declare function createRawHandler | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TMultipart extends BaseSchema | undefined = undefined, TParams = Record, TPlugin = unknown, TServiceConfig = Record, TParamsSchema extends BaseSchema | undefined = undefined>(_schemas: RawHandlerSchemas, handler: (ctx: RouteHandlerContext, SchemaOutput>, SchemaOutput>, SchemaOutput>, TPlugin, TServiceConfig> & { readonly multipart: SchemaOutput; }) => Response | Promise): RawRouteHandler, SchemaOutput>, SchemaOutput>, SchemaOutput>, TPlugin, TServiceConfig>; export declare namespace createRawHandler { function forContext>(): | undefined = undefined, THeaders extends BaseSchema | undefined = undefined, TRequest extends BaseSchema | undefined = undefined, TMultipart extends BaseSchema | undefined = undefined, TParams = Record, TParamsSchema extends BaseSchema | undefined = undefined>(schemas: RawHandlerSchemas, handler: (ctx: RouteHandlerContext, SchemaOutput>, SchemaOutput>, SchemaOutput>, TPlugin, TServiceConfig> & { readonly multipart: SchemaOutput; }) => Response | Promise) => RawRouteHandler, SchemaOutput>, SchemaOutput>, SchemaOutput>, TPlugin, TServiceConfig>; } export {}; //# sourceMappingURL=handler.d.ts.map