@superutils/fetch 1.2.1 → 1.2.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/README.md +232 -68
- package/dist/index.d.ts +351 -292
- package/dist/index.js +222 -153
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
// src/createClient.ts
|
|
2
|
+
import PromisE3 from "@superutils/promise";
|
|
3
|
+
|
|
1
4
|
// src/fetch.ts
|
|
2
5
|
import {
|
|
3
|
-
fallbackIfFails as
|
|
6
|
+
fallbackIfFails as fallbackIfFails3,
|
|
4
7
|
isFn as isFn2,
|
|
5
8
|
isPositiveNumber,
|
|
6
9
|
isPromise,
|
|
@@ -12,7 +15,7 @@ import PromisE2 from "@superutils/promise";
|
|
|
12
15
|
import { fallbackIfFails, isFn } from "@superutils/core";
|
|
13
16
|
var executeInterceptors = async (value, interceptors, ...args) => {
|
|
14
17
|
var _a;
|
|
15
|
-
for (const interceptor of interceptors.filter(isFn)) {
|
|
18
|
+
for (const interceptor of [...interceptors != null ? interceptors : []].filter(isFn)) {
|
|
16
19
|
value = (_a = await fallbackIfFails(
|
|
17
20
|
interceptor,
|
|
18
21
|
[value, ...args],
|
|
@@ -23,12 +26,31 @@ var executeInterceptors = async (value, interceptors, ...args) => {
|
|
|
23
26
|
};
|
|
24
27
|
var executeInterceptors_default = executeInterceptors;
|
|
25
28
|
|
|
29
|
+
// src/getAbortCtrl.ts
|
|
30
|
+
var getAbortCtrl = (options) => {
|
|
31
|
+
options != null ? options : options = {};
|
|
32
|
+
if (!(options.abortCtrl instanceof AbortController))
|
|
33
|
+
options.abortCtrl = new AbortController();
|
|
34
|
+
const { abortCtrl, signal } = options;
|
|
35
|
+
if (signal instanceof AbortSignal && !signal.aborted) {
|
|
36
|
+
const handleAbort = () => abortCtrl.abort();
|
|
37
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
38
|
+
abortCtrl.signal.addEventListener(
|
|
39
|
+
"abort",
|
|
40
|
+
() => signal.removeEventListener("abort", handleAbort),
|
|
41
|
+
{ once: true }
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return abortCtrl;
|
|
45
|
+
};
|
|
46
|
+
|
|
26
47
|
// src/getResponse.ts
|
|
48
|
+
import { fallbackIfFails as fallbackIfFails2, isPositiveInteger } from "@superutils/core";
|
|
27
49
|
import PromisE from "@superutils/promise";
|
|
28
|
-
|
|
29
|
-
var getResponse = async (...[url, options = {}]) => {
|
|
50
|
+
var getResponse = async (url, options = {}) => {
|
|
30
51
|
const fetchFunc = globalThis.fetch;
|
|
31
|
-
if (!isPositiveInteger(options.retry))
|
|
52
|
+
if (!isPositiveInteger(options.retry))
|
|
53
|
+
return fetchFunc(url, options);
|
|
32
54
|
let attemptCount = 0;
|
|
33
55
|
const response = PromisE.retry(
|
|
34
56
|
() => {
|
|
@@ -37,9 +59,14 @@ var getResponse = async (...[url, options = {}]) => {
|
|
|
37
59
|
},
|
|
38
60
|
{
|
|
39
61
|
...options,
|
|
40
|
-
retryIf: async (res, count) => {
|
|
41
|
-
var _a;
|
|
42
|
-
|
|
62
|
+
retryIf: async (res, count, error) => {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const failed = !!error || !(res == null ? void 0 : res.ok);
|
|
65
|
+
return !!((_b = await fallbackIfFails2(
|
|
66
|
+
(_a = options == null ? void 0 : options.retryIf) != null ? _a : failed,
|
|
67
|
+
[res, count, error],
|
|
68
|
+
failed
|
|
69
|
+
)) != null ? _b : failed);
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
).catch(
|
|
@@ -54,21 +81,22 @@ var getResponse = async (...[url, options = {}]) => {
|
|
|
54
81
|
var getResponse_default = getResponse;
|
|
55
82
|
|
|
56
83
|
// src/mergeFetchOptions.ts
|
|
57
|
-
import { isEmpty, objKeys } from "@superutils/core";
|
|
84
|
+
import { isEmpty, isObj, objKeys } from "@superutils/core";
|
|
58
85
|
var mergeFetchOptions = (...allOptions) => allOptions.reduce(
|
|
59
|
-
(
|
|
86
|
+
(merged, next) => {
|
|
60
87
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
61
|
-
|
|
62
|
-
const { errMsgs
|
|
63
|
-
|
|
88
|
+
next = isObj(next) ? next : {};
|
|
89
|
+
const { errMsgs = {}, headers, interceptors: ints1 = {} } = merged;
|
|
90
|
+
const { errMsgs: msgs2 = {}, interceptors: ints2 = {} } = next;
|
|
91
|
+
next.headers && new Headers(next.headers).forEach((value, key) => {
|
|
64
92
|
headers && headers.set(key, value);
|
|
65
93
|
});
|
|
66
94
|
for (const key of objKeys(msgs2)) {
|
|
67
95
|
if (!isEmpty(msgs2[key])) errMsgs[key] = msgs2[key];
|
|
68
96
|
}
|
|
69
97
|
return {
|
|
70
|
-
...
|
|
71
|
-
...
|
|
98
|
+
...merged,
|
|
99
|
+
...next,
|
|
72
100
|
errMsgs,
|
|
73
101
|
headers,
|
|
74
102
|
interceptors: {
|
|
@@ -86,18 +114,37 @@ var mergeFetchOptions = (...allOptions) => allOptions.reduce(
|
|
|
86
114
|
...(_h = ints2 == null ? void 0 : ints2.result) != null ? _h : []
|
|
87
115
|
]
|
|
88
116
|
},
|
|
89
|
-
timeout: (_j = (_i =
|
|
117
|
+
timeout: (_j = (_i = next.timeout) != null ? _i : merged.timeout) != null ? _j : 0
|
|
90
118
|
};
|
|
91
119
|
},
|
|
92
120
|
{ headers: new Headers() }
|
|
93
121
|
);
|
|
94
122
|
var mergeFetchOptions_default = mergeFetchOptions;
|
|
123
|
+
var mergePartialOptions = (...optionsAr) => {
|
|
124
|
+
optionsAr = optionsAr.filter((x) => !isEmpty(x));
|
|
125
|
+
return optionsAr.length <= 1 ? optionsAr[0] : mergeFetchOptions(...optionsAr);
|
|
126
|
+
};
|
|
95
127
|
|
|
96
128
|
// src/types.ts
|
|
97
129
|
import {
|
|
98
130
|
ResolveError,
|
|
99
131
|
ResolveIgnored
|
|
100
132
|
} from "@superutils/promise";
|
|
133
|
+
var ContentType = {
|
|
134
|
+
APPLICATION_JAVASCRIPT: "application/javascript",
|
|
135
|
+
APPLICATION_JSON: "application/json",
|
|
136
|
+
APPLICATION_OCTET_STREAM: "application/octet-stream",
|
|
137
|
+
APPLICATION_PDF: "application/pdf",
|
|
138
|
+
APPLICATION_X_WWW_FORM_URLENCODED: "application/x-www-form-urlencoded",
|
|
139
|
+
APPLICATION_XML: "application/xml",
|
|
140
|
+
APPLICATION_ZIP: "application/zip",
|
|
141
|
+
AUDIO_MPEG: "audio/mpeg",
|
|
142
|
+
MULTIPART_FORM_DATA: "multipart/form-data",
|
|
143
|
+
TEXT_CSS: "text/css",
|
|
144
|
+
TEXT_HTML: "text/html",
|
|
145
|
+
TEXT_PLAIN: "text/plain",
|
|
146
|
+
VIDEO_MP4: "video/mp4"
|
|
147
|
+
};
|
|
101
148
|
var FetchAs = /* @__PURE__ */ ((FetchAs2) => {
|
|
102
149
|
FetchAs2["arrayBuffer"] = "arrayBuffer";
|
|
103
150
|
FetchAs2["blob"] = "blob";
|
|
@@ -126,44 +173,59 @@ var FetchError = class _FetchError extends Error {
|
|
|
126
173
|
|
|
127
174
|
// src/fetch.ts
|
|
128
175
|
var fetch = (url, options = {}) => {
|
|
129
|
-
let abortCtrl;
|
|
130
176
|
let timeoutId;
|
|
177
|
+
const abortCtrl = getAbortCtrl(options);
|
|
131
178
|
const promise = new PromisE2(async (resolve, reject) => {
|
|
132
|
-
var _a, _b, _c
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
179
|
+
var _a, _b, _c;
|
|
180
|
+
let errResponse;
|
|
181
|
+
const _options = mergeFetchOptions_default(fetch.defaults, options);
|
|
182
|
+
(_a = _options.as) != null ? _a : _options.as = "json" /* json */;
|
|
183
|
+
(_b = _options.method) != null ? _b : _options.method = "get";
|
|
184
|
+
let contentType = _options.headers.get("content-type");
|
|
185
|
+
if (!contentType) {
|
|
186
|
+
_options.headers.set("content-type", ContentType.APPLICATION_JSON);
|
|
187
|
+
contentType = ContentType.APPLICATION_JSON;
|
|
188
|
+
}
|
|
189
|
+
url = await executeInterceptors_default(
|
|
190
|
+
url,
|
|
191
|
+
_options.interceptors.request,
|
|
192
|
+
_options
|
|
193
|
+
);
|
|
194
|
+
const {
|
|
195
|
+
as: parseAs,
|
|
196
|
+
body,
|
|
197
|
+
errMsgs,
|
|
198
|
+
timeout,
|
|
199
|
+
validateUrl = true
|
|
200
|
+
} = _options;
|
|
142
201
|
if (isPositiveNumber(timeout)) {
|
|
143
|
-
|
|
144
|
-
timeoutId = setTimeout(() => {
|
|
145
|
-
var _a2;
|
|
146
|
-
return (_a2 = _options2.abortCtrl) == null ? void 0 : _a2.abort();
|
|
147
|
-
}, timeout);
|
|
202
|
+
timeoutId = setTimeout(() => abortCtrl.abort(), timeout);
|
|
148
203
|
}
|
|
149
|
-
abortCtrl =
|
|
150
|
-
if (_options2.abortCtrl) _options2.signal = _options2.abortCtrl.signal;
|
|
151
|
-
let errResponse;
|
|
204
|
+
if (_options.abortCtrl) _options.signal = _options.abortCtrl.signal;
|
|
152
205
|
try {
|
|
153
|
-
if (!isUrlValid(url, false))
|
|
154
|
-
|
|
206
|
+
if (validateUrl && !isUrlValid(url, false))
|
|
207
|
+
throw new Error(errMsgs.invalidUrl);
|
|
208
|
+
const shouldStringifyBody = [
|
|
209
|
+
ContentType.APPLICATION_JSON,
|
|
210
|
+
ContentType.APPLICATION_X_WWW_FORM_URLENCODED
|
|
211
|
+
].find((x) => contentType.includes(x)) && !["undefined", "string"].includes(typeof body);
|
|
212
|
+
if (shouldStringifyBody)
|
|
213
|
+
_options.body = JSON.stringify(
|
|
214
|
+
isFn2(body) ? fallbackIfFails3(body, [], void 0) : body
|
|
215
|
+
);
|
|
216
|
+
let response = await getResponse_default(url, _options);
|
|
155
217
|
response = await executeInterceptors_default(
|
|
156
218
|
response,
|
|
157
|
-
|
|
219
|
+
_options.interceptors.response,
|
|
158
220
|
url,
|
|
159
|
-
|
|
221
|
+
_options
|
|
160
222
|
);
|
|
161
223
|
errResponse = response;
|
|
162
224
|
const { status = 0 } = response;
|
|
163
225
|
const isSuccess = status >= 200 && status < 300;
|
|
164
226
|
if (!isSuccess) {
|
|
165
227
|
const fallbackMsg = `${errMsgs.requestFailed} ${status}`;
|
|
166
|
-
const jsonError = await
|
|
228
|
+
const jsonError = await fallbackIfFails3(
|
|
167
229
|
// try to parse error response as json first
|
|
168
230
|
() => response.json(),
|
|
169
231
|
[],
|
|
@@ -189,31 +251,31 @@ var fetch = (url, options = {}) => {
|
|
|
189
251
|
}
|
|
190
252
|
result = await executeInterceptors_default(
|
|
191
253
|
result,
|
|
192
|
-
|
|
254
|
+
_options.interceptors.result,
|
|
193
255
|
url,
|
|
194
|
-
|
|
256
|
+
_options
|
|
195
257
|
);
|
|
196
258
|
resolve(result);
|
|
197
259
|
} catch (err) {
|
|
198
260
|
const errX = err;
|
|
199
261
|
const msg = (errX == null ? void 0 : errX.name) === "AbortError" ? errMsgs.reqTimedout : err == null ? void 0 : err.message;
|
|
200
262
|
let error = new FetchError(msg, {
|
|
201
|
-
cause: (
|
|
263
|
+
cause: (_c = errX == null ? void 0 : errX.cause) != null ? _c : err,
|
|
202
264
|
response: errResponse,
|
|
203
|
-
options:
|
|
265
|
+
options: _options,
|
|
204
266
|
url
|
|
205
267
|
});
|
|
206
268
|
error = await executeInterceptors_default(
|
|
207
269
|
error,
|
|
208
|
-
|
|
270
|
+
_options.interceptors.error,
|
|
209
271
|
url,
|
|
210
|
-
|
|
272
|
+
_options
|
|
211
273
|
);
|
|
212
274
|
reject(error);
|
|
213
275
|
}
|
|
214
276
|
timeoutId && clearTimeout(timeoutId);
|
|
215
277
|
});
|
|
216
|
-
promise.onEarlyFinalize.push(() => abortCtrl
|
|
278
|
+
promise.onEarlyFinalize.push(() => abortCtrl.abort());
|
|
217
279
|
return promise;
|
|
218
280
|
};
|
|
219
281
|
fetch.defaults = {
|
|
@@ -224,7 +286,7 @@ fetch.defaults = {
|
|
|
224
286
|
requestFailed: "Request failed with status code:"
|
|
225
287
|
},
|
|
226
288
|
// all error messages must be defined here
|
|
227
|
-
headers: new Headers(
|
|
289
|
+
headers: new Headers(),
|
|
228
290
|
/** Global interceptors for fetch requests */
|
|
229
291
|
interceptors: {
|
|
230
292
|
/**
|
|
@@ -238,119 +300,122 @@ fetch.defaults = {
|
|
|
238
300
|
result: []
|
|
239
301
|
},
|
|
240
302
|
/** Request timeout duration in milliseconds. Default: `0` */
|
|
241
|
-
timeout: 0
|
|
303
|
+
timeout: 0,
|
|
304
|
+
validateUrl: true
|
|
242
305
|
};
|
|
243
306
|
var fetch_default = fetch;
|
|
244
307
|
|
|
245
|
-
// src/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
_abortCtrl = options.abortCtrl;
|
|
256
|
-
const promise = fetch_default(
|
|
257
|
-
defaultUrl != null ? defaultUrl : args[0],
|
|
258
|
-
options
|
|
308
|
+
// src/createClient.ts
|
|
309
|
+
var createClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
310
|
+
const func = (url, options) => {
|
|
311
|
+
return fetch_default(
|
|
312
|
+
url,
|
|
313
|
+
mergePartialOptions(
|
|
314
|
+
commonOptions,
|
|
315
|
+
options,
|
|
316
|
+
fixedOptions
|
|
317
|
+
)
|
|
259
318
|
);
|
|
260
|
-
promise.onEarlyFinalize.push(() => _abortCtrl == null ? void 0 : _abortCtrl.abort());
|
|
261
|
-
return promise;
|
|
262
|
-
};
|
|
263
|
-
return PromisE3.deferredCallback(fetchCallback, deferOptions);
|
|
264
|
-
}
|
|
265
|
-
var fetchDeferred_default = fetchDeferred;
|
|
266
|
-
|
|
267
|
-
// src/createFetchMethodFunc.ts
|
|
268
|
-
var createFetchMethodFunc = (method = "get") => {
|
|
269
|
-
const methodFunc = (...args) => {
|
|
270
|
-
var _a;
|
|
271
|
-
(_a = args[1]) != null ? _a : args[1] = {};
|
|
272
|
-
args[1].method = method;
|
|
273
|
-
return fetch_default(...args);
|
|
274
319
|
};
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
320
|
+
func.deferred = (deferOptions = {}, defaultUrl, defaultOptions) => {
|
|
321
|
+
let _abortCtrl;
|
|
322
|
+
const fetchCb = (...args) => {
|
|
323
|
+
var _a, _b;
|
|
324
|
+
const options = mergePartialOptions(
|
|
325
|
+
commonOptions,
|
|
326
|
+
defaultOptions,
|
|
327
|
+
defaultUrl === void 0 ? args[1] : args[0],
|
|
328
|
+
fixedOptions
|
|
329
|
+
);
|
|
330
|
+
((_a = _abortCtrl == null ? void 0 : _abortCtrl.signal) == null ? void 0 : _a.aborted) === false && ((_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl));
|
|
331
|
+
_abortCtrl = getAbortCtrl(options);
|
|
332
|
+
const promise = fetch_default(
|
|
333
|
+
defaultUrl != null ? defaultUrl : args[0],
|
|
334
|
+
options
|
|
335
|
+
);
|
|
336
|
+
promise.onEarlyFinalize.push(() => _abortCtrl == null ? void 0 : _abortCtrl.abort());
|
|
337
|
+
return promise;
|
|
338
|
+
};
|
|
339
|
+
return PromisE3.deferredCallback(fetchCb, {
|
|
340
|
+
...commonDeferOptions,
|
|
341
|
+
...deferOptions
|
|
342
|
+
});
|
|
280
343
|
};
|
|
281
|
-
return
|
|
344
|
+
return func;
|
|
282
345
|
};
|
|
283
|
-
var
|
|
346
|
+
var createClient_default = createClient;
|
|
284
347
|
|
|
285
|
-
// src/
|
|
286
|
-
import { isFn as isFn3, isStr } from "@superutils/core";
|
|
287
|
-
function post(...[url = "", data, options = {}]) {
|
|
288
|
-
var _a;
|
|
289
|
-
(_a = options.method) != null ? _a : options.method = "post";
|
|
290
|
-
return fetch_default(url, {
|
|
291
|
-
...options,
|
|
292
|
-
body: isStr(data) ? data : JSON.stringify(isFn3(data) ? data() : data)
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// src/postDeferred.ts
|
|
348
|
+
// src/createPostClient.ts
|
|
297
349
|
import PromisE4 from "@superutils/promise";
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
(_b = options.abortCtrl) != null ? _b : options.abortCtrl = new AbortController();
|
|
306
|
-
(_c = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _c.call(_abortCtrl);
|
|
307
|
-
_abortCtrl = options.abortCtrl;
|
|
308
|
-
const promise = post(
|
|
309
|
-
args[0],
|
|
310
|
-
args[1],
|
|
311
|
-
options
|
|
350
|
+
var createPostClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
351
|
+
const client2 = (url, data, options) => {
|
|
352
|
+
var _a;
|
|
353
|
+
const _options = mergePartialOptions(
|
|
354
|
+
commonOptions,
|
|
355
|
+
options,
|
|
356
|
+
fixedOptions
|
|
312
357
|
);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return PromisE4.deferredCallback(doPost, deferOptions);
|
|
317
|
-
}
|
|
318
|
-
var postDeferred_default = postDeferred;
|
|
319
|
-
|
|
320
|
-
// src/createPostMethodFunc.ts
|
|
321
|
-
var createPostMethodFunc = (method = "post") => {
|
|
322
|
-
const methodFunc = (url, data, options) => {
|
|
323
|
-
options != null ? options : options = {};
|
|
324
|
-
options.method = method;
|
|
325
|
-
return post(url, data, options);
|
|
358
|
+
_options.body = data;
|
|
359
|
+
(_a = _options.method) != null ? _a : _options.method = "post";
|
|
360
|
+
return fetch_default(url, _options);
|
|
326
361
|
};
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
362
|
+
client2.deferred = (deferOptions = {}, defaultUrl, defaultData, defaultOptions) => {
|
|
363
|
+
let _abortCtrl;
|
|
364
|
+
const postCb = (...args) => {
|
|
365
|
+
var _a, _b, _c, _d;
|
|
366
|
+
if (defaultUrl !== void 0) args.splice(0, 0, defaultUrl);
|
|
367
|
+
if (defaultData !== void 0) args.splice(1, 0, defaultData);
|
|
368
|
+
const options = mergePartialOptions(
|
|
369
|
+
commonOptions,
|
|
370
|
+
defaultOptions,
|
|
371
|
+
args[2],
|
|
372
|
+
fixedOptions
|
|
373
|
+
);
|
|
374
|
+
((_a = _abortCtrl == null ? void 0 : _abortCtrl.signal) == null ? void 0 : _a.aborted) === false && ((_b = _abortCtrl == null ? void 0 : _abortCtrl.abort) == null ? void 0 : _b.call(_abortCtrl));
|
|
375
|
+
_abortCtrl = getAbortCtrl(options);
|
|
376
|
+
options.body = (_c = args[1]) != null ? _c : options.body;
|
|
377
|
+
(_d = options.method) != null ? _d : options.method = "post";
|
|
378
|
+
const promise = fetch_default(args[0], options);
|
|
379
|
+
promise.onEarlyFinalize.push(() => _abortCtrl == null ? void 0 : _abortCtrl.abort());
|
|
380
|
+
return promise;
|
|
381
|
+
};
|
|
382
|
+
return PromisE4.deferredCallback(postCb, {
|
|
383
|
+
...commonDeferOptions,
|
|
384
|
+
...deferOptions
|
|
385
|
+
});
|
|
332
386
|
};
|
|
333
|
-
return
|
|
387
|
+
return client2;
|
|
334
388
|
};
|
|
335
|
-
var
|
|
389
|
+
var createPostClient_default = createPostClient;
|
|
390
|
+
var client = createPostClient();
|
|
391
|
+
client.deferred();
|
|
336
392
|
|
|
337
393
|
// src/fetchResponse.ts
|
|
338
|
-
var fetchResponse = (
|
|
339
|
-
var _a
|
|
340
|
-
|
|
341
|
-
(
|
|
342
|
-
return fetch_default(
|
|
394
|
+
var fetchResponse = (url, options) => {
|
|
395
|
+
var _a;
|
|
396
|
+
options != null ? options : options = {};
|
|
397
|
+
(_a = options.as) != null ? _a : options.as = "response" /* response */;
|
|
398
|
+
return fetch_default(url, options);
|
|
343
399
|
};
|
|
344
400
|
var fetchResponse_default = fetchResponse;
|
|
345
401
|
|
|
346
402
|
// src/fetchDefault.ts
|
|
347
|
-
var
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
403
|
+
var methods = {
|
|
404
|
+
/** Make HTTP requests with method GET */
|
|
405
|
+
get: createClient_default({ method: "get" }),
|
|
406
|
+
/** Make HTTP requests with method HEAD */
|
|
407
|
+
head: createClient_default({ method: "head" }),
|
|
408
|
+
/** Make HTTP requests with method OPTIONS */
|
|
409
|
+
options: createClient_default({ method: "options" }),
|
|
410
|
+
/** Make HTTP requests with method DELETE */
|
|
411
|
+
delete: createPostClient_default({ method: "delete" }),
|
|
412
|
+
/** Make HTTP requests with method PATCH */
|
|
413
|
+
patch: createPostClient_default({ method: "patch" }),
|
|
414
|
+
/** Make HTTP requests with method POST */
|
|
415
|
+
post: createPostClient_default({ method: "post" }),
|
|
416
|
+
/** Make HTTP requests with method PUT */
|
|
417
|
+
put: createPostClient_default({ method: "put" })
|
|
418
|
+
};
|
|
354
419
|
var fetchDefault = fetchResponse_default;
|
|
355
420
|
Object.defineProperty(fetchDefault, "defaults", {
|
|
356
421
|
get() {
|
|
@@ -360,28 +425,32 @@ Object.defineProperty(fetchDefault, "defaults", {
|
|
|
360
425
|
fetch_default.defaults = newDefaults;
|
|
361
426
|
}
|
|
362
427
|
});
|
|
363
|
-
fetchDefault.delete =
|
|
364
|
-
fetchDefault.get =
|
|
365
|
-
fetchDefault.head =
|
|
366
|
-
fetchDefault.options =
|
|
367
|
-
fetchDefault.patch =
|
|
368
|
-
fetchDefault.post =
|
|
369
|
-
fetchDefault.put =
|
|
428
|
+
fetchDefault.delete = methods.delete;
|
|
429
|
+
fetchDefault.get = methods.get;
|
|
430
|
+
fetchDefault.head = methods.head;
|
|
431
|
+
fetchDefault.options = methods.options;
|
|
432
|
+
fetchDefault.patch = methods.patch;
|
|
433
|
+
fetchDefault.post = methods.post;
|
|
434
|
+
fetchDefault.put = methods.put;
|
|
370
435
|
var fetchDefault_default = fetchDefault;
|
|
371
436
|
|
|
372
437
|
// src/index.ts
|
|
373
438
|
var index_default = fetchDefault_default;
|
|
439
|
+
fetchDefault_default.get;
|
|
374
440
|
export {
|
|
441
|
+
ContentType,
|
|
375
442
|
FetchAs,
|
|
376
443
|
FetchError,
|
|
377
444
|
ResolveError,
|
|
378
445
|
ResolveIgnored,
|
|
379
|
-
|
|
380
|
-
|
|
446
|
+
createClient,
|
|
447
|
+
createPostClient,
|
|
381
448
|
index_default as default,
|
|
449
|
+
executeInterceptors,
|
|
382
450
|
fetch,
|
|
383
|
-
fetchDeferred,
|
|
384
451
|
fetchResponse,
|
|
452
|
+
getAbortCtrl,
|
|
453
|
+
getResponse,
|
|
385
454
|
mergeFetchOptions,
|
|
386
|
-
|
|
455
|
+
mergePartialOptions
|
|
387
456
|
};
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
},
|
|
6
6
|
"description": "A lightweight `fetch` wrapper for browsers and Node.js, designed to simplify data fetching and reduce boilerplate.",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@superutils/core": "^1.1.
|
|
9
|
-
"@superutils/promise": "^1.1.
|
|
8
|
+
"@superutils/core": "^1.1.6",
|
|
9
|
+
"@superutils/promise": "^1.1.6"
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"name": "@superutils/fetch",
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@superutils/core": "^1.1.
|
|
28
|
-
"@superutils/promise": "^1.1.
|
|
27
|
+
"@superutils/core": "^1.1.6",
|
|
28
|
+
"@superutils/promise": "^1.1.6"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"sideEffects": false,
|
|
46
46
|
"type": "module",
|
|
47
47
|
"types": "dist/index.d.ts",
|
|
48
|
-
"version": "1.2.
|
|
48
|
+
"version": "1.2.3"
|
|
49
49
|
}
|