@hey-api/openapi-ts 0.83.0 → 0.83.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.
@@ -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._fns) {
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._fns) {
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._fns) {
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
- _fns: (Interceptor | null)[];
341
+ fns: Array<Interceptor | null> = [];
342
342
 
343
- constructor() {
344
- this._fns = [];
343
+ clear(): void {
344
+ this.fns = [];
345
345
  }
346
346
 
347
- clear() {
348
- this._fns = [];
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
- exists(id: number | Interceptor) {
353
+
354
+ exists(id: number | Interceptor): boolean {
359
355
  const index = this.getInterceptorIndex(id);
360
- return !!this._fns[index];
356
+ return Boolean(this.fns[index]);
361
357
  }
362
358
 
363
- eject(id: number | Interceptor) {
364
- const index = this.getInterceptorIndex(id);
365
- if (this._fns[index]) {
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(id: number | Interceptor, fn: Interceptor) {
366
+ update(
367
+ id: number | Interceptor,
368
+ fn: Interceptor,
369
+ ): number | Interceptor | false {
371
370
  const index = this.getInterceptorIndex(id);
372
- if (this._fns[index]) {
373
- this._fns[index] = fn;
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._fns = [...this._fns, fn];
382
- return this._fns.length - 1;
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: Pick<
390
- Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
391
- 'eject' | 'use'
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
- // do not add `Middleware` as return type so we can use _fns internally
401
- export const createInterceptors = <Req, Res, Err, Options>() => ({
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>>(),
@@ -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._fns) {
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._fns) {
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._fns) {
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._fns) {
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
- _fns: (Interceptor | null)[];
245
+ fns: Array<Interceptor | null> = [];
246
246
 
247
- constructor() {
248
- this._fns = [];
247
+ clear(): void {
248
+ this.fns = [];
249
249
  }
250
250
 
251
- clear() {
252
- this._fns = [];
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
- exists(id: number | Interceptor) {
257
+
258
+ exists(id: number | Interceptor): boolean {
263
259
  const index = this.getInterceptorIndex(id);
264
- return !!this._fns[index];
260
+ return Boolean(this.fns[index]);
265
261
  }
266
262
 
267
- eject(id: number | Interceptor) {
268
- const index = this.getInterceptorIndex(id);
269
- if (this._fns[index]) {
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(id: number | Interceptor, fn: Interceptor) {
270
+ update(
271
+ id: number | Interceptor,
272
+ fn: Interceptor,
273
+ ): number | Interceptor | false {
275
274
  const index = this.getInterceptorIndex(id);
276
- if (this._fns[index]) {
277
- this._fns[index] = fn;
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._fns = [...this._fns, fn];
286
- return this._fns.length - 1;
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: Pick<
294
- Interceptors<ErrInterceptor<Err, Res, Req, Options>>,
295
- 'eject' | 'use'
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
- // do not add `Middleware` as return type so we can use _fns internally
305
- export const createInterceptors = <Req, Res, Err, Options>() => ({
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._fns) {
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._fns) {
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._fns) {
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._fns) {
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
- _fns: (Interceptor | null)[];
352
+ fns: Array<Interceptor | null> = [];
353
353
 
354
- constructor() {
355
- this._fns = [];
354
+ clear(): void {
355
+ this.fns = [];
356
356
  }
357
357
 
358
- clear() {
359
- this._fns = [];
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
- exists(id: number | Interceptor) {
364
+
365
+ exists(id: number | Interceptor): boolean {
370
366
  const index = this.getInterceptorIndex(id);
371
- return !!this._fns[index];
367
+ return Boolean(this.fns[index]);
372
368
  }
373
369
 
374
- eject(id: number | Interceptor) {
375
- const index = this.getInterceptorIndex(id);
376
- if (this._fns[index]) {
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(id: number | Interceptor, fn: Interceptor) {
377
+ update(
378
+ id: number | Interceptor,
379
+ fn: Interceptor,
380
+ ): number | Interceptor | false {
382
381
  const index = this.getInterceptorIndex(id);
383
- if (this._fns[index]) {
384
- this._fns[index] = fn;
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._fns = [...this._fns, fn];
393
- return this._fns.length - 1;
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: Pick<Interceptors<ErrInterceptor<Err, Res, Options>>, 'eject' | 'use'>;
401
- request: Pick<Interceptors<ReqInterceptor<Options>>, 'eject' | 'use'>;
402
- response: Pick<Interceptors<ResInterceptor<Res, Options>>, 'eject' | 'use'>;
396
+ error: Interceptors<ErrInterceptor<Err, Res, Options>>;
397
+ request: Interceptors<ReqInterceptor<Options>>;
398
+ response: Interceptors<ResInterceptor<Res, Options>>;
403
399
  }
404
400
 
405
- // do not add `Middleware` as return type so we can use _fns internally
406
- export const createInterceptors = <Res, Err, Options>() => ({
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>>(),