@hey-api/openapi-ts 0.80.18 → 0.81.1
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/dist/chunk-A2YBSPFD.js +43 -0
- package/dist/chunk-A2YBSPFD.js.map +1 -0
- package/dist/clients/angular/client.ts +50 -14
- package/dist/clients/angular/types.ts +52 -17
- package/dist/clients/axios/client.ts +49 -10
- package/dist/clients/axios/types.ts +53 -18
- package/dist/clients/axios/utils.ts +5 -112
- package/dist/clients/core/serverSentEvents.ts +235 -0
- package/dist/clients/core/types.ts +20 -22
- package/dist/clients/core/utils.ts +112 -0
- package/dist/clients/fetch/client.ts +53 -12
- package/dist/clients/fetch/types.ts +51 -15
- package/dist/clients/fetch/utils.ts +4 -117
- package/dist/clients/next/client.ts +56 -14
- package/dist/clients/next/types.ts +49 -14
- package/dist/clients/nuxt/client.ts +78 -13
- package/dist/clients/nuxt/types.ts +23 -2
- package/dist/clients/nuxt/utils.ts +1 -1
- package/dist/index.cjs +68 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/internal.cjs +13 -13
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/{types.d-CFCN8diW.d.cts → types.d-BGYcYtD8.d.cts} +272 -3
- package/dist/{types.d-CFCN8diW.d.ts → types.d-BGYcYtD8.d.ts} +272 -3
- package/package.json +1 -1
- package/dist/chunk-4ELE5AM4.js +0 -43
- package/dist/chunk-4ELE5AM4.js.map +0 -1
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
import { firstValueFrom } from 'rxjs';
|
|
15
15
|
import { filter } from 'rxjs/operators';
|
|
16
16
|
|
|
17
|
+
import { createSseClient } from '../core/serverSentEvents';
|
|
18
|
+
import type { HttpMethod } from '../core/types';
|
|
17
19
|
import type {
|
|
18
20
|
Client,
|
|
19
21
|
Config,
|
|
@@ -58,7 +60,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
58
60
|
ThrowOnError extends boolean = false,
|
|
59
61
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
60
62
|
>(
|
|
61
|
-
options: RequestOptions<TResponseStyle, ThrowOnError>,
|
|
63
|
+
options: RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
62
64
|
) => {
|
|
63
65
|
const opts = {
|
|
64
66
|
..._config,
|
|
@@ -100,11 +102,11 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
100
102
|
},
|
|
101
103
|
);
|
|
102
104
|
|
|
103
|
-
return { opts, req };
|
|
105
|
+
return { opts, req, url };
|
|
104
106
|
};
|
|
105
107
|
|
|
106
|
-
const
|
|
107
|
-
const { opts, req
|
|
108
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
109
|
+
const { opts, req, url } = requestOptions(options);
|
|
108
110
|
|
|
109
111
|
if (opts.security) {
|
|
110
112
|
await setAuthParams({
|
|
@@ -117,6 +119,13 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
117
119
|
await opts.requestValidator(opts);
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
return { opts, req, url };
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const request: Client['request'] = async (options) => {
|
|
126
|
+
// @ts-expect-error
|
|
127
|
+
const { opts, req: initialReq } = await beforeRequest(options);
|
|
128
|
+
|
|
120
129
|
let req = initialReq;
|
|
121
130
|
|
|
122
131
|
for (const fn of interceptors.request._fns) {
|
|
@@ -190,18 +199,34 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
190
199
|
}
|
|
191
200
|
};
|
|
192
201
|
|
|
202
|
+
const makeMethodFn =
|
|
203
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
204
|
+
request({ ...options, method });
|
|
205
|
+
|
|
206
|
+
const makeSseFn =
|
|
207
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
208
|
+
const { opts, url } = await beforeRequest(options);
|
|
209
|
+
return createSseClient({
|
|
210
|
+
...opts,
|
|
211
|
+
body: opts.body as BodyInit | null | undefined,
|
|
212
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
213
|
+
method,
|
|
214
|
+
url,
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
193
218
|
return {
|
|
194
219
|
buildUrl,
|
|
195
|
-
connect: (
|
|
196
|
-
delete: (
|
|
197
|
-
get: (
|
|
220
|
+
connect: makeMethodFn('CONNECT'),
|
|
221
|
+
delete: makeMethodFn('DELETE'),
|
|
222
|
+
get: makeMethodFn('GET'),
|
|
198
223
|
getConfig,
|
|
199
|
-
head: (
|
|
224
|
+
head: makeMethodFn('HEAD'),
|
|
200
225
|
interceptors,
|
|
201
|
-
options: (
|
|
202
|
-
patch: (
|
|
203
|
-
post: (
|
|
204
|
-
put: (
|
|
226
|
+
options: makeMethodFn('OPTIONS'),
|
|
227
|
+
patch: makeMethodFn('PATCH'),
|
|
228
|
+
post: makeMethodFn('POST'),
|
|
229
|
+
put: makeMethodFn('PUT'),
|
|
205
230
|
request,
|
|
206
231
|
requestOptions: (options) => {
|
|
207
232
|
if (options.security) {
|
|
@@ -217,6 +242,17 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
217
242
|
return requestOptions(options).req;
|
|
218
243
|
},
|
|
219
244
|
setConfig,
|
|
220
|
-
|
|
221
|
-
|
|
245
|
+
sse: {
|
|
246
|
+
connect: makeSseFn('CONNECT'),
|
|
247
|
+
delete: makeSseFn('DELETE'),
|
|
248
|
+
get: makeSseFn('GET'),
|
|
249
|
+
head: makeSseFn('HEAD'),
|
|
250
|
+
options: makeSseFn('OPTIONS'),
|
|
251
|
+
patch: makeSseFn('PATCH'),
|
|
252
|
+
post: makeSseFn('POST'),
|
|
253
|
+
put: makeSseFn('PUT'),
|
|
254
|
+
trace: makeSseFn('TRACE'),
|
|
255
|
+
},
|
|
256
|
+
trace: makeMethodFn('TRACE'),
|
|
257
|
+
} as Client;
|
|
222
258
|
};
|
|
@@ -8,6 +8,10 @@ import type {
|
|
|
8
8
|
import type { Injector } from '@angular/core';
|
|
9
9
|
|
|
10
10
|
import type { Auth } from '../core/auth';
|
|
11
|
+
import type {
|
|
12
|
+
ServerSentEventsOptions,
|
|
13
|
+
ServerSentEventsResult,
|
|
14
|
+
} from '../core/serverSentEvents';
|
|
11
15
|
import type {
|
|
12
16
|
Client as CoreClient,
|
|
13
17
|
Config as CoreConfig,
|
|
@@ -61,13 +65,22 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
export interface RequestOptions<
|
|
68
|
+
TData = unknown,
|
|
64
69
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
65
70
|
ThrowOnError extends boolean = boolean,
|
|
66
71
|
Url extends string = string,
|
|
67
72
|
> extends Config<{
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
responseStyle: TResponseStyle;
|
|
74
|
+
throwOnError: ThrowOnError;
|
|
75
|
+
}>,
|
|
76
|
+
Pick<
|
|
77
|
+
ServerSentEventsOptions<TData>,
|
|
78
|
+
| 'onSseError'
|
|
79
|
+
| 'onSseEvent'
|
|
80
|
+
| 'sseDefaultRetryDelay'
|
|
81
|
+
| 'sseMaxRetryAttempts'
|
|
82
|
+
| 'sseMaxRetryDelay'
|
|
83
|
+
> {
|
|
71
84
|
/**
|
|
72
85
|
* Any body that you want to add to your request.
|
|
73
86
|
*
|
|
@@ -91,7 +104,7 @@ export interface ResolvedRequestOptions<
|
|
|
91
104
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
92
105
|
ThrowOnError extends boolean = boolean,
|
|
93
106
|
Url extends string = string,
|
|
94
|
-
> extends RequestOptions<TResponseStyle, ThrowOnError, Url> {
|
|
107
|
+
> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
95
108
|
serializedBody?: string;
|
|
96
109
|
}
|
|
97
110
|
|
|
@@ -148,24 +161,36 @@ type MethodFn = <
|
|
|
148
161
|
ThrowOnError extends boolean = false,
|
|
149
162
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
150
163
|
>(
|
|
151
|
-
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'>,
|
|
164
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
152
165
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
153
166
|
|
|
167
|
+
type SseFn = <
|
|
168
|
+
TData = unknown,
|
|
169
|
+
TError = unknown,
|
|
170
|
+
ThrowOnError extends boolean = false,
|
|
171
|
+
TResponseStyle extends ResponseStyle = 'fields',
|
|
172
|
+
>(
|
|
173
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'>,
|
|
174
|
+
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
175
|
+
|
|
154
176
|
type RequestFn = <
|
|
155
177
|
TData = unknown,
|
|
156
178
|
TError = unknown,
|
|
157
179
|
ThrowOnError extends boolean = false,
|
|
158
180
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
159
181
|
>(
|
|
160
|
-
options: Omit<RequestOptions<TResponseStyle, ThrowOnError>, 'method'> &
|
|
161
|
-
Pick<
|
|
182
|
+
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
|
|
183
|
+
Pick<
|
|
184
|
+
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
|
|
185
|
+
'method'
|
|
186
|
+
>,
|
|
162
187
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
163
188
|
|
|
164
189
|
type RequestOptionsFn = <
|
|
165
190
|
ThrowOnError extends boolean = false,
|
|
166
191
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
167
192
|
>(
|
|
168
|
-
options: RequestOptions<TResponseStyle, ThrowOnError>,
|
|
193
|
+
options: RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
169
194
|
) => HttpRequest<unknown>;
|
|
170
195
|
|
|
171
196
|
type BuildUrlFn = <
|
|
@@ -179,14 +204,19 @@ type BuildUrlFn = <
|
|
|
179
204
|
options: Pick<TData, 'url'> & Options<TData>,
|
|
180
205
|
) => string;
|
|
181
206
|
|
|
182
|
-
export type Client = CoreClient<
|
|
207
|
+
export type Client = CoreClient<
|
|
208
|
+
RequestFn,
|
|
209
|
+
Config,
|
|
210
|
+
MethodFn,
|
|
211
|
+
BuildUrlFn,
|
|
212
|
+
SseFn
|
|
213
|
+
> & {
|
|
183
214
|
interceptors: Middleware<
|
|
184
215
|
HttpRequest<unknown>,
|
|
185
216
|
HttpResponse<unknown>,
|
|
186
217
|
unknown,
|
|
187
218
|
ResolvedRequestOptions
|
|
188
219
|
>;
|
|
189
|
-
|
|
190
220
|
requestOptions: RequestOptionsFn;
|
|
191
221
|
};
|
|
192
222
|
|
|
@@ -215,9 +245,10 @@ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
|
215
245
|
export type Options<
|
|
216
246
|
TData extends TDataShape = TDataShape,
|
|
217
247
|
ThrowOnError extends boolean = boolean,
|
|
248
|
+
TResponse = unknown,
|
|
218
249
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
219
250
|
> = OmitKeys<
|
|
220
|
-
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
251
|
+
RequestOptions<TResponse, TResponseStyle, ThrowOnError>,
|
|
221
252
|
'body' | 'path' | 'query' | 'url'
|
|
222
253
|
> &
|
|
223
254
|
Omit<TData, 'url'>;
|
|
@@ -229,18 +260,22 @@ export type OptionsLegacyParser<
|
|
|
229
260
|
> = TData extends { body?: any }
|
|
230
261
|
? TData extends { headers?: any }
|
|
231
262
|
? OmitKeys<
|
|
232
|
-
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
263
|
+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
233
264
|
'body' | 'headers' | 'url'
|
|
234
265
|
> &
|
|
235
266
|
TData
|
|
236
|
-
: OmitKeys<
|
|
267
|
+
: OmitKeys<
|
|
268
|
+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
269
|
+
'body' | 'url'
|
|
270
|
+
> &
|
|
237
271
|
TData &
|
|
238
|
-
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'headers'>
|
|
272
|
+
Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'headers'>
|
|
239
273
|
: TData extends { headers?: any }
|
|
240
274
|
? OmitKeys<
|
|
241
|
-
RequestOptions<TResponseStyle, ThrowOnError>,
|
|
275
|
+
RequestOptions<unknown, TResponseStyle, ThrowOnError>,
|
|
242
276
|
'headers' | 'url'
|
|
243
277
|
> &
|
|
244
278
|
TData &
|
|
245
|
-
Pick<RequestOptions<TResponseStyle, ThrowOnError>, 'body'>
|
|
246
|
-
: OmitKeys<RequestOptions<TResponseStyle, ThrowOnError>, 'url'> &
|
|
279
|
+
Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'body'>
|
|
280
|
+
: OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, 'url'> &
|
|
281
|
+
TData;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { AxiosError, AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import { createSseClient } from '../core/serverSentEvents';
|
|
5
|
+
import type { HttpMethod } from '../core/types';
|
|
6
|
+
import type { Client, Config, RequestOptions } from './types';
|
|
5
7
|
import {
|
|
6
8
|
buildUrl,
|
|
7
9
|
createConfig,
|
|
@@ -36,8 +38,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
36
38
|
return getConfig();
|
|
37
39
|
};
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
const request: Client['request'] = async (options) => {
|
|
41
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
41
42
|
const opts = {
|
|
42
43
|
..._config,
|
|
43
44
|
...options,
|
|
@@ -62,6 +63,13 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
62
63
|
|
|
63
64
|
const url = buildUrl(opts);
|
|
64
65
|
|
|
66
|
+
return { opts, url };
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
const request: Client['request'] = async (options) => {
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
const { opts, url } = await beforeRequest(options);
|
|
65
73
|
try {
|
|
66
74
|
// assign Axios here for consistency with fetch
|
|
67
75
|
const _axios = opts.axios!;
|
|
@@ -104,18 +112,49 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
104
112
|
}
|
|
105
113
|
};
|
|
106
114
|
|
|
115
|
+
const makeMethodFn =
|
|
116
|
+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
117
|
+
request({ ...options, method });
|
|
118
|
+
|
|
119
|
+
const makeSseFn =
|
|
120
|
+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
121
|
+
const { opts, url } = await beforeRequest(options);
|
|
122
|
+
return createSseClient({
|
|
123
|
+
...opts,
|
|
124
|
+
body: opts.body as BodyInit | null | undefined,
|
|
125
|
+
headers: opts.headers as Record<string, string>,
|
|
126
|
+
method,
|
|
127
|
+
// @ts-expect-error
|
|
128
|
+
signal: opts.signal,
|
|
129
|
+
url,
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
107
133
|
return {
|
|
108
134
|
buildUrl,
|
|
109
|
-
|
|
110
|
-
|
|
135
|
+
connect: makeMethodFn('CONNECT'),
|
|
136
|
+
delete: makeMethodFn('DELETE'),
|
|
137
|
+
get: makeMethodFn('GET'),
|
|
111
138
|
getConfig,
|
|
112
|
-
head: (
|
|
139
|
+
head: makeMethodFn('HEAD'),
|
|
113
140
|
instance,
|
|
114
|
-
options: (
|
|
115
|
-
patch: (
|
|
116
|
-
post: (
|
|
117
|
-
put: (
|
|
141
|
+
options: makeMethodFn('OPTIONS'),
|
|
142
|
+
patch: makeMethodFn('PATCH'),
|
|
143
|
+
post: makeMethodFn('POST'),
|
|
144
|
+
put: makeMethodFn('PUT'),
|
|
118
145
|
request,
|
|
119
146
|
setConfig,
|
|
147
|
+
sse: {
|
|
148
|
+
connect: makeSseFn('CONNECT'),
|
|
149
|
+
delete: makeSseFn('DELETE'),
|
|
150
|
+
get: makeSseFn('GET'),
|
|
151
|
+
head: makeSseFn('HEAD'),
|
|
152
|
+
options: makeSseFn('OPTIONS'),
|
|
153
|
+
patch: makeSseFn('PATCH'),
|
|
154
|
+
post: makeSseFn('POST'),
|
|
155
|
+
put: makeSseFn('PUT'),
|
|
156
|
+
trace: makeSseFn('TRACE'),
|
|
157
|
+
},
|
|
158
|
+
trace: makeMethodFn('TRACE'),
|
|
120
159
|
} as Client;
|
|
121
160
|
};
|
|
@@ -8,6 +8,10 @@ import type {
|
|
|
8
8
|
} from 'axios';
|
|
9
9
|
|
|
10
10
|
import type { Auth } from '../core/auth';
|
|
11
|
+
import type {
|
|
12
|
+
ServerSentEventsOptions,
|
|
13
|
+
ServerSentEventsResult,
|
|
14
|
+
} from '../core/serverSentEvents';
|
|
11
15
|
import type {
|
|
12
16
|
Client as CoreClient,
|
|
13
17
|
Config as CoreConfig,
|
|
@@ -54,11 +58,20 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
export interface RequestOptions<
|
|
61
|
+
TData = unknown,
|
|
57
62
|
ThrowOnError extends boolean = boolean,
|
|
58
63
|
Url extends string = string,
|
|
59
64
|
> extends Config<{
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
throwOnError: ThrowOnError;
|
|
66
|
+
}>,
|
|
67
|
+
Pick<
|
|
68
|
+
ServerSentEventsOptions<TData>,
|
|
69
|
+
| 'onSseError'
|
|
70
|
+
| 'onSseEvent'
|
|
71
|
+
| 'sseDefaultRetryDelay'
|
|
72
|
+
| 'sseMaxRetryAttempts'
|
|
73
|
+
| 'sseMaxRetryDelay'
|
|
74
|
+
> {
|
|
62
75
|
/**
|
|
63
76
|
* Any body that you want to add to your request.
|
|
64
77
|
*
|
|
@@ -74,6 +87,11 @@ export interface RequestOptions<
|
|
|
74
87
|
url: Url;
|
|
75
88
|
}
|
|
76
89
|
|
|
90
|
+
export interface ClientOptions {
|
|
91
|
+
baseURL?: string;
|
|
92
|
+
throwOnError?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
77
95
|
export type RequestResult<
|
|
78
96
|
TData = unknown,
|
|
79
97
|
TError = unknown,
|
|
@@ -98,26 +116,29 @@ export type RequestResult<
|
|
|
98
116
|
})
|
|
99
117
|
>;
|
|
100
118
|
|
|
101
|
-
export interface ClientOptions {
|
|
102
|
-
baseURL?: string;
|
|
103
|
-
throwOnError?: boolean;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
119
|
type MethodFn = <
|
|
107
120
|
TData = unknown,
|
|
108
121
|
TError = unknown,
|
|
109
122
|
ThrowOnError extends boolean = false,
|
|
110
123
|
>(
|
|
111
|
-
options: Omit<RequestOptions<ThrowOnError>, 'method'>,
|
|
124
|
+
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
112
125
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
113
126
|
|
|
127
|
+
type SseFn = <
|
|
128
|
+
TData = unknown,
|
|
129
|
+
TError = unknown,
|
|
130
|
+
ThrowOnError extends boolean = false,
|
|
131
|
+
>(
|
|
132
|
+
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
133
|
+
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
134
|
+
|
|
114
135
|
type RequestFn = <
|
|
115
136
|
TData = unknown,
|
|
116
137
|
TError = unknown,
|
|
117
138
|
ThrowOnError extends boolean = false,
|
|
118
139
|
>(
|
|
119
|
-
options: Omit<RequestOptions<ThrowOnError>, 'method'> &
|
|
120
|
-
Pick<Required<RequestOptions<ThrowOnError>>, 'method'>,
|
|
140
|
+
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
141
|
+
Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>,
|
|
121
142
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
122
143
|
|
|
123
144
|
type BuildUrlFn = <
|
|
@@ -131,7 +152,13 @@ type BuildUrlFn = <
|
|
|
131
152
|
options: Pick<TData, 'url'> & Omit<Options<TData>, 'axios'>,
|
|
132
153
|
) => string;
|
|
133
154
|
|
|
134
|
-
export type Client = CoreClient<
|
|
155
|
+
export type Client = CoreClient<
|
|
156
|
+
RequestFn,
|
|
157
|
+
Config,
|
|
158
|
+
MethodFn,
|
|
159
|
+
BuildUrlFn,
|
|
160
|
+
SseFn
|
|
161
|
+
> & {
|
|
135
162
|
instance: AxiosInstance;
|
|
136
163
|
};
|
|
137
164
|
|
|
@@ -160,7 +187,11 @@ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
|
160
187
|
export type Options<
|
|
161
188
|
TData extends TDataShape = TDataShape,
|
|
162
189
|
ThrowOnError extends boolean = boolean,
|
|
163
|
-
|
|
190
|
+
TResponse = unknown,
|
|
191
|
+
> = OmitKeys<
|
|
192
|
+
RequestOptions<TResponse, ThrowOnError>,
|
|
193
|
+
'body' | 'path' | 'query' | 'url'
|
|
194
|
+
> &
|
|
164
195
|
Omit<TData, 'url'>;
|
|
165
196
|
|
|
166
197
|
export type OptionsLegacyParser<
|
|
@@ -168,12 +199,16 @@ export type OptionsLegacyParser<
|
|
|
168
199
|
ThrowOnError extends boolean = boolean,
|
|
169
200
|
> = TData extends { body?: any }
|
|
170
201
|
? TData extends { headers?: any }
|
|
171
|
-
? OmitKeys<
|
|
172
|
-
|
|
202
|
+
? OmitKeys<
|
|
203
|
+
RequestOptions<unknown, ThrowOnError>,
|
|
204
|
+
'body' | 'headers' | 'url'
|
|
205
|
+
> &
|
|
206
|
+
TData
|
|
207
|
+
: OmitKeys<RequestOptions<unknown, ThrowOnError>, 'body' | 'url'> &
|
|
173
208
|
TData &
|
|
174
|
-
Pick<RequestOptions<ThrowOnError>, 'headers'>
|
|
209
|
+
Pick<RequestOptions<unknown, ThrowOnError>, 'headers'>
|
|
175
210
|
: TData extends { headers?: any }
|
|
176
|
-
? OmitKeys<RequestOptions<ThrowOnError>, 'headers' | 'url'> &
|
|
211
|
+
? OmitKeys<RequestOptions<unknown, ThrowOnError>, 'headers' | 'url'> &
|
|
177
212
|
TData &
|
|
178
|
-
Pick<RequestOptions<ThrowOnError>, 'body'>
|
|
179
|
-
: OmitKeys<RequestOptions<ThrowOnError>, 'url'> & TData;
|
|
213
|
+
Pick<RequestOptions<unknown, ThrowOnError>, 'body'>
|
|
214
|
+
: OmitKeys<RequestOptions<unknown, ThrowOnError>, 'url'> & TData;
|
|
@@ -1,93 +1,13 @@
|
|
|
1
1
|
import { getAuthToken } from '../core/auth';
|
|
2
|
-
import type {
|
|
3
|
-
QuerySerializer,
|
|
4
|
-
QuerySerializerOptions,
|
|
5
|
-
} from '../core/bodySerializer';
|
|
6
|
-
import type { ArraySeparatorStyle } from '../core/pathSerializer';
|
|
2
|
+
import type { QuerySerializerOptions } from '../core/bodySerializer';
|
|
7
3
|
import {
|
|
8
4
|
serializeArrayParam,
|
|
9
5
|
serializeObjectParam,
|
|
10
6
|
serializePrimitiveParam,
|
|
11
7
|
} from '../core/pathSerializer';
|
|
8
|
+
import { getUrl } from '../core/utils';
|
|
12
9
|
import type { Client, ClientOptions, Config, RequestOptions } from './types';
|
|
13
10
|
|
|
14
|
-
interface PathSerializer {
|
|
15
|
-
path: Record<string, unknown>;
|
|
16
|
-
url: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
20
|
-
|
|
21
|
-
const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
22
|
-
let url = _url;
|
|
23
|
-
const matches = _url.match(PATH_PARAM_RE);
|
|
24
|
-
if (matches) {
|
|
25
|
-
for (const match of matches) {
|
|
26
|
-
let explode = false;
|
|
27
|
-
let name = match.substring(1, match.length - 1);
|
|
28
|
-
let style: ArraySeparatorStyle = 'simple';
|
|
29
|
-
|
|
30
|
-
if (name.endsWith('*')) {
|
|
31
|
-
explode = true;
|
|
32
|
-
name = name.substring(0, name.length - 1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (name.startsWith('.')) {
|
|
36
|
-
name = name.substring(1);
|
|
37
|
-
style = 'label';
|
|
38
|
-
} else if (name.startsWith(';')) {
|
|
39
|
-
name = name.substring(1);
|
|
40
|
-
style = 'matrix';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const value = path[name];
|
|
44
|
-
|
|
45
|
-
if (value === undefined || value === null) {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (Array.isArray(value)) {
|
|
50
|
-
url = url.replace(
|
|
51
|
-
match,
|
|
52
|
-
serializeArrayParam({ explode, name, style, value }),
|
|
53
|
-
);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (typeof value === 'object') {
|
|
58
|
-
url = url.replace(
|
|
59
|
-
match,
|
|
60
|
-
serializeObjectParam({
|
|
61
|
-
explode,
|
|
62
|
-
name,
|
|
63
|
-
style,
|
|
64
|
-
value: value as Record<string, unknown>,
|
|
65
|
-
valueOnly: true,
|
|
66
|
-
}),
|
|
67
|
-
);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (style === 'matrix') {
|
|
72
|
-
url = url.replace(
|
|
73
|
-
match,
|
|
74
|
-
`;${serializePrimitiveParam({
|
|
75
|
-
name,
|
|
76
|
-
value: value as string,
|
|
77
|
-
})}`,
|
|
78
|
-
);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const replaceValue = encodeURIComponent(
|
|
83
|
-
style === 'label' ? `.${value as string}` : (value as string),
|
|
84
|
-
);
|
|
85
|
-
url = url.replace(match, replaceValue);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return url;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
11
|
export const createQuerySerializer = <T = unknown>({
|
|
92
12
|
allowReserved,
|
|
93
13
|
array,
|
|
@@ -203,8 +123,9 @@ export const setAuthParams = async ({
|
|
|
203
123
|
}
|
|
204
124
|
};
|
|
205
125
|
|
|
206
|
-
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
207
|
-
|
|
126
|
+
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
127
|
+
getUrl({
|
|
128
|
+
baseUrl: options.baseURL as string,
|
|
208
129
|
path: options.path,
|
|
209
130
|
// let `paramsSerializer()` handle query params if it exists
|
|
210
131
|
query: !options.paramsSerializer ? options.query : undefined,
|
|
@@ -214,34 +135,6 @@ export const buildUrl: Client['buildUrl'] = (options) => {
|
|
|
214
135
|
: createQuerySerializer(options.querySerializer),
|
|
215
136
|
url: options.url,
|
|
216
137
|
});
|
|
217
|
-
return url;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export const getUrl = ({
|
|
221
|
-
path,
|
|
222
|
-
query,
|
|
223
|
-
querySerializer,
|
|
224
|
-
url: _url,
|
|
225
|
-
}: {
|
|
226
|
-
path?: Record<string, unknown>;
|
|
227
|
-
query?: Record<string, unknown>;
|
|
228
|
-
querySerializer: QuerySerializer;
|
|
229
|
-
url: string;
|
|
230
|
-
}) => {
|
|
231
|
-
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
232
|
-
let url = pathUrl;
|
|
233
|
-
if (path) {
|
|
234
|
-
url = defaultPathSerializer({ path, url });
|
|
235
|
-
}
|
|
236
|
-
let search = query ? querySerializer(query) : '';
|
|
237
|
-
if (search.startsWith('?')) {
|
|
238
|
-
search = search.substring(1);
|
|
239
|
-
}
|
|
240
|
-
if (search) {
|
|
241
|
-
url += `?${search}`;
|
|
242
|
-
}
|
|
243
|
-
return url;
|
|
244
|
-
};
|
|
245
138
|
|
|
246
139
|
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
247
140
|
const config = { ...a, ...b };
|