openapi-typesafe-helpers 1.0.0-rc.2 → 1.0.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,169 @@
1
+ # openapi-typesafe-helpers
2
+
3
+ This package is a fork of `openapi-typescript-helpers`. The entries above `0.1.0` are releases of openapi-typesafe-helpers; `0.1.0` and the entries below it are the upstream history up to the fork point (upstream commit `d46a319a`), with `openapi-typescript-helpers` versions.
4
+
5
+ ## 1.0.0-rc.4
6
+
7
+ ### Patch Changes
8
+
9
+ - [#48](https://github.com/openapi-typesafe/openapi-typesafe/pull/48) [`cff72cd`](https://github.com/openapi-typesafe/openapi-typesafe/commit/cff72cd19bf7a68429f302e0ece79304fcb6ba5c) Thanks [@fedorello](https://github.com/fedorello)! - A call with a union of paths (`client.GET(path)` with `path: "/a" | "/b"`) types `data` and
10
+ `error` as the union of each operation's types. In openapi-fetch a path without a response body
11
+ typed `data` as its content map, and a path with only a `default` response typed it `undefined`.
12
+ `SuccessResponse` and `ErrorResponse` of a union of response maps are the union of each map's
13
+ responses.
14
+ - Updated dependencies [[`bc4d41d`](https://github.com/openapi-typesafe/openapi-typesafe/commit/bc4d41d870d13fdb5eb1303744e5235308cdc2bb), [`1c8af0d`](https://github.com/openapi-typesafe/openapi-typesafe/commit/1c8af0dc371ae8be5b595b055ee1ebc53916088f), [`2afc816`](https://github.com/openapi-typesafe/openapi-typesafe/commit/2afc816881dab23d3dd8fe4d1a2d20456dd917f8), [`cff72cd`](https://github.com/openapi-typesafe/openapi-typesafe/commit/cff72cd19bf7a68429f302e0ece79304fcb6ba5c), [`bc4d41d`](https://github.com/openapi-typesafe/openapi-typesafe/commit/bc4d41d870d13fdb5eb1303744e5235308cdc2bb), [`1c8af0d`](https://github.com/openapi-typesafe/openapi-typesafe/commit/1c8af0dc371ae8be5b595b055ee1ebc53916088f), [`cff72cd`](https://github.com/openapi-typesafe/openapi-typesafe/commit/cff72cd19bf7a68429f302e0ece79304fcb6ba5c)]:
15
+ - openapi-typesafe-fetch@1.0.0-rc.4
16
+
17
+ ## 1.0.0-rc.3
18
+
19
+ No changes in this release.
20
+
21
+ ## 1.0.0-rc.2
22
+
23
+ ### Major Changes
24
+
25
+ - [#18](https://github.com/openapi-typesafe/openapi-typesafe/pull/18) [`bfd3e60`](https://github.com/openapi-typesafe/openapi-typesafe/commit/bfd3e605bdbe240d7a8a327a59d8924781016fbd) Thanks [@fedorello](https://github.com/fedorello)! - First stable release of openapi-typesafe-helpers, the successor of openapi-typescript-helpers
26
+ 0.1.0. From 1.0 the package follows semver.
27
+
28
+ Changes that can need work when you move from openapi-typescript-helpers 0.1.0:
29
+ - `engines.node` is `>=22`.
30
+ - `HttpMethod` includes `"query"`: a hand-written `Record<HttpMethod, …>` needs a `query` entry.
31
+
32
+ ### Patch Changes
33
+
34
+ - [#16](https://github.com/openapi-typesafe/openapi-typesafe/pull/16) [`cd79dbd`](https://github.com/openapi-typesafe/openapi-typesafe/commit/cd79dbd39d33dc913ec101a4c46560dff801da4e) Thanks [@fedorello](https://github.com/fedorello)! - The type declarations keep their JSDoc, so editors show descriptions and mark deprecated exports.
35
+
36
+ ## 1.0.0-rc.1
37
+
38
+ ### Patch Changes
39
+
40
+ - [#9](https://github.com/openapi-typesafe/openapi-typesafe/pull/9) [`14494f5`](https://github.com/openapi-typesafe/openapi-typesafe/commit/14494f5553575d15ad8f4d54f59ddabddb3a3e01) Thanks [@fedorello](https://github.com/fedorello)! - An operation that declares no 2XX response types `data` with its `default` response, which covers
41
+ every undeclared status, successes too. `data` was `never` (upstream [#1862](https://github.com/openapi-typesafe/openapi-typesafe/issues/1862)). `SuccessResponse`
42
+ follows the same rule. With a 2XX response declared, `default` still types only `error`.
43
+
44
+ - [#9](https://github.com/openapi-typesafe/openapi-typesafe/pull/9) [`14494f5`](https://github.com/openapi-typesafe/openapi-typesafe/commit/14494f5553575d15ad8f4d54f59ddabddb3a3e01) Thanks [@fedorello](https://github.com/fedorello)! - `Parameters<typeof $api.queryOptions>` (and of `useQuery`, `useSuspenseQuery` and the fetch
45
+ client's `request`) takes the arguments of every operation; its path was `never` (upstream [#2178](https://github.com/openapi-typesafe/openapi-typesafe/issues/2178)).
46
+ `PathsWithMethod<paths, HttpMethod>` is now every path that has some method; a known method or set
47
+ of methods still gives the paths that have each of them, as before. Code that is generic in the
48
+ paths, such as swr-openapi's hooks, compiles as with openapi-typescript's helpers. The init in those parameters is required when some operation
49
+ requires one (`IsInitOptional`), so a helper passes `{}` for a path that needs none. A single call
50
+ is checked as before, also with a union of paths or methods.
51
+ `ReturnType` of these generic functions stays `any`; the `queryOptions` docs show what to use.
52
+
53
+ ## 1.0.0-rc.0
54
+
55
+ ### Minor Changes
56
+
57
+ - [`551c058`](https://github.com/openapi-typesafe/openapi-typesafe/commit/551c05889d32eaf1d328111e5c4d167e0337e5a4) Thanks [@fedorello](https://github.com/fedorello)! - The OpenAPI 3.2 `QUERY` method: `HttpMethod` includes `"query"`, the fetch client has
58
+ `client.QUERY(url, { body })` (also through `request("query", …)` and the path-based client), and
59
+ the react-query hooks accept `"query"`. A `Record<HttpMethod, …>` written by hand needs a `query`
60
+ entry. The path-based client maps only HTTP method keys, so `parameters` no longer shows up as a
61
+ `PARAMETERS()` call that always failed.
62
+
63
+ ### Patch Changes
64
+
65
+ - [`e49344a`](https://github.com/openapi-typesafe/openapi-typesafe/commit/e49344a208fb3bb38cd86f62c1395f8f7ca950f6) Thanks [@fedorello](https://github.com/fedorello)! - Packages contain only their build output, sources for source maps, the CLI, and the README, license and changelog. Coverage reports, local logs and tool configs are no longer packed.
66
+
67
+ - [`63275f8`](https://github.com/openapi-typesafe/openapi-typesafe/commit/63275f86ff7ba855338f09f87fb9567c8ed91300) Thanks [@fedorello](https://github.com/fedorello)! - `Readable` and `Writable` keep function types as they are. Before, they mapped a `Blob` or a `Date`
68
+ in response data into an object whose methods could not be called, so `data.file.arrayBuffer()`
69
+ did not type check. The helper types that `--read-write-markers` writes into the output change the
70
+ same way. See ADR-014, decision 6.
71
+
72
+ - [`d5dcbb3`](https://github.com/openapi-typesafe/openapi-typesafe/commit/d5dcbb3f38e4d583334977c50db92461085d4a11) Thanks [@fedorello](https://github.com/fedorello)! - `Readable` and `Writable` keep the shape of types without markers: readonly arrays stay arrays, tuples stay tuples, branded primitives (`string & { __brand }`) stay as they are, `allOf` arrays keep the properties of every member (so unions narrow again), and an optional `null` property is no longer dropped from request bodies. The `--read-write-markers` output carries the same fixed helpers (ADR-014). Fixes upstream [#2615](https://github.com/openapi-typesafe/openapi-typesafe/issues/2615), [#2620](https://github.com/openapi-typesafe/openapi-typesafe/issues/2620), [#2632](https://github.com/openapi-typesafe/openapi-typesafe/issues/2632), [#2717](https://github.com/openapi-typesafe/openapi-typesafe/issues/2717), [#2765](https://github.com/openapi-typesafe/openapi-typesafe/issues/2765).
73
+
74
+ ## 0.1.0
75
+
76
+ ### Minor Changes
77
+
78
+ - [#2549](https://github.com/openapi-ts/openapi-typescript/pull/2549) [`a690e52`](https://github.com/openapi-ts/openapi-typescript/commit/a690e526b7693479bc2f2f002d71a020fa5e4e16) Thanks [@abumalick](https://github.com/abumalick)! - Add readOnly/writeOnly support via `--read-write-markers` flag. When enabled, readOnly properties are wrapped with `$Read<T>` and writeOnly properties with `$Write<T>`. openapi-fetch uses `Readable<T>` and `Writable<T>` helpers to exclude these properties from responses and request bodies respectively.
79
+
80
+ ## 0.0.15
81
+
82
+ ### Patch Changes
83
+
84
+ - [#1937](https://github.com/openapi-ts/openapi-typescript/pull/1937) [`06163a2`](https://github.com/openapi-ts/openapi-typescript/commit/06163a2030eaf8d0579f624d86481e1205aef396) Thanks [@DjordyKoert](https://github.com/DjordyKoert)! - client data & error now return a union of possible types
85
+
86
+ ## 0.0.14
87
+
88
+ ### Patch Changes
89
+
90
+ - [#1948](https://github.com/openapi-ts/openapi-typescript/pull/1948) [`abfad56`](https://github.com/openapi-ts/openapi-typescript/commit/abfad5659183f95f705598dc52ae2dfe7a18ec04) Thanks [@piousdeer](https://github.com/piousdeer)! - fix SuccessResponseJSON, ErrorResponseJSON and RequestBodyJSON helpers
91
+
92
+ ## 0.0.13
93
+
94
+ ### Patch Changes
95
+
96
+ - [#1871](https://github.com/openapi-ts/openapi-typescript/pull/1871) [`bd88568`](https://github.com/openapi-ts/openapi-typescript/commit/bd8856854eaaf213b96d04b9eb130db1695bb1f1) Thanks [@brunolca](https://github.com/brunolca)! - fix SuccessResponseJSON and ErrorResponseJSON helpers
97
+
98
+ ## 0.0.12
99
+
100
+ ### Patch Changes
101
+
102
+ - [#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
103
+
104
+ ## 0.0.11
105
+
106
+ ### Patch Changes
107
+
108
+ - [#1788](https://github.com/openapi-ts/openapi-typescript/pull/1788) [`bcc9222`](https://github.com/openapi-ts/openapi-typescript/commit/bcc92223c83ba074316e17534a173fee8da9cd41) Thanks [@yukukotani](https://github.com/yukukotani)! - keep index.d.cts in npm distribution
109
+
110
+ ## 0.0.10
111
+
112
+ ### Patch Changes
113
+
114
+ - [#1717](https://github.com/openapi-ts/openapi-typescript/pull/1717) [`335530c`](https://github.com/openapi-ts/openapi-typescript/commit/335530c4f8f966d0154f19504585c462f5f5a409) Thanks [@kerwanp](https://github.com/kerwanp)! - Ignore configuration files in published package
115
+
116
+ ## 0.0.9
117
+
118
+ ### Patch Changes
119
+
120
+ - Improved handling of `SuccessResponse<T>` and `ErrorResponse<T>`
121
+ - Changed handling of `ErrorResponse<T>` to produce one and only one error type (rather than an impossible union)
122
+
123
+ ## 0.0.8
124
+
125
+ ### Patch Changes
126
+
127
+ - [#1610](https://github.com/openapi-ts/openapi-typescript/pull/1610) [`cc8073b`](https://github.com/openapi-ts/openapi-typescript/commit/cc8073b3ee42e7aaa546a9c6a0553c300d8882de) Thanks [@illright](https://github.com/illright)! - Fix data/error discrimination when there are empty-body errors
128
+
129
+ - [#1559](https://github.com/openapi-ts/openapi-typescript/pull/1559) [`6fe2c85`](https://github.com/openapi-ts/openapi-typescript/commit/6fe2c856331e910b9c8376fc151d63028dcfba11) Thanks [@drwpow](https://github.com/drwpow)! - Simplify build
130
+
131
+ ## 0.0.7
132
+
133
+ ### Patch Changes
134
+
135
+ - [#1479](https://github.com/openapi-ts/openapi-typescript/pull/1479) [`c6d945b`](https://github.com/openapi-ts/openapi-typescript/commit/c6d945be717bb3999178fb3a77292e41e1b7ab80) Thanks [@darwish](https://github.com/darwish)! - Fixed build of openapi-typescript-helpers for CommonJS environments
136
+
137
+ ## 0.0.6
138
+
139
+ ### Patch Changes
140
+
141
+ - [#1458](https://github.com/openapi-ts/openapi-typescript/pull/1458) [`23517a2`](https://github.com/openapi-ts/openapi-typescript/commit/23517a2c2ab94d49085391130cd7d11f4da33cfb) Thanks [@drwpow](https://github.com/drwpow)! - Add RequestBodyJSON helper
142
+
143
+ ## 0.0.5
144
+
145
+ ### Patch Changes
146
+
147
+ - [#1456](https://github.com/openapi-ts/openapi-typescript/pull/1456) [`5be2082`](https://github.com/openapi-ts/openapi-typescript/commit/5be20827334c60e53222445561b9cfc526f4f6a9) Thanks [@drwpow](https://github.com/drwpow)! - Add SuccessResponseJSON, ErrorResponseJSON helpers
148
+
149
+ ## 0.0.4
150
+
151
+ ### Patch Changes
152
+
153
+ - [#1366](https://github.com/openapi-ts/openapi-typescript/pull/1366) [`04dbd6d`](https://github.com/openapi-ts/openapi-typescript/commit/04dbd6d84fffd1d88300421bae25e946f1c303da) Thanks [@drwpow](https://github.com/drwpow)! - Add HasRequiredKeys<T> helper
154
+
155
+ ## 0.0.3
156
+
157
+ ### Patch Changes
158
+
159
+ - [#1357](https://github.com/openapi-ts/openapi-typescript/pull/1357) [`996e51e`](https://github.com/openapi-ts/openapi-typescript/commit/996e51e9b475f4818af77301ed5c0ab458736cb9) Thanks [@muttonchop](https://github.com/muttonchop)! - adds 500-511 error status codes
160
+
161
+ ## 0.0.2
162
+
163
+ ### Patch Changes
164
+
165
+ - [#1326](https://github.com/openapi-ts/openapi-typescript/pull/1326) [`e63a345`](https://github.com/openapi-ts/openapi-typescript/commit/e63a34561c8137c4cfdef858a2272be32960ca4f) Thanks [@drwpow](https://github.com/drwpow)! - Fix type bug
166
+
167
+ ## 0.0.0
168
+
169
+ Initial release
package/README.md CHANGED
@@ -1,8 +1,15 @@
1
1
  # openapi-typesafe-helpers
2
2
 
3
- Type helpers shared by `openapi-typesafe-fetch` and `openapi-typesafe-react-query` (for example `PathsWithMethod`,
3
+ Type helpers for the types that openapi-typesafe generates (for example `PathsWithMethod`,
4
4
  `SuccessResponse`, `ErrorResponse`, `MediaType`). Types only; no runtime code.
5
5
 
6
+ `openapi-typesafe-fetch` declares the helper types in its `helpers` entry, and this package
7
+ re-exports them, so it depends on the client. The names of both packages are one declaration: a
8
+ value typed with one fits the other, also in generic code. A library built with
9
+ `declaration: true` under Yarn PnP that depends only on this package and exports an inferred type
10
+ that prints a helper type gets `import("openapi-typesafe-fetch/helpers")` in its declarations: add
11
+ `openapi-typesafe-fetch` to its dependencies, or annotate the type.
12
+
6
13
  A maintained successor to `openapi-typescript-helpers` (see the [repository README](../../README.md)).
7
14
  Most projects do not need to install it directly.
8
15
 
package/dist/index.d.cts CHANGED
@@ -1,290 +1 @@
1
- type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"
2
- /** OpenAPI 3.2: a safe, idempotent request with a body. */
3
- | "query";
4
- /** 2XX statuses */
5
- type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207 | "2XX";
6
- /** 4XX and 5XX statuses */
7
- type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | "5XX" | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | "4XX" | "default";
8
- /** Get a union of OK Statuses */
9
- type OKStatusUnion<T> = FilterKeys<T, OkStatus>;
10
- /** Get first error status, in order */
11
- type FirstErrorStatus<T> = T extends {
12
- 500: unknown;
13
- } ? T[500] : T extends {
14
- 501: unknown;
15
- } ? T[501] : T extends {
16
- 502: unknown;
17
- } ? T[502] : T extends {
18
- 503: unknown;
19
- } ? T[503] : T extends {
20
- 504: unknown;
21
- } ? T[504] : T extends {
22
- 505: unknown;
23
- } ? T[505] : T extends {
24
- 506: unknown;
25
- } ? T[506] : T extends {
26
- 507: unknown;
27
- } ? T[507] : T extends {
28
- 508: unknown;
29
- } ? T[508] : T extends {
30
- 510: unknown;
31
- } ? T[510] : T extends {
32
- 511: unknown;
33
- } ? T[511] : T extends {
34
- "5XX": unknown;
35
- } ? T["5XX"] : T extends {
36
- 400: unknown;
37
- } ? T[400] : T extends {
38
- 401: unknown;
39
- } ? T[401] : T extends {
40
- 402: unknown;
41
- } ? T[402] : T extends {
42
- 403: unknown;
43
- } ? T[403] : T extends {
44
- 404: unknown;
45
- } ? T[404] : T extends {
46
- 405: unknown;
47
- } ? T[405] : T extends {
48
- 406: unknown;
49
- } ? T[406] : T extends {
50
- 407: unknown;
51
- } ? T[407] : T extends {
52
- 408: unknown;
53
- } ? T[408] : T extends {
54
- 409: unknown;
55
- } ? T[409] : T extends {
56
- 410: unknown;
57
- } ? T[410] : T extends {
58
- 411: unknown;
59
- } ? T[411] : T extends {
60
- 412: unknown;
61
- } ? T[412] : T extends {
62
- 413: unknown;
63
- } ? T[413] : T extends {
64
- 414: unknown;
65
- } ? T[414] : T extends {
66
- 415: unknown;
67
- } ? T[415] : T extends {
68
- 416: unknown;
69
- } ? T[416] : T extends {
70
- 417: unknown;
71
- } ? T[417] : T extends {
72
- 418: unknown;
73
- } ? T[418] : T extends {
74
- 420: unknown;
75
- } ? T[420] : T extends {
76
- 421: unknown;
77
- } ? T[421] : T extends {
78
- 422: unknown;
79
- } ? T[422] : T extends {
80
- 423: unknown;
81
- } ? T[423] : T extends {
82
- 424: unknown;
83
- } ? T[424] : T extends {
84
- 425: unknown;
85
- } ? T[425] : T extends {
86
- 426: unknown;
87
- } ? T[426] : T extends {
88
- 427: unknown;
89
- } ? T[427] : T extends {
90
- 428: unknown;
91
- } ? T[428] : T extends {
92
- 429: unknown;
93
- } ? T[429] : T extends {
94
- 430: unknown;
95
- } ? T[430] : T extends {
96
- 431: unknown;
97
- } ? T[431] : T extends {
98
- 444: unknown;
99
- } ? T[444] : T extends {
100
- 450: unknown;
101
- } ? T[450] : T extends {
102
- 451: unknown;
103
- } ? T[451] : T extends {
104
- 497: unknown;
105
- } ? T[497] : T extends {
106
- 498: unknown;
107
- } ? T[498] : T extends {
108
- 499: unknown;
109
- } ? T[499] : T extends {
110
- "4XX": unknown;
111
- } ? T["4XX"] : T extends {
112
- default: unknown;
113
- } ? T["default"] : never;
114
- /** The paths that have each of the methods: upstream's `PathsWithMethod`. */
115
- type PathsWithEveryMethod<Paths extends {}, PathnameMethod extends HttpMethod> = {
116
- [Pathname in keyof Paths]: Paths[Pathname] extends {
117
- [K in PathnameMethod]: unknown;
118
- } ? Pathname : never;
119
- }[keyof Paths];
120
- /** The paths that have at least one method. */
121
- type PathsWithAnyMethod<Paths extends {}> = {
122
- [Pathname in keyof Paths]: {
123
- [Method in HttpMethod]: Paths[Pathname] extends {
124
- [K in Method]: unknown;
125
- } ? Pathname : never;
126
- }[HttpMethod];
127
- }[keyof Paths];
128
- /**
129
- * Given an OpenAPI **Paths Object**, find all paths that have the given method. For a union of
130
- * methods, the paths that have each of them, so a call with either method finds its operation.
131
- * For `HttpMethod` itself, a method not known yet, the paths that have any method too: TypeScript
132
- * uses it where a hook's `Method` is not inferred, as in `Parameters<typeof $api.queryOptions>`,
133
- * and the paths with every method were none (upstream #2178).
134
- *
135
- * A union with upstream's type, not a conditional type over the method: code that is generic in
136
- * the method (`Path extends PathsWithMethod<Paths, Method>`, as swr-openapi has) must still
137
- * relate one `PathsWithMethod` to another, and TypeScript cannot relate a type to a conditional
138
- * type that waits for its method (TS2344). For a known method the second member is `never`.
139
- */
140
- type PathsWithMethod<Paths extends {}, PathnameMethod extends HttpMethod> = PathsWithEveryMethod<Paths, PathnameMethod> | (HttpMethod extends PathnameMethod ? PathsWithAnyMethod<Paths> : never);
141
- /**
142
- * DO NOT USE!
143
- * Only used only for OperationObject type inference
144
- */
145
- interface OperationObject {
146
- parameters: any;
147
- requestBody: any;
148
- responses: any;
149
- }
150
- /** Internal helper used in PathsWithMethod */
151
- type PathItemObject = {
152
- [M in HttpMethod]: OperationObject;
153
- } & {
154
- parameters?: any;
155
- };
156
- /** Return `responses` for an Operation Object */
157
- type ResponseObjectMap<T> = T extends {
158
- responses: any;
159
- } ? T["responses"] : unknown;
160
- /** Return `content` for a Response Object */
161
- type ResponseContent<T> = T extends {
162
- content: any;
163
- } ? T["content"] : unknown;
164
- /** Return type of `requestBody` for an Operation Object */
165
- type OperationRequestBody<T> = "requestBody" extends keyof T ? T["requestBody"] : never;
166
- /** Internal helper to get object type with only the `requestBody` property */
167
- type PickRequestBody<T> = "requestBody" extends keyof T ? Pick<T, "requestBody"> : never;
168
- /** Resolve to `true` if request body is optional, else `false` */
169
- type IsOperationRequestBodyOptional<T> = RequiredKeysOf<PickRequestBody<T>> extends never ? true : false;
170
- /** Internal helper used in OperationRequestBodyContent */
171
- type OperationRequestBodyMediaContent<T> = IsOperationRequestBodyOptional<T> extends true ? ResponseContent<NonNullable<OperationRequestBody<T>>> | undefined : ResponseContent<OperationRequestBody<T>>;
172
- /** Return first `content` from a Request Object Mapping, allowing any media type */
173
- type OperationRequestBodyContent<T> = FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never ? FilterKeys<NonNullable<OperationRequestBodyMediaContent<T>>, MediaType> | undefined : FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
174
- /**
175
- * The statuses of success responses in a Response Object Map: the 2XX statuses, or `default` when
176
- * no 2XX status is declared. `default` covers every status the operation does not declare (OpenAPI
177
- * Responses Object), so then it covers every success (upstream #1862). With a 2XX status declared,
178
- * `default` is left to the errors, as before.
179
- */
180
- type SuccessStatus<T> = [Extract<keyof T, OkStatus>] extends [never] ? "default" : OkStatus;
181
- /** Return all 2XX responses from a Response Object Map, or `default` if it declares no 2XX one */
182
- type SuccessResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, SuccessStatus<T>>;
183
- type GetResponseContent<T extends Record<string | number, any>, Media extends MediaType = MediaType, ResponseCode extends keyof T = keyof T> = ResponseCode extends keyof T ? {
184
- [K in ResponseCode]: T[K]["content"] extends Record<string, any> ? FilterKeys<T[K]["content"], Media> extends never ? T[K]["content"] : FilterKeys<T[K]["content"], Media> : K extends keyof T ? T[K]["content"] : never;
185
- }[ResponseCode] : never;
186
- /**
187
- * Return all 5XX and 4XX responses (in that order) from a Response Object Map
188
- */
189
- type ErrorResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, ErrorStatus>;
190
- /** Return first JSON-like 2XX response from a path + HTTP method */
191
- type SuccessResponseJSON<PathMethod extends Record<string | number, any>> = SuccessResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
192
- /** Return first JSON-like 5XX or 4XX response from a path + HTTP method */
193
- type ErrorResponseJSON<PathMethod extends Record<string | number, any>> = ErrorResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
194
- /** Return JSON-like request body from a path + HTTP method */
195
- type RequestBodyJSON<PathMethod> = JSONLike<FilterKeys<OperationRequestBody<PathMethod>, "content">>;
196
- /** Find first match of multiple keys */
197
- type FilterKeys<Obj, Matchers> = Obj[keyof Obj & Matchers];
198
- /**
199
- * @deprecated Use `FilterKeys` instead
200
- * Get the type of a value of an input object with a given key. If the key is
201
- * not found, return a default type. Works with unions of objects too.
202
- */
203
- type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends unknown ? FilterKeys<Obj, KeyPattern> extends never ? Default : FilterKeys<Obj, KeyPattern> : never;
204
- /**
205
- * Return any `[string]/[string]` media type (important because openapi-typesafe-fetch allows any
206
- * content response, not just JSON-like)
207
- */
208
- type MediaType = `${string}/${string}`;
209
- /**
210
- * Return any media type containing "json" (works for "application/json",
211
- * "application/vnd.api+json", "application/vnd.oai.openapi+json")
212
- */
213
- type JSONLike<T> = FilterKeys<T, `${string}/json`>;
214
- /**
215
- * Filter objects that have required keys
216
- * @deprecated Use `RequiredKeysOf` instead
217
- */
218
- type FindRequiredKeys<T, K extends keyof T> = K extends unknown ? undefined extends T[K] ? never : K : K;
219
- /**
220
- * Does this object contain required keys?
221
- * @deprecated Use `RequiredKeysOf` instead
222
- */
223
- type HasRequiredKeys<T> = FindRequiredKeys<T, keyof T>;
224
- /**
225
- * Helper to get the required keys of an object. If no keys are required, will be `undefined` with
226
- * strictNullChecks enabled, else `never`
227
- */
228
- type RequiredKeysOfHelper<T> = {
229
- [K in keyof T]: {} extends Pick<T, K> ? never : K;
230
- }[keyof T];
231
- /** Get the required keys of an object, or `never` if no keys are required */
232
- type RequiredKeysOf<T> = RequiredKeysOfHelper<T> extends undefined ? never : RequiredKeysOfHelper<T>;
233
- /** Marker type for readOnly properties (excluded from request bodies) */
234
- type $Read<T> = {
235
- readonly $read: T;
236
- };
237
- /** Marker type for writeOnly properties (excluded from response bodies) */
238
- type $Write<T> = {
239
- readonly $write: T;
240
- };
241
- /** Primitives, also branded ones (`string & { __brand: "Id" }`), which stay unmapped (#2765). */
242
- type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;
243
- /**
244
- * Types that stay unmapped. Mapping a function type drops its call signatures, so a `Blob` from
245
- * `--binary-as-blob` lost its methods (`arrayBuffer()`, `text()`, ...) in response data.
246
- */
247
- type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);
248
- /**
249
- * Keys of `T` whose value is a `Marker`. A key whose value is only `null` or `undefined` is not
250
- * marked: `NonNullable` of it is `never`, and `never` extends every marker (upstream #2717). The
251
- * checks are not distributive (`NonNullable<T[K]>` is not a type parameter), so `never` is seen.
252
- */
253
- type ReadWriteMarkedKeys<T, Marker> = {
254
- [K in keyof T]-?: NonNullable<T[K]> extends never ? never : NonNullable<T[K]> extends Marker ? K : never;
255
- }[keyof T];
256
- /**
257
- * Resolve an array or a tuple element by element. An array uses `T[number]`, not `infer E`: for an
258
- * intersection of arrays (`allOf`) inference keeps one member and narrowing breaks (upstream
259
- * #2620). `T` is a plain array when an array of its elements is assignable to it; otherwise it is a
260
- * tuple (also `[A, ...B[]]`), mapped homomorphically to stay a tuple (upstream #2632). Both keep
261
- * `readonly` (upstream #2615).
262
- */
263
- type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | "write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {
264
- [K in keyof T]: ReadWriteResolve<T[K], Resolved>;
265
- };
266
- type ReadWriteResolve<T, Resolved extends "read" | "write"> = Resolved extends "read" ? Readable<T> : Writable<T>;
267
- /**
268
- * Resolve type for reading (responses): strips $Write properties, unwraps $Read
269
- * - $Read<T> → T (readable), continues recursion
270
- * - $Write<T> → never (excluded from response)
271
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
272
- * recursively
273
- */
274
- type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? Readable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "read"> : T extends object ? {
275
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Write<any>> ? never : K]: Readable<T[K]>;
276
- } : T;
277
- /**
278
- * Resolve type for writing (requests): strips $Read properties, unwraps $Write
279
- * - $Write<T> → T (writable), continues recursion
280
- * - $Read<T> → never (excluded from request)
281
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
282
- * recursively
283
- */
284
- type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? Writable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "write"> : T extends object ? {
285
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Read<any>> ? never : K]: Writable<T[K]>;
286
- } & {
287
- [K in ReadWriteMarkedKeys<T, $Read<any>>]?: never;
288
- } : T;
289
-
290
- export type { $Read, $Write, ErrorResponse, ErrorResponseJSON, ErrorStatus, FilterKeys, FindRequiredKeys, FirstErrorStatus, GetResponseContent, GetValueWithDefault, HasRequiredKeys, HttpMethod, IsOperationRequestBodyOptional, JSONLike, MediaType, OKStatusUnion, OkStatus, OperationObject, OperationRequestBody, OperationRequestBodyContent, OperationRequestBodyMediaContent, PathItemObject, PathsWithMethod, Readable, RequestBodyJSON, RequiredKeysOf, ResponseContent, ResponseObjectMap, SuccessResponse, SuccessResponseJSON, Writable };
1
+ export * from 'openapi-typesafe-fetch/helpers';
package/dist/index.d.mts CHANGED
@@ -1,290 +1 @@
1
- type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"
2
- /** OpenAPI 3.2: a safe, idempotent request with a body. */
3
- | "query";
4
- /** 2XX statuses */
5
- type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207 | "2XX";
6
- /** 4XX and 5XX statuses */
7
- type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | "5XX" | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | "4XX" | "default";
8
- /** Get a union of OK Statuses */
9
- type OKStatusUnion<T> = FilterKeys<T, OkStatus>;
10
- /** Get first error status, in order */
11
- type FirstErrorStatus<T> = T extends {
12
- 500: unknown;
13
- } ? T[500] : T extends {
14
- 501: unknown;
15
- } ? T[501] : T extends {
16
- 502: unknown;
17
- } ? T[502] : T extends {
18
- 503: unknown;
19
- } ? T[503] : T extends {
20
- 504: unknown;
21
- } ? T[504] : T extends {
22
- 505: unknown;
23
- } ? T[505] : T extends {
24
- 506: unknown;
25
- } ? T[506] : T extends {
26
- 507: unknown;
27
- } ? T[507] : T extends {
28
- 508: unknown;
29
- } ? T[508] : T extends {
30
- 510: unknown;
31
- } ? T[510] : T extends {
32
- 511: unknown;
33
- } ? T[511] : T extends {
34
- "5XX": unknown;
35
- } ? T["5XX"] : T extends {
36
- 400: unknown;
37
- } ? T[400] : T extends {
38
- 401: unknown;
39
- } ? T[401] : T extends {
40
- 402: unknown;
41
- } ? T[402] : T extends {
42
- 403: unknown;
43
- } ? T[403] : T extends {
44
- 404: unknown;
45
- } ? T[404] : T extends {
46
- 405: unknown;
47
- } ? T[405] : T extends {
48
- 406: unknown;
49
- } ? T[406] : T extends {
50
- 407: unknown;
51
- } ? T[407] : T extends {
52
- 408: unknown;
53
- } ? T[408] : T extends {
54
- 409: unknown;
55
- } ? T[409] : T extends {
56
- 410: unknown;
57
- } ? T[410] : T extends {
58
- 411: unknown;
59
- } ? T[411] : T extends {
60
- 412: unknown;
61
- } ? T[412] : T extends {
62
- 413: unknown;
63
- } ? T[413] : T extends {
64
- 414: unknown;
65
- } ? T[414] : T extends {
66
- 415: unknown;
67
- } ? T[415] : T extends {
68
- 416: unknown;
69
- } ? T[416] : T extends {
70
- 417: unknown;
71
- } ? T[417] : T extends {
72
- 418: unknown;
73
- } ? T[418] : T extends {
74
- 420: unknown;
75
- } ? T[420] : T extends {
76
- 421: unknown;
77
- } ? T[421] : T extends {
78
- 422: unknown;
79
- } ? T[422] : T extends {
80
- 423: unknown;
81
- } ? T[423] : T extends {
82
- 424: unknown;
83
- } ? T[424] : T extends {
84
- 425: unknown;
85
- } ? T[425] : T extends {
86
- 426: unknown;
87
- } ? T[426] : T extends {
88
- 427: unknown;
89
- } ? T[427] : T extends {
90
- 428: unknown;
91
- } ? T[428] : T extends {
92
- 429: unknown;
93
- } ? T[429] : T extends {
94
- 430: unknown;
95
- } ? T[430] : T extends {
96
- 431: unknown;
97
- } ? T[431] : T extends {
98
- 444: unknown;
99
- } ? T[444] : T extends {
100
- 450: unknown;
101
- } ? T[450] : T extends {
102
- 451: unknown;
103
- } ? T[451] : T extends {
104
- 497: unknown;
105
- } ? T[497] : T extends {
106
- 498: unknown;
107
- } ? T[498] : T extends {
108
- 499: unknown;
109
- } ? T[499] : T extends {
110
- "4XX": unknown;
111
- } ? T["4XX"] : T extends {
112
- default: unknown;
113
- } ? T["default"] : never;
114
- /** The paths that have each of the methods: upstream's `PathsWithMethod`. */
115
- type PathsWithEveryMethod<Paths extends {}, PathnameMethod extends HttpMethod> = {
116
- [Pathname in keyof Paths]: Paths[Pathname] extends {
117
- [K in PathnameMethod]: unknown;
118
- } ? Pathname : never;
119
- }[keyof Paths];
120
- /** The paths that have at least one method. */
121
- type PathsWithAnyMethod<Paths extends {}> = {
122
- [Pathname in keyof Paths]: {
123
- [Method in HttpMethod]: Paths[Pathname] extends {
124
- [K in Method]: unknown;
125
- } ? Pathname : never;
126
- }[HttpMethod];
127
- }[keyof Paths];
128
- /**
129
- * Given an OpenAPI **Paths Object**, find all paths that have the given method. For a union of
130
- * methods, the paths that have each of them, so a call with either method finds its operation.
131
- * For `HttpMethod` itself, a method not known yet, the paths that have any method too: TypeScript
132
- * uses it where a hook's `Method` is not inferred, as in `Parameters<typeof $api.queryOptions>`,
133
- * and the paths with every method were none (upstream #2178).
134
- *
135
- * A union with upstream's type, not a conditional type over the method: code that is generic in
136
- * the method (`Path extends PathsWithMethod<Paths, Method>`, as swr-openapi has) must still
137
- * relate one `PathsWithMethod` to another, and TypeScript cannot relate a type to a conditional
138
- * type that waits for its method (TS2344). For a known method the second member is `never`.
139
- */
140
- type PathsWithMethod<Paths extends {}, PathnameMethod extends HttpMethod> = PathsWithEveryMethod<Paths, PathnameMethod> | (HttpMethod extends PathnameMethod ? PathsWithAnyMethod<Paths> : never);
141
- /**
142
- * DO NOT USE!
143
- * Only used only for OperationObject type inference
144
- */
145
- interface OperationObject {
146
- parameters: any;
147
- requestBody: any;
148
- responses: any;
149
- }
150
- /** Internal helper used in PathsWithMethod */
151
- type PathItemObject = {
152
- [M in HttpMethod]: OperationObject;
153
- } & {
154
- parameters?: any;
155
- };
156
- /** Return `responses` for an Operation Object */
157
- type ResponseObjectMap<T> = T extends {
158
- responses: any;
159
- } ? T["responses"] : unknown;
160
- /** Return `content` for a Response Object */
161
- type ResponseContent<T> = T extends {
162
- content: any;
163
- } ? T["content"] : unknown;
164
- /** Return type of `requestBody` for an Operation Object */
165
- type OperationRequestBody<T> = "requestBody" extends keyof T ? T["requestBody"] : never;
166
- /** Internal helper to get object type with only the `requestBody` property */
167
- type PickRequestBody<T> = "requestBody" extends keyof T ? Pick<T, "requestBody"> : never;
168
- /** Resolve to `true` if request body is optional, else `false` */
169
- type IsOperationRequestBodyOptional<T> = RequiredKeysOf<PickRequestBody<T>> extends never ? true : false;
170
- /** Internal helper used in OperationRequestBodyContent */
171
- type OperationRequestBodyMediaContent<T> = IsOperationRequestBodyOptional<T> extends true ? ResponseContent<NonNullable<OperationRequestBody<T>>> | undefined : ResponseContent<OperationRequestBody<T>>;
172
- /** Return first `content` from a Request Object Mapping, allowing any media type */
173
- type OperationRequestBodyContent<T> = FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never ? FilterKeys<NonNullable<OperationRequestBodyMediaContent<T>>, MediaType> | undefined : FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
174
- /**
175
- * The statuses of success responses in a Response Object Map: the 2XX statuses, or `default` when
176
- * no 2XX status is declared. `default` covers every status the operation does not declare (OpenAPI
177
- * Responses Object), so then it covers every success (upstream #1862). With a 2XX status declared,
178
- * `default` is left to the errors, as before.
179
- */
180
- type SuccessStatus<T> = [Extract<keyof T, OkStatus>] extends [never] ? "default" : OkStatus;
181
- /** Return all 2XX responses from a Response Object Map, or `default` if it declares no 2XX one */
182
- type SuccessResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, SuccessStatus<T>>;
183
- type GetResponseContent<T extends Record<string | number, any>, Media extends MediaType = MediaType, ResponseCode extends keyof T = keyof T> = ResponseCode extends keyof T ? {
184
- [K in ResponseCode]: T[K]["content"] extends Record<string, any> ? FilterKeys<T[K]["content"], Media> extends never ? T[K]["content"] : FilterKeys<T[K]["content"], Media> : K extends keyof T ? T[K]["content"] : never;
185
- }[ResponseCode] : never;
186
- /**
187
- * Return all 5XX and 4XX responses (in that order) from a Response Object Map
188
- */
189
- type ErrorResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, ErrorStatus>;
190
- /** Return first JSON-like 2XX response from a path + HTTP method */
191
- type SuccessResponseJSON<PathMethod extends Record<string | number, any>> = SuccessResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
192
- /** Return first JSON-like 5XX or 4XX response from a path + HTTP method */
193
- type ErrorResponseJSON<PathMethod extends Record<string | number, any>> = ErrorResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
194
- /** Return JSON-like request body from a path + HTTP method */
195
- type RequestBodyJSON<PathMethod> = JSONLike<FilterKeys<OperationRequestBody<PathMethod>, "content">>;
196
- /** Find first match of multiple keys */
197
- type FilterKeys<Obj, Matchers> = Obj[keyof Obj & Matchers];
198
- /**
199
- * @deprecated Use `FilterKeys` instead
200
- * Get the type of a value of an input object with a given key. If the key is
201
- * not found, return a default type. Works with unions of objects too.
202
- */
203
- type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends unknown ? FilterKeys<Obj, KeyPattern> extends never ? Default : FilterKeys<Obj, KeyPattern> : never;
204
- /**
205
- * Return any `[string]/[string]` media type (important because openapi-typesafe-fetch allows any
206
- * content response, not just JSON-like)
207
- */
208
- type MediaType = `${string}/${string}`;
209
- /**
210
- * Return any media type containing "json" (works for "application/json",
211
- * "application/vnd.api+json", "application/vnd.oai.openapi+json")
212
- */
213
- type JSONLike<T> = FilterKeys<T, `${string}/json`>;
214
- /**
215
- * Filter objects that have required keys
216
- * @deprecated Use `RequiredKeysOf` instead
217
- */
218
- type FindRequiredKeys<T, K extends keyof T> = K extends unknown ? undefined extends T[K] ? never : K : K;
219
- /**
220
- * Does this object contain required keys?
221
- * @deprecated Use `RequiredKeysOf` instead
222
- */
223
- type HasRequiredKeys<T> = FindRequiredKeys<T, keyof T>;
224
- /**
225
- * Helper to get the required keys of an object. If no keys are required, will be `undefined` with
226
- * strictNullChecks enabled, else `never`
227
- */
228
- type RequiredKeysOfHelper<T> = {
229
- [K in keyof T]: {} extends Pick<T, K> ? never : K;
230
- }[keyof T];
231
- /** Get the required keys of an object, or `never` if no keys are required */
232
- type RequiredKeysOf<T> = RequiredKeysOfHelper<T> extends undefined ? never : RequiredKeysOfHelper<T>;
233
- /** Marker type for readOnly properties (excluded from request bodies) */
234
- type $Read<T> = {
235
- readonly $read: T;
236
- };
237
- /** Marker type for writeOnly properties (excluded from response bodies) */
238
- type $Write<T> = {
239
- readonly $write: T;
240
- };
241
- /** Primitives, also branded ones (`string & { __brand: "Id" }`), which stay unmapped (#2765). */
242
- type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;
243
- /**
244
- * Types that stay unmapped. Mapping a function type drops its call signatures, so a `Blob` from
245
- * `--binary-as-blob` lost its methods (`arrayBuffer()`, `text()`, ...) in response data.
246
- */
247
- type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);
248
- /**
249
- * Keys of `T` whose value is a `Marker`. A key whose value is only `null` or `undefined` is not
250
- * marked: `NonNullable` of it is `never`, and `never` extends every marker (upstream #2717). The
251
- * checks are not distributive (`NonNullable<T[K]>` is not a type parameter), so `never` is seen.
252
- */
253
- type ReadWriteMarkedKeys<T, Marker> = {
254
- [K in keyof T]-?: NonNullable<T[K]> extends never ? never : NonNullable<T[K]> extends Marker ? K : never;
255
- }[keyof T];
256
- /**
257
- * Resolve an array or a tuple element by element. An array uses `T[number]`, not `infer E`: for an
258
- * intersection of arrays (`allOf`) inference keeps one member and narrowing breaks (upstream
259
- * #2620). `T` is a plain array when an array of its elements is assignable to it; otherwise it is a
260
- * tuple (also `[A, ...B[]]`), mapped homomorphically to stay a tuple (upstream #2632). Both keep
261
- * `readonly` (upstream #2615).
262
- */
263
- type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | "write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {
264
- [K in keyof T]: ReadWriteResolve<T[K], Resolved>;
265
- };
266
- type ReadWriteResolve<T, Resolved extends "read" | "write"> = Resolved extends "read" ? Readable<T> : Writable<T>;
267
- /**
268
- * Resolve type for reading (responses): strips $Write properties, unwraps $Read
269
- * - $Read<T> → T (readable), continues recursion
270
- * - $Write<T> → never (excluded from response)
271
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
272
- * recursively
273
- */
274
- type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? Readable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "read"> : T extends object ? {
275
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Write<any>> ? never : K]: Readable<T[K]>;
276
- } : T;
277
- /**
278
- * Resolve type for writing (requests): strips $Read properties, unwraps $Write
279
- * - $Write<T> → T (writable), continues recursion
280
- * - $Read<T> → never (excluded from request)
281
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
282
- * recursively
283
- */
284
- type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? Writable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "write"> : T extends object ? {
285
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Read<any>> ? never : K]: Writable<T[K]>;
286
- } & {
287
- [K in ReadWriteMarkedKeys<T, $Read<any>>]?: never;
288
- } : T;
289
-
290
- export type { $Read, $Write, ErrorResponse, ErrorResponseJSON, ErrorStatus, FilterKeys, FindRequiredKeys, FirstErrorStatus, GetResponseContent, GetValueWithDefault, HasRequiredKeys, HttpMethod, IsOperationRequestBodyOptional, JSONLike, MediaType, OKStatusUnion, OkStatus, OperationObject, OperationRequestBody, OperationRequestBodyContent, OperationRequestBodyMediaContent, PathItemObject, PathsWithMethod, Readable, RequestBodyJSON, RequiredKeysOf, ResponseContent, ResponseObjectMap, SuccessResponse, SuccessResponseJSON, Writable };
1
+ export * from 'openapi-typesafe-fetch/helpers';
package/dist/index.d.ts CHANGED
@@ -1,290 +1 @@
1
- type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace"
2
- /** OpenAPI 3.2: a safe, idempotent request with a body. */
3
- | "query";
4
- /** 2XX statuses */
5
- type OkStatus = 200 | 201 | 202 | 203 | 204 | 206 | 207 | "2XX";
6
- /** 4XX and 5XX statuses */
7
- type ErrorStatus = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511 | "5XX" | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 444 | 450 | 451 | 497 | 498 | 499 | "4XX" | "default";
8
- /** Get a union of OK Statuses */
9
- type OKStatusUnion<T> = FilterKeys<T, OkStatus>;
10
- /** Get first error status, in order */
11
- type FirstErrorStatus<T> = T extends {
12
- 500: unknown;
13
- } ? T[500] : T extends {
14
- 501: unknown;
15
- } ? T[501] : T extends {
16
- 502: unknown;
17
- } ? T[502] : T extends {
18
- 503: unknown;
19
- } ? T[503] : T extends {
20
- 504: unknown;
21
- } ? T[504] : T extends {
22
- 505: unknown;
23
- } ? T[505] : T extends {
24
- 506: unknown;
25
- } ? T[506] : T extends {
26
- 507: unknown;
27
- } ? T[507] : T extends {
28
- 508: unknown;
29
- } ? T[508] : T extends {
30
- 510: unknown;
31
- } ? T[510] : T extends {
32
- 511: unknown;
33
- } ? T[511] : T extends {
34
- "5XX": unknown;
35
- } ? T["5XX"] : T extends {
36
- 400: unknown;
37
- } ? T[400] : T extends {
38
- 401: unknown;
39
- } ? T[401] : T extends {
40
- 402: unknown;
41
- } ? T[402] : T extends {
42
- 403: unknown;
43
- } ? T[403] : T extends {
44
- 404: unknown;
45
- } ? T[404] : T extends {
46
- 405: unknown;
47
- } ? T[405] : T extends {
48
- 406: unknown;
49
- } ? T[406] : T extends {
50
- 407: unknown;
51
- } ? T[407] : T extends {
52
- 408: unknown;
53
- } ? T[408] : T extends {
54
- 409: unknown;
55
- } ? T[409] : T extends {
56
- 410: unknown;
57
- } ? T[410] : T extends {
58
- 411: unknown;
59
- } ? T[411] : T extends {
60
- 412: unknown;
61
- } ? T[412] : T extends {
62
- 413: unknown;
63
- } ? T[413] : T extends {
64
- 414: unknown;
65
- } ? T[414] : T extends {
66
- 415: unknown;
67
- } ? T[415] : T extends {
68
- 416: unknown;
69
- } ? T[416] : T extends {
70
- 417: unknown;
71
- } ? T[417] : T extends {
72
- 418: unknown;
73
- } ? T[418] : T extends {
74
- 420: unknown;
75
- } ? T[420] : T extends {
76
- 421: unknown;
77
- } ? T[421] : T extends {
78
- 422: unknown;
79
- } ? T[422] : T extends {
80
- 423: unknown;
81
- } ? T[423] : T extends {
82
- 424: unknown;
83
- } ? T[424] : T extends {
84
- 425: unknown;
85
- } ? T[425] : T extends {
86
- 426: unknown;
87
- } ? T[426] : T extends {
88
- 427: unknown;
89
- } ? T[427] : T extends {
90
- 428: unknown;
91
- } ? T[428] : T extends {
92
- 429: unknown;
93
- } ? T[429] : T extends {
94
- 430: unknown;
95
- } ? T[430] : T extends {
96
- 431: unknown;
97
- } ? T[431] : T extends {
98
- 444: unknown;
99
- } ? T[444] : T extends {
100
- 450: unknown;
101
- } ? T[450] : T extends {
102
- 451: unknown;
103
- } ? T[451] : T extends {
104
- 497: unknown;
105
- } ? T[497] : T extends {
106
- 498: unknown;
107
- } ? T[498] : T extends {
108
- 499: unknown;
109
- } ? T[499] : T extends {
110
- "4XX": unknown;
111
- } ? T["4XX"] : T extends {
112
- default: unknown;
113
- } ? T["default"] : never;
114
- /** The paths that have each of the methods: upstream's `PathsWithMethod`. */
115
- type PathsWithEveryMethod<Paths extends {}, PathnameMethod extends HttpMethod> = {
116
- [Pathname in keyof Paths]: Paths[Pathname] extends {
117
- [K in PathnameMethod]: unknown;
118
- } ? Pathname : never;
119
- }[keyof Paths];
120
- /** The paths that have at least one method. */
121
- type PathsWithAnyMethod<Paths extends {}> = {
122
- [Pathname in keyof Paths]: {
123
- [Method in HttpMethod]: Paths[Pathname] extends {
124
- [K in Method]: unknown;
125
- } ? Pathname : never;
126
- }[HttpMethod];
127
- }[keyof Paths];
128
- /**
129
- * Given an OpenAPI **Paths Object**, find all paths that have the given method. For a union of
130
- * methods, the paths that have each of them, so a call with either method finds its operation.
131
- * For `HttpMethod` itself, a method not known yet, the paths that have any method too: TypeScript
132
- * uses it where a hook's `Method` is not inferred, as in `Parameters<typeof $api.queryOptions>`,
133
- * and the paths with every method were none (upstream #2178).
134
- *
135
- * A union with upstream's type, not a conditional type over the method: code that is generic in
136
- * the method (`Path extends PathsWithMethod<Paths, Method>`, as swr-openapi has) must still
137
- * relate one `PathsWithMethod` to another, and TypeScript cannot relate a type to a conditional
138
- * type that waits for its method (TS2344). For a known method the second member is `never`.
139
- */
140
- type PathsWithMethod<Paths extends {}, PathnameMethod extends HttpMethod> = PathsWithEveryMethod<Paths, PathnameMethod> | (HttpMethod extends PathnameMethod ? PathsWithAnyMethod<Paths> : never);
141
- /**
142
- * DO NOT USE!
143
- * Only used only for OperationObject type inference
144
- */
145
- interface OperationObject {
146
- parameters: any;
147
- requestBody: any;
148
- responses: any;
149
- }
150
- /** Internal helper used in PathsWithMethod */
151
- type PathItemObject = {
152
- [M in HttpMethod]: OperationObject;
153
- } & {
154
- parameters?: any;
155
- };
156
- /** Return `responses` for an Operation Object */
157
- type ResponseObjectMap<T> = T extends {
158
- responses: any;
159
- } ? T["responses"] : unknown;
160
- /** Return `content` for a Response Object */
161
- type ResponseContent<T> = T extends {
162
- content: any;
163
- } ? T["content"] : unknown;
164
- /** Return type of `requestBody` for an Operation Object */
165
- type OperationRequestBody<T> = "requestBody" extends keyof T ? T["requestBody"] : never;
166
- /** Internal helper to get object type with only the `requestBody` property */
167
- type PickRequestBody<T> = "requestBody" extends keyof T ? Pick<T, "requestBody"> : never;
168
- /** Resolve to `true` if request body is optional, else `false` */
169
- type IsOperationRequestBodyOptional<T> = RequiredKeysOf<PickRequestBody<T>> extends never ? true : false;
170
- /** Internal helper used in OperationRequestBodyContent */
171
- type OperationRequestBodyMediaContent<T> = IsOperationRequestBodyOptional<T> extends true ? ResponseContent<NonNullable<OperationRequestBody<T>>> | undefined : ResponseContent<OperationRequestBody<T>>;
172
- /** Return first `content` from a Request Object Mapping, allowing any media type */
173
- type OperationRequestBodyContent<T> = FilterKeys<OperationRequestBodyMediaContent<T>, MediaType> extends never ? FilterKeys<NonNullable<OperationRequestBodyMediaContent<T>>, MediaType> | undefined : FilterKeys<OperationRequestBodyMediaContent<T>, MediaType>;
174
- /**
175
- * The statuses of success responses in a Response Object Map: the 2XX statuses, or `default` when
176
- * no 2XX status is declared. `default` covers every status the operation does not declare (OpenAPI
177
- * Responses Object), so then it covers every success (upstream #1862). With a 2XX status declared,
178
- * `default` is left to the errors, as before.
179
- */
180
- type SuccessStatus<T> = [Extract<keyof T, OkStatus>] extends [never] ? "default" : OkStatus;
181
- /** Return all 2XX responses from a Response Object Map, or `default` if it declares no 2XX one */
182
- type SuccessResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, SuccessStatus<T>>;
183
- type GetResponseContent<T extends Record<string | number, any>, Media extends MediaType = MediaType, ResponseCode extends keyof T = keyof T> = ResponseCode extends keyof T ? {
184
- [K in ResponseCode]: T[K]["content"] extends Record<string, any> ? FilterKeys<T[K]["content"], Media> extends never ? T[K]["content"] : FilterKeys<T[K]["content"], Media> : K extends keyof T ? T[K]["content"] : never;
185
- }[ResponseCode] : never;
186
- /**
187
- * Return all 5XX and 4XX responses (in that order) from a Response Object Map
188
- */
189
- type ErrorResponse<T extends Record<string | number, any>, Media extends MediaType = MediaType> = GetResponseContent<T, Media, ErrorStatus>;
190
- /** Return first JSON-like 2XX response from a path + HTTP method */
191
- type SuccessResponseJSON<PathMethod extends Record<string | number, any>> = SuccessResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
192
- /** Return first JSON-like 5XX or 4XX response from a path + HTTP method */
193
- type ErrorResponseJSON<PathMethod extends Record<string | number, any>> = ErrorResponse<ResponseObjectMap<PathMethod>, `${string}/json`>;
194
- /** Return JSON-like request body from a path + HTTP method */
195
- type RequestBodyJSON<PathMethod> = JSONLike<FilterKeys<OperationRequestBody<PathMethod>, "content">>;
196
- /** Find first match of multiple keys */
197
- type FilterKeys<Obj, Matchers> = Obj[keyof Obj & Matchers];
198
- /**
199
- * @deprecated Use `FilterKeys` instead
200
- * Get the type of a value of an input object with a given key. If the key is
201
- * not found, return a default type. Works with unions of objects too.
202
- */
203
- type GetValueWithDefault<Obj, KeyPattern, Default> = Obj extends unknown ? FilterKeys<Obj, KeyPattern> extends never ? Default : FilterKeys<Obj, KeyPattern> : never;
204
- /**
205
- * Return any `[string]/[string]` media type (important because openapi-typesafe-fetch allows any
206
- * content response, not just JSON-like)
207
- */
208
- type MediaType = `${string}/${string}`;
209
- /**
210
- * Return any media type containing "json" (works for "application/json",
211
- * "application/vnd.api+json", "application/vnd.oai.openapi+json")
212
- */
213
- type JSONLike<T> = FilterKeys<T, `${string}/json`>;
214
- /**
215
- * Filter objects that have required keys
216
- * @deprecated Use `RequiredKeysOf` instead
217
- */
218
- type FindRequiredKeys<T, K extends keyof T> = K extends unknown ? undefined extends T[K] ? never : K : K;
219
- /**
220
- * Does this object contain required keys?
221
- * @deprecated Use `RequiredKeysOf` instead
222
- */
223
- type HasRequiredKeys<T> = FindRequiredKeys<T, keyof T>;
224
- /**
225
- * Helper to get the required keys of an object. If no keys are required, will be `undefined` with
226
- * strictNullChecks enabled, else `never`
227
- */
228
- type RequiredKeysOfHelper<T> = {
229
- [K in keyof T]: {} extends Pick<T, K> ? never : K;
230
- }[keyof T];
231
- /** Get the required keys of an object, or `never` if no keys are required */
232
- type RequiredKeysOf<T> = RequiredKeysOfHelper<T> extends undefined ? never : RequiredKeysOfHelper<T>;
233
- /** Marker type for readOnly properties (excluded from request bodies) */
234
- type $Read<T> = {
235
- readonly $read: T;
236
- };
237
- /** Marker type for writeOnly properties (excluded from response bodies) */
238
- type $Write<T> = {
239
- readonly $write: T;
240
- };
241
- /** Primitives, also branded ones (`string & { __brand: "Id" }`), which stay unmapped (#2765). */
242
- type ReadWritePrimitive = string | number | boolean | bigint | symbol | null | undefined;
243
- /**
244
- * Types that stay unmapped. Mapping a function type drops its call signatures, so a `Blob` from
245
- * `--binary-as-blob` lost its methods (`arrayBuffer()`, `text()`, ...) in response data.
246
- */
247
- type ReadWriteLeaf = ReadWritePrimitive | ((...args: never) => unknown);
248
- /**
249
- * Keys of `T` whose value is a `Marker`. A key whose value is only `null` or `undefined` is not
250
- * marked: `NonNullable` of it is `never`, and `never` extends every marker (upstream #2717). The
251
- * checks are not distributive (`NonNullable<T[K]>` is not a type parameter), so `never` is seen.
252
- */
253
- type ReadWriteMarkedKeys<T, Marker> = {
254
- [K in keyof T]-?: NonNullable<T[K]> extends never ? never : NonNullable<T[K]> extends Marker ? K : never;
255
- }[keyof T];
256
- /**
257
- * Resolve an array or a tuple element by element. An array uses `T[number]`, not `infer E`: for an
258
- * intersection of arrays (`allOf`) inference keeps one member and narrowing breaks (upstream
259
- * #2620). `T` is a plain array when an array of its elements is assignable to it; otherwise it is a
260
- * tuple (also `[A, ...B[]]`), mapped homomorphically to stay a tuple (upstream #2632). Both keep
261
- * `readonly` (upstream #2615).
262
- */
263
- type ReadWriteResolveArray<T extends readonly unknown[], Resolved extends "read" | "write"> = T[number][] extends T ? T extends unknown[] ? ReadWriteResolve<T[number], Resolved>[] : readonly ReadWriteResolve<T[number], Resolved>[] : {
264
- [K in keyof T]: ReadWriteResolve<T[K], Resolved>;
265
- };
266
- type ReadWriteResolve<T, Resolved extends "read" | "write"> = Resolved extends "read" ? Readable<T> : Writable<T>;
267
- /**
268
- * Resolve type for reading (responses): strips $Write properties, unwraps $Read
269
- * - $Read<T> → T (readable), continues recursion
270
- * - $Write<T> → never (excluded from response)
271
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
272
- * recursively
273
- */
274
- type Readable<T> = T extends $Write<any> ? never : T extends $Read<infer U> ? Readable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "read"> : T extends object ? {
275
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Write<any>> ? never : K]: Readable<T[K]>;
276
- } : T;
277
- /**
278
- * Resolve type for writing (requests): strips $Read properties, unwraps $Write
279
- * - $Write<T> → T (writable), continues recursion
280
- * - $Read<T> → never (excluded from request)
281
- * - primitives (also branded), functions, arrays and tuples keep their shape; objects resolve
282
- * recursively
283
- */
284
- type Writable<T> = T extends $Read<any> ? never : T extends $Write<infer U> ? Writable<U> : T extends ReadWriteLeaf ? T : T extends readonly unknown[] ? ReadWriteResolveArray<T, "write"> : T extends object ? {
285
- [K in keyof T as K extends ReadWriteMarkedKeys<T, $Read<any>> ? never : K]: Writable<T[K]>;
286
- } & {
287
- [K in ReadWriteMarkedKeys<T, $Read<any>>]?: never;
288
- } : T;
289
-
290
- export type { $Read, $Write, ErrorResponse, ErrorResponseJSON, ErrorStatus, FilterKeys, FindRequiredKeys, FirstErrorStatus, GetResponseContent, GetValueWithDefault, HasRequiredKeys, HttpMethod, IsOperationRequestBodyOptional, JSONLike, MediaType, OKStatusUnion, OkStatus, OperationObject, OperationRequestBody, OperationRequestBodyContent, OperationRequestBodyMediaContent, PathItemObject, PathsWithMethod, Readable, RequestBodyJSON, RequiredKeysOf, ResponseContent, ResponseObjectMap, SuccessResponse, SuccessResponseJSON, Writable };
1
+ export * from 'openapi-typesafe-fetch/helpers';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "openapi-typesafe-helpers",
3
3
  "description": "TypeScript helpers for consuming openapi-typesafe types",
4
- "version": "1.0.0-rc.2",
4
+ "version": "1.0.0-rc.4",
5
5
  "author": {
6
6
  "name": "Fedor Chishchin",
7
7
  "url": "https://github.com/fedorello"
@@ -24,6 +24,7 @@
24
24
  "./*": "./*"
25
25
  },
26
26
  "files": [
27
+ "CHANGELOG.md",
27
28
  "dist"
28
29
  ],
29
30
  "homepage": "https://github.com/openapi-typesafe/openapi-typesafe#readme",
@@ -35,6 +36,9 @@
35
36
  "bugs": {
36
37
  "url": "https://github.com/openapi-typesafe/openapi-typesafe/issues"
37
38
  },
39
+ "dependencies": {
40
+ "openapi-typesafe-fetch": "^1.0.0-rc.4"
41
+ },
38
42
  "devDependencies": {
39
43
  "typescript": "^6.0.3",
40
44
  "vite-node": "6.0.0"
@@ -49,7 +53,8 @@
49
53
  "lint:js": "biome check src",
50
54
  "lint:ts": "tsc --noEmit",
51
55
  "lint:sizes": "vite-node ../openapi-typesafe/scripts/size-rules/check-sizes.ts src",
52
- "test": "pnpm run test:exports",
53
- "test:exports": "pnpm run build && ../../scripts/check-exports.sh"
56
+ "test": "pnpm run test:js && pnpm run test:exports",
57
+ "test:js": "vitest run",
58
+ "test:exports": "../../scripts/check-exports.sh"
54
59
  }
55
60
  }