vigor-fetch 4.0.11 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -13
- package/dist/index.cjs +287 -108
- package/dist/index.d.cts +374 -169
- package/dist/index.d.ts +374 -169
- package/dist/index.js +283 -108
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -92,9 +92,11 @@ declare abstract class VigorStatus<Base, Config extends Base, TL extends VigorTy
|
|
|
92
92
|
/**
|
|
93
93
|
* Deep-merges `target` onto `source`, honoring an optional per-path
|
|
94
94
|
* `strategy` tree. Objects merge key by key, arrays concatenate (unless
|
|
95
|
-
* `"replace"` is specified), and any other
|
|
95
|
+
* `"replace"` is specified, or `arrayMode` is `"replace"`), and any other
|
|
96
|
+
* value — including `null` — is overwritten. Only `undefined` keeps the
|
|
97
|
+
* source value.
|
|
96
98
|
*/
|
|
97
|
-
protected _merge<A, B>(source: A, target: B, strategy?: unknown): VigorDeepMerge<A, B>;
|
|
99
|
+
protected _merge<A, B>(source: A, target: B, strategy?: unknown, arrayMode?: "concat" | "replace"): VigorDeepMerge<A, B>;
|
|
98
100
|
/** The default/base config this builder was constructed with. */
|
|
99
101
|
get base(): Base;
|
|
100
102
|
/** The current, merged config for this builder instance. */
|
|
@@ -105,11 +107,19 @@ type VigorAllPolicySettingsSchema<T extends VigorAllSchema<T>> = {
|
|
|
105
107
|
__brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
106
108
|
concurrency: number;
|
|
107
109
|
onlySuccess: boolean;
|
|
110
|
+
/** Per-task timeout in milliseconds. `VigorEmpty` (the default) disables it. */
|
|
111
|
+
timeout: number | VigorEmptyType;
|
|
112
|
+
/** When `true`, the first task failure (not recovered by `onErrorEach`) aborts the remaining tasks and fails the batch. */
|
|
113
|
+
failFast: boolean;
|
|
108
114
|
};
|
|
109
115
|
declare const VigorAllPolicySettingsBase: {
|
|
110
116
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
111
117
|
readonly concurrency: 5;
|
|
112
118
|
readonly onlySuccess: false;
|
|
119
|
+
readonly timeout: symbol & {
|
|
120
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
121
|
+
};
|
|
122
|
+
readonly failFast: false;
|
|
113
123
|
};
|
|
114
124
|
/** Immutable builder for an all-policy's general settings. */
|
|
115
125
|
declare class VigorAllPolicySettings<T extends VigorAllSchema<T> = typeof VigorAllBase> extends VigorStatus<VigorAllSchema<any>, T, VigorAllPolicySettingsTypeLambda> {
|
|
@@ -131,11 +141,33 @@ declare class VigorAllPolicySettings<T extends VigorAllSchema<T> = typeof VigorA
|
|
|
131
141
|
};
|
|
132
142
|
};
|
|
133
143
|
}>>>;
|
|
144
|
+
/** Sets the per-task timeout, in milliseconds. A task exceeding it fails with `TIMED_OUT`. */
|
|
145
|
+
timeout<const N extends VigorExcludeEmpty<VigorAllSchema<any>["policy"]["settings"]["timeout"]>>(num: N): VigorAllPolicySettings<VigorAllIn<VigorDeepMerge<T, {
|
|
146
|
+
readonly policy: {
|
|
147
|
+
readonly settings: {
|
|
148
|
+
readonly timeout: N;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}>>>;
|
|
152
|
+
/** When enabled, the first unrecovered task failure aborts the remaining tasks and fails the batch with that error. */
|
|
153
|
+
failFast<const N extends VigorAllSchema<any>["policy"]["settings"]["failFast"]>(bool: N): VigorAllPolicySettings<VigorAllIn<VigorDeepMerge<T, {
|
|
154
|
+
readonly policy: {
|
|
155
|
+
readonly settings: {
|
|
156
|
+
readonly failFast: N;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
}>>>;
|
|
134
160
|
}
|
|
135
161
|
|
|
136
|
-
|
|
162
|
+
/**
|
|
163
|
+
* A single task. It receives an `AbortSignal` that fires when the task's
|
|
164
|
+
* `timeout` elapses, the batch's `abortSignals` abort, or `failFast` stops
|
|
165
|
+
* the batch — tasks that ignore it keep running in the background, but
|
|
166
|
+
* their result is discarded.
|
|
167
|
+
*/
|
|
168
|
+
type VigorAllTask = (signal: AbortSignal) => unknown | Promise<unknown>;
|
|
137
169
|
/** Extracts (and unwraps `Promise`/`Awaited`) the result type of a single task. */
|
|
138
|
-
type VigorAllTaskResult<F> = F extends () => infer R ? Awaited<R> : never;
|
|
170
|
+
type VigorAllTaskResult<F> = F extends (...args: any[]) => infer R ? Awaited<R> : never;
|
|
139
171
|
/**
|
|
140
172
|
* Maps a tuple of tasks to a tuple of their (awaited) result types, in the
|
|
141
173
|
* same order and length as `N`. If `N` isn't a literal tuple (e.g. the
|
|
@@ -147,16 +179,22 @@ type VigorAllTasksTuple<N extends readonly VigorAllTask[]> = {
|
|
|
147
179
|
type VigorAllPolicySchema<T extends VigorAllSchema<T>> = {
|
|
148
180
|
__brand: VigorBrand<"All", "Policy<Schema">;
|
|
149
181
|
target: VigorAllTask[];
|
|
182
|
+
abortSignals: AbortSignal[];
|
|
150
183
|
settings: VigorAllPolicySettingsSchema<T>;
|
|
151
184
|
middlewares: VigorAllPolicyMiddlewaresSchema<T>;
|
|
152
185
|
};
|
|
153
186
|
declare const VigorAllPolicyBase: {
|
|
154
187
|
readonly __brand: VigorBrand<"All", "Policy<Schema">;
|
|
155
188
|
readonly target: [];
|
|
189
|
+
readonly abortSignals: [];
|
|
156
190
|
readonly settings: {
|
|
157
191
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
158
192
|
readonly concurrency: 5;
|
|
159
193
|
readonly onlySuccess: false;
|
|
194
|
+
readonly timeout: symbol & {
|
|
195
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
196
|
+
};
|
|
197
|
+
readonly failFast: false;
|
|
160
198
|
};
|
|
161
199
|
readonly middlewares: {
|
|
162
200
|
readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
|
|
@@ -388,14 +426,91 @@ type VigorAllOnResultContextSchema<T extends VigorAllSchema<T>> = VigorAllPipeSt
|
|
|
388
426
|
/** Per-task context, seen by `beforeEach` / `afterEach` / `onErrorEach`. */
|
|
389
427
|
type VigorAllEachContextSchema<T extends VigorAllSchema<T>> = {
|
|
390
428
|
__brand: VigorBrand<"All", "EachContext<Schema">;
|
|
429
|
+
/** Position of this task in the `target` list. */
|
|
430
|
+
index: number;
|
|
391
431
|
result: unknown | VigorDefaultType;
|
|
392
432
|
error: unknown;
|
|
393
433
|
flags: {
|
|
394
|
-
|
|
434
|
+
overridden: boolean;
|
|
395
435
|
};
|
|
396
436
|
record: Record<string, any>;
|
|
397
437
|
};
|
|
398
438
|
|
|
439
|
+
/**
|
|
440
|
+
* The `error` of a failed result envelope: `E` is the module's own typed
|
|
441
|
+
* errors, and `{} | null | undefined` stands for anything else that reached
|
|
442
|
+
* the caller — an error thrown by your own target/middleware, an abort
|
|
443
|
+
* reason, a network `TypeError`, even a bare `throw null`.
|
|
444
|
+
*
|
|
445
|
+
* Because of that tail, reading `error.code` directly doesn't compile. Narrow
|
|
446
|
+
* first (`isVigorRetryError(err)`), and `code` then narrows `data` to that
|
|
447
|
+
* code's payload.
|
|
448
|
+
*/
|
|
449
|
+
type VigorResultError<E> = E | {} | null | undefined;
|
|
450
|
+
type VigorErrorOptions<D, T> = {
|
|
451
|
+
cause?: unknown;
|
|
452
|
+
data: D;
|
|
453
|
+
method: string;
|
|
454
|
+
context?: T;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Base class for all Vigor error types. Subclasses (`VigorRetryError`,
|
|
458
|
+
* `VigorFetchError`, `VigorParseError`, `VigorAllError`) fix `C`, `D`, and
|
|
459
|
+
* `T` to their own error-code union, data shape, and context shape.
|
|
460
|
+
*
|
|
461
|
+
* @typeParam C - Union of error codes for the subclass.
|
|
462
|
+
* @typeParam D - Shape of the structured error data.
|
|
463
|
+
* @typeParam T - Shape of the domain context.
|
|
464
|
+
*/
|
|
465
|
+
declare abstract class VigorError<C extends string, D, T> extends Error {
|
|
466
|
+
readonly timestamp: Date;
|
|
467
|
+
readonly cause?: unknown;
|
|
468
|
+
readonly code: C;
|
|
469
|
+
readonly data: D;
|
|
470
|
+
readonly method: string;
|
|
471
|
+
readonly context: T | undefined;
|
|
472
|
+
/**
|
|
473
|
+
* @param code - Machine-readable error code.
|
|
474
|
+
* @param message - Human-readable message (rendered after the `[code]` prefix).
|
|
475
|
+
* @param options - Additional error metadata (cause, data, method, context).
|
|
476
|
+
*/
|
|
477
|
+
constructor(code: C, message: string, options: VigorErrorOptions<D, T>);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
declare const VigorAllErrorMessageFuncs: {
|
|
481
|
+
readonly EMPTY_TARGET: (_: {}) => string;
|
|
482
|
+
readonly TIMED_OUT: ({ limit, index }: {
|
|
483
|
+
limit: number;
|
|
484
|
+
index: number;
|
|
485
|
+
}) => string;
|
|
486
|
+
};
|
|
487
|
+
type VigorAllErrorCodes = keyof typeof VigorAllErrorMessageFuncs;
|
|
488
|
+
type VigorAllErrorDatas<C extends VigorAllErrorCodes> = Parameters<typeof VigorAllErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
489
|
+
/**
|
|
490
|
+
* Every all error code as its own union member, so narrowing by `code`
|
|
491
|
+
* also narrows `data` to that code's payload.
|
|
492
|
+
*/
|
|
493
|
+
type VigorAllErrors<T extends VigorAllSchema<any> = VigorAllSchema<any>> = {
|
|
494
|
+
[C in VigorAllErrorCodes]: VigorAllError<C, T>;
|
|
495
|
+
}[VigorAllErrorCodes];
|
|
496
|
+
/** `error` of a failed `requestVerbose()` — this module's errors, or anything else that was thrown (e.g. a task's error under `failFast`). */
|
|
497
|
+
type VigorAllRequestError<T extends VigorAllSchema<any> = any> = VigorResultError<VigorAllErrors<T>>;
|
|
498
|
+
/** Error type thrown by the all module. */
|
|
499
|
+
declare class VigorAllError<C extends VigorAllErrorCodes, T extends VigorAllSchema<T>> extends VigorError<C, VigorAllErrorDatas<C>, VigorAllContextSchema<T>> {
|
|
500
|
+
/**
|
|
501
|
+
* @param code - One of the all module's error codes.
|
|
502
|
+
* @param options - Error metadata, including the `data` payload for `code`.
|
|
503
|
+
*/
|
|
504
|
+
constructor(code: C, options: VigorErrorOptions<VigorAllErrorDatas<C>, VigorAllContextSchema<T>>);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Narrows an error from a failed result envelope to the all module's typed
|
|
508
|
+
* error union. Prefer this over a bare `instanceof`: the envelope's `{}`
|
|
509
|
+
* member makes `instanceof` widen `data` back to every code's payload,
|
|
510
|
+
* while this guard keeps `code` and `data` in sync.
|
|
511
|
+
*/
|
|
512
|
+
declare const isVigorAllError: (error: unknown) => error is VigorAllErrors;
|
|
513
|
+
|
|
399
514
|
type VigorAllSchema<T extends VigorAllSchema<T>> = {
|
|
400
515
|
__brand: VigorBrand<"All", "Schema">;
|
|
401
516
|
policy: VigorAllPolicySchema<T>;
|
|
@@ -407,10 +522,15 @@ declare const VigorAllBase: {
|
|
|
407
522
|
readonly policy: {
|
|
408
523
|
readonly __brand: VigorBrand<"All", "Policy<Schema">;
|
|
409
524
|
readonly target: [];
|
|
525
|
+
readonly abortSignals: [];
|
|
410
526
|
readonly settings: {
|
|
411
527
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
412
528
|
readonly concurrency: 5;
|
|
413
529
|
readonly onlySuccess: false;
|
|
530
|
+
readonly timeout: symbol & {
|
|
531
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
532
|
+
};
|
|
533
|
+
readonly failFast: false;
|
|
414
534
|
};
|
|
415
535
|
readonly middlewares: {
|
|
416
536
|
readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
|
|
@@ -440,6 +560,12 @@ declare class VigorAll<T extends VigorAllSchema<T> = typeof VigorAllBase> extend
|
|
|
440
560
|
readonly target: N;
|
|
441
561
|
};
|
|
442
562
|
}>>>;
|
|
563
|
+
/** Sets external abort signals that, when aborted, cancel the remaining tasks and fail the batch. */
|
|
564
|
+
abortSignals<const N extends VigorAllSchema<T>["policy"]["abortSignals"]>(...sig: N): VigorAll<VigorAllIn<VigorDeepMerge<T, {
|
|
565
|
+
readonly policy: {
|
|
566
|
+
readonly abortSignals: N;
|
|
567
|
+
};
|
|
568
|
+
}>>>;
|
|
443
569
|
/** Configures the all-policy's general settings (concurrency, onlySuccess). */
|
|
444
570
|
settings<const N extends VigorDeepPartial<VigorAllPolicySettingsSchema<T>>>(input: N): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
|
|
445
571
|
policy: {
|
|
@@ -487,13 +613,13 @@ declare class VigorAll<T extends VigorAllSchema<T> = typeof VigorAllBase> extend
|
|
|
487
613
|
request<R = VigorExcludeDefault<VigorAllContextSchema<T>["result"]>>(): Promise<R>;
|
|
488
614
|
/** Runs all tasks and returns a result/error envelope instead of throwing. */
|
|
489
615
|
requestVerbose<R = VigorExcludeDefault<VigorAllContextSchema<T>["result"]>>(): Promise<{
|
|
490
|
-
success: false;
|
|
491
|
-
data: null;
|
|
492
|
-
error: unknown;
|
|
493
|
-
} | {
|
|
494
616
|
success: true;
|
|
495
617
|
data: R;
|
|
496
618
|
error: null;
|
|
619
|
+
} | {
|
|
620
|
+
success: false;
|
|
621
|
+
data: null;
|
|
622
|
+
error: VigorAllRequestError<T>;
|
|
497
623
|
}>;
|
|
498
624
|
/** Internal execution loop implementing the bounded-concurrency worker pool and the batch-level before/after/onResult pipeline. */
|
|
499
625
|
private requestRuntime;
|
|
@@ -727,13 +853,21 @@ type VigorFetchPolicySettingsSchema<T extends VigorFetchSchema<T>> = {
|
|
|
727
853
|
__brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
728
854
|
retryHeaders: string[];
|
|
729
855
|
unretryStatus: number[];
|
|
856
|
+
/**
|
|
857
|
+
* When `true` (the default), a `3xx` response carrying a `Location`
|
|
858
|
+
* header navigates the page to that URL via `window.location.href`.
|
|
859
|
+
* Outside a browser (no `window.location`) this does nothing, exactly
|
|
860
|
+
* like `false`.
|
|
861
|
+
*/
|
|
862
|
+
redirect: boolean;
|
|
730
863
|
maxRestarts: number;
|
|
731
864
|
default: ((ctx: VigorFetchContextSchema<T>) => any | Promise<any>) | VigorEmptyType;
|
|
732
865
|
};
|
|
733
866
|
declare const VigorFetchPolicySettingsBase: {
|
|
734
867
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
735
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
868
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
736
869
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
870
|
+
readonly redirect: true;
|
|
737
871
|
readonly maxRestarts: 3;
|
|
738
872
|
readonly default: symbol & {
|
|
739
873
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -743,7 +877,7 @@ declare const VigorFetchPolicySettingsBase: {
|
|
|
743
877
|
declare class VigorFetchPolicySettings<T extends VigorFetchSchema<T> = typeof VigorFetchBase> extends VigorStatus<VigorFetchSchema<any>, T, VigorFetchPolicySettingsTypeLambda> {
|
|
744
878
|
constructor(config?: T);
|
|
745
879
|
protected _create<C>(config: C): VigorApply<VigorFetchPolicySettingsTypeLambda, C>;
|
|
746
|
-
/** Sets response headers consulted to compute a server-suggested retry delay. */
|
|
880
|
+
/** Sets (replaces) the response headers consulted to compute a server-suggested retry delay. */
|
|
747
881
|
retryHeaders<const N extends VigorFetchSchema<any>["policy"]["settings"]["retryHeaders"]>(...strs: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
|
|
748
882
|
readonly policy: {
|
|
749
883
|
readonly settings: {
|
|
@@ -751,7 +885,7 @@ declare class VigorFetchPolicySettings<T extends VigorFetchSchema<T> = typeof Vi
|
|
|
751
885
|
};
|
|
752
886
|
};
|
|
753
887
|
}>>>;
|
|
754
|
-
/** Sets HTTP status codes that should never be retried. */
|
|
888
|
+
/** Sets (replaces) the HTTP status codes that should never be retried. */
|
|
755
889
|
unretryStatus<const N extends VigorFetchSchema<any>["policy"]["settings"]["unretryStatus"]>(...nums: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
|
|
756
890
|
readonly policy: {
|
|
757
891
|
readonly settings: {
|
|
@@ -759,6 +893,18 @@ declare class VigorFetchPolicySettings<T extends VigorFetchSchema<T> = typeof Vi
|
|
|
759
893
|
};
|
|
760
894
|
};
|
|
761
895
|
}>>>;
|
|
896
|
+
/**
|
|
897
|
+
* When enabled, a `3xx` response with a `Location` header navigates the
|
|
898
|
+
* page to that URL (`window.location.href`). Without `window.location`
|
|
899
|
+
* — e.g. in Node — this behaves like `false`.
|
|
900
|
+
*/
|
|
901
|
+
redirect<const N extends VigorFetchSchema<any>["policy"]["settings"]["redirect"]>(bool: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
|
|
902
|
+
readonly policy: {
|
|
903
|
+
readonly settings: {
|
|
904
|
+
readonly redirect: N;
|
|
905
|
+
};
|
|
906
|
+
};
|
|
907
|
+
}>>>;
|
|
762
908
|
/** Sets the maximum number of full restarts allowed. */
|
|
763
909
|
maxRestarts<const N extends VigorFetchSchema<any>["policy"]["settings"]["maxRestarts"]>(num: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
|
|
764
910
|
readonly policy: {
|
|
@@ -1557,18 +1703,61 @@ declare class VigorRetry<T extends VigorRetrySchema<T> = typeof VigorRetryBase>
|
|
|
1557
1703
|
request<R = VigorExcludeDefault<VigorRetryContextSchema<T>["result"]>>(): Promise<R>;
|
|
1558
1704
|
/** Runs the target and returns a result/error envelope instead of throwing. */
|
|
1559
1705
|
requestVerbose<R = VigorExcludeDefault<VigorRetryContextSchema<T>["result"]>>(): Promise<{
|
|
1560
|
-
success: false;
|
|
1561
|
-
data: null;
|
|
1562
|
-
error: unknown;
|
|
1563
|
-
} | {
|
|
1564
1706
|
success: true;
|
|
1565
1707
|
data: R;
|
|
1566
1708
|
error: null;
|
|
1709
|
+
} | {
|
|
1710
|
+
success: false;
|
|
1711
|
+
data: null;
|
|
1712
|
+
error: VigorRetryRequestError<T>;
|
|
1567
1713
|
}>;
|
|
1568
1714
|
/** Internal execution loop implementing the attempt/retry/restart lifecycle. */
|
|
1569
1715
|
private requestRuntime;
|
|
1570
1716
|
}
|
|
1571
1717
|
|
|
1718
|
+
declare const VigorRetryErrorMessageFuncs: {
|
|
1719
|
+
readonly VALUE_REQUIRED: ({ key }: {
|
|
1720
|
+
key: string;
|
|
1721
|
+
}) => string;
|
|
1722
|
+
readonly RETRY_EXHAUSTED: ({ maxAttempts }: {
|
|
1723
|
+
maxAttempts: number;
|
|
1724
|
+
error: unknown;
|
|
1725
|
+
}) => string;
|
|
1726
|
+
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
1727
|
+
maxAttempts: number;
|
|
1728
|
+
error: unknown;
|
|
1729
|
+
}) => string;
|
|
1730
|
+
readonly TIMED_OUT: ({ limit }: {
|
|
1731
|
+
limit: number;
|
|
1732
|
+
}) => string;
|
|
1733
|
+
};
|
|
1734
|
+
type VigorRetryErrorCodes = keyof typeof VigorRetryErrorMessageFuncs;
|
|
1735
|
+
type VigorRetryErrorDatas<C extends VigorRetryErrorCodes> = Parameters<typeof VigorRetryErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
1736
|
+
/**
|
|
1737
|
+
* Every retry error code as its own union member, so narrowing by `code`
|
|
1738
|
+
* also narrows `data` to that code's payload.
|
|
1739
|
+
*/
|
|
1740
|
+
type VigorRetryErrors<T extends VigorRetrySchema<any> = VigorRetrySchema<any>> = {
|
|
1741
|
+
[C in VigorRetryErrorCodes]: VigorRetryError<C, T>;
|
|
1742
|
+
}[VigorRetryErrorCodes];
|
|
1743
|
+
/** `error` of a failed `requestVerbose()` — this module's errors, or anything else that was thrown. */
|
|
1744
|
+
type VigorRetryRequestError<T extends VigorRetrySchema<any> = any> = VigorResultError<VigorRetryErrors<T>>;
|
|
1745
|
+
/** Error type thrown by the retry module. */
|
|
1746
|
+
declare class VigorRetryError<C extends VigorRetryErrorCodes, T extends VigorRetrySchema<T>> extends VigorError<C, VigorRetryErrorDatas<C>, VigorRetryContextSchema<T>> {
|
|
1747
|
+
/**
|
|
1748
|
+
* @param code - One of the retry module's error codes.
|
|
1749
|
+
* @param options - Error metadata, including the `data` payload for `code`.
|
|
1750
|
+
*/
|
|
1751
|
+
constructor(code: C, options: VigorErrorOptions<VigorRetryErrorDatas<C>, VigorRetryContextSchema<T>>);
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Narrows an error from a failed result envelope to the retry module's typed
|
|
1755
|
+
* error union. Prefer this over a bare `instanceof`: the envelope's `{}`
|
|
1756
|
+
* member makes `instanceof` widen `data` back to every code's payload,
|
|
1757
|
+
* while this guard keeps `code` and `data` in sync.
|
|
1758
|
+
*/
|
|
1759
|
+
declare const isVigorRetryError: (error: unknown) => error is VigorRetryErrors;
|
|
1760
|
+
|
|
1572
1761
|
type VigorParseStrategyFunc = (response: Response) => Promise<any>;
|
|
1573
1762
|
type VigorParsePolicyStrategiesSchema<T extends VigorParseSchema<T>> = {
|
|
1574
1763
|
__brand: VigorBrand<"Parse", "Policy<Strategies<Schema">;
|
|
@@ -1578,7 +1767,11 @@ declare const VigorParsePolicyStrategiesBase: {
|
|
|
1578
1767
|
readonly __brand: VigorBrand<"Parse", "Policy<Strategies<Schema">;
|
|
1579
1768
|
readonly funcs: VigorParseStrategyFunc[];
|
|
1580
1769
|
};
|
|
1581
|
-
/**
|
|
1770
|
+
/**
|
|
1771
|
+
* Parses a response by matching its `Content-Type` header against a known
|
|
1772
|
+
* parser table. A response without a body (e.g. `204 No Content`) resolves to
|
|
1773
|
+
* `null`, and one without a `Content-Type` is read as text (`null` if empty).
|
|
1774
|
+
*/
|
|
1582
1775
|
declare const VigorParseContentTypeStrategy: VigorParseStrategyFunc;
|
|
1583
1776
|
/** Parses a response by trying a sequence of body-reading methods until one succeeds. */
|
|
1584
1777
|
declare const VigorParseSniffStrategy: VigorParseStrategyFunc;
|
|
@@ -1857,7 +2050,7 @@ type VigorParseContextSchema<T extends VigorParseSchema<T>, R = VigorParsePipeRe
|
|
|
1857
2050
|
error: unknown;
|
|
1858
2051
|
response: VigorParsePolicySchema<T>["target"];
|
|
1859
2052
|
flags: {
|
|
1860
|
-
|
|
2053
|
+
overridden: boolean;
|
|
1861
2054
|
restarted: boolean;
|
|
1862
2055
|
};
|
|
1863
2056
|
record: Record<string, any>;
|
|
@@ -2075,18 +2268,125 @@ declare class VigorParse<T extends VigorParseSchema<T> = typeof VigorParseBase>
|
|
|
2075
2268
|
request<R = VigorExcludeDefault<VigorParseContextSchema<T>["result"]>>(): Promise<R>;
|
|
2076
2269
|
/** Runs parsing and returns a result/error envelope instead of throwing. */
|
|
2077
2270
|
requestVerbose<R = VigorExcludeDefault<VigorParseContextSchema<T>["result"]>>(): Promise<{
|
|
2078
|
-
success: false;
|
|
2079
|
-
data: null;
|
|
2080
|
-
error: unknown;
|
|
2081
|
-
} | {
|
|
2082
2271
|
success: true;
|
|
2083
2272
|
data: R;
|
|
2084
2273
|
error: null;
|
|
2274
|
+
} | {
|
|
2275
|
+
success: false;
|
|
2276
|
+
data: null;
|
|
2277
|
+
error: VigorParseRequestError<T>;
|
|
2085
2278
|
}>;
|
|
2086
2279
|
/** Internal execution loop implementing the strategy fallback and restart handling. */
|
|
2087
2280
|
private requestRuntime;
|
|
2088
2281
|
}
|
|
2089
2282
|
|
|
2283
|
+
declare const VigorParseErrorMessageFuncs: {
|
|
2284
|
+
readonly VALUE_REQUIRED: ({ key }: {
|
|
2285
|
+
key: string;
|
|
2286
|
+
}) => string;
|
|
2287
|
+
readonly INVALID_CONTENT_TYPE: ({ received }: {
|
|
2288
|
+
received: unknown;
|
|
2289
|
+
}) => string;
|
|
2290
|
+
readonly PARSER_NOT_FOUND: ({ received, expected }: {
|
|
2291
|
+
received: unknown;
|
|
2292
|
+
expected: Array<string>;
|
|
2293
|
+
}) => string;
|
|
2294
|
+
readonly PARSER_ALL_FAILED: ({ tried }: {
|
|
2295
|
+
tried: Array<string>;
|
|
2296
|
+
}) => string;
|
|
2297
|
+
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
2298
|
+
maxAttempts: number;
|
|
2299
|
+
error: unknown;
|
|
2300
|
+
}) => string;
|
|
2301
|
+
};
|
|
2302
|
+
type VigorParseErrorCodes = keyof typeof VigorParseErrorMessageFuncs;
|
|
2303
|
+
type VigorParseErrorDatas<C extends VigorParseErrorCodes> = Parameters<typeof VigorParseErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
2304
|
+
/**
|
|
2305
|
+
* Every parse error code as its own union member, so narrowing by `code`
|
|
2306
|
+
* also narrows `data` to that code's payload.
|
|
2307
|
+
*/
|
|
2308
|
+
type VigorParseErrors<T extends VigorParseSchema<any> = VigorParseSchema<any>> = {
|
|
2309
|
+
[C in VigorParseErrorCodes]: VigorParseError<C, T>;
|
|
2310
|
+
}[VigorParseErrorCodes];
|
|
2311
|
+
/** `error` of a failed `requestVerbose()` — this module's errors, or anything else that was thrown. */
|
|
2312
|
+
type VigorParseRequestError<T extends VigorParseSchema<any> = any> = VigorResultError<VigorParseErrors<T>>;
|
|
2313
|
+
/** Error type thrown by the parse module. */
|
|
2314
|
+
declare class VigorParseError<C extends VigorParseErrorCodes, T extends VigorParseSchema<T>> extends VigorError<C, VigorParseErrorDatas<C>, VigorParseContextSchema<T>> {
|
|
2315
|
+
/**
|
|
2316
|
+
* @param code - One of the parse module's error codes.
|
|
2317
|
+
* @param options - Error metadata, including the `data` payload for `code`.
|
|
2318
|
+
*/
|
|
2319
|
+
constructor(code: C, options: VigorErrorOptions<VigorParseErrorDatas<C>, VigorParseContextSchema<T>>);
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Narrows an error from a failed result envelope to the parse module's typed
|
|
2323
|
+
* error union. Prefer this over a bare `instanceof`: the envelope's `{}`
|
|
2324
|
+
* member makes `instanceof` widen `data` back to every code's payload,
|
|
2325
|
+
* while this guard keeps `code` and `data` in sync.
|
|
2326
|
+
*/
|
|
2327
|
+
declare const isVigorParseError: (error: unknown) => error is VigorParseErrors;
|
|
2328
|
+
|
|
2329
|
+
declare const VigorFetchErrorMessageFuncs: {
|
|
2330
|
+
readonly VALUE_REQUIRED: ({ key }: {
|
|
2331
|
+
key: string;
|
|
2332
|
+
}) => string;
|
|
2333
|
+
readonly INVALID_BODY: ({ received }: {
|
|
2334
|
+
received: unknown;
|
|
2335
|
+
}) => string;
|
|
2336
|
+
readonly INVALID_PROTOCOL: ({ origin, base }: {
|
|
2337
|
+
origin: string;
|
|
2338
|
+
base: string | undefined;
|
|
2339
|
+
}) => string;
|
|
2340
|
+
readonly FETCH_FAILED: ({ status, statusText }: {
|
|
2341
|
+
status: number;
|
|
2342
|
+
statusText: string;
|
|
2343
|
+
response: Response;
|
|
2344
|
+
url: string;
|
|
2345
|
+
parsed: unknown;
|
|
2346
|
+
}) => string;
|
|
2347
|
+
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
2348
|
+
maxAttempts: number;
|
|
2349
|
+
error: unknown;
|
|
2350
|
+
}) => string;
|
|
2351
|
+
readonly REDIRECTED: ({ url, status }: {
|
|
2352
|
+
url: string;
|
|
2353
|
+
status: number;
|
|
2354
|
+
response: Response;
|
|
2355
|
+
}) => string;
|
|
2356
|
+
};
|
|
2357
|
+
type VigorFetchErrorCodes = keyof typeof VigorFetchErrorMessageFuncs;
|
|
2358
|
+
type VigorFetchErrorDatas<C extends VigorFetchErrorCodes> = Parameters<typeof VigorFetchErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
2359
|
+
/**
|
|
2360
|
+
* Every fetch error code as its own union member, so narrowing by `code`
|
|
2361
|
+
* also narrows `data` to that code's payload.
|
|
2362
|
+
*/
|
|
2363
|
+
type VigorFetchErrors<T extends VigorFetchSchema<any> = VigorFetchSchema<any>> = {
|
|
2364
|
+
[C in VigorFetchErrorCodes]: VigorFetchError<C, T>;
|
|
2365
|
+
}[VigorFetchErrorCodes];
|
|
2366
|
+
/**
|
|
2367
|
+
* `error` of a failed `requestVerbose()`. Includes the nested engines'
|
|
2368
|
+
* errors, since fetch surfaces them as-is: a retried-out request fails with
|
|
2369
|
+
* `VigorRetryError("RETRY_EXHAUSTED")` (its `cause` holding the last
|
|
2370
|
+
* `VigorFetchError`), and a body that can't be parsed fails with a
|
|
2371
|
+
* `VigorParseError`.
|
|
2372
|
+
*/
|
|
2373
|
+
type VigorFetchRequestError<T extends VigorFetchSchema<any> = any> = VigorResultError<VigorFetchErrors<T> | VigorRetryErrors | VigorParseErrors>;
|
|
2374
|
+
/** Error type thrown by the fetch module. */
|
|
2375
|
+
declare class VigorFetchError<C extends VigorFetchErrorCodes, T extends VigorFetchSchema<T>> extends VigorError<C, VigorFetchErrorDatas<C>, VigorFetchContextSchema<T>> {
|
|
2376
|
+
/**
|
|
2377
|
+
* @param code - One of the fetch module's error codes.
|
|
2378
|
+
* @param options - Error metadata, including the `data` payload for `code`.
|
|
2379
|
+
*/
|
|
2380
|
+
constructor(code: C, options: VigorErrorOptions<VigorFetchErrorDatas<C>, VigorFetchContextSchema<T>>);
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Narrows an error from a failed result envelope to the fetch module's typed
|
|
2384
|
+
* error union. Prefer this over a bare `instanceof`: the envelope's `{}`
|
|
2385
|
+
* member makes `instanceof` widen `data` back to every code's payload,
|
|
2386
|
+
* while this guard keeps `code` and `data` in sync.
|
|
2387
|
+
*/
|
|
2388
|
+
declare const isVigorFetchError: (error: unknown) => error is VigorFetchErrors;
|
|
2389
|
+
|
|
2090
2390
|
type VigorStringable = string | number | boolean | null | undefined | Date;
|
|
2091
2391
|
type VigorFetchPolicySchema<T extends VigorFetchSchema<T>> = {
|
|
2092
2392
|
__brand: VigorBrand<"Fetch", "Policy<Schema">;
|
|
@@ -2121,8 +2421,9 @@ declare const VigorFetchPolicyBase: {
|
|
|
2121
2421
|
readonly extra: {};
|
|
2122
2422
|
readonly settings: {
|
|
2123
2423
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
2124
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
2424
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
2125
2425
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
2426
|
+
readonly redirect: true;
|
|
2126
2427
|
readonly maxRestarts: 3;
|
|
2127
2428
|
readonly default: symbol & {
|
|
2128
2429
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -2232,8 +2533,9 @@ declare const VigorFetchBase: {
|
|
|
2232
2533
|
readonly extra: {};
|
|
2233
2534
|
readonly settings: {
|
|
2234
2535
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
2235
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
2536
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
2236
2537
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
2538
|
+
readonly redirect: true;
|
|
2237
2539
|
readonly maxRestarts: 3;
|
|
2238
2540
|
readonly default: symbol & {
|
|
2239
2541
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -2485,6 +2787,25 @@ declare class VigorFetch<T extends VigorFetchSchema<T> = typeof VigorFetchBase>
|
|
|
2485
2787
|
headers: Record<string, string>;
|
|
2486
2788
|
body: BodyInit | null | undefined;
|
|
2487
2789
|
};
|
|
2790
|
+
/**
|
|
2791
|
+
* Returns the absolute URL a `3xx` response points at, or `null` when the
|
|
2792
|
+
* response isn't a redirect or carries no usable `Location` header. A
|
|
2793
|
+
* relative `Location` is resolved against the responding URL.
|
|
2794
|
+
*/
|
|
2795
|
+
protected _resolveRedirect(response: Response, href: string): string | null;
|
|
2796
|
+
/** The browser's `location`, or `null` in environments without one (e.g. Node). */
|
|
2797
|
+
protected _browserLocation(): {
|
|
2798
|
+
href: string;
|
|
2799
|
+
} | null;
|
|
2800
|
+
/** Assigns `source` headers onto `target`, replacing any existing key that differs only in case. */
|
|
2801
|
+
protected _assignHeaders(target: Record<string, string>, source: Record<string, string>): void;
|
|
2802
|
+
/**
|
|
2803
|
+
* Converts a rate-limit header value into a delay in milliseconds, or
|
|
2804
|
+
* `null` if it can't be used. Accepts delta seconds (`Retry-After: 120`),
|
|
2805
|
+
* Unix epoch seconds or milliseconds (`X-RateLimit-Reset: 1735689600`),
|
|
2806
|
+
* and HTTP dates.
|
|
2807
|
+
*/
|
|
2808
|
+
protected _parseRetryHeader(value: string | null): number | null;
|
|
2488
2809
|
/**
|
|
2489
2810
|
* Overrides the resolved result type with `T`, taking priority over the
|
|
2490
2811
|
* default `unknown` result. Can be called before or after `parse()` (or
|
|
@@ -2498,13 +2819,13 @@ declare class VigorFetch<T extends VigorFetchSchema<T> = typeof VigorFetchBase>
|
|
|
2498
2819
|
request<R = VigorExcludeDefault<VigorFetchContextSchema<T>["result"]>>(): Promise<R>;
|
|
2499
2820
|
/** Runs the request and returns a result/error envelope instead of throwing. */
|
|
2500
2821
|
requestVerbose<R = VigorExcludeDefault<VigorFetchContextSchema<T>["result"]>>(): Promise<{
|
|
2501
|
-
success: false;
|
|
2502
|
-
data: null;
|
|
2503
|
-
error: unknown;
|
|
2504
|
-
} | {
|
|
2505
2822
|
success: true;
|
|
2506
2823
|
data: R;
|
|
2507
2824
|
error: null;
|
|
2825
|
+
} | {
|
|
2826
|
+
success: false;
|
|
2827
|
+
data: null;
|
|
2828
|
+
error: VigorFetchRequestError<T>;
|
|
2508
2829
|
}>;
|
|
2509
2830
|
/** Internal execution loop implementing URL building, retry, parsing, and restart handling. */
|
|
2510
2831
|
private requestRuntime;
|
|
@@ -2598,8 +2919,9 @@ declare function fetchWithOrigin<const F extends Parameters<VigorFetch["origin"]
|
|
|
2598
2919
|
__brand: VigorBrand<"Fetch", "Policy<Schema">;
|
|
2599
2920
|
settings: {
|
|
2600
2921
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
2601
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
2922
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
2602
2923
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
2924
|
+
readonly redirect: true;
|
|
2603
2925
|
readonly maxRestarts: 3;
|
|
2604
2926
|
readonly default: symbol & {
|
|
2605
2927
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -2703,10 +3025,15 @@ declare function allWithTargets<const F extends VigorAllTask[]>(tasks: F): Vigor
|
|
|
2703
3025
|
policy: {
|
|
2704
3026
|
target: F extends VigorBuiltin ? F : F extends readonly any[] ? [...F] : F;
|
|
2705
3027
|
__brand: VigorBrand<"All", "Policy<Schema">;
|
|
3028
|
+
abortSignals: [];
|
|
2706
3029
|
settings: {
|
|
2707
3030
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
2708
3031
|
readonly concurrency: 5;
|
|
2709
3032
|
readonly onlySuccess: false;
|
|
3033
|
+
readonly timeout: symbol & {
|
|
3034
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
3035
|
+
};
|
|
3036
|
+
readonly failFast: false;
|
|
2710
3037
|
};
|
|
2711
3038
|
middlewares: {
|
|
2712
3039
|
readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
|
|
@@ -2773,8 +3100,9 @@ declare const vigorBase: {
|
|
|
2773
3100
|
readonly extra: {};
|
|
2774
3101
|
readonly settings: {
|
|
2775
3102
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
2776
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
3103
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
2777
3104
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
3105
|
+
readonly redirect: true;
|
|
2778
3106
|
readonly maxRestarts: 3;
|
|
2779
3107
|
readonly default: symbol & {
|
|
2780
3108
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -2881,8 +3209,9 @@ declare const vigorBase: {
|
|
|
2881
3209
|
readonly extra: {};
|
|
2882
3210
|
readonly settings: {
|
|
2883
3211
|
readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
|
|
2884
|
-
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"
|
|
3212
|
+
readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after"];
|
|
2885
3213
|
readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
|
|
3214
|
+
readonly redirect: true;
|
|
2886
3215
|
readonly maxRestarts: 3;
|
|
2887
3216
|
readonly default: symbol & {
|
|
2888
3217
|
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
@@ -3228,10 +3557,15 @@ declare const vigorBase: {
|
|
|
3228
3557
|
readonly policy: {
|
|
3229
3558
|
readonly __brand: VigorBrand<"All", "Policy<Schema">;
|
|
3230
3559
|
readonly target: [];
|
|
3560
|
+
readonly abortSignals: [];
|
|
3231
3561
|
readonly settings: {
|
|
3232
3562
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
3233
3563
|
readonly concurrency: 5;
|
|
3234
3564
|
readonly onlySuccess: false;
|
|
3565
|
+
readonly timeout: symbol & {
|
|
3566
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
3567
|
+
};
|
|
3568
|
+
readonly failFast: false;
|
|
3235
3569
|
};
|
|
3236
3570
|
readonly middlewares: {
|
|
3237
3571
|
readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
|
|
@@ -3252,10 +3586,15 @@ declare const vigorBase: {
|
|
|
3252
3586
|
readonly policy: {
|
|
3253
3587
|
readonly __brand: VigorBrand<"All", "Policy<Schema">;
|
|
3254
3588
|
readonly target: [];
|
|
3589
|
+
readonly abortSignals: [];
|
|
3255
3590
|
readonly settings: {
|
|
3256
3591
|
readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
|
|
3257
3592
|
readonly concurrency: 5;
|
|
3258
3593
|
readonly onlySuccess: false;
|
|
3594
|
+
readonly timeout: symbol & {
|
|
3595
|
+
__brand: VigorBrand<"Core", "Symbol_Empty">;
|
|
3596
|
+
};
|
|
3597
|
+
readonly failFast: false;
|
|
3259
3598
|
};
|
|
3260
3599
|
readonly middlewares: {
|
|
3261
3600
|
readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
|
|
@@ -3274,8 +3613,9 @@ declare const vigorBase: {
|
|
|
3274
3613
|
};
|
|
3275
3614
|
};
|
|
3276
3615
|
};
|
|
3277
|
-
|
|
3278
|
-
|
|
3616
|
+
/** `Ext` accumulates every plugin extension applied so far, so `use().use()` keeps all of them. */
|
|
3617
|
+
type VigorInstance<Ext = {}> = typeof vigorBase & Ext & {
|
|
3618
|
+
use: <P extends VigorPlugin<any, any>>(plugin: P, options?: P["options"]) => VigorInstance<Ext & ReturnType<P["func"]>>;
|
|
3279
3619
|
};
|
|
3280
3620
|
/**
|
|
3281
3621
|
* A plugin never mutates the `VigorInstance` it receives — it reads from it
|
|
@@ -3291,139 +3631,4 @@ type VigorPlugin<O extends {
|
|
|
3291
3631
|
};
|
|
3292
3632
|
declare const vigor: VigorInstance;
|
|
3293
3633
|
|
|
3294
|
-
type VigorErrorOptions
|
|
3295
|
-
cause?: unknown;
|
|
3296
|
-
data: D;
|
|
3297
|
-
method: string;
|
|
3298
|
-
context?: T;
|
|
3299
|
-
};
|
|
3300
|
-
/**
|
|
3301
|
-
* Base class for all Vigor error types. Subclasses (`VigorRetryError`,
|
|
3302
|
-
* `VigorFetchError`, `VigorParseError`, `VigorAllError`) fix `C`, `D`, and
|
|
3303
|
-
* `T` to their own error-code union, data shape, and context shape.
|
|
3304
|
-
*
|
|
3305
|
-
* @typeParam C - Union of error codes for the subclass.
|
|
3306
|
-
* @typeParam D - Shape of the structured error data.
|
|
3307
|
-
* @typeParam T - Shape of the domain context.
|
|
3308
|
-
*/
|
|
3309
|
-
declare abstract class VigorError<C extends string, D, T> extends Error {
|
|
3310
|
-
readonly timestamp: Date;
|
|
3311
|
-
readonly cause?: unknown;
|
|
3312
|
-
readonly code: C;
|
|
3313
|
-
readonly data: D;
|
|
3314
|
-
readonly method: string;
|
|
3315
|
-
readonly context: T | undefined;
|
|
3316
|
-
/**
|
|
3317
|
-
* @param code - Machine-readable error code.
|
|
3318
|
-
* @param message - Human-readable message (rendered after the `[code]` prefix).
|
|
3319
|
-
* @param options - Additional error metadata (cause, data, method, context).
|
|
3320
|
-
*/
|
|
3321
|
-
constructor(code: C, message: string, options: VigorErrorOptions<D, T>);
|
|
3322
|
-
}
|
|
3323
|
-
|
|
3324
|
-
declare const VigorRetryErrorMessageFuncs: {
|
|
3325
|
-
readonly VALUE_REQUIRED: ({ key }: {
|
|
3326
|
-
key: string;
|
|
3327
|
-
}) => string;
|
|
3328
|
-
readonly RETRY_EXHAUSTED: ({ maxAttempts }: {
|
|
3329
|
-
maxAttempts: number;
|
|
3330
|
-
error: unknown;
|
|
3331
|
-
}) => string;
|
|
3332
|
-
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
3333
|
-
maxAttempts: number;
|
|
3334
|
-
error: unknown;
|
|
3335
|
-
}) => string;
|
|
3336
|
-
readonly TIMED_OUT: ({ limit }: {
|
|
3337
|
-
limit: number;
|
|
3338
|
-
}) => string;
|
|
3339
|
-
};
|
|
3340
|
-
type VigorRetryErrorCodes = keyof typeof VigorRetryErrorMessageFuncs;
|
|
3341
|
-
type VigorRetryErrorDatas<C extends VigorRetryErrorCodes> = Parameters<typeof VigorRetryErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
3342
|
-
/** Error type thrown by the retry module. */
|
|
3343
|
-
declare class VigorRetryError<C extends VigorRetryErrorCodes, T extends VigorRetrySchema<T>> extends VigorError<C, VigorRetryErrorDatas<C>, VigorRetryContextSchema<T>> {
|
|
3344
|
-
/**
|
|
3345
|
-
* @param code - One of the retry module's error codes.
|
|
3346
|
-
* @param options - Error metadata, including the `data` payload for `code`.
|
|
3347
|
-
*/
|
|
3348
|
-
constructor(code: C, options: VigorErrorOptions<VigorRetryErrorDatas<C>, VigorRetryContextSchema<T>>);
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
declare const VigorParseErrorMessageFuncs: {
|
|
3352
|
-
readonly VALUE_REQUIRED: ({ key }: {
|
|
3353
|
-
key: string;
|
|
3354
|
-
}) => string;
|
|
3355
|
-
readonly INVALID_CONTENT_TYPE: ({ received }: {
|
|
3356
|
-
received: unknown;
|
|
3357
|
-
}) => string;
|
|
3358
|
-
readonly PARSER_NOT_FOUND: ({ received, expected }: {
|
|
3359
|
-
received: unknown;
|
|
3360
|
-
expected: Array<string>;
|
|
3361
|
-
}) => string;
|
|
3362
|
-
readonly PARSER_ALL_FAILED: ({ tried }: {
|
|
3363
|
-
tried: Array<string>;
|
|
3364
|
-
}) => string;
|
|
3365
|
-
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
3366
|
-
maxAttempts: number;
|
|
3367
|
-
error: unknown;
|
|
3368
|
-
}) => string;
|
|
3369
|
-
};
|
|
3370
|
-
type VigorParseErrorCodes = keyof typeof VigorParseErrorMessageFuncs;
|
|
3371
|
-
type VigorParseErrorDatas<C extends VigorParseErrorCodes> = Parameters<typeof VigorParseErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
3372
|
-
/** Error type thrown by the parse module. */
|
|
3373
|
-
declare class VigorParseError<C extends VigorParseErrorCodes, T extends VigorParseSchema<T>> extends VigorError<C, VigorParseErrorDatas<C>, VigorParseContextSchema<T>> {
|
|
3374
|
-
/**
|
|
3375
|
-
* @param code - One of the parse module's error codes.
|
|
3376
|
-
* @param options - Error metadata, including the `data` payload for `code`.
|
|
3377
|
-
*/
|
|
3378
|
-
constructor(code: C, options: VigorErrorOptions<VigorParseErrorDatas<C>, VigorParseContextSchema<T>>);
|
|
3379
|
-
}
|
|
3380
|
-
|
|
3381
|
-
declare const VigorFetchErrorMessageFuncs: {
|
|
3382
|
-
readonly VALUE_REQUIRED: ({ key }: {
|
|
3383
|
-
key: string;
|
|
3384
|
-
}) => string;
|
|
3385
|
-
readonly INVALID_BODY: ({ received }: {
|
|
3386
|
-
received: unknown;
|
|
3387
|
-
}) => string;
|
|
3388
|
-
readonly INVALID_PROTOCOL: ({ origin, base }: {
|
|
3389
|
-
origin: string;
|
|
3390
|
-
base: string | undefined;
|
|
3391
|
-
}) => string;
|
|
3392
|
-
readonly FETCH_FAILED: ({ status, statusText }: {
|
|
3393
|
-
status: number;
|
|
3394
|
-
statusText: string;
|
|
3395
|
-
response: Response;
|
|
3396
|
-
url: string;
|
|
3397
|
-
parsed: unknown;
|
|
3398
|
-
}) => string;
|
|
3399
|
-
readonly RESTART_EXHAUSTED: ({ maxAttempts }: {
|
|
3400
|
-
maxAttempts: number;
|
|
3401
|
-
error: unknown;
|
|
3402
|
-
}) => string;
|
|
3403
|
-
};
|
|
3404
|
-
type VigorFetchErrorCodes = keyof typeof VigorFetchErrorMessageFuncs;
|
|
3405
|
-
type VigorFetchErrorDatas<C extends VigorFetchErrorCodes> = Parameters<typeof VigorFetchErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
3406
|
-
/** Error type thrown by the fetch module. */
|
|
3407
|
-
declare class VigorFetchError<C extends VigorFetchErrorCodes, T extends VigorFetchSchema<T>> extends VigorError<C, VigorFetchErrorDatas<C>, VigorFetchContextSchema<T>> {
|
|
3408
|
-
/**
|
|
3409
|
-
* @param code - One of the fetch module's error codes.
|
|
3410
|
-
* @param options - Error metadata, including the `data` payload for `code`.
|
|
3411
|
-
*/
|
|
3412
|
-
constructor(code: C, options: VigorErrorOptions<VigorFetchErrorDatas<C>, VigorFetchContextSchema<T>>);
|
|
3413
|
-
}
|
|
3414
|
-
|
|
3415
|
-
declare const VigorAllErrorMessageFuncs: {
|
|
3416
|
-
readonly EMPTY_TARGET: (_: {}) => string;
|
|
3417
|
-
};
|
|
3418
|
-
type VigorAllErrorCodes = keyof typeof VigorAllErrorMessageFuncs;
|
|
3419
|
-
type VigorAllErrorDatas<C extends VigorAllErrorCodes> = Parameters<typeof VigorAllErrorMessageFuncs[C]> extends [infer A] ? A : undefined;
|
|
3420
|
-
/** Error type thrown by the all module. */
|
|
3421
|
-
declare class VigorAllError<C extends VigorAllErrorCodes, T extends VigorAllSchema<T>> extends VigorError<C, VigorAllErrorDatas<C>, VigorAllContextSchema<T>> {
|
|
3422
|
-
/**
|
|
3423
|
-
* @param code - One of the all module's error codes.
|
|
3424
|
-
* @param options - Error metadata, including the `data` payload for `code`.
|
|
3425
|
-
*/
|
|
3426
|
-
constructor(code: C, options: VigorErrorOptions<VigorAllErrorDatas<C>, VigorAllContextSchema<T>>);
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
export { VigorAll, VigorAllBase, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllNaturalResult, type VigorAllPipeInitialContext, type VigorAllPipeResult, type VigorAllPipeStepResult, type VigorAllPipeStepVoid, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresPipe, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllSchema, type VigorAllTask, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorBuiltin, type VigorCastResult, type VigorConcat, type VigorDeepMerge, type VigorDeepPartial, VigorError, type VigorErrorOptions, VigorFetch, VigorFetchBase, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchPipeInitialContext, type VigorFetchPipeResult, type VigorFetchPipeStepResult, type VigorFetchPipeStepVoid, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresPipe, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchSchema, type VigorInstance, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, VigorParse, VigorParseBase, VigorParseContentTypeStrategy, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParsePipeInitialContext, type VigorParsePipeResult, type VigorParsePipeStepResult, type VigorParsePipeStepVoid, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresPipe, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, VigorRetry, VigorRetryBase, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryPipeInitialContext, type VigorRetryPipeResult, type VigorRetryPipeStepResult, type VigorRetryPipeStepRetryIf, type VigorRetryPipeStepVoid, VigorRetryPolicyAlgorithms, VigorRetryPolicyAlgorithmsBackoff, VigorRetryPolicyAlgorithmsBackoffBase, type VigorRetryPolicyAlgorithmsBackoffSchema, VigorRetryPolicyAlgorithmsBase, VigorRetryPolicyAlgorithmsConstant, VigorRetryPolicyAlgorithmsConstantBase, type VigorRetryPolicyAlgorithmsConstantSchema, VigorRetryPolicyAlgorithmsCustom, VigorRetryPolicyAlgorithmsCustomBase, type VigorRetryPolicyAlgorithmsCustomSchema, VigorRetryPolicyAlgorithmsLinear, VigorRetryPolicyAlgorithmsLinearBase, type VigorRetryPolicyAlgorithmsLinearSchema, type VigorRetryPolicyAlgorithmsSchema, VigorRetryPolicyBase, VigorRetryPolicyMiddlewares, type VigorRetryPolicyMiddlewaresApi, VigorRetryPolicyMiddlewaresBase, type VigorRetryPolicyMiddlewaresFluent, type VigorRetryPolicyMiddlewaresIntercept, type VigorRetryPolicyMiddlewaresPipe, type VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetrySchema, type VigorReturnType, type VigorSimplify, VigorStatus, type VigorStringable, vigor as default, vigor };
|
|
3634
|
+
export { VigorAll, VigorAllBase, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllErrors, type VigorAllNaturalResult, type VigorAllPipeInitialContext, type VigorAllPipeResult, type VigorAllPipeStepResult, type VigorAllPipeStepVoid, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresPipe, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllRequestError, type VigorAllSchema, type VigorAllTask, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorBuiltin, type VigorCastResult, type VigorConcat, type VigorDeepMerge, type VigorDeepPartial, VigorError, type VigorErrorOptions, VigorFetch, VigorFetchBase, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchErrors, type VigorFetchPipeInitialContext, type VigorFetchPipeResult, type VigorFetchPipeStepResult, type VigorFetchPipeStepVoid, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresPipe, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchRequestError, type VigorFetchSchema, type VigorInstance, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, VigorParse, VigorParseBase, VigorParseContentTypeStrategy, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParseErrors, type VigorParsePipeInitialContext, type VigorParsePipeResult, type VigorParsePipeStepResult, type VigorParsePipeStepVoid, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresPipe, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseRequestError, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, type VigorResultError, VigorRetry, VigorRetryBase, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryErrors, type VigorRetryPipeInitialContext, type VigorRetryPipeResult, type VigorRetryPipeStepResult, type VigorRetryPipeStepRetryIf, type VigorRetryPipeStepVoid, VigorRetryPolicyAlgorithms, VigorRetryPolicyAlgorithmsBackoff, VigorRetryPolicyAlgorithmsBackoffBase, type VigorRetryPolicyAlgorithmsBackoffSchema, VigorRetryPolicyAlgorithmsBase, VigorRetryPolicyAlgorithmsConstant, VigorRetryPolicyAlgorithmsConstantBase, type VigorRetryPolicyAlgorithmsConstantSchema, VigorRetryPolicyAlgorithmsCustom, VigorRetryPolicyAlgorithmsCustomBase, type VigorRetryPolicyAlgorithmsCustomSchema, VigorRetryPolicyAlgorithmsLinear, VigorRetryPolicyAlgorithmsLinearBase, type VigorRetryPolicyAlgorithmsLinearSchema, type VigorRetryPolicyAlgorithmsSchema, VigorRetryPolicyBase, VigorRetryPolicyMiddlewares, type VigorRetryPolicyMiddlewaresApi, VigorRetryPolicyMiddlewaresBase, type VigorRetryPolicyMiddlewaresFluent, type VigorRetryPolicyMiddlewaresIntercept, type VigorRetryPolicyMiddlewaresPipe, type VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetryRequestError, type VigorRetrySchema, type VigorReturnType, type VigorSimplify, VigorStatus, type VigorStringable, vigor as default, isVigorAllError, isVigorFetchError, isVigorParseError, isVigorRetryError, vigor };
|