import type { ConvertToStringified, MapToValues, ResolvedObjectUnion } from "./type-utils.ts"; /** Base type that any api spec should extend. */ export type AnyApiSpec = NonNullable; /** Intersection of HTTP methods that are supported by both OpenAPI-TS and MSW. */ export type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch"; /** Returns a union of all paths that exists in an api spec for a given method. */ export type PathsForMethod = { [Path in keyof ApiSpec]: ApiSpec[Path] extends Record ? Path : never; }[keyof ApiSpec]; /** Extract the path params of a given path and method from an api spec. */ export type PathParams = Method extends keyof ApiSpec[Path] ? ApiSpec[Path][Method] extends { parameters: { path: any; }; } ? ConvertToStringified : never : never; /** Extract the query params of a given path and method from an api spec. */ export type QueryParams = Method extends keyof ApiSpec[Path] ? ApiSpec[Path][Method] extends { parameters: { query?: any; }; } ? ConvertToStringified["query"]>> : never : never; /** Ensures that query params are not usable in case no query params are specified (never). */ type StrictQueryParams = [Params] extends [never] ? NonNullable : Params; /** * Extract a request map for a given path and method from an api spec. * A request map has the shape of (media-type -> body). */ export type RequestMap = Method extends keyof ApiSpec[Path] ? ApiSpec[Path][Method] extends { requestBody?: any; } ? undefined extends ApiSpec[Path][Method]["requestBody"] ? Partial["content"]> : ApiSpec[Path][Method]["requestBody"]["content"] : never : never; /** Extract the request body of a given path and method from an api spec. */ export type RequestBody = MapToValues>; /** * Extract a response map for a given path and method from an api spec. * A response map has the shape of (status -> media-type -> body). */ export type ResponseMap = Method extends keyof ApiSpec[Path] ? ApiSpec[Path][Method] extends { responses: any; } ? { [Status in keyof ApiSpec[Path][Method]["responses"]]: ConvertContent["content"]; } : never : never; /** Extract the response body of a given path and method from an api spec. */ export type ResponseBody = MapToValues>>>; /** * OpenAPI-TS generates "no content" with `content?: never`. * However, `new Response().body` is `null` and strictly typing no-content in * MSW requires `null`. Therefore, this helper ensures that "no-content" * can be mapped to null when typing the response body. */ type ConvertContent = Required extends { content: never; } ? { content: { "no-content": null; }; } : Content extends { content: any; } ? Content : never; export {}; //# sourceMappingURL=api-spec.d.ts.map