import { S as Strip, A as AnyCtx, a as AnyMeta, b as Awaitable } from './util-CHs1TI3T.js'; import { Parser, Infer, InferIn } from 'schema-shift'; import { Typify, TypeKey, TypeOf } from './util.js'; import { Midwinter, AnyCtx as AnyCtx$1, AnyMeta as AnyMeta$1 } from 'midwinter'; import { d as EndMiddleware } from './types-xEg9liKj.js'; type ValidSchemaOpts = { Query?: Parser; Params?: Parser; Body?: Parser; Headers?: Parser; Output?: Parser; }; type ValidSchemaCtx = { params: unknown extends T["Params"] ? Default["Params"] : Infer; query: unknown extends T["Query"] ? Default["Query"] : Infer; body: unknown extends T["Body"] ? Default["Body"] : Infer; headers: unknown extends T["Headers"] ? Default["Headers"] : Infer; }; type ValidLazySchemaCtx = { parse: ParseInputsFn>; }; type ValidSchemaMeta = T & Typify; } & { [Key in keyof T & string as `${Key}_In`]: InferIn; }, [ never, never ]>>; type ValidTypeOpts = { Query?: Record; Params?: Record; Headers?: Record; Body?: unknown; Output?: unknown; }; type ValidTypeCtx = { params: unknown extends T["Params"] ? Default["Params"] : T["Params"]; query: unknown extends T["Query"] ? Default["Query"] : T["Query"]; body: unknown extends T["Body"] ? Default["Body"] : T["Body"]; headers: unknown extends T["Headers"] ? Default["Headers"] : T["Headers"]; }; type ValidLazyTypeCtx = { parse: ParseInputsFn>; }; type ValidTypeMeta = Typify>; type Default = { Params: Record; Query: Record; Body: unknown; Headers: Record; }; type OutputHandler = (request: Request, ctx: TCtx, meta: Readonly) => Awaitable; type InputTypeKey = "params" | "query" | "body" | "headers"; interface ParseInputsFn> { /** Parses the selected input part */ (key: TKey): Promise; /** Parses all inputs and returns as an object */ (): Promise; } type InferMetaOutputIn = TMeta[TypeKey<"Output_In">] extends TypeOf ? Inner : any; type ParseQueryStringFn = (url: URL) => Record; type ParseOpts = ValidSchemaOpts & { path?: string; parseQueryString?: ParseQueryStringFn; }; type ParserFn = (req: Request, opts: ParseOpts) => T; declare const parseQuery: (req: Request, opts: ParseOpts) => any; declare const parseParams: (req: Request, opts: ParseOpts) => any; declare const parseBody: (_req: Request, opts: ParseOpts) => Promise; declare const parseHeaders: (req: Request, opts: ParseOpts) => any; declare const getCachedParsers: (req: Request, opts: ParseOpts) => { query: () => Promise; params: () => Promise; headers: () => Promise; body: () => Promise>; }; declare const makeParseFn: (req: Request, opts: T) => ParseInputsFn>; interface ValidationOpts { parseQueryString?: ParseQueryStringFn; } interface ValidationPlugin { /** * Add synchronous parsing and validation, resulting in the * query, params, body and headers being added to the ctx. */ valid(): Midwinter, ValidTypeMeta>; valid(opts: T): Midwinter, ValidSchemaMeta>; validLazy(): Midwinter, ValidTypeMeta>; /** Add lazy validation that can be triggered via the `ctx.parse()` function */ validLazy(opts: T): Midwinter, ValidSchemaMeta>; /** * Parses the response type according to the valid.Output field and packages * within a Response object. * * If no `Output` schema was provided, the result JSON.stringified without any validation. */ output = InferMetaOutputIn>(handler: OutputHandler, opts?: ResponseInit): EndMiddleware ] extends [never] ? {} : ValidTypeMeta<{ Output: TValue; }>, TMeta>; } declare const init: (opts?: ValidationOpts) => ValidationPlugin; export { type Default, type InferMetaOutputIn, type InputTypeKey, type OutputHandler, type ParseInputsFn, type ParseOpts, type ParseQueryStringFn, type ParserFn, type ValidLazySchemaCtx, type ValidLazyTypeCtx, type ValidSchemaCtx, type ValidSchemaMeta, type ValidSchemaOpts, type ValidTypeCtx, type ValidTypeMeta, type ValidTypeOpts, type ValidationOpts, type ValidationPlugin, getCachedParsers, init, makeParseFn, parseBody, parseHeaders, parseParams, parseQuery };