@ahoo-wang/fetcher 2.11.2 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function
|
|
1
|
+
function G(e) {
|
|
2
2
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return
|
|
4
|
+
function M(e, t) {
|
|
5
|
+
return G(t) ? t : t ? e.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : e;
|
|
6
6
|
}
|
|
7
7
|
var H = /* @__PURE__ */ ((e) => (e[e.UriTemplate = 0] = "UriTemplate", e[e.Express = 1] = "Express", e))(H || {});
|
|
8
8
|
function j(e) {
|
|
9
|
-
return e === 1 ?
|
|
9
|
+
return e === 1 ? V : $;
|
|
10
10
|
}
|
|
11
11
|
function C(e, t, r) {
|
|
12
12
|
return r ? e.replace(t, (s, o) => {
|
|
@@ -167,8 +167,8 @@ const $ = new P(), l = class l {
|
|
|
167
167
|
};
|
|
168
168
|
l.PATH_PARAM_REGEX = /:([^/]+)/g;
|
|
169
169
|
let y = l;
|
|
170
|
-
const
|
|
171
|
-
class
|
|
170
|
+
const V = new y();
|
|
171
|
+
class X {
|
|
172
172
|
/**
|
|
173
173
|
* Initializes a new UrlBuilder instance.
|
|
174
174
|
*
|
|
@@ -208,7 +208,7 @@ class V {
|
|
|
208
208
|
* ```
|
|
209
209
|
*/
|
|
210
210
|
build(t, r) {
|
|
211
|
-
const s = r?.path, o = r?.query, n =
|
|
211
|
+
const s = r?.path, o = r?.query, n = M(this.baseURL, t);
|
|
212
212
|
let u = this.urlTemplateResolver.resolve(n, s);
|
|
213
213
|
if (o) {
|
|
214
214
|
const a = new URLSearchParams(o).toString();
|
|
@@ -253,7 +253,7 @@ class E extends p {
|
|
|
253
253
|
super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, E.prototype);
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
|
-
class
|
|
256
|
+
class O extends p {
|
|
257
257
|
/**
|
|
258
258
|
* Creates a new FetchTimeoutError instance.
|
|
259
259
|
*
|
|
@@ -261,7 +261,7 @@ class _ extends p {
|
|
|
261
261
|
*/
|
|
262
262
|
constructor(t) {
|
|
263
263
|
const r = t.method || "GET", s = `Request timeout of ${t.timeout}ms exceeded for ${r} ${t.url}`;
|
|
264
|
-
super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this,
|
|
264
|
+
super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this, O.prototype);
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
function k(e, t) {
|
|
@@ -279,8 +279,8 @@ async function J(e) {
|
|
|
279
279
|
const u = new Promise((a, T) => {
|
|
280
280
|
n = setTimeout(() => {
|
|
281
281
|
n && clearTimeout(n);
|
|
282
|
-
const
|
|
283
|
-
o.abort(
|
|
282
|
+
const b = new O(e);
|
|
283
|
+
o.abort(b), T(b);
|
|
284
284
|
}, r);
|
|
285
285
|
});
|
|
286
286
|
try {
|
|
@@ -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", D = Number.MIN_SAFE_INTEGER + 1e3;
|
|
439
439
|
class ot {
|
|
440
440
|
constructor() {
|
|
441
|
-
this.name = st, this.order =
|
|
441
|
+
this.name = st, this.order = D;
|
|
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 = D + 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 N = 0;
|
|
564
|
+
function x(e, t) {
|
|
565
|
+
return (e.order ?? N) - (t.order ?? N);
|
|
566
566
|
}
|
|
567
567
|
function f(e, t) {
|
|
568
|
-
return t ? e.filter(t).sort(
|
|
568
|
+
return t ? e.filter(t).sort(x) : [...e].sort(x);
|
|
569
569
|
}
|
|
570
570
|
class m {
|
|
571
571
|
/**
|
|
@@ -660,16 +660,16 @@ class m {
|
|
|
660
660
|
await r.intercept(t);
|
|
661
661
|
}
|
|
662
662
|
}
|
|
663
|
-
class
|
|
663
|
+
class I extends E {
|
|
664
664
|
constructor(t) {
|
|
665
665
|
super(
|
|
666
666
|
t,
|
|
667
667
|
`Request failed with status code ${t.response?.status} for ${t.request.url}`
|
|
668
|
-
), this.name = "HttpStatusValidationError", Object.setPrototypeOf(this,
|
|
668
|
+
), this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, I.prototype);
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
|
-
const lt = (e) => e >= 200 && e < 300, Et = "ValidateStatusInterceptor", Rt = Number.MAX_SAFE_INTEGER - 1e3;
|
|
672
|
-
class
|
|
671
|
+
const lt = (e) => e >= 200 && e < 300, Et = "ValidateStatusInterceptor", Rt = Number.MAX_SAFE_INTEGER - 1e3, dt = "__ignoreValidateStatus__";
|
|
672
|
+
class pt {
|
|
673
673
|
/**
|
|
674
674
|
* Creates a new ValidateStatusInterceptor instance.
|
|
675
675
|
*
|
|
@@ -706,23 +706,26 @@ class dt {
|
|
|
706
706
|
* are caught and converted to HttpStatusValidationError early in the pipeline,
|
|
707
707
|
* preventing other response handlers from attempting to process them. Valid responses
|
|
708
708
|
* proceed through the rest of the response interceptor chain normally.
|
|
709
|
+
*
|
|
710
|
+
* If the exchange attributes contain IGNORE_VALIDATE_STATUS set to true, status
|
|
711
|
+
* validation is skipped entirely, allowing any response status to pass through.
|
|
709
712
|
*/
|
|
710
713
|
intercept(t) {
|
|
711
|
-
if (!t.response)
|
|
714
|
+
if (t.attributes.get(dt) === !0 || !t.response)
|
|
712
715
|
return;
|
|
713
716
|
const r = t.response.status;
|
|
714
717
|
if (!this.validateStatus(r))
|
|
715
|
-
throw new
|
|
718
|
+
throw new I(t);
|
|
716
719
|
}
|
|
717
720
|
}
|
|
718
|
-
class
|
|
721
|
+
class Tt {
|
|
719
722
|
constructor() {
|
|
720
723
|
this.request = new m([
|
|
721
724
|
new ot(),
|
|
722
725
|
new ut(),
|
|
723
726
|
new ht()
|
|
724
727
|
]), this.response = new m([
|
|
725
|
-
new
|
|
728
|
+
new pt()
|
|
726
729
|
]), this.error = new m();
|
|
727
730
|
}
|
|
728
731
|
/**
|
|
@@ -821,7 +824,7 @@ class pt {
|
|
|
821
824
|
}
|
|
822
825
|
}
|
|
823
826
|
}
|
|
824
|
-
function
|
|
827
|
+
function At(e, t) {
|
|
825
828
|
if (Object.keys(e).length === 0)
|
|
826
829
|
return t;
|
|
827
830
|
if (Object.keys(t).length === 0)
|
|
@@ -851,11 +854,11 @@ function A(e, t) {
|
|
|
851
854
|
attributes: t?.attributes ?? e?.attributes
|
|
852
855
|
};
|
|
853
856
|
}
|
|
854
|
-
const
|
|
857
|
+
const _ = {
|
|
855
858
|
[c]: R.APPLICATION_JSON
|
|
856
|
-
},
|
|
859
|
+
}, v = {
|
|
857
860
|
baseURL: "",
|
|
858
|
-
headers:
|
|
861
|
+
headers: _
|
|
859
862
|
}, L = {
|
|
860
863
|
resultExtractor: q.Exchange
|
|
861
864
|
}, F = {
|
|
@@ -875,8 +878,8 @@ class B {
|
|
|
875
878
|
* @param options.urlTemplateStyle - Style for URL template parameter interpolation.
|
|
876
879
|
* @param options.interceptors - Interceptor manager for processing requests and responses.
|
|
877
880
|
*/
|
|
878
|
-
constructor(t =
|
|
879
|
-
this.headers =
|
|
881
|
+
constructor(t = v) {
|
|
882
|
+
this.headers = _, this.urlBuilder = new X(t.baseURL, t.urlTemplateStyle), this.headers = t.headers ?? _, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new Tt();
|
|
880
883
|
}
|
|
881
884
|
/**
|
|
882
885
|
* Resolves a FetchRequest and RequestOptions into a FetchExchange object.
|
|
@@ -1164,8 +1167,8 @@ class B {
|
|
|
1164
1167
|
return await this.methodFetch(i.TRACE, t, r, s);
|
|
1165
1168
|
}
|
|
1166
1169
|
}
|
|
1167
|
-
const
|
|
1168
|
-
class
|
|
1170
|
+
const w = "default";
|
|
1171
|
+
class ft {
|
|
1169
1172
|
constructor() {
|
|
1170
1173
|
this.registrar = /* @__PURE__ */ new Map();
|
|
1171
1174
|
}
|
|
@@ -1238,7 +1241,7 @@ class Tt {
|
|
|
1238
1241
|
* const defaultFetcher = fetcherRegistrar.default;
|
|
1239
1242
|
*/
|
|
1240
1243
|
get default() {
|
|
1241
|
-
return this.requiredGet(
|
|
1244
|
+
return this.requiredGet(w);
|
|
1242
1245
|
}
|
|
1243
1246
|
/**
|
|
1244
1247
|
* Set the default Fetcher instance
|
|
@@ -1249,7 +1252,7 @@ class Tt {
|
|
|
1249
1252
|
* fetcherRegistrar.default = fetcher;
|
|
1250
1253
|
*/
|
|
1251
1254
|
set default(t) {
|
|
1252
|
-
this.register(
|
|
1255
|
+
this.register(w, t);
|
|
1253
1256
|
}
|
|
1254
1257
|
/**
|
|
1255
1258
|
* Get a copy of all registered fetchers
|
|
@@ -1265,11 +1268,11 @@ class Tt {
|
|
|
1265
1268
|
return new Map(this.registrar);
|
|
1266
1269
|
}
|
|
1267
1270
|
}
|
|
1268
|
-
const
|
|
1269
|
-
function
|
|
1270
|
-
return e ? e instanceof B ? e :
|
|
1271
|
+
const g = new ft();
|
|
1272
|
+
function Pt(e, t) {
|
|
1273
|
+
return e ? e instanceof B ? e : g.requiredGet(e) : t ?? g.default;
|
|
1271
1274
|
}
|
|
1272
|
-
class
|
|
1275
|
+
class mt extends B {
|
|
1273
1276
|
/**
|
|
1274
1277
|
* Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
|
|
1275
1278
|
*
|
|
@@ -1287,20 +1290,20 @@ class ft extends B {
|
|
|
1287
1290
|
* headers: { 'Authorization': 'Bearer token' }
|
|
1288
1291
|
* });
|
|
1289
1292
|
*/
|
|
1290
|
-
constructor(t, r =
|
|
1291
|
-
super(r), this.name = t,
|
|
1293
|
+
constructor(t, r = v) {
|
|
1294
|
+
super(r), this.name = t, g.register(t, this);
|
|
1292
1295
|
}
|
|
1293
1296
|
}
|
|
1294
|
-
const
|
|
1297
|
+
const yt = new mt(w);
|
|
1295
1298
|
export {
|
|
1296
1299
|
Z as ArrayBufferResultExtractor,
|
|
1297
1300
|
W as BlobResultExtractor,
|
|
1298
1301
|
tt as BytesResultExtractor,
|
|
1299
1302
|
c as CONTENT_TYPE_HEADER,
|
|
1300
1303
|
R as ContentTypeValues,
|
|
1301
|
-
|
|
1304
|
+
w as DEFAULT_FETCHER_NAME,
|
|
1302
1305
|
F as DEFAULT_FETCH_OPTIONS,
|
|
1303
|
-
|
|
1306
|
+
v as DEFAULT_OPTIONS,
|
|
1304
1307
|
L as DEFAULT_REQUEST_OPTIONS,
|
|
1305
1308
|
E as ExchangeError,
|
|
1306
1309
|
Q as ExchangeResultExtractor,
|
|
@@ -1309,16 +1312,17 @@ export {
|
|
|
1309
1312
|
ct as FETCH_INTERCEPTOR_ORDER,
|
|
1310
1313
|
rt as FetchExchange,
|
|
1311
1314
|
ht as FetchInterceptor,
|
|
1312
|
-
|
|
1315
|
+
O as FetchTimeoutError,
|
|
1313
1316
|
B as Fetcher,
|
|
1314
1317
|
p as FetcherError,
|
|
1315
|
-
|
|
1318
|
+
ft as FetcherRegistrar,
|
|
1316
1319
|
i as HttpMethod,
|
|
1317
|
-
|
|
1318
|
-
|
|
1320
|
+
I as HttpStatusValidationError,
|
|
1321
|
+
dt as IGNORE_VALIDATE_STATUS,
|
|
1322
|
+
Tt as InterceptorManager,
|
|
1319
1323
|
m as InterceptorRegistry,
|
|
1320
1324
|
z as JsonResultExtractor,
|
|
1321
|
-
|
|
1325
|
+
mt as NamedFetcher,
|
|
1322
1326
|
nt as REQUEST_BODY_INTERCEPTOR_NAME,
|
|
1323
1327
|
it as REQUEST_BODY_INTERCEPTOR_ORDER,
|
|
1324
1328
|
ut as RequestBodyInterceptor,
|
|
@@ -1326,27 +1330,27 @@ export {
|
|
|
1326
1330
|
q as ResultExtractors,
|
|
1327
1331
|
K as TextResultExtractor,
|
|
1328
1332
|
st as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
1329
|
-
|
|
1333
|
+
D as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
1330
1334
|
P as UriTemplateResolver,
|
|
1331
|
-
|
|
1335
|
+
X as UrlBuilder,
|
|
1332
1336
|
ot as UrlResolveInterceptor,
|
|
1333
1337
|
H as UrlTemplateStyle,
|
|
1334
1338
|
Et as VALIDATE_STATUS_INTERCEPTOR_NAME,
|
|
1335
1339
|
Rt as VALIDATE_STATUS_INTERCEPTOR_ORDER,
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1340
|
+
pt as ValidateStatusInterceptor,
|
|
1341
|
+
M as combineURLs,
|
|
1342
|
+
V as expressUrlTemplateResolver,
|
|
1343
|
+
yt as fetcher,
|
|
1344
|
+
g as fetcherRegistrar,
|
|
1345
|
+
Pt as getFetcher,
|
|
1342
1346
|
j as getUrlTemplateResolver,
|
|
1343
|
-
|
|
1347
|
+
G as isAbsoluteURL,
|
|
1344
1348
|
et as mergeRecordToMap,
|
|
1345
1349
|
S as mergeRecords,
|
|
1346
|
-
|
|
1350
|
+
At as mergeRequest,
|
|
1347
1351
|
A as mergeRequestOptions,
|
|
1348
1352
|
k as resolveTimeout,
|
|
1349
|
-
|
|
1353
|
+
x as sortOrder,
|
|
1350
1354
|
J as timeoutFetch,
|
|
1351
1355
|
f as toSorted,
|
|
1352
1356
|
$ as uriTemplateResolver,
|