@hey-api/openapi-ts 0.97.2 → 0.98.0
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/README.md +54 -53
- package/dist/clients/angular/index.ts +1 -0
- package/dist/clients/angular/types.ts +3 -2
- package/dist/clients/angular/utils.ts +3 -3
- package/dist/clients/axios/index.ts +1 -0
- package/dist/clients/axios/types.ts +7 -2
- package/dist/clients/axios/utils.ts +2 -2
- package/dist/clients/core/auth.ts +7 -0
- package/dist/clients/core/params.ts +14 -12
- package/dist/clients/core/pathSerializer.ts +6 -6
- package/dist/clients/core/queryKeySerializer.ts +1 -1
- package/dist/clients/core/utils.ts +4 -4
- package/dist/clients/fetch/index.ts +1 -0
- package/dist/clients/fetch/types.ts +3 -2
- package/dist/clients/fetch/utils.ts +2 -2
- package/dist/clients/ky/index.ts +1 -0
- package/dist/clients/ky/types.ts +3 -2
- package/dist/clients/ky/utils.ts +2 -2
- package/dist/clients/next/index.ts +1 -0
- package/dist/clients/next/types.ts +7 -2
- package/dist/clients/next/utils.ts +3 -3
- package/dist/clients/nuxt/index.ts +1 -0
- package/dist/clients/nuxt/utils.ts +3 -3
- package/dist/clients/ofetch/index.ts +1 -0
- package/dist/clients/ofetch/types.ts +3 -2
- package/dist/clients/ofetch/utils.ts +2 -2
- package/dist/index.d.mts +852 -689
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/{init-CitwzRmB.mjs → init-BENFi6V7.mjs} +2711 -3023
- package/dist/init-BENFi6V7.mjs.map +1 -0
- package/dist/internal.d.mts +1 -1
- package/dist/internal.d.mts.map +1 -1
- package/dist/internal.mjs +1 -1
- package/dist/run.mjs +2 -2
- package/dist/run.mjs.map +1 -1
- package/dist/{src-DEol_iHK.mjs → src-BXIUXBF6.mjs} +5 -5
- package/dist/src-BXIUXBF6.mjs.map +1 -0
- package/dist/{types-KzipN7UT.d.mts → types-DH7EVLYi.d.mts} +2 -10
- package/dist/types-DH7EVLYi.d.mts.map +1 -0
- package/package.json +7 -7
- package/dist/init-CitwzRmB.mjs.map +0 -1
- package/dist/src-DEol_iHK.mjs.map +0 -1
- package/dist/types-KzipN7UT.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ Part of the Hey API ecosystem.
|
|
|
39
39
|
- HTTP clients for Fetch API, Angular, Axios, Next.js, Nuxt, and more
|
|
40
40
|
- 20+ plugins to reduce third-party boilerplate
|
|
41
41
|
- highly customizable via plugins
|
|
42
|
-
- [sync with Hey API Registry](https://heyapi.dev/openapi
|
|
42
|
+
- [sync with Hey API Registry](https://heyapi.dev/docs/openapi/typescript/integrations) for spec management
|
|
43
43
|
|
|
44
44
|
<!-- template-contributing-start -->
|
|
45
45
|
|
|
@@ -177,7 +177,7 @@ The fastest way to use `@hey-api/openapi-ts` is via npx
|
|
|
177
177
|
npx @hey-api/openapi-ts -i hey-api/backend -o src/client
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/openapi
|
|
180
|
+
Congratulations on creating your first client! 🎉 You can learn more about the generated files on the [Output](https://heyapi.dev/docs/openapi/typescript/output) page.
|
|
181
181
|
|
|
182
182
|
## Installation
|
|
183
183
|
|
|
@@ -211,7 +211,7 @@ bun add @hey-api/openapi-ts -D
|
|
|
211
211
|
|
|
212
212
|
This package is in [initial development](https://semver.org/#spec-item-4). Please pin an exact version so you can safely upgrade when you're ready.
|
|
213
213
|
|
|
214
|
-
We publish [migration notes](https://heyapi.dev/openapi
|
|
214
|
+
We publish [migration notes](https://heyapi.dev/docs/openapi/typescript/migrating) for every breaking release. You might not be impacted by a breaking change if you don't use the affected features.
|
|
215
215
|
|
|
216
216
|
## Usage
|
|
217
217
|
|
|
@@ -225,7 +225,7 @@ Most people run `@hey-api/openapi-ts` via CLI. To do that, add a script to your
|
|
|
225
225
|
}
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
-
The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/openapi
|
|
228
|
+
The above script can be executed by running `npm run openapi-ts` or equivalent command in other package managers. Next, we will create a [configuration](https://heyapi.dev/docs/openapi/typescript/configuration) file and move our options from Quick Start to it.
|
|
229
229
|
|
|
230
230
|
### Node.js
|
|
231
231
|
|
|
@@ -290,7 +290,7 @@ export default defineConfig({
|
|
|
290
290
|
});
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
See the [Vite](https://heyapi.dev/openapi
|
|
293
|
+
See the [Vite](https://heyapi.dev/docs/openapi/typescript/configuration/vite) page for full configuration options.
|
|
294
294
|
|
|
295
295
|
## Configuration
|
|
296
296
|
|
|
@@ -355,73 +355,74 @@ Clients are responsible for sending the actual HTTP requests. We default to Fetc
|
|
|
355
355
|
|
|
356
356
|
### Available Clients
|
|
357
357
|
|
|
358
|
-
- [`@hey-api/client-fetch`](https://heyapi.dev/openapi
|
|
359
|
-
- [`@hey-api/client-angular`](https://heyapi.dev/openapi
|
|
360
|
-
- [`@hey-api/client-axios`](https://heyapi.dev/openapi
|
|
361
|
-
- [`@hey-api/client-ky`](https://heyapi.dev/openapi
|
|
362
|
-
- [`@hey-api/client-next`](https://heyapi.dev/openapi
|
|
363
|
-
- [`@hey-api/client-nuxt`](https://heyapi.dev/openapi
|
|
364
|
-
- [`@hey-api/client-ofetch`](https://heyapi.dev/openapi
|
|
358
|
+
- [`@hey-api/client-fetch`](https://heyapi.dev/docs/openapi/typescript/clients/fetch)
|
|
359
|
+
- [`@hey-api/client-angular`](https://heyapi.dev/docs/openapi/typescript/clients/angular)
|
|
360
|
+
- [`@hey-api/client-axios`](https://heyapi.dev/docs/openapi/typescript/clients/axios)
|
|
361
|
+
- [`@hey-api/client-ky`](https://heyapi.dev/docs/openapi/typescript/clients/ky)
|
|
362
|
+
- [`@hey-api/client-next`](https://heyapi.dev/docs/openapi/typescript/clients/next-js)
|
|
363
|
+
- [`@hey-api/client-nuxt`](https://heyapi.dev/docs/openapi/typescript/clients/nuxt)
|
|
364
|
+
- [`@hey-api/client-ofetch`](https://heyapi.dev/docs/openapi/typescript/clients/ofetch)
|
|
365
365
|
|
|
366
366
|
### Proposed Clients (Vote to Prioritize)
|
|
367
367
|
|
|
368
368
|
The following clients are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
|
|
369
369
|
|
|
370
|
-
- [`@hey-api/client-effect`](https://heyapi.dev/openapi
|
|
370
|
+
- [`@hey-api/client-effect`](https://heyapi.dev/docs/openapi/typescript/clients/effect)
|
|
371
371
|
|
|
372
|
-
Don't see your client? [Build your own](https://heyapi.dev/openapi
|
|
372
|
+
Don't see your client? [Build your own](https://heyapi.dev/docs/openapi/typescript/clients/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
373
373
|
|
|
374
374
|
### Available Plugins
|
|
375
375
|
|
|
376
376
|
These plugins help reduce boilerplate associated with third-party dependencies. Hey API natively supports the most popular packages. Please open an issue on [GitHub](https://github.com/hey-api/openapi-ts/issues) if you'd like us to support your favorite package.
|
|
377
377
|
|
|
378
|
-
- [`@angular/common`](https://heyapi.dev/openapi
|
|
379
|
-
- [`@hey-api/schemas`](https://heyapi.dev/openapi
|
|
380
|
-
- [`@hey-api/sdk`](https://heyapi.dev/openapi
|
|
381
|
-
- [`@hey-api/transformers`](https://heyapi.dev/openapi
|
|
382
|
-
- [`@hey-api/typescript`](https://heyapi.dev/openapi
|
|
383
|
-
- [`@pinia/colada`](https://heyapi.dev/openapi
|
|
384
|
-
- [`@tanstack/angular-query-experimental`](https://heyapi.dev/openapi
|
|
385
|
-
- [`@tanstack/preact-query`](https://heyapi.dev/openapi
|
|
386
|
-
- [`@tanstack/react-query`](https://heyapi.dev/openapi
|
|
387
|
-
- [`@tanstack/solid-query`](https://heyapi.dev/openapi
|
|
388
|
-
- [`@tanstack/svelte-query`](https://heyapi.dev/openapi
|
|
389
|
-
- [`@tanstack/vue-query`](https://heyapi.dev/openapi
|
|
390
|
-
- [`fastify`](https://heyapi.dev/openapi
|
|
391
|
-
- [`orpc`](https://heyapi.dev/openapi
|
|
392
|
-
- [`nestjs`](https://heyapi.dev/openapi
|
|
393
|
-
- [`valibot`](https://heyapi.dev/openapi
|
|
394
|
-
- [`zod`](https://heyapi.dev/openapi
|
|
378
|
+
- [`@angular/common`](https://heyapi.dev/docs/openapi/typescript/plugins/angular)
|
|
379
|
+
- [`@hey-api/schemas`](https://heyapi.dev/docs/openapi/typescript/plugins/schemas)
|
|
380
|
+
- [`@hey-api/sdk`](https://heyapi.dev/docs/openapi/typescript/plugins/sdk)
|
|
381
|
+
- [`@hey-api/transformers`](https://heyapi.dev/docs/openapi/typescript/plugins/transformers)
|
|
382
|
+
- [`@hey-api/typescript`](https://heyapi.dev/docs/openapi/typescript/plugins/typescript)
|
|
383
|
+
- [`@pinia/colada`](https://heyapi.dev/docs/openapi/typescript/plugins/pinia-colada)
|
|
384
|
+
- [`@tanstack/angular-query-experimental`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
385
|
+
- [`@tanstack/preact-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
386
|
+
- [`@tanstack/react-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
387
|
+
- [`@tanstack/solid-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
388
|
+
- [`@tanstack/svelte-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
389
|
+
- [`@tanstack/vue-query`](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-query)
|
|
390
|
+
- [`fastify`](https://heyapi.dev/docs/openapi/typescript/plugins/fastify)
|
|
391
|
+
- [`orpc`](https://heyapi.dev/docs/openapi/typescript/plugins/orpc)
|
|
392
|
+
- [`nestjs`](https://heyapi.dev/docs/openapi/typescript/plugins/nest)
|
|
393
|
+
- [`valibot`](https://heyapi.dev/docs/openapi/typescript/plugins/valibot)
|
|
394
|
+
- [`zod`](https://heyapi.dev/docs/openapi/typescript/plugins/zod)
|
|
395
395
|
|
|
396
396
|
### Proposed Plugins (Vote to Prioritize)
|
|
397
397
|
|
|
398
398
|
The following plugins are roadmap proposals and are not started yet. You can help us prioritize them by voting on [GitHub](https://github.com/hey-api/openapi-ts/issues?q=state%3Aopen%20label%3A%22vote%20%F0%9F%93%A9%22).
|
|
399
399
|
|
|
400
|
-
- [Adonis](https://heyapi.dev/openapi
|
|
401
|
-
- [Ajv](https://heyapi.dev/openapi
|
|
402
|
-
- [Arktype](https://heyapi.dev/openapi
|
|
403
|
-
- [Chance](https://heyapi.dev/openapi
|
|
404
|
-
- [Elysia](https://heyapi.dev/openapi
|
|
405
|
-
- [Express](https://heyapi.dev/openapi
|
|
406
|
-
- [Faker](https://heyapi.dev/openapi
|
|
407
|
-
- [Falso](https://heyapi.dev/openapi
|
|
408
|
-
- [Hono](https://heyapi.dev/openapi
|
|
409
|
-
- [Joi](https://heyapi.dev/openapi
|
|
410
|
-
- [Koa](https://heyapi.dev/openapi
|
|
411
|
-
- [MSW](https://heyapi.dev/openapi
|
|
412
|
-
- [Nock](https://heyapi.dev/openapi
|
|
413
|
-
- [Superstruct](https://heyapi.dev/openapi
|
|
414
|
-
- [Supertest](https://heyapi.dev/openapi
|
|
415
|
-
- [SWR](https://heyapi.dev/openapi
|
|
416
|
-
- [
|
|
417
|
-
- [
|
|
418
|
-
- [
|
|
419
|
-
|
|
420
|
-
|
|
400
|
+
- [Adonis](https://heyapi.dev/docs/openapi/typescript/plugins/adonis)
|
|
401
|
+
- [Ajv](https://heyapi.dev/docs/openapi/typescript/plugins/ajv)
|
|
402
|
+
- [Arktype](https://heyapi.dev/docs/openapi/typescript/plugins/arktype)
|
|
403
|
+
- [Chance](https://heyapi.dev/docs/openapi/typescript/plugins/chance)
|
|
404
|
+
- [Elysia](https://heyapi.dev/docs/openapi/typescript/plugins/elysia)
|
|
405
|
+
- [Express](https://heyapi.dev/docs/openapi/typescript/plugins/express)
|
|
406
|
+
- [Faker](https://heyapi.dev/docs/openapi/typescript/plugins/faker)
|
|
407
|
+
- [Falso](https://heyapi.dev/docs/openapi/typescript/plugins/falso)
|
|
408
|
+
- [Hono](https://heyapi.dev/docs/openapi/typescript/plugins/hono)
|
|
409
|
+
- [Joi](https://heyapi.dev/docs/openapi/typescript/plugins/joi)
|
|
410
|
+
- [Koa](https://heyapi.dev/docs/openapi/typescript/plugins/koa)
|
|
411
|
+
- [MSW](https://heyapi.dev/docs/openapi/typescript/plugins/msw)
|
|
412
|
+
- [Nock](https://heyapi.dev/docs/openapi/typescript/plugins/nock)
|
|
413
|
+
- [Superstruct](https://heyapi.dev/docs/openapi/typescript/plugins/superstruct)
|
|
414
|
+
- [Supertest](https://heyapi.dev/docs/openapi/typescript/plugins/supertest)
|
|
415
|
+
- [SWR](https://heyapi.dev/docs/openapi/typescript/plugins/swr)
|
|
416
|
+
- [TanStack Start](https://heyapi.dev/docs/openapi/typescript/plugins/tanstack-start)
|
|
417
|
+
- [TypeBox](https://heyapi.dev/docs/openapi/typescript/plugins/typebox)
|
|
418
|
+
- [Yup](https://heyapi.dev/docs/openapi/typescript/plugins/yup)
|
|
419
|
+
- [Zustand](https://heyapi.dev/docs/openapi/typescript/plugins/zustand)
|
|
420
|
+
|
|
421
|
+
Don't see your plugin? [Build your own](https://heyapi.dev/docs/openapi/typescript/plugins/custom) or let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
|
|
421
422
|
|
|
422
423
|
## Migrating
|
|
423
424
|
|
|
424
|
-
You can learn more on the [Migrating](https://heyapi.dev/openapi
|
|
425
|
+
You can learn more on the [Migrating](https://heyapi.dev/docs/openapi/typescript/migrating) page.
|
|
425
426
|
|
|
426
427
|
<!-- template-license-start -->
|
|
427
428
|
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -156,12 +156,13 @@ type MethodFn = <
|
|
|
156
156
|
|
|
157
157
|
type SseFn = <
|
|
158
158
|
TData = unknown,
|
|
159
|
-
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
160
|
+
_TError = unknown,
|
|
160
161
|
ThrowOnError extends boolean = false,
|
|
161
162
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
162
163
|
>(
|
|
163
164
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
164
|
-
) => Promise<ServerSentEventsResult<TData
|
|
165
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
165
166
|
|
|
166
167
|
type RequestFn = <
|
|
167
168
|
TData = unknown,
|
|
@@ -93,8 +93,8 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
|
93
93
|
export const createQuerySerializer = <T = unknown>({
|
|
94
94
|
parameters = {},
|
|
95
95
|
...args
|
|
96
|
-
}: QuerySerializerOptions = {}) => {
|
|
97
|
-
const querySerializer = (queryParams: T) => {
|
|
96
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
97
|
+
const querySerializer = (queryParams: T): string => {
|
|
98
98
|
const search: string[] = [];
|
|
99
99
|
if (queryParams && typeof queryParams === 'object') {
|
|
100
100
|
for (const name in queryParams) {
|
|
@@ -240,7 +240,7 @@ export const getUrl = ({
|
|
|
240
240
|
query?: Record<string, unknown>;
|
|
241
241
|
querySerializer: QuerySerializer;
|
|
242
242
|
url: string;
|
|
243
|
-
}) => {
|
|
243
|
+
}): string => {
|
|
244
244
|
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
245
245
|
let url = (baseUrl ?? '') + pathUrl;
|
|
246
246
|
if (path) {
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -105,9 +105,14 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
|
|
|
105
105
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
106
106
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
107
107
|
|
|
108
|
-
type SseFn = <
|
|
108
|
+
type SseFn = <
|
|
109
|
+
TData = unknown,
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
111
|
+
_TError = unknown,
|
|
112
|
+
ThrowOnError extends boolean = false,
|
|
113
|
+
>(
|
|
109
114
|
options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
|
|
110
|
-
) => Promise<ServerSentEventsResult<TData
|
|
115
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
111
116
|
|
|
112
117
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
113
118
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
@@ -11,8 +11,8 @@ import type { Client, ClientOptions, Config, RequestOptions } from './types';
|
|
|
11
11
|
export const createQuerySerializer = <T = unknown>({
|
|
12
12
|
parameters = {},
|
|
13
13
|
...args
|
|
14
|
-
}: QuerySerializerOptions = {}) => {
|
|
15
|
-
const querySerializer = (queryParams: T) => {
|
|
14
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
15
|
+
const querySerializer = (queryParams: T): string => {
|
|
16
16
|
const search: string[] = [];
|
|
17
17
|
if (queryParams && typeof queryParams === 'object') {
|
|
18
18
|
for (const name in queryParams) {
|
|
@@ -7,6 +7,13 @@ export interface Auth {
|
|
|
7
7
|
* @default 'header'
|
|
8
8
|
*/
|
|
9
9
|
in?: 'header' | 'query' | 'cookie';
|
|
10
|
+
/**
|
|
11
|
+
* A unique identifier for the security scheme.
|
|
12
|
+
*
|
|
13
|
+
* Defined only when there are multiple security schemes whose `Auth`
|
|
14
|
+
* shape would otherwise be identical.
|
|
15
|
+
*/
|
|
16
|
+
key?: string;
|
|
10
17
|
/**
|
|
11
18
|
* Header or query parameter name.
|
|
12
19
|
*
|
|
@@ -60,7 +60,7 @@ type KeyMap = Map<
|
|
|
60
60
|
}
|
|
61
61
|
>;
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
function buildKeyMap(fields: FieldsConfig, map?: KeyMap): KeyMap {
|
|
64
64
|
if (!map) {
|
|
65
65
|
map = new Map();
|
|
66
66
|
}
|
|
@@ -83,7 +83,7 @@ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
return map;
|
|
86
|
-
}
|
|
86
|
+
}
|
|
87
87
|
|
|
88
88
|
interface Params {
|
|
89
89
|
body: unknown;
|
|
@@ -92,20 +92,22 @@ interface Params {
|
|
|
92
92
|
query: Record<string, unknown>;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
type ParamsSlotMap = Record<Slot, unknown>;
|
|
96
|
+
|
|
97
|
+
function stripEmptySlots(params: ParamsSlotMap): void {
|
|
96
98
|
for (const [slot, value] of Object.entries(params)) {
|
|
97
99
|
if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).length) {
|
|
98
100
|
delete params[slot as Slot];
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
|
-
}
|
|
103
|
+
}
|
|
102
104
|
|
|
103
|
-
export
|
|
104
|
-
const params:
|
|
105
|
-
body:
|
|
106
|
-
headers:
|
|
107
|
-
path:
|
|
108
|
-
query:
|
|
105
|
+
export function buildClientParams(args: ReadonlyArray<unknown>, fields: FieldsConfig): Params {
|
|
106
|
+
const params: ParamsSlotMap = {
|
|
107
|
+
body: Object.create(null),
|
|
108
|
+
headers: Object.create(null),
|
|
109
|
+
path: Object.create(null),
|
|
110
|
+
query: Object.create(null),
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
const map = buildKeyMap(fields);
|
|
@@ -163,5 +165,5 @@ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsCo
|
|
|
163
165
|
|
|
164
166
|
stripEmptySlots(params);
|
|
165
167
|
|
|
166
|
-
return params;
|
|
167
|
-
}
|
|
168
|
+
return params as Params;
|
|
169
|
+
}
|
|
@@ -23,7 +23,7 @@ interface SerializePrimitiveParam extends SerializePrimitiveOptions {
|
|
|
23
23
|
value: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
|
|
26
|
+
export const separatorArrayExplode = (style: ArraySeparatorStyle): '.' | ';' | ',' | '&' => {
|
|
27
27
|
switch (style) {
|
|
28
28
|
case 'label':
|
|
29
29
|
return '.';
|
|
@@ -36,7 +36,7 @@ export const separatorArrayExplode = (style: ArraySeparatorStyle) => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
|
|
39
|
+
export const separatorArrayNoExplode = (style: ArraySeparatorStyle): ',' | '|' | '%20' => {
|
|
40
40
|
switch (style) {
|
|
41
41
|
case 'form':
|
|
42
42
|
return ',';
|
|
@@ -49,7 +49,7 @@ export const separatorArrayNoExplode = (style: ArraySeparatorStyle) => {
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export const separatorObjectExplode = (style: ObjectSeparatorStyle) => {
|
|
52
|
+
export const separatorObjectExplode = (style: ObjectSeparatorStyle): '.' | ';' | ',' | '&' => {
|
|
53
53
|
switch (style) {
|
|
54
54
|
case 'label':
|
|
55
55
|
return '.';
|
|
@@ -70,7 +70,7 @@ export const serializeArrayParam = ({
|
|
|
70
70
|
value,
|
|
71
71
|
}: SerializeOptions<ArraySeparatorStyle> & {
|
|
72
72
|
value: unknown[];
|
|
73
|
-
}) => {
|
|
73
|
+
}): string => {
|
|
74
74
|
if (!explode) {
|
|
75
75
|
const joinedValues = (
|
|
76
76
|
allowReserved ? value : value.map((v) => encodeURIComponent(v as string))
|
|
@@ -108,7 +108,7 @@ export const serializePrimitiveParam = ({
|
|
|
108
108
|
allowReserved,
|
|
109
109
|
name,
|
|
110
110
|
value,
|
|
111
|
-
}: SerializePrimitiveParam) => {
|
|
111
|
+
}: SerializePrimitiveParam): string => {
|
|
112
112
|
if (value === undefined || value === null) {
|
|
113
113
|
return '';
|
|
114
114
|
}
|
|
@@ -132,7 +132,7 @@ export const serializeObjectParam = ({
|
|
|
132
132
|
}: SerializeOptions<ObjectSeparatorStyle> & {
|
|
133
133
|
value: Record<string, unknown> | Date;
|
|
134
134
|
valueOnly?: boolean;
|
|
135
|
-
}) => {
|
|
135
|
+
}): string => {
|
|
136
136
|
if (value instanceof Date) {
|
|
137
137
|
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
138
138
|
}
|
|
@@ -12,7 +12,7 @@ export type JsonValue =
|
|
|
12
12
|
/**
|
|
13
13
|
* Replacer that converts non-JSON values (bigint, Date, etc.) to safe substitutes.
|
|
14
14
|
*/
|
|
15
|
-
export const queryKeyJsonReplacer = (_key: string, value: unknown) => {
|
|
15
|
+
export const queryKeyJsonReplacer = (_key: string, value: unknown): unknown | undefined => {
|
|
16
16
|
if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
@@ -11,9 +11,9 @@ export interface PathSerializer {
|
|
|
11
11
|
url: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
14
|
+
export const PATH_PARAM_RE: RegExp = /\{[^{}]+\}/g;
|
|
15
15
|
|
|
16
|
-
export const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
16
|
+
export const defaultPathSerializer = ({ path, url: _url }: PathSerializer): string => {
|
|
17
17
|
let url = _url;
|
|
18
18
|
const matches = _url.match(PATH_PARAM_RE);
|
|
19
19
|
if (matches) {
|
|
@@ -92,7 +92,7 @@ export const getUrl = ({
|
|
|
92
92
|
query?: Record<string, unknown>;
|
|
93
93
|
querySerializer: QuerySerializer;
|
|
94
94
|
url: string;
|
|
95
|
-
}) => {
|
|
95
|
+
}): string => {
|
|
96
96
|
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
97
97
|
let url = (baseUrl ?? '') + pathUrl;
|
|
98
98
|
if (path) {
|
|
@@ -112,7 +112,7 @@ export function getValidRequestBody(options: {
|
|
|
112
112
|
body?: unknown;
|
|
113
113
|
bodySerializer?: BodySerializer | null;
|
|
114
114
|
serializedBody?: unknown;
|
|
115
|
-
}) {
|
|
115
|
+
}): unknown {
|
|
116
116
|
const hasBody = options.body !== undefined;
|
|
117
117
|
const isSerializedBody = hasBody && options.bodySerializer;
|
|
118
118
|
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -149,12 +149,13 @@ type MethodFn = <
|
|
|
149
149
|
|
|
150
150
|
type SseFn = <
|
|
151
151
|
TData = unknown,
|
|
152
|
-
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
_TError = unknown,
|
|
153
154
|
ThrowOnError extends boolean = false,
|
|
154
155
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
155
156
|
>(
|
|
156
157
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
157
|
-
) => Promise<ServerSentEventsResult<TData
|
|
158
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
158
159
|
|
|
159
160
|
type RequestFn = <
|
|
160
161
|
TData = unknown,
|
|
@@ -12,8 +12,8 @@ import type { Client, ClientOptions, Config, RequestOptions } from './types';
|
|
|
12
12
|
export const createQuerySerializer = <T = unknown>({
|
|
13
13
|
parameters = {},
|
|
14
14
|
...args
|
|
15
|
-
}: QuerySerializerOptions = {}) => {
|
|
16
|
-
const querySerializer = (queryParams: T) => {
|
|
15
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
16
|
+
const querySerializer = (queryParams: T): string => {
|
|
17
17
|
const search: string[] = [];
|
|
18
18
|
if (queryParams && typeof queryParams === 'object') {
|
|
19
19
|
for (const name in queryParams) {
|
package/dist/clients/ky/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
package/dist/clients/ky/types.ts
CHANGED
|
@@ -167,12 +167,13 @@ type MethodFn = <
|
|
|
167
167
|
|
|
168
168
|
type SseFn = <
|
|
169
169
|
TData = unknown,
|
|
170
|
-
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
171
|
+
_TError = unknown,
|
|
171
172
|
ThrowOnError extends boolean = false,
|
|
172
173
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
173
174
|
>(
|
|
174
175
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
175
|
-
) => Promise<ServerSentEventsResult<TData
|
|
176
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
176
177
|
|
|
177
178
|
type RequestFn = <
|
|
178
179
|
TData = unknown,
|
package/dist/clients/ky/utils.ts
CHANGED
|
@@ -12,8 +12,8 @@ import type { Client, ClientOptions, Config, RequestOptions } from './types';
|
|
|
12
12
|
export const createQuerySerializer = <T = unknown>({
|
|
13
13
|
parameters = {},
|
|
14
14
|
...args
|
|
15
|
-
}: QuerySerializerOptions = {}) => {
|
|
16
|
-
const querySerializer = (queryParams: T) => {
|
|
15
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
16
|
+
const querySerializer = (queryParams: T): string => {
|
|
17
17
|
const search: string[] = [];
|
|
18
18
|
if (queryParams && typeof queryParams === 'object') {
|
|
19
19
|
for (const name in queryParams) {
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -111,9 +111,14 @@ type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean
|
|
|
111
111
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
112
112
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
113
113
|
|
|
114
|
-
type SseFn = <
|
|
114
|
+
type SseFn = <
|
|
115
|
+
TData = unknown,
|
|
116
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
117
|
+
_TError = unknown,
|
|
118
|
+
ThrowOnError extends boolean = false,
|
|
119
|
+
>(
|
|
115
120
|
options: Omit<RequestOptions<never, ThrowOnError>, 'method'>,
|
|
116
|
-
) => Promise<ServerSentEventsResult<TData
|
|
121
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
117
122
|
|
|
118
123
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
119
124
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
@@ -92,8 +92,8 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
|
92
92
|
export const createQuerySerializer = <T = unknown>({
|
|
93
93
|
parameters = {},
|
|
94
94
|
...args
|
|
95
|
-
}: QuerySerializerOptions = {}) => {
|
|
96
|
-
const querySerializer = (queryParams: T) => {
|
|
95
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
96
|
+
const querySerializer = (queryParams: T): string => {
|
|
97
97
|
const search: string[] = [];
|
|
98
98
|
if (queryParams && typeof queryParams === 'object') {
|
|
99
99
|
for (const name in queryParams) {
|
|
@@ -257,7 +257,7 @@ export const getUrl = ({
|
|
|
257
257
|
query?: Record<string, unknown>;
|
|
258
258
|
querySerializer: QuerySerializer;
|
|
259
259
|
url: string;
|
|
260
|
-
}) => {
|
|
260
|
+
}): string => {
|
|
261
261
|
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
262
262
|
let url = (baseUrl ?? '') + pathUrl;
|
|
263
263
|
if (path) {
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -95,8 +95,8 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
|
95
95
|
export const createQuerySerializer = <T = unknown>({
|
|
96
96
|
parameters = {},
|
|
97
97
|
...args
|
|
98
|
-
}: QuerySerializerOptions = {}) => {
|
|
99
|
-
const querySerializer = (queryParams: T) => {
|
|
98
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
99
|
+
const querySerializer = (queryParams: T): string => {
|
|
100
100
|
const search: string[] = [];
|
|
101
101
|
const qParams = toValue(queryParams);
|
|
102
102
|
if (qParams && typeof qParams === 'object') {
|
|
@@ -225,7 +225,7 @@ export const getUrl = ({
|
|
|
225
225
|
}: Pick<BuildUrlOptions, 'path' | 'query' | 'url'> & {
|
|
226
226
|
baseUrl?: string;
|
|
227
227
|
querySerializer: QuerySerializer;
|
|
228
|
-
}) => {
|
|
228
|
+
}): string => {
|
|
229
229
|
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
230
230
|
let url = (baseUrl ?? '') + pathUrl;
|
|
231
231
|
if (path) {
|
|
@@ -7,6 +7,7 @@ export {
|
|
|
7
7
|
} from '../core/bodySerializer';
|
|
8
8
|
export { buildClientParams } from '../core/params';
|
|
9
9
|
export { serializeQueryKeyValue } from '../core/queryKeySerializer';
|
|
10
|
+
export type { ServerSentEventsResult } from '../core/serverSentEvents';
|
|
10
11
|
export { createClient } from './client';
|
|
11
12
|
export type {
|
|
12
13
|
Client,
|
|
@@ -212,12 +212,13 @@ type MethodFn = <
|
|
|
212
212
|
|
|
213
213
|
type SseFn = <
|
|
214
214
|
TData = unknown,
|
|
215
|
-
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
216
|
+
_TError = unknown,
|
|
216
217
|
ThrowOnError extends boolean = false,
|
|
217
218
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
218
219
|
>(
|
|
219
220
|
options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, 'method'>,
|
|
220
|
-
) => Promise<ServerSentEventsResult<TData
|
|
221
|
+
) => Promise<ServerSentEventsResult<TData>>;
|
|
221
222
|
|
|
222
223
|
type RequestFn = <
|
|
223
224
|
TData = unknown,
|
|
@@ -21,8 +21,8 @@ import type {
|
|
|
21
21
|
export const createQuerySerializer = <T = unknown>({
|
|
22
22
|
parameters = {},
|
|
23
23
|
...args
|
|
24
|
-
}: QuerySerializerOptions = {}) => {
|
|
25
|
-
const querySerializer = (queryParams: T) => {
|
|
24
|
+
}: QuerySerializerOptions = {}): ((queryParams: T) => string) => {
|
|
25
|
+
const querySerializer = (queryParams: T): string => {
|
|
26
26
|
const search: string[] = [];
|
|
27
27
|
if (queryParams && typeof queryParams === 'object') {
|
|
28
28
|
for (const name in queryParams) {
|