import type { QueryApiMiddleware, QueryApiRequestContext } from './middleware.js'; /** A single schema violation, flattened so consumers never touch zod's types. */ export type ResponseValidationIssue = { /** Dot-joined path to the offending value, `''` at the root. */ path: string; message: string; }; /** Thrown when a response body does not match its OpenAPI component schema. */ export declare class ZodResponseValidationError extends Error { readonly name = "ZodResponseValidationError"; readonly method: string; readonly path: string; /** The `components.schemas` name the body was validated against. */ readonly schemaName: string; readonly issues: readonly ResponseValidationIssue[]; constructor(init: { method: string; path: string; schemaName: string; issues: readonly ResponseValidationIssue[]; cause?: unknown; }); } /** * Narrows a caught value to {@link ZodResponseValidationError}. * * Matches on `name` rather than `instanceof` for the same reason * `isHttpRequestError` does: a consumer can end up with two copies of this * package in its module graph, and an error thrown by one is not `instanceof` * the class the other closed over. */ export declare function isZodResponseValidationError(value: unknown): value is ZodResponseValidationError; /** * How to find the component schema for an operation: either a lookup table * keyed `${method} ${path}` (`'get /users/{id}'`), or a function for specs * whose naming is derivable. */ export type ResponseSchemaSource = Readonly> | ((ctx: QueryApiRequestContext) => string | undefined); export type ZodResponseMiddlewareOptions = { /** The parsed OpenAPI document the `TPaths` types were generated from. */ document: unknown; schemas: ResponseSchemaSource; /** * Called instead of throwing when a body fails validation. Use it to report * drift without breaking the screen; the unmodified body is passed through. */ onInvalid?: (error: ZodResponseValidationError) => void; }; /** * Validates response bodies against the OpenAPI document at runtime, reusing * `getComponentSchemaFromOpenApi` from http-client-core so the schema and the * `TPaths` types come from the same spec. * * The validated body is passed through **unmodified** — the middleware never * substitutes zod's parse output, so the runtime value always matches the * statically inferred one and no coercion happens behind the caller's back. * * Compiled schemas are memoized per middleware instance; * `z.fromJSONSchema` is far too expensive to run per request. */ export declare function createZodResponseMiddleware(options: ZodResponseMiddlewareOptions): QueryApiMiddleware;