@superutils/fetch 1.5.16 → 1.5.17
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 +75 -80
- package/dist/browser/index.min.js +2 -1
- package/dist/browser/index.min.js.map +1 -1
- package/dist/index.cjs +106 -32
- package/dist/index.d.cts +83 -184
- package/dist/index.d.ts +83 -184
- package/dist/index.js +103 -32
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -20,9 +20,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
ApiClient: () => ApiClient,
|
|
23
24
|
ContentType: () => ContentType,
|
|
24
25
|
FetchAs: () => FetchAs,
|
|
25
26
|
FetchError: () => FetchError,
|
|
27
|
+
POST_METHODS: () => POST_METHODS,
|
|
26
28
|
ResolveError: () => import_promise5.ResolveError,
|
|
27
29
|
ResolveIgnored: () => import_promise5.ResolveIgnored,
|
|
28
30
|
TIMEOUT_FALLBACK: () => import_promise5.TIMEOUT_FALLBACK,
|
|
@@ -31,6 +33,7 @@ __export(index_exports, {
|
|
|
31
33
|
createClient: () => createClient,
|
|
32
34
|
createPostClient: () => createPostClient,
|
|
33
35
|
default: () => index_default,
|
|
36
|
+
defaultErrorMsgs: () => defaultErrorMsgs,
|
|
34
37
|
executeInterceptors: () => executeInterceptors,
|
|
35
38
|
fetch: () => fetch2,
|
|
36
39
|
mergeOptions: () => mergeOptions
|
|
@@ -38,6 +41,9 @@ __export(index_exports, {
|
|
|
38
41
|
module.exports = __toCommonJS(index_exports);
|
|
39
42
|
var import_promise5 = require("@superutils/promise");
|
|
40
43
|
|
|
44
|
+
// src/ApiClient.ts
|
|
45
|
+
var import_core6 = require("@superutils/core");
|
|
46
|
+
|
|
41
47
|
// src/createClient.ts
|
|
42
48
|
var import_promise3 = require("@superutils/promise");
|
|
43
49
|
|
|
@@ -335,18 +341,19 @@ var defaultErrorMsgs = Object.freeze({
|
|
|
335
341
|
timedout: "Request timed out",
|
|
336
342
|
requestFailed: "Request failed with status code:"
|
|
337
343
|
});
|
|
344
|
+
var POST_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
338
345
|
var fetch = (url, options = {}) => {
|
|
339
346
|
var _a, _b, _c;
|
|
340
347
|
if (!(0, import_core5.isObj)(options)) options = {};
|
|
341
348
|
let response;
|
|
342
349
|
const opts = mergeOptions_default(
|
|
343
350
|
{ errMsgs: defaultErrorMsgs },
|
|
344
|
-
fetch.defaults,
|
|
351
|
+
options.ignoreGlobalDefaults ? void 0 : fetch.defaults,
|
|
345
352
|
options
|
|
346
353
|
);
|
|
347
354
|
opts.abortCtrl = opts.abortCtrl instanceof AbortController ? opts.abortCtrl : new AbortController();
|
|
348
355
|
(_a = opts.as) != null ? _a : opts.as = "response" /* response */;
|
|
349
|
-
(_b = opts.method) != null ? _b : opts.method = "
|
|
356
|
+
(_b = opts.method) != null ? _b : opts.method = "GET";
|
|
350
357
|
(_c = opts.signal) != null ? _c : opts.signal = opts.abortCtrl.signal;
|
|
351
358
|
const { abortCtrl, as: parseAs, headers, onAbort, onTimeout } = opts;
|
|
352
359
|
opts.onAbort = async () => {
|
|
@@ -385,9 +392,7 @@ var fetch = (url, options = {}) => {
|
|
|
385
392
|
(_b2 = opts.signal) != null ? _b2 : opts.signal = abortCtrl.signal;
|
|
386
393
|
if (validateUrl && !(0, import_core5.isUrlValid)(url, false))
|
|
387
394
|
throw new Error(errMsgs.invalidUrl);
|
|
388
|
-
const stringify = ["
|
|
389
|
-
`${opts.method}`.toLowerCase()
|
|
390
|
-
) && !["undefined", "string"].includes(typeof body) && (0, import_core5.isObj)(body, true) && headers.get("content-type") === ContentType.APPLICATION_JSON;
|
|
395
|
+
const stringify = POST_METHODS.includes(`${opts.method}`.toUpperCase()) && !["undefined", "string"].includes(typeof body) && (0, import_core5.isObj)(body, true) && headers.get("content-type") === ContentType.APPLICATION_JSON;
|
|
391
396
|
if (stringify) opts.body = JSON.stringify(opts.body);
|
|
392
397
|
response = await getResponse_default(url, opts);
|
|
393
398
|
response = await executeInterceptors_default(
|
|
@@ -482,7 +487,6 @@ var createClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
|
482
487
|
function client(url, options) {
|
|
483
488
|
var _a;
|
|
484
489
|
const mergedOptions = mergeOptions_default(
|
|
485
|
-
fetch_default.defaults,
|
|
486
490
|
commonOptions,
|
|
487
491
|
options,
|
|
488
492
|
fixedOptions
|
|
@@ -496,7 +500,6 @@ var createClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
|
496
500
|
const fetchCb = (...args) => {
|
|
497
501
|
var _a, _b;
|
|
498
502
|
const mergedOptions = mergeOptions_default(
|
|
499
|
-
fetch_default.defaults,
|
|
500
503
|
commonOptions,
|
|
501
504
|
defaultOptions,
|
|
502
505
|
defaultUrl === void 0 ? args[1] : args[0],
|
|
@@ -533,7 +536,7 @@ var createPostClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
|
533
536
|
);
|
|
534
537
|
(_a = mergedOptions.as) != null ? _a : mergedOptions.as = "json" /* json */;
|
|
535
538
|
mergedOptions.body = data != null ? data : mergedOptions.body;
|
|
536
|
-
(_b = mergedOptions.method) != null ? _b : mergedOptions.method = "
|
|
539
|
+
(_b = mergedOptions.method) != null ? _b : mergedOptions.method = "POST";
|
|
537
540
|
const headers = mergedOptions.headers;
|
|
538
541
|
if (!headers.get("content-type")) {
|
|
539
542
|
headers.set("content-type", ContentType.APPLICATION_JSON);
|
|
@@ -547,7 +550,6 @@ var createPostClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
|
547
550
|
if (defaultUrl !== void 0) args.splice(0, 0, defaultUrl);
|
|
548
551
|
if (defaultData !== void 0) args.splice(1, 0, defaultData);
|
|
549
552
|
const mergedOptions = mergeOptions_default(
|
|
550
|
-
fetch_default.defaults,
|
|
551
553
|
commonOptions,
|
|
552
554
|
defaultOptions,
|
|
553
555
|
args[2],
|
|
@@ -572,37 +574,108 @@ var createPostClient = (fixedOptions, commonOptions, commonDeferOptions) => {
|
|
|
572
574
|
};
|
|
573
575
|
var createPostClient_default = createPostClient;
|
|
574
576
|
|
|
575
|
-
// src/
|
|
576
|
-
var
|
|
577
|
-
/**
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
577
|
+
// src/ApiClient.ts
|
|
578
|
+
var ApiClient = class {
|
|
579
|
+
/**
|
|
580
|
+
* Creates a new ApiClient instance.
|
|
581
|
+
*
|
|
582
|
+
* @param apiBaseUrl - The base URL for the API. Relative paths passed to methods will be appended to this.
|
|
583
|
+
* @param config - Optional configuration for headers, interceptors, and default behavior.
|
|
584
|
+
*/
|
|
585
|
+
constructor(apiBaseUrl, config = {}) {
|
|
586
|
+
this.apiBaseUrl = apiBaseUrl;
|
|
587
|
+
const {
|
|
588
|
+
errorPrefix,
|
|
589
|
+
fixedOptions = {},
|
|
590
|
+
commonOptions = {},
|
|
591
|
+
commonDeferOptions = {},
|
|
592
|
+
withBaseClients = true
|
|
593
|
+
} = config;
|
|
594
|
+
const interceptors = {};
|
|
595
|
+
if (errorPrefix)
|
|
596
|
+
interceptors.error = [
|
|
597
|
+
(err) => {
|
|
598
|
+
err.message = `${errorPrefix} ${err.message}`;
|
|
599
|
+
return err;
|
|
600
|
+
}
|
|
601
|
+
];
|
|
602
|
+
if ((0, import_core6.isStr)(this.apiBaseUrl)) {
|
|
603
|
+
interceptors.request = [
|
|
604
|
+
(url) => {
|
|
605
|
+
const useBaseUrl = (0, import_core6.isStr)(url) && !url.startsWith("http://") && !url.startsWith("https://") && !url.startsWith(this.apiBaseUrl);
|
|
606
|
+
if (useBaseUrl) url = `${this.apiBaseUrl}${url}`;
|
|
607
|
+
return url;
|
|
608
|
+
}
|
|
609
|
+
];
|
|
610
|
+
}
|
|
611
|
+
const getMethods = [
|
|
612
|
+
withBaseClients ? "client" : "",
|
|
613
|
+
"get",
|
|
614
|
+
"head",
|
|
615
|
+
"options"
|
|
616
|
+
].filter(Boolean);
|
|
617
|
+
const postMethods = [
|
|
618
|
+
withBaseClients ? "postClient" : "",
|
|
619
|
+
"delete",
|
|
620
|
+
"patch",
|
|
621
|
+
"post",
|
|
622
|
+
"put"
|
|
623
|
+
].filter(Boolean);
|
|
624
|
+
const methods = [...getMethods, ...postMethods].reduce(
|
|
625
|
+
(obj, method) => {
|
|
626
|
+
const isBaseClient = method.toLowerCase().includes("client");
|
|
627
|
+
const _createClient = getMethods.includes(method) ? createClient_default : createPostClient_default;
|
|
628
|
+
return {
|
|
629
|
+
[method]: {
|
|
630
|
+
enumerable: false,
|
|
631
|
+
value: _createClient(
|
|
632
|
+
mergeOptions_default(fixedOptions, {
|
|
633
|
+
interceptors,
|
|
634
|
+
method: isBaseClient ? void 0 : method.toUpperCase()
|
|
635
|
+
}),
|
|
636
|
+
{ ignoreGlobalDefaults: true, ...commonOptions },
|
|
637
|
+
commonDeferOptions
|
|
638
|
+
),
|
|
639
|
+
writable: false
|
|
640
|
+
},
|
|
641
|
+
...obj
|
|
642
|
+
};
|
|
643
|
+
},
|
|
644
|
+
{}
|
|
645
|
+
);
|
|
646
|
+
Object.defineProperties(this, methods);
|
|
647
|
+
}
|
|
591
648
|
};
|
|
649
|
+
var ApiClient_default = ApiClient;
|
|
650
|
+
|
|
651
|
+
// src/index.ts
|
|
592
652
|
var fetch2 = fetch_default;
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
fetch2
|
|
599
|
-
|
|
653
|
+
var globalClient = new ApiClient_default(void 0, {
|
|
654
|
+
commonOptions: { ignoreGlobalDefaults: false },
|
|
655
|
+
withBaseClients: false
|
|
656
|
+
});
|
|
657
|
+
Object.defineProperties(
|
|
658
|
+
fetch2,
|
|
659
|
+
["delete", "get", "head", "options", "patch", "post", "put"].reduce(
|
|
660
|
+
(obj, method) => ({
|
|
661
|
+
[method]: {
|
|
662
|
+
enumerable: false,
|
|
663
|
+
value: globalClient[method],
|
|
664
|
+
writable: false
|
|
665
|
+
},
|
|
666
|
+
...obj
|
|
667
|
+
}),
|
|
668
|
+
{}
|
|
669
|
+
)
|
|
670
|
+
);
|
|
600
671
|
var index_default = fetch2;
|
|
601
672
|
// Annotate the CommonJS export names for ESM import in node:
|
|
602
673
|
0 && (module.exports = {
|
|
674
|
+
ApiClient,
|
|
603
675
|
ContentType,
|
|
604
676
|
FetchAs,
|
|
605
677
|
FetchError,
|
|
678
|
+
POST_METHODS,
|
|
606
679
|
ResolveError,
|
|
607
680
|
ResolveIgnored,
|
|
608
681
|
TIMEOUT_FALLBACK,
|
|
@@ -610,6 +683,7 @@ var index_default = fetch2;
|
|
|
610
683
|
TimeoutPromise,
|
|
611
684
|
createClient,
|
|
612
685
|
createPostClient,
|
|
686
|
+
defaultErrorMsgs,
|
|
613
687
|
executeInterceptors,
|
|
614
688
|
fetch,
|
|
615
689
|
mergeOptions
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import * as _superutils_core from '@superutils/core';
|
|
2
|
-
import { ValueOrPromise, DropFirst } from '@superutils/core';
|
|
3
|
-
import * as _superutils_promise from '@superutils/promise';
|
|
4
1
|
import { RetryOptions, RetryIfFunc, TimeoutOptions, IPromisE_Timeout, DeferredAsyncOptions } from '@superutils/promise';
|
|
5
2
|
export { DeferredAsyncOptions, OnEarlyFinalize, OnFinalize, ResolveError, ResolveIgnored, RetryIfFunc, RetryOptions, TIMEOUT_FALLBACK, TIMEOUT_MAX, TimeoutOptions, TimeoutPromise } from '@superutils/promise';
|
|
3
|
+
import { ValueOrPromise, DropFirst } from '@superutils/core';
|
|
6
4
|
|
|
7
5
|
/** Commonly used content types for easier access */
|
|
8
6
|
declare const ContentType: {
|
|
@@ -279,6 +277,13 @@ type FetchCustomOptions = {
|
|
|
279
277
|
abortCtrl?: AbortController;
|
|
280
278
|
body?: PostArgs[1];
|
|
281
279
|
errMsgs?: FetchErrMsgs;
|
|
280
|
+
/**
|
|
281
|
+
* If set to `true`, the global `fetch.defaults` (including global headers, interceptors,
|
|
282
|
+
* and timeout settings) will not be merged into the options for this request.
|
|
283
|
+
*
|
|
284
|
+
* Default: `false`
|
|
285
|
+
*/
|
|
286
|
+
ignoreGlobalDefaults?: boolean;
|
|
282
287
|
/**
|
|
283
288
|
* Custom fetch function to use instead of the global `fetch`.
|
|
284
289
|
* Useful for testing or using a different fetch implementation (e.g. `node-fetch` in older Node versions).
|
|
@@ -314,7 +319,7 @@ type FetchFunc = (...args: FetchArgs) => Promise<Response>;
|
|
|
314
319
|
*/
|
|
315
320
|
type FetchOptions = Omit<RequestInit, 'body'> & FetchCustomOptions;
|
|
316
321
|
/** Default fetch options */
|
|
317
|
-
type FetchOptionsDefault = Omit<FetchOptionsInterceptor, 'abortCtrl' | 'as' | 'body' | 'method' | 'signal' | 'timeout' | 'headers'> & {
|
|
322
|
+
type FetchOptionsDefault = Omit<FetchOptionsInterceptor, 'abortCtrl' | 'as' | 'body' | 'ignoreGlobalDefaults' | 'method' | 'signal' | 'timeout' | 'headers'> & {
|
|
318
323
|
/**
|
|
319
324
|
* Request headers.
|
|
320
325
|
*
|
|
@@ -645,6 +650,75 @@ commonOptions?: PostOptions & CommonOptions, commonDeferOptions?: DeferredAsyncO
|
|
|
645
650
|
deferred<ThisArg, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] | undefined, DefaultOptions extends ExcludePostOptions<FixedOptions> | undefined = ExcludePostOptions<FixedOptions> | undefined, Delay extends CommonDelay | number = number>(deferOptions?: DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl, defaultData?: DefaultData, defaultOptions?: DefaultOptions): <T extends ClientData<FixedOptions> = never, Options_1 extends ExcludePostOptions<FixedOptions> | undefined = ExcludePostOptions<FixedOptions> | undefined, TReturn = GetFetchResult<[FixedOptions, Options_1, DefaultOptions, CommonOptions], T>>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, Options_1>) => IPromise_Fetch<TReturn>;
|
|
646
651
|
};
|
|
647
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Configuration for the ApiClient instance.
|
|
655
|
+
*/
|
|
656
|
+
type ApiClientConfig<
|
|
657
|
+
/** Options that are enforced for every request and cannot be overridden. */
|
|
658
|
+
FixedOptions extends ApiClientFetchOptions,
|
|
659
|
+
/** Default options that can be overridden by individual request calls. */
|
|
660
|
+
CommonOptions extends ExcludeOptions<FixedOptions, ApiClientFetchOptions>, CommonDelay extends number> = {
|
|
661
|
+
commonOptions?: CommonOptions;
|
|
662
|
+
commonDeferOptions?: DeferredAsyncOptions<unknown, CommonDelay>;
|
|
663
|
+
errorPrefix?: string;
|
|
664
|
+
fixedOptions?: FixedOptions;
|
|
665
|
+
withBaseClients?: boolean;
|
|
666
|
+
};
|
|
667
|
+
type ApiClientFetchOptions = Omit<FetchOptions, 'method'>;
|
|
668
|
+
/**
|
|
669
|
+
* A fully encapsulated and isolated API client factory.
|
|
670
|
+
*
|
|
671
|
+
* ApiClient creates a sandboxed environment for a specific API service. It provides
|
|
672
|
+
* complete isolation by ignoring global `fetch.defaults` by default, ensuring that instance-specific
|
|
673
|
+
* configurations remain clean and predictable. It bundles RESTful methods and execution
|
|
674
|
+
* controls (like debounce/throttle) into a single, cohesive unit.
|
|
675
|
+
*
|
|
676
|
+
* ### Key Features:
|
|
677
|
+
* - **Isolation**: Instance-specific options are scoped to this client and isolated from other instances.
|
|
678
|
+
* - **Base Resolution**: Automatic path joining when `apiBaseUrl` is provided.
|
|
679
|
+
* - **Unified Error Handling**: Optional `errorPrefix` to namespace errors for easier debugging.
|
|
680
|
+
* - **Method Suite**: Integrated `delete`, `get`, `head`, `options`, `patch`, `post` and `put` methods.
|
|
681
|
+
*
|
|
682
|
+
* ### Precedence & Merging Nuances
|
|
683
|
+
* - **Options follow a strict hierarchy**: `fixedOptions` > `call options` > `commonOptions`.
|
|
684
|
+
* - Global `fetch.defaults` are ignored by default.
|
|
685
|
+
* - **Headers**: Merged by key. Specifying headers in a call overrides common headers with the
|
|
686
|
+
* same name, but does NOT remove or replace the entire header set.
|
|
687
|
+
* - **Interceptors**: Cumulative. Interceptors from all levels are concatenated and executed
|
|
688
|
+
* sequentially (Common -> Call -> Fixed). They cannot be overridden or replaced.
|
|
689
|
+
* - **Error Messages**: Merged by key, allowing per-service or per-call customization of
|
|
690
|
+
* specific error strings without losing the rest of the global message set.
|
|
691
|
+
*/
|
|
692
|
+
declare class ApiClient<FixedOptions extends ApiClientFetchOptions = {}, // "{}" is required to correct infer common options
|
|
693
|
+
CommonOptions extends ExcludeOptions<FixedOptions, ApiClientFetchOptions> = ExcludeOptions<FixedOptions, ApiClientFetchOptions>, CommonDelay extends number = number> {
|
|
694
|
+
apiBaseUrl?: string | undefined;
|
|
695
|
+
/** The base GET-style client. Defaults to GET method. */
|
|
696
|
+
readonly client: ReturnType<typeof createClient<FixedOptions, CommonOptions, CommonDelay>>;
|
|
697
|
+
/** The base POST-style client. Defaults to POST method and supports request bodies. */
|
|
698
|
+
readonly postClient: ReturnType<typeof createPostClient<FixedOptions, CommonOptions, CommonDelay>>;
|
|
699
|
+
/** Alias for postClient with DELETE method. */
|
|
700
|
+
readonly delete: typeof this.postClient;
|
|
701
|
+
/** Alias for client with GET method. */
|
|
702
|
+
readonly get: typeof this.client;
|
|
703
|
+
/** Alias for client with HEAD method. */
|
|
704
|
+
readonly head: typeof this.client;
|
|
705
|
+
/** Alias for client with OPTIONS method. */
|
|
706
|
+
readonly options: typeof this.client;
|
|
707
|
+
/** Alias for postClient with POST method. */
|
|
708
|
+
readonly post: typeof this.postClient;
|
|
709
|
+
/** Alias for postClient with PUT method. */
|
|
710
|
+
readonly put: typeof this.postClient;
|
|
711
|
+
/** Alias for postClient with PATCH method. */
|
|
712
|
+
readonly patch: typeof this.postClient;
|
|
713
|
+
/**
|
|
714
|
+
* Creates a new ApiClient instance.
|
|
715
|
+
*
|
|
716
|
+
* @param apiBaseUrl - The base URL for the API. Relative paths passed to methods will be appended to this.
|
|
717
|
+
* @param config - Optional configuration for headers, interceptors, and default behavior.
|
|
718
|
+
*/
|
|
719
|
+
constructor(apiBaseUrl?: string | undefined, config?: ApiClientConfig<FixedOptions, CommonOptions, CommonDelay>);
|
|
720
|
+
}
|
|
721
|
+
|
|
648
722
|
/**
|
|
649
723
|
* Gracefully executes interceptors and returns the processed value.
|
|
650
724
|
* If the value is not transformed (by returning a new value) by the interceptors,
|
|
@@ -662,9 +736,11 @@ commonOptions?: PostOptions & CommonOptions, commonDeferOptions?: DeferredAsyncO
|
|
|
662
736
|
*/
|
|
663
737
|
declare const executeInterceptors: <T, TArgs extends unknown[]>(value: T, signal?: AbortSignal, interceptors?: Interceptor<T, TArgs>[], ...args: TArgs) => Promise<T>;
|
|
664
738
|
|
|
739
|
+
declare const defaultErrorMsgs: Required<FetchErrMsgs>;
|
|
740
|
+
declare const POST_METHODS: string[];
|
|
665
741
|
declare const fetch$1: {
|
|
666
742
|
<T = unknown, TOptions extends FetchOptions = FetchOptions, TAs extends FetchAs = TOptions["as"] extends FetchAs ? TOptions["as"] : FetchAs.response, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: FetchOptions & TOptions): IPromise_Fetch<TReturn>;
|
|
667
|
-
/**
|
|
743
|
+
/** Global default fetch options */
|
|
668
744
|
defaults: FetchOptionsDefault;
|
|
669
745
|
};
|
|
670
746
|
|
|
@@ -683,183 +759,6 @@ declare const fetch$1: {
|
|
|
683
759
|
*/
|
|
684
760
|
declare const mergeOptions: (...allOptions: (FetchOptions | undefined)[]) => FetchOptionsInterceptor;
|
|
685
761
|
|
|
686
|
-
declare const methods: {
|
|
687
|
-
/** Make HTTP requests with method GET */
|
|
688
|
-
get: {
|
|
689
|
-
<T extends unknown = never, TOptions extends ({
|
|
690
|
-
headers?: HeadersInit | undefined;
|
|
691
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
692
|
-
headers?: HeadersInit | undefined;
|
|
693
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
694
|
-
method: string;
|
|
695
|
-
}, TOptions, ({
|
|
696
|
-
headers?: HeadersInit | undefined;
|
|
697
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: FetchArgs[0], options?: TOptions | undefined): IPromise_Fetch<Result>;
|
|
698
|
-
deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = URL | RequestInfo | undefined, DefaultOptions extends ({
|
|
699
|
-
headers?: HeadersInit | undefined;
|
|
700
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
701
|
-
headers?: HeadersInit | undefined;
|
|
702
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, TOptions extends ({
|
|
703
|
-
headers?: HeadersInit | undefined;
|
|
704
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
705
|
-
headers?: HeadersInit | undefined;
|
|
706
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
707
|
-
method: string;
|
|
708
|
-
}, TOptions, DefaultOptions, ({
|
|
709
|
-
headers?: HeadersInit | undefined;
|
|
710
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: DefaultUrl extends undefined ? [url: URL | RequestInfo, options?: TOptions | undefined] : [options?: TOptions | undefined]) => IPromise_Fetch<Result>;
|
|
711
|
-
};
|
|
712
|
-
/** Make HTTP requests with method HEAD */
|
|
713
|
-
head: {
|
|
714
|
-
<T extends unknown = never, TOptions extends ({
|
|
715
|
-
headers?: HeadersInit | undefined;
|
|
716
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
717
|
-
headers?: HeadersInit | undefined;
|
|
718
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
719
|
-
method: string;
|
|
720
|
-
}, TOptions, ({
|
|
721
|
-
headers?: HeadersInit | undefined;
|
|
722
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: FetchArgs[0], options?: TOptions | undefined): IPromise_Fetch<Result>;
|
|
723
|
-
deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = URL | RequestInfo | undefined, DefaultOptions extends ({
|
|
724
|
-
headers?: HeadersInit | undefined;
|
|
725
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
726
|
-
headers?: HeadersInit | undefined;
|
|
727
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, TOptions extends ({
|
|
728
|
-
headers?: HeadersInit | undefined;
|
|
729
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
730
|
-
headers?: HeadersInit | undefined;
|
|
731
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
732
|
-
method: string;
|
|
733
|
-
}, TOptions, DefaultOptions, ({
|
|
734
|
-
headers?: HeadersInit | undefined;
|
|
735
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: DefaultUrl extends undefined ? [url: URL | RequestInfo, options?: TOptions | undefined] : [options?: TOptions | undefined]) => IPromise_Fetch<Result>;
|
|
736
|
-
};
|
|
737
|
-
/** Make HTTP requests with method OPTIONS */
|
|
738
|
-
options: {
|
|
739
|
-
<T extends unknown = never, TOptions extends ({
|
|
740
|
-
headers?: HeadersInit | undefined;
|
|
741
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
742
|
-
headers?: HeadersInit | undefined;
|
|
743
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
744
|
-
method: string;
|
|
745
|
-
}, TOptions, ({
|
|
746
|
-
headers?: HeadersInit | undefined;
|
|
747
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: FetchArgs[0], options?: TOptions | undefined): IPromise_Fetch<Result>;
|
|
748
|
-
deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = URL | RequestInfo | undefined, DefaultOptions extends ({
|
|
749
|
-
headers?: HeadersInit | undefined;
|
|
750
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
751
|
-
headers?: HeadersInit | undefined;
|
|
752
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, TOptions extends ({
|
|
753
|
-
headers?: HeadersInit | undefined;
|
|
754
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
755
|
-
headers?: HeadersInit | undefined;
|
|
756
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
757
|
-
method: string;
|
|
758
|
-
}, TOptions, DefaultOptions, ({
|
|
759
|
-
headers?: HeadersInit | undefined;
|
|
760
|
-
} & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: DefaultUrl extends undefined ? [url: URL | RequestInfo, options?: TOptions | undefined] : [options?: TOptions | undefined]) => IPromise_Fetch<Result>;
|
|
761
|
-
};
|
|
762
|
-
/** Make HTTP requests with method DELETE */
|
|
763
|
-
delete: {
|
|
764
|
-
<T extends unknown = never, Options extends ({
|
|
765
|
-
headers?: HeadersInit | undefined;
|
|
766
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
767
|
-
headers?: HeadersInit | undefined;
|
|
768
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
769
|
-
method: "delete";
|
|
770
|
-
}, Options, ({
|
|
771
|
-
headers?: HeadersInit | undefined;
|
|
772
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: PostArgs[0], data?: PostArgs[1], options?: Options | undefined): IPromise_Fetch<Result>;
|
|
773
|
-
deferred<ThisArg, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] | undefined, DefaultOptions extends ({
|
|
774
|
-
headers?: HeadersInit | undefined;
|
|
775
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
776
|
-
headers?: HeadersInit | undefined;
|
|
777
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Delay extends number = number>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, Options extends ({
|
|
778
|
-
headers?: HeadersInit | undefined;
|
|
779
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
780
|
-
headers?: HeadersInit | undefined;
|
|
781
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TReturn = GetFetchResult<[{
|
|
782
|
-
method: "delete";
|
|
783
|
-
}, Options, DefaultOptions, ({
|
|
784
|
-
headers?: HeadersInit | undefined;
|
|
785
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, Options, [url: URL | RequestInfo, data: PostBody | (() => _superutils_core.ValueOrPromise<PostBody>), options: PostOptions], undefined extends DefaultUrl ? DefaultUrl & undefined : DefaultUrl, undefined extends DefaultData ? DefaultData & undefined : DefaultData>) => IPromise_Fetch<TReturn>;
|
|
786
|
-
};
|
|
787
|
-
/** Make HTTP requests with method PATCH */
|
|
788
|
-
patch: {
|
|
789
|
-
<T extends unknown = never, Options extends ({
|
|
790
|
-
headers?: HeadersInit | undefined;
|
|
791
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
792
|
-
headers?: HeadersInit | undefined;
|
|
793
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
794
|
-
method: "patch";
|
|
795
|
-
}, Options, ({
|
|
796
|
-
headers?: HeadersInit | undefined;
|
|
797
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: PostArgs[0], data?: PostArgs[1], options?: Options | undefined): IPromise_Fetch<Result>;
|
|
798
|
-
deferred<ThisArg, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] | undefined, DefaultOptions extends ({
|
|
799
|
-
headers?: HeadersInit | undefined;
|
|
800
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
801
|
-
headers?: HeadersInit | undefined;
|
|
802
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Delay extends number = number>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, Options extends ({
|
|
803
|
-
headers?: HeadersInit | undefined;
|
|
804
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
805
|
-
headers?: HeadersInit | undefined;
|
|
806
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TReturn = GetFetchResult<[{
|
|
807
|
-
method: "patch";
|
|
808
|
-
}, Options, DefaultOptions, ({
|
|
809
|
-
headers?: HeadersInit | undefined;
|
|
810
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, Options, [url: URL | RequestInfo, data: PostBody | (() => _superutils_core.ValueOrPromise<PostBody>), options: PostOptions], undefined extends DefaultUrl ? DefaultUrl & undefined : DefaultUrl, undefined extends DefaultData ? DefaultData & undefined : DefaultData>) => IPromise_Fetch<TReturn>;
|
|
811
|
-
};
|
|
812
|
-
/** Make HTTP requests with method POST */
|
|
813
|
-
post: {
|
|
814
|
-
<T extends unknown = never, Options extends ({
|
|
815
|
-
headers?: HeadersInit | undefined;
|
|
816
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
817
|
-
headers?: HeadersInit | undefined;
|
|
818
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
819
|
-
method: "post";
|
|
820
|
-
}, Options, ({
|
|
821
|
-
headers?: HeadersInit | undefined;
|
|
822
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: PostArgs[0], data?: PostArgs[1], options?: Options | undefined): IPromise_Fetch<Result>;
|
|
823
|
-
deferred<ThisArg, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] | undefined, DefaultOptions extends ({
|
|
824
|
-
headers?: HeadersInit | undefined;
|
|
825
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
826
|
-
headers?: HeadersInit | undefined;
|
|
827
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Delay extends number = number>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, Options extends ({
|
|
828
|
-
headers?: HeadersInit | undefined;
|
|
829
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
830
|
-
headers?: HeadersInit | undefined;
|
|
831
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TReturn = GetFetchResult<[{
|
|
832
|
-
method: "post";
|
|
833
|
-
}, Options, DefaultOptions, ({
|
|
834
|
-
headers?: HeadersInit | undefined;
|
|
835
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, Options, [url: URL | RequestInfo, data: PostBody | (() => _superutils_core.ValueOrPromise<PostBody>), options: PostOptions], undefined extends DefaultUrl ? DefaultUrl & undefined : DefaultUrl, undefined extends DefaultData ? DefaultData & undefined : DefaultData>) => IPromise_Fetch<TReturn>;
|
|
836
|
-
};
|
|
837
|
-
/** Make HTTP requests with method PUT */
|
|
838
|
-
put: {
|
|
839
|
-
<T extends unknown = never, Options extends ({
|
|
840
|
-
headers?: HeadersInit | undefined;
|
|
841
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
842
|
-
headers?: HeadersInit | undefined;
|
|
843
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Result = GetFetchResult<[{
|
|
844
|
-
method: "put";
|
|
845
|
-
}, Options, ({
|
|
846
|
-
headers?: HeadersInit | undefined;
|
|
847
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(url: PostArgs[0], data?: PostArgs[1], options?: Options | undefined): IPromise_Fetch<Result>;
|
|
848
|
-
deferred<ThisArg, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] | undefined, DefaultOptions extends ({
|
|
849
|
-
headers?: HeadersInit | undefined;
|
|
850
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
851
|
-
headers?: HeadersInit | undefined;
|
|
852
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, Delay extends number = number>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay> | undefined, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <T extends unknown = never, Options extends ({
|
|
853
|
-
headers?: HeadersInit | undefined;
|
|
854
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
|
|
855
|
-
headers?: HeadersInit | undefined;
|
|
856
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TReturn = GetFetchResult<[{
|
|
857
|
-
method: "put";
|
|
858
|
-
}, Options, DefaultOptions, ({
|
|
859
|
-
headers?: HeadersInit | undefined;
|
|
860
|
-
} & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined], T>>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, Options, [url: URL | RequestInfo, data: PostBody | (() => _superutils_core.ValueOrPromise<PostBody>), options: PostOptions], undefined extends DefaultUrl ? DefaultUrl & undefined : DefaultUrl, undefined extends DefaultData ? DefaultData & undefined : DefaultData>) => IPromise_Fetch<TReturn>;
|
|
861
|
-
};
|
|
862
|
-
};
|
|
863
762
|
/**
|
|
864
763
|
* A `fetch()` replacement that simplifies data fetching with automatic JSON parsing, request timeouts, retries,
|
|
865
764
|
* and handy interceptors that also work as transformers. It also includes deferred and throttled request
|
|
@@ -982,6 +881,6 @@ declare const methods: {
|
|
|
982
881
|
* })
|
|
983
882
|
* ```
|
|
984
883
|
*/
|
|
985
|
-
declare const fetch: typeof fetch$1 &
|
|
884
|
+
declare const fetch: typeof fetch$1 & ApiClient;
|
|
986
885
|
|
|
987
|
-
export { type ClientData, ContentType, type ExcludeOptions, type ExcludePostOptions, type ExtractAs, type FetchArgs, type FetchArgsInterceptor, FetchAs, type FetchCustomOptions, type FetchErrMsgs, FetchError, type FetchFunc, type FetchInterceptorError, type FetchInterceptorRequest, type FetchInterceptorResponse, type FetchInterceptorResult, type FetchInterceptors, type FetchInterceptorsMerged, type FetchOptions, type FetchOptionsDefault, type FetchOptionsInterceptor, type FetchResult, type FetchRetryOptions, type GetFetchResult, type IPromise_Fetch, type Interceptor, type OnDownloadProgress, type PostArgs, type PostBody, type PostDeferredCbArgs, type PostOptions, createClient, createPostClient, fetch as default, executeInterceptors, fetch, mergeOptions };
|
|
886
|
+
export { ApiClient, type ApiClientConfig, type ApiClientFetchOptions, type ClientData, ContentType, type ExcludeOptions, type ExcludePostOptions, type ExtractAs, type FetchArgs, type FetchArgsInterceptor, FetchAs, type FetchCustomOptions, type FetchErrMsgs, FetchError, type FetchFunc, type FetchInterceptorError, type FetchInterceptorRequest, type FetchInterceptorResponse, type FetchInterceptorResult, type FetchInterceptors, type FetchInterceptorsMerged, type FetchOptions, type FetchOptionsDefault, type FetchOptionsInterceptor, type FetchResult, type FetchRetryOptions, type GetFetchResult, type IPromise_Fetch, type Interceptor, type OnDownloadProgress, POST_METHODS, type PostArgs, type PostBody, type PostDeferredCbArgs, type PostOptions, createClient, createPostClient, fetch as default, defaultErrorMsgs, executeInterceptors, fetch, mergeOptions };
|