@ahoo-wang/fetcher 1.6.0 → 1.6.2
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 +21 -7
- 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 +429 -361
- 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
|
|
7
|
+
var v = /* @__PURE__ */ ((r) => (r[r.UriTemplate = 0] = "UriTemplate", r[r.Express = 1] = "Express", r))(v || {});
|
|
8
8
|
function D(r) {
|
|
9
|
-
return r === 1 ?
|
|
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 L = new
|
|
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 L = 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 L = 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 x {
|
|
|
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 x {
|
|
|
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 x {
|
|
|
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
|
|
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
|
|
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 =
|
|
349
|
-
s["Content-Type"] || (s["Content-Type"] =
|
|
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
|
|
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.
|
|
@@ -698,6 +714,24 @@ class se {
|
|
|
698
714
|
hasError() {
|
|
699
715
|
return !!this.error;
|
|
700
716
|
}
|
|
717
|
+
/**
|
|
718
|
+
* Sets the response object for this exchange.
|
|
719
|
+
* Also invalidates the cached extracted result to ensure data consistency
|
|
720
|
+
* when the response changes.
|
|
721
|
+
*
|
|
722
|
+
* @param response - The Response object to set, or undefined to clear the response
|
|
723
|
+
*/
|
|
724
|
+
set response(t) {
|
|
725
|
+
this._response = t, this.cachedExtractedResult = void 0;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Gets the response object for this exchange.
|
|
729
|
+
*
|
|
730
|
+
* @returns The response object if available, undefined otherwise
|
|
731
|
+
*/
|
|
732
|
+
get response() {
|
|
733
|
+
return this._response;
|
|
734
|
+
}
|
|
701
735
|
/**
|
|
702
736
|
* Checks if the exchange has a response.
|
|
703
737
|
*
|
|
@@ -718,29 +752,61 @@ class se {
|
|
|
718
752
|
*/
|
|
719
753
|
get requiredResponse() {
|
|
720
754
|
if (!this.response)
|
|
721
|
-
throw new
|
|
755
|
+
throw new R(
|
|
722
756
|
this,
|
|
723
757
|
`Request to ${this.request.url} failed with no response`
|
|
724
758
|
);
|
|
725
759
|
return this.response;
|
|
726
760
|
}
|
|
727
761
|
/**
|
|
728
|
-
*
|
|
729
|
-
* 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.
|
|
730
764
|
*
|
|
731
|
-
* @returns The extracted result
|
|
765
|
+
* @returns The extracted result
|
|
732
766
|
*/
|
|
733
|
-
|
|
767
|
+
extractResult() {
|
|
734
768
|
return this.cachedExtractedResult !== void 0 ? this.cachedExtractedResult : (this.cachedExtractedResult = this.resultExtractor(this), this.cachedExtractedResult);
|
|
735
769
|
}
|
|
736
770
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
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 = {
|
|
802
|
+
"Content-Type": E.APPLICATION_JSON
|
|
803
|
+
}, F = {
|
|
740
804
|
baseURL: "",
|
|
741
|
-
headers:
|
|
805
|
+
headers: A
|
|
806
|
+
}, x = { resultExtractor: O.Exchange }, ut = {
|
|
807
|
+
resultExtractor: O.Response
|
|
742
808
|
};
|
|
743
|
-
class
|
|
809
|
+
class ct {
|
|
744
810
|
/**
|
|
745
811
|
* Initializes a new Fetcher instance with optional configuration.
|
|
746
812
|
*
|
|
@@ -748,9 +814,14 @@ class oe {
|
|
|
748
814
|
* If no interceptors are provided, a default set of interceptors will be used.
|
|
749
815
|
*
|
|
750
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.
|
|
751
822
|
*/
|
|
752
|
-
constructor(
|
|
753
|
-
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();
|
|
754
825
|
}
|
|
755
826
|
/**
|
|
756
827
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -759,51 +830,57 @@ class oe {
|
|
|
759
830
|
* creates a FetchExchange object, and passes it through the exchange method
|
|
760
831
|
* for interceptor processing.
|
|
761
832
|
*
|
|
833
|
+
* @template R - The type of the result to be returned
|
|
762
834
|
* @param request - Complete request configuration object
|
|
763
|
-
* @param
|
|
764
|
-
*
|
|
765
|
-
*
|
|
766
|
-
*
|
|
767
|
-
*
|
|
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.
|
|
768
841
|
* @returns Promise that resolves to the extracted result based on resultExtractor
|
|
769
842
|
* @throws Error if an unhandled error occurs during request processing
|
|
770
843
|
*/
|
|
771
|
-
async request(
|
|
772
|
-
const
|
|
844
|
+
async request(t, e) {
|
|
845
|
+
const s = {
|
|
773
846
|
...this.headers,
|
|
774
|
-
...
|
|
775
|
-
},
|
|
776
|
-
...
|
|
777
|
-
headers:
|
|
778
|
-
timeout:
|
|
779
|
-
},
|
|
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({
|
|
780
856
|
fetcher: this,
|
|
781
|
-
request:
|
|
782
|
-
resultExtractor:
|
|
783
|
-
attributes:
|
|
857
|
+
request: o,
|
|
858
|
+
resultExtractor: n,
|
|
859
|
+
attributes: i
|
|
784
860
|
});
|
|
785
|
-
return await this.interceptors.exchange(u), u.
|
|
861
|
+
return await this.interceptors.exchange(u), u.extractResult();
|
|
786
862
|
}
|
|
787
863
|
/**
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
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));
|
|
807
884
|
}
|
|
808
885
|
/**
|
|
809
886
|
* Internal helper method for making HTTP requests with a specific method.
|
|
@@ -811,25 +888,26 @@ class oe {
|
|
|
811
888
|
* This private method is used by the public HTTP method methods (get, post, etc.)
|
|
812
889
|
* to execute requests with the appropriate HTTP verb.
|
|
813
890
|
*
|
|
891
|
+
* @template R - The type of the result to be returned
|
|
814
892
|
* @param method - The HTTP method to use for the request
|
|
815
893
|
* @param url - The URL path for the request
|
|
816
894
|
* @param request - Additional request options
|
|
817
|
-
* @param
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
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.
|
|
822
901
|
* @returns Promise that resolves to the HTTP response
|
|
823
902
|
*/
|
|
824
|
-
async methodFetch(
|
|
903
|
+
async methodFetch(t, e, s = {}, o) {
|
|
825
904
|
return this.fetch(
|
|
826
|
-
|
|
905
|
+
e,
|
|
827
906
|
{
|
|
828
907
|
...s,
|
|
829
|
-
method:
|
|
908
|
+
method: t
|
|
830
909
|
},
|
|
831
|
-
o
|
|
832
|
-
n
|
|
910
|
+
o
|
|
833
911
|
);
|
|
834
912
|
}
|
|
835
913
|
/**
|
|
@@ -838,85 +916,95 @@ class oe {
|
|
|
838
916
|
* Convenience method for making GET requests. The request body is omitted
|
|
839
917
|
* as GET requests should not contain a body according to HTTP specification.
|
|
840
918
|
*
|
|
919
|
+
* @template R - The type of the result to be returned
|
|
841
920
|
* @param url - The URL path for the request
|
|
842
921
|
* @param request - Request options excluding method and body
|
|
843
|
-
* @param
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
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.
|
|
848
928
|
* @returns Promise that resolves to the HTTP response
|
|
849
929
|
*/
|
|
850
|
-
async get(
|
|
851
|
-
return this.methodFetch(c.GET,
|
|
930
|
+
async get(t, e = {}, s) {
|
|
931
|
+
return this.methodFetch(c.GET, t, e, s);
|
|
852
932
|
}
|
|
853
933
|
/**
|
|
854
|
-
* Makes a
|
|
934
|
+
* Makes a PUT HTTP request.
|
|
855
935
|
*
|
|
856
|
-
* Convenience method for making
|
|
936
|
+
* Convenience method for making PUT requests, commonly used for updating resources.
|
|
857
937
|
*
|
|
938
|
+
* @template R - The type of the result to be returned
|
|
858
939
|
* @param url - The URL path for the request
|
|
859
940
|
* @param request - Request options including body and other parameters
|
|
860
|
-
* @param
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
*
|
|
864
|
-
*
|
|
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.
|
|
865
947
|
* @returns Promise that resolves to the HTTP response
|
|
866
948
|
*/
|
|
867
|
-
async
|
|
868
|
-
return this.methodFetch(c.
|
|
949
|
+
async put(t, e = {}, s) {
|
|
950
|
+
return this.methodFetch(c.PUT, t, e, s);
|
|
869
951
|
}
|
|
870
952
|
/**
|
|
871
|
-
* Makes a
|
|
953
|
+
* Makes a POST HTTP request.
|
|
872
954
|
*
|
|
873
|
-
* Convenience method for making
|
|
955
|
+
* Convenience method for making POST requests, commonly used for creating resources.
|
|
874
956
|
*
|
|
957
|
+
* @template R - The type of the result to be returned
|
|
875
958
|
* @param url - The URL path for the request
|
|
876
959
|
* @param request - Request options including body and other parameters
|
|
877
|
-
* @param
|
|
878
|
-
*
|
|
879
|
-
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
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.
|
|
882
966
|
* @returns Promise that resolves to the HTTP response
|
|
883
967
|
*/
|
|
884
|
-
async
|
|
885
|
-
return this.methodFetch(c.
|
|
968
|
+
async post(t, e = {}, s) {
|
|
969
|
+
return this.methodFetch(c.POST, t, e, s);
|
|
886
970
|
}
|
|
887
971
|
/**
|
|
888
|
-
* Makes a
|
|
972
|
+
* Makes a PATCH HTTP request.
|
|
889
973
|
*
|
|
890
|
-
* Convenience method for making
|
|
974
|
+
* Convenience method for making PATCH requests, commonly used for partial updates.
|
|
891
975
|
*
|
|
976
|
+
* @template R - The type of the result to be returned
|
|
892
977
|
* @param url - The URL path for the request
|
|
893
|
-
* @param request - Request options
|
|
894
|
-
* @param
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
*
|
|
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.
|
|
899
985
|
* @returns Promise that resolves to the HTTP response
|
|
900
986
|
*/
|
|
901
|
-
async
|
|
902
|
-
return this.methodFetch(c.
|
|
987
|
+
async patch(t, e = {}, s) {
|
|
988
|
+
return this.methodFetch(c.PATCH, t, e, s);
|
|
903
989
|
}
|
|
904
990
|
/**
|
|
905
|
-
* Makes a
|
|
991
|
+
* Makes a DELETE HTTP request.
|
|
906
992
|
*
|
|
907
|
-
* Convenience method for making
|
|
993
|
+
* Convenience method for making DELETE requests, commonly used for deleting resources.
|
|
908
994
|
*
|
|
995
|
+
* @template R - The type of the result to be returned
|
|
909
996
|
* @param url - The URL path for the request
|
|
910
|
-
* @param request - Request options
|
|
911
|
-
* @param
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
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.
|
|
916
1004
|
* @returns Promise that resolves to the HTTP response
|
|
917
1005
|
*/
|
|
918
|
-
async
|
|
919
|
-
return this.methodFetch(c.
|
|
1006
|
+
async delete(t, e = {}, s) {
|
|
1007
|
+
return this.methodFetch(c.DELETE, t, e, s);
|
|
920
1008
|
}
|
|
921
1009
|
/**
|
|
922
1010
|
* Makes a HEAD HTTP request.
|
|
@@ -924,17 +1012,19 @@ class oe {
|
|
|
924
1012
|
* Convenience method for making HEAD requests, which retrieve headers only.
|
|
925
1013
|
* The request body is omitted as HEAD requests should not contain a body.
|
|
926
1014
|
*
|
|
1015
|
+
* @template R - The type of the result to be returned
|
|
927
1016
|
* @param url - The URL path for the request
|
|
928
1017
|
* @param request - Request options excluding method and body
|
|
929
|
-
* @param
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
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.
|
|
934
1024
|
* @returns Promise that resolves to the HTTP response
|
|
935
1025
|
*/
|
|
936
|
-
async head(
|
|
937
|
-
return this.methodFetch(c.HEAD,
|
|
1026
|
+
async head(t, e = {}, s) {
|
|
1027
|
+
return this.methodFetch(c.HEAD, t, e, s);
|
|
938
1028
|
}
|
|
939
1029
|
/**
|
|
940
1030
|
* Makes an OPTIONS HTTP request.
|
|
@@ -942,21 +1032,23 @@ class oe {
|
|
|
942
1032
|
* Convenience method for making OPTIONS requests, commonly used for CORS preflight.
|
|
943
1033
|
* The request body is omitted as OPTIONS requests typically don't contain a body.
|
|
944
1034
|
*
|
|
1035
|
+
* @template R - The type of the result to be returned
|
|
945
1036
|
* @param url - The URL path for the request
|
|
946
1037
|
* @param request - Request options excluding method and body
|
|
947
|
-
* @param
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
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.
|
|
952
1044
|
* @returns Promise that resolves to the HTTP response
|
|
953
1045
|
*/
|
|
954
|
-
async options(
|
|
955
|
-
return this.methodFetch(c.OPTIONS,
|
|
1046
|
+
async options(t, e = {}, s) {
|
|
1047
|
+
return this.methodFetch(c.OPTIONS, t, e, s);
|
|
956
1048
|
}
|
|
957
1049
|
}
|
|
958
|
-
const
|
|
959
|
-
class
|
|
1050
|
+
const y = "default";
|
|
1051
|
+
class at {
|
|
960
1052
|
constructor() {
|
|
961
1053
|
this.registrar = /* @__PURE__ */ new Map();
|
|
962
1054
|
}
|
|
@@ -969,8 +1061,8 @@ class ne {
|
|
|
969
1061
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
970
1062
|
* fetcherRegistrar.register('api', fetcher);
|
|
971
1063
|
*/
|
|
972
|
-
register(
|
|
973
|
-
this.registrar.set(
|
|
1064
|
+
register(t, e) {
|
|
1065
|
+
this.registrar.set(t, e);
|
|
974
1066
|
}
|
|
975
1067
|
/**
|
|
976
1068
|
* Unregister a Fetcher instance by name
|
|
@@ -983,8 +1075,8 @@ class ne {
|
|
|
983
1075
|
* console.log('Fetcher unregistered successfully');
|
|
984
1076
|
* }
|
|
985
1077
|
*/
|
|
986
|
-
unregister(
|
|
987
|
-
return this.registrar.delete(
|
|
1078
|
+
unregister(t) {
|
|
1079
|
+
return this.registrar.delete(t);
|
|
988
1080
|
}
|
|
989
1081
|
/**
|
|
990
1082
|
* Get a Fetcher instance by name
|
|
@@ -997,8 +1089,8 @@ class ne {
|
|
|
997
1089
|
* // Use the fetcher
|
|
998
1090
|
* }
|
|
999
1091
|
*/
|
|
1000
|
-
get(
|
|
1001
|
-
return this.registrar.get(
|
|
1092
|
+
get(t) {
|
|
1093
|
+
return this.registrar.get(t);
|
|
1002
1094
|
}
|
|
1003
1095
|
/**
|
|
1004
1096
|
* Get a Fetcher instance by name, throwing an error if not found
|
|
@@ -1014,11 +1106,11 @@ class ne {
|
|
|
1014
1106
|
* console.error('Fetcher not found:', error.message);
|
|
1015
1107
|
* }
|
|
1016
1108
|
*/
|
|
1017
|
-
requiredGet(
|
|
1018
|
-
const
|
|
1019
|
-
if (!
|
|
1020
|
-
throw new Error(`Fetcher ${
|
|
1021
|
-
return
|
|
1109
|
+
requiredGet(t) {
|
|
1110
|
+
const e = this.get(t);
|
|
1111
|
+
if (!e)
|
|
1112
|
+
throw new Error(`Fetcher ${t} not found`);
|
|
1113
|
+
return e;
|
|
1022
1114
|
}
|
|
1023
1115
|
/**
|
|
1024
1116
|
* Get the default Fetcher instance
|
|
@@ -1029,7 +1121,7 @@ class ne {
|
|
|
1029
1121
|
* const defaultFetcher = fetcherRegistrar.default;
|
|
1030
1122
|
*/
|
|
1031
1123
|
get default() {
|
|
1032
|
-
return this.requiredGet(
|
|
1124
|
+
return this.requiredGet(y);
|
|
1033
1125
|
}
|
|
1034
1126
|
/**
|
|
1035
1127
|
* Set the default Fetcher instance
|
|
@@ -1039,8 +1131,8 @@ class ne {
|
|
|
1039
1131
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
1040
1132
|
* fetcherRegistrar.default = fetcher;
|
|
1041
1133
|
*/
|
|
1042
|
-
set default(
|
|
1043
|
-
this.register(
|
|
1134
|
+
set default(t) {
|
|
1135
|
+
this.register(y, t);
|
|
1044
1136
|
}
|
|
1045
1137
|
/**
|
|
1046
1138
|
* Get a copy of all registered fetchers
|
|
@@ -1056,36 +1148,8 @@ class ne {
|
|
|
1056
1148
|
return new Map(this.registrar);
|
|
1057
1149
|
}
|
|
1058
1150
|
}
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
if (!(r === void 0 && e === void 0))
|
|
1062
|
-
return e === void 0 ? r : r === void 0 ? e : { ...r, ...e };
|
|
1063
|
-
}
|
|
1064
|
-
function ae(r, e) {
|
|
1065
|
-
if (Object.keys(r).length === 0)
|
|
1066
|
-
return e;
|
|
1067
|
-
if (Object.keys(e).length === 0)
|
|
1068
|
-
return r;
|
|
1069
|
-
const t = {
|
|
1070
|
-
path: g(r.urlParams?.path, e.urlParams?.path),
|
|
1071
|
-
query: g(r.urlParams?.query, e.urlParams?.query)
|
|
1072
|
-
}, s = {
|
|
1073
|
-
...r.headers,
|
|
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;
|
|
1076
|
-
return {
|
|
1077
|
-
...r,
|
|
1078
|
-
...e,
|
|
1079
|
-
method: o,
|
|
1080
|
-
urlParams: t,
|
|
1081
|
-
headers: s,
|
|
1082
|
-
body: n,
|
|
1083
|
-
timeout: u,
|
|
1084
|
-
signal: a,
|
|
1085
|
-
abortController: m
|
|
1086
|
-
};
|
|
1087
|
-
}
|
|
1088
|
-
class ue extends oe {
|
|
1151
|
+
const ht = new at();
|
|
1152
|
+
class lt extends ct {
|
|
1089
1153
|
/**
|
|
1090
1154
|
* Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
|
|
1091
1155
|
*
|
|
@@ -1103,61 +1167,65 @@ class ue extends oe {
|
|
|
1103
1167
|
* headers: { 'Authorization': 'Bearer token' }
|
|
1104
1168
|
* });
|
|
1105
1169
|
*/
|
|
1106
|
-
constructor(
|
|
1107
|
-
super(
|
|
1170
|
+
constructor(t, e = F) {
|
|
1171
|
+
super(e), this.name = t, ht.register(t, this);
|
|
1108
1172
|
}
|
|
1109
1173
|
}
|
|
1110
|
-
const
|
|
1174
|
+
const Rt = new lt(y);
|
|
1111
1175
|
export {
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1176
|
+
Et as CONTENT_TYPE_HEADER,
|
|
1177
|
+
E as ContentTypeValues,
|
|
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,
|
|
1189
|
+
b as FetchTimeoutError,
|
|
1190
|
+
ct as Fetcher,
|
|
1191
|
+
l as FetcherError,
|
|
1192
|
+
at as FetcherRegistrar,
|
|
1127
1193
|
c as HttpMethod,
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
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,
|
|
1152
1218
|
D as getUrlTemplateResolver,
|
|
1153
|
-
|
|
1219
|
+
C as isAbsoluteURL,
|
|
1220
|
+
nt as mergeRecordToMap,
|
|
1154
1221
|
g as mergeRecords,
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1222
|
+
dt as mergeRequest,
|
|
1223
|
+
q as mergeRequestOptions,
|
|
1224
|
+
H as resolveTimeout,
|
|
1225
|
+
j as timeoutFetch,
|
|
1158
1226
|
T as toSorted,
|
|
1159
1227
|
L as uriTemplateResolver,
|
|
1160
|
-
|
|
1161
|
-
|
|
1228
|
+
N as urlTemplateRegexExtract,
|
|
1229
|
+
w as urlTemplateRegexResolve
|
|
1162
1230
|
};
|
|
1163
1231
|
//# sourceMappingURL=index.es.js.map
|