@ahoo-wang/fetcher 2.6.9 → 2.6.12
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.map +1 -1
- package/dist/fetcherError.d.ts +33 -0
- package/dist/fetcherError.d.ts.map +1 -1
- package/dist/index.es.js +214 -213
- 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/interceptorManager.d.ts +0 -33
- package/dist/interceptorManager.d.ts.map +1 -1
- package/dist/validateStatusInterceptor.d.ts +2 -3
- package/dist/validateStatusInterceptor.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchExchange.d.ts","sourceRoot":"","sources":["../src/fetchExchange.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchExchange.d.ts","sourceRoot":"","sources":["../src/fetchExchange.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AAItE,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrD;AAED,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IACtB,eAAe,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,qBAAa,aACX,YAAW,UAAU,CAAC,iBAAiB,EAAE,YAAY,CAAC;IACtD;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;;OAGG;IACH,eAAe,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC;IACtC;;OAEG;IACH,OAAO,CAAC,SAAS,CAAC,CAAW;IAE7B;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,qBAAqB,CAAC,CAAqB;IACnD;;;;;;;;;;;;;OAaG;IACH,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;gBAEjB,YAAY,EAAE,iBAAiB;IAU3C;;;;;;;;OAQG;IACH,oBAAoB,IAAI,cAAc;IAOtC;;;;;;;;;;OAUG;IACH,sBAAsB,IAAI,QAAQ,CAAC,SAAS,CAAC;IAgB7C;;;;OAIG;IACH,QAAQ,IAAI,OAAO;IAInB;;;;;;OAMG;IACH,IAAI,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAG1C;IAED;;;;OAIG;IACH,IAAI,QAAQ,IAAI,QAAQ,GAAG,SAAS,CAEnC;IAED;;;;OAIG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;OASG;IACH,IAAI,gBAAgB,IAAI,QAAQ,CAQ/B;IAED;;;;;OAKG;IACG,aAAa,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;CAOrC"}
|
package/dist/fetcherError.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetchExchange } from './fetchExchange';
|
|
1
2
|
/**
|
|
2
3
|
* Base error class for all Fetcher-related errors.
|
|
3
4
|
*
|
|
@@ -29,4 +30,36 @@ export declare class FetcherError extends Error {
|
|
|
29
30
|
*/
|
|
30
31
|
constructor(errorMsg?: string, cause?: (Error | any) | undefined);
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Custom error class for FetchExchange related errors.
|
|
35
|
+
*
|
|
36
|
+
* This error is thrown when there are issues with the HTTP exchange process,
|
|
37
|
+
* such as when a request fails and no response is generated. It provides
|
|
38
|
+
* comprehensive information about the failed request through the exchange object.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* try {
|
|
43
|
+
* await fetcher.get('/api/users');
|
|
44
|
+
* } catch (error) {
|
|
45
|
+
* if (error instanceof ExchangeError) {
|
|
46
|
+
* console.log('Request URL:', error.exchange.request.url);
|
|
47
|
+
* console.log('Request method:', error.exchange.request.method);
|
|
48
|
+
* if (error.exchange.error) {
|
|
49
|
+
* console.log('Underlying error:', error.exchange.error);
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare class ExchangeError extends FetcherError {
|
|
56
|
+
readonly exchange: FetchExchange;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new ExchangeError instance.
|
|
59
|
+
*
|
|
60
|
+
* @param exchange - The FetchExchange object containing request/response/error information.
|
|
61
|
+
* @param errorMsg - An optional error message.
|
|
62
|
+
*/
|
|
63
|
+
constructor(exchange: FetchExchange, errorMsg?: string);
|
|
64
|
+
}
|
|
32
65
|
//# sourceMappingURL=fetcherError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcherError.d.ts","sourceRoot":"","sources":["../src/fetcherError.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAa,SAAQ,KAAK;aASnB,KAAK,CAAC,GAAE,KAAK,GAAG,GAAG;IARrC;;;;;OAKG;gBAED,QAAQ,CAAC,EAAE,MAAM,EACD,KAAK,CAAC,GAAE,KAAK,GAAG,GAAG,aAAA;CAetC"}
|
|
1
|
+
{"version":3,"file":"fetcherError.d.ts","sourceRoot":"","sources":["../src/fetcherError.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAa,SAAQ,KAAK;aASnB,KAAK,CAAC,GAAE,KAAK,GAAG,GAAG;IARrC;;;;;OAKG;gBAED,QAAQ,CAAC,EAAE,MAAM,EACD,KAAK,CAAC,GAAE,KAAK,GAAG,GAAG,aAAA;CAetC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,aAAc,SAAQ,YAAY;aAQ3B,QAAQ,EAAE,aAAa;IAPzC;;;;;OAKG;gBAEe,QAAQ,EAAE,aAAa,EACvC,QAAQ,CAAC,EAAE,MAAM;CAWpB"}
|
package/dist/index.es.js
CHANGED
|
@@ -229,7 +229,7 @@ class $ {
|
|
|
229
229
|
return this.build(t.url, t.urlParams);
|
|
230
230
|
}
|
|
231
231
|
}
|
|
232
|
-
class
|
|
232
|
+
class p extends Error {
|
|
233
233
|
/**
|
|
234
234
|
* Creates a new FetcherError instance.
|
|
235
235
|
*
|
|
@@ -238,10 +238,22 @@ class E extends Error {
|
|
|
238
238
|
*/
|
|
239
239
|
constructor(t, r) {
|
|
240
240
|
const s = t || r?.message || "An error occurred in the fetcher";
|
|
241
|
-
super(s), this.cause = r, this.name = "FetcherError", r?.stack && (this.stack = r.stack), Object.setPrototypeOf(this,
|
|
241
|
+
super(s), this.cause = r, this.name = "FetcherError", r?.stack && (this.stack = r.stack), Object.setPrototypeOf(this, p.prototype);
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
class
|
|
244
|
+
class E extends p {
|
|
245
|
+
/**
|
|
246
|
+
* Creates a new ExchangeError instance.
|
|
247
|
+
*
|
|
248
|
+
* @param exchange - The FetchExchange object containing request/response/error information.
|
|
249
|
+
* @param errorMsg - An optional error message.
|
|
250
|
+
*/
|
|
251
|
+
constructor(t, r) {
|
|
252
|
+
const s = r || t.error?.message || t.response?.statusText || `Request to ${t.request.url} failed during exchange`;
|
|
253
|
+
super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, E.prototype);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
class O extends p {
|
|
245
257
|
/**
|
|
246
258
|
* Creates a new FetchTimeoutError instance.
|
|
247
259
|
*
|
|
@@ -277,10 +289,156 @@ async function V(e) {
|
|
|
277
289
|
n && clearTimeout(n);
|
|
278
290
|
}
|
|
279
291
|
}
|
|
280
|
-
const k =
|
|
281
|
-
|
|
292
|
+
const k = (e) => e, J = (e) => e.requiredResponse, Q = (e) => e.requiredResponse.json(), Y = (e) => e.requiredResponse.text(), z = (e) => e.requiredResponse.blob(), K = (e) => e.requiredResponse.arrayBuffer(), W = (e) => e.requiredResponse.bytes(), q = {
|
|
293
|
+
/**
|
|
294
|
+
* Returns the original FetchExchange object
|
|
295
|
+
*/
|
|
296
|
+
Exchange: k,
|
|
297
|
+
/**
|
|
298
|
+
* Extracts the raw Response object
|
|
299
|
+
*/
|
|
300
|
+
Response: J,
|
|
301
|
+
/**
|
|
302
|
+
* Parses and returns response body as JSON
|
|
303
|
+
*/
|
|
304
|
+
Json: Q,
|
|
305
|
+
/**
|
|
306
|
+
* Returns response body as text
|
|
307
|
+
*/
|
|
308
|
+
Text: Y,
|
|
309
|
+
/**
|
|
310
|
+
* Returns response body as a Blob
|
|
311
|
+
*/
|
|
312
|
+
Blob: z,
|
|
313
|
+
/**
|
|
314
|
+
* Returns response body as an ArrayBuffer
|
|
315
|
+
*/
|
|
316
|
+
ArrayBuffer: K,
|
|
317
|
+
/**
|
|
318
|
+
* Returns response body as a Uint8Array
|
|
319
|
+
*/
|
|
320
|
+
Bytes: W
|
|
321
|
+
};
|
|
322
|
+
function S(e, t) {
|
|
323
|
+
if (!(e === void 0 && t === void 0))
|
|
324
|
+
return t === void 0 ? e : e === void 0 ? t : { ...e, ...t };
|
|
325
|
+
}
|
|
326
|
+
function Z(e, t) {
|
|
327
|
+
if (t ??= /* @__PURE__ */ new Map(), !e)
|
|
328
|
+
return t;
|
|
329
|
+
if (e instanceof Map) {
|
|
330
|
+
for (const [r, s] of e)
|
|
331
|
+
t.set(r, s);
|
|
332
|
+
return t;
|
|
333
|
+
}
|
|
334
|
+
for (const [r, s] of Object.entries(e))
|
|
335
|
+
t.set(r, s);
|
|
336
|
+
return t;
|
|
337
|
+
}
|
|
338
|
+
class tt {
|
|
339
|
+
constructor(t) {
|
|
340
|
+
this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ?? q.Exchange, this.attributes = Z(t.attributes), this._response = t.response, this.error = t.error;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Ensures that request headers object exists, creating it if necessary.
|
|
344
|
+
*
|
|
345
|
+
* This method checks if the request headers object is present and initializes
|
|
346
|
+
* it as an empty object if it's missing. This guarantees that headers can
|
|
347
|
+
* be safely accessed and modified after calling this method.
|
|
348
|
+
*
|
|
349
|
+
* @returns The request headers object, guaranteed to be non-null
|
|
350
|
+
*/
|
|
351
|
+
ensureRequestHeaders() {
|
|
352
|
+
return this.request.headers || (this.request.headers = {}), this.request.headers;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Ensures that request URL parameters object exists with all required properties,
|
|
356
|
+
* creating them if necessary.
|
|
357
|
+
*
|
|
358
|
+
* This method checks if the request URL parameters object is present and initializes
|
|
359
|
+
* it with empty path and query objects if it's missing. It also ensures that both
|
|
360
|
+
* path and query sub-objects exist. This guarantees that URL parameters can be
|
|
361
|
+
* safely accessed and modified after calling this method.
|
|
362
|
+
*
|
|
363
|
+
* @returns The request URL parameters object with guaranteed non-null path and query properties
|
|
364
|
+
*/
|
|
365
|
+
ensureRequestUrlParams() {
|
|
366
|
+
return this.request.urlParams || (this.request.urlParams = {
|
|
367
|
+
path: {},
|
|
368
|
+
query: {}
|
|
369
|
+
}), this.request.urlParams.path || (this.request.urlParams.path = {}), this.request.urlParams.query || (this.request.urlParams.query = {}), this.request.urlParams;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Checks if the exchange has an error.
|
|
373
|
+
*
|
|
374
|
+
* @returns true if an error is present, false otherwise
|
|
375
|
+
*/
|
|
376
|
+
hasError() {
|
|
377
|
+
return !!this.error;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Sets the response object for this exchange.
|
|
381
|
+
* Also invalidates the cached extracted result to ensure data consistency
|
|
382
|
+
* when the response changes.
|
|
383
|
+
*
|
|
384
|
+
* @param response - The Response object to set, or undefined to clear the response
|
|
385
|
+
*/
|
|
386
|
+
set response(t) {
|
|
387
|
+
this._response = t, this.cachedExtractedResult = void 0;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Gets the response object for this exchange.
|
|
391
|
+
*
|
|
392
|
+
* @returns The response object if available, undefined otherwise
|
|
393
|
+
*/
|
|
394
|
+
get response() {
|
|
395
|
+
return this._response;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Checks if the exchange has a response.
|
|
399
|
+
*
|
|
400
|
+
* @returns true if a response is present, false otherwise
|
|
401
|
+
*/
|
|
402
|
+
hasResponse() {
|
|
403
|
+
return !!this.response;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Gets the required response object, throwing an error if no response is available.
|
|
407
|
+
*
|
|
408
|
+
* This getter ensures that a response object is available, and throws an ExchangeError
|
|
409
|
+
* with details about the request if no response was received. This is useful for
|
|
410
|
+
* guaranteeing that downstream code always has a valid Response object to work with.
|
|
411
|
+
*
|
|
412
|
+
* @throws {ExchangeError} If no response is available for the current exchange
|
|
413
|
+
* @returns The Response object for this exchange
|
|
414
|
+
*/
|
|
415
|
+
get requiredResponse() {
|
|
416
|
+
if (!this.response)
|
|
417
|
+
throw new E(
|
|
418
|
+
this,
|
|
419
|
+
`Request to ${this.request.url} failed with no response`
|
|
420
|
+
);
|
|
421
|
+
return this.response;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Extracts the result by applying the result extractor to the exchange.
|
|
425
|
+
* The result is cached after the first computation to avoid repeated computations.
|
|
426
|
+
*
|
|
427
|
+
* @returns The extracted result
|
|
428
|
+
*/
|
|
429
|
+
async extractResult() {
|
|
430
|
+
return this.cachedExtractedResult !== void 0 ? await this.cachedExtractedResult : (this.cachedExtractedResult = this.resultExtractor(this), await this.cachedExtractedResult);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
var i = /* @__PURE__ */ ((e) => (e.GET = "GET", e.POST = "POST", e.PUT = "PUT", e.DELETE = "DELETE", e.PATCH = "PATCH", e.HEAD = "HEAD", e.OPTIONS = "OPTIONS", e.TRACE = "TRACE", e))(i || {});
|
|
434
|
+
const c = "Content-Type", d = class d {
|
|
435
|
+
};
|
|
436
|
+
d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
|
|
437
|
+
let R = d;
|
|
438
|
+
const et = "UrlResolveInterceptor", C = Number.MIN_SAFE_INTEGER + 1e3;
|
|
439
|
+
class rt {
|
|
282
440
|
constructor() {
|
|
283
|
-
this.name =
|
|
441
|
+
this.name = et, this.order = C;
|
|
284
442
|
}
|
|
285
443
|
/**
|
|
286
444
|
* Resolves the final URL by combining the base URL, path parameters, and query parameters.
|
|
@@ -292,15 +450,10 @@ class J {
|
|
|
292
450
|
r.url = t.fetcher.urlBuilder.resolveRequestUrl(r);
|
|
293
451
|
}
|
|
294
452
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
};
|
|
298
|
-
d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
|
|
299
|
-
let R = d;
|
|
300
|
-
const Q = "RequestBodyInterceptor", Y = C + 1e3;
|
|
301
|
-
class z {
|
|
453
|
+
const st = "RequestBodyInterceptor", ot = C + 1e3;
|
|
454
|
+
class nt {
|
|
302
455
|
constructor() {
|
|
303
|
-
this.name =
|
|
456
|
+
this.name = st, this.order = ot;
|
|
304
457
|
}
|
|
305
458
|
/**
|
|
306
459
|
* Checks if the provided body is of a supported complex type that doesn't require JSON serialization.
|
|
@@ -373,10 +526,10 @@ class z {
|
|
|
373
526
|
this.isSupportedComplexBodyType(r.body) || (t.request.body = JSON.stringify(r.body), s[c] || (s[c] = R.APPLICATION_JSON));
|
|
374
527
|
}
|
|
375
528
|
}
|
|
376
|
-
const
|
|
377
|
-
class
|
|
529
|
+
const it = "FetchInterceptor", at = Number.MAX_SAFE_INTEGER - 1e3;
|
|
530
|
+
class ut {
|
|
378
531
|
constructor() {
|
|
379
|
-
this.name =
|
|
532
|
+
this.name = it, this.order = at;
|
|
380
533
|
}
|
|
381
534
|
/**
|
|
382
535
|
* Intercept and process HTTP requests.
|
|
@@ -503,21 +656,22 @@ class m {
|
|
|
503
656
|
await r.intercept(t);
|
|
504
657
|
}
|
|
505
658
|
}
|
|
506
|
-
class
|
|
659
|
+
class b extends E {
|
|
507
660
|
constructor(t) {
|
|
508
661
|
super(
|
|
662
|
+
t,
|
|
509
663
|
`Request failed with status code ${t.response?.status} for ${t.request.url}`
|
|
510
|
-
), this.
|
|
664
|
+
), this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, b.prototype);
|
|
511
665
|
}
|
|
512
666
|
}
|
|
513
|
-
const
|
|
514
|
-
class
|
|
667
|
+
const ct = (e) => e >= 200 && e < 300, ht = "ValidateStatusInterceptor", lt = Number.MAX_SAFE_INTEGER - 1e3;
|
|
668
|
+
class Et {
|
|
515
669
|
/**
|
|
516
670
|
* Creates a new ValidateStatusInterceptor instance.
|
|
517
671
|
*
|
|
518
672
|
* @param validateStatus - Function that determines if a status code is valid
|
|
519
673
|
*/
|
|
520
|
-
constructor(t =
|
|
674
|
+
constructor(t = ct) {
|
|
521
675
|
this.validateStatus = t;
|
|
522
676
|
}
|
|
523
677
|
/**
|
|
@@ -526,7 +680,7 @@ class st {
|
|
|
526
680
|
* @returns The name of this interceptor
|
|
527
681
|
*/
|
|
528
682
|
get name() {
|
|
529
|
-
return
|
|
683
|
+
return ht;
|
|
530
684
|
}
|
|
531
685
|
/**
|
|
532
686
|
* Gets the order of this interceptor.
|
|
@@ -534,7 +688,7 @@ class st {
|
|
|
534
688
|
* @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
|
|
535
689
|
*/
|
|
536
690
|
get order() {
|
|
537
|
-
return
|
|
691
|
+
return lt;
|
|
538
692
|
}
|
|
539
693
|
/**
|
|
540
694
|
* Validates the response status code.
|
|
@@ -554,29 +708,17 @@ class st {
|
|
|
554
708
|
return;
|
|
555
709
|
const r = t.response.status;
|
|
556
710
|
if (!this.validateStatus(r))
|
|
557
|
-
throw new
|
|
711
|
+
throw new b(t);
|
|
558
712
|
}
|
|
559
713
|
}
|
|
560
|
-
class
|
|
561
|
-
/**
|
|
562
|
-
* Creates a new ExchangeError instance.
|
|
563
|
-
*
|
|
564
|
-
* @param exchange - The FetchExchange object containing request/response/error information.
|
|
565
|
-
* @param errorMsg - An optional error message.
|
|
566
|
-
*/
|
|
567
|
-
constructor(t, r) {
|
|
568
|
-
const s = r || t.error?.message || t.response?.statusText || `Request to ${t.request.url} failed during exchange`;
|
|
569
|
-
super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, p.prototype);
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
class ot {
|
|
714
|
+
class Rt {
|
|
573
715
|
constructor() {
|
|
574
716
|
this.request = new m([
|
|
575
|
-
new
|
|
576
|
-
new
|
|
577
|
-
new
|
|
717
|
+
new rt(),
|
|
718
|
+
new nt(),
|
|
719
|
+
new ut()
|
|
578
720
|
]), this.response = new m([
|
|
579
|
-
new
|
|
721
|
+
new Et()
|
|
580
722
|
]), this.error = new m();
|
|
581
723
|
}
|
|
582
724
|
/**
|
|
@@ -671,151 +813,10 @@ class ot {
|
|
|
671
813
|
} catch (r) {
|
|
672
814
|
if (t.error = r, await this.error.intercept(t), !t.hasError())
|
|
673
815
|
return t;
|
|
674
|
-
throw new
|
|
816
|
+
throw new E(t);
|
|
675
817
|
}
|
|
676
818
|
}
|
|
677
819
|
}
|
|
678
|
-
const nt = (e) => e, it = (e) => e.requiredResponse, at = (e) => e.requiredResponse.json(), ut = (e) => e.requiredResponse.text(), ct = (e) => e.requiredResponse.blob(), ht = (e) => e.requiredResponse.arrayBuffer(), lt = (e) => e.requiredResponse.bytes(), b = {
|
|
679
|
-
/**
|
|
680
|
-
* Returns the original FetchExchange object
|
|
681
|
-
*/
|
|
682
|
-
Exchange: nt,
|
|
683
|
-
/**
|
|
684
|
-
* Extracts the raw Response object
|
|
685
|
-
*/
|
|
686
|
-
Response: it,
|
|
687
|
-
/**
|
|
688
|
-
* Parses and returns response body as JSON
|
|
689
|
-
*/
|
|
690
|
-
Json: at,
|
|
691
|
-
/**
|
|
692
|
-
* Returns response body as text
|
|
693
|
-
*/
|
|
694
|
-
Text: ut,
|
|
695
|
-
/**
|
|
696
|
-
* Returns response body as a Blob
|
|
697
|
-
*/
|
|
698
|
-
Blob: ct,
|
|
699
|
-
/**
|
|
700
|
-
* Returns response body as an ArrayBuffer
|
|
701
|
-
*/
|
|
702
|
-
ArrayBuffer: ht,
|
|
703
|
-
/**
|
|
704
|
-
* Returns response body as a Uint8Array
|
|
705
|
-
*/
|
|
706
|
-
Bytes: lt
|
|
707
|
-
};
|
|
708
|
-
function S(e, t) {
|
|
709
|
-
if (!(e === void 0 && t === void 0))
|
|
710
|
-
return t === void 0 ? e : e === void 0 ? t : { ...e, ...t };
|
|
711
|
-
}
|
|
712
|
-
function Et(e, t) {
|
|
713
|
-
if (t ??= /* @__PURE__ */ new Map(), !e)
|
|
714
|
-
return t;
|
|
715
|
-
if (e instanceof Map) {
|
|
716
|
-
for (const [r, s] of e)
|
|
717
|
-
t.set(r, s);
|
|
718
|
-
return t;
|
|
719
|
-
}
|
|
720
|
-
for (const [r, s] of Object.entries(e))
|
|
721
|
-
t.set(r, s);
|
|
722
|
-
return t;
|
|
723
|
-
}
|
|
724
|
-
class Rt {
|
|
725
|
-
constructor(t) {
|
|
726
|
-
this.fetcher = t.fetcher, this.request = t.request, this.resultExtractor = t.resultExtractor ?? b.Exchange, this.attributes = Et(t.attributes), this._response = t.response, this.error = t.error;
|
|
727
|
-
}
|
|
728
|
-
/**
|
|
729
|
-
* Ensures that request headers object exists, creating it if necessary.
|
|
730
|
-
*
|
|
731
|
-
* This method checks if the request headers object is present and initializes
|
|
732
|
-
* it as an empty object if it's missing. This guarantees that headers can
|
|
733
|
-
* be safely accessed and modified after calling this method.
|
|
734
|
-
*
|
|
735
|
-
* @returns The request headers object, guaranteed to be non-null
|
|
736
|
-
*/
|
|
737
|
-
ensureRequestHeaders() {
|
|
738
|
-
return this.request.headers || (this.request.headers = {}), this.request.headers;
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* Ensures that request URL parameters object exists with all required properties,
|
|
742
|
-
* creating them if necessary.
|
|
743
|
-
*
|
|
744
|
-
* This method checks if the request URL parameters object is present and initializes
|
|
745
|
-
* it with empty path and query objects if it's missing. It also ensures that both
|
|
746
|
-
* path and query sub-objects exist. This guarantees that URL parameters can be
|
|
747
|
-
* safely accessed and modified after calling this method.
|
|
748
|
-
*
|
|
749
|
-
* @returns The request URL parameters object with guaranteed non-null path and query properties
|
|
750
|
-
*/
|
|
751
|
-
ensureRequestUrlParams() {
|
|
752
|
-
return this.request.urlParams || (this.request.urlParams = {
|
|
753
|
-
path: {},
|
|
754
|
-
query: {}
|
|
755
|
-
}), this.request.urlParams.path || (this.request.urlParams.path = {}), this.request.urlParams.query || (this.request.urlParams.query = {}), this.request.urlParams;
|
|
756
|
-
}
|
|
757
|
-
/**
|
|
758
|
-
* Checks if the exchange has an error.
|
|
759
|
-
*
|
|
760
|
-
* @returns true if an error is present, false otherwise
|
|
761
|
-
*/
|
|
762
|
-
hasError() {
|
|
763
|
-
return !!this.error;
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Sets the response object for this exchange.
|
|
767
|
-
* Also invalidates the cached extracted result to ensure data consistency
|
|
768
|
-
* when the response changes.
|
|
769
|
-
*
|
|
770
|
-
* @param response - The Response object to set, or undefined to clear the response
|
|
771
|
-
*/
|
|
772
|
-
set response(t) {
|
|
773
|
-
this._response = t, this.cachedExtractedResult = void 0;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Gets the response object for this exchange.
|
|
777
|
-
*
|
|
778
|
-
* @returns The response object if available, undefined otherwise
|
|
779
|
-
*/
|
|
780
|
-
get response() {
|
|
781
|
-
return this._response;
|
|
782
|
-
}
|
|
783
|
-
/**
|
|
784
|
-
* Checks if the exchange has a response.
|
|
785
|
-
*
|
|
786
|
-
* @returns true if a response is present, false otherwise
|
|
787
|
-
*/
|
|
788
|
-
hasResponse() {
|
|
789
|
-
return !!this.response;
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Gets the required response object, throwing an error if no response is available.
|
|
793
|
-
*
|
|
794
|
-
* This getter ensures that a response object is available, and throws an ExchangeError
|
|
795
|
-
* with details about the request if no response was received. This is useful for
|
|
796
|
-
* guaranteeing that downstream code always has a valid Response object to work with.
|
|
797
|
-
*
|
|
798
|
-
* @throws {ExchangeError} If no response is available for the current exchange
|
|
799
|
-
* @returns The Response object for this exchange
|
|
800
|
-
*/
|
|
801
|
-
get requiredResponse() {
|
|
802
|
-
if (!this.response)
|
|
803
|
-
throw new p(
|
|
804
|
-
this,
|
|
805
|
-
`Request to ${this.request.url} failed with no response`
|
|
806
|
-
);
|
|
807
|
-
return this.response;
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
* Extracts the result by applying the result extractor to the exchange.
|
|
811
|
-
* The result is cached after the first computation to avoid repeated computations.
|
|
812
|
-
*
|
|
813
|
-
* @returns The extracted result
|
|
814
|
-
*/
|
|
815
|
-
async extractResult() {
|
|
816
|
-
return this.cachedExtractedResult !== void 0 ? await this.cachedExtractedResult : (this.cachedExtractedResult = this.resultExtractor(this), await this.cachedExtractedResult);
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
820
|
function Tt(e, t) {
|
|
820
821
|
if (Object.keys(e).length === 0)
|
|
821
822
|
return t;
|
|
@@ -852,9 +853,9 @@ const w = {
|
|
|
852
853
|
baseURL: "",
|
|
853
854
|
headers: w
|
|
854
855
|
}, v = {
|
|
855
|
-
resultExtractor:
|
|
856
|
+
resultExtractor: q.Exchange
|
|
856
857
|
}, N = {
|
|
857
|
-
resultExtractor:
|
|
858
|
+
resultExtractor: q.Response
|
|
858
859
|
};
|
|
859
860
|
class D {
|
|
860
861
|
/**
|
|
@@ -871,7 +872,7 @@ class D {
|
|
|
871
872
|
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
872
873
|
*/
|
|
873
874
|
constructor(t = U) {
|
|
874
|
-
this.headers = w, this.urlBuilder = new $(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? w, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new
|
|
875
|
+
this.headers = w, this.urlBuilder = new $(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? w, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new Rt();
|
|
875
876
|
}
|
|
876
877
|
/**
|
|
877
878
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -894,7 +895,7 @@ class D {
|
|
|
894
895
|
}, { resultExtractor: n, attributes: a } = A(
|
|
895
896
|
v,
|
|
896
897
|
r
|
|
897
|
-
), u = new
|
|
898
|
+
), u = new tt({
|
|
898
899
|
fetcher: this,
|
|
899
900
|
request: o,
|
|
900
901
|
resultExtractor: n,
|
|
@@ -1264,47 +1265,47 @@ class pt extends D {
|
|
|
1264
1265
|
}
|
|
1265
1266
|
const mt = new pt(g);
|
|
1266
1267
|
export {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1268
|
+
K as ArrayBufferResultExtractor,
|
|
1269
|
+
z as BlobResultExtractor,
|
|
1270
|
+
W as BytesResultExtractor,
|
|
1270
1271
|
c as CONTENT_TYPE_HEADER,
|
|
1271
1272
|
R as ContentTypeValues,
|
|
1272
1273
|
g as DEFAULT_FETCHER_NAME,
|
|
1273
1274
|
N as DEFAULT_FETCH_OPTIONS,
|
|
1274
1275
|
U as DEFAULT_OPTIONS,
|
|
1275
1276
|
v as DEFAULT_REQUEST_OPTIONS,
|
|
1276
|
-
|
|
1277
|
-
|
|
1277
|
+
E as ExchangeError,
|
|
1278
|
+
k as ExchangeResultExtractor,
|
|
1278
1279
|
y as ExpressUrlTemplateResolver,
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1280
|
+
it as FETCH_INTERCEPTOR_NAME,
|
|
1281
|
+
at as FETCH_INTERCEPTOR_ORDER,
|
|
1282
|
+
tt as FetchExchange,
|
|
1283
|
+
ut as FetchInterceptor,
|
|
1283
1284
|
O as FetchTimeoutError,
|
|
1284
1285
|
D as Fetcher,
|
|
1285
|
-
|
|
1286
|
+
p as FetcherError,
|
|
1286
1287
|
dt as FetcherRegistrar,
|
|
1287
1288
|
i as HttpMethod,
|
|
1288
|
-
|
|
1289
|
-
|
|
1289
|
+
b as HttpStatusValidationError,
|
|
1290
|
+
Rt as InterceptorManager,
|
|
1290
1291
|
m as InterceptorRegistry,
|
|
1291
|
-
|
|
1292
|
+
Q as JsonResultExtractor,
|
|
1292
1293
|
pt as NamedFetcher,
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1294
|
+
st as REQUEST_BODY_INTERCEPTOR_NAME,
|
|
1295
|
+
ot as REQUEST_BODY_INTERCEPTOR_ORDER,
|
|
1296
|
+
nt as RequestBodyInterceptor,
|
|
1297
|
+
J as ResponseResultExtractor,
|
|
1298
|
+
q as ResultExtractors,
|
|
1299
|
+
Y as TextResultExtractor,
|
|
1300
|
+
et as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
1300
1301
|
C as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
1301
1302
|
P as UriTemplateResolver,
|
|
1302
1303
|
$ as UrlBuilder,
|
|
1303
|
-
|
|
1304
|
+
rt as UrlResolveInterceptor,
|
|
1304
1305
|
M as UrlTemplateStyle,
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1306
|
+
ht as VALIDATE_STATUS_INTERCEPTOR_NAME,
|
|
1307
|
+
lt as VALIDATE_STATUS_INTERCEPTOR_ORDER,
|
|
1308
|
+
Et as ValidateStatusInterceptor,
|
|
1308
1309
|
B as combineURLs,
|
|
1309
1310
|
j as expressUrlTemplateResolver,
|
|
1310
1311
|
mt as fetcher,
|
|
@@ -1312,7 +1313,7 @@ export {
|
|
|
1312
1313
|
ft as getFetcher,
|
|
1313
1314
|
G as getUrlTemplateResolver,
|
|
1314
1315
|
L as isAbsoluteURL,
|
|
1315
|
-
|
|
1316
|
+
Z as mergeRecordToMap,
|
|
1316
1317
|
S as mergeRecords,
|
|
1317
1318
|
Tt as mergeRequest,
|
|
1318
1319
|
A as mergeRequestOptions,
|