import type { Schema } from "../../extensions/schema/index.js"; import { type RequestLimits, type ValidatedData } from "./types.js"; /** Configuration for `createValidatedHandler()`. */ export interface ValidatedHandlerConfig { body?: Schema; query?: Schema; limits?: RequestLimits; } /** Handler signature that receives validated request data. */ export type ValidatedHandlerFunction = (request: Request, validated: ValidatedData) => Promise | Response; /** * Resolve the underlying `Request` a validated handler must read. * * The App Router invokes handlers with a real `Request`, but the Pages Router * invokes them with the `APIContext` it builds (see `routing/api/route-executor.ts`), * whose `.body` is a reader *function* rather than a `ReadableStream`. Reading * that context as if it were a `Request` threw * `request.body?.getReader is not a function` before validation could run, so * no POST body could ever be validated (issue #3666). Accept either shape and * hand the real `Request` to the body/limit machinery and to the handler. */ /** * Unwrap the live `Request` from whatever a router handed the handler. * * The app router passes a real `Request`; the pages executor passes its * `APIContext`, which exposes the request as `.request` / `.req` and whose * `body` is a reader *function*. A handler that assumes a `Request` therefore * sails past `if (!request.body)` — a function is truthy — and throws on * `request.body.getReader()`. * * @internal shared with the upload handlers, which take the same shape. */ export declare function resolveValidatedRequest(candidate: Request): Request; /** * Create a validated API handler with bounded body/query validation. * Bodies without a schema are preflighted through a clone, leaving the * original request body available to the handler after its size is verified. */ export declare function createValidatedHandler(config: ValidatedHandlerConfig, handler: ValidatedHandlerFunction): (request: Request) => Promise; //# sourceMappingURL=handler.d.ts.map