@hey-api/openapi-ts 0.83.0 → 0.84.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 +1 -1
- package/dist/chunk-ZXJLXXXN.js +54 -0
- package/dist/chunk-ZXJLXXXN.js.map +1 -0
- package/dist/clients/angular/client.ts +3 -3
- package/dist/clients/angular/utils.ts +33 -39
- package/dist/clients/axios/client.ts +1 -1
- package/dist/clients/axios/types.ts +1 -1
- package/dist/clients/axios/utils.ts +11 -3
- package/dist/clients/fetch/client.ts +4 -4
- package/dist/clients/fetch/utils.ts +33 -39
- package/dist/clients/next/client.ts +4 -4
- package/dist/clients/next/utils.ts +32 -33
- package/dist/index.cjs +74 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -30
- package/dist/index.d.ts +39 -30
- package/dist/index.js +12 -15
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +23 -26
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/{types.d-CcDC5oij.d.cts → types.d-ClTVswi2.d.cts} +2225 -2231
- package/dist/{types.d-CcDC5oij.d.ts → types.d-ClTVswi2.d.ts} +2225 -2231
- package/package.json +12 -11
- package/dist/chunk-XDXACE7V.js +0 -57
- package/dist/chunk-XDXACE7V.js.map +0 -1
|
@@ -129,7 +129,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
129
129
|
|
|
130
130
|
let req = initialReq;
|
|
131
131
|
|
|
132
|
-
for (const fn of interceptors.request.
|
|
132
|
+
for (const fn of interceptors.request.fns) {
|
|
133
133
|
if (fn) {
|
|
134
134
|
req = await fn(req, opts as any);
|
|
135
135
|
}
|
|
@@ -150,7 +150,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
150
150
|
.pipe(filter((event) => event.type === HttpEventType.Response)),
|
|
151
151
|
)) as HttpResponse<unknown>;
|
|
152
152
|
|
|
153
|
-
for (const fn of interceptors.response.
|
|
153
|
+
for (const fn of interceptors.response.fns) {
|
|
154
154
|
if (fn) {
|
|
155
155
|
result.response = await fn(result.response, req, opts as any);
|
|
156
156
|
}
|
|
@@ -176,7 +176,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
176
176
|
|
|
177
177
|
let finalError = error instanceof HttpErrorResponse ? error.error : error;
|
|
178
178
|
|
|
179
|
-
for (const fn of interceptors.error.
|
|
179
|
+
for (const fn of interceptors.error.fns) {
|
|
180
180
|
if (fn) {
|
|
181
181
|
finalError = (await fn(
|
|
182
182
|
finalError,
|
|
@@ -338,67 +338,61 @@ type ResInterceptor<Res, Req, Options> = (
|
|
|
338
338
|
) => Res | Promise<Res>;
|
|
339
339
|
|
|
340
340
|
class Interceptors<Interceptor> {
|
|
341
|
-
|
|
341
|
+
fns: Array<Interceptor | null> = [];
|
|
342
342
|
|
|
343
|
-
|
|
344
|
-
this.
|
|
343
|
+
clear(): void {
|
|
344
|
+
this.fns = [];
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
getInterceptorIndex(id: number | Interceptor): number {
|
|
352
|
-
if (typeof id === 'number') {
|
|
353
|
-
return this._fns[id] ? id : -1;
|
|
354
|
-
} else {
|
|
355
|
-
return this._fns.indexOf(id);
|
|
347
|
+
eject(id: number | Interceptor): void {
|
|
348
|
+
const index = this.getInterceptorIndex(id);
|
|
349
|
+
if (this.fns[index]) {
|
|
350
|
+
this.fns[index] = null;
|
|
356
351
|
}
|
|
357
352
|
}
|
|
358
|
-
|
|
353
|
+
|
|
354
|
+
exists(id: number | Interceptor): boolean {
|
|
359
355
|
const index = this.getInterceptorIndex(id);
|
|
360
|
-
return
|
|
356
|
+
return Boolean(this.fns[index]);
|
|
361
357
|
}
|
|
362
358
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
this._fns[index] = null;
|
|
359
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
360
|
+
if (typeof id === 'number') {
|
|
361
|
+
return this.fns[id] ? id : -1;
|
|
367
362
|
}
|
|
363
|
+
return this.fns.indexOf(id);
|
|
368
364
|
}
|
|
369
365
|
|
|
370
|
-
update(
|
|
366
|
+
update(
|
|
367
|
+
id: number | Interceptor,
|
|
368
|
+
fn: Interceptor,
|
|
369
|
+
): number | Interceptor | false {
|
|
371
370
|
const index = this.getInterceptorIndex(id);
|
|
372
|
-
if (this.
|
|
373
|
-
this.
|
|
371
|
+
if (this.fns[index]) {
|
|
372
|
+
this.fns[index] = fn;
|
|
374
373
|
return id;
|
|
375
|
-
} else {
|
|
376
|
-
return false;
|
|
377
374
|
}
|
|
375
|
+
return false;
|
|
378
376
|
}
|
|
379
377
|
|
|
380
|
-
use(fn: Interceptor) {
|
|
381
|
-
this.
|
|
382
|
-
return this.
|
|
378
|
+
use(fn: Interceptor): number {
|
|
379
|
+
this.fns.push(fn);
|
|
380
|
+
return this.fns.length - 1;
|
|
383
381
|
}
|
|
384
382
|
}
|
|
385
383
|
|
|
386
|
-
// `createInterceptors()` response, meant for external use as it does not
|
|
387
|
-
// expose internals
|
|
388
384
|
export interface Middleware<Req, Res, Err, Options> {
|
|
389
|
-
error:
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
>;
|
|
393
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
|
|
394
|
-
response: Pick<
|
|
395
|
-
Interceptors<ResInterceptor<Res, Req, Options>>,
|
|
396
|
-
'eject' | 'use'
|
|
397
|
-
>;
|
|
385
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
386
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
387
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
398
388
|
}
|
|
399
389
|
|
|
400
|
-
|
|
401
|
-
|
|
390
|
+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
391
|
+
Req,
|
|
392
|
+
Res,
|
|
393
|
+
Err,
|
|
394
|
+
Options
|
|
395
|
+
> => ({
|
|
402
396
|
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
403
397
|
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
404
398
|
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
|
@@ -78,7 +78,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
78
78
|
const { auth, ...optsWithoutAuth } = opts;
|
|
79
79
|
const response = await _axios({
|
|
80
80
|
...optsWithoutAuth,
|
|
81
|
-
baseURL:
|
|
81
|
+
baseURL: '', // the baseURL is already included in `url`
|
|
82
82
|
data: getValidRequestBody(opts),
|
|
83
83
|
headers: opts.headers as RawAxiosRequestHeaders,
|
|
84
84
|
// let `paramsSerializer()` handle query params if it exists
|
|
@@ -123,9 +123,16 @@ export const setAuthParams = async ({
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
export const buildUrl: Client['buildUrl'] = (options) =>
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
export const buildUrl: Client['buildUrl'] = (options) => {
|
|
127
|
+
const instanceBaseUrl = options.axios?.defaults?.baseURL;
|
|
128
|
+
|
|
129
|
+
const baseUrl =
|
|
130
|
+
!!options.baseURL && typeof options.baseURL === 'string'
|
|
131
|
+
? options.baseURL
|
|
132
|
+
: instanceBaseUrl;
|
|
133
|
+
|
|
134
|
+
return getUrl({
|
|
135
|
+
baseUrl: baseUrl as string,
|
|
129
136
|
path: options.path,
|
|
130
137
|
// let `paramsSerializer()` handle query params if it exists
|
|
131
138
|
query: !options.paramsSerializer ? options.query : undefined,
|
|
@@ -135,6 +142,7 @@ export const buildUrl: Client['buildUrl'] = (options) =>
|
|
|
135
142
|
: createQuerySerializer(options.querySerializer),
|
|
136
143
|
url: options.url,
|
|
137
144
|
});
|
|
145
|
+
};
|
|
138
146
|
|
|
139
147
|
export const mergeConfigs = (a: Config, b: Config): Config => {
|
|
140
148
|
const config = { ...a, ...b };
|
|
@@ -84,7 +84,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
84
84
|
|
|
85
85
|
let request = new Request(url, requestInit);
|
|
86
86
|
|
|
87
|
-
for (const fn of interceptors.request.
|
|
87
|
+
for (const fn of interceptors.request.fns) {
|
|
88
88
|
if (fn) {
|
|
89
89
|
request = await fn(request, opts);
|
|
90
90
|
}
|
|
@@ -95,7 +95,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
95
95
|
const _fetch = opts.fetch!;
|
|
96
96
|
let response = await _fetch(request);
|
|
97
97
|
|
|
98
|
-
for (const fn of interceptors.response.
|
|
98
|
+
for (const fn of interceptors.response.fns) {
|
|
99
99
|
if (fn) {
|
|
100
100
|
response = await fn(response, request, opts);
|
|
101
101
|
}
|
|
@@ -190,7 +190,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
190
190
|
const error = jsonError ?? textError;
|
|
191
191
|
let finalError = error;
|
|
192
192
|
|
|
193
|
-
for (const fn of interceptors.error.
|
|
193
|
+
for (const fn of interceptors.error.fns) {
|
|
194
194
|
if (fn) {
|
|
195
195
|
finalError = (await fn(error, response, request, opts)) as string;
|
|
196
196
|
}
|
|
@@ -225,7 +225,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
225
225
|
method,
|
|
226
226
|
onRequest: async (url, init) => {
|
|
227
227
|
let request = new Request(url, init);
|
|
228
|
-
for (const fn of interceptors.request.
|
|
228
|
+
for (const fn of interceptors.request.fns) {
|
|
229
229
|
if (fn) {
|
|
230
230
|
request = await fn(request, opts);
|
|
231
231
|
}
|
|
@@ -242,67 +242,61 @@ type ResInterceptor<Res, Req, Options> = (
|
|
|
242
242
|
) => Res | Promise<Res>;
|
|
243
243
|
|
|
244
244
|
class Interceptors<Interceptor> {
|
|
245
|
-
|
|
245
|
+
fns: Array<Interceptor | null> = [];
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
this.
|
|
247
|
+
clear(): void {
|
|
248
|
+
this.fns = [];
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
getInterceptorIndex(id: number | Interceptor): number {
|
|
256
|
-
if (typeof id === 'number') {
|
|
257
|
-
return this._fns[id] ? id : -1;
|
|
258
|
-
} else {
|
|
259
|
-
return this._fns.indexOf(id);
|
|
251
|
+
eject(id: number | Interceptor): void {
|
|
252
|
+
const index = this.getInterceptorIndex(id);
|
|
253
|
+
if (this.fns[index]) {
|
|
254
|
+
this.fns[index] = null;
|
|
260
255
|
}
|
|
261
256
|
}
|
|
262
|
-
|
|
257
|
+
|
|
258
|
+
exists(id: number | Interceptor): boolean {
|
|
263
259
|
const index = this.getInterceptorIndex(id);
|
|
264
|
-
return
|
|
260
|
+
return Boolean(this.fns[index]);
|
|
265
261
|
}
|
|
266
262
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
this._fns[index] = null;
|
|
263
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
264
|
+
if (typeof id === 'number') {
|
|
265
|
+
return this.fns[id] ? id : -1;
|
|
271
266
|
}
|
|
267
|
+
return this.fns.indexOf(id);
|
|
272
268
|
}
|
|
273
269
|
|
|
274
|
-
update(
|
|
270
|
+
update(
|
|
271
|
+
id: number | Interceptor,
|
|
272
|
+
fn: Interceptor,
|
|
273
|
+
): number | Interceptor | false {
|
|
275
274
|
const index = this.getInterceptorIndex(id);
|
|
276
|
-
if (this.
|
|
277
|
-
this.
|
|
275
|
+
if (this.fns[index]) {
|
|
276
|
+
this.fns[index] = fn;
|
|
278
277
|
return id;
|
|
279
|
-
} else {
|
|
280
|
-
return false;
|
|
281
278
|
}
|
|
279
|
+
return false;
|
|
282
280
|
}
|
|
283
281
|
|
|
284
|
-
use(fn: Interceptor) {
|
|
285
|
-
this.
|
|
286
|
-
return this.
|
|
282
|
+
use(fn: Interceptor): number {
|
|
283
|
+
this.fns.push(fn);
|
|
284
|
+
return this.fns.length - 1;
|
|
287
285
|
}
|
|
288
286
|
}
|
|
289
287
|
|
|
290
|
-
// `createInterceptors()` response, meant for external use as it does not
|
|
291
|
-
// expose internals
|
|
292
288
|
export interface Middleware<Req, Res, Err, Options> {
|
|
293
|
-
error:
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
>;
|
|
297
|
-
request: Pick<Interceptors<ReqInterceptor<Req, Options>>, 'eject' | 'use'>;
|
|
298
|
-
response: Pick<
|
|
299
|
-
Interceptors<ResInterceptor<Res, Req, Options>>,
|
|
300
|
-
'eject' | 'use'
|
|
301
|
-
>;
|
|
289
|
+
error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
|
|
290
|
+
request: Interceptors<ReqInterceptor<Req, Options>>;
|
|
291
|
+
response: Interceptors<ResInterceptor<Res, Req, Options>>;
|
|
302
292
|
}
|
|
303
293
|
|
|
304
|
-
|
|
305
|
-
|
|
294
|
+
export const createInterceptors = <Req, Res, Err, Options>(): Middleware<
|
|
295
|
+
Req,
|
|
296
|
+
Res,
|
|
297
|
+
Err,
|
|
298
|
+
Options
|
|
299
|
+
> => ({
|
|
306
300
|
error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
|
|
307
301
|
request: new Interceptors<ReqInterceptor<Req, Options>>(),
|
|
308
302
|
response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
|
|
@@ -77,7 +77,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
77
77
|
// @ts-expect-error
|
|
78
78
|
const { opts, url } = await beforeRequest(options);
|
|
79
79
|
|
|
80
|
-
for (const fn of interceptors.request.
|
|
80
|
+
for (const fn of interceptors.request.fns) {
|
|
81
81
|
if (fn) {
|
|
82
82
|
await fn(opts);
|
|
83
83
|
}
|
|
@@ -93,7 +93,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
93
93
|
|
|
94
94
|
let response = await _fetch(url, requestInit);
|
|
95
95
|
|
|
96
|
-
for (const fn of interceptors.response.
|
|
96
|
+
for (const fn of interceptors.response.fns) {
|
|
97
97
|
if (fn) {
|
|
98
98
|
response = await fn(response, opts);
|
|
99
99
|
}
|
|
@@ -181,7 +181,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
181
181
|
const error = jsonError ?? textError;
|
|
182
182
|
let finalError = error;
|
|
183
183
|
|
|
184
|
-
for (const fn of interceptors.error.
|
|
184
|
+
for (const fn of interceptors.error.fns) {
|
|
185
185
|
if (fn) {
|
|
186
186
|
finalError = (await fn(error, response, opts)) as string;
|
|
187
187
|
}
|
|
@@ -218,7 +218,7 @@ export const createClient = (config: Config = {}): Client => {
|
|
|
218
218
|
method: init.method as Config['method'],
|
|
219
219
|
url,
|
|
220
220
|
};
|
|
221
|
-
for (const fn of interceptors.request.
|
|
221
|
+
for (const fn of interceptors.request.fns) {
|
|
222
222
|
if (fn) {
|
|
223
223
|
await fn(requestInit);
|
|
224
224
|
request = new Request(requestInit.url, requestInit);
|
|
@@ -349,61 +349,60 @@ type ResInterceptor<Res, Options> = (
|
|
|
349
349
|
) => Res | Promise<Res>;
|
|
350
350
|
|
|
351
351
|
class Interceptors<Interceptor> {
|
|
352
|
-
|
|
352
|
+
fns: Array<Interceptor | null> = [];
|
|
353
353
|
|
|
354
|
-
|
|
355
|
-
this.
|
|
354
|
+
clear(): void {
|
|
355
|
+
this.fns = [];
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
getInterceptorIndex(id: number | Interceptor): number {
|
|
363
|
-
if (typeof id === 'number') {
|
|
364
|
-
return this._fns[id] ? id : -1;
|
|
365
|
-
} else {
|
|
366
|
-
return this._fns.indexOf(id);
|
|
358
|
+
eject(id: number | Interceptor): void {
|
|
359
|
+
const index = this.getInterceptorIndex(id);
|
|
360
|
+
if (this.fns[index]) {
|
|
361
|
+
this.fns[index] = null;
|
|
367
362
|
}
|
|
368
363
|
}
|
|
369
|
-
|
|
364
|
+
|
|
365
|
+
exists(id: number | Interceptor): boolean {
|
|
370
366
|
const index = this.getInterceptorIndex(id);
|
|
371
|
-
return
|
|
367
|
+
return Boolean(this.fns[index]);
|
|
372
368
|
}
|
|
373
369
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
this._fns[index] = null;
|
|
370
|
+
getInterceptorIndex(id: number | Interceptor): number {
|
|
371
|
+
if (typeof id === 'number') {
|
|
372
|
+
return this.fns[id] ? id : -1;
|
|
378
373
|
}
|
|
374
|
+
return this.fns.indexOf(id);
|
|
379
375
|
}
|
|
380
376
|
|
|
381
|
-
update(
|
|
377
|
+
update(
|
|
378
|
+
id: number | Interceptor,
|
|
379
|
+
fn: Interceptor,
|
|
380
|
+
): number | Interceptor | false {
|
|
382
381
|
const index = this.getInterceptorIndex(id);
|
|
383
|
-
if (this.
|
|
384
|
-
this.
|
|
382
|
+
if (this.fns[index]) {
|
|
383
|
+
this.fns[index] = fn;
|
|
385
384
|
return id;
|
|
386
|
-
} else {
|
|
387
|
-
return false;
|
|
388
385
|
}
|
|
386
|
+
return false;
|
|
389
387
|
}
|
|
390
388
|
|
|
391
|
-
use(fn: Interceptor) {
|
|
392
|
-
this.
|
|
393
|
-
return this.
|
|
389
|
+
use(fn: Interceptor): number {
|
|
390
|
+
this.fns.push(fn);
|
|
391
|
+
return this.fns.length - 1;
|
|
394
392
|
}
|
|
395
393
|
}
|
|
396
394
|
|
|
397
|
-
// `createInterceptors()` response, meant for external use as it does not
|
|
398
|
-
// expose internals
|
|
399
395
|
export interface Middleware<Res, Err, Options> {
|
|
400
|
-
error:
|
|
401
|
-
request:
|
|
402
|
-
response:
|
|
396
|
+
error: Interceptors<ErrInterceptor<Err, Res, Options>>;
|
|
397
|
+
request: Interceptors<ReqInterceptor<Options>>;
|
|
398
|
+
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
403
399
|
}
|
|
404
400
|
|
|
405
|
-
|
|
406
|
-
|
|
401
|
+
export const createInterceptors = <Res, Err, Options>(): Middleware<
|
|
402
|
+
Res,
|
|
403
|
+
Err,
|
|
404
|
+
Options
|
|
405
|
+
> => ({
|
|
407
406
|
error: new Interceptors<ErrInterceptor<Err, Res, Options>>(),
|
|
408
407
|
request: new Interceptors<ReqInterceptor<Options>>(),
|
|
409
408
|
response: new Interceptors<ResInterceptor<Res, Options>>(),
|