@superutils/fetch 1.2.3 → 1.4.1

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.
Files changed (4) hide show
  1. package/README.md +97 -100
  2. package/dist/index.d.ts +275 -157
  3. package/dist/index.js +188 -172
  4. package/package.json +6 -5
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _superutils_promise from '@superutils/promise';
2
- import { RetryOptions, RetryIfFunc, DeferredAsyncOptions, IPromisE } from '@superutils/promise';
2
+ import { RetryOptions, RetryIfFunc, TimeoutOptions, DeferredAsyncOptions, IPromisE_Timeout } from '@superutils/promise';
3
3
  export { DeferredAsyncOptions, ResolveError, ResolveIgnored } from '@superutils/promise';
4
4
  import { ValueOrPromise } from '@superutils/core';
5
5
 
@@ -19,16 +19,6 @@ declare const ContentType: {
19
19
  readonly TEXT_PLAIN: "text/plain";
20
20
  readonly VIDEO_MP4: "video/mp4";
21
21
  };
22
- type ExcludeOptions<Target, // options to exclude
23
- Options extends FetchOptions = FetchOptions> = Target extends FetchOptions ? {
24
- headers?: Options['headers'];
25
- } & Omit<Options, 'headers' | keyof Target> & Partial<Record<Exclude<keyof Target, 'headers'>, never>> : Options;
26
- type ExcludePostOptions<Target> = ExcludeOptions<Target, PostOptions>;
27
- type FetchArgs = [url: string | URL, options?: FetchOptions];
28
- type FetchArgsInterceptor = [
29
- url: string | URL,
30
- options: FetchOptionsInterceptor
31
- ];
32
22
  declare enum FetchAs {
33
23
  arrayBuffer = "arrayBuffer",
34
24
  blob = "blob",
@@ -38,53 +28,18 @@ declare enum FetchAs {
38
28
  response = "response",
39
29
  text = "text"
40
30
  }
41
- /** Extract `FetchAs` from `FetchOptions` */
42
- type FetchAsFromOptions<TOptions, TFallback = FetchAs.json> = TOptions extends {
43
- as: infer As;
44
- } ? As extends FetchAs ? As : TFallback : TFallback;
45
- /** Custom fetch options (not used by built-in `fetch()`*/
46
- type FetchCustomOptions = {
47
- /**
48
- * Specify how the parse the result. To get raw response use {@link FetchAs.response}.
49
- * Default: 'json'
50
- */
51
- as?: FetchAs;
52
- abortCtrl?: AbortController;
53
- body?: PostBody | (() => PostBody);
54
- errMsgs?: FetchErrMsgs;
55
- interceptors?: FetchInterceptors;
56
- /** Request timeout in milliseconds. */
57
- timeout?: number;
58
- validateUrl?: boolean;
59
- } & FetchRetryOptions;
60
- /** Default args */
61
- type FetchDeferredArgs<OmitMethod extends boolean = false> = [
62
- url?: string | URL,
63
- options?: Omit<FetchOptions, 'abortCtrl' | (OmitMethod extends true ? 'method' : never)>
64
- ];
65
- type FetchErrMsgs = {
66
- invalidUrl?: string;
67
- parseFailed?: string;
68
- reqTimedout?: string;
69
- requestFailed?: string;
70
- };
71
- /** Custom error message for fetch requests with more detailed info about the request URL, fetch options and response */
72
- declare class FetchError extends Error {
73
- options: FetchOptions;
74
- response?: Response;
75
- url: string | URL;
76
- constructor(message: string, options: {
77
- cause?: unknown;
78
- options: FetchOptions;
79
- response?: Response;
80
- url: string | URL;
81
- });
82
- clone: (newMessage: string) => FetchError;
83
- }
31
+
32
+ /**
33
+ * Generic definition for interceptor and transformer callbacks used throughout the fetch lifecycle.
34
+ */
35
+ type Interceptor<T, TArgs extends unknown[]> = (...args: [value: T, ...TArgs]) => ValueOrPromise<void> | ValueOrPromise<T>;
84
36
  /**
85
37
  * Fetch error interceptor to be invoked whenever an exception occurs.
86
38
  * This interceptor can also be used as the error transformer by returning {@link FetchError}.
87
39
  *
40
+ * Note: The error interceptor is only triggered if the request ultimately fails. If retries are enabled (`retry > 0`)
41
+ * and a subsequent attempt succeeds, this interceptor will not be invoked for the intermediate failures.
42
+ *
88
43
  * @param {FetchError} fetchError custom error that also contain URL, options & response
89
44
  *
90
45
  * @returns returning undefined or not returning anything will not override the error
@@ -217,10 +172,10 @@ type FetchInterceptorResult<Args extends unknown[] = FetchArgsInterceptor> = Int
217
172
  /**
218
173
  * All valid interceptors for fetch requests are:
219
174
  * ---
220
- * 1. error,
175
+ * 1. error
221
176
  * 2. request
222
177
  * 3. response
223
- * 4. result.
178
+ * 4. result
224
179
  *
225
180
  * An interceptor can be any of the following:
226
181
  * ---
@@ -239,10 +194,9 @@ type FetchInterceptorResult<Args extends unknown[] = FetchArgsInterceptor> = Int
239
194
  * 1. Any exception thrown by interceptors will gracefully ignored.
240
195
  * 2. Interceptors will be executed in the sequence they're given.
241
196
  * 3. Execution priority: global interceptors will always be executed before local interceptors.
197
+ * 4. The following options cannot be modified using interceptors: abortCtrl, as, signal, timeout
242
198
  *
243
- *
244
- *
245
- * More info & examples:
199
+ * More info about specific interceptor types & examples:
246
200
  * ---
247
201
  * See the following for more details and examples:
248
202
  *
@@ -252,24 +206,107 @@ type FetchInterceptorResult<Args extends unknown[] = FetchArgsInterceptor> = Int
252
206
  * - `result`: {@link FetchInterceptorResult}
253
207
  */
254
208
  type FetchInterceptors = {
209
+ /** Request error interceptors/transformers. See {@link FetchInterceptorError} for more details. */
255
210
  error?: FetchInterceptorError[];
211
+ /** Request request interceptors/transformers. See {@link FetchInterceptorRequest} for more details. */
256
212
  request?: FetchInterceptorRequest[];
213
+ /** Request response interceptors/transformers. See {@link FetchInterceptorResponse} for more details. */
257
214
  response?: FetchInterceptorResponse[];
215
+ /** Request result interceptors/transformers. See {@link FetchInterceptorResult} for more details. */
258
216
  result?: FetchInterceptorResult[];
259
217
  };
218
+
219
+ type ExcludeOptions<Target, // options to exclude
220
+ Options extends FetchOptions = FetchOptions> = Target extends FetchOptions ? {
221
+ headers?: Options['headers'];
222
+ } & Omit<Options, 'headers' | keyof Target> & Partial<Record<Exclude<keyof Target, 'headers'>, never>> : Options;
223
+ type ExcludePostOptions<Target> = ExcludeOptions<Target, PostOptions>;
224
+ type FetchArgs = [url: string | URL, options?: FetchOptions];
225
+ type FetchArgsInterceptor = [
226
+ url: string | URL,
227
+ options: FetchOptionsInterceptor
228
+ ];
229
+ /** Extract `FetchAs` from `FetchOptions` */
230
+ type FetchAsFromOptions<TOptions, TFallback = FetchAs.json> = TOptions extends {
231
+ as: infer As;
232
+ } ? As extends FetchAs ? As : TFallback : TFallback;
233
+ /** Custom fetch options (not used by built-in `fetch()`*/
234
+ type FetchCustomOptions = {
235
+ /**
236
+ * Specify how the parse the result. To get raw response use {@link FetchAs.response}.
237
+ * Default: 'json'
238
+ */
239
+ as?: FetchAs;
240
+ /**
241
+ * An `AbortController` instance to control the request.
242
+ *
243
+ * If not provided, a new instance is automatically created internally.
244
+ *
245
+ * It is supported in addition to the standard `signal`. If both are provided, `abortCtrl` will be aborted
246
+ * when the `signal` aborts or when the request times out.
247
+ *
248
+ * Recommendation:
249
+ * - For request timeout purposes, setting a timeout duration will be sufficient.
250
+ * Abort controller/signal is not needed.
251
+ * - Use `abortCtrl` instead of `signal` to prevent creating internal `AbortController` instance.
252
+ */
253
+ abortCtrl?: AbortController;
254
+ body?: PostBody | (() => PostBody);
255
+ /**
256
+ * Custom fetch function to use instead of the global `fetch`.
257
+ * Useful for testing or using a different fetch implementation (e.g. `node-fetch` in older Node versions).
258
+ *
259
+ * Default: `globalThis.fetch`
260
+ */
261
+ fetchFunc?: FetchFunc;
262
+ errMsgs?: FetchErrMsgs;
263
+ /**
264
+ * Interceptor/transformer callback executed at different stages of the request.
265
+ * See {@link FetchInterceptors} for more details.
266
+ */
267
+ interceptors?: FetchInterceptors;
268
+ /** Whether to validate URL before making the request. Default: `true` */
269
+ validateUrl?: boolean;
270
+ } & FetchRetryOptions & TimeoutOptions<[]>;
271
+ /** Default args */
272
+ type FetchDeferredArgs<OmitMethod extends boolean = false> = [
273
+ url?: string | URL,
274
+ options?: Omit<FetchOptions, 'abortCtrl' | (OmitMethod extends true ? 'method' : never)>
275
+ ];
276
+ type FetchErrMsgs = {
277
+ /** Error message to be used when request is aborted without specifying a message */
278
+ aborted?: string;
279
+ /** Error message to be use when URL validation fails */
280
+ invalidUrl?: string;
281
+ /** Error message to be used when request parse failes */
282
+ parseFailed?: string;
283
+ /** Error message to be used when request times out */
284
+ timedout?: string;
285
+ /** Error message to be used when request fails */
286
+ requestFailed?: string;
287
+ };
288
+ type FetchFunc = (...args: FetchArgs) => Promise<Response>;
260
289
  /**
261
290
  * Fetch request options
262
291
  */
263
292
  type FetchOptions = Omit<RequestInit, 'body'> & FetchCustomOptions;
264
- type FetchOptionsDefaults = Omit<FetchOptionsInterceptor, 'as' | 'method'>;
293
+ /** Default fetch options */
294
+ type FetchOptionsDefault = Omit<FetchOptionsInterceptor, 'abortCtrl' | 'as' | 'method' | 'signal' | 'timeout'> & {
295
+ /** Request timeout duration in milliseconds. Default: `30_000` (30 seconds) */
296
+ timeout: number;
297
+ };
265
298
  /**
266
- * Fetch options available to interceptors
299
+ * Fetch options available to interceptors.
300
+ *
267
301
  */
268
- type FetchOptionsInterceptor = Omit<FetchOptions, 'as' | 'errMsgs' | 'interceptors' | 'headers' | keyof FetchRetryOptions> & {
302
+ type FetchOptionsInterceptor = Omit<FetchOptions, 'as' | 'errMsgs' | 'interceptors' | 'headers' | 'timeout' | keyof FetchRetryOptions> & {
269
303
  as: FetchAs;
304
+ /** Error messages */
270
305
  errMsgs: Required<FetchErrMsgs>;
271
306
  headers: Headers;
307
+ /** Interceptors/transformers for fetch requests. See {@link FetchInterceptors} for more details. */
272
308
  interceptors: Required<FetchInterceptors>;
309
+ timeout: number;
273
310
  } & FetchRetryOptions;
274
311
  /**
275
312
  * Result types for specific parsers ("as": FetchAs)
@@ -297,10 +334,6 @@ type FetchRetryOptions = Omit<Partial<RetryOptions>, 'retry' | 'retryIf'> & {
297
334
  retry?: number;
298
335
  retryIf?: RetryIfFunc<Response>;
299
336
  };
300
- /**
301
- * Generic fetch interceptor type
302
- */
303
- type Interceptor<T, TArgs extends unknown[]> = (...args: [value: T, ...TArgs]) => ValueOrPromise<void> | ValueOrPromise<T>;
304
337
  type PostBody = Record<string, unknown> | BodyInit | null;
305
338
  type PostArgs<OmitMethod = false> = [
306
339
  url: string | URL,
@@ -356,6 +389,21 @@ type PostOptions = {
356
389
  method?: 'post' | 'put' | 'patch' | 'delete' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
357
390
  } & Omit<FetchOptions, 'method'>;
358
391
 
392
+ /** Custom error message for fetch requests with more detailed info about the request URL, fetch options and response */
393
+ declare class FetchError extends Error {
394
+ /** Create a new `FetchError` with a new `message` while preserving all metadata */
395
+ clone: (newMessage: string) => FetchError;
396
+ options: FetchOptions;
397
+ response: Response | undefined;
398
+ url: string | URL;
399
+ constructor(message: string, options: {
400
+ cause?: unknown;
401
+ options: FetchOptions;
402
+ response?: Response;
403
+ url: string | URL;
404
+ });
405
+ }
406
+
359
407
  /**
360
408
  * Create a reusable fetch client with shared options. The returned function comes attached with a
361
409
  * `.deferred()` function for debounce and throttle behavior.
@@ -412,13 +460,17 @@ type PostOptions = {
412
460
  * .then(console.log, console.warn)
413
461
  * ```
414
462
  */
415
- declare const createClient: <FixedOpts extends FetchOptions | undefined, CommonOpts extends ExcludeOptions<FixedOpts> | undefined, FixedAs extends FetchAs | undefined = FetchAsFromOptions<FixedOpts, undefined>>(
463
+ declare const createClient: <FixedOpts extends FetchOptions | undefined, CommonOpts extends ExcludeOptions<FixedOpts> | undefined, FixedAs extends FetchAs | undefined = FetchAsFromOptions<FixedOpts, undefined>, CommonDelay extends number = number>(
416
464
  /** Mandatory fetch options that cannot be overriden by individual request */
417
465
  fixedOptions?: FixedOpts,
418
466
  /** Common fetch options that can be overriden by individual request */
419
- commonOptions?: FetchOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOptions<unknown, unknown>) => {
420
- <T, TOptions extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined, TAs extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions, FetchAsFromOptions<CommonOpts>>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions): IPromisE<TReturn>;
421
- deferred<ThisArg = unknown, Delay extends number = number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined>(deferOptions?: DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl, defaultOptions?: DefaultOptions): <TResult = unknown, TOptions_1 extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined, TAs_1 extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions_1, FetchAsFromOptions<CommonOpts>>, TReturn_1 = FetchResult<TResult>[TAs_1]>(...args: DefaultUrl extends undefined ? [url: FetchArgs[0], options?: TOptions_1] : [options?: TOptions_1]) => IPromisE<TReturn_1>;
467
+ commonOptions?: FetchOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOptions<unknown, CommonDelay>) => {
468
+ <T = unknown, TOptions extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined, TAs extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions, FetchAsFromOptions<CommonOpts>>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
469
+ abortCtrl: AbortController;
470
+ };
471
+ deferred<ThisArg, Delay extends CommonDelay | number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined>(deferOptions?: DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl, defaultOptions?: DefaultOptions): <TResult = unknown, TOptions_1 extends ExcludeOptions<FixedOpts> | undefined = ExcludeOptions<FixedOpts> | undefined, TAs_1 extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions_1, FetchAsFromOptions<CommonOpts>>, TReturn_1 = FetchResult<TResult>[TAs_1]>(...args: DefaultUrl extends undefined ? [url: FetchArgs[0], options?: TOptions_1] : [options?: TOptions_1]) => Omit<_superutils_promise.IPromisE_Timeout<TReturn_1>, "abortCtrl"> & {
472
+ abortCtrl: AbortController;
473
+ };
422
474
  };
423
475
 
424
476
  /**
@@ -455,8 +507,9 @@ commonOptions?: FetchOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOpt
455
507
  * const updateProduct = postClient.deferred(
456
508
  * {
457
509
  * delayMs: 300, // debounce duration
510
+ * onResult: console.log, // prints only successful results
458
511
  * },
459
- * 'https://dummyjson.com/products/1',
512
+ * 'https://dummyjson.com/products/add',
460
513
  * {
461
514
  * method: 'patch',
462
515
  * timeout: 3000,
@@ -466,29 +519,21 @@ commonOptions?: FetchOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOpt
466
519
  * updateProduct({ title: 'New title 2' }) // executed
467
520
  * ```
468
521
  */
469
- declare const createPostClient: <FixedOpts extends PostOptions | undefined, CommonOpts extends ExcludePostOptions<FixedOpts> | undefined, FixedAs extends FetchAs | undefined = FetchAsFromOptions<FixedOpts, undefined>>(
522
+ declare const createPostClient: <FixedOpts extends PostOptions | undefined, CommonOpts extends ExcludePostOptions<FixedOpts> | undefined, FixedAs extends FetchAs | undefined = FetchAsFromOptions<FixedOpts, undefined>, CommonDelay extends number = number>(
470
523
  /** Mandatory fetch options that cannot be overriden by individual request */
471
524
  fixedOptions?: FixedOpts,
472
525
  /** Common fetch options that can be overriden by individual request */
473
- commonOptions?: PostOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOptions<unknown, unknown>) => {
474
- <T = unknown, TOptions extends ExcludePostOptions<FixedOpts> | undefined = ExcludePostOptions<FixedOpts> | undefined, TAs extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions, FetchAsFromOptions<CommonOpts>>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions): IPromisE<TReturn>;
475
- deferred<ThisArg, Delay extends number, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] = undefined, DefaultOptions extends ExcludePostOptions<FixedOpts> | undefined = undefined>(deferOptions?: DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl, defaultData?: DefaultData, defaultOptions?: DefaultOptions): <TResult = unknown, TOptions_1 extends ExcludePostOptions<FixedOpts> | undefined = ExcludePostOptions<FixedOpts>, TAs_1 extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions_1, FetchAsFromOptions<CommonOpts>>, TReturn_1 = FetchResult<TResult>[TAs_1]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions_1>) => IPromisE<TReturn_1>;
526
+ commonOptions?: PostOptions & CommonOpts, commonDeferOptions?: DeferredAsyncOptions<unknown, CommonDelay>) => {
527
+ <T = unknown, TOptions extends ExcludePostOptions<FixedOpts> | undefined = ExcludePostOptions<FixedOpts> | undefined, TAs extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions, FetchAsFromOptions<CommonOpts>>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
528
+ abortCtrl: AbortController;
529
+ };
530
+ deferred<ThisArg, Delay extends CommonDelay | number, DefaultOptions extends ExcludePostOptions<FixedOpts> | undefined = ExcludePostOptions<FixedOpts> | undefined, DefaultUrl extends PostArgs[0] | undefined = string | URL | undefined, DefaultData extends PostArgs[1] = PostBody | (() => PostBody) | undefined>(deferOptions?: DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl, defaultData?: DefaultData, defaultOptions?: DefaultOptions): <TResult = unknown, TOptions_1 extends ExcludePostOptions<FixedOpts> | undefined = ExcludePostOptions<FixedOpts> | undefined, TAs_1 extends FetchAs = FixedAs extends FetchAs ? FixedAs : FetchAsFromOptions<TOptions_1, FetchAsFromOptions<CommonOpts>>, TReturn_1 = FetchResult<TResult>[TAs_1]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions_1>) => Omit<_superutils_promise.IPromisE_Timeout<TReturn_1>, "abortCtrl"> & {
531
+ abortCtrl: AbortController;
532
+ };
476
533
  };
477
534
 
478
- /**
479
- * Gracefully executes interceptors and returns the processed value.
480
- * If the value is not transformed (by returning a new value) by the interceptors,
481
- * the original value is returned.
482
- *
483
- * @param value value to be passed to the interceptors
484
- * @param interceptors interceptor callbacks
485
- * @param args (optional) common arguments to be supplied to all the interceptors in addition to
486
- * the `value' which will always be the first argument.
487
- *
488
- * Interceptor arguments: `[value, ...args]`
489
- */
490
- declare const executeInterceptors: <T, TArgs extends unknown[]>(value: T, interceptors?: Interceptor<T, TArgs>[], ...args: TArgs) => Promise<T>;
491
-
535
+ /** Node.js setTimeout limit is 2147483647 (2^31-1). Larger values fire immediately. */
536
+ declare const MAX_TIMEOUT = 2147483647;
492
537
  /**
493
538
  * Extended `fetch` with timeout, retry, and other options. Automatically parses as JSON by default on success.
494
539
  *
@@ -508,9 +553,12 @@ declare const executeInterceptors: <T, TArgs extends unknown[]>(value: T, interc
508
553
  * ```
509
554
  */
510
555
  declare const fetch: {
511
- <T, TOptions extends FetchOptions = FetchOptions, TAs extends FetchAs = TOptions["as"] extends FetchAs ? TOptions["as"] : FetchAs.json, TReturn = FetchResult<T>[TAs]>(url: string | URL, options?: FetchOptions & TOptions): IPromisE<TReturn>;
556
+ <T, TOptions extends FetchOptions = FetchOptions, TAs extends FetchAs = TOptions["as"] extends FetchAs ? TOptions["as"] : FetchAs.json, TReturn = FetchResult<T>[TAs]>(url: string | URL, options?: FetchOptions & TOptions): Omit<IPromisE_Timeout<TReturn>, "abortCtrl"> & {
557
+ /** An `AbortController` instance to control the request. */
558
+ abortCtrl: AbortController;
559
+ };
512
560
  /** Default fetch options */
513
- defaults: FetchOptionsDefaults;
561
+ defaults: FetchOptionsDefault;
514
562
  };
515
563
 
516
564
  /**
@@ -528,17 +576,24 @@ declare const fetch: {
528
576
  * .then(console.log, console.error)
529
577
  * ```
530
578
  */
531
- declare const fetchResponse: <T = Response, TOptions extends FetchOptions = FetchOptions, TAs extends FetchAs = TOptions["as"] extends FetchAs ? TOptions["as"] : FetchAs.response, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options: Parameters<typeof fetch<T, TOptions, TAs, TReturn>>[1]) => IPromisE<TReturn>;
579
+ declare const fetchResponse: {
580
+ <T = Response, TOptions extends FetchOptions = FetchOptions, TAs extends FetchAs = TOptions["as"] extends FetchAs ? TOptions["as"] : FetchAs.response, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: Parameters<typeof fetch<T, TOptions, TAs, TReturn>>[1]): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
581
+ abortCtrl: AbortController;
582
+ };
583
+ defaults: FetchOptionsDefault;
584
+ };
532
585
 
533
586
  declare const methods: {
534
587
  /** Make HTTP requests with method GET */
535
588
  get: {
536
- <T, TOptions extends ({
589
+ <T = unknown, TOptions extends ({
537
590
  headers?: HeadersInit | undefined;
538
591
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
539
592
  headers?: HeadersInit | undefined;
540
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
541
- deferred<ThisArg = unknown, Delay extends number = number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
593
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
594
+ abortCtrl: AbortController;
595
+ };
596
+ deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
542
597
  headers?: HeadersInit | undefined;
543
598
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
544
599
  headers?: HeadersInit | undefined;
@@ -546,16 +601,20 @@ declare const methods: {
546
601
  headers?: HeadersInit | undefined;
547
602
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
548
603
  headers?: HeadersInit | undefined;
549
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => _superutils_promise.IPromisE<TReturn>;
604
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
605
+ abortCtrl: AbortController;
606
+ };
550
607
  };
551
608
  /** Make HTTP requests with method HEAD */
552
609
  head: {
553
- <T, TOptions extends ({
610
+ <T = unknown, TOptions extends ({
554
611
  headers?: HeadersInit | undefined;
555
612
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
556
613
  headers?: HeadersInit | undefined;
557
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
558
- deferred<ThisArg = unknown, Delay extends number = number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
614
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
615
+ abortCtrl: AbortController;
616
+ };
617
+ deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
559
618
  headers?: HeadersInit | undefined;
560
619
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
561
620
  headers?: HeadersInit | undefined;
@@ -563,16 +622,20 @@ declare const methods: {
563
622
  headers?: HeadersInit | undefined;
564
623
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
565
624
  headers?: HeadersInit | undefined;
566
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => _superutils_promise.IPromisE<TReturn>;
625
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
626
+ abortCtrl: AbortController;
627
+ };
567
628
  };
568
629
  /** Make HTTP requests with method OPTIONS */
569
630
  options: {
570
- <T, TOptions extends ({
631
+ <T = unknown, TOptions extends ({
571
632
  headers?: HeadersInit | undefined;
572
633
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
573
634
  headers?: HeadersInit | undefined;
574
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
575
- deferred<ThisArg = unknown, Delay extends number = number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
635
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: FetchArgs[0], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
636
+ abortCtrl: AbortController;
637
+ };
638
+ deferred<ThisArg, Delay extends number, DefaultUrl extends FetchArgs[0] | undefined = string | URL | undefined, DefaultOptions extends ({
576
639
  headers?: HeadersInit | undefined;
577
640
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
578
641
  headers?: HeadersInit | undefined;
@@ -580,7 +643,9 @@ declare const methods: {
580
643
  headers?: HeadersInit | undefined;
581
644
  } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
582
645
  headers?: HeadersInit | undefined;
583
- } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => _superutils_promise.IPromisE<TReturn>;
646
+ } & Omit<FetchOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: DefaultUrl extends undefined ? [url: string | URL, options?: TOptions | undefined] : [options?: TOptions | undefined]) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
647
+ abortCtrl: AbortController;
648
+ };
584
649
  };
585
650
  /** Make HTTP requests with method DELETE */
586
651
  delete: {
@@ -588,14 +653,20 @@ declare const methods: {
588
653
  headers?: HeadersInit | undefined;
589
654
  } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
590
655
  headers?: HeadersInit | undefined;
591
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
592
- deferred<ThisArg, Delay extends number, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] = undefined, DefaultOptions extends ({
656
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
657
+ abortCtrl: AbortController;
658
+ };
659
+ deferred<ThisArg, Delay extends number, DefaultOptions extends ({
660
+ headers?: HeadersInit | undefined;
661
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
593
662
  headers?: HeadersInit | undefined;
594
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
663
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, DefaultUrl extends PostArgs[0] | undefined = string | URL | undefined, DefaultData extends PostArgs[1] = PostBody | (() => PostBody) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
595
664
  headers?: HeadersInit | undefined;
596
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = {
665
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
597
666
  headers?: HeadersInit | undefined;
598
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => _superutils_promise.IPromisE<TReturn>;
667
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
668
+ abortCtrl: AbortController;
669
+ };
599
670
  };
600
671
  /** Make HTTP requests with method PATCH */
601
672
  patch: {
@@ -603,14 +674,20 @@ declare const methods: {
603
674
  headers?: HeadersInit | undefined;
604
675
  } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
605
676
  headers?: HeadersInit | undefined;
606
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
607
- deferred<ThisArg, Delay extends number, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] = undefined, DefaultOptions extends ({
677
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
678
+ abortCtrl: AbortController;
679
+ };
680
+ deferred<ThisArg, Delay extends number, DefaultOptions extends ({
608
681
  headers?: HeadersInit | undefined;
609
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
682
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
610
683
  headers?: HeadersInit | undefined;
611
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = {
684
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, DefaultUrl extends PostArgs[0] | undefined = string | URL | undefined, DefaultData extends PostArgs[1] = PostBody | (() => PostBody) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
612
685
  headers?: HeadersInit | undefined;
613
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => _superutils_promise.IPromisE<TReturn>;
686
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
687
+ headers?: HeadersInit | undefined;
688
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
689
+ abortCtrl: AbortController;
690
+ };
614
691
  };
615
692
  /** Make HTTP requests with method POST */
616
693
  post: {
@@ -618,14 +695,20 @@ declare const methods: {
618
695
  headers?: HeadersInit | undefined;
619
696
  } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
620
697
  headers?: HeadersInit | undefined;
621
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
622
- deferred<ThisArg, Delay extends number, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] = undefined, DefaultOptions extends ({
698
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
699
+ abortCtrl: AbortController;
700
+ };
701
+ deferred<ThisArg, Delay extends number, DefaultOptions extends ({
702
+ headers?: HeadersInit | undefined;
703
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
623
704
  headers?: HeadersInit | undefined;
624
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
705
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, DefaultUrl extends PostArgs[0] | undefined = string | URL | undefined, DefaultData extends PostArgs[1] = PostBody | (() => PostBody) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
625
706
  headers?: HeadersInit | undefined;
626
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = {
707
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
627
708
  headers?: HeadersInit | undefined;
628
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => _superutils_promise.IPromisE<TReturn>;
709
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
710
+ abortCtrl: AbortController;
711
+ };
629
712
  };
630
713
  /** Make HTTP requests with method PUT */
631
714
  put: {
@@ -633,14 +716,20 @@ declare const methods: {
633
716
  headers?: HeadersInit | undefined;
634
717
  } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
635
718
  headers?: HeadersInit | undefined;
636
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): _superutils_promise.IPromisE<TReturn>;
637
- deferred<ThisArg, Delay extends number, DefaultUrl extends PostArgs[0] | undefined, DefaultData extends PostArgs[1] = undefined, DefaultOptions extends ({
719
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<T>[TAs]>(url: PostArgs[0], data?: PostArgs[1], options?: TOptions | undefined): Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
720
+ abortCtrl: AbortController;
721
+ };
722
+ deferred<ThisArg, Delay extends number, DefaultOptions extends ({
638
723
  headers?: HeadersInit | undefined;
639
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
724
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
640
725
  headers?: HeadersInit | undefined;
641
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = {
726
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, DefaultUrl extends PostArgs[0] | undefined = string | URL | undefined, DefaultData extends PostArgs[1] = PostBody | (() => PostBody) | undefined>(deferOptions?: _superutils_promise.DeferredAsyncOptions<ThisArg, Delay>, defaultUrl?: DefaultUrl | undefined, defaultData?: DefaultData | undefined, defaultOptions?: DefaultOptions | undefined): <TResult = unknown, TOptions extends ({
642
727
  headers?: HeadersInit | undefined;
643
- } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => _superutils_promise.IPromisE<TReturn>;
728
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined = ({
729
+ headers?: HeadersInit | undefined;
730
+ } & Omit<PostOptions, "headers" | "method"> & Partial<Record<"method", never>>) | undefined, TAs extends FetchAs = FetchAsFromOptions<TOptions, FetchAs.json>, TReturn = FetchResult<TResult>[TAs]>(...args: PostDeferredCbArgs<DefaultUrl, DefaultData, TOptions, [url: string | URL, data: PostBody | (() => PostBody), options: PostOptions]>) => Omit<_superutils_promise.IPromisE_Timeout<TReturn>, "abortCtrl"> & {
731
+ abortCtrl: AbortController;
732
+ };
644
733
  };
645
734
  };
646
735
  /**
@@ -688,16 +777,29 @@ declare const methods: {
688
777
  * @param url
689
778
  * @param options (optional) Standard `fetch` options extended with {@link FetchCustomOptions}
690
779
  * @param options.abortCtrl (optional) if not provided `AbortController` will be instantiated when `timeout` used.
691
- * @param options.as (optional) (optional) specify how to parse the result. Default: {@link FetchAs.json}
780
+ *
781
+ * Default: `new AbortController()`
782
+ * @param options.as (optional) (optional) specify how to parse the result.
692
783
  * For raw `Response` use {@link FetchAs.response}
784
+ *
785
+ * Default: {@link FetchAs.json}
693
786
  * @param options.headers (optional) request headers
694
- * Default: `{ 'content-type': 'application/json' }` (or whaterver is set in the `fetch.defaults`).
695
- * @param options.interceptors (optional) request interceptor callbacks. See {@link FetchInterceptors} for details.
696
- * @param options.method (optional) fetch method. Default: `'get'`
697
- * @param options.timeout (optional) duration in milliseconds to abort the request if it takes longer.
698
787
  *
788
+ * Default: `{ 'content-type': 'application/json' }`
789
+ * @param options.interceptors (optional) request interceptor/transformer callbacks.
790
+ * See {@link FetchInterceptors} for details.
791
+ * @param options.method (optional) fetch method.
792
+ *
793
+ * Default: `'get'`
794
+ * @param options.timeout (optional) duration in milliseconds to abort the request.
795
+ * This duration includes the execution of all interceptors/transformers.
796
+ *
797
+ * Default: `30_000`
798
+ *
799
+ * ---
699
800
  *
700
801
  * @example Drop-in replacement for built-in fetch
802
+ *
701
803
  * ```javascript
702
804
  * import fetch from '@superutils/fetch'
703
805
  *
@@ -729,44 +831,60 @@ declare const methods: {
729
831
  * ```typescript
730
832
  * import fetch from '@superutils/fetch'
731
833
  *
732
- * fetch.defaults = {
733
- * errMsgs: {
734
- * invalidUrl: 'Invalid URL',
735
- * parseFailed: 'Failed to parse response as',
736
- * reqTimedout: 'Request timed out',
737
- * requestFailed: 'Request failed with status code:',
738
- * },
739
- * headers: new Headers([['content-type', 'application/json']]),
740
- * // Global/application-wide Interceptor & Transfermers
741
- * interceptors: {
742
- * error: [],
743
- * request: [],
744
- * response: [],
745
- * result: [],
746
- * },
747
- * timeout: 0,
748
- * //........
749
- * }
834
+ * const { defaults, errorMsgs, interceptors } = fetch
835
+ *
836
+ * // set default request timeout duration in milliseconds
837
+ * defaults.timeout = 40_000
838
+ *
839
+ * // default headers
840
+ * defaults.headers = { 'content-type': 'text/plain' }
841
+ *
842
+ * // override error messages
843
+ * errorMsgs.invalidUrl = 'URL is not valid'
844
+ * errorMsgs.timedout = 'Request took longer than expected'
845
+ *
846
+ * // add an interceptor to log all request failures.
847
+ * const fetchLogger = (fetchErr, url, options) => console.log('Fetch error log', fetchErr)
848
+ * interceptors.error.push(fetchLogger)
849
+ *
850
+ * // add an interceptor to conditionally include header before making requests
851
+ * interceptors.request.push((url, options) => {
852
+ * // ignore login requests
853
+ * if (`${url}`.includes('/login')) return
854
+ *
855
+ * options.headers.set('x-auth-token', 'my-auth-token')
856
+ * })
750
857
  * ```
751
858
  */
752
- declare const fetchDefault: typeof fetchResponse & typeof methods;
859
+ declare const defaultFetch: typeof fetchResponse & typeof methods;
753
860
 
754
861
  /**
755
- * Add AbortController to options if not present and propagate external abort signal if provided.
862
+ * Gracefully executes interceptors and returns the processed value.
863
+ * If the value is not transformed (by returning a new value) by the interceptors,
864
+ * the original value is returned.
756
865
  *
757
- * @param options The fetch options object.
866
+ * @param value value to be passed to the interceptors
867
+ * @param signal The AbortController used to monitor the request status. If the signal is aborted (e.g. due to
868
+ * timeout or manual cancellation), the interceptor chain halts immediately. Note: This does not interrupt the
869
+ * currently executing interceptor, but prevents subsequent ones from running.
870
+ * @param interceptors interceptor/transformer callbacks
871
+ * @param args (optional) common arguments to be supplied to all the interceptors in addition to
872
+ * the `value' which will always be the first argument.
758
873
  *
759
- * @returns The AbortController instance associated with the options.
874
+ * Interceptor arguments: `[value, ...args]`
760
875
  */
761
- declare const getAbortCtrl: (options: Partial<FetchOptions>) => AbortController;
876
+ declare const executeInterceptors: <T, TArgs extends unknown[]>(value: T, signal?: AbortSignal, interceptors?: Interceptor<T, TArgs>[], ...args: TArgs) => Promise<T>;
762
877
 
763
878
  /**
764
- * Execute built-in `fetch()` and retry if request fails and `options.retry > 0`.
879
+ * Executes the built-in `fetch()` (or a custom `fetchFunc` if provided) with support for automatic retries.
765
880
  *
766
- * @param url request URL
767
- * @param options (optional)
881
+ * If `options.retry` is greater than 0, the request will be retried if it fails or if the response is not OK,
882
+ * unless overridden by `options.retryIf`.
883
+ *
884
+ * @param url The request URL.
885
+ * @param options (optional) Fetch options, including retry settings.
768
886
  *
769
- * @returns response
887
+ * @returns A promise resolving to the Response.
770
888
  */
771
889
  declare const getResponse: (url: FetchArgs[0], options?: FetchArgs[1]) => Promise<Response>;
772
890
 
@@ -788,4 +906,4 @@ declare const mergeFetchOptions: (...allOptions: FetchOptions[]) => FetchOptions
788
906
  /** Merges partial fetch options ignoring empty or undefined. Otherwise, will return the first argument. */
789
907
  declare const mergePartialOptions: (...optionsAr: (Partial<FetchOptions> | undefined)[]) => Partial<FetchOptions> | undefined;
790
908
 
791
- export { ContentType, type ExcludeOptions, type ExcludePostOptions, type FetchArgs, type FetchArgsInterceptor, FetchAs, type FetchAsFromOptions, type FetchCustomOptions, type FetchDeferredArgs, type FetchErrMsgs, FetchError, type FetchInterceptorError, type FetchInterceptorRequest, type FetchInterceptorResponse, type FetchInterceptorResult, type FetchInterceptors, type FetchOptions, type FetchOptionsDefaults, type FetchOptionsInterceptor, type FetchResult, type FetchRetryOptions, type Interceptor, type PostArgs, type PostBody, type PostDeferredCbArgs, type PostOptions, createClient, createPostClient, fetchDefault as default, executeInterceptors, fetch, fetchResponse, getAbortCtrl, getResponse, mergeFetchOptions, mergePartialOptions };
909
+ export { ContentType, type ExcludeOptions, type ExcludePostOptions, type FetchArgs, type FetchArgsInterceptor, FetchAs, type FetchAsFromOptions, type FetchCustomOptions, type FetchDeferredArgs, type FetchErrMsgs, FetchError, type FetchFunc, type FetchInterceptorError, type FetchInterceptorRequest, type FetchInterceptorResponse, type FetchInterceptorResult, type FetchInterceptors, type FetchOptions, type FetchOptionsDefault, type FetchOptionsInterceptor, type FetchResult, type FetchRetryOptions, type Interceptor, MAX_TIMEOUT, type PostArgs, type PostBody, type PostDeferredCbArgs, type PostOptions, createClient, createPostClient, defaultFetch as default, executeInterceptors, fetch, fetchResponse, getResponse, mergeFetchOptions, mergePartialOptions };