@ahoo-wang/fetcher 1.0.6 → 1.1.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/fetchRequest.d.ts +5 -5
- package/dist/fetchRequest.d.ts.map +1 -1
- package/dist/index.es.js +209 -207
- 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/index.es.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
function g(r) {
|
|
2
2
|
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(r);
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
return g(
|
|
4
|
+
function b(r, t) {
|
|
5
|
+
return g(t) ? t : t ? r.replace(/\/?\/$/, "") + "/" + t.replace(/^\/+/, "") : r;
|
|
6
6
|
}
|
|
7
|
-
class
|
|
7
|
+
class S {
|
|
8
8
|
/**
|
|
9
9
|
* Initializes a new UrlBuilder instance.
|
|
10
10
|
*
|
|
@@ -15,8 +15,8 @@ class b {
|
|
|
15
15
|
* const urlBuilder = new UrlBuilder('https://api.example.com');
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
19
|
-
this.baseURL =
|
|
18
|
+
constructor(t) {
|
|
19
|
+
this.baseURL = t;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Builds a complete URL, including path parameter replacement and query parameter addition.
|
|
@@ -36,8 +36,8 @@ class b {
|
|
|
36
36
|
* // Result: https://api.example.com/users/123/posts/456?filter=active&limit=10
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
build(
|
|
40
|
-
const s =
|
|
39
|
+
build(t, e) {
|
|
40
|
+
const s = e?.path, o = e?.query, i = b(this.baseURL, t);
|
|
41
41
|
let n = this.interpolateUrl(i, s);
|
|
42
42
|
if (o) {
|
|
43
43
|
const u = new URLSearchParams(o).toString();
|
|
@@ -54,8 +54,8 @@ class b {
|
|
|
54
54
|
* @param request - The FetchRequest containing URL and URL parameters
|
|
55
55
|
* @returns Complete resolved URL string
|
|
56
56
|
*/
|
|
57
|
-
resolveRequestUrl(
|
|
58
|
-
return this.build(
|
|
57
|
+
resolveRequestUrl(t) {
|
|
58
|
+
return this.build(t.url, t.urlParams);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Replaces placeholders in the URL with path parameters.
|
|
@@ -84,13 +84,13 @@ class b {
|
|
|
84
84
|
* }
|
|
85
85
|
* ```
|
|
86
86
|
*/
|
|
87
|
-
interpolateUrl(
|
|
88
|
-
return
|
|
89
|
-
const i =
|
|
87
|
+
interpolateUrl(t, e) {
|
|
88
|
+
return e ? t.replace(/{([^}]+)}/g, (s, o) => {
|
|
89
|
+
const i = e[o];
|
|
90
90
|
if (i === void 0)
|
|
91
91
|
throw new Error(`Missing required path parameter: ${o}`);
|
|
92
92
|
return String(i);
|
|
93
|
-
}) :
|
|
93
|
+
}) : t;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
class a extends Error {
|
|
@@ -100,69 +100,71 @@ class a extends Error {
|
|
|
100
100
|
* @param errorMsg - Optional error message. If not provided, will use the cause's message or a default message.
|
|
101
101
|
* @param cause - Optional underlying error that caused this error.
|
|
102
102
|
*/
|
|
103
|
-
constructor(
|
|
104
|
-
const s =
|
|
105
|
-
super(s), this.cause =
|
|
103
|
+
constructor(t, e) {
|
|
104
|
+
const s = t || e?.message || "An error occurred in the fetcher";
|
|
105
|
+
super(s), this.cause = e, this.name = "FetcherError", e?.stack && (this.stack = e.stack), Object.setPrototypeOf(this, a.prototype);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
class
|
|
108
|
+
class R extends a {
|
|
109
109
|
/**
|
|
110
110
|
* Creates a new FetchTimeoutError instance.
|
|
111
111
|
*
|
|
112
112
|
* @param request - The request options that timed out
|
|
113
113
|
*/
|
|
114
|
-
constructor(
|
|
115
|
-
const
|
|
116
|
-
super(s), this.name = "FetchTimeoutError", this.request =
|
|
114
|
+
constructor(t) {
|
|
115
|
+
const e = t.method || "GET", s = `Request timeout of ${t.timeout}ms exceeded for ${e} ${t.url}`;
|
|
116
|
+
super(s), this.name = "FetchTimeoutError", this.request = t, Object.setPrototypeOf(this, R.prototype);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
return typeof r < "u" ? r :
|
|
119
|
+
function _(r, t) {
|
|
120
|
+
return typeof r < "u" ? r : t;
|
|
121
121
|
}
|
|
122
|
-
async function
|
|
123
|
-
const
|
|
124
|
-
if (!
|
|
125
|
-
return fetch(
|
|
122
|
+
async function w(r) {
|
|
123
|
+
const t = r.url, e = r.timeout, s = r;
|
|
124
|
+
if (!e)
|
|
125
|
+
return fetch(t, s);
|
|
126
126
|
const o = new AbortController(), i = {
|
|
127
127
|
...s,
|
|
128
128
|
signal: o.signal
|
|
129
129
|
};
|
|
130
130
|
let n = null;
|
|
131
|
-
const u = new Promise((
|
|
131
|
+
const u = new Promise((Y, P) => {
|
|
132
132
|
n = setTimeout(() => {
|
|
133
133
|
n && clearTimeout(n);
|
|
134
|
-
const
|
|
135
|
-
o.abort(
|
|
136
|
-
},
|
|
134
|
+
const y = new R(r);
|
|
135
|
+
o.abort(y), P(y);
|
|
136
|
+
}, e);
|
|
137
137
|
});
|
|
138
138
|
try {
|
|
139
|
-
return await Promise.race([fetch(
|
|
139
|
+
return await Promise.race([fetch(t, i), u]);
|
|
140
140
|
} finally {
|
|
141
141
|
n && clearTimeout(n);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const
|
|
145
|
-
class
|
|
144
|
+
const N = "UrlResolveInterceptor", O = Number.MIN_SAFE_INTEGER + 1e3;
|
|
145
|
+
class F {
|
|
146
146
|
constructor() {
|
|
147
|
-
this.name =
|
|
147
|
+
this.name = N, this.order = O;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Resolves the final URL by combining the base URL, path parameters, and query parameters.
|
|
151
151
|
*
|
|
152
152
|
* @param exchange - The fetch exchange containing the request information
|
|
153
153
|
*/
|
|
154
|
-
intercept(
|
|
155
|
-
const
|
|
156
|
-
|
|
154
|
+
intercept(t) {
|
|
155
|
+
const e = t.request;
|
|
156
|
+
e.url = t.fetcher.urlBuilder.resolveRequestUrl(e);
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
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 || {});
|
|
160
|
-
const z = "Content-Type"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
const z = "Content-Type", d = class d {
|
|
161
|
+
};
|
|
162
|
+
d.APPLICATION_JSON = "application/json", d.TEXT_EVENT_STREAM = "text/event-stream";
|
|
163
|
+
let h = d;
|
|
164
|
+
const q = "RequestBodyInterceptor", U = O + 1e3;
|
|
165
|
+
class D {
|
|
164
166
|
constructor() {
|
|
165
|
-
this.name =
|
|
167
|
+
this.name = q, this.order = U;
|
|
166
168
|
}
|
|
167
169
|
/**
|
|
168
170
|
* Attempts to convert request body to a valid fetch API body type.
|
|
@@ -201,21 +203,21 @@ class U {
|
|
|
201
203
|
* // exchange.request.body will be '{"name":"John","age":30}'
|
|
202
204
|
* // exchange.request.headers will include 'Content-Type: application/json'
|
|
203
205
|
*/
|
|
204
|
-
intercept(
|
|
205
|
-
const
|
|
206
|
-
if (
|
|
207
|
-
|
|
206
|
+
intercept(t) {
|
|
207
|
+
const e = t.request;
|
|
208
|
+
if (e.body === void 0 || e.body === null || typeof e.body != "object" || e.body instanceof ArrayBuffer || ArrayBuffer.isView(e.body) || // Includes TypedArray and DataView
|
|
209
|
+
e.body instanceof Blob || e.body instanceof File || e.body instanceof URLSearchParams || e.body instanceof FormData || e.body instanceof ReadableStream)
|
|
208
210
|
return;
|
|
209
|
-
const s = { ...
|
|
210
|
-
s.body = JSON.stringify(
|
|
211
|
+
const s = { ...e };
|
|
212
|
+
s.body = JSON.stringify(e.body), s.headers || (s.headers = {});
|
|
211
213
|
const o = s.headers;
|
|
212
|
-
o["Content-Type"] || (o["Content-Type"] =
|
|
214
|
+
o["Content-Type"] || (o["Content-Type"] = h.APPLICATION_JSON), t.request = s;
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
|
-
const
|
|
216
|
-
class
|
|
217
|
+
const L = "FetchInterceptor", C = Number.MAX_SAFE_INTEGER - 1e3;
|
|
218
|
+
class v {
|
|
217
219
|
constructor() {
|
|
218
|
-
this.name =
|
|
220
|
+
this.name = L, this.order = C;
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
223
|
* Intercept and process HTTP requests.
|
|
@@ -242,14 +244,14 @@ class D {
|
|
|
242
244
|
* await fetchInterceptor.intercept(exchange);
|
|
243
245
|
* console.log(exchange.response); // HTTP response object
|
|
244
246
|
*/
|
|
245
|
-
async intercept(
|
|
246
|
-
|
|
247
|
+
async intercept(t) {
|
|
248
|
+
t.response = await w(t.request);
|
|
247
249
|
}
|
|
248
250
|
}
|
|
249
|
-
function
|
|
250
|
-
return
|
|
251
|
+
function E(r, t) {
|
|
252
|
+
return t ? r.filter(t).sort((e, s) => e.order - s.order) : [...r].sort((e, s) => e.order - s.order);
|
|
251
253
|
}
|
|
252
|
-
class
|
|
254
|
+
class p {
|
|
253
255
|
/**
|
|
254
256
|
* Initializes a new InterceptorRegistry instance.
|
|
255
257
|
*
|
|
@@ -259,8 +261,8 @@ class l {
|
|
|
259
261
|
* The provided interceptors will be sorted by their order property immediately
|
|
260
262
|
* upon construction.
|
|
261
263
|
*/
|
|
262
|
-
constructor(
|
|
263
|
-
this.sortedInterceptors = [], this.sortedInterceptors =
|
|
264
|
+
constructor(t = []) {
|
|
265
|
+
this.sortedInterceptors = [], this.sortedInterceptors = E(t);
|
|
264
266
|
}
|
|
265
267
|
/**
|
|
266
268
|
* Gets the name of this interceptor registry.
|
|
@@ -297,10 +299,10 @@ class l {
|
|
|
297
299
|
*
|
|
298
300
|
* After adding, interceptors are automatically sorted by their order property.
|
|
299
301
|
*/
|
|
300
|
-
use(
|
|
301
|
-
return this.sortedInterceptors.some((
|
|
302
|
+
use(t) {
|
|
303
|
+
return this.sortedInterceptors.some((e) => e.name === t.name) ? !1 : (this.sortedInterceptors = E([
|
|
302
304
|
...this.sortedInterceptors,
|
|
303
|
-
|
|
305
|
+
t
|
|
304
306
|
]), !0);
|
|
305
307
|
}
|
|
306
308
|
/**
|
|
@@ -310,12 +312,12 @@ class l {
|
|
|
310
312
|
* @returns True if an interceptor was removed, false if no interceptor with the
|
|
311
313
|
* given name was found
|
|
312
314
|
*/
|
|
313
|
-
eject(
|
|
314
|
-
const
|
|
315
|
-
return this.sortedInterceptors =
|
|
316
|
-
|
|
317
|
-
(s) => s.name !==
|
|
318
|
-
),
|
|
315
|
+
eject(t) {
|
|
316
|
+
const e = this.sortedInterceptors;
|
|
317
|
+
return this.sortedInterceptors = E(
|
|
318
|
+
e,
|
|
319
|
+
(s) => s.name !== t
|
|
320
|
+
), e.length !== this.sortedInterceptors.length;
|
|
319
321
|
}
|
|
320
322
|
/**
|
|
321
323
|
* Removes all interceptors from this registry.
|
|
@@ -337,27 +339,27 @@ class l {
|
|
|
337
339
|
* If any interceptor throws an error, the execution chain is broken and the error
|
|
338
340
|
* is propagated to the caller.
|
|
339
341
|
*/
|
|
340
|
-
async intercept(
|
|
341
|
-
for (const
|
|
342
|
-
await
|
|
342
|
+
async intercept(t) {
|
|
343
|
+
for (const e of this.sortedInterceptors)
|
|
344
|
+
await e.intercept(t);
|
|
343
345
|
}
|
|
344
346
|
}
|
|
345
|
-
class
|
|
346
|
-
constructor(
|
|
347
|
+
class f extends a {
|
|
348
|
+
constructor(t) {
|
|
347
349
|
super(
|
|
348
|
-
`Request failed with status code ${
|
|
349
|
-
), this.exchange =
|
|
350
|
+
`Request failed with status code ${t.response?.status} for ${t.request.url}`
|
|
351
|
+
), this.exchange = t, this.name = "HttpStatusValidationError", Object.setPrototypeOf(this, f.prototype);
|
|
350
352
|
}
|
|
351
353
|
}
|
|
352
|
-
const
|
|
353
|
-
class
|
|
354
|
+
const B = (r) => r >= 200 && r < 300, G = "ValidateStatusInterceptor", M = Number.MAX_SAFE_INTEGER - 1e3;
|
|
355
|
+
class $ {
|
|
354
356
|
/**
|
|
355
357
|
* Creates a new ValidateStatusInterceptor instance.
|
|
356
358
|
*
|
|
357
359
|
* @param validateStatus - Function that determines if a status code is valid
|
|
358
360
|
*/
|
|
359
|
-
constructor(
|
|
360
|
-
this.validateStatus =
|
|
361
|
+
constructor(t = B) {
|
|
362
|
+
this.validateStatus = t;
|
|
361
363
|
}
|
|
362
364
|
/**
|
|
363
365
|
* Gets the name of this interceptor.
|
|
@@ -365,7 +367,7 @@ class M {
|
|
|
365
367
|
* @returns The name of this interceptor
|
|
366
368
|
*/
|
|
367
369
|
get name() {
|
|
368
|
-
return
|
|
370
|
+
return G;
|
|
369
371
|
}
|
|
370
372
|
/**
|
|
371
373
|
* Gets the order of this interceptor.
|
|
@@ -373,7 +375,7 @@ class M {
|
|
|
373
375
|
* @returns VALIDATE_STATUS_INTERCEPTOR_ORDER, indicating this interceptor should execute early
|
|
374
376
|
*/
|
|
375
377
|
get order() {
|
|
376
|
-
return
|
|
378
|
+
return M;
|
|
377
379
|
}
|
|
378
380
|
/**
|
|
379
381
|
* Validates the response status code.
|
|
@@ -388,35 +390,35 @@ class M {
|
|
|
388
390
|
* preventing other response handlers from attempting to process them. Valid responses
|
|
389
391
|
* proceed through the rest of the response interceptor chain normally.
|
|
390
392
|
*/
|
|
391
|
-
intercept(
|
|
392
|
-
if (!
|
|
393
|
+
intercept(t) {
|
|
394
|
+
if (!t.response)
|
|
393
395
|
return;
|
|
394
|
-
const
|
|
395
|
-
if (!this.validateStatus(
|
|
396
|
-
throw new
|
|
396
|
+
const e = t.response.status;
|
|
397
|
+
if (!this.validateStatus(e))
|
|
398
|
+
throw new f(t);
|
|
397
399
|
}
|
|
398
400
|
}
|
|
399
|
-
class
|
|
401
|
+
class l extends a {
|
|
400
402
|
/**
|
|
401
403
|
* Creates a new ExchangeError instance.
|
|
402
404
|
*
|
|
403
405
|
* @param exchange - The FetchExchange object containing request/response/error information.
|
|
404
406
|
* @param errorMsg - An optional error message.
|
|
405
407
|
*/
|
|
406
|
-
constructor(
|
|
407
|
-
const s =
|
|
408
|
-
super(s,
|
|
408
|
+
constructor(t, e) {
|
|
409
|
+
const s = e || t.error?.message || t.response?.statusText || `Request to ${t.request.url} failed during exchange`;
|
|
410
|
+
super(s, t.error), this.exchange = t, this.name = "ExchangeError", Object.setPrototypeOf(this, l.prototype);
|
|
409
411
|
}
|
|
410
412
|
}
|
|
411
|
-
class
|
|
413
|
+
class j {
|
|
412
414
|
constructor() {
|
|
413
|
-
this.request = new
|
|
414
|
-
new
|
|
415
|
-
new
|
|
416
|
-
new
|
|
417
|
-
]), this.response = new
|
|
418
|
-
new
|
|
419
|
-
]), this.error = new
|
|
415
|
+
this.request = new p([
|
|
416
|
+
new F(),
|
|
417
|
+
new D(),
|
|
418
|
+
new v()
|
|
419
|
+
]), this.response = new p([
|
|
420
|
+
new $()
|
|
421
|
+
]), this.error = new p();
|
|
420
422
|
}
|
|
421
423
|
/**
|
|
422
424
|
* Processes a FetchExchange through the interceptor pipeline.
|
|
@@ -504,19 +506,19 @@ class $ {
|
|
|
504
506
|
* const result = await fetcher.exchange(exchange);
|
|
505
507
|
* ```
|
|
506
508
|
*/
|
|
507
|
-
async exchange(
|
|
509
|
+
async exchange(t) {
|
|
508
510
|
try {
|
|
509
|
-
return await this.request.intercept(
|
|
510
|
-
} catch (
|
|
511
|
-
if (
|
|
512
|
-
return
|
|
513
|
-
throw new
|
|
511
|
+
return await this.request.intercept(t), await this.response.intercept(t), t;
|
|
512
|
+
} catch (e) {
|
|
513
|
+
if (t.error = e, await this.error.intercept(t), !t.hasError())
|
|
514
|
+
return t;
|
|
515
|
+
throw new l(t);
|
|
514
516
|
}
|
|
515
517
|
}
|
|
516
518
|
}
|
|
517
|
-
class
|
|
518
|
-
constructor(
|
|
519
|
-
this.attributes = {}, this.fetcher =
|
|
519
|
+
class H {
|
|
520
|
+
constructor(t, e, s, o) {
|
|
521
|
+
this.attributes = {}, this.fetcher = t, this.request = e, this.response = s, this.error = o;
|
|
520
522
|
}
|
|
521
523
|
/**
|
|
522
524
|
* Checks if the exchange has an error.
|
|
@@ -546,18 +548,18 @@ class j {
|
|
|
546
548
|
*/
|
|
547
549
|
get requiredResponse() {
|
|
548
550
|
if (!this.response)
|
|
549
|
-
throw new
|
|
551
|
+
throw new l(
|
|
550
552
|
this,
|
|
551
553
|
`Request to ${this.request.url} failed with no response`
|
|
552
554
|
);
|
|
553
555
|
return this.response;
|
|
554
556
|
}
|
|
555
557
|
}
|
|
556
|
-
const
|
|
557
|
-
"Content-Type":
|
|
558
|
-
},
|
|
558
|
+
const m = {
|
|
559
|
+
"Content-Type": h.APPLICATION_JSON
|
|
560
|
+
}, A = {
|
|
559
561
|
baseURL: "",
|
|
560
|
-
headers:
|
|
562
|
+
headers: m
|
|
561
563
|
};
|
|
562
564
|
class V {
|
|
563
565
|
/**
|
|
@@ -568,8 +570,8 @@ class V {
|
|
|
568
570
|
*
|
|
569
571
|
* @param options - Configuration options for the Fetcher instance
|
|
570
572
|
*/
|
|
571
|
-
constructor(
|
|
572
|
-
this.headers =
|
|
573
|
+
constructor(t = A) {
|
|
574
|
+
this.headers = m, this.urlBuilder = new S(t.baseURL), this.headers = t.headers ?? m, this.timeout = t.timeout, this.interceptors = t.interceptors ?? new j();
|
|
573
575
|
}
|
|
574
576
|
/**
|
|
575
577
|
* Executes an HTTP request with the specified URL and options.
|
|
@@ -582,9 +584,9 @@ class V {
|
|
|
582
584
|
* @returns Promise that resolves to the HTTP response
|
|
583
585
|
* @throws FetchError if the request fails and no response is generated
|
|
584
586
|
*/
|
|
585
|
-
async fetch(
|
|
586
|
-
const s =
|
|
587
|
-
return s.url =
|
|
587
|
+
async fetch(t, e = {}) {
|
|
588
|
+
const s = e;
|
|
589
|
+
return s.url = t, (await this.request(s)).requiredResponse;
|
|
588
590
|
}
|
|
589
591
|
/**
|
|
590
592
|
* Processes an HTTP request through the Fetcher's internal workflow.
|
|
@@ -597,15 +599,15 @@ class V {
|
|
|
597
599
|
* @returns Promise that resolves to a FetchExchange containing request/response data
|
|
598
600
|
* @throws Error if an unhandled error occurs during request processing
|
|
599
601
|
*/
|
|
600
|
-
async request(
|
|
601
|
-
const
|
|
602
|
+
async request(t) {
|
|
603
|
+
const e = {
|
|
602
604
|
...this.headers,
|
|
603
|
-
...
|
|
605
|
+
...t.headers
|
|
604
606
|
}, s = {
|
|
605
|
-
...
|
|
606
|
-
headers:
|
|
607
|
-
timeout:
|
|
608
|
-
}, o = new
|
|
607
|
+
...t,
|
|
608
|
+
headers: e,
|
|
609
|
+
timeout: _(t.timeout, this.timeout)
|
|
610
|
+
}, o = new H(this, s);
|
|
609
611
|
return this.interceptors.exchange(o);
|
|
610
612
|
}
|
|
611
613
|
/**
|
|
@@ -619,10 +621,10 @@ class V {
|
|
|
619
621
|
* @param request - Additional request options
|
|
620
622
|
* @returns Promise that resolves to the HTTP response
|
|
621
623
|
*/
|
|
622
|
-
async methodFetch(
|
|
623
|
-
return this.fetch(
|
|
624
|
+
async methodFetch(t, e, s = {}) {
|
|
625
|
+
return this.fetch(e, {
|
|
624
626
|
...s,
|
|
625
|
-
method:
|
|
627
|
+
method: t
|
|
626
628
|
});
|
|
627
629
|
}
|
|
628
630
|
/**
|
|
@@ -635,8 +637,8 @@ class V {
|
|
|
635
637
|
* @param request - Request options excluding method and body
|
|
636
638
|
* @returns Promise that resolves to the HTTP response
|
|
637
639
|
*/
|
|
638
|
-
async get(
|
|
639
|
-
return this.methodFetch(c.GET,
|
|
640
|
+
async get(t, e = {}) {
|
|
641
|
+
return this.methodFetch(c.GET, t, e);
|
|
640
642
|
}
|
|
641
643
|
/**
|
|
642
644
|
* Makes a POST HTTP request.
|
|
@@ -647,8 +649,8 @@ class V {
|
|
|
647
649
|
* @param request - Request options including body and other parameters
|
|
648
650
|
* @returns Promise that resolves to the HTTP response
|
|
649
651
|
*/
|
|
650
|
-
async post(
|
|
651
|
-
return this.methodFetch(c.POST,
|
|
652
|
+
async post(t, e = {}) {
|
|
653
|
+
return this.methodFetch(c.POST, t, e);
|
|
652
654
|
}
|
|
653
655
|
/**
|
|
654
656
|
* Makes a PUT HTTP request.
|
|
@@ -659,8 +661,8 @@ class V {
|
|
|
659
661
|
* @param request - Request options including body and other parameters
|
|
660
662
|
* @returns Promise that resolves to the HTTP response
|
|
661
663
|
*/
|
|
662
|
-
async put(
|
|
663
|
-
return this.methodFetch(c.PUT,
|
|
664
|
+
async put(t, e = {}) {
|
|
665
|
+
return this.methodFetch(c.PUT, t, e);
|
|
664
666
|
}
|
|
665
667
|
/**
|
|
666
668
|
* Makes a DELETE HTTP request.
|
|
@@ -671,8 +673,8 @@ class V {
|
|
|
671
673
|
* @param request - Request options excluding method and body
|
|
672
674
|
* @returns Promise that resolves to the HTTP response
|
|
673
675
|
*/
|
|
674
|
-
async delete(
|
|
675
|
-
return this.methodFetch(c.DELETE,
|
|
676
|
+
async delete(t, e = {}) {
|
|
677
|
+
return this.methodFetch(c.DELETE, t, e);
|
|
676
678
|
}
|
|
677
679
|
/**
|
|
678
680
|
* Makes a PATCH HTTP request.
|
|
@@ -683,8 +685,8 @@ class V {
|
|
|
683
685
|
* @param request - Request options including body and other parameters
|
|
684
686
|
* @returns Promise that resolves to the HTTP response
|
|
685
687
|
*/
|
|
686
|
-
async patch(
|
|
687
|
-
return this.methodFetch(c.PATCH,
|
|
688
|
+
async patch(t, e = {}) {
|
|
689
|
+
return this.methodFetch(c.PATCH, t, e);
|
|
688
690
|
}
|
|
689
691
|
/**
|
|
690
692
|
* Makes a HEAD HTTP request.
|
|
@@ -696,8 +698,8 @@ class V {
|
|
|
696
698
|
* @param request - Request options excluding method and body
|
|
697
699
|
* @returns Promise that resolves to the HTTP response
|
|
698
700
|
*/
|
|
699
|
-
async head(
|
|
700
|
-
return this.methodFetch(c.HEAD,
|
|
701
|
+
async head(t, e = {}) {
|
|
702
|
+
return this.methodFetch(c.HEAD, t, e);
|
|
701
703
|
}
|
|
702
704
|
/**
|
|
703
705
|
* Makes an OPTIONS HTTP request.
|
|
@@ -709,12 +711,12 @@ class V {
|
|
|
709
711
|
* @param request - Request options excluding method and body
|
|
710
712
|
* @returns Promise that resolves to the HTTP response
|
|
711
713
|
*/
|
|
712
|
-
async options(
|
|
713
|
-
return this.methodFetch(c.OPTIONS,
|
|
714
|
+
async options(t, e = {}) {
|
|
715
|
+
return this.methodFetch(c.OPTIONS, t, e);
|
|
714
716
|
}
|
|
715
717
|
}
|
|
716
|
-
const
|
|
717
|
-
class
|
|
718
|
+
const T = "default";
|
|
719
|
+
class k {
|
|
718
720
|
constructor() {
|
|
719
721
|
this.registrar = /* @__PURE__ */ new Map();
|
|
720
722
|
}
|
|
@@ -727,8 +729,8 @@ class H {
|
|
|
727
729
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
728
730
|
* fetcherRegistrar.register('api', fetcher);
|
|
729
731
|
*/
|
|
730
|
-
register(
|
|
731
|
-
this.registrar.set(
|
|
732
|
+
register(t, e) {
|
|
733
|
+
this.registrar.set(t, e);
|
|
732
734
|
}
|
|
733
735
|
/**
|
|
734
736
|
* Unregister a Fetcher instance by name
|
|
@@ -741,8 +743,8 @@ class H {
|
|
|
741
743
|
* console.log('Fetcher unregistered successfully');
|
|
742
744
|
* }
|
|
743
745
|
*/
|
|
744
|
-
unregister(
|
|
745
|
-
return this.registrar.delete(
|
|
746
|
+
unregister(t) {
|
|
747
|
+
return this.registrar.delete(t);
|
|
746
748
|
}
|
|
747
749
|
/**
|
|
748
750
|
* Get a Fetcher instance by name
|
|
@@ -755,8 +757,8 @@ class H {
|
|
|
755
757
|
* // Use the fetcher
|
|
756
758
|
* }
|
|
757
759
|
*/
|
|
758
|
-
get(
|
|
759
|
-
return this.registrar.get(
|
|
760
|
+
get(t) {
|
|
761
|
+
return this.registrar.get(t);
|
|
760
762
|
}
|
|
761
763
|
/**
|
|
762
764
|
* Get a Fetcher instance by name, throwing an error if not found
|
|
@@ -772,11 +774,11 @@ class H {
|
|
|
772
774
|
* console.error('Fetcher not found:', error.message);
|
|
773
775
|
* }
|
|
774
776
|
*/
|
|
775
|
-
requiredGet(
|
|
776
|
-
const
|
|
777
|
-
if (!
|
|
778
|
-
throw new Error(`Fetcher ${
|
|
779
|
-
return
|
|
777
|
+
requiredGet(t) {
|
|
778
|
+
const e = this.get(t);
|
|
779
|
+
if (!e)
|
|
780
|
+
throw new Error(`Fetcher ${t} not found`);
|
|
781
|
+
return e;
|
|
780
782
|
}
|
|
781
783
|
/**
|
|
782
784
|
* Get the default Fetcher instance
|
|
@@ -787,7 +789,7 @@ class H {
|
|
|
787
789
|
* const defaultFetcher = fetcherRegistrar.default;
|
|
788
790
|
*/
|
|
789
791
|
get default() {
|
|
790
|
-
return this.requiredGet(
|
|
792
|
+
return this.requiredGet(T);
|
|
791
793
|
}
|
|
792
794
|
/**
|
|
793
795
|
* Set the default Fetcher instance
|
|
@@ -797,8 +799,8 @@ class H {
|
|
|
797
799
|
* const fetcher = new Fetcher({ baseURL: 'https://api.example.com' });
|
|
798
800
|
* fetcherRegistrar.default = fetcher;
|
|
799
801
|
*/
|
|
800
|
-
set default(
|
|
801
|
-
this.register(
|
|
802
|
+
set default(t) {
|
|
803
|
+
this.register(T, t);
|
|
802
804
|
}
|
|
803
805
|
/**
|
|
804
806
|
* Get a copy of all registered fetchers
|
|
@@ -814,35 +816,35 @@ class H {
|
|
|
814
816
|
return new Map(this.registrar);
|
|
815
817
|
}
|
|
816
818
|
}
|
|
817
|
-
const
|
|
818
|
-
function
|
|
819
|
-
if (!(r === void 0 &&
|
|
820
|
-
return
|
|
819
|
+
const J = new k();
|
|
820
|
+
function I(r, t) {
|
|
821
|
+
if (!(r === void 0 && t === void 0))
|
|
822
|
+
return t === void 0 ? r : r === void 0 ? t : { ...r, ...t };
|
|
821
823
|
}
|
|
822
|
-
function Q(r,
|
|
824
|
+
function Q(r, t) {
|
|
823
825
|
if (Object.keys(r).length === 0)
|
|
824
|
-
return
|
|
825
|
-
if (Object.keys(
|
|
826
|
+
return t;
|
|
827
|
+
if (Object.keys(t).length === 0)
|
|
826
828
|
return r;
|
|
827
|
-
const
|
|
828
|
-
path:
|
|
829
|
-
query:
|
|
829
|
+
const e = {
|
|
830
|
+
path: I(r.urlParams?.path, t.urlParams?.path),
|
|
831
|
+
query: I(r.urlParams?.query, t.urlParams?.query)
|
|
830
832
|
}, s = {
|
|
831
833
|
...r.headers,
|
|
832
|
-
...
|
|
833
|
-
}, o =
|
|
834
|
+
...t.headers
|
|
835
|
+
}, o = t.method ?? r.method, i = t.body ?? r.body, n = t.timeout ?? r.timeout, u = t.signal ?? r.signal;
|
|
834
836
|
return {
|
|
835
837
|
...r,
|
|
836
|
-
...
|
|
838
|
+
...t,
|
|
837
839
|
method: o,
|
|
838
|
-
urlParams:
|
|
840
|
+
urlParams: e,
|
|
839
841
|
headers: s,
|
|
840
842
|
body: i,
|
|
841
843
|
timeout: n,
|
|
842
844
|
signal: u
|
|
843
845
|
};
|
|
844
846
|
}
|
|
845
|
-
class
|
|
847
|
+
class X extends V {
|
|
846
848
|
/**
|
|
847
849
|
* Create a NamedFetcher instance and automatically register it with the global fetcherRegistrar
|
|
848
850
|
*
|
|
@@ -860,48 +862,48 @@ class J extends V {
|
|
|
860
862
|
* headers: { 'Authorization': 'Bearer token' }
|
|
861
863
|
* });
|
|
862
864
|
*/
|
|
863
|
-
constructor(
|
|
864
|
-
super(
|
|
865
|
+
constructor(t, e = A) {
|
|
866
|
+
super(e), this.name = t, J.register(t, this);
|
|
865
867
|
}
|
|
866
868
|
}
|
|
867
|
-
const
|
|
869
|
+
const x = new X(T);
|
|
868
870
|
export {
|
|
869
|
-
z as
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
871
|
+
z as CONTENT_TYPE_HEADER,
|
|
872
|
+
h as ContentTypeValues,
|
|
873
|
+
T as DEFAULT_FETCHER_NAME,
|
|
874
|
+
A as DEFAULT_OPTIONS,
|
|
875
|
+
l as ExchangeError,
|
|
876
|
+
L as FETCH_INTERCEPTOR_NAME,
|
|
877
|
+
C as FETCH_INTERCEPTOR_ORDER,
|
|
878
|
+
H as FetchExchange,
|
|
879
|
+
v as FetchInterceptor,
|
|
880
|
+
R as FetchTimeoutError,
|
|
879
881
|
V as Fetcher,
|
|
880
882
|
a as FetcherError,
|
|
881
|
-
|
|
883
|
+
k as FetcherRegistrar,
|
|
882
884
|
c as HttpMethod,
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
885
|
+
f as HttpStatusValidationError,
|
|
886
|
+
j as InterceptorManager,
|
|
887
|
+
p as InterceptorRegistry,
|
|
888
|
+
X as NamedFetcher,
|
|
889
|
+
q as REQUEST_BODY_INTERCEPTOR_NAME,
|
|
890
|
+
U as REQUEST_BODY_INTERCEPTOR_ORDER,
|
|
891
|
+
D as RequestBodyInterceptor,
|
|
892
|
+
N as URL_RESOLVE_INTERCEPTOR_NAME,
|
|
893
|
+
O as URL_RESOLVE_INTERCEPTOR_ORDER,
|
|
894
|
+
S as UrlBuilder,
|
|
895
|
+
F as UrlResolveInterceptor,
|
|
896
|
+
G as VALIDATE_STATUS_INTERCEPTOR_NAME,
|
|
897
|
+
M as VALIDATE_STATUS_INTERCEPTOR_ORDER,
|
|
898
|
+
$ as ValidateStatusInterceptor,
|
|
899
|
+
b as combineURLs,
|
|
900
|
+
x as fetcher,
|
|
901
|
+
J as fetcherRegistrar,
|
|
900
902
|
g as isAbsoluteURL,
|
|
901
|
-
|
|
903
|
+
I as mergeRecords,
|
|
902
904
|
Q as mergeRequest,
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
905
|
+
_ as resolveTimeout,
|
|
906
|
+
w as timeoutFetch,
|
|
907
|
+
E as toSorted
|
|
906
908
|
};
|
|
907
909
|
//# sourceMappingURL=index.es.js.map
|