@ahoo-wang/fetcher 1.6.1 → 1.6.3
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/fetchExchange.d.ts +6 -6
- package/dist/fetchExchange.d.ts.map +1 -1
- package/dist/fetcher.d.ts +111 -72
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js +413 -363
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/mergeRequest.d.ts +9 -0
- package/dist/mergeRequest.d.ts.map +1 -1
- package/dist/resultExtractor.d.ts +7 -0
- package/dist/resultExtractor.d.ts.map +1 -1
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
function
|
|
1
|
+
function C(r) {
|
|
2
2
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(r);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function U(r, t) {
|
|
5
|
+
return C(t) ? t : t ? r.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : r;
|
|
6
6
|
}
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
return r === 1 ?
|
|
7
|
+
var v = /* @__PURE__ */ ((r) => (r[r.UriTemplate = 0] = "UriTemplate", r[r.Express = 1] = "Express", r))(v || {});
|
|
8
|
+
function D(r) {
|
|
9
|
+
return r === 1 ? M : L;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
13
|
-
const n =
|
|
11
|
+
function w(r, t, e) {
|
|
12
|
+
return e ? r.replace(t, (s, o) => {
|
|
13
|
+
const n = e[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
|
|
20
|
-
const
|
|
19
|
+
function N(r, t) {
|
|
20
|
+
const e = [];
|
|
21
21
|
let s;
|
|
22
|
-
for (; (s =
|
|
23
|
-
|
|
24
|
-
return
|
|
22
|
+
for (; (s = t.exec(r)) !== null; )
|
|
23
|
+
e.push(s[1]);
|
|
24
|
+
return e;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const a = class a {
|
|
27
27
|
/**
|
|
28
28
|
* Extracts path parameters from a URL string.
|
|
29
29
|
*
|
|
@@ -47,10 +47,10 @@ const h = class h {
|
|
|
47
47
|
* // noParams = []
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
|
-
extractPathParams(
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
extractPathParams(t) {
|
|
51
|
+
return N(
|
|
52
|
+
t,
|
|
53
|
+
a.PATH_PARAM_REGEX
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -89,17 +89,17 @@ const h = class h {
|
|
|
89
89
|
* }
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
|
-
resolve(
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
resolve(t, e) {
|
|
93
|
+
return w(
|
|
94
|
+
t,
|
|
95
|
+
a.PATH_PARAM_REGEX,
|
|
96
|
+
e
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
const
|
|
100
|
+
a.PATH_PARAM_REGEX = /{([^}]+)}/g;
|
|
101
|
+
let f = a;
|
|
102
|
+
const L = new f(), h = class h {
|
|
103
103
|
/**
|
|
104
104
|
* Extracts path parameters from an Express-style URL string.
|
|
105
105
|
*
|
|
@@ -119,10 +119,10 @@ const x = new P(), l = class l {
|
|
|
119
119
|
* // noParams = []
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
|
-
extractPathParams(
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
extractPathParams(t) {
|
|
123
|
+
return N(
|
|
124
|
+
t,
|
|
125
|
+
h.PATH_PARAM_REGEX
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
@@ -157,18 +157,18 @@ const x = new P(), l = class l {
|
|
|
157
157
|
* }
|
|
158
158
|
* ```
|
|
159
159
|
*/
|
|
160
|
-
resolve(
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
resolve(t, e) {
|
|
161
|
+
return w(
|
|
162
|
+
t,
|
|
163
|
+
h.PATH_PARAM_REGEX,
|
|
164
|
+
e
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
|
|
169
|
-
let
|
|
170
|
-
const
|
|
171
|
-
class
|
|
168
|
+
h.PATH_PARAM_REGEX = /:([^/]+)/g;
|
|
169
|
+
let P = h;
|
|
170
|
+
const M = new P();
|
|
171
|
+
class G {
|
|
172
172
|
/**
|
|
173
173
|
* Initializes a new UrlBuilder instance.
|
|
174
174
|
*
|
|
@@ -186,8 +186,8 @@ class L {
|
|
|
186
186
|
* const expressUrlBuilder = new UrlBuilder('https://api.example.com', UrlTemplateStyle.Express);
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
|
-
constructor(
|
|
190
|
-
this.baseURL =
|
|
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 L {
|
|
|
207
207
|
* // Result: https://api.example.com/users/123/posts/456?filter=active&limit=10
|
|
208
208
|
* ```
|
|
209
209
|
*/
|
|
210
|
-
build(
|
|
211
|
-
const s =
|
|
212
|
-
let
|
|
210
|
+
build(t, e) {
|
|
211
|
+
const s = e?.path, o = e?.query, n = U(this.baseURL, t);
|
|
212
|
+
let i = this.urlTemplateResolver.resolve(n, s);
|
|
213
213
|
if (o) {
|
|
214
|
-
const
|
|
215
|
-
|
|
214
|
+
const u = new URLSearchParams(o).toString();
|
|
215
|
+
u && (i += "?" + u);
|
|
216
216
|
}
|
|
217
|
-
return
|
|
217
|
+
return i;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
220
|
* Resolves a complete URL from a FetchRequest.
|
|
@@ -225,82 +225,82 @@ class L {
|
|
|
225
225
|
* @param request - The FetchRequest containing URL and URL parameters
|
|
226
226
|
* @returns Complete resolved URL string
|
|
227
227
|
*/
|
|
228
|
-
resolveRequestUrl(
|
|
229
|
-
return this.build(
|
|
228
|
+
resolveRequestUrl(t) {
|
|
229
|
+
return this.build(t.url, t.urlParams);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
class
|
|
232
|
+
class l 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(
|
|
240
|
-
const s =
|
|
241
|
-
super(s), this.cause =
|
|
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 b extends
|
|
244
|
+
class b 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(
|
|
251
|
-
const
|
|
252
|
-
super(s), this.name = "FetchTimeoutError", this.request =
|
|
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, b.prototype);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
function
|
|
256
|
-
return typeof r < "u" ? r :
|
|
255
|
+
function H(r, t) {
|
|
256
|
+
return typeof r < "u" ? r : t;
|
|
257
257
|
}
|
|
258
|
-
async function
|
|
259
|
-
const
|
|
258
|
+
async function j(r) {
|
|
259
|
+
const t = r.url, e = r.timeout, s = r;
|
|
260
260
|
if (r.signal)
|
|
261
|
-
return fetch(
|
|
262
|
-
if (!
|
|
263
|
-
return r.abortController && (s.signal = r.abortController.signal), fetch(
|
|
261
|
+
return fetch(t, s);
|
|
262
|
+
if (!e)
|
|
263
|
+
return r.abortController && (s.signal = r.abortController.signal), fetch(t, s);
|
|
264
264
|
const o = r.abortController ?? new AbortController();
|
|
265
265
|
s.signal = o.signal;
|
|
266
266
|
let n = null;
|
|
267
|
-
const
|
|
267
|
+
const i = new Promise((u, p) => {
|
|
268
268
|
n = setTimeout(() => {
|
|
269
269
|
n && clearTimeout(n);
|
|
270
|
-
const
|
|
271
|
-
o.abort(
|
|
272
|
-
},
|
|
270
|
+
const I = new b(r);
|
|
271
|
+
o.abort(I), p(I);
|
|
272
|
+
}, e);
|
|
273
273
|
});
|
|
274
274
|
try {
|
|
275
|
-
return await Promise.race([fetch(
|
|
275
|
+
return await Promise.race([fetch(t, s), i]);
|
|
276
276
|
} finally {
|
|
277
277
|
n && clearTimeout(n);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
const
|
|
281
|
-
class
|
|
280
|
+
const B = "UrlResolveInterceptor", S = Number.MIN_SAFE_INTEGER + 1e3;
|
|
281
|
+
class $ {
|
|
282
282
|
constructor() {
|
|
283
|
-
this.name =
|
|
283
|
+
this.name = B, this.order = S;
|
|
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(
|
|
291
|
-
const
|
|
292
|
-
|
|
290
|
+
intercept(t) {
|
|
291
|
+
const e = t.request;
|
|
292
|
+
e.url = t.fetcher.urlBuilder.resolveRequestUrl(e);
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
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
|
|
296
|
+
const Et = "Content-Type", d = class d {
|
|
297
297
|
};
|
|
298
|
-
|
|
299
|
-
let E =
|
|
300
|
-
const
|
|
301
|
-
class
|
|
298
|
+
d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
|
|
299
|
+
let E = d;
|
|
300
|
+
const X = "RequestBodyInterceptor", V = S + 1e3;
|
|
301
|
+
class k {
|
|
302
302
|
constructor() {
|
|
303
|
-
this.name =
|
|
303
|
+
this.name = X, this.order = V;
|
|
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(
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
345
|
-
|
|
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
|
-
|
|
348
|
-
const s =
|
|
347
|
+
t.request.body = JSON.stringify(e.body);
|
|
348
|
+
const s = t.ensureRequestHeaders();
|
|
349
349
|
s["Content-Type"] || (s["Content-Type"] = E.APPLICATION_JSON);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
|
-
const
|
|
353
|
-
class
|
|
352
|
+
const J = "FetchInterceptor", Q = Number.MAX_SAFE_INTEGER - 1e3;
|
|
353
|
+
class Y {
|
|
354
354
|
constructor() {
|
|
355
|
-
this.name =
|
|
355
|
+
this.name = J, this.order = Q;
|
|
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(
|
|
383
|
-
|
|
382
|
+
async intercept(t) {
|
|
383
|
+
t.response = await j(t.request);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
function T(r,
|
|
387
|
-
return
|
|
386
|
+
function T(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
|
|
389
|
+
class m {
|
|
390
390
|
/**
|
|
391
391
|
* Initializes a new InterceptorRegistry instance.
|
|
392
392
|
*
|
|
@@ -396,8 +396,8 @@ class f {
|
|
|
396
396
|
* The provided interceptors will be sorted by their order property immediately
|
|
397
397
|
* upon construction.
|
|
398
398
|
*/
|
|
399
|
-
constructor(
|
|
400
|
-
this.sortedInterceptors = [], this.sortedInterceptors = T(
|
|
399
|
+
constructor(t = []) {
|
|
400
|
+
this.sortedInterceptors = [], this.sortedInterceptors = T(t);
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Gets the name of this interceptor registry.
|
|
@@ -434,10 +434,10 @@ class f {
|
|
|
434
434
|
*
|
|
435
435
|
* After adding, interceptors are automatically sorted by their order property.
|
|
436
436
|
*/
|
|
437
|
-
use(
|
|
438
|
-
return this.sortedInterceptors.some((
|
|
437
|
+
use(t) {
|
|
438
|
+
return this.sortedInterceptors.some((e) => e.name === t.name) ? !1 : (this.sortedInterceptors = T([
|
|
439
439
|
...this.sortedInterceptors,
|
|
440
|
-
|
|
440
|
+
t
|
|
441
441
|
]), !0);
|
|
442
442
|
}
|
|
443
443
|
/**
|
|
@@ -447,12 +447,12 @@ class f {
|
|
|
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(
|
|
451
|
-
const
|
|
450
|
+
eject(t) {
|
|
451
|
+
const e = this.sortedInterceptors;
|
|
452
452
|
return this.sortedInterceptors = T(
|
|
453
|
-
|
|
454
|
-
(s) => s.name !==
|
|
455
|
-
),
|
|
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 f {
|
|
|
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(
|
|
478
|
-
for (const
|
|
479
|
-
await
|
|
477
|
+
async intercept(t) {
|
|
478
|
+
for (const e of this.sortedInterceptors)
|
|
479
|
+
await e.intercept(t);
|
|
480
480
|
}
|
|
481
481
|
}
|
|
482
|
-
class
|
|
483
|
-
constructor(
|
|
482
|
+
class _ extends l {
|
|
483
|
+
constructor(t) {
|
|
484
484
|
super(
|
|
485
|
-
`Request failed with status code ${
|
|
486
|
-
), this.exchange =
|
|
485
|
+
`Request failed with status code ${t.response?.status} for ${t.request.url}`
|
|
486
|
+
), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, _.prototype);
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
-
const
|
|
490
|
-
class
|
|
489
|
+
const z = (r) => r >= 200 && r < 300, K = "ValidateStatusInterceptor", W = Number.MAX_SAFE_INTEGER - 1e3;
|
|
490
|
+
class Z {
|
|
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(
|
|
497
|
-
this.validateStatus =
|
|
496
|
+
constructor(t = z) {
|
|
497
|
+
this.validateStatus = t;
|
|
498
498
|
}
|
|
499
499
|
/**
|
|
500
500
|
* Gets the name of this interceptor.
|
|
@@ -502,7 +502,7 @@ class K {
|
|
|
502
502
|
* @returns The name of this interceptor
|
|
503
503
|
*/
|
|
504
504
|
get name() {
|
|
505
|
-
return
|
|
505
|
+
return K;
|
|
506
506
|
}
|
|
507
507
|
/**
|
|
508
508
|
* Gets the order of this interceptor.
|
|
@@ -510,7 +510,7 @@ class K {
|
|
|
510
510
|
* @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
|
|
511
511
|
*/
|
|
512
512
|
get order() {
|
|
513
|
-
return
|
|
513
|
+
return W;
|
|
514
514
|
}
|
|
515
515
|
/**
|
|
516
516
|
* Validates the response status code.
|
|
@@ -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(
|
|
529
|
-
if (!
|
|
528
|
+
intercept(t) {
|
|
529
|
+
if (!t.response)
|
|
530
530
|
return;
|
|
531
|
-
const
|
|
532
|
-
if (!this.validateStatus(
|
|
533
|
-
throw new
|
|
531
|
+
const e = t.response.status;
|
|
532
|
+
if (!this.validateStatus(e))
|
|
533
|
+
throw new _(t);
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
|
-
class
|
|
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(
|
|
544
|
-
const s =
|
|
545
|
-
super(s,
|
|
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
|
|
548
|
+
class tt {
|
|
549
549
|
constructor() {
|
|
550
|
-
this.request = new
|
|
551
|
-
new
|
|
552
|
-
new
|
|
553
|
-
new
|
|
554
|
-
]), this.response = new
|
|
555
|
-
new
|
|
556
|
-
]), this.error = new
|
|
550
|
+
this.request = new m([
|
|
551
|
+
new $(),
|
|
552
|
+
new k(),
|
|
553
|
+
new Y()
|
|
554
|
+
]), this.response = new m([
|
|
555
|
+
new Z()
|
|
556
|
+
]), this.error = new m();
|
|
557
557
|
}
|
|
558
558
|
/**
|
|
559
559
|
* Processes a FetchExchange through the interceptor pipeline.
|
|
@@ -641,25 +641,41 @@ class W {
|
|
|
641
641
|
* const result = await fetcher.exchange(exchange);
|
|
642
642
|
* ```
|
|
643
643
|
*/
|
|
644
|
-
async exchange(
|
|
644
|
+
async exchange(t) {
|
|
645
645
|
try {
|
|
646
|
-
return await this.request.intercept(
|
|
647
|
-
} catch (
|
|
648
|
-
if (
|
|
649
|
-
return
|
|
650
|
-
throw new
|
|
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
|
-
const
|
|
655
|
-
Exchange:
|
|
656
|
-
Response:
|
|
657
|
-
Json:
|
|
658
|
-
Text:
|
|
654
|
+
const et = (r) => r, rt = (r) => r.requiredResponse, st = (r) => r.requiredResponse.json(), ot = (r) => r.requiredResponse.text(), O = {
|
|
655
|
+
Exchange: et,
|
|
656
|
+
Response: rt,
|
|
657
|
+
Json: st,
|
|
658
|
+
Text: ot
|
|
659
659
|
};
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
660
|
+
function g(r, t) {
|
|
661
|
+
if (!(r === void 0 && t === void 0))
|
|
662
|
+
return t === void 0 ? r : r === void 0 ? t : { ...r, ...t };
|
|
663
|
+
}
|
|
664
|
+
function nt(r, t) {
|
|
665
|
+
if (t ??= /* @__PURE__ */ new Map(), !r)
|
|
666
|
+
return t;
|
|
667
|
+
if (r instanceof Map) {
|
|
668
|
+
for (const [e, s] of r)
|
|
669
|
+
t.set(e, s);
|
|
670
|
+
return t;
|
|
671
|
+
}
|
|
672
|
+
for (const [e, s] of Object.entries(r))
|
|
673
|
+
t.set(e, s);
|
|
674
|
+
return t;
|
|
675
|
+
}
|
|
676
|
+
class it {
|
|
677
|
+
constructor(t) {
|
|
678
|
+
this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ?? O.Exchange, this.attributes = nt(t.attributes), this._response = t.response, this.error = t.error;
|
|
663
679
|
}
|
|
664
680
|
/**
|
|
665
681
|
* Ensures that request headers object exists, creating it if necessary.
|
|
@@ -705,8 +721,8 @@ class se {
|
|
|
705
721
|
*
|
|
706
722
|
* @param response - The Response object to set, or undefined to clear the response
|
|
707
723
|
*/
|
|
708
|
-
set response(
|
|
709
|
-
this._response =
|
|
724
|
+
set response(t) {
|
|
725
|
+
this._response = t, this.cachedExtractedResult = void 0;
|
|
710
726
|
}
|
|
711
727
|
/**
|
|
712
728
|
* Gets the response object for this exchange.
|
|
@@ -736,29 +752,61 @@ class se {
|
|
|
736
752
|
*/
|
|
737
753
|
get requiredResponse() {
|
|
738
754
|
if (!this.response)
|
|
739
|
-
throw new
|
|
755
|
+
throw new R(
|
|
740
756
|
this,
|
|
741
757
|
`Request to ${this.request.url} failed with no response`
|
|
742
758
|
);
|
|
743
759
|
return this.response;
|
|
744
760
|
}
|
|
745
761
|
/**
|
|
746
|
-
*
|
|
747
|
-
* The result is cached after the first computation.
|
|
762
|
+
* Extracts the result by applying the result extractor to the exchange.
|
|
763
|
+
* The result is cached after the first computation to avoid repeated computations.
|
|
748
764
|
*
|
|
749
|
-
* @returns The extracted result
|
|
765
|
+
* @returns The extracted result
|
|
750
766
|
*/
|
|
751
|
-
|
|
767
|
+
extractResult() {
|
|
752
768
|
return this.cachedExtractedResult !== void 0 ? this.cachedExtractedResult : (this.cachedExtractedResult = this.resultExtractor(this), this.cachedExtractedResult);
|
|
753
769
|
}
|
|
754
770
|
}
|
|
755
|
-
|
|
771
|
+
function dt(r, t) {
|
|
772
|
+
if (Object.keys(r).length === 0)
|
|
773
|
+
return t;
|
|
774
|
+
if (Object.keys(t).length === 0)
|
|
775
|
+
return r;
|
|
776
|
+
const e = {
|
|
777
|
+
path: g(r.urlParams?.path, t.urlParams?.path),
|
|
778
|
+
query: g(r.urlParams?.query, t.urlParams?.query)
|
|
779
|
+
}, s = {
|
|
780
|
+
...r.headers,
|
|
781
|
+
...t.headers
|
|
782
|
+
}, o = t.method ?? r.method, n = t.body ?? r.body, i = t.timeout ?? r.timeout, u = t.signal ?? r.signal, p = t.abortController ?? r.abortController;
|
|
783
|
+
return {
|
|
784
|
+
...r,
|
|
785
|
+
...t,
|
|
786
|
+
method: o,
|
|
787
|
+
urlParams: e,
|
|
788
|
+
headers: s,
|
|
789
|
+
body: n,
|
|
790
|
+
timeout: i,
|
|
791
|
+
signal: u,
|
|
792
|
+
abortController: p
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function q(r, t) {
|
|
796
|
+
return t && t.resultExtractor && t.attributes ? t : {
|
|
797
|
+
resultExtractor: t?.resultExtractor ?? r?.resultExtractor ?? x.resultExtractor,
|
|
798
|
+
attributes: t?.attributes ?? r?.attributes
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
const A = {
|
|
756
802
|
"Content-Type": E.APPLICATION_JSON
|
|
757
|
-
},
|
|
803
|
+
}, F = {
|
|
758
804
|
baseURL: "",
|
|
759
|
-
headers:
|
|
805
|
+
headers: A
|
|
806
|
+
}, x = { resultExtractor: O.Exchange }, ut = {
|
|
807
|
+
resultExtractor: O.Response
|
|
760
808
|
};
|
|
761
|
-
class
|
|
809
|
+
class ct {
|
|
762
810
|
/**
|
|
763
811
|
* Initializes a new Fetcher instance with optional configuration.
|
|
764
812
|
*
|
|
@@ -766,9 +814,14 @@ class oe {
|
|
|
766
814
|
* If no interceptors are provided, a default set of interceptors will be used.
|
|
767
815
|
*
|
|
768
816
|
* @param options - Configuration options for the Fetcher instance
|
|
817
|
+
* @param options.baseURL - The base URL to prepend to all requests. Defaults to empty string.
|
|
818
|
+
* @param options.headers - Default headers to include in all requests. Defaults to JSON content type.
|
|
819
|
+
* @param options.timeout - Default timeout for requests in milliseconds. No timeout by default.
|
|
820
|
+
* @param options.urlTemplateStyle - Style for URL template parameter interpolation.
|
|
821
|
+
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
769
822
|
*/
|
|
770
|
-
constructor(
|
|
771
|
-
this.headers =
|
|
823
|
+
constructor(t = F) {
|
|
824
|
+
this.headers = A, this.urlBuilder = new G(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? A, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new tt();
|
|
772
825
|
}
|
|
773
826
|
/**
|
|
774
827
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -777,51 +830,57 @@ class oe {
|
|
|
777
830
|
* creates a FetchExchange object, and passes it through the exchange method
|
|
778
831
|
* for interceptor processing.
|
|
779
832
|
*
|
|
833
|
+
* @template R - The type of the result to be returned
|
|
780
834
|
* @param request - Complete request configuration object
|
|
781
|
-
* @param
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
835
|
+
* @param options - Request options including result extractor and attributes
|
|
836
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
837
|
+
* Defaults to ExchangeResultExtractor which returns the entire exchange object.
|
|
838
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
839
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
840
|
+
* custom data between different interceptors.
|
|
786
841
|
* @returns Promise that resolves to the extracted result based on resultExtractor
|
|
787
842
|
* @throws Error if an unhandled error occurs during request processing
|
|
788
843
|
*/
|
|
789
|
-
async request(
|
|
790
|
-
const
|
|
844
|
+
async request(t, e) {
|
|
845
|
+
const s = {
|
|
791
846
|
...this.headers,
|
|
792
|
-
...
|
|
793
|
-
},
|
|
794
|
-
...
|
|
795
|
-
headers:
|
|
796
|
-
timeout:
|
|
797
|
-
},
|
|
847
|
+
...t.headers
|
|
848
|
+
}, o = {
|
|
849
|
+
...t,
|
|
850
|
+
headers: s,
|
|
851
|
+
timeout: H(t.timeout, this.timeout)
|
|
852
|
+
}, {
|
|
853
|
+
resultExtractor: n,
|
|
854
|
+
attributes: i
|
|
855
|
+
} = q(x, e), u = new it({
|
|
798
856
|
fetcher: this,
|
|
799
|
-
request:
|
|
800
|
-
resultExtractor:
|
|
801
|
-
attributes:
|
|
857
|
+
request: o,
|
|
858
|
+
resultExtractor: n,
|
|
859
|
+
attributes: i
|
|
802
860
|
});
|
|
803
|
-
return await this.interceptors.exchange(u), u.
|
|
861
|
+
return await this.interceptors.exchange(u), u.extractResult();
|
|
804
862
|
}
|
|
805
863
|
/**
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
864
|
+
* Executes an HTTP request with the specified URL and options.
|
|
865
|
+
*
|
|
866
|
+
* This is the primary method for making HTTP requests. It processes the request
|
|
867
|
+
* through the interceptor chain and returns the resulting Response.
|
|
868
|
+
*
|
|
869
|
+
* @template R - The type of the result to be returned
|
|
870
|
+
* @param url - The URL path for the request (relative to baseURL if set)
|
|
871
|
+
* @param request - Request configuration including headers, body, parameters, etc.
|
|
872
|
+
* @param options - Request options including result extractor and attributes
|
|
873
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
874
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
875
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
876
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
877
|
+
* custom data between different interceptors.
|
|
878
|
+
* @returns Promise that resolves to the HTTP response
|
|
879
|
+
* @throws FetchError if the request fails and no response is generated
|
|
880
|
+
*/
|
|
881
|
+
async fetch(t, e = {}, s) {
|
|
882
|
+
const o = e;
|
|
883
|
+
return o.url = t, this.request(o, q(ut, s));
|
|
825
884
|
}
|
|
826
885
|
/**
|
|
827
886
|
* Internal helper method for making HTTP requests with a specific method.
|
|
@@ -829,25 +888,26 @@ class oe {
|
|
|
829
888
|
* This private method is used by the public HTTP method methods (get, post, etc.)
|
|
830
889
|
* to execute requests with the appropriate HTTP verb.
|
|
831
890
|
*
|
|
891
|
+
* @template R - The type of the result to be returned
|
|
832
892
|
* @param method - The HTTP method to use for the request
|
|
833
893
|
* @param url - The URL path for the request
|
|
834
894
|
* @param request - Additional request options
|
|
835
|
-
* @param
|
|
836
|
-
*
|
|
837
|
-
*
|
|
838
|
-
*
|
|
839
|
-
*
|
|
895
|
+
* @param options - Request options including result extractor and attributes
|
|
896
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
897
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
898
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
899
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
900
|
+
* custom data between different interceptors.
|
|
840
901
|
* @returns Promise that resolves to the HTTP response
|
|
841
902
|
*/
|
|
842
|
-
async methodFetch(
|
|
903
|
+
async methodFetch(t, e, s = {}, o) {
|
|
843
904
|
return this.fetch(
|
|
844
|
-
|
|
905
|
+
e,
|
|
845
906
|
{
|
|
846
907
|
...s,
|
|
847
|
-
method:
|
|
908
|
+
method: t
|
|
848
909
|
},
|
|
849
|
-
o
|
|
850
|
-
n
|
|
910
|
+
o
|
|
851
911
|
);
|
|
852
912
|
}
|
|
853
913
|
/**
|
|
@@ -856,85 +916,95 @@ class oe {
|
|
|
856
916
|
* Convenience method for making GET requests. The request body is omitted
|
|
857
917
|
* as GET requests should not contain a body according to HTTP specification.
|
|
858
918
|
*
|
|
919
|
+
* @template R - The type of the result to be returned
|
|
859
920
|
* @param url - The URL path for the request
|
|
860
921
|
* @param request - Request options excluding method and body
|
|
861
|
-
* @param
|
|
862
|
-
*
|
|
863
|
-
*
|
|
864
|
-
*
|
|
865
|
-
*
|
|
922
|
+
* @param options - Request options including result extractor and attributes
|
|
923
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
924
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
925
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
926
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
927
|
+
* custom data between different interceptors.
|
|
866
928
|
* @returns Promise that resolves to the HTTP response
|
|
867
929
|
*/
|
|
868
|
-
async get(
|
|
869
|
-
return this.methodFetch(c.GET,
|
|
930
|
+
async get(t, e = {}, s) {
|
|
931
|
+
return this.methodFetch(c.GET, t, e, s);
|
|
870
932
|
}
|
|
871
933
|
/**
|
|
872
|
-
* Makes a
|
|
934
|
+
* Makes a PUT HTTP request.
|
|
873
935
|
*
|
|
874
|
-
* Convenience method for making
|
|
936
|
+
* Convenience method for making PUT requests, commonly used for updating resources.
|
|
875
937
|
*
|
|
938
|
+
* @template R - The type of the result to be returned
|
|
876
939
|
* @param url - The URL path for the request
|
|
877
940
|
* @param request - Request options including body and other parameters
|
|
878
|
-
* @param
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
941
|
+
* @param options - Request options including result extractor and attributes
|
|
942
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
943
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
944
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
945
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
946
|
+
* custom data between different interceptors.
|
|
883
947
|
* @returns Promise that resolves to the HTTP response
|
|
884
948
|
*/
|
|
885
|
-
async
|
|
886
|
-
return this.methodFetch(c.
|
|
949
|
+
async put(t, e = {}, s) {
|
|
950
|
+
return this.methodFetch(c.PUT, t, e, s);
|
|
887
951
|
}
|
|
888
952
|
/**
|
|
889
|
-
* Makes a
|
|
953
|
+
* Makes a POST HTTP request.
|
|
890
954
|
*
|
|
891
|
-
* Convenience method for making
|
|
955
|
+
* Convenience method for making POST requests, commonly used for creating resources.
|
|
892
956
|
*
|
|
957
|
+
* @template R - The type of the result to be returned
|
|
893
958
|
* @param url - The URL path for the request
|
|
894
959
|
* @param request - Request options including body and other parameters
|
|
895
|
-
* @param
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
899
|
-
*
|
|
960
|
+
* @param options - Request options including result extractor and attributes
|
|
961
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
962
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
963
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
964
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
965
|
+
* custom data between different interceptors.
|
|
900
966
|
* @returns Promise that resolves to the HTTP response
|
|
901
967
|
*/
|
|
902
|
-
async
|
|
903
|
-
return this.methodFetch(c.
|
|
968
|
+
async post(t, e = {}, s) {
|
|
969
|
+
return this.methodFetch(c.POST, t, e, s);
|
|
904
970
|
}
|
|
905
971
|
/**
|
|
906
|
-
* Makes a
|
|
972
|
+
* Makes a PATCH HTTP request.
|
|
907
973
|
*
|
|
908
|
-
* Convenience method for making
|
|
974
|
+
* Convenience method for making PATCH requests, commonly used for partial updates.
|
|
909
975
|
*
|
|
976
|
+
* @template R - The type of the result to be returned
|
|
910
977
|
* @param url - The URL path for the request
|
|
911
|
-
* @param request - Request options
|
|
912
|
-
* @param
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
916
|
-
*
|
|
978
|
+
* @param request - Request options including body and other parameters
|
|
979
|
+
* @param options - Request options including result extractor and attributes
|
|
980
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
981
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
982
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
983
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
984
|
+
* custom data between different interceptors.
|
|
917
985
|
* @returns Promise that resolves to the HTTP response
|
|
918
986
|
*/
|
|
919
|
-
async
|
|
920
|
-
return this.methodFetch(c.
|
|
987
|
+
async patch(t, e = {}, s) {
|
|
988
|
+
return this.methodFetch(c.PATCH, t, e, s);
|
|
921
989
|
}
|
|
922
990
|
/**
|
|
923
|
-
* Makes a
|
|
991
|
+
* Makes a DELETE HTTP request.
|
|
924
992
|
*
|
|
925
|
-
* Convenience method for making
|
|
993
|
+
* Convenience method for making DELETE requests, commonly used for deleting resources.
|
|
926
994
|
*
|
|
995
|
+
* @template R - The type of the result to be returned
|
|
927
996
|
* @param url - The URL path for the request
|
|
928
|
-
* @param request - Request options
|
|
929
|
-
* @param
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
997
|
+
* @param request - Request options excluding method and body
|
|
998
|
+
* @param options - Request options including result extractor and attributes
|
|
999
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
1000
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
1001
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
1002
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
1003
|
+
* custom data between different interceptors.
|
|
934
1004
|
* @returns Promise that resolves to the HTTP response
|
|
935
1005
|
*/
|
|
936
|
-
async
|
|
937
|
-
return this.methodFetch(c.
|
|
1006
|
+
async delete(t, e = {}, s) {
|
|
1007
|
+
return this.methodFetch(c.DELETE, t, e, s);
|
|
938
1008
|
}
|
|
939
1009
|
/**
|
|
940
1010
|
* Makes a HEAD HTTP request.
|
|
@@ -942,17 +1012,19 @@ class oe {
|
|
|
942
1012
|
* Convenience method for making HEAD requests, which retrieve headers only.
|
|
943
1013
|
* The request body is omitted as HEAD requests should not contain a body.
|
|
944
1014
|
*
|
|
1015
|
+
* @template R - The type of the result to be returned
|
|
945
1016
|
* @param url - The URL path for the request
|
|
946
1017
|
* @param request - Request options excluding method and body
|
|
947
|
-
* @param
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
1018
|
+
* @param options - Request options including result extractor and attributes
|
|
1019
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
1020
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
1021
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
1022
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
1023
|
+
* custom data between different interceptors.
|
|
952
1024
|
* @returns Promise that resolves to the HTTP response
|
|
953
1025
|
*/
|
|
954
|
-
async head(
|
|
955
|
-
return this.methodFetch(c.HEAD,
|
|
1026
|
+
async head(t, e = {}, s) {
|
|
1027
|
+
return this.methodFetch(c.HEAD, t, e, s);
|
|
956
1028
|
}
|
|
957
1029
|
/**
|
|
958
1030
|
* Makes an OPTIONS HTTP request.
|
|
@@ -960,21 +1032,23 @@ class oe {
|
|
|
960
1032
|
* Convenience method for making OPTIONS requests, commonly used for CORS preflight.
|
|
961
1033
|
* The request body is omitted as OPTIONS requests typically don't contain a body.
|
|
962
1034
|
*
|
|
1035
|
+
* @template R - The type of the result to be returned
|
|
963
1036
|
* @param url - The URL path for the request
|
|
964
1037
|
* @param request - Request options excluding method and body
|
|
965
|
-
* @param
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
1038
|
+
* @param options - Request options including result extractor and attributes
|
|
1039
|
+
* @param options.resultExtractor - Function to extract the desired result from the exchange.
|
|
1040
|
+
* Defaults to ResponseResultExtractor which returns the entire exchange object.
|
|
1041
|
+
* @param options.attributes - Optional shared attributes that can be accessed by interceptors
|
|
1042
|
+
* throughout the request lifecycle. These attributes allow passing
|
|
1043
|
+
* custom data between different interceptors.
|
|
970
1044
|
* @returns Promise that resolves to the HTTP response
|
|
971
1045
|
*/
|
|
972
|
-
async options(
|
|
973
|
-
return this.methodFetch(c.OPTIONS,
|
|
1046
|
+
async options(t, e = {}, s) {
|
|
1047
|
+
return this.methodFetch(c.OPTIONS, t, e, s);
|
|
974
1048
|
}
|
|
975
1049
|
}
|
|
976
|
-
const
|
|
977
|
-
class
|
|
1050
|
+
const y = "default";
|
|
1051
|
+
class at {
|
|
978
1052
|
constructor() {
|
|
979
1053
|
this.registrar = /* @__PURE__ */ new Map();
|
|
980
1054
|
}
|
|
@@ -987,8 +1061,8 @@ class ne {
|
|
|
987
1061
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
988
1062
|
* fetcherRegistrar.register('api', fetcher);
|
|
989
1063
|
*/
|
|
990
|
-
register(
|
|
991
|
-
this.registrar.set(
|
|
1064
|
+
register(t, e) {
|
|
1065
|
+
this.registrar.set(t, e);
|
|
992
1066
|
}
|
|
993
1067
|
/**
|
|
994
1068
|
* Unregister a Fetcher instance by name
|
|
@@ -1001,8 +1075,8 @@ class ne {
|
|
|
1001
1075
|
* console.log('Fetcher unregistered successfully');
|
|
1002
1076
|
* }
|
|
1003
1077
|
*/
|
|
1004
|
-
unregister(
|
|
1005
|
-
return this.registrar.delete(
|
|
1078
|
+
unregister(t) {
|
|
1079
|
+
return this.registrar.delete(t);
|
|
1006
1080
|
}
|
|
1007
1081
|
/**
|
|
1008
1082
|
* Get a Fetcher instance by name
|
|
@@ -1015,8 +1089,8 @@ class ne {
|
|
|
1015
1089
|
* // Use the fetcher
|
|
1016
1090
|
* }
|
|
1017
1091
|
*/
|
|
1018
|
-
get(
|
|
1019
|
-
return this.registrar.get(
|
|
1092
|
+
get(t) {
|
|
1093
|
+
return this.registrar.get(t);
|
|
1020
1094
|
}
|
|
1021
1095
|
/**
|
|
1022
1096
|
* Get a Fetcher instance by name, throwing an error if not found
|
|
@@ -1032,11 +1106,11 @@ class ne {
|
|
|
1032
1106
|
* console.error('Fetcher not found:', error.message);
|
|
1033
1107
|
* }
|
|
1034
1108
|
*/
|
|
1035
|
-
requiredGet(
|
|
1036
|
-
const
|
|
1037
|
-
if (!
|
|
1038
|
-
throw new Error(`Fetcher ${
|
|
1039
|
-
return
|
|
1109
|
+
requiredGet(t) {
|
|
1110
|
+
const e = this.get(t);
|
|
1111
|
+
if (!e)
|
|
1112
|
+
throw new Error(`Fetcher ${t} not found`);
|
|
1113
|
+
return e;
|
|
1040
1114
|
}
|
|
1041
1115
|
/**
|
|
1042
1116
|
* Get the default Fetcher instance
|
|
@@ -1047,7 +1121,7 @@ class ne {
|
|
|
1047
1121
|
* const defaultFetcher = fetcherRegistrar.default;
|
|
1048
1122
|
*/
|
|
1049
1123
|
get default() {
|
|
1050
|
-
return this.requiredGet(
|
|
1124
|
+
return this.requiredGet(y);
|
|
1051
1125
|
}
|
|
1052
1126
|
/**
|
|
1053
1127
|
* Set the default Fetcher instance
|
|
@@ -1057,8 +1131,8 @@ class ne {
|
|
|
1057
1131
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
1058
1132
|
* fetcherRegistrar.default = fetcher;
|
|
1059
1133
|
*/
|
|
1060
|
-
set default(
|
|
1061
|
-
this.register(
|
|
1134
|
+
set default(t) {
|
|
1135
|
+
this.register(y, t);
|
|
1062
1136
|
}
|
|
1063
1137
|
/**
|
|
1064
1138
|
* Get a copy of all registered fetchers
|
|
@@ -1074,36 +1148,8 @@ class ne {
|
|
|
1074
1148
|
return new Map(this.registrar);
|
|
1075
1149
|
}
|
|
1076
1150
|
}
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
if (!(r === void 0 && e === void 0))
|
|
1080
|
-
return e === void 0 ? r : r === void 0 ? e : { ...r, ...e };
|
|
1081
|
-
}
|
|
1082
|
-
function ae(r, e) {
|
|
1083
|
-
if (Object.keys(r).length === 0)
|
|
1084
|
-
return e;
|
|
1085
|
-
if (Object.keys(e).length === 0)
|
|
1086
|
-
return r;
|
|
1087
|
-
const t = {
|
|
1088
|
-
path: O(r.urlParams?.path, e.urlParams?.path),
|
|
1089
|
-
query: O(r.urlParams?.query, e.urlParams?.query)
|
|
1090
|
-
}, s = {
|
|
1091
|
-
...r.headers,
|
|
1092
|
-
...e.headers
|
|
1093
|
-
}, 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;
|
|
1094
|
-
return {
|
|
1095
|
-
...r,
|
|
1096
|
-
...e,
|
|
1097
|
-
method: o,
|
|
1098
|
-
urlParams: t,
|
|
1099
|
-
headers: s,
|
|
1100
|
-
body: n,
|
|
1101
|
-
timeout: u,
|
|
1102
|
-
signal: a,
|
|
1103
|
-
abortController: m
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
class ue extends oe {
|
|
1151
|
+
const ht = new at();
|
|
1152
|
+
class lt extends ct {
|
|
1107
1153
|
/**
|
|
1108
1154
|
* Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
|
|
1109
1155
|
*
|
|
@@ -1121,61 +1167,65 @@ class ue extends oe {
|
|
|
1121
1167
|
* headers: { 'Authorization': 'Bearer token' }
|
|
1122
1168
|
* });
|
|
1123
1169
|
*/
|
|
1124
|
-
constructor(
|
|
1125
|
-
super(
|
|
1170
|
+
constructor(t, e = F) {
|
|
1171
|
+
super(e), this.name = t, ht.register(t, this);
|
|
1126
1172
|
}
|
|
1127
1173
|
}
|
|
1128
|
-
const
|
|
1174
|
+
const Rt = new lt(y);
|
|
1129
1175
|
export {
|
|
1130
|
-
|
|
1176
|
+
Et as CONTENT_TYPE_HEADER,
|
|
1131
1177
|
E as ContentTypeValues,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1178
|
+
y as DEFAULT_FETCHER_NAME,
|
|
1179
|
+
ut as DEFAULT_FETCH_OPTIONS,
|
|
1180
|
+
F as DEFAULT_OPTIONS,
|
|
1181
|
+
x as DEFAULT_REQUEST_OPTIONS,
|
|
1182
|
+
R as ExchangeError,
|
|
1183
|
+
et as ExchangeResultExtractor,
|
|
1184
|
+
P as ExpressUrlTemplateResolver,
|
|
1185
|
+
J as FETCH_INTERCEPTOR_NAME,
|
|
1186
|
+
Q as FETCH_INTERCEPTOR_ORDER,
|
|
1187
|
+
it as FetchExchange,
|
|
1188
|
+
Y as FetchInterceptor,
|
|
1141
1189
|
b as FetchTimeoutError,
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1190
|
+
ct as Fetcher,
|
|
1191
|
+
l as FetcherError,
|
|
1192
|
+
at as FetcherRegistrar,
|
|
1145
1193
|
c as HttpMethod,
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1194
|
+
_ as HttpStatusValidationError,
|
|
1195
|
+
tt as InterceptorManager,
|
|
1196
|
+
m as InterceptorRegistry,
|
|
1197
|
+
st as JsonResultExtractor,
|
|
1198
|
+
lt as NamedFetcher,
|
|
1199
|
+
X as REQUEST_BODY_INTERCEPTOR_NAME,
|
|
1200
|
+
V as REQUEST_BODY_INTERCEPTOR_ORDER,
|
|
1201
|
+
k as RequestBodyInterceptor,
|
|
1202
|
+
rt as ResponseResultExtractor,
|
|
1203
|
+
O as ResultExtractors,
|
|
1204
|
+
ot as TextResultExtractor,
|
|
1205
|
+
B as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
1206
|
+
S as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
1207
|
+
f as UriTemplateResolver,
|
|
1208
|
+
G as UrlBuilder,
|
|
1209
|
+
$ as UrlResolveInterceptor,
|
|
1210
|
+
v as UrlTemplateStyle,
|
|
1211
|
+
K as VALIDATE_STATUS_INTERCEPTOR_NAME,
|
|
1212
|
+
W as VALIDATE_STATUS_INTERCEPTOR_ORDER,
|
|
1213
|
+
Z as ValidateStatusInterceptor,
|
|
1214
|
+
U as combineURLs,
|
|
1215
|
+
M as expressUrlTemplateResolver,
|
|
1216
|
+
Rt as fetcher,
|
|
1217
|
+
ht as fetcherRegistrar,
|
|
1218
|
+
D as getUrlTemplateResolver,
|
|
1219
|
+
C as isAbsoluteURL,
|
|
1220
|
+
nt as mergeRecordToMap,
|
|
1221
|
+
g as mergeRecords,
|
|
1222
|
+
dt as mergeRequest,
|
|
1223
|
+
q as mergeRequestOptions,
|
|
1224
|
+
H as resolveTimeout,
|
|
1225
|
+
j as timeoutFetch,
|
|
1176
1226
|
T as toSorted,
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1227
|
+
L as uriTemplateResolver,
|
|
1228
|
+
N as urlTemplateRegexExtract,
|
|
1229
|
+
w as urlTemplateRegexResolve
|
|
1180
1230
|
};
|
|
1181
1231
|
//# sourceMappingURL=index.es.js.map
|