openapi-fetch
Advanced tools
Comparing version 0.11.0 to 0.11.1
# openapi-fetch | ||
## 0.11.1 | ||
### Patch Changes | ||
- [#1831](https://github.com/openapi-ts/openapi-typescript/pull/1831) [`091e71a`](https://github.com/openapi-ts/openapi-typescript/commit/091e71ad4bf805be32261a53524f320c2fa42690) Thanks [@SebastienGllmt](https://github.com/SebastienGllmt)! - Add MethodResponse utility type to easily get the return type of an endpoint on a client | ||
- [#1833](https://github.com/openapi-ts/openapi-typescript/pull/1833) [`cec023d`](https://github.com/openapi-ts/openapi-typescript/commit/cec023d3461c79ca355a88366949d0f6382e4e2a) Thanks [@ngraef](https://github.com/ngraef)! - Fix identification of required properties when `strictNullChecks` is disabled | ||
- Updated dependencies [[`cec023d`](https://github.com/openapi-ts/openapi-typescript/commit/cec023d3461c79ca355a88366949d0f6382e4e2a)]: | ||
- openapi-typescript-helpers@0.0.12 | ||
## 0.11.0 | ||
@@ -4,0 +15,0 @@ |
import type { | ||
ErrorResponse, | ||
FilterKeys, | ||
HasRequiredKeys, | ||
HttpMethod, | ||
IsOperationRequestBodyOptional, | ||
MediaType, | ||
@@ -10,2 +10,3 @@ OperationRequestBodyContent, | ||
ResponseObjectMap, | ||
RequiredKeysOf, | ||
SuccessResponse, | ||
@@ -86,3 +87,3 @@ } from "openapi-typescript-helpers"; | ||
} | ||
? HasRequiredKeys<T["parameters"]> extends never | ||
? RequiredKeysOf<T["parameters"]> extends never | ||
? { params?: T["parameters"] } | ||
@@ -94,3 +95,3 @@ : { params: T["parameters"] } | ||
? { body?: never } | ||
: undefined extends OperationRequestBodyContent<T> | ||
: IsOperationRequestBodyOptional<T> extends true | ||
? { body?: OperationRequestBodyContent<T> } | ||
@@ -156,3 +157,3 @@ : { body: OperationRequestBodyContent<T> }; | ||
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */ | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = HasRequiredKeys< | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = RequiredKeysOf< | ||
FetchOptions<FilterKeys<Params, Location>> | ||
@@ -166,4 +167,4 @@ > extends never | ||
// - Performs arbitrary [key: string] addition. | ||
// Note: the addition It MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = HasRequiredKeys<Init> extends never | ||
// Note: the addition MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = RequiredKeysOf<Init> extends never | ||
? [(Init & { [key: string]: unknown })?] | ||
@@ -210,2 +211,16 @@ : [Init & { [key: string]: unknown }]; | ||
export type ClientPathsWithMethod< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
> = CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method> : never; | ||
export type MethodResponse< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
Path extends ClientPathsWithMethod<CreatedClient, Method>, | ||
Options = {}, | ||
> = CreatedClient extends Client<infer Paths extends { [key: string]: any }, infer Media extends MediaType> | ||
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]> | ||
: never; | ||
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>( | ||
@@ -212,0 +227,0 @@ clientOptions?: ClientOptions, |
import type { | ||
ErrorResponse, | ||
FilterKeys, | ||
HasRequiredKeys, | ||
HttpMethod, | ||
IsOperationRequestBodyOptional, | ||
MediaType, | ||
@@ -10,2 +10,3 @@ OperationRequestBodyContent, | ||
ResponseObjectMap, | ||
RequiredKeysOf, | ||
SuccessResponse, | ||
@@ -86,3 +87,3 @@ } from "openapi-typescript-helpers"; | ||
} | ||
? HasRequiredKeys<T["parameters"]> extends never | ||
? RequiredKeysOf<T["parameters"]> extends never | ||
? { params?: T["parameters"] } | ||
@@ -94,3 +95,3 @@ : { params: T["parameters"] } | ||
? { body?: never } | ||
: undefined extends OperationRequestBodyContent<T> | ||
: IsOperationRequestBodyOptional<T> extends true | ||
? { body?: OperationRequestBodyContent<T> } | ||
@@ -156,3 +157,3 @@ : { body: OperationRequestBodyContent<T> }; | ||
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */ | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = HasRequiredKeys< | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = RequiredKeysOf< | ||
FetchOptions<FilterKeys<Params, Location>> | ||
@@ -166,4 +167,4 @@ > extends never | ||
// - Performs arbitrary [key: string] addition. | ||
// Note: the addition It MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = HasRequiredKeys<Init> extends never | ||
// Note: the addition MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = RequiredKeysOf<Init> extends never | ||
? [(Init & { [key: string]: unknown })?] | ||
@@ -210,2 +211,16 @@ : [Init & { [key: string]: unknown }]; | ||
export type ClientPathsWithMethod< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
> = CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method> : never; | ||
export type MethodResponse< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
Path extends ClientPathsWithMethod<CreatedClient, Method>, | ||
Options = {}, | ||
> = CreatedClient extends Client<infer Paths extends { [key: string]: any }, infer Media extends MediaType> | ||
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]> | ||
: never; | ||
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>( | ||
@@ -212,0 +227,0 @@ clientOptions?: ClientOptions, |
{ | ||
"name": "openapi-fetch", | ||
"description": "Fast, type-safe fetch client for your OpenAPI schema. Only 5 kb (min). Works with React, Vue, Svelte, or vanilla JS.", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"author": { | ||
@@ -50,3 +50,3 @@ "name": "Drew Powers", | ||
"dependencies": { | ||
"openapi-typescript-helpers": "^0.0.11" | ||
"openapi-typescript-helpers": "^0.0.12" | ||
}, | ||
@@ -79,2 +79,3 @@ "devDependencies": { | ||
"test:ts": "tsc --noEmit", | ||
"test:ts-no-strict": "tsc --noEmit -p test/no-strict-null-checks/tsconfig.json", | ||
"test-e2e": "playwright test", | ||
@@ -81,0 +82,0 @@ "e2e-vite-build": "vite build test/fixtures/e2e", |
import type { | ||
ErrorResponse, | ||
FilterKeys, | ||
HasRequiredKeys, | ||
HttpMethod, | ||
IsOperationRequestBodyOptional, | ||
MediaType, | ||
@@ -10,2 +10,3 @@ OperationRequestBodyContent, | ||
ResponseObjectMap, | ||
RequiredKeysOf, | ||
SuccessResponse, | ||
@@ -86,3 +87,3 @@ } from "openapi-typescript-helpers"; | ||
} | ||
? HasRequiredKeys<T["parameters"]> extends never | ||
? RequiredKeysOf<T["parameters"]> extends never | ||
? { params?: T["parameters"] } | ||
@@ -94,3 +95,3 @@ : { params: T["parameters"] } | ||
? { body?: never } | ||
: undefined extends OperationRequestBodyContent<T> | ||
: IsOperationRequestBodyOptional<T> extends true | ||
? { body?: OperationRequestBodyContent<T> } | ||
@@ -156,3 +157,3 @@ : { body: OperationRequestBodyContent<T> }; | ||
/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */ | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = HasRequiredKeys< | ||
export type MaybeOptionalInit<Params extends Record<HttpMethod, {}>, Location extends keyof Params> = RequiredKeysOf< | ||
FetchOptions<FilterKeys<Params, Location>> | ||
@@ -166,4 +167,4 @@ > extends never | ||
// - Performs arbitrary [key: string] addition. | ||
// Note: the addition It MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = HasRequiredKeys<Init> extends never | ||
// Note: the addition MUST happen after all the inference happens (otherwise TS can’t infer if init is required or not). | ||
type InitParam<Init> = RequiredKeysOf<Init> extends never | ||
? [(Init & { [key: string]: unknown })?] | ||
@@ -210,2 +211,16 @@ : [Init & { [key: string]: unknown }]; | ||
export type ClientPathsWithMethod< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
> = CreatedClient extends Client<infer Paths, infer _Media> ? PathsWithMethod<Paths, Method> : never; | ||
export type MethodResponse< | ||
CreatedClient extends Client<any, any>, | ||
Method extends HttpMethod, | ||
Path extends ClientPathsWithMethod<CreatedClient, Method>, | ||
Options = {}, | ||
> = CreatedClient extends Client<infer Paths extends { [key: string]: any }, infer Media extends MediaType> | ||
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]> | ||
: never; | ||
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>( | ||
@@ -212,0 +227,0 @@ clientOptions?: ClientOptions, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130143
2332
+ Addedopenapi-typescript-helpers@0.0.12(transitive)
- Removedopenapi-typescript-helpers@0.0.11(transitive)