@ahoo-wang/fetcher 1.5.9 → 1.6.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
1
  function F(r) {
2
2
  return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(r);
3
3
  }
4
- function C(r, t) {
5
- return F(t) ? t : t ? r.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : r;
4
+ function C(r, e) {
5
+ return F(e) ? e : e ? r.replace(/\/?\/$/, "") + "/" + e.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
9
  return r === 1 ? v : L;
10
10
  }
11
- function q(r, t, e) {
12
- return e ? r.replace(t, (s, o) => {
13
- const n = e[o];
11
+ function q(r, e, t) {
12
+ return t ? r.replace(e, (s, o) => {
13
+ const n = t[o];
14
14
  if (n === void 0)
15
15
  throw new Error(`Missing required path parameter: ${o}`);
16
16
  return encodeURIComponent(n);
17
17
  }) : r;
18
18
  }
19
- function w(r, t) {
20
- const e = [];
19
+ function w(r, e) {
20
+ const t = [];
21
21
  let s;
22
- for (; (s = t.exec(r)) !== null; )
23
- e.push(s[1]);
24
- return e;
22
+ for (; (s = e.exec(r)) !== null; )
23
+ t.push(s[1]);
24
+ return t;
25
25
  }
26
- const a = class a {
26
+ const h = class h {
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(t) {
50
+ extractPathParams(e) {
51
51
  return w(
52
- t,
53
- a.PATH_PARAM_REGEX
52
+ e,
53
+ h.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(t, e) {
92
+ resolve(e, t) {
93
93
  return q(
94
- t,
95
- a.PATH_PARAM_REGEX,
96
- e
94
+ e,
95
+ h.PATH_PARAM_REGEX,
96
+ t
97
97
  );
98
98
  }
99
99
  };
100
- a.PATH_PARAM_REGEX = /{([^}]+)}/g;
101
- let f = a;
102
- const L = new f(), h = class h {
100
+ h.PATH_PARAM_REGEX = /{([^}]+)}/g;
101
+ let P = h;
102
+ const L = new P(), l = class l {
103
103
  /**
104
104
  * Extracts path parameters from an Express-style URL string.
105
105
  *
@@ -119,10 +119,10 @@ const L = new f(), h = class h {
119
119
  * // noParams = []
120
120
  * ```
121
121
  */
122
- extractPathParams(t) {
122
+ extractPathParams(e) {
123
123
  return w(
124
- t,
125
- h.PATH_PARAM_REGEX
124
+ e,
125
+ l.PATH_PARAM_REGEX
126
126
  );
127
127
  }
128
128
  /**
@@ -157,17 +157,17 @@ const L = new f(), h = class h {
157
157
  * }
158
158
  * ```
159
159
  */
160
- resolve(t, e) {
160
+ resolve(e, t) {
161
161
  return q(
162
- t,
163
- h.PATH_PARAM_REGEX,
164
- e
162
+ e,
163
+ l.PATH_PARAM_REGEX,
164
+ t
165
165
  );
166
166
  }
167
167
  };
168
- h.PATH_PARAM_REGEX = /:([^/]+)/g;
169
- let P = h;
170
- const v = new P();
168
+ l.PATH_PARAM_REGEX = /:([^/]+)/g;
169
+ let A = l;
170
+ const v = new A();
171
171
  class x {
172
172
  /**
173
173
  * Initializes a new UrlBuilder instance.
@@ -186,8 +186,8 @@ class x {
186
186
  * const expressUrlBuilder = new UrlBuilder('https://api.example.com', UrlTemplateStyle.Express);
187
187
  * ```
188
188
  */
189
- constructor(t, e) {
190
- this.baseURL = t, this.urlTemplateResolver = D(e);
189
+ constructor(e, t) {
190
+ this.baseURL = e, this.urlTemplateResolver = D(t);
191
191
  }
192
192
  /**
193
193
  * Builds a complete URL, including path parameter replacement and query parameter addition.
@@ -207,14 +207,14 @@ class x {
207
207
  * // Result: https://api.example.com/users/123/posts/456?filter=active&limit=10
208
208
  * ```
209
209
  */
210
- build(t, e) {
211
- const s = e?.path, o = e?.query, n = C(this.baseURL, t);
212
- let i = this.urlTemplateResolver.resolve(n, s);
210
+ build(e, t) {
211
+ const s = t?.path, o = t?.query, n = C(this.baseURL, e);
212
+ let u = this.urlTemplateResolver.resolve(n, s);
213
213
  if (o) {
214
- const c = new URLSearchParams(o).toString();
215
- c && (i += "?" + c);
214
+ const a = new URLSearchParams(o).toString();
215
+ a && (u += "?" + a);
216
216
  }
217
- return i;
217
+ return u;
218
218
  }
219
219
  /**
220
220
  * Resolves a complete URL from a FetchRequest.
@@ -225,54 +225,54 @@ class x {
225
225
  * @param request - The FetchRequest containing URL and URL parameters
226
226
  * @returns Complete resolved URL string
227
227
  */
228
- resolveRequestUrl(t) {
229
- return this.build(t.url, t.urlParams);
228
+ resolveRequestUrl(e) {
229
+ return this.build(e.url, e.urlParams);
230
230
  }
231
231
  }
232
- class l extends Error {
232
+ class E extends Error {
233
233
  /**
234
234
  * Creates a new FetcherError instance.
235
235
  *
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(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);
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, E.prototype);
242
242
  }
243
243
  }
244
- class I extends l {
244
+ class I extends E {
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(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);
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, I.prototype);
253
253
  }
254
254
  }
255
- function G(r, t) {
256
- return typeof r < "u" ? r : t;
255
+ function G(r, e) {
256
+ return typeof r < "u" ? r : e;
257
257
  }
258
258
  async function M(r) {
259
- const t = r.url, e = r.timeout, s = r;
259
+ const e = r.url, t = r.timeout, s = r;
260
260
  if (r.signal)
261
- return fetch(t, s);
262
- if (!e)
263
- return r.abortController && (s.signal = r.abortController.signal), fetch(t, s);
261
+ return fetch(e, s);
262
+ if (!t)
263
+ return r.abortController && (s.signal = r.abortController.signal), fetch(e, s);
264
264
  const o = r.abortController ?? new AbortController();
265
265
  s.signal = o.signal;
266
266
  let n = null;
267
- const i = new Promise((c, p) => {
267
+ const u = new Promise((a, m) => {
268
268
  n = setTimeout(() => {
269
269
  n && clearTimeout(n);
270
270
  const _ = new I(r);
271
- o.abort(_), p(_);
272
- }, e);
271
+ o.abort(_), m(_);
272
+ }, t);
273
273
  });
274
274
  try {
275
- return await Promise.race([fetch(t, s), i]);
275
+ return await Promise.race([fetch(e, s), u]);
276
276
  } finally {
277
277
  n && clearTimeout(n);
278
278
  }
@@ -287,16 +287,16 @@ class j {
287
287
  *
288
288
  * @param exchange - The fetch exchange containing the request information
289
289
  */
290
- intercept(t) {
291
- const e = t.request;
292
- e.url = t.fetcher.urlBuilder.resolveRequestUrl(e);
290
+ intercept(e) {
291
+ const t = e.request;
292
+ t.url = e.fetcher.urlBuilder.resolveRequestUrl(t);
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 ct = "Content-Type", d = class d {
295
+ var c = /* @__PURE__ */ ((r) => (r.GET = "GET", r.POST = "POST", r.PUT = "PUT", r.DELETE = "DELETE", r.PATCH = "PATCH", r.HEAD = "HEAD", r.OPTIONS = "OPTIONS", r))(c || {});
296
+ const ce = "Content-Type", R = class R {
297
297
  };
298
- d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
299
- let E = d;
298
+ R.APPLICATION_JSON = "application/json", R.TEXT_EVENT_STREAM = "text/event-stream";
299
+ let d = R;
300
300
  const B = "RequestBodyInterceptor", $ = N + 1e3;
301
301
  class X {
302
302
  constructor() {
@@ -339,14 +339,14 @@ 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(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)
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)
346
346
  return;
347
- t.request.body = JSON.stringify(e.body);
348
- const s = t.ensureRequestHeaders();
349
- s["Content-Type"] || (s["Content-Type"] = E.APPLICATION_JSON);
347
+ e.request.body = JSON.stringify(t.body);
348
+ const s = e.ensureRequestHeaders();
349
+ s["Content-Type"] || (s["Content-Type"] = d.APPLICATION_JSON);
350
350
  }
351
351
  }
352
352
  const V = "FetchInterceptor", J = Number.MAX_SAFE_INTEGER - 1e3;
@@ -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(t) {
383
- t.response = await M(t.request);
382
+ async intercept(e) {
383
+ e.response = await M(e.request);
384
384
  }
385
385
  }
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);
386
+ function T(r, e) {
387
+ return e ? r.filter(e).sort((t, s) => t.order - s.order) : [...r].sort((t, s) => t.order - s.order);
388
388
  }
389
- class T {
389
+ class f {
390
390
  /**
391
391
  * Initializes a new InterceptorRegistry instance.
392
392
  *
@@ -396,8 +396,8 @@ class T {
396
396
  * The provided interceptors will be sorted by their order property immediately
397
397
  * upon construction.
398
398
  */
399
- constructor(t = []) {
400
- this.sortedInterceptors = [], this.sortedInterceptors = m(t);
399
+ constructor(e = []) {
400
+ this.sortedInterceptors = [], this.sortedInterceptors = T(e);
401
401
  }
402
402
  /**
403
403
  * Gets the name of this interceptor registry.
@@ -434,10 +434,10 @@ class T {
434
434
  *
435
435
  * After adding, interceptors are automatically sorted by their order property.
436
436
  */
437
- use(t) {
438
- return this.sortedInterceptors.some((e) => e.name === t.name) ? !1 : (this.sortedInterceptors = m([
437
+ use(e) {
438
+ return this.sortedInterceptors.some((t) => t.name === e.name) ? !1 : (this.sortedInterceptors = T([
439
439
  ...this.sortedInterceptors,
440
- t
440
+ e
441
441
  ]), !0);
442
442
  }
443
443
  /**
@@ -447,12 +447,12 @@ class T {
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(t) {
451
- const e = this.sortedInterceptors;
452
- return this.sortedInterceptors = m(
453
- e,
454
- (s) => s.name !== t
455
- ), e.length !== this.sortedInterceptors.length;
450
+ eject(e) {
451
+ const t = this.sortedInterceptors;
452
+ return this.sortedInterceptors = T(
453
+ t,
454
+ (s) => s.name !== e
455
+ ), t.length !== this.sortedInterceptors.length;
456
456
  }
457
457
  /**
458
458
  * Removes all interceptors from this registry.
@@ -474,16 +474,16 @@ class T {
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(t) {
478
- for (const e of this.sortedInterceptors)
479
- await e.intercept(t);
477
+ async intercept(e) {
478
+ for (const t of this.sortedInterceptors)
479
+ await t.intercept(e);
480
480
  }
481
481
  }
482
- class O extends l {
483
- constructor(t) {
482
+ class O extends E {
483
+ constructor(e) {
484
484
  super(
485
- `Request failed with status code ${t.response?.status} for ${t.request.url}`
486
- ), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, O.prototype);
485
+ `Request failed with status code ${e.response?.status} for ${e.request.url}`
486
+ ), this.exchange = e, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, O.prototype);
487
487
  }
488
488
  }
489
489
  const Y = (r) => r >= 200 && r < 300, z = "ValidateStatusInterceptor", Q = Number.MAX_SAFE_INTEGER - 1e3;
@@ -493,8 +493,8 @@ class K {
493
493
  *
494
494
  * @param validateStatus - Function that determines if a status code is valid
495
495
  */
496
- constructor(t = Y) {
497
- this.validateStatus = t;
496
+ constructor(e = Y) {
497
+ this.validateStatus = e;
498
498
  }
499
499
  /**
500
500
  * Gets the name of this interceptor.
@@ -525,35 +525,35 @@ class K {
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(t) {
529
- if (!t.response)
528
+ intercept(e) {
529
+ if (!e.response)
530
530
  return;
531
- const e = t.response.status;
532
- if (!this.validateStatus(e))
533
- throw new O(t);
531
+ const t = e.response.status;
532
+ if (!this.validateStatus(t))
533
+ throw new O(e);
534
534
  }
535
535
  }
536
- class R extends l {
536
+ class p extends E {
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(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);
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, p.prototype);
546
546
  }
547
547
  }
548
548
  class W {
549
549
  constructor() {
550
- this.request = new T([
550
+ this.request = new f([
551
551
  new j(),
552
552
  new X(),
553
553
  new k()
554
- ]), this.response = new T([
554
+ ]), this.response = new f([
555
555
  new K()
556
- ]), this.error = new T();
556
+ ]), this.error = new f();
557
557
  }
558
558
  /**
559
559
  * Processes a FetchExchange through the interceptor pipeline.
@@ -641,25 +641,25 @@ class W {
641
641
  * const result = await fetcher.exchange(exchange);
642
642
  * ```
643
643
  */
644
- async exchange(t) {
644
+ async exchange(e) {
645
645
  try {
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);
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 p(e);
651
651
  }
652
652
  }
653
653
  }
654
- const Z = (r) => r, tt = (r) => r.requiredResponse, et = (r) => r.requiredResponse.json(), rt = (r) => r.requiredResponse.text(), A = {
654
+ const Z = (r) => r, ee = (r) => r.requiredResponse, te = (r) => r.requiredResponse.json(), re = (r) => r.requiredResponse.text(), i = {
655
655
  Exchange: Z,
656
- Response: tt,
657
- Json: et,
658
- Text: rt
656
+ Response: ee,
657
+ Json: te,
658
+ Text: re
659
659
  };
660
- class st {
661
- constructor(t) {
662
- this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ?? A.Exchange, this.attributes = t.attributes ?? {}, this.response = t.response, this.error = t.error;
660
+ class se {
661
+ constructor(e) {
662
+ this.fetcher = e.fetcher, this.request = e.request, this.resultExtractor = e.resultExtractor ?? i.Exchange, this.attributes = e.attributes ?? {}, this.response = e.response, this.error = e.error;
663
663
  }
664
664
  /**
665
665
  * Ensures that request headers object exists, creating it if necessary.
@@ -718,7 +718,7 @@ class st {
718
718
  */
719
719
  get requiredResponse() {
720
720
  if (!this.response)
721
- throw new R(
721
+ throw new p(
722
722
  this,
723
723
  `Request to ${this.request.url} failed with no response`
724
724
  );
@@ -735,12 +735,12 @@ class st {
735
735
  }
736
736
  }
737
737
  const y = {
738
- "Content-Type": E.APPLICATION_JSON
738
+ "Content-Type": d.APPLICATION_JSON
739
739
  }, S = {
740
740
  baseURL: "",
741
741
  headers: y
742
742
  };
743
- class ot {
743
+ class oe {
744
744
  /**
745
745
  * Initializes a new Fetcher instance with optional configuration.
746
746
  *
@@ -749,26 +749,8 @@ class ot {
749
749
  *
750
750
  * @param options - Configuration options for the Fetcher instance
751
751
  */
752
- constructor(t = S) {
753
- this.headers = y, this.urlBuilder = new x(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? y, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new W();
754
- }
755
- /**
756
- * Executes an HTTP request with the specified URL and options.
757
- *
758
- * This is the primary method for making HTTP requests. It processes the request
759
- * through the interceptor chain and returns the resulting Response.
760
- *
761
- * @param url - The URL path for the request (relative to baseURL if set)
762
- * @param request - Request configuration including headers, body, parameters, etc.
763
- * @param attributes - Optional shared attributes that can be accessed by interceptors
764
- * throughout the request lifecycle. These attributes allow passing
765
- * custom data between different interceptors.
766
- * @returns Promise that resolves to the HTTP response
767
- * @throws FetchError if the request fails and no response is generated
768
- */
769
- async fetch(t, e = {}, s) {
770
- const o = e;
771
- return o.url = t, this.request(o, A.Response, s);
752
+ constructor(e = S) {
753
+ this.headers = y, this.urlBuilder = new x(e.baseURL, e.urlTemplateStyle), this.headers = e.headers ?? y, this.timeout = e.timeout, this.interceptors = e.interceptors ?? new W();
772
754
  }
773
755
  /**
774
756
  * Processes an HTTP request through the Fetcher's internal workflow.
@@ -786,21 +768,42 @@ class ot {
786
768
  * @returns Promise that resolves to the extracted result based on resultExtractor
787
769
  * @throws Error if an unhandled error occurs during request processing
788
770
  */
789
- async request(t, e = A.Exchange, s) {
771
+ async request(e, t = i.Exchange, s) {
790
772
  const o = {
791
773
  ...this.headers,
792
- ...t.headers
774
+ ...e.headers
793
775
  }, n = {
794
- ...t,
776
+ ...e,
795
777
  headers: o,
796
- timeout: G(t.timeout, this.timeout)
797
- }, i = new st({
778
+ timeout: G(e.timeout, this.timeout)
779
+ }, u = new se({
798
780
  fetcher: this,
799
781
  request: n,
800
- resultExtractor: e,
782
+ resultExtractor: t,
801
783
  attributes: s
802
784
  });
803
- return await this.interceptors.exchange(i), i.typedExtractedResult();
785
+ return await this.interceptors.exchange(u), u.typedExtractedResult();
786
+ }
787
+ /**
788
+ * Executes an HTTP request with the specified URL and options.
789
+ *
790
+ * This is the primary method for making HTTP requests. It processes the request
791
+ * through the interceptor chain and returns the resulting Response.
792
+ *
793
+ * @param url - The URL path for the request (relative to baseURL if set)
794
+ * @param request - Request configuration including headers, body, parameters, etc.
795
+ * @param resultExtractor - Function to extract the desired result from the exchange.
796
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
797
+ * @param attributes - Optional shared attributes that can be accessed by interceptors
798
+ * throughout the request lifecycle. These attributes allow passing
799
+ * custom data between different interceptors.
800
+
801
+ * @returns Promise that resolves to the HTTP response
802
+ * @throws FetchError if the request fails and no response is generated
803
+ */
804
+ async fetch(e, t = {}, s = i.Response, o) {
805
+ const n = t;
806
+ return n.url = e, this.request(n, s, o);
804
807
  }
805
808
  /**
806
809
  * Internal helper method for making HTTP requests with a specific method.
@@ -811,19 +814,22 @@ class ot {
811
814
  * @param method - The HTTP method to use for the request
812
815
  * @param url - The URL path for the request
813
816
  * @param request - Additional request options
817
+ * @param resultExtractor - Function to extract the desired result from the exchange.
818
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
814
819
  * @param attributes - Optional shared attributes that can be accessed by interceptors
815
820
  * throughout the request lifecycle. These attributes allow passing
816
821
  * custom data between different interceptors.
817
822
  * @returns Promise that resolves to the HTTP response
818
823
  */
819
- async methodFetch(t, e, s = {}, o) {
824
+ async methodFetch(e, t, s = {}, o = i.Response, n) {
820
825
  return this.fetch(
821
- e,
826
+ t,
822
827
  {
823
828
  ...s,
824
- method: t
829
+ method: e
825
830
  },
826
- o
831
+ o,
832
+ n
827
833
  );
828
834
  }
829
835
  /**
@@ -834,13 +840,15 @@ class ot {
834
840
  *
835
841
  * @param url - The URL path for the request
836
842
  * @param request - Request options excluding method and body
843
+ * @param resultExtractor - Function to extract the desired result from the exchange.
844
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
837
845
  * @param attributes - Optional shared attributes that can be accessed by interceptors
838
846
  * throughout the request lifecycle. These attributes allow passing
839
847
  * custom data between different interceptors.
840
848
  * @returns Promise that resolves to the HTTP response
841
849
  */
842
- async get(t, e = {}, s) {
843
- return this.methodFetch(u.GET, t, e, s);
850
+ async get(e, t = {}, s = i.Response, o) {
851
+ return this.methodFetch(c.GET, e, t, s, o);
844
852
  }
845
853
  /**
846
854
  * Makes a POST HTTP request.
@@ -849,13 +857,15 @@ class ot {
849
857
  *
850
858
  * @param url - The URL path for the request
851
859
  * @param request - Request options including body and other parameters
860
+ * @param resultExtractor - Function to extract the desired result from the exchange.
861
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
852
862
  * @param attributes - Optional shared attributes that can be accessed by interceptors
853
863
  * throughout the request lifecycle. These attributes allow passing
854
864
  * custom data between different interceptors.
855
865
  * @returns Promise that resolves to the HTTP response
856
866
  */
857
- async post(t, e = {}, s) {
858
- return this.methodFetch(u.POST, t, e, s);
867
+ async post(e, t = {}, s = i.Response, o) {
868
+ return this.methodFetch(c.POST, e, t, s, o);
859
869
  }
860
870
  /**
861
871
  * Makes a PUT HTTP request.
@@ -864,13 +874,15 @@ class ot {
864
874
  *
865
875
  * @param url - The URL path for the request
866
876
  * @param request - Request options including body and other parameters
877
+ * @param resultExtractor - Function to extract the desired result from the exchange.
878
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
867
879
  * @param attributes - Optional shared attributes that can be accessed by interceptors
868
880
  * throughout the request lifecycle. These attributes allow passing
869
881
  * custom data between different interceptors.
870
882
  * @returns Promise that resolves to the HTTP response
871
883
  */
872
- async put(t, e = {}, s) {
873
- return this.methodFetch(u.PUT, t, e, s);
884
+ async put(e, t = {}, s = i.Response, o) {
885
+ return this.methodFetch(c.PUT, e, t, s, o);
874
886
  }
875
887
  /**
876
888
  * Makes a DELETE HTTP request.
@@ -879,13 +891,15 @@ class ot {
879
891
  *
880
892
  * @param url - The URL path for the request
881
893
  * @param request - Request options excluding method and body
894
+ * @param resultExtractor - Function to extract the desired result from the exchange.
895
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
882
896
  * @param attributes - Optional shared attributes that can be accessed by interceptors
883
897
  * throughout the request lifecycle. These attributes allow passing
884
898
  * custom data between different interceptors.
885
899
  * @returns Promise that resolves to the HTTP response
886
900
  */
887
- async delete(t, e = {}, s) {
888
- return this.methodFetch(u.DELETE, t, e, s);
901
+ async delete(e, t = {}, s = i.Response, o) {
902
+ return this.methodFetch(c.DELETE, e, t, s, o);
889
903
  }
890
904
  /**
891
905
  * Makes a PATCH HTTP request.
@@ -894,13 +908,15 @@ class ot {
894
908
  *
895
909
  * @param url - The URL path for the request
896
910
  * @param request - Request options including body and other parameters
911
+ * @param resultExtractor - Function to extract the desired result from the exchange.
912
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
897
913
  * @param attributes - Optional shared attributes that can be accessed by interceptors
898
914
  * throughout the request lifecycle. These attributes allow passing
899
915
  * custom data between different interceptors.
900
916
  * @returns Promise that resolves to the HTTP response
901
917
  */
902
- async patch(t, e = {}, s) {
903
- return this.methodFetch(u.PATCH, t, e, s);
918
+ async patch(e, t = {}, s = i.Response, o) {
919
+ return this.methodFetch(c.PATCH, e, t, s, o);
904
920
  }
905
921
  /**
906
922
  * Makes a HEAD HTTP request.
@@ -910,13 +926,15 @@ class ot {
910
926
  *
911
927
  * @param url - The URL path for the request
912
928
  * @param request - Request options excluding method and body
929
+ * @param resultExtractor - Function to extract the desired result from the exchange.
930
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
913
931
  * @param attributes - Optional shared attributes that can be accessed by interceptors
914
932
  * throughout the request lifecycle. These attributes allow passing
915
933
  * custom data between different interceptors.
916
934
  * @returns Promise that resolves to the HTTP response
917
935
  */
918
- async head(t, e = {}, s) {
919
- return this.methodFetch(u.HEAD, t, e, s);
936
+ async head(e, t = {}, s = i.Response, o) {
937
+ return this.methodFetch(c.HEAD, e, t, s, o);
920
938
  }
921
939
  /**
922
940
  * Makes an OPTIONS HTTP request.
@@ -926,17 +944,19 @@ class ot {
926
944
  *
927
945
  * @param url - The URL path for the request
928
946
  * @param request - Request options excluding method and body
947
+ * @param resultExtractor - Function to extract the desired result from the exchange.
948
+ * Defaults to ExchangeResultExtractor which returns the entire exchange object.
929
949
  * @param attributes - Optional shared attributes that can be accessed by interceptors
930
950
  * throughout the request lifecycle. These attributes allow passing
931
951
  * custom data between different interceptors.
932
952
  * @returns Promise that resolves to the HTTP response
933
953
  */
934
- async options(t, e = {}, s) {
935
- return this.methodFetch(u.OPTIONS, t, e, s);
954
+ async options(e, t = {}, s = i.Response, o) {
955
+ return this.methodFetch(c.OPTIONS, e, t, s, o);
936
956
  }
937
957
  }
938
958
  const b = "default";
939
- class nt {
959
+ class ne {
940
960
  constructor() {
941
961
  this.registrar = /* @__PURE__ */ new Map();
942
962
  }
@@ -949,8 +969,8 @@ class nt {
949
969
  * const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
950
970
  * fetcherRegistrar.register('api', fetcher);
951
971
  */
952
- register(t, e) {
953
- this.registrar.set(t, e);
972
+ register(e, t) {
973
+ this.registrar.set(e, t);
954
974
  }
955
975
  /**
956
976
  * Unregister a Fetcher instance by name
@@ -963,8 +983,8 @@ class nt {
963
983
  * console.log('Fetcher unregistered successfully');
964
984
  * }
965
985
  */
966
- unregister(t) {
967
- return this.registrar.delete(t);
986
+ unregister(e) {
987
+ return this.registrar.delete(e);
968
988
  }
969
989
  /**
970
990
  * Get a Fetcher instance by name
@@ -977,8 +997,8 @@ class nt {
977
997
  * // Use the fetcher
978
998
  * }
979
999
  */
980
- get(t) {
981
- return this.registrar.get(t);
1000
+ get(e) {
1001
+ return this.registrar.get(e);
982
1002
  }
983
1003
  /**
984
1004
  * Get a Fetcher instance by name, throwing an error if not found
@@ -994,11 +1014,11 @@ class nt {
994
1014
  * console.error('Fetcher not found:', error.message);
995
1015
  * }
996
1016
  */
997
- requiredGet(t) {
998
- const e = this.get(t);
999
- if (!e)
1000
- throw new Error(`Fetcher ${t} not found`);
1001
- return e;
1017
+ requiredGet(e) {
1018
+ const t = this.get(e);
1019
+ if (!t)
1020
+ throw new Error(`Fetcher ${e} not found`);
1021
+ return t;
1002
1022
  }
1003
1023
  /**
1004
1024
  * Get the default Fetcher instance
@@ -1019,8 +1039,8 @@ class nt {
1019
1039
  * const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
1020
1040
  * fetcherRegistrar.default = fetcher;
1021
1041
  */
1022
- set default(t) {
1023
- this.register(b, t);
1042
+ set default(e) {
1043
+ this.register(b, e);
1024
1044
  }
1025
1045
  /**
1026
1046
  * Get a copy of all registered fetchers
@@ -1036,36 +1056,36 @@ class nt {
1036
1056
  return new Map(this.registrar);
1037
1057
  }
1038
1058
  }
1039
- const it = new nt();
1040
- function g(r, t) {
1041
- if (!(r === void 0 && t === void 0))
1042
- return t === void 0 ? r : r === void 0 ? t : { ...r, ...t };
1059
+ const ie = new ne();
1060
+ function g(r, e) {
1061
+ if (!(r === void 0 && e === void 0))
1062
+ return e === void 0 ? r : r === void 0 ? e : { ...r, ...e };
1043
1063
  }
1044
- function at(r, t) {
1064
+ function ae(r, e) {
1045
1065
  if (Object.keys(r).length === 0)
1046
- return t;
1047
- if (Object.keys(t).length === 0)
1066
+ return e;
1067
+ if (Object.keys(e).length === 0)
1048
1068
  return r;
1049
- const e = {
1050
- path: g(r.urlParams?.path, t.urlParams?.path),
1051
- query: g(r.urlParams?.query, t.urlParams?.query)
1069
+ const t = {
1070
+ path: g(r.urlParams?.path, e.urlParams?.path),
1071
+ query: g(r.urlParams?.query, e.urlParams?.query)
1052
1072
  }, s = {
1053
1073
  ...r.headers,
1054
- ...t.headers
1055
- }, o = t.method ?? r.method, n = t.body ?? r.body, i = t.timeout ?? r.timeout, c = t.signal ?? r.signal, p = t.abortController ?? r.abortController;
1074
+ ...e.headers
1075
+ }, o = e.method ?? r.method, n = e.body ?? r.body, u = e.timeout ?? r.timeout, a = e.signal ?? r.signal, m = e.abortController ?? r.abortController;
1056
1076
  return {
1057
1077
  ...r,
1058
- ...t,
1078
+ ...e,
1059
1079
  method: o,
1060
- urlParams: e,
1080
+ urlParams: t,
1061
1081
  headers: s,
1062
1082
  body: n,
1063
- timeout: i,
1064
- signal: c,
1065
- abortController: p
1083
+ timeout: u,
1084
+ signal: a,
1085
+ abortController: m
1066
1086
  };
1067
1087
  }
1068
- class ut extends ot {
1088
+ class ue extends oe {
1069
1089
  /**
1070
1090
  * Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
1071
1091
  *
@@ -1083,42 +1103,42 @@ class ut extends ot {
1083
1103
  * headers: { 'Authorization': 'Bearer token' }
1084
1104
  * });
1085
1105
  */
1086
- constructor(t, e = S) {
1087
- super(e), this.name = t, it.register(t, this);
1106
+ constructor(e, t = S) {
1107
+ super(t), this.name = e, ie.register(e, this);
1088
1108
  }
1089
1109
  }
1090
- const ht = new ut(b);
1110
+ const he = new ue(b);
1091
1111
  export {
1092
- ct as CONTENT_TYPE_HEADER,
1093
- E as ContentTypeValues,
1112
+ ce as CONTENT_TYPE_HEADER,
1113
+ d as ContentTypeValues,
1094
1114
  b as DEFAULT_FETCHER_NAME,
1095
1115
  S as DEFAULT_OPTIONS,
1096
- R as ExchangeError,
1116
+ p as ExchangeError,
1097
1117
  Z as ExchangeResultExtractor,
1098
- P as ExpressUrlTemplateResolver,
1118
+ A as ExpressUrlTemplateResolver,
1099
1119
  V as FETCH_INTERCEPTOR_NAME,
1100
1120
  J as FETCH_INTERCEPTOR_ORDER,
1101
- st as FetchExchange,
1121
+ se as FetchExchange,
1102
1122
  k as FetchInterceptor,
1103
1123
  I as FetchTimeoutError,
1104
- ot as Fetcher,
1105
- l as FetcherError,
1106
- nt as FetcherRegistrar,
1107
- u as HttpMethod,
1124
+ oe as Fetcher,
1125
+ E as FetcherError,
1126
+ ne as FetcherRegistrar,
1127
+ c as HttpMethod,
1108
1128
  O as HttpStatusValidationError,
1109
1129
  W as InterceptorManager,
1110
- T as InterceptorRegistry,
1111
- et as JsonResultExtractor,
1112
- ut as NamedFetcher,
1130
+ f as InterceptorRegistry,
1131
+ te as JsonResultExtractor,
1132
+ ue as NamedFetcher,
1113
1133
  B as REQUEST_BODY_INTERCEPTOR_NAME,
1114
1134
  $ as REQUEST_BODY_INTERCEPTOR_ORDER,
1115
1135
  X as RequestBodyInterceptor,
1116
- tt as ResponseResultExtractor,
1117
- A as ResultExtractors,
1118
- rt as TextResultExtractor,
1136
+ ee as ResponseResultExtractor,
1137
+ i as ResultExtractors,
1138
+ re as TextResultExtractor,
1119
1139
  H as URL_RESOLVE_INTERCEPTOR_NAME,
1120
1140
  N as URL_RESOLVE_INTERCEPTOR_ORDER,
1121
- f as UriTemplateResolver,
1141
+ P as UriTemplateResolver,
1122
1142
  x as UrlBuilder,
1123
1143
  j as UrlResolveInterceptor,
1124
1144
  U as UrlTemplateStyle,
@@ -1127,15 +1147,15 @@ export {
1127
1147
  K as ValidateStatusInterceptor,
1128
1148
  C as combineURLs,
1129
1149
  v as expressUrlTemplateResolver,
1130
- ht as fetcher,
1131
- it as fetcherRegistrar,
1150
+ he as fetcher,
1151
+ ie as fetcherRegistrar,
1132
1152
  D as getUrlTemplateResolver,
1133
1153
  F as isAbsoluteURL,
1134
1154
  g as mergeRecords,
1135
- at as mergeRequest,
1155
+ ae as mergeRequest,
1136
1156
  G as resolveTimeout,
1137
1157
  M as timeoutFetch,
1138
- m as toSorted,
1158
+ T as toSorted,
1139
1159
  L as uriTemplateResolver,
1140
1160
  w as urlTemplateRegexExtract,
1141
1161
  q as urlTemplateRegexResolve