@hey-api/openapi-ts 0.90.10 → 0.91.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/clients/angular/client.ts +23 -49
- package/dist/clients/angular/types.ts +11 -34
- package/dist/clients/angular/utils.ts +6 -22
- package/dist/clients/axios/client.ts +16 -27
- package/dist/clients/axios/types.ts +17 -54
- package/dist/clients/axios/utils.ts +3 -8
- package/dist/clients/core/auth.ts +1 -2
- package/dist/clients/core/bodySerializer.ts +5 -21
- package/dist/clients/core/params.ts +3 -10
- package/dist/clients/core/pathSerializer.ts +4 -14
- package/dist/clients/core/queryKeySerializer.ts +6 -25
- package/dist/clients/core/serverSentEvents.ts +8 -31
- package/dist/clients/core/types.ts +4 -18
- package/dist/clients/core/utils.ts +1 -4
- package/dist/clients/fetch/client.ts +25 -48
- package/dist/clients/fetch/types.ts +12 -40
- package/dist/clients/fetch/utils.ts +6 -22
- package/dist/clients/ky/client.ts +27 -58
- package/dist/clients/ky/types.ts +19 -47
- package/dist/clients/ky/utils.ts +6 -22
- package/dist/clients/next/client.ts +30 -47
- package/dist/clients/next/types.ts +13 -47
- package/dist/clients/next/utils.ts +8 -31
- package/dist/clients/nuxt/client.ts +18 -37
- package/dist/clients/nuxt/types.ts +12 -31
- package/dist/clients/nuxt/utils.ts +5 -17
- package/dist/clients/ofetch/client.ts +34 -60
- package/dist/clients/ofetch/types.ts +13 -44
- package/dist/clients/ofetch/utils.ts +20 -58
- package/dist/index.d.mts +8731 -54
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -3
- package/dist/{openApi-Gs-XGatv.mjs → init-CvGgSlz8.mjs} +134 -8346
- package/dist/init-CvGgSlz8.mjs.map +1 -0
- package/dist/internal.d.mts +2 -68
- package/dist/internal.d.mts.map +1 -0
- package/dist/internal.mjs +2 -2
- package/dist/run.d.mts +0 -1
- package/dist/run.mjs +5 -7
- package/dist/run.mjs.map +1 -1
- package/dist/src-Dgh53q8K.mjs +228 -0
- package/dist/src-Dgh53q8K.mjs.map +1 -0
- package/dist/types-Ba27ofyy.d.mts +157 -0
- package/dist/types-Ba27ofyy.d.mts.map +1 -0
- package/package.json +39 -58
- package/dist/index.cjs +0 -30
- package/dist/index.d.cts +0 -990
- package/dist/internal.cjs +0 -6
- package/dist/internal.d.cts +0 -99
- package/dist/openApi-Dy5wknYZ.cjs +0 -22032
- package/dist/openApi-Dy5wknYZ.cjs.map +0 -1
- package/dist/openApi-Gs-XGatv.mjs.map +0 -1
- package/dist/run.cjs +0 -61
- package/dist/run.cjs.map +0 -1
- package/dist/run.d.cts +0 -2
- package/dist/src-DMQOp4DI.cjs +0 -476
- package/dist/src-DMQOp4DI.cjs.map +0 -1
- package/dist/src-YIQMkx2V.mjs +0 -455
- package/dist/src-YIQMkx2V.mjs.map +0 -1
- package/dist/types-BcLsQaJ_.d.cts +0 -15600
- package/dist/types-CLcjoomL.d.mts +0 -16472
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { HttpResponse } from '@angular/common/http';
|
|
2
|
-
import {
|
|
3
|
-
HttpClient,
|
|
4
|
-
HttpErrorResponse,
|
|
5
|
-
HttpEventType,
|
|
6
|
-
HttpRequest,
|
|
7
|
-
} from '@angular/common/http';
|
|
2
|
+
import { HttpClient, HttpErrorResponse, HttpEventType, HttpRequest } from '@angular/common/http';
|
|
8
3
|
import {
|
|
9
4
|
assertInInjectionContext,
|
|
10
5
|
inject,
|
|
@@ -73,9 +68,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
73
68
|
|
|
74
69
|
if (!opts.httpClient) {
|
|
75
70
|
if (opts.injector) {
|
|
76
|
-
opts.httpClient = runInInjectionContext(opts.injector, () =>
|
|
77
|
-
inject(HttpClient),
|
|
78
|
-
);
|
|
71
|
+
opts.httpClient = runInInjectionContext(opts.injector, () => inject(HttpClient));
|
|
79
72
|
} else {
|
|
80
73
|
assertInInjectionContext(requestOptions);
|
|
81
74
|
opts.httpClient = inject(HttpClient);
|
|
@@ -93,15 +86,10 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
93
86
|
|
|
94
87
|
const url = buildUrl(opts as any);
|
|
95
88
|
|
|
96
|
-
const req = new HttpRequest<unknown>(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
redirect: 'follow',
|
|
102
|
-
...opts,
|
|
103
|
-
},
|
|
104
|
-
);
|
|
89
|
+
const req = new HttpRequest<unknown>(opts.method ?? 'GET', url, getValidRequestBody(opts), {
|
|
90
|
+
redirect: 'follow',
|
|
91
|
+
...opts,
|
|
92
|
+
});
|
|
105
93
|
|
|
106
94
|
return { opts, req, url };
|
|
107
95
|
};
|
|
@@ -166,9 +154,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
166
154
|
bodyResponse = await opts.responseTransformer(bodyResponse);
|
|
167
155
|
}
|
|
168
156
|
|
|
169
|
-
return opts.responseStyle === 'data'
|
|
170
|
-
? bodyResponse
|
|
171
|
-
: { data: bodyResponse, ...result };
|
|
157
|
+
return opts.responseStyle === 'data' ? bodyResponse : { data: bodyResponse, ...result };
|
|
172
158
|
} catch (error) {
|
|
173
159
|
if (error instanceof HttpErrorResponse) {
|
|
174
160
|
result.response = error;
|
|
@@ -178,12 +164,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
178
164
|
|
|
179
165
|
for (const fn of interceptors.error.fns) {
|
|
180
166
|
if (fn) {
|
|
181
|
-
finalError = (await fn(
|
|
182
|
-
finalError,
|
|
183
|
-
result.response as any,
|
|
184
|
-
req,
|
|
185
|
-
opts as any,
|
|
186
|
-
)) as string;
|
|
167
|
+
finalError = (await fn(finalError, result.response as any, req, opts as any)) as string;
|
|
187
168
|
}
|
|
188
169
|
}
|
|
189
170
|
|
|
@@ -200,25 +181,20 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
200
181
|
}
|
|
201
182
|
};
|
|
202
183
|
|
|
203
|
-
const makeMethodFn =
|
|
204
|
-
(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
| null
|
|
218
|
-
| undefined,
|
|
219
|
-
url,
|
|
220
|
-
});
|
|
221
|
-
};
|
|
184
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
185
|
+
request({ ...options, method });
|
|
186
|
+
|
|
187
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
188
|
+
const { opts, url } = await beforeRequest(options);
|
|
189
|
+
return createSseClient({
|
|
190
|
+
...opts,
|
|
191
|
+
body: opts.body as BodyInit | null | undefined,
|
|
192
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
193
|
+
method,
|
|
194
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
195
|
+
url,
|
|
196
|
+
});
|
|
197
|
+
};
|
|
222
198
|
|
|
223
199
|
return {
|
|
224
200
|
buildUrl,
|
|
@@ -239,9 +215,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
239
215
|
}
|
|
240
216
|
|
|
241
217
|
if (options.requestValidator) {
|
|
242
|
-
throw new Error(
|
|
243
|
-
'Request validation is not supported in requestOptions',
|
|
244
|
-
);
|
|
218
|
+
throw new Error('Request validation is not supported in requestOptions');
|
|
245
219
|
}
|
|
246
220
|
|
|
247
221
|
return requestOptions(options).req;
|
|
@@ -12,17 +12,13 @@ import type {
|
|
|
12
12
|
ServerSentEventsOptions,
|
|
13
13
|
ServerSentEventsResult,
|
|
14
14
|
} from '../core/serverSentEvents';
|
|
15
|
-
import type {
|
|
16
|
-
Client as CoreClient,
|
|
17
|
-
Config as CoreConfig,
|
|
18
|
-
} from '../core/types';
|
|
15
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
19
16
|
import type { Middleware } from './utils';
|
|
20
17
|
|
|
21
18
|
export type ResponseStyle = 'data' | 'fields';
|
|
22
19
|
|
|
23
20
|
export interface Config<T extends ClientOptions = ClientOptions>
|
|
24
|
-
extends Omit<RequestInit, 'body' | 'headers' | 'method'>,
|
|
25
|
-
Omit<CoreConfig, 'headers'> {
|
|
21
|
+
extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Omit<CoreConfig, 'headers'> {
|
|
26
22
|
/**
|
|
27
23
|
* Base URL for all requests made by this client.
|
|
28
24
|
*/
|
|
@@ -37,13 +33,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
37
33
|
| HttpHeaders
|
|
38
34
|
| Record<
|
|
39
35
|
string,
|
|
40
|
-
| string
|
|
41
|
-
| number
|
|
42
|
-
| boolean
|
|
43
|
-
| (string | number | boolean)[]
|
|
44
|
-
| null
|
|
45
|
-
| undefined
|
|
46
|
-
| unknown
|
|
36
|
+
string | number | boolean | (string | number | boolean)[] | null | undefined | unknown
|
|
47
37
|
>;
|
|
48
38
|
/**
|
|
49
39
|
* The HTTP client to use for making requests.
|
|
@@ -69,7 +59,9 @@ export interface RequestOptions<
|
|
|
69
59
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
70
60
|
ThrowOnError extends boolean = boolean,
|
|
71
61
|
Url extends string = string,
|
|
72
|
-
>
|
|
62
|
+
>
|
|
63
|
+
extends
|
|
64
|
+
Config<{
|
|
73
65
|
responseStyle: TResponseStyle;
|
|
74
66
|
throwOnError: ThrowOnError;
|
|
75
67
|
}>,
|
|
@@ -120,21 +112,15 @@ export type RequestResult<
|
|
|
120
112
|
? TData[keyof TData]
|
|
121
113
|
: TData
|
|
122
114
|
: {
|
|
123
|
-
data: TData extends Record<string, unknown>
|
|
124
|
-
? TData[keyof TData]
|
|
125
|
-
: TData;
|
|
115
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
126
116
|
request: HttpRequest<unknown>;
|
|
127
117
|
response: HttpResponse<TData>;
|
|
128
118
|
}
|
|
129
119
|
: TResponseStyle extends 'data'
|
|
130
|
-
?
|
|
131
|
-
| (TData extends Record<string, unknown> ? TData[keyof TData] : TData)
|
|
132
|
-
| undefined
|
|
120
|
+
? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
|
|
133
121
|
:
|
|
134
122
|
| {
|
|
135
|
-
data: TData extends Record<string, unknown>
|
|
136
|
-
? TData[keyof TData]
|
|
137
|
-
: TData;
|
|
123
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
138
124
|
error: undefined;
|
|
139
125
|
request: HttpRequest<unknown>;
|
|
140
126
|
response: HttpResponse<TData>;
|
|
@@ -180,10 +166,7 @@ type RequestFn = <
|
|
|
180
166
|
TResponseStyle extends ResponseStyle = 'fields',
|
|
181
167
|
>(
|
|
182
168
|
options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, 'method'> &
|
|
183
|
-
Pick<
|
|
184
|
-
Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>,
|
|
185
|
-
'method'
|
|
186
|
-
>,
|
|
169
|
+
Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, 'method'>,
|
|
187
170
|
) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
188
171
|
|
|
189
172
|
type RequestOptionsFn = <
|
|
@@ -204,13 +187,7 @@ type BuildUrlFn = <
|
|
|
204
187
|
options: TData & Options<TData>,
|
|
205
188
|
) => string;
|
|
206
189
|
|
|
207
|
-
export type Client = CoreClient<
|
|
208
|
-
RequestFn,
|
|
209
|
-
Config,
|
|
210
|
-
MethodFn,
|
|
211
|
-
BuildUrlFn,
|
|
212
|
-
SseFn
|
|
213
|
-
> & {
|
|
190
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
214
191
|
interceptors: Middleware<
|
|
215
192
|
HttpRequest<unknown>,
|
|
216
193
|
HttpResponse<unknown>,
|
|
@@ -52,10 +52,7 @@ const defaultPathSerializer = ({ path, url: _url }: PathSerializer) => {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (Array.isArray(value)) {
|
|
55
|
-
url = url.replace(
|
|
56
|
-
match,
|
|
57
|
-
serializeArrayParam({ explode, name, style, value }),
|
|
58
|
-
);
|
|
55
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
59
56
|
continue;
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -162,10 +159,7 @@ export const getParseAs = (
|
|
|
162
159
|
return;
|
|
163
160
|
}
|
|
164
161
|
|
|
165
|
-
if (
|
|
166
|
-
cleanContent.startsWith('application/json') ||
|
|
167
|
-
cleanContent.endsWith('+json')
|
|
168
|
-
) {
|
|
162
|
+
if (cleanContent.startsWith('application/json') || cleanContent.endsWith('+json')) {
|
|
169
163
|
return 'json';
|
|
170
164
|
}
|
|
171
165
|
|
|
@@ -174,9 +168,7 @@ export const getParseAs = (
|
|
|
174
168
|
}
|
|
175
169
|
|
|
176
170
|
if (
|
|
177
|
-
['application/', 'audio/', 'image/', 'video/'].some((type) =>
|
|
178
|
-
cleanContent.startsWith(type),
|
|
179
|
-
)
|
|
171
|
+
['application/', 'audio/', 'image/', 'video/'].some((type) => cleanContent.startsWith(type))
|
|
180
172
|
) {
|
|
181
173
|
return 'blob';
|
|
182
174
|
}
|
|
@@ -308,9 +300,7 @@ export const mergeHeaders = (
|
|
|
308
300
|
// content value in OpenAPI specification is 'application/json'
|
|
309
301
|
mergedHeaders = mergedHeaders.set(
|
|
310
302
|
key,
|
|
311
|
-
typeof value === 'object'
|
|
312
|
-
? JSON.stringify(value)
|
|
313
|
-
: (value as string),
|
|
303
|
+
typeof value === 'object' ? JSON.stringify(value) : (value as string),
|
|
314
304
|
);
|
|
315
305
|
}
|
|
316
306
|
}
|
|
@@ -327,10 +317,7 @@ type ErrInterceptor<Err, Res, Req, Options> = (
|
|
|
327
317
|
options: Options,
|
|
328
318
|
) => Err | Promise<Err>;
|
|
329
319
|
|
|
330
|
-
type ReqInterceptor<Req, Options> = (
|
|
331
|
-
request: Req,
|
|
332
|
-
options: Options,
|
|
333
|
-
) => Req | Promise<Req>;
|
|
320
|
+
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
334
321
|
|
|
335
322
|
type ResInterceptor<Res, Req, Options> = (
|
|
336
323
|
response: Res,
|
|
@@ -364,10 +351,7 @@ class Interceptors<Interceptor> {
|
|
|
364
351
|
return this.fns.indexOf(id);
|
|
365
352
|
}
|
|
366
353
|
|
|
367
|
-
update(
|
|
368
|
-
id: number | Interceptor,
|
|
369
|
-
fn: Interceptor,
|
|
370
|
-
): number | Interceptor | false {
|
|
354
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false {
|
|
371
355
|
const index = this.getInterceptorIndex(id);
|
|
372
356
|
if (this.fns[index]) {
|
|
373
357
|
this.fns[index] = fn;
|
|
@@ -5,13 +5,7 @@ import { createSseClient } from '../core/serverSentEvents';
|
|
|
5
5
|
import type { HttpMethod } from '../core/types';
|
|
6
6
|
import { getValidRequestBody } from '../core/utils';
|
|
7
7
|
import type { Client, Config, RequestOptions } from './types';
|
|
8
|
-
import {
|
|
9
|
-
buildUrl,
|
|
10
|
-
createConfig,
|
|
11
|
-
mergeConfigs,
|
|
12
|
-
mergeHeaders,
|
|
13
|
-
setAuthParams,
|
|
14
|
-
} from './utils';
|
|
8
|
+
import { buildUrl, createConfig, mergeConfigs, mergeHeaders, setAuthParams } from './utils';
|
|
15
9
|
|
|
16
10
|
export const createClient = (config: Config = {}): Client => {
|
|
17
11
|
let _config = mergeConfigs(createConfig(), config);
|
|
@@ -113,27 +107,22 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
113
107
|
}
|
|
114
108
|
};
|
|
115
109
|
|
|
116
|
-
const makeMethodFn =
|
|
117
|
-
(
|
|
118
|
-
request({ ...options, method });
|
|
110
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
111
|
+
request({ ...options, method });
|
|
119
112
|
|
|
120
|
-
const makeSseFn =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
signal: opts.signal,
|
|
134
|
-
url,
|
|
135
|
-
});
|
|
136
|
-
};
|
|
113
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
114
|
+
const { opts, url } = await beforeRequest(options);
|
|
115
|
+
return createSseClient({
|
|
116
|
+
...opts,
|
|
117
|
+
body: opts.body as BodyInit | null | undefined,
|
|
118
|
+
headers: opts.headers as Record<string, string>,
|
|
119
|
+
method,
|
|
120
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
121
|
+
// @ts-expect-error
|
|
122
|
+
signal: opts.signal,
|
|
123
|
+
url,
|
|
124
|
+
});
|
|
125
|
+
};
|
|
137
126
|
|
|
138
127
|
return {
|
|
139
128
|
buildUrl,
|
|
@@ -12,14 +12,10 @@ import type {
|
|
|
12
12
|
ServerSentEventsOptions,
|
|
13
13
|
ServerSentEventsResult,
|
|
14
14
|
} from '../core/serverSentEvents';
|
|
15
|
-
import type {
|
|
16
|
-
Client as CoreClient,
|
|
17
|
-
Config as CoreConfig,
|
|
18
|
-
} from '../core/types';
|
|
15
|
+
import type { Client as CoreClient, Config as CoreConfig } from '../core/types';
|
|
19
16
|
|
|
20
17
|
export interface Config<T extends ClientOptions = ClientOptions>
|
|
21
|
-
extends Omit<CreateAxiosDefaults, 'auth' | 'baseURL' | 'headers' | 'method'>,
|
|
22
|
-
CoreConfig {
|
|
18
|
+
extends Omit<CreateAxiosDefaults, 'auth' | 'baseURL' | 'headers' | 'method'>, CoreConfig {
|
|
23
19
|
/**
|
|
24
20
|
* Axios implementation. You can use this option to provide either an
|
|
25
21
|
* `AxiosStatic` or an `AxiosInstance`.
|
|
@@ -41,13 +37,7 @@ export interface Config<T extends ClientOptions = ClientOptions>
|
|
|
41
37
|
| AxiosRequestHeaders
|
|
42
38
|
| Record<
|
|
43
39
|
string,
|
|
44
|
-
| string
|
|
45
|
-
| number
|
|
46
|
-
| boolean
|
|
47
|
-
| (string | number | boolean)[]
|
|
48
|
-
| null
|
|
49
|
-
| undefined
|
|
50
|
-
| unknown
|
|
40
|
+
string | number | boolean | (string | number | boolean)[] | null | undefined | unknown
|
|
51
41
|
>;
|
|
52
42
|
/**
|
|
53
43
|
* Throw an error instead of returning it in the response?
|
|
@@ -61,7 +51,9 @@ export interface RequestOptions<
|
|
|
61
51
|
TData = unknown,
|
|
62
52
|
ThrowOnError extends boolean = boolean,
|
|
63
53
|
Url extends string = string,
|
|
64
|
-
>
|
|
54
|
+
>
|
|
55
|
+
extends
|
|
56
|
+
Config<{
|
|
65
57
|
throwOnError: ThrowOnError;
|
|
66
58
|
}>,
|
|
67
59
|
Pick<
|
|
@@ -97,46 +89,26 @@ export type RequestResult<
|
|
|
97
89
|
TError = unknown,
|
|
98
90
|
ThrowOnError extends boolean = boolean,
|
|
99
91
|
> = ThrowOnError extends true
|
|
100
|
-
? Promise<
|
|
101
|
-
AxiosResponse<
|
|
102
|
-
TData extends Record<string, unknown> ? TData[keyof TData] : TData
|
|
103
|
-
>
|
|
104
|
-
>
|
|
92
|
+
? Promise<AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData>>
|
|
105
93
|
: Promise<
|
|
106
|
-
| (AxiosResponse<
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
| (AxiosError<
|
|
110
|
-
TError extends Record<string, unknown> ? TError[keyof TError] : TError
|
|
111
|
-
> & {
|
|
94
|
+
| (AxiosResponse<TData extends Record<string, unknown> ? TData[keyof TData] : TData> & {
|
|
95
|
+
error: undefined;
|
|
96
|
+
})
|
|
97
|
+
| (AxiosError<TError extends Record<string, unknown> ? TError[keyof TError] : TError> & {
|
|
112
98
|
data: undefined;
|
|
113
|
-
error: TError extends Record<string, unknown>
|
|
114
|
-
? TError[keyof TError]
|
|
115
|
-
: TError;
|
|
99
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
116
100
|
})
|
|
117
101
|
>;
|
|
118
102
|
|
|
119
|
-
type MethodFn = <
|
|
120
|
-
TData = unknown,
|
|
121
|
-
TError = unknown,
|
|
122
|
-
ThrowOnError extends boolean = false,
|
|
123
|
-
>(
|
|
103
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
124
104
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
125
105
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
126
106
|
|
|
127
|
-
type SseFn = <
|
|
128
|
-
TData = unknown,
|
|
129
|
-
TError = unknown,
|
|
130
|
-
ThrowOnError extends boolean = false,
|
|
131
|
-
>(
|
|
107
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
132
108
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>,
|
|
133
109
|
) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
134
110
|
|
|
135
|
-
type RequestFn = <
|
|
136
|
-
TData = unknown,
|
|
137
|
-
TError = unknown,
|
|
138
|
-
ThrowOnError extends boolean = false,
|
|
139
|
-
>(
|
|
111
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(
|
|
140
112
|
options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> &
|
|
141
113
|
Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>,
|
|
142
114
|
) => RequestResult<TData, TError, ThrowOnError>;
|
|
@@ -152,13 +124,7 @@ type BuildUrlFn = <
|
|
|
152
124
|
options: TData & Options<TData>,
|
|
153
125
|
) => string;
|
|
154
126
|
|
|
155
|
-
export type Client = CoreClient<
|
|
156
|
-
RequestFn,
|
|
157
|
-
Config,
|
|
158
|
-
MethodFn,
|
|
159
|
-
BuildUrlFn,
|
|
160
|
-
SseFn
|
|
161
|
-
> & {
|
|
127
|
+
export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
162
128
|
instance: AxiosInstance;
|
|
163
129
|
};
|
|
164
130
|
|
|
@@ -188,8 +154,5 @@ export type Options<
|
|
|
188
154
|
TData extends TDataShape = TDataShape,
|
|
189
155
|
ThrowOnError extends boolean = boolean,
|
|
190
156
|
TResponse = unknown,
|
|
191
|
-
> = OmitKeys<
|
|
192
|
-
RequestOptions<TResponse, ThrowOnError>,
|
|
193
|
-
'body' | 'path' | 'query' | 'url'
|
|
194
|
-
> &
|
|
157
|
+
> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> &
|
|
195
158
|
([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
@@ -128,9 +128,7 @@ export const buildUrl: Client['buildUrl'] = (options) => {
|
|
|
128
128
|
const instanceBaseUrl = options.axios?.defaults?.baseURL;
|
|
129
129
|
|
|
130
130
|
const baseUrl =
|
|
131
|
-
!!options.baseURL && typeof options.baseURL === 'string'
|
|
132
|
-
? options.baseURL
|
|
133
|
-
: instanceBaseUrl;
|
|
131
|
+
!!options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
|
|
134
132
|
|
|
135
133
|
return getUrl({
|
|
136
134
|
baseUrl: baseUrl as string,
|
|
@@ -177,9 +175,7 @@ export const mergeHeaders = (
|
|
|
177
175
|
|
|
178
176
|
for (const [key, value] of iterator) {
|
|
179
177
|
if (
|
|
180
|
-
axiosHeadersKeywords.includes(
|
|
181
|
-
key as (typeof axiosHeadersKeywords)[number],
|
|
182
|
-
) &&
|
|
178
|
+
axiosHeadersKeywords.includes(key as (typeof axiosHeadersKeywords)[number]) &&
|
|
183
179
|
typeof value === 'object'
|
|
184
180
|
) {
|
|
185
181
|
mergedHeaders[key] = {
|
|
@@ -196,8 +192,7 @@ export const mergeHeaders = (
|
|
|
196
192
|
} else if (value !== undefined) {
|
|
197
193
|
// assume object headers are meant to be JSON stringified, i.e. their
|
|
198
194
|
// content value in OpenAPI specification is 'application/json'
|
|
199
|
-
mergedHeaders[key] =
|
|
200
|
-
typeof value === 'object' ? JSON.stringify(value) : (value as string);
|
|
195
|
+
mergedHeaders[key] = typeof value === 'object' ? JSON.stringify(value) : (value as string);
|
|
201
196
|
}
|
|
202
197
|
}
|
|
203
198
|
}
|
|
@@ -21,8 +21,7 @@ export const getAuthToken = async (
|
|
|
21
21
|
auth: Auth,
|
|
22
22
|
callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
|
|
23
23
|
): Promise<string | undefined> => {
|
|
24
|
-
const token =
|
|
25
|
-
typeof callback === 'function' ? await callback(auth) : callback;
|
|
24
|
+
const token = typeof callback === 'function' ? await callback(auth) : callback;
|
|
26
25
|
|
|
27
26
|
if (!token) {
|
|
28
27
|
return;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ArrayStyle,
|
|
3
|
-
ObjectStyle,
|
|
4
|
-
SerializerOptions,
|
|
5
|
-
} from './pathSerializer';
|
|
1
|
+
import type { ArrayStyle, ObjectStyle, SerializerOptions } from './pathSerializer';
|
|
6
2
|
|
|
7
3
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
8
4
|
|
|
@@ -22,11 +18,7 @@ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
|
22
18
|
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
23
19
|
};
|
|
24
20
|
|
|
25
|
-
const serializeFormDataPair = (
|
|
26
|
-
data: FormData,
|
|
27
|
-
key: string,
|
|
28
|
-
value: unknown,
|
|
29
|
-
): void => {
|
|
21
|
+
const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
|
|
30
22
|
if (typeof value === 'string' || value instanceof Blob) {
|
|
31
23
|
data.append(key, value);
|
|
32
24
|
} else if (value instanceof Date) {
|
|
@@ -36,11 +28,7 @@ const serializeFormDataPair = (
|
|
|
36
28
|
}
|
|
37
29
|
};
|
|
38
30
|
|
|
39
|
-
const serializeUrlSearchParamsPair = (
|
|
40
|
-
data: URLSearchParams,
|
|
41
|
-
key: string,
|
|
42
|
-
value: unknown,
|
|
43
|
-
): void => {
|
|
31
|
+
const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
|
|
44
32
|
if (typeof value === 'string') {
|
|
45
33
|
data.append(key, value);
|
|
46
34
|
} else {
|
|
@@ -71,15 +59,11 @@ export const formDataBodySerializer = {
|
|
|
71
59
|
|
|
72
60
|
export const jsonBodySerializer = {
|
|
73
61
|
bodySerializer: <T>(body: T): string =>
|
|
74
|
-
JSON.stringify(body, (_key, value) =>
|
|
75
|
-
typeof value === 'bigint' ? value.toString() : value,
|
|
76
|
-
),
|
|
62
|
+
JSON.stringify(body, (_key, value) => (typeof value === 'bigint' ? value.toString() : value)),
|
|
77
63
|
};
|
|
78
64
|
|
|
79
65
|
export const urlSearchParamsBodySerializer = {
|
|
80
|
-
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(
|
|
81
|
-
body: T,
|
|
82
|
-
): string => {
|
|
66
|
+
bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
|
|
83
67
|
const data = new URLSearchParams();
|
|
84
68
|
|
|
85
69
|
Object.entries(body).forEach(([key, value]) => {
|
|
@@ -100,10 +100,7 @@ const stripEmptySlots = (params: Params) => {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
export const buildClientParams = (
|
|
104
|
-
args: ReadonlyArray<unknown>,
|
|
105
|
-
fields: FieldsConfig,
|
|
106
|
-
) => {
|
|
103
|
+
export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
|
|
107
104
|
const params: Params = {
|
|
108
105
|
body: {},
|
|
109
106
|
headers: {},
|
|
@@ -146,15 +143,11 @@ export const buildClientParams = (
|
|
|
146
143
|
params[field.map] = value;
|
|
147
144
|
}
|
|
148
145
|
} else {
|
|
149
|
-
const extra = extraPrefixes.find(([prefix]) =>
|
|
150
|
-
key.startsWith(prefix),
|
|
151
|
-
);
|
|
146
|
+
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
152
147
|
|
|
153
148
|
if (extra) {
|
|
154
149
|
const [prefix, slot] = extra;
|
|
155
|
-
(params[slot] as Record<string, unknown>)[
|
|
156
|
-
key.slice(prefix.length)
|
|
157
|
-
] = value;
|
|
150
|
+
(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value;
|
|
158
151
|
} else if ('allowExtra' in config && config.allowExtra) {
|
|
159
152
|
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
160
153
|
if (allowed) {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
interface SerializeOptions<T>
|
|
2
|
-
extends SerializePrimitiveOptions,
|
|
3
|
-
SerializerOptions<T> {}
|
|
1
|
+
interface SerializeOptions<T> extends SerializePrimitiveOptions, SerializerOptions<T> {}
|
|
4
2
|
|
|
5
3
|
interface SerializePrimitiveOptions {
|
|
6
4
|
allowReserved?: boolean;
|
|
@@ -103,9 +101,7 @@ export const serializeArrayParam = ({
|
|
|
103
101
|
});
|
|
104
102
|
})
|
|
105
103
|
.join(separator);
|
|
106
|
-
return style === 'label' || style === 'matrix'
|
|
107
|
-
? separator + joinedValues
|
|
108
|
-
: joinedValues;
|
|
104
|
+
return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
|
|
109
105
|
};
|
|
110
106
|
|
|
111
107
|
export const serializePrimitiveParam = ({
|
|
@@ -144,11 +140,7 @@ export const serializeObjectParam = ({
|
|
|
144
140
|
if (style !== 'deepObject' && !explode) {
|
|
145
141
|
let values: string[] = [];
|
|
146
142
|
Object.entries(value).forEach(([key, v]) => {
|
|
147
|
-
values = [
|
|
148
|
-
...values,
|
|
149
|
-
key,
|
|
150
|
-
allowReserved ? (v as string) : encodeURIComponent(v as string),
|
|
151
|
-
];
|
|
143
|
+
values = [...values, key, allowReserved ? (v as string) : encodeURIComponent(v as string)];
|
|
152
144
|
});
|
|
153
145
|
const joinedValues = values.join(',');
|
|
154
146
|
switch (style) {
|
|
@@ -173,7 +165,5 @@ export const serializeObjectParam = ({
|
|
|
173
165
|
}),
|
|
174
166
|
)
|
|
175
167
|
.join(separator);
|
|
176
|
-
return style === 'label' || style === 'matrix'
|
|
177
|
-
? separator + joinedValues
|
|
178
|
-
: joinedValues;
|
|
168
|
+
return style === 'label' || style === 'matrix' ? separator + joinedValues : joinedValues;
|
|
179
169
|
};
|