import type { AsyncResponseResolverReturnType, HttpResponseResolver } from "msw"; import type { AnyApiSpec, HttpMethod, PathParams, QueryParams, RequestBody, RequestMap, ResponseBody, ResponseMap } from "./api-spec.ts"; import { QueryParams as QueryParamsUtil } from "./query-params.ts"; import type { OpenApiRequest } from "./request.ts"; import { type OpenApiResponse } from "./response.ts"; /** Response resolver that gets provided to HTTP handler factories. */ export type ResponseResolver = (info: ResponseResolverInfo) => AsyncResponseResolverReturnType>; /** Response resolver info that extends MSW's resolver info with additional functionality. */ export interface ResponseResolverInfo extends MSWResponseResolverInfo { /** Standard request with enhanced typing for body methods based on the given OpenAPI spec. */ request: OpenApiRequest>; /** * Type-safe wrapper around {@link URLSearchParams} that implements methods for * reading query parameters. * * **Example** * ```typescript * const handler = http.get("/query-example", ({ query }) => { * const filter = query.get("filter"); * const sortBy = query.getAll("sortBy"); * * if (query.has("sort", "asc")) { ... } * * return HttpResponse.json({ ... }); * }); * ``` */ query: QueryParamsUtil>; /** * A type-safe response helper that narrows allowed status codes and content types * based on the given OpenAPI spec. The response body is further narrowed to * the match the selected status code and content type. * * If a wildcard status code is chosen, a specific status code for the response * must be provided in the {@linkcode ResponseInit} argument. All status codes * allowed by the wildcard are inferred. * * A fallback for returning any response without casting is provided * through `response.untyped(...)`. * * **Example** * ```typescript * const handler = http.get("/response-example", ({ response }) => { * return response(200).json({ id: 123 }); * }); * * const empty = http.get("/response-example", ({ response }) => { * return response(204).empty(); * }); * * const wildcard = http.get("/response-example", ({ response }) => { * return response("5XX").text("Unexpected Error", { status: 501 }); * }); * * const fallback = http.get("/response-example", ({ response }) => { * return response.untyped(new Response("Hello")); * }); * ``` */ response: OpenApiResponse, ResponseBody>; } /** Wraps MSW's resolver function to provide additional info to a given resolver. */ export declare function createResolverWrapper(resolver: ResponseResolver): MSWResponseResolver; /** MSW response resolver info that is made type-safe through an api spec. */ type MSWResponseResolverInfo = Parameters>[0]; /** MSW response resolver function that is made type-safe through an api spec. */ export type MSWResponseResolver = HttpResponseResolver, RequestBody, ResponseBody>; export {}; //# sourceMappingURL=response-resolver.d.ts.map