import type { FetchResponse, MaybeOptionalInit } from "openapi-fetch"; import type { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf, } from "openapi-typescript-helpers"; import type { SWRConfiguration, SWRResponse } from "swr"; type MaybeRequired = RequiredKeysOf extends never ? T | undefined : T; type TryKey = T extends { [Key in K]?: unknown } ? T[K] : undefined; /** * Provides specific types used within a given request */ export type TypesForRequest< Paths extends Record, Method extends Extract, Path extends PathsWithMethod, // --- Init = MaybeOptionalInit, Params = Init extends { params?: unknown } ? Init["params"] : undefined, Res = FetchResponse, Data = Extract["data"], Error = Extract["error"], PathParams = TryKey, Query = TryKey, Headers = TryKey, Cookies = TryKey, SWRConfig = SWRConfiguration, > = { Init: Init; Data: Data; Error: Error; Path: MaybeRequired; Query: MaybeRequired; Headers: MaybeRequired; Cookies: Cookies; SWRConfig: SWRConfig; SWRResponse: SWRResponse; }; /** * Provides specific types for GET requests * * Uses {@link TypesForRequest} */ export type TypesForGetRequest< Paths extends Record, Path extends PathsWithMethod>, > = TypesForRequest, Path>;