@ahoo-wang/fetcher 2.9.1 → 2.9.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/fetcher.d.ts +21 -0
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js +49 -25
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/fetcher.d.ts
CHANGED
|
@@ -80,6 +80,27 @@ export declare class Fetcher implements UrlBuilderCapable, RequestHeadersCapable
|
|
|
80
80
|
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
81
81
|
*/
|
|
82
82
|
constructor(options?: FetcherOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Resolves a FetchRequest and RequestOptions into a FetchExchange object.
|
|
85
|
+
*
|
|
86
|
+
* This internal method prepares a complete FetchExchange by merging headers,
|
|
87
|
+
* resolving timeout settings, and combining request options. It serves as the
|
|
88
|
+
* preparation step before passing the exchange through the interceptor chain.
|
|
89
|
+
*
|
|
90
|
+
* The resolution process includes:
|
|
91
|
+
* - Merging default headers with request-level headers (request headers take precedence)
|
|
92
|
+
* - Resolving timeout settings (request timeout takes precedence over fetcher timeout)
|
|
93
|
+
* - Merging request options with defaults
|
|
94
|
+
* - Creating the final FetchExchange object with all resolved configuration
|
|
95
|
+
*
|
|
96
|
+
* @param request - The HTTP request configuration to resolve
|
|
97
|
+
* @param options - Optional request options including result extractor and attributes
|
|
98
|
+
* @returns A new FetchExchange object with fully resolved configuration
|
|
99
|
+
*
|
|
100
|
+
* @internal This method is used internally by the exchange method and should not
|
|
101
|
+
* be called directly by external consumers.
|
|
102
|
+
*/
|
|
103
|
+
resolveExchange(request: FetchRequest, options?: RequestOptions): FetchExchange;
|
|
83
104
|
/**
|
|
84
105
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
85
106
|
*
|
package/dist/fetcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EACL,cAAc,EAGd,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAoB,MAAM,mBAAmB,CAAC;AAG7E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cACf,SAAQ,cAAc,EACpB,qBAAqB,EACrB,cAAc;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;OAGG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC;AAMD,eAAO,MAAM,eAAe,EAAE,cAG7B,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cACf,SAAQ,iBAAiB,EACvB,sBAAsB;
|
|
1
|
+
{"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../src/fetcher.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EACL,cAAc,EAGd,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO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AAE,QAAQ,CAAM,EAC9C,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb;;;;;;;;;;;;;;;;OAgBG;IACG,IAAI,CAAC,CAAC,GAAG,QAAQ,EACrB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAM,EACvD,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb;;;;;;;;;;;;;;;;OAgBG;IACG,OAAO,CAAC,CAAC,GAAG,QAAQ,EACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAM,EACvD,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;IAIb;;;;;;;;;;;;;;OAcG;IACG,KAAK,CAAC,CAAC,GAAG,QAAQ,EACtB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,MAAM,CAAM,EACvD,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,CAAC;CAGd"}
|
package/dist/index.es.js
CHANGED
|
@@ -435,10 +435,10 @@ const c = "Content-Type", d = class d {
|
|
|
435
435
|
};
|
|
436
436
|
d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
|
|
437
437
|
let R = d;
|
|
438
|
-
const st = "UrlResolveInterceptor",
|
|
438
|
+
const st = "UrlResolveInterceptor", v = Number.MIN_SAFE_INTEGER + 1e3;
|
|
439
439
|
class ot {
|
|
440
440
|
constructor() {
|
|
441
|
-
this.name = st, this.order =
|
|
441
|
+
this.name = st, this.order = v;
|
|
442
442
|
}
|
|
443
443
|
/**
|
|
444
444
|
* Resolves the final URL by combining the base URL, path parameters, and query parameters.
|
|
@@ -450,7 +450,7 @@ class ot {
|
|
|
450
450
|
r.url = t.fetcher.urlBuilder.resolveRequestUrl(r);
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
const nt = "RequestBodyInterceptor", it =
|
|
453
|
+
const nt = "RequestBodyInterceptor", it = v + 1e3;
|
|
454
454
|
class ut {
|
|
455
455
|
constructor() {
|
|
456
456
|
this.name = nt, this.order = it;
|
|
@@ -560,12 +560,12 @@ class ht {
|
|
|
560
560
|
t.response = await J(t.request);
|
|
561
561
|
}
|
|
562
562
|
}
|
|
563
|
-
const
|
|
564
|
-
function
|
|
565
|
-
return (e.order ??
|
|
563
|
+
const x = 0;
|
|
564
|
+
function N(e, t) {
|
|
565
|
+
return (e.order ?? x) - (t.order ?? x);
|
|
566
566
|
}
|
|
567
567
|
function f(e, t) {
|
|
568
|
-
return t ? e.filter(t).sort(
|
|
568
|
+
return t ? e.filter(t).sort(N) : [...e].sort(N);
|
|
569
569
|
}
|
|
570
570
|
class m {
|
|
571
571
|
/**
|
|
@@ -847,16 +847,16 @@ function mt(e, t) {
|
|
|
847
847
|
}
|
|
848
848
|
function A(e, t) {
|
|
849
849
|
return t && t.resultExtractor && t.attributes ? t : {
|
|
850
|
-
resultExtractor: t?.resultExtractor ?? e?.resultExtractor ??
|
|
850
|
+
resultExtractor: t?.resultExtractor ?? e?.resultExtractor ?? L.resultExtractor,
|
|
851
851
|
attributes: t?.attributes ?? e?.attributes
|
|
852
852
|
};
|
|
853
853
|
}
|
|
854
854
|
const w = {
|
|
855
855
|
[c]: R.APPLICATION_JSON
|
|
856
|
-
},
|
|
856
|
+
}, D = {
|
|
857
857
|
baseURL: "",
|
|
858
858
|
headers: w
|
|
859
|
-
},
|
|
859
|
+
}, L = {
|
|
860
860
|
resultExtractor: q.Exchange
|
|
861
861
|
}, F = {
|
|
862
862
|
resultExtractor: q.Response
|
|
@@ -875,20 +875,30 @@ class B {
|
|
|
875
875
|
* @param options.urlTemplateStyle - Style for URL template parameter interpolation.
|
|
876
876
|
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
877
877
|
*/
|
|
878
|
-
constructor(t =
|
|
878
|
+
constructor(t = D) {
|
|
879
879
|
this.headers = w, this.urlBuilder = new V(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? w, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new pt();
|
|
880
880
|
}
|
|
881
881
|
/**
|
|
882
|
-
*
|
|
882
|
+
* Resolves a FetchRequest and RequestOptions into a FetchExchange object.
|
|
883
883
|
*
|
|
884
|
-
* This method
|
|
885
|
-
*
|
|
884
|
+
* This internal method prepares a complete FetchExchange by merging headers,
|
|
885
|
+
* resolving timeout settings, and combining request options. It serves as the
|
|
886
|
+
* preparation step before passing the exchange through the interceptor chain.
|
|
886
887
|
*
|
|
887
|
-
*
|
|
888
|
+
* The resolution process includes:
|
|
889
|
+
* - Merging default headers with request-level headers (request headers take precedence)
|
|
890
|
+
* - Resolving timeout settings (request timeout takes precedence over fetcher timeout)
|
|
891
|
+
* - Merging request options with defaults
|
|
892
|
+
* - Creating the final FetchExchange object with all resolved configuration
|
|
893
|
+
*
|
|
894
|
+
* @param request - The HTTP request configuration to resolve
|
|
888
895
|
* @param options - Optional request options including result extractor and attributes
|
|
889
|
-
* @returns
|
|
896
|
+
* @returns A new FetchExchange object with fully resolved configuration
|
|
897
|
+
*
|
|
898
|
+
* @internal This method is used internally by the exchange method and should not
|
|
899
|
+
* be called directly by external consumers.
|
|
890
900
|
*/
|
|
891
|
-
|
|
901
|
+
resolveExchange(t, r) {
|
|
892
902
|
const s = {
|
|
893
903
|
...this.headers,
|
|
894
904
|
...t.headers
|
|
@@ -897,15 +907,29 @@ class B {
|
|
|
897
907
|
headers: s,
|
|
898
908
|
timeout: k(t.timeout, this.timeout)
|
|
899
909
|
}, { resultExtractor: n, attributes: u } = A(
|
|
900
|
-
|
|
910
|
+
L,
|
|
901
911
|
r
|
|
902
|
-
)
|
|
912
|
+
);
|
|
913
|
+
return new rt({
|
|
903
914
|
fetcher: this,
|
|
904
915
|
request: o,
|
|
905
916
|
resultExtractor: n,
|
|
906
917
|
attributes: u
|
|
907
918
|
});
|
|
908
|
-
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
922
|
+
*
|
|
923
|
+
* This method creates a FetchExchange object and passes it through the interceptor chain.
|
|
924
|
+
* It handles header merging, timeout resolution, and result extractor configuration.
|
|
925
|
+
*
|
|
926
|
+
* @param request - The HTTP request configuration to process
|
|
927
|
+
* @param options - Optional request options including result extractor and attributes
|
|
928
|
+
* @returns Promise that resolves to the processed FetchExchange object
|
|
929
|
+
*/
|
|
930
|
+
async exchange(t, r) {
|
|
931
|
+
const s = this.resolveExchange(t, r);
|
|
932
|
+
return await this.interceptors.exchange(s);
|
|
909
933
|
}
|
|
910
934
|
/**
|
|
911
935
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -1263,7 +1287,7 @@ class ft extends B {
|
|
|
1263
1287
|
* headers: { 'Authorization': 'Bearer token' }
|
|
1264
1288
|
* });
|
|
1265
1289
|
*/
|
|
1266
|
-
constructor(t, r =
|
|
1290
|
+
constructor(t, r = D) {
|
|
1267
1291
|
super(r), this.name = t, O.register(t, this);
|
|
1268
1292
|
}
|
|
1269
1293
|
}
|
|
@@ -1276,8 +1300,8 @@ export {
|
|
|
1276
1300
|
R as ContentTypeValues,
|
|
1277
1301
|
g as DEFAULT_FETCHER_NAME,
|
|
1278
1302
|
F as DEFAULT_FETCH_OPTIONS,
|
|
1279
|
-
|
|
1280
|
-
|
|
1303
|
+
D as DEFAULT_OPTIONS,
|
|
1304
|
+
L as DEFAULT_REQUEST_OPTIONS,
|
|
1281
1305
|
E as ExchangeError,
|
|
1282
1306
|
Q as ExchangeResultExtractor,
|
|
1283
1307
|
y as ExpressUrlTemplateResolver,
|
|
@@ -1302,7 +1326,7 @@ export {
|
|
|
1302
1326
|
q as ResultExtractors,
|
|
1303
1327
|
K as TextResultExtractor,
|
|
1304
1328
|
st as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
1305
|
-
|
|
1329
|
+
v as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
1306
1330
|
P as UriTemplateResolver,
|
|
1307
1331
|
V as UrlBuilder,
|
|
1308
1332
|
ot as UrlResolveInterceptor,
|
|
@@ -1322,7 +1346,7 @@ export {
|
|
|
1322
1346
|
mt as mergeRequest,
|
|
1323
1347
|
A as mergeRequestOptions,
|
|
1324
1348
|
k as resolveTimeout,
|
|
1325
|
-
|
|
1349
|
+
N as sortOrder,
|
|
1326
1350
|
J as timeoutFetch,
|
|
1327
1351
|
f as toSorted,
|
|
1328
1352
|
$ as uriTemplateResolver,
|