@ahoo-wang/fetcher 1.3.3 → 1.5.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/dist/index.es.js CHANGED
@@ -1,29 +1,29 @@
1
- function S(r) {
1
+ function F(r) {
2
2
  return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(r);
3
3
  }
4
- function F(r, e) {
5
- return S(e) ? e : e ? r.replace(/\/?\/$/, "") + "/" + e.replace(/^\/+/, "") : r;
4
+ function C(r, t) {
5
+ return F(t) ? t : t ? r.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : r;
6
6
  }
7
7
  var U = /* @__PURE__ */ ((r) => (r[r.UriTemplate = 0] = "UriTemplate", r[r.Express = 1] = "Express", r))(U || {});
8
8
  function D(r) {
9
- return r === 1 ? C : L;
9
+ return r === 1 ? v : L;
10
10
  }
11
- function _(r, e, t) {
12
- return t ? r.replace(e, (s, n) => {
13
- const i = t[n];
14
- if (i === void 0)
11
+ function q(r, t, e) {
12
+ return e ? r.replace(t, (s, n) => {
13
+ const o = e[n];
14
+ if (o === void 0)
15
15
  throw new Error(`Missing required path parameter: ${n}`);
16
- return encodeURIComponent(i);
16
+ return encodeURIComponent(o);
17
17
  }) : r;
18
18
  }
19
- function q(r, e) {
20
- const t = [];
19
+ function w(r, t) {
20
+ const e = [];
21
21
  let s;
22
- for (; (s = e.exec(r)) !== null; )
23
- t.push(s[1]);
24
- return t;
22
+ for (; (s = t.exec(r)) !== null; )
23
+ e.push(s[1]);
24
+ return e;
25
25
  }
26
- const a = class a {
26
+ const c = class c {
27
27
  /**
28
28
  * Extracts path parameters from a URL string.
29
29
  *
@@ -47,10 +47,10 @@ const a = class a {
47
47
  * // noParams = []
48
48
  * ```
49
49
  */
50
- extractPathParams(e) {
51
- return q(
52
- e,
53
- a.PATH_PARAM_REGEX
50
+ extractPathParams(t) {
51
+ return w(
52
+ t,
53
+ c.PATH_PARAM_REGEX
54
54
  );
55
55
  }
56
56
  /**
@@ -89,17 +89,17 @@ const a = class a {
89
89
  * }
90
90
  * ```
91
91
  */
92
- resolve(e, t) {
93
- return _(
94
- e,
95
- a.PATH_PARAM_REGEX,
96
- t
92
+ resolve(t, e) {
93
+ return q(
94
+ t,
95
+ c.PATH_PARAM_REGEX,
96
+ e
97
97
  );
98
98
  }
99
99
  };
100
- a.PATH_PARAM_REGEX = /{([^}]+)}/g;
101
- let T = a;
102
- const L = new T(), h = class h {
100
+ c.PATH_PARAM_REGEX = /{([^}]+)}/g;
101
+ let f = c;
102
+ const L = new f(), h = class h {
103
103
  /**
104
104
  * Extracts path parameters from an Express-style URL string.
105
105
  *
@@ -119,9 +119,9 @@ const L = new T(), h = class h {
119
119
  * // noParams = []
120
120
  * ```
121
121
  */
122
- extractPathParams(e) {
123
- return q(
124
- e,
122
+ extractPathParams(t) {
123
+ return w(
124
+ t,
125
125
  h.PATH_PARAM_REGEX
126
126
  );
127
127
  }
@@ -157,18 +157,18 @@ const L = new T(), h = class h {
157
157
  * }
158
158
  * ```
159
159
  */
160
- resolve(e, t) {
161
- return _(
162
- e,
160
+ resolve(t, e) {
161
+ return q(
162
+ t,
163
163
  h.PATH_PARAM_REGEX,
164
- t
164
+ e
165
165
  );
166
166
  }
167
167
  };
168
168
  h.PATH_PARAM_REGEX = /:([^/]+)/g;
169
- let f = h;
170
- const C = new f();
171
- class v {
169
+ let P = h;
170
+ const v = new P();
171
+ class x {
172
172
  /**
173
173
  * Initializes a new UrlBuilder instance.
174
174
  *
@@ -186,8 +186,8 @@ class v {
186
186
  * const expressUrlBuilder = new UrlBuilder('https://api.example.com', UrlTemplateStyle.Express);
187
187
  * ```
188
188
  */
189
- constructor(e, t) {
190
- this.baseURL = e, this.urlTemplateResolver = D(t);
189
+ constructor(t, e) {
190
+ this.baseURL = t, this.urlTemplateResolver = D(e);
191
191
  }
192
192
  /**
193
193
  * Builds a complete URL, including path parameter replacement and query parameter addition.
@@ -207,14 +207,14 @@ class v {
207
207
  * // Result: https://api.example.com/users/123/posts/456?filter=active&limit=10
208
208
  * ```
209
209
  */
210
- build(e, t) {
211
- const s = t?.path, n = t?.query, i = F(this.baseURL, e);
212
- let o = this.urlTemplateResolver.resolve(i, s);
210
+ build(t, e) {
211
+ const s = e?.path, n = e?.query, o = C(this.baseURL, t);
212
+ let u = this.urlTemplateResolver.resolve(o, s);
213
213
  if (n) {
214
- const c = new URLSearchParams(n).toString();
215
- c && (o += "?" + c);
214
+ const a = new URLSearchParams(n).toString();
215
+ a && (u += "?" + a);
216
216
  }
217
- return o;
217
+ return u;
218
218
  }
219
219
  /**
220
220
  * Resolves a complete URL from a FetchRequest.
@@ -225,8 +225,8 @@ class v {
225
225
  * @param request - The FetchRequest containing URL and URL parameters
226
226
  * @returns Complete resolved URL string
227
227
  */
228
- resolveRequestUrl(e) {
229
- return this.build(e.url, e.urlParams);
228
+ resolveRequestUrl(t) {
229
+ return this.build(t.url, t.urlParams);
230
230
  }
231
231
  }
232
232
  class l extends Error {
@@ -236,71 +236,71 @@ class l extends Error {
236
236
  * @param errorMsg - Optional error message. If not provided, will use the cause's message or a default message.
237
237
  * @param cause - Optional underlying error that caused this error.
238
238
  */
239
- constructor(e, t) {
240
- const s = e || t?.message || "An error occurred in the fetcher";
241
- super(s), this.cause = t, this.name = "FetcherError", t?.stack && (this.stack = t.stack), Object.setPrototypeOf(this, l.prototype);
239
+ constructor(t, e) {
240
+ const s = t || e?.message || "An error occurred in the fetcher";
241
+ super(s), this.cause = e, this.name = "FetcherError", e?.stack && (this.stack = e.stack), Object.setPrototypeOf(this, l.prototype);
242
242
  }
243
243
  }
244
- class y extends l {
244
+ class I extends l {
245
245
  /**
246
246
  * Creates a new FetchTimeoutError instance.
247
247
  *
248
248
  * @param request - The request options that timed out
249
249
  */
250
- constructor(e) {
251
- const t = e.method || "GET", s = `Request timeout of ${e.timeout}ms exceeded for ${t} ${e.url}`;
252
- super(s), this.name = "FetchTimeoutError", this.request = e, Object.setPrototypeOf(this, y.prototype);
250
+ constructor(t) {
251
+ const e = t.method || "GET", s = `Request timeout of ${t.timeout}ms exceeded for ${e} ${t.url}`;
252
+ super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this, I.prototype);
253
253
  }
254
254
  }
255
- function G(r, e) {
256
- return typeof r < "u" ? r : e;
255
+ function G(r, t) {
256
+ return typeof r < "u" ? r : t;
257
257
  }
258
258
  async function M(r) {
259
- const e = r.url, t = r.timeout, s = r;
260
- if (r.signal || !t)
261
- return fetch(e, s);
262
- const n = new AbortController(), i = {
263
- ...s,
264
- signal: n.signal
265
- };
259
+ const t = r.url, e = r.timeout, s = r;
260
+ if (r.signal)
261
+ return fetch(t, s);
262
+ if (!e)
263
+ return r.abortController && (s.signal = r.abortController.signal), fetch(t, s);
264
+ const n = r.abortController ?? new AbortController();
265
+ s.signal = n.signal;
266
266
  let o = null;
267
- const c = new Promise((se, N) => {
267
+ const u = new Promise((a, p) => {
268
268
  o = setTimeout(() => {
269
269
  o && clearTimeout(o);
270
- const g = new y(r);
271
- n.abort(g), N(g);
272
- }, t);
270
+ const b = new I(r);
271
+ n.abort(b), p(b);
272
+ }, e);
273
273
  });
274
274
  try {
275
- return await Promise.race([fetch(e, i), c]);
275
+ return await Promise.race([fetch(t, s), u]);
276
276
  } finally {
277
277
  o && clearTimeout(o);
278
278
  }
279
279
  }
280
- const H = "UrlResolveInterceptor", w = Number.MIN_SAFE_INTEGER + 1e3;
281
- class B {
280
+ const H = "UrlResolveInterceptor", N = Number.MIN_SAFE_INTEGER + 1e3;
281
+ class j {
282
282
  constructor() {
283
- this.name = H, this.order = w;
283
+ this.name = H, this.order = N;
284
284
  }
285
285
  /**
286
286
  * Resolves the final URL by combining the base URL, path parameters, and query parameters.
287
287
  *
288
288
  * @param exchange - The fetch exchange containing the request information
289
289
  */
290
- intercept(e) {
291
- const t = e.request;
292
- t.url = e.fetcher.urlBuilder.resolveRequestUrl(t);
290
+ intercept(t) {
291
+ const e = t.request;
292
+ e.url = t.fetcher.urlBuilder.resolveRequestUrl(e);
293
293
  }
294
294
  }
295
- var u = /* @__PURE__ */ ((r) => (r.GET = "GET", r.POST = "POST", r.PUT = "PUT", r.DELETE = "DELETE", r.PATCH = "PATCH", r.HEAD = "HEAD", r.OPTIONS = "OPTIONS", r))(u || {});
296
- const ne = "Content-Type", E = class E {
295
+ var i = /* @__PURE__ */ ((r) => (r.GET = "GET", r.POST = "POST", r.PUT = "PUT", r.DELETE = "DELETE", r.PATCH = "PATCH", r.HEAD = "HEAD", r.OPTIONS = "OPTIONS", r))(i || {});
296
+ const at = "Content-Type", d = class d {
297
297
  };
298
- E.APPLICATION_JSON = "application/json", E.TEXT_EVENT_STREAM = "text/event-stream";
299
- let d = E;
300
- const $ = "RequestBodyInterceptor", j = w + 1e3;
298
+ d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
299
+ let E = d;
300
+ const B = "RequestBodyInterceptor", $ = N + 1e3;
301
301
  class X {
302
302
  constructor() {
303
- this.name = $, this.order = j;
303
+ this.name = B, this.order = $;
304
304
  }
305
305
  /**
306
306
  * Attempts to convert request body to a valid fetch API body type.
@@ -339,20 +339,20 @@ class X {
339
339
  * // exchange.request.body will be '{"name":"John","age":30}'
340
340
  * // exchange.request.headers will include 'Content-Type: application/json'
341
341
  */
342
- intercept(e) {
343
- const t = e.request;
344
- if (t.body === void 0 || t.body === null || typeof t.body != "object" || t.body instanceof ArrayBuffer || ArrayBuffer.isView(t.body) || // Includes TypedArray and DataView
345
- t.body instanceof Blob || t.body instanceof File || t.body instanceof URLSearchParams || t.body instanceof FormData || t.body instanceof ReadableStream)
342
+ intercept(t) {
343
+ const e = t.request;
344
+ if (e.body === void 0 || e.body === null || typeof e.body != "object" || e.body instanceof ArrayBuffer || ArrayBuffer.isView(e.body) || // Includes TypedArray and DataView
345
+ e.body instanceof Blob || e.body instanceof File || e.body instanceof URLSearchParams || e.body instanceof FormData || e.body instanceof ReadableStream)
346
346
  return;
347
- e.request.body = JSON.stringify(t.body);
348
- const s = e.ensureRequestHeaders();
349
- s["Content-Type"] || (s["Content-Type"] = d.APPLICATION_JSON);
347
+ t.request.body = JSON.stringify(e.body);
348
+ const s = t.ensureRequestHeaders();
349
+ s["Content-Type"] || (s["Content-Type"] = E.APPLICATION_JSON);
350
350
  }
351
351
  }
352
- const x = "FetchInterceptor", V = Number.MAX_SAFE_INTEGER - 1e3;
352
+ const V = "FetchInterceptor", J = Number.MAX_SAFE_INTEGER - 1e3;
353
353
  class k {
354
354
  constructor() {
355
- this.name = x, this.order = V;
355
+ this.name = V, this.order = J;
356
356
  }
357
357
  /**
358
358
  * Intercept and process HTTP requests.
@@ -379,14 +379,14 @@ class k {
379
379
  * await fetchInterceptor.intercept(exchange);
380
380
  * console.log(exchange.response); // HTTP response object
381
381
  */
382
- async intercept(e) {
383
- e.response = await M(e.request);
382
+ async intercept(t) {
383
+ t.response = await M(t.request);
384
384
  }
385
385
  }
386
- function p(r, e) {
387
- return e ? r.filter(e).sort((t, s) => t.order - s.order) : [...r].sort((t, s) => t.order - s.order);
386
+ function m(r, t) {
387
+ return t ? r.filter(t).sort((e, s) => e.order - s.order) : [...r].sort((e, s) => e.order - s.order);
388
388
  }
389
- class R {
389
+ class T {
390
390
  /**
391
391
  * Initializes a new InterceptorRegistry instance.
392
392
  *
@@ -396,8 +396,8 @@ class R {
396
396
  * The provided interceptors will be sorted by their order property immediately
397
397
  * upon construction.
398
398
  */
399
- constructor(e = []) {
400
- this.sortedInterceptors = [], this.sortedInterceptors = p(e);
399
+ constructor(t = []) {
400
+ this.sortedInterceptors = [], this.sortedInterceptors = m(t);
401
401
  }
402
402
  /**
403
403
  * Gets the name of this interceptor registry.
@@ -434,10 +434,10 @@ class R {
434
434
  *
435
435
  * After adding, interceptors are automatically sorted by their order property.
436
436
  */
437
- use(e) {
438
- return this.sortedInterceptors.some((t) => t.name === e.name) ? !1 : (this.sortedInterceptors = p([
437
+ use(t) {
438
+ return this.sortedInterceptors.some((e) => e.name === t.name) ? !1 : (this.sortedInterceptors = m([
439
439
  ...this.sortedInterceptors,
440
- e
440
+ t
441
441
  ]), !0);
442
442
  }
443
443
  /**
@@ -447,12 +447,12 @@ class R {
447
447
  * @returns True if an interceptor was removed, false if no interceptor with the
448
448
  * given name was found
449
449
  */
450
- eject(e) {
451
- const t = this.sortedInterceptors;
452
- return this.sortedInterceptors = p(
453
- t,
454
- (s) => s.name !== e
455
- ), t.length !== this.sortedInterceptors.length;
450
+ eject(t) {
451
+ const e = this.sortedInterceptors;
452
+ return this.sortedInterceptors = m(
453
+ e,
454
+ (s) => s.name !== t
455
+ ), e.length !== this.sortedInterceptors.length;
456
456
  }
457
457
  /**
458
458
  * Removes all interceptors from this registry.
@@ -474,27 +474,27 @@ class R {
474
474
  * If any interceptor throws an error, the execution chain is broken and the error
475
475
  * is propagated to the caller.
476
476
  */
477
- async intercept(e) {
478
- for (const t of this.sortedInterceptors)
479
- await t.intercept(e);
477
+ async intercept(t) {
478
+ for (const e of this.sortedInterceptors)
479
+ await e.intercept(t);
480
480
  }
481
481
  }
482
- class I extends l {
483
- constructor(e) {
482
+ class g extends l {
483
+ constructor(t) {
484
484
  super(
485
- `Request failed with status code ${e.response?.status} for ${e.request.url}`
486
- ), this.exchange = e, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, I.prototype);
485
+ `Request failed with status code ${t.response?.status} for ${t.request.url}`
486
+ ), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, g.prototype);
487
487
  }
488
488
  }
489
- const J = (r) => r >= 200 && r < 300, Y = "ValidateStatusInterceptor", z = Number.MAX_SAFE_INTEGER - 1e3;
490
- class Q {
489
+ const Y = (r) => r >= 200 && r < 300, z = "ValidateStatusInterceptor", Q = Number.MAX_SAFE_INTEGER - 1e3;
490
+ class K {
491
491
  /**
492
492
  * Creates a new ValidateStatusInterceptor instance.
493
493
  *
494
494
  * @param validateStatus - Function that determines if a status code is valid
495
495
  */
496
- constructor(e = J) {
497
- this.validateStatus = e;
496
+ constructor(t = Y) {
497
+ this.validateStatus = t;
498
498
  }
499
499
  /**
500
500
  * Gets the name of this interceptor.
@@ -502,7 +502,7 @@ class Q {
502
502
  * @returns The name of this interceptor
503
503
  */
504
504
  get name() {
505
- return Y;
505
+ return z;
506
506
  }
507
507
  /**
508
508
  * Gets the order of this interceptor.
@@ -510,7 +510,7 @@ class Q {
510
510
  * @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
511
511
  */
512
512
  get order() {
513
- return z;
513
+ return Q;
514
514
  }
515
515
  /**
516
516
  * Validates the response status code.
@@ -525,35 +525,35 @@ class Q {
525
525
  * preventing other response handlers from attempting to process them. Valid responses
526
526
  * proceed through the rest of the response interceptor chain normally.
527
527
  */
528
- intercept(e) {
529
- if (!e.response)
528
+ intercept(t) {
529
+ if (!t.response)
530
530
  return;
531
- const t = e.response.status;
532
- if (!this.validateStatus(t))
533
- throw new I(e);
531
+ const e = t.response.status;
532
+ if (!this.validateStatus(e))
533
+ throw new g(t);
534
534
  }
535
535
  }
536
- class m extends l {
536
+ class R extends l {
537
537
  /**
538
538
  * Creates a new ExchangeError instance.
539
539
  *
540
540
  * @param exchange - The FetchExchange object containing request/response/error information.
541
541
  * @param errorMsg - An optional error message.
542
542
  */
543
- constructor(e, t) {
544
- const s = t || e.error?.message || e.response?.statusText || `Request to ${e.request.url} failed during exchange`;
545
- super(s, e.error), this.exchange = e, this.name = "ExchangeError", Object.setPrototypeOf(this, m.prototype);
543
+ constructor(t, e) {
544
+ const s = e || t.error?.message || t.response?.statusText || `Request to ${t.request.url} failed during exchange`;
545
+ super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, R.prototype);
546
546
  }
547
547
  }
548
- class K {
548
+ class W {
549
549
  constructor() {
550
- this.request = new R([
551
- new B(),
550
+ this.request = new T([
551
+ new j(),
552
552
  new X(),
553
553
  new k()
554
- ]), this.response = new R([
555
- new Q()
556
- ]), this.error = new R();
554
+ ]), this.response = new T([
555
+ new K()
556
+ ]), this.error = new T();
557
557
  }
558
558
  /**
559
559
  * Processes a FetchExchange through the interceptor pipeline.
@@ -641,19 +641,19 @@ class K {
641
641
  * const result = await fetcher.exchange(exchange);
642
642
  * ```
643
643
  */
644
- async exchange(e) {
644
+ async exchange(t) {
645
645
  try {
646
- return await this.request.intercept(e), await this.response.intercept(e), e;
647
- } catch (t) {
648
- if (e.error = t, await this.error.intercept(e), !e.hasError())
649
- return e;
650
- throw new m(e);
646
+ return await this.request.intercept(t), await this.response.intercept(t), t;
647
+ } catch (e) {
648
+ if (t.error = e, await this.error.intercept(t), !t.hasError())
649
+ return t;
650
+ throw new R(t);
651
651
  }
652
652
  }
653
653
  }
654
- class W {
655
- constructor(e, t, s, n) {
656
- this.attributes = {}, this.fetcher = e, this.request = t, this.response = s, this.error = n;
654
+ class Z {
655
+ constructor(t, e, s, n) {
656
+ this.attributes = {}, this.fetcher = t, this.request = e, this.response = s, this.error = n;
657
657
  }
658
658
  /**
659
659
  * Ensures that request headers object exists, creating it if necessary.
@@ -712,20 +712,25 @@ class W {
712
712
  */
713
713
  get requiredResponse() {
714
714
  if (!this.response)
715
- throw new m(
715
+ throw new R(
716
716
  this,
717
717
  `Request to ${this.request.url} failed with no response`
718
718
  );
719
719
  return this.response;
720
720
  }
721
721
  }
722
- const P = {
723
- "Content-Type": d.APPLICATION_JSON
724
- }, b = {
722
+ const tt = (r) => r, et = (r) => r.requiredResponse, rt = (r) => r.requiredResponse.json(), st = (r) => r.requiredResponse.text(), O = {
723
+ Exchange: tt,
724
+ Response: et,
725
+ Json: rt,
726
+ Text: st
727
+ }, A = {
728
+ "Content-Type": E.APPLICATION_JSON
729
+ }, S = {
725
730
  baseURL: "",
726
- headers: P
731
+ headers: A
727
732
  };
728
- class Z {
733
+ class ot {
729
734
  /**
730
735
  * Initializes a new Fetcher instance with optional configuration.
731
736
  *
@@ -734,8 +739,8 @@ class Z {
734
739
  *
735
740
  * @param options - Configuration options for the Fetcher instance
736
741
  */
737
- constructor(e = b) {
738
- this.headers = P, this.urlBuilder = new v(e.baseURL, e.urlTemplateStyle), this.headers = e.headers ?? P, this.timeout = e.timeout, this.interceptors = e.interceptors ?? new K();
742
+ constructor(t = S) {
743
+ this.headers = A, this.urlBuilder = new x(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? A, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new W();
739
744
  }
740
745
  /**
741
746
  * Executes an HTTP request with the specified URL and options.
@@ -748,9 +753,9 @@ class Z {
748
753
  * @returns Promise that resolves to the HTTP response
749
754
  * @throws FetchError if the request fails and no response is generated
750
755
  */
751
- async fetch(e, t = {}) {
752
- const s = t;
753
- return s.url = e, (await this.request(s)).requiredResponse;
756
+ async fetch(t, e = {}) {
757
+ const s = e;
758
+ return s.url = t, this.request(s, O.Response);
754
759
  }
755
760
  /**
756
761
  * Processes an HTTP request through the Fetcher's internal workflow.
@@ -760,19 +765,22 @@ class Z {
760
765
  * for interceptor processing.
761
766
  *
762
767
  * @param request - Complete request configuration object
763
- * @returns Promise that resolves to a FetchExchange containing request/response data
768
+ * @param resultExtractor - Function to extract the desired result from the exchange.
769
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
770
+ * @returns Promise that resolves to the extracted result based on resultExtractor
764
771
  * @throws Error if an unhandled error occurs during request processing
765
772
  */
766
- async request(e) {
767
- const t = {
773
+ // @ts-expect-error - Required to bypass type checking for resultExtractor default value assignment
774
+ async request(t, e = O.Exchange) {
775
+ const s = {
768
776
  ...this.headers,
769
- ...e.headers
770
- }, s = {
771
- ...e,
772
- headers: t,
773
- timeout: G(e.timeout, this.timeout)
774
- }, n = new W(this, s);
775
- return this.interceptors.exchange(n);
777
+ ...t.headers
778
+ }, n = {
779
+ ...t,
780
+ headers: s,
781
+ timeout: G(t.timeout, this.timeout)
782
+ }, o = new Z(this, n);
783
+ return await this.interceptors.exchange(o), e(o);
776
784
  }
777
785
  /**
778
786
  * Internal helper method for making HTTP requests with a specific method.
@@ -785,10 +793,10 @@ class Z {
785
793
  * @param request - Additional request options
786
794
  * @returns Promise that resolves to the HTTP response
787
795
  */
788
- async methodFetch(e, t, s = {}) {
789
- return this.fetch(t, {
796
+ async methodFetch(t, e, s = {}) {
797
+ return this.fetch(e, {
790
798
  ...s,
791
- method: e
799
+ method: t
792
800
  });
793
801
  }
794
802
  /**
@@ -801,8 +809,8 @@ class Z {
801
809
  * @param request - Request options excluding method and body
802
810
  * @returns Promise that resolves to the HTTP response
803
811
  */
804
- async get(e, t = {}) {
805
- return this.methodFetch(u.GET, e, t);
812
+ async get(t, e = {}) {
813
+ return this.methodFetch(i.GET, t, e);
806
814
  }
807
815
  /**
808
816
  * Makes a POST HTTP request.
@@ -813,8 +821,8 @@ class Z {
813
821
  * @param request - Request options including body and other parameters
814
822
  * @returns Promise that resolves to the HTTP response
815
823
  */
816
- async post(e, t = {}) {
817
- return this.methodFetch(u.POST, e, t);
824
+ async post(t, e = {}) {
825
+ return this.methodFetch(i.POST, t, e);
818
826
  }
819
827
  /**
820
828
  * Makes a PUT HTTP request.
@@ -825,8 +833,8 @@ class Z {
825
833
  * @param request - Request options including body and other parameters
826
834
  * @returns Promise that resolves to the HTTP response
827
835
  */
828
- async put(e, t = {}) {
829
- return this.methodFetch(u.PUT, e, t);
836
+ async put(t, e = {}) {
837
+ return this.methodFetch(i.PUT, t, e);
830
838
  }
831
839
  /**
832
840
  * Makes a DELETE HTTP request.
@@ -837,8 +845,8 @@ class Z {
837
845
  * @param request - Request options excluding method and body
838
846
  * @returns Promise that resolves to the HTTP response
839
847
  */
840
- async delete(e, t = {}) {
841
- return this.methodFetch(u.DELETE, e, t);
848
+ async delete(t, e = {}) {
849
+ return this.methodFetch(i.DELETE, t, e);
842
850
  }
843
851
  /**
844
852
  * Makes a PATCH HTTP request.
@@ -849,8 +857,8 @@ class Z {
849
857
  * @param request - Request options including body and other parameters
850
858
  * @returns Promise that resolves to the HTTP response
851
859
  */
852
- async patch(e, t = {}) {
853
- return this.methodFetch(u.PATCH, e, t);
860
+ async patch(t, e = {}) {
861
+ return this.methodFetch(i.PATCH, t, e);
854
862
  }
855
863
  /**
856
864
  * Makes a HEAD HTTP request.
@@ -862,8 +870,8 @@ class Z {
862
870
  * @param request - Request options excluding method and body
863
871
  * @returns Promise that resolves to the HTTP response
864
872
  */
865
- async head(e, t = {}) {
866
- return this.methodFetch(u.HEAD, e, t);
873
+ async head(t, e = {}) {
874
+ return this.methodFetch(i.HEAD, t, e);
867
875
  }
868
876
  /**
869
877
  * Makes an OPTIONS HTTP request.
@@ -875,12 +883,12 @@ class Z {
875
883
  * @param request - Request options excluding method and body
876
884
  * @returns Promise that resolves to the HTTP response
877
885
  */
878
- async options(e, t = {}) {
879
- return this.methodFetch(u.OPTIONS, e, t);
886
+ async options(t, e = {}) {
887
+ return this.methodFetch(i.OPTIONS, t, e);
880
888
  }
881
889
  }
882
- const A = "default";
883
- class ee {
890
+ const y = "default";
891
+ class nt {
884
892
  constructor() {
885
893
  this.registrar = /* @__PURE__ */ new Map();
886
894
  }
@@ -893,8 +901,8 @@ class ee {
893
901
  * const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
894
902
  * fetcherRegistrar.register('api', fetcher);
895
903
  */
896
- register(e, t) {
897
- this.registrar.set(e, t);
904
+ register(t, e) {
905
+ this.registrar.set(t, e);
898
906
  }
899
907
  /**
900
908
  * Unregister a Fetcher instance by name
@@ -907,8 +915,8 @@ class ee {
907
915
  * console.log('Fetcher unregistered successfully');
908
916
  * }
909
917
  */
910
- unregister(e) {
911
- return this.registrar.delete(e);
918
+ unregister(t) {
919
+ return this.registrar.delete(t);
912
920
  }
913
921
  /**
914
922
  * Get a Fetcher instance by name
@@ -921,8 +929,8 @@ class ee {
921
929
  * // Use the fetcher
922
930
  * }
923
931
  */
924
- get(e) {
925
- return this.registrar.get(e);
932
+ get(t) {
933
+ return this.registrar.get(t);
926
934
  }
927
935
  /**
928
936
  * Get a Fetcher instance by name, throwing an error if not found
@@ -938,11 +946,11 @@ class ee {
938
946
  * console.error('Fetcher not found:', error.message);
939
947
  * }
940
948
  */
941
- requiredGet(e) {
942
- const t = this.get(e);
943
- if (!t)
944
- throw new Error(`Fetcher ${e} not found`);
945
- return t;
949
+ requiredGet(t) {
950
+ const e = this.get(t);
951
+ if (!e)
952
+ throw new Error(`Fetcher ${t} not found`);
953
+ return e;
946
954
  }
947
955
  /**
948
956
  * Get the default Fetcher instance
@@ -953,7 +961,7 @@ class ee {
953
961
  * const defaultFetcher = fetcherRegistrar.default;
954
962
  */
955
963
  get default() {
956
- return this.requiredGet(A);
964
+ return this.requiredGet(y);
957
965
  }
958
966
  /**
959
967
  * Set the default Fetcher instance
@@ -963,8 +971,8 @@ class ee {
963
971
  * const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
964
972
  * fetcherRegistrar.default = fetcher;
965
973
  */
966
- set default(e) {
967
- this.register(A, e);
974
+ set default(t) {
975
+ this.register(y, t);
968
976
  }
969
977
  /**
970
978
  * Get a copy of all registered fetchers
@@ -980,35 +988,36 @@ class ee {
980
988
  return new Map(this.registrar);
981
989
  }
982
990
  }
983
- const te = new ee();
984
- function O(r, e) {
985
- if (!(r === void 0 && e === void 0))
986
- return e === void 0 ? r : r === void 0 ? e : { ...r, ...e };
991
+ const it = new nt();
992
+ function _(r, t) {
993
+ if (!(r === void 0 && t === void 0))
994
+ return t === void 0 ? r : r === void 0 ? t : { ...r, ...t };
987
995
  }
988
- function oe(r, e) {
996
+ function ct(r, t) {
989
997
  if (Object.keys(r).length === 0)
990
- return e;
991
- if (Object.keys(e).length === 0)
998
+ return t;
999
+ if (Object.keys(t).length === 0)
992
1000
  return r;
993
- const t = {
994
- path: O(r.urlParams?.path, e.urlParams?.path),
995
- query: O(r.urlParams?.query, e.urlParams?.query)
1001
+ const e = {
1002
+ path: _(r.urlParams?.path, t.urlParams?.path),
1003
+ query: _(r.urlParams?.query, t.urlParams?.query)
996
1004
  }, s = {
997
1005
  ...r.headers,
998
- ...e.headers
999
- }, n = e.method ?? r.method, i = e.body ?? r.body, o = e.timeout ?? r.timeout, c = e.signal ?? r.signal;
1006
+ ...t.headers
1007
+ }, n = t.method ?? r.method, o = t.body ?? r.body, u = t.timeout ?? r.timeout, a = t.signal ?? r.signal, p = t.abortController ?? r.abortController;
1000
1008
  return {
1001
1009
  ...r,
1002
- ...e,
1010
+ ...t,
1003
1011
  method: n,
1004
- urlParams: t,
1012
+ urlParams: e,
1005
1013
  headers: s,
1006
- body: i,
1007
- timeout: o,
1008
- signal: c
1014
+ body: o,
1015
+ timeout: u,
1016
+ signal: a,
1017
+ abortController: p
1009
1018
  };
1010
1019
  }
1011
- class re extends Z {
1020
+ class ut extends ot {
1012
1021
  /**
1013
1022
  * Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
1014
1023
  *
@@ -1026,56 +1035,61 @@ class re extends Z {
1026
1035
  * headers: { 'Authorization': 'Bearer token' }
1027
1036
  * });
1028
1037
  */
1029
- constructor(e, t = b) {
1030
- super(t), this.name = e, te.register(e, this);
1038
+ constructor(t, e = S) {
1039
+ super(e), this.name = t, it.register(t, this);
1031
1040
  }
1032
1041
  }
1033
- const ie = new re(A);
1042
+ const ht = new ut(y);
1034
1043
  export {
1035
- ne as CONTENT_TYPE_HEADER,
1036
- d as ContentTypeValues,
1037
- A as DEFAULT_FETCHER_NAME,
1038
- b as DEFAULT_OPTIONS,
1039
- m as ExchangeError,
1040
- f as ExpressUrlTemplateResolver,
1041
- x as FETCH_INTERCEPTOR_NAME,
1042
- V as FETCH_INTERCEPTOR_ORDER,
1043
- W as FetchExchange,
1044
+ at as CONTENT_TYPE_HEADER,
1045
+ E as ContentTypeValues,
1046
+ y as DEFAULT_FETCHER_NAME,
1047
+ S as DEFAULT_OPTIONS,
1048
+ R as ExchangeError,
1049
+ tt as ExchangeResultExtractor,
1050
+ P as ExpressUrlTemplateResolver,
1051
+ V as FETCH_INTERCEPTOR_NAME,
1052
+ J as FETCH_INTERCEPTOR_ORDER,
1053
+ Z as FetchExchange,
1044
1054
  k as FetchInterceptor,
1045
- y as FetchTimeoutError,
1046
- Z as Fetcher,
1055
+ I as FetchTimeoutError,
1056
+ ot as Fetcher,
1047
1057
  l as FetcherError,
1048
- ee as FetcherRegistrar,
1049
- u as HttpMethod,
1050
- I as HttpStatusValidationError,
1051
- K as InterceptorManager,
1052
- R as InterceptorRegistry,
1053
- re as NamedFetcher,
1054
- $ as REQUEST_BODY_INTERCEPTOR_NAME,
1055
- j as REQUEST_BODY_INTERCEPTOR_ORDER,
1058
+ nt as FetcherRegistrar,
1059
+ i as HttpMethod,
1060
+ g as HttpStatusValidationError,
1061
+ W as InterceptorManager,
1062
+ T as InterceptorRegistry,
1063
+ rt as JsonResultExtractor,
1064
+ ut as NamedFetcher,
1065
+ B as REQUEST_BODY_INTERCEPTOR_NAME,
1066
+ $ as REQUEST_BODY_INTERCEPTOR_ORDER,
1056
1067
  X as RequestBodyInterceptor,
1068
+ et as ResponseResultExtractor,
1069
+ O as ResultExtractors,
1070
+ st as TextResultExtractor,
1057
1071
  H as URL_RESOLVE_INTERCEPTOR_NAME,
1058
- w as URL_RESOLVE_INTERCEPTOR_ORDER,
1059
- T as UriTemplateResolver,
1060
- v as UrlBuilder,
1061
- B as UrlResolveInterceptor,
1072
+ N as URL_RESOLVE_INTERCEPTOR_ORDER,
1073
+ f as UriTemplateResolver,
1074
+ x as UrlBuilder,
1075
+ j as UrlResolveInterceptor,
1062
1076
  U as UrlTemplateStyle,
1063
- Y as VALIDATE_STATUS_INTERCEPTOR_NAME,
1064
- z as VALIDATE_STATUS_INTERCEPTOR_ORDER,
1065
- Q as ValidateStatusInterceptor,
1066
- F as combineURLs,
1067
- C as expressUrlTemplateResolver,
1068
- ie as fetcher,
1069
- te as fetcherRegistrar,
1077
+ z as VALIDATE_STATUS_INTERCEPTOR_NAME,
1078
+ Q as VALIDATE_STATUS_INTERCEPTOR_ORDER,
1079
+ K as ValidateStatusInterceptor,
1080
+ C as combineURLs,
1081
+ v as expressUrlTemplateResolver,
1082
+ ht as fetcher,
1083
+ it as fetcherRegistrar,
1070
1084
  D as getUrlTemplateResolver,
1071
- S as isAbsoluteURL,
1072
- O as mergeRecords,
1073
- oe as mergeRequest,
1085
+ F as isAbsoluteURL,
1086
+ _ as mergeRecords,
1087
+ ct as mergeRequest,
1074
1088
  G as resolveTimeout,
1075
1089
  M as timeoutFetch,
1076
- p as toSorted,
1090
+ m as toSorted,
1077
1091
  L as uriTemplateResolver,
1078
- q as urlTemplateRegexExtract,
1079
- _ as urlTemplateRegexResolve
1092
+ w as urlTemplateRegexExtract,
1093
+ q as urlTemplateRegexResolve
1080
1094
  };
1081
1095
  //# sourceMappingURL=index.es.js.map