vigor-fetch 5.2.0 → 5.3.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 CHANGED
@@ -145,14 +145,16 @@ vigor.guards.fetch(err) // isVigorFetchError
145
145
  vigor.guards.all(err) // isVigorAllError
146
146
  ```
147
147
 
148
- Each guard also has a `find` that looks inside wrapped errors. A request that runs out of attempts fails with `RETRY_EXHAUSTED`, and the error that actually happened (a `FETCH_FAILED`, a `TIMED_OUT`, ...) sits in its `data.error`. `find` walks the error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`, then `cause`, and returns the first error with one of the given codes, or `null`:
148
+ A request that runs out of attempts fails with `RETRY_EXHAUSTED`, and the error that actually happened (a `FETCH_FAILED`, a `TIMED_OUT`, ...) sits in its `data.error`. To reach it, pass a callback as the third argument, with the code (or an array of codes) as the second. The guard then looks at the error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`, then `cause`, and calls the callback with the first match, typed for its code. It returns what the callback returns, or `undefined` when nothing matches:
149
149
 
150
150
  ```ts
151
- const failed = vigor.guards.fetch.find(err, "FETCH_FAILED") // same as findVigorFetchError(err, "FETCH_FAILED")
152
- if (failed) failed.data.status
151
+ vigor.guards.fetch(err, "FETCH_FAILED", failed => {
152
+ failed.data.status // found even when wrapped in RETRY_EXHAUSTED
153
+ })
154
+ const status = vigor.guards.fetch(err, ["FETCH_FAILED", "TIMED_OUT"], e => e.code) // "FETCH_FAILED" | "TIMED_OUT" | undefined
153
155
  ```
154
156
 
155
- The guard itself only checks the error you pass: a guard narrows its argument, so it can't say `true` for an error found one level down. Use `find` when you want the underlying error wherever it is, and the guard when the outer code matters (e.g. "did we give up retrying?").
157
+ Without a callback the guard only checks the error you pass, as before: it narrows its argument, and that argument is still the wrapper. So `vigor.guards.fetch(err, "FETCH_FAILED")` is `false` for a `RETRY_EXHAUSTED`, and `vigor.guards.fetch(err, "RETRY_EXHAUSTED")` is how you ask "did we give up retrying?".
156
158
 
157
159
  ---
158
160
 
@@ -829,7 +831,7 @@ try {
829
831
 
830
832
  `VigorRetryErrors` & co. are unions with **one member per error code**, so narrowing by `code` also narrows `data` to that code's payload. The `{} | null | undefined` tail is everything Vigor didn't create — an error your own target or middleware threw, an abort reason, a network `TypeError`, or even a bare `throw null`. It's there because those really do reach you: a `cancelRetry()`/`breakRetry()`/abort path returns your error as-is, rather than wrapping it.
831
833
 
832
- Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`). To reach an error wrapped by `RETRY_EXHAUSTED`, use `findVigor*Error` (or `vigor.guards.*.find`, see [`vigor.guards`](#vigorguards)):
834
+ Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`). To reach an error wrapped by `RETRY_EXHAUSTED`, pass a callback (see [`vigor.guards`](#vigorguards)):
833
835
 
834
836
  ```ts
835
837
  const res = await vigor.retry(task).requestVerbose();
@@ -914,10 +916,11 @@ With an [API map](#route-descriptions) route that declares failure `responses`,
914
916
  ```ts
915
917
  const res = await api.route("POST /users").body("overwrite", { name: "a" }).requestVerbose()
916
918
  if (!res.success) {
917
- const err = findVigorFetchError(res.error, "FETCH_FAILED") // unwraps RETRY_EXHAUSTED if needed
918
- if (err && err.data.status === 422) {
919
- err.data.parsed // { fields: Record<string, string> } | undefined
920
- }
919
+ isVigorFetchError(res.error, "FETCH_FAILED", err => { // unwraps RETRY_EXHAUSTED if needed
920
+ if (err.data.status === 422) {
921
+ err.data.parsed // { fields: Record<string, string> } | undefined
922
+ }
923
+ })
921
924
  }
922
925
  ```
923
926
 
package/dist/index.cjs CHANGED
@@ -86,10 +86,6 @@ __export(index_exports, {
86
86
  createVigorTimelineRecorder: () => createVigorTimelineRecorder,
87
87
  default: () => index_default,
88
88
  findInVigorErrorChain: () => findInVigorErrorChain,
89
- findVigorAllError: () => findVigorAllError,
90
- findVigorFetchError: () => findVigorFetchError,
91
- findVigorParseError: () => findVigorParseError,
92
- findVigorRetryError: () => findVigorRetryError,
93
89
  isVigorAllError: () => isVigorAllError,
94
90
  isVigorDefault: () => isVigorDefault,
95
91
  isVigorEmpty: () => isVigorEmpty,
@@ -99,6 +95,7 @@ __export(index_exports, {
99
95
  isVigorRetryError: () => isVigorRetryError,
100
96
  markVigorInternal: () => markVigorInternal,
101
97
  readVigorParseBody: () => readVigorParseBody,
98
+ runVigorGuard: () => runVigorGuard,
102
99
  vigor: () => vigor
103
100
  });
104
101
  module.exports = __toCommonJS(index_exports);
@@ -343,6 +340,13 @@ function findInVigorErrorChain(error, match) {
343
340
  };
344
341
  return visit(error);
345
342
  }
343
+ function runVigorGuard(error, args, is) {
344
+ const callback = args[args.length - 1];
345
+ if (typeof callback !== "function") return is(error, args);
346
+ const codes = Array.isArray(args[0]) ? args[0] : [args[0]];
347
+ const found = findInVigorErrorChain(error, (e) => is(e, codes));
348
+ return found === void 0 ? void 0 : callback(found);
349
+ }
346
350
 
347
351
  // src/all/error.ts
348
352
  var VigorAllErrorMessageFuncs = {
@@ -359,12 +363,8 @@ var VigorAllError = class extends VigorError {
359
363
  super(code, messageFn(options.data), options);
360
364
  }
361
365
  };
362
- function isVigorAllError(error, ...codes) {
363
- return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
364
- }
365
- function findVigorAllError(error, ...codes) {
366
- const found = findInVigorErrorChain(error, (e) => isVigorAllError(e, ...codes));
367
- return found === void 0 ? null : found;
366
+ function isVigorAllError(error, ...args) {
367
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorAllError && (codes.length === 0 || codes.includes(e.code)));
368
368
  }
369
369
 
370
370
  // src/core/timeline.ts
@@ -880,12 +880,8 @@ var VigorRetryError = class extends VigorError {
880
880
  super(code, messageFn(options.data), options);
881
881
  }
882
882
  };
883
- function isVigorRetryError(error, ...codes) {
884
- return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
885
- }
886
- function findVigorRetryError(error, ...codes) {
887
- const found = findInVigorErrorChain(error, (e) => isVigorRetryError(e, ...codes));
888
- return found === void 0 ? null : found;
883
+ function isVigorRetryError(error, ...args) {
884
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorRetryError && (codes.length === 0 || codes.includes(e.code)));
889
885
  }
890
886
 
891
887
  // src/retry/algorithms.ts
@@ -1588,12 +1584,8 @@ var VigorParseError = class extends VigorError {
1588
1584
  super(code, messageFn(options.data), options);
1589
1585
  }
1590
1586
  };
1591
- function isVigorParseError(error, ...codes) {
1592
- return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1593
- }
1594
- function findVigorParseError(error, ...codes) {
1595
- const found = findInVigorErrorChain(error, (e) => isVigorParseError(e, ...codes));
1596
- return found === void 0 ? null : found;
1587
+ function isVigorParseError(error, ...args) {
1588
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorParseError && (codes.length === 0 || codes.includes(e.code)));
1597
1589
  }
1598
1590
 
1599
1591
  // src/parse/strategies.ts
@@ -2084,12 +2076,8 @@ var VigorFetchError = class extends VigorError {
2084
2076
  super(code, messageFn(options.data), options);
2085
2077
  }
2086
2078
  };
2087
- function isVigorFetchError(error, ...codes) {
2088
- return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
2089
- }
2090
- function findVigorFetchError(error, ...codes) {
2091
- const found = findInVigorErrorChain(error, (e) => isVigorFetchError(e, ...codes));
2092
- return found === void 0 ? null : found;
2079
+ function isVigorFetchError(error, ...args) {
2080
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorFetchError && (codes.length === 0 || codes.includes(e.code)));
2093
2081
  }
2094
2082
  function adoptVigorFetchError(error, context) {
2095
2083
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
@@ -2662,7 +2650,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
2662
2650
  };
2663
2651
 
2664
2652
  // src/entry/main.ts
2665
- var guardWithFind = (guard, find) => Object.assign(((...args) => guard(...args)), { find });
2666
2653
  function retryWithTarget(task) {
2667
2654
  return new VigorRetry().target(task);
2668
2655
  }
@@ -2707,10 +2694,10 @@ var vigorBase = {
2707
2694
  }
2708
2695
  },
2709
2696
  guards: {
2710
- retry: guardWithFind(isVigorRetryError, findVigorRetryError),
2711
- parse: guardWithFind(isVigorParseError, findVigorParseError),
2712
- fetch: guardWithFind(isVigorFetchError, findVigorFetchError),
2713
- all: guardWithFind(isVigorAllError, findVigorAllError)
2697
+ retry: isVigorRetryError,
2698
+ parse: isVigorParseError,
2699
+ fetch: isVigorFetchError,
2700
+ all: isVigorAllError
2714
2701
  }
2715
2702
  };
2716
2703
  var cloneVigor = (v) => ({
@@ -2805,10 +2792,6 @@ var index_default = vigor;
2805
2792
  createBrand,
2806
2793
  createVigorTimelineRecorder,
2807
2794
  findInVigorErrorChain,
2808
- findVigorAllError,
2809
- findVigorFetchError,
2810
- findVigorParseError,
2811
- findVigorRetryError,
2812
2795
  isVigorAllError,
2813
2796
  isVigorDefault,
2814
2797
  isVigorEmpty,
@@ -2818,5 +2801,6 @@ var index_default = vigor;
2818
2801
  isVigorRetryError,
2819
2802
  markVigorInternal,
2820
2803
  readVigorParseBody,
2804
+ runVigorGuard,
2821
2805
  vigor
2822
2806
  });
package/dist/index.d.cts CHANGED
@@ -764,11 +764,21 @@ declare abstract class VigorError<C extends string, D, T = unknown> extends Erro
764
764
  * `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`), then its `cause`. Each wrapped
765
765
  * error is searched fully before moving on. Cycles are skipped.
766
766
  *
767
- * This is what the `find` of each `vigor.guards.*` uses, so a caller can ask
768
- * for the error that actually happened (e.g. `FETCH_FAILED`) without
769
- * unwrapping the retry layers by hand.
767
+ * This is what the callback form of the `isVigor*Error` guards uses, so a
768
+ * caller can ask for the error that actually happened (e.g. `FETCH_FAILED`)
769
+ * without unwrapping the retry layers by hand.
770
770
  */
771
771
  declare function findInVigorErrorChain(error: unknown, match: (error: unknown) => boolean): unknown;
772
+ /**
773
+ * Shared body of the `isVigor*Error` guards. `is` checks one error against a
774
+ * code list (empty means any code of that module).
775
+ *
776
+ * - `(error, ...codes)`: checks `error` itself and returns a boolean.
777
+ * - `(error, codes, callback)`: searches `error`'s chain (see
778
+ * {@link findInVigorErrorChain}) and calls `callback` with the first match.
779
+ * Returns what `callback` returns, or `undefined` when nothing matches.
780
+ */
781
+ declare function runVigorGuard(error: unknown, args: readonly unknown[], is: (error: unknown, codes: readonly unknown[]) => boolean): unknown;
772
782
 
773
783
  declare const VigorParseErrorMessageFuncs: {
774
784
  readonly VALUE_REQUIRED: ({ key }: {
@@ -851,23 +861,23 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
851
861
  * if (isVigorParseError(error, "PARSER_NOT_FOUND")) {
852
862
  * error.data // that code's payload
853
863
  * }
854
- */
855
- declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
856
- declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
857
- /**
858
- * Like `isVigorParseError(error, ...codes)`, but also looks inside the errors
859
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
860
- * then `cause` — and returns the first match, outermost first. Returns
861
- * `null` when there is none. `error` itself is left as it is.
862
864
  *
863
- * A guard can't do this: it narrows the value you pass, so a `true` for a
864
- * wrapped match would claim the wrapper has the inner error's `data`.
865
+ * Pass a `callback` as the third argument (with the code, or an array of
866
+ * codes, as the second) to also look inside the errors `error` wraps: the
867
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
868
+ * then `cause`. `callback` gets the first match, outermost first, typed for
869
+ * its code; the guard returns what `callback` returns, or `undefined` when
870
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
871
+ * which is still the wrapper.)
865
872
  *
866
873
  * @example
867
- * const notFound = findVigorParseError(error, "PARSER_NOT_FOUND")
868
- * if (notFound) notFound.data.expected
874
+ * isVigorParseError(error, "PARSER_NOT_FOUND", error => {
875
+ * error.data.expected // found even when wrapped in RETRY_EXHAUSTED
876
+ * })
869
877
  */
870
- declare function findVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorParseErrorsIn<E, C> | null;
878
+ declare function isVigorParseError<E, const C extends VigorParseErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorParseErrorsIn<E, C>) => R): R | undefined;
879
+ declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
880
+ declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
871
881
 
872
882
  type VigorParsePolicySchema<T extends VigorParseSchema<T>> = {
873
883
  __brand: VigorBrand<"Parse", "Policy<Schema">;
@@ -1736,23 +1746,23 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1736
1746
  * if (isVigorRetryError(error, "TIMED_OUT")) {
1737
1747
  * error.data // that code's payload
1738
1748
  * }
1739
- */
1740
- declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1741
- declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1742
- /**
1743
- * Like `isVigorRetryError(error, ...codes)`, but also looks inside the errors
1744
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
1745
- * then `cause` — and returns the first match, outermost first. Returns
1746
- * `null` when there is none. `error` itself is left as it is.
1747
1749
  *
1748
- * A guard can't do this: it narrows the value you pass, so a `true` for a
1749
- * wrapped match would claim the wrapper has the inner error's `data`.
1750
+ * Pass a `callback` as the third argument (with the code, or an array of
1751
+ * codes, as the second) to also look inside the errors `error` wraps: the
1752
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
1753
+ * then `cause`. `callback` gets the first match, outermost first, typed for
1754
+ * its code; the guard returns what `callback` returns, or `undefined` when
1755
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
1756
+ * which is still the wrapper.)
1750
1757
  *
1751
1758
  * @example
1752
- * const timedOut = findVigorRetryError(error, "TIMED_OUT")
1753
- * if (timedOut) timedOut.data.limit
1759
+ * isVigorRetryError(error, "TIMED_OUT", error => {
1760
+ * error.data.limit // found even when wrapped in RETRY_EXHAUSTED
1761
+ * })
1754
1762
  */
1755
- declare function findVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorRetryErrorsIn<E, C> | null;
1763
+ declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorRetryErrorsIn<E, C>) => R): R | undefined;
1764
+ declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1765
+ declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1756
1766
 
1757
1767
  type VigorRetryPolicySchema<T extends VigorRetrySchema<T>> = {
1758
1768
  __brand: VigorBrand<"Retry", "Policy<Schema">;
@@ -2520,23 +2530,23 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2520
2530
  * if (isVigorAllError(error, "TIMED_OUT")) {
2521
2531
  * error.data // that code's payload
2522
2532
  * }
2523
- */
2524
- declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2525
- declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2526
- /**
2527
- * Like `isVigorAllError(error, ...codes)`, but also looks inside the errors
2528
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
2529
- * then `cause` — and returns the first match, outermost first. Returns
2530
- * `null` when there is none. `error` itself is left as it is.
2531
2533
  *
2532
- * A guard can't do this: it narrows the value you pass, so a `true` for a
2533
- * wrapped match would claim the wrapper has the inner error's `data`.
2534
+ * Pass a `callback` as the third argument (with the code, or an array of
2535
+ * codes, as the second) to also look inside the errors `error` wraps: the
2536
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
2537
+ * then `cause`. `callback` gets the first match, outermost first, typed for
2538
+ * its code; the guard returns what `callback` returns, or `undefined` when
2539
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
2540
+ * which is still the wrapper.)
2534
2541
  *
2535
2542
  * @example
2536
- * const timedOut = findVigorAllError(error, "TIMED_OUT")
2537
- * if (timedOut) timedOut.data.index
2543
+ * isVigorAllError(error, "TIMED_OUT", error => {
2544
+ * error.data.index // found even when wrapped in RETRY_EXHAUSTED
2545
+ * })
2538
2546
  */
2539
- declare function findVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorAllErrorsIn<E, C> | null;
2547
+ declare function isVigorAllError<E, const C extends VigorAllErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorAllErrorsIn<E, C>) => R): R | undefined;
2548
+ declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2549
+ declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2540
2550
 
2541
2551
  /**
2542
2552
  * A single task. It receives an `AbortSignal` that fires when the task's
@@ -4064,23 +4074,23 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4064
4074
  * if (isVigorFetchError(error, "FETCH_FAILED")) {
4065
4075
  * error.data // that code's payload
4066
4076
  * }
4067
- */
4068
- declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4069
- declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4070
- /**
4071
- * Like `isVigorFetchError(error, ...codes)`, but also looks inside the errors
4072
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
4073
- * then `cause` — and returns the first match, outermost first. Returns
4074
- * `null` when there is none. `error` itself is left as it is.
4075
4077
  *
4076
- * A guard can't do this: it narrows the value you pass, so a `true` for a
4077
- * wrapped match would claim the wrapper has the inner error's `data`.
4078
+ * Pass a `callback` as the third argument (with the code, or an array of
4079
+ * codes, as the second) to also look inside the errors `error` wraps: the
4080
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
4081
+ * then `cause`. `callback` gets the first match, outermost first, typed for
4082
+ * its code; the guard returns what `callback` returns, or `undefined` when
4083
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
4084
+ * which is still the wrapper.)
4078
4085
  *
4079
4086
  * @example
4080
- * const failed = findVigorFetchError(error, "FETCH_FAILED")
4081
- * if (failed) failed.data.status
4087
+ * isVigorFetchError(error, "FETCH_FAILED", error => {
4088
+ * error.data.status // found even when wrapped in RETRY_EXHAUSTED
4089
+ * })
4082
4090
  */
4083
- declare function findVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorFetchErrorsIn<E, C> | null;
4091
+ declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorFetchErrorsIn<E, C>) => R): R | undefined;
4092
+ declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4093
+ declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4084
4094
  /**
4085
4095
  * Re-raises an error of the nested retry/parse engine as a `VigorFetchError`
4086
4096
  * with the same `code`, `data`, and `method`, keeping the original as
@@ -5481,18 +5491,10 @@ declare const vigorBase: {
5481
5491
  };
5482
5492
  };
5483
5493
  guards: {
5484
- retry: typeof isVigorRetryError & {
5485
- find: typeof findVigorRetryError;
5486
- };
5487
- parse: typeof isVigorParseError & {
5488
- find: typeof findVigorParseError;
5489
- };
5490
- fetch: typeof isVigorFetchError & {
5491
- find: typeof findVigorFetchError;
5492
- };
5493
- all: typeof isVigorAllError & {
5494
- find: typeof findVigorAllError;
5495
- };
5494
+ retry: typeof isVigorRetryError;
5495
+ parse: typeof isVigorParseError;
5496
+ fetch: typeof isVigorFetchError;
5497
+ all: typeof isVigorAllError;
5496
5498
  };
5497
5499
  };
5498
5500
  /** `A` with `B`'s properties replacing same-named ones, like `{ ...A, ...B }`. */
@@ -5522,4 +5524,4 @@ type VigorPlugin<O extends {
5522
5524
  };
5523
5525
  declare const vigor: VigorInstance;
5524
5526
 
5525
- export { VigorAll, type VigorAllAfterContextSchema, VigorAllBase, type VigorAllBeforeContextSchema, type VigorAllCastNaturalResult, VigorAllContextBase, type VigorAllContextSchema, VigorAllEachContextBase, type VigorAllEachContextSchema, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorCodesWithOptionalContext, type VigorAllErrorCodesWithoutContext, type VigorAllErrorContext, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllErrors, type VigorAllErrorsIn, type VigorAllNaturalResult, type VigorAllOnResultContextSchema, type VigorAllPipeResult, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllProcessHandler, type VigorAllRequestError, type VigorAllResult, type VigorAllResultContextSchema, type VigorAllSchema, type VigorAllSettled, type VigorAllTask, type VigorAllTaskError, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorAllTimeline, type VigorAllTimelineEvents, type VigorAllTimelineSnapshot, type VigorApiFailure, type VigorApiKeys, type VigorApiMap, type VigorApiMapSlot, type VigorApiMatch, type VigorApiMatched, type VigorApiMethod, type VigorApiNoMatchType, type VigorApiParamValue, type VigorApiRequestIssue, type VigorApiRequestIssues, type VigorApiResponse, type VigorApiRoute, type VigorApiRouteKey, type VigorApiRouteOf, type VigorApiStatusClass, type VigorApiSuccess, type VigorBrand, type VigorBuiltin, VigorCastPlaceholder, type VigorCastPlaceholderType, type VigorCastResult, type VigorConcat, type VigorContextApply, type VigorContextChanges, type VigorContextReset, type VigorContextStage, type VigorDeepMerge, type VigorDeepPartial, VigorDefault, type VigorDefaultType, VigorEmpty, type VigorEmptyType, VigorError, type VigorErrorContext, type VigorErrorOptions, type VigorExcludeDefault, type VigorExcludeEmpty, VigorFetch, type VigorFetchAfterContextSchema, VigorFetchBase, type VigorFetchBeforeContextSchema, type VigorFetchBodyFor, VigorFetchContextBase, type VigorFetchContextSchema, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorCodesWithOptionalContext, type VigorFetchErrorCodesWithoutContext, type VigorFetchErrorContext, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchErrorPipeResult, type VigorFetchErrors, type VigorFetchErrorsIn, type VigorFetchExtraOptions, type VigorFetchFailedData, type VigorFetchInferResult, type VigorFetchMethodFor, type VigorFetchNaturalFor, type VigorFetchNaturalResult, type VigorFetchOnErrorContextSchema, type VigorFetchOnResultContextSchema, type VigorFetchOptions, type VigorFetchParseSource, type VigorFetchParsedResult, type VigorFetchPipeResult, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchProcessHandler, type VigorFetchRequestError, type VigorFetchRequestThis, type VigorFetchResult, type VigorFetchResultContextSchema, type VigorFetchRouteKeys, type VigorFetchSchema, type VigorFetchTimeline, type VigorFetchTimelineEvents, type VigorFetchTimelineSnapshot, type VigorFetchVerboseResult, type VigorHttpFailureStatus, type VigorHttpStatusOf, type VigorHttpSuccessStatus, type VigorInstance, type VigorIsSame, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, type VigorNoExtraKeys, VigorParse, type VigorParseAfterContextSchema, VigorParseBase, type VigorParseBeforeContextSchema, type VigorParseBody, VigorParseContentTypeStrategy, VigorParseContextBase, type VigorParseContextSchema, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorCodesWithOptionalContext, type VigorParseErrorCodesWithoutContext, type VigorParseErrorContext, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParseErrorPipeResult, type VigorParseErrors, type VigorParseErrorsIn, type VigorParseNaturalResult, type VigorParseOnErrorContextSchema, type VigorParseOnResultContextSchema, type VigorParsePipeResult, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseProcessHandler, type VigorParseRequestError, type VigorParseResult, type VigorParseResultContextSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorParseTimeline, type VigorParseTimelineEvents, type VigorParseTimelineSnapshot, type VigorPathList, type VigorPathSegments, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, type VigorResolvedMethod, type VigorResultError, type VigorResultOf, VigorRetry, type VigorRetryAfterContextSchema, VigorRetryBase, type VigorRetryBeforeContextSchema, VigorRetryContextBase, type VigorRetryContextSchema, type VigorRetryDecisionReason, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorCodesWithOptionalContext, type VigorRetryErrorCodesWithoutContext, type VigorRetryErrorContext, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryErrorPipeResult, type VigorRetryErrors, type VigorRetryErrorsIn, type VigorRetryNaturalResult, type VigorRetryOnErrorContextSchema, type VigorRetryOnResultContextSchema, type VigorRetryOnRetryContextSchema, type VigorRetryPipeResult, 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 VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetryProcessHandler, type VigorRetryRequestError, type VigorRetryResult, type VigorRetryResultContextSchema, type VigorRetryRetryIfContextSchema, type VigorRetrySchema, type VigorRetryTimeline, type VigorRetryTimelineEvents, type VigorRetryTimelineSnapshot, type VigorReturnType, type VigorRouteMethod, type VigorRouteParams, type VigorRoutePath, type VigorRoutePathList, type VigorRouteWithParams, type VigorRouteWithoutParams, type VigorSimplify, VigorStatus, type VigorStringable, type VigorTimeline, type VigorTimelineEndEvents, type VigorTimelineItem, type VigorTimelineMiddlewareEvents, type VigorTimelineOutcome, type VigorTimelineProcessEvents, type VigorTimelineSnapshot, adoptVigorFetchError, createBrand, createVigorTimelineRecorder, vigor as default, findInVigorErrorChain, findVigorAllError, findVigorFetchError, findVigorParseError, findVigorRetryError, isVigorAllError, isVigorDefault, isVigorEmpty, isVigorFetchError, isVigorInternalMiddleware, isVigorParseError, isVigorRetryError, markVigorInternal, readVigorParseBody, vigor };
5527
+ export { VigorAll, type VigorAllAfterContextSchema, VigorAllBase, type VigorAllBeforeContextSchema, type VigorAllCastNaturalResult, VigorAllContextBase, type VigorAllContextSchema, VigorAllEachContextBase, type VigorAllEachContextSchema, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorCodesWithOptionalContext, type VigorAllErrorCodesWithoutContext, type VigorAllErrorContext, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllErrors, type VigorAllErrorsIn, type VigorAllNaturalResult, type VigorAllOnResultContextSchema, type VigorAllPipeResult, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllProcessHandler, type VigorAllRequestError, type VigorAllResult, type VigorAllResultContextSchema, type VigorAllSchema, type VigorAllSettled, type VigorAllTask, type VigorAllTaskError, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorAllTimeline, type VigorAllTimelineEvents, type VigorAllTimelineSnapshot, type VigorApiFailure, type VigorApiKeys, type VigorApiMap, type VigorApiMapSlot, type VigorApiMatch, type VigorApiMatched, type VigorApiMethod, type VigorApiNoMatchType, type VigorApiParamValue, type VigorApiRequestIssue, type VigorApiRequestIssues, type VigorApiResponse, type VigorApiRoute, type VigorApiRouteKey, type VigorApiRouteOf, type VigorApiStatusClass, type VigorApiSuccess, type VigorBrand, type VigorBuiltin, VigorCastPlaceholder, type VigorCastPlaceholderType, type VigorCastResult, type VigorConcat, type VigorContextApply, type VigorContextChanges, type VigorContextReset, type VigorContextStage, type VigorDeepMerge, type VigorDeepPartial, VigorDefault, type VigorDefaultType, VigorEmpty, type VigorEmptyType, VigorError, type VigorErrorContext, type VigorErrorOptions, type VigorExcludeDefault, type VigorExcludeEmpty, VigorFetch, type VigorFetchAfterContextSchema, VigorFetchBase, type VigorFetchBeforeContextSchema, type VigorFetchBodyFor, VigorFetchContextBase, type VigorFetchContextSchema, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorCodesWithOptionalContext, type VigorFetchErrorCodesWithoutContext, type VigorFetchErrorContext, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchErrorPipeResult, type VigorFetchErrors, type VigorFetchErrorsIn, type VigorFetchExtraOptions, type VigorFetchFailedData, type VigorFetchInferResult, type VigorFetchMethodFor, type VigorFetchNaturalFor, type VigorFetchNaturalResult, type VigorFetchOnErrorContextSchema, type VigorFetchOnResultContextSchema, type VigorFetchOptions, type VigorFetchParseSource, type VigorFetchParsedResult, type VigorFetchPipeResult, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchProcessHandler, type VigorFetchRequestError, type VigorFetchRequestThis, type VigorFetchResult, type VigorFetchResultContextSchema, type VigorFetchRouteKeys, type VigorFetchSchema, type VigorFetchTimeline, type VigorFetchTimelineEvents, type VigorFetchTimelineSnapshot, type VigorFetchVerboseResult, type VigorHttpFailureStatus, type VigorHttpStatusOf, type VigorHttpSuccessStatus, type VigorInstance, type VigorIsSame, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, type VigorNoExtraKeys, VigorParse, type VigorParseAfterContextSchema, VigorParseBase, type VigorParseBeforeContextSchema, type VigorParseBody, VigorParseContentTypeStrategy, VigorParseContextBase, type VigorParseContextSchema, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorCodesWithOptionalContext, type VigorParseErrorCodesWithoutContext, type VigorParseErrorContext, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParseErrorPipeResult, type VigorParseErrors, type VigorParseErrorsIn, type VigorParseNaturalResult, type VigorParseOnErrorContextSchema, type VigorParseOnResultContextSchema, type VigorParsePipeResult, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseProcessHandler, type VigorParseRequestError, type VigorParseResult, type VigorParseResultContextSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorParseTimeline, type VigorParseTimelineEvents, type VigorParseTimelineSnapshot, type VigorPathList, type VigorPathSegments, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, type VigorResolvedMethod, type VigorResultError, type VigorResultOf, VigorRetry, type VigorRetryAfterContextSchema, VigorRetryBase, type VigorRetryBeforeContextSchema, VigorRetryContextBase, type VigorRetryContextSchema, type VigorRetryDecisionReason, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorCodesWithOptionalContext, type VigorRetryErrorCodesWithoutContext, type VigorRetryErrorContext, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryErrorPipeResult, type VigorRetryErrors, type VigorRetryErrorsIn, type VigorRetryNaturalResult, type VigorRetryOnErrorContextSchema, type VigorRetryOnResultContextSchema, type VigorRetryOnRetryContextSchema, type VigorRetryPipeResult, 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 VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetryProcessHandler, type VigorRetryRequestError, type VigorRetryResult, type VigorRetryResultContextSchema, type VigorRetryRetryIfContextSchema, type VigorRetrySchema, type VigorRetryTimeline, type VigorRetryTimelineEvents, type VigorRetryTimelineSnapshot, type VigorReturnType, type VigorRouteMethod, type VigorRouteParams, type VigorRoutePath, type VigorRoutePathList, type VigorRouteWithParams, type VigorRouteWithoutParams, type VigorSimplify, VigorStatus, type VigorStringable, type VigorTimeline, type VigorTimelineEndEvents, type VigorTimelineItem, type VigorTimelineMiddlewareEvents, type VigorTimelineOutcome, type VigorTimelineProcessEvents, type VigorTimelineSnapshot, adoptVigorFetchError, createBrand, createVigorTimelineRecorder, vigor as default, findInVigorErrorChain, isVigorAllError, isVigorDefault, isVigorEmpty, isVigorFetchError, isVigorInternalMiddleware, isVigorParseError, isVigorRetryError, markVigorInternal, readVigorParseBody, runVigorGuard, vigor };
package/dist/index.d.ts CHANGED
@@ -764,11 +764,21 @@ declare abstract class VigorError<C extends string, D, T = unknown> extends Erro
764
764
  * `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`), then its `cause`. Each wrapped
765
765
  * error is searched fully before moving on. Cycles are skipped.
766
766
  *
767
- * This is what the `find` of each `vigor.guards.*` uses, so a caller can ask
768
- * for the error that actually happened (e.g. `FETCH_FAILED`) without
769
- * unwrapping the retry layers by hand.
767
+ * This is what the callback form of the `isVigor*Error` guards uses, so a
768
+ * caller can ask for the error that actually happened (e.g. `FETCH_FAILED`)
769
+ * without unwrapping the retry layers by hand.
770
770
  */
771
771
  declare function findInVigorErrorChain(error: unknown, match: (error: unknown) => boolean): unknown;
772
+ /**
773
+ * Shared body of the `isVigor*Error` guards. `is` checks one error against a
774
+ * code list (empty means any code of that module).
775
+ *
776
+ * - `(error, ...codes)`: checks `error` itself and returns a boolean.
777
+ * - `(error, codes, callback)`: searches `error`'s chain (see
778
+ * {@link findInVigorErrorChain}) and calls `callback` with the first match.
779
+ * Returns what `callback` returns, or `undefined` when nothing matches.
780
+ */
781
+ declare function runVigorGuard(error: unknown, args: readonly unknown[], is: (error: unknown, codes: readonly unknown[]) => boolean): unknown;
772
782
 
773
783
  declare const VigorParseErrorMessageFuncs: {
774
784
  readonly VALUE_REQUIRED: ({ key }: {
@@ -851,23 +861,23 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
851
861
  * if (isVigorParseError(error, "PARSER_NOT_FOUND")) {
852
862
  * error.data // that code's payload
853
863
  * }
854
- */
855
- declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
856
- declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
857
- /**
858
- * Like `isVigorParseError(error, ...codes)`, but also looks inside the errors
859
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
860
- * then `cause` — and returns the first match, outermost first. Returns
861
- * `null` when there is none. `error` itself is left as it is.
862
864
  *
863
- * A guard can't do this: it narrows the value you pass, so a `true` for a
864
- * wrapped match would claim the wrapper has the inner error's `data`.
865
+ * Pass a `callback` as the third argument (with the code, or an array of
866
+ * codes, as the second) to also look inside the errors `error` wraps: the
867
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
868
+ * then `cause`. `callback` gets the first match, outermost first, typed for
869
+ * its code; the guard returns what `callback` returns, or `undefined` when
870
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
871
+ * which is still the wrapper.)
865
872
  *
866
873
  * @example
867
- * const notFound = findVigorParseError(error, "PARSER_NOT_FOUND")
868
- * if (notFound) notFound.data.expected
874
+ * isVigorParseError(error, "PARSER_NOT_FOUND", error => {
875
+ * error.data.expected // found even when wrapped in RETRY_EXHAUSTED
876
+ * })
869
877
  */
870
- declare function findVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorParseErrorsIn<E, C> | null;
878
+ declare function isVigorParseError<E, const C extends VigorParseErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorParseErrorsIn<E, C>) => R): R | undefined;
879
+ declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
880
+ declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
871
881
 
872
882
  type VigorParsePolicySchema<T extends VigorParseSchema<T>> = {
873
883
  __brand: VigorBrand<"Parse", "Policy<Schema">;
@@ -1736,23 +1746,23 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1736
1746
  * if (isVigorRetryError(error, "TIMED_OUT")) {
1737
1747
  * error.data // that code's payload
1738
1748
  * }
1739
- */
1740
- declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1741
- declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1742
- /**
1743
- * Like `isVigorRetryError(error, ...codes)`, but also looks inside the errors
1744
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
1745
- * then `cause` — and returns the first match, outermost first. Returns
1746
- * `null` when there is none. `error` itself is left as it is.
1747
1749
  *
1748
- * A guard can't do this: it narrows the value you pass, so a `true` for a
1749
- * wrapped match would claim the wrapper has the inner error's `data`.
1750
+ * Pass a `callback` as the third argument (with the code, or an array of
1751
+ * codes, as the second) to also look inside the errors `error` wraps: the
1752
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
1753
+ * then `cause`. `callback` gets the first match, outermost first, typed for
1754
+ * its code; the guard returns what `callback` returns, or `undefined` when
1755
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
1756
+ * which is still the wrapper.)
1750
1757
  *
1751
1758
  * @example
1752
- * const timedOut = findVigorRetryError(error, "TIMED_OUT")
1753
- * if (timedOut) timedOut.data.limit
1759
+ * isVigorRetryError(error, "TIMED_OUT", error => {
1760
+ * error.data.limit // found even when wrapped in RETRY_EXHAUSTED
1761
+ * })
1754
1762
  */
1755
- declare function findVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorRetryErrorsIn<E, C> | null;
1763
+ declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorRetryErrorsIn<E, C>) => R): R | undefined;
1764
+ declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1765
+ declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1756
1766
 
1757
1767
  type VigorRetryPolicySchema<T extends VigorRetrySchema<T>> = {
1758
1768
  __brand: VigorBrand<"Retry", "Policy<Schema">;
@@ -2520,23 +2530,23 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2520
2530
  * if (isVigorAllError(error, "TIMED_OUT")) {
2521
2531
  * error.data // that code's payload
2522
2532
  * }
2523
- */
2524
- declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2525
- declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2526
- /**
2527
- * Like `isVigorAllError(error, ...codes)`, but also looks inside the errors
2528
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
2529
- * then `cause` — and returns the first match, outermost first. Returns
2530
- * `null` when there is none. `error` itself is left as it is.
2531
2533
  *
2532
- * A guard can't do this: it narrows the value you pass, so a `true` for a
2533
- * wrapped match would claim the wrapper has the inner error's `data`.
2534
+ * Pass a `callback` as the third argument (with the code, or an array of
2535
+ * codes, as the second) to also look inside the errors `error` wraps: the
2536
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
2537
+ * then `cause`. `callback` gets the first match, outermost first, typed for
2538
+ * its code; the guard returns what `callback` returns, or `undefined` when
2539
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
2540
+ * which is still the wrapper.)
2534
2541
  *
2535
2542
  * @example
2536
- * const timedOut = findVigorAllError(error, "TIMED_OUT")
2537
- * if (timedOut) timedOut.data.index
2543
+ * isVigorAllError(error, "TIMED_OUT", error => {
2544
+ * error.data.index // found even when wrapped in RETRY_EXHAUSTED
2545
+ * })
2538
2546
  */
2539
- declare function findVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorAllErrorsIn<E, C> | null;
2547
+ declare function isVigorAllError<E, const C extends VigorAllErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorAllErrorsIn<E, C>) => R): R | undefined;
2548
+ declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2549
+ declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2540
2550
 
2541
2551
  /**
2542
2552
  * A single task. It receives an `AbortSignal` that fires when the task's
@@ -4064,23 +4074,23 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4064
4074
  * if (isVigorFetchError(error, "FETCH_FAILED")) {
4065
4075
  * error.data // that code's payload
4066
4076
  * }
4067
- */
4068
- declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4069
- declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4070
- /**
4071
- * Like `isVigorFetchError(error, ...codes)`, but also looks inside the errors
4072
- * `error` wraps — `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
4073
- * then `cause` — and returns the first match, outermost first. Returns
4074
- * `null` when there is none. `error` itself is left as it is.
4075
4077
  *
4076
- * A guard can't do this: it narrows the value you pass, so a `true` for a
4077
- * wrapped match would claim the wrapper has the inner error's `data`.
4078
+ * Pass a `callback` as the third argument (with the code, or an array of
4079
+ * codes, as the second) to also look inside the errors `error` wraps: the
4080
+ * error itself, then `data.error` of `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`,
4081
+ * then `cause`. `callback` gets the first match, outermost first, typed for
4082
+ * its code; the guard returns what `callback` returns, or `undefined` when
4083
+ * nothing matches. (A plain guard can't do this: it narrows `error` itself,
4084
+ * which is still the wrapper.)
4078
4085
  *
4079
4086
  * @example
4080
- * const failed = findVigorFetchError(error, "FETCH_FAILED")
4081
- * if (failed) failed.data.status
4087
+ * isVigorFetchError(error, "FETCH_FAILED", error => {
4088
+ * error.data.status // found even when wrapped in RETRY_EXHAUSTED
4089
+ * })
4082
4090
  */
4083
- declare function findVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorFetchErrorsIn<E, C> | null;
4091
+ declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes, R>(error: E, codes: C | readonly [C, ...C[]], callback: (error: VigorFetchErrorsIn<E, C>) => R): R | undefined;
4092
+ declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4093
+ declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4084
4094
  /**
4085
4095
  * Re-raises an error of the nested retry/parse engine as a `VigorFetchError`
4086
4096
  * with the same `code`, `data`, and `method`, keeping the original as
@@ -5481,18 +5491,10 @@ declare const vigorBase: {
5481
5491
  };
5482
5492
  };
5483
5493
  guards: {
5484
- retry: typeof isVigorRetryError & {
5485
- find: typeof findVigorRetryError;
5486
- };
5487
- parse: typeof isVigorParseError & {
5488
- find: typeof findVigorParseError;
5489
- };
5490
- fetch: typeof isVigorFetchError & {
5491
- find: typeof findVigorFetchError;
5492
- };
5493
- all: typeof isVigorAllError & {
5494
- find: typeof findVigorAllError;
5495
- };
5494
+ retry: typeof isVigorRetryError;
5495
+ parse: typeof isVigorParseError;
5496
+ fetch: typeof isVigorFetchError;
5497
+ all: typeof isVigorAllError;
5496
5498
  };
5497
5499
  };
5498
5500
  /** `A` with `B`'s properties replacing same-named ones, like `{ ...A, ...B }`. */
@@ -5522,4 +5524,4 @@ type VigorPlugin<O extends {
5522
5524
  };
5523
5525
  declare const vigor: VigorInstance;
5524
5526
 
5525
- export { VigorAll, type VigorAllAfterContextSchema, VigorAllBase, type VigorAllBeforeContextSchema, type VigorAllCastNaturalResult, VigorAllContextBase, type VigorAllContextSchema, VigorAllEachContextBase, type VigorAllEachContextSchema, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorCodesWithOptionalContext, type VigorAllErrorCodesWithoutContext, type VigorAllErrorContext, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllErrors, type VigorAllErrorsIn, type VigorAllNaturalResult, type VigorAllOnResultContextSchema, type VigorAllPipeResult, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllProcessHandler, type VigorAllRequestError, type VigorAllResult, type VigorAllResultContextSchema, type VigorAllSchema, type VigorAllSettled, type VigorAllTask, type VigorAllTaskError, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorAllTimeline, type VigorAllTimelineEvents, type VigorAllTimelineSnapshot, type VigorApiFailure, type VigorApiKeys, type VigorApiMap, type VigorApiMapSlot, type VigorApiMatch, type VigorApiMatched, type VigorApiMethod, type VigorApiNoMatchType, type VigorApiParamValue, type VigorApiRequestIssue, type VigorApiRequestIssues, type VigorApiResponse, type VigorApiRoute, type VigorApiRouteKey, type VigorApiRouteOf, type VigorApiStatusClass, type VigorApiSuccess, type VigorBrand, type VigorBuiltin, VigorCastPlaceholder, type VigorCastPlaceholderType, type VigorCastResult, type VigorConcat, type VigorContextApply, type VigorContextChanges, type VigorContextReset, type VigorContextStage, type VigorDeepMerge, type VigorDeepPartial, VigorDefault, type VigorDefaultType, VigorEmpty, type VigorEmptyType, VigorError, type VigorErrorContext, type VigorErrorOptions, type VigorExcludeDefault, type VigorExcludeEmpty, VigorFetch, type VigorFetchAfterContextSchema, VigorFetchBase, type VigorFetchBeforeContextSchema, type VigorFetchBodyFor, VigorFetchContextBase, type VigorFetchContextSchema, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorCodesWithOptionalContext, type VigorFetchErrorCodesWithoutContext, type VigorFetchErrorContext, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchErrorPipeResult, type VigorFetchErrors, type VigorFetchErrorsIn, type VigorFetchExtraOptions, type VigorFetchFailedData, type VigorFetchInferResult, type VigorFetchMethodFor, type VigorFetchNaturalFor, type VigorFetchNaturalResult, type VigorFetchOnErrorContextSchema, type VigorFetchOnResultContextSchema, type VigorFetchOptions, type VigorFetchParseSource, type VigorFetchParsedResult, type VigorFetchPipeResult, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchProcessHandler, type VigorFetchRequestError, type VigorFetchRequestThis, type VigorFetchResult, type VigorFetchResultContextSchema, type VigorFetchRouteKeys, type VigorFetchSchema, type VigorFetchTimeline, type VigorFetchTimelineEvents, type VigorFetchTimelineSnapshot, type VigorFetchVerboseResult, type VigorHttpFailureStatus, type VigorHttpStatusOf, type VigorHttpSuccessStatus, type VigorInstance, type VigorIsSame, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, type VigorNoExtraKeys, VigorParse, type VigorParseAfterContextSchema, VigorParseBase, type VigorParseBeforeContextSchema, type VigorParseBody, VigorParseContentTypeStrategy, VigorParseContextBase, type VigorParseContextSchema, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorCodesWithOptionalContext, type VigorParseErrorCodesWithoutContext, type VigorParseErrorContext, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParseErrorPipeResult, type VigorParseErrors, type VigorParseErrorsIn, type VigorParseNaturalResult, type VigorParseOnErrorContextSchema, type VigorParseOnResultContextSchema, type VigorParsePipeResult, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseProcessHandler, type VigorParseRequestError, type VigorParseResult, type VigorParseResultContextSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorParseTimeline, type VigorParseTimelineEvents, type VigorParseTimelineSnapshot, type VigorPathList, type VigorPathSegments, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, type VigorResolvedMethod, type VigorResultError, type VigorResultOf, VigorRetry, type VigorRetryAfterContextSchema, VigorRetryBase, type VigorRetryBeforeContextSchema, VigorRetryContextBase, type VigorRetryContextSchema, type VigorRetryDecisionReason, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorCodesWithOptionalContext, type VigorRetryErrorCodesWithoutContext, type VigorRetryErrorContext, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryErrorPipeResult, type VigorRetryErrors, type VigorRetryErrorsIn, type VigorRetryNaturalResult, type VigorRetryOnErrorContextSchema, type VigorRetryOnResultContextSchema, type VigorRetryOnRetryContextSchema, type VigorRetryPipeResult, 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 VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetryProcessHandler, type VigorRetryRequestError, type VigorRetryResult, type VigorRetryResultContextSchema, type VigorRetryRetryIfContextSchema, type VigorRetrySchema, type VigorRetryTimeline, type VigorRetryTimelineEvents, type VigorRetryTimelineSnapshot, type VigorReturnType, type VigorRouteMethod, type VigorRouteParams, type VigorRoutePath, type VigorRoutePathList, type VigorRouteWithParams, type VigorRouteWithoutParams, type VigorSimplify, VigorStatus, type VigorStringable, type VigorTimeline, type VigorTimelineEndEvents, type VigorTimelineItem, type VigorTimelineMiddlewareEvents, type VigorTimelineOutcome, type VigorTimelineProcessEvents, type VigorTimelineSnapshot, adoptVigorFetchError, createBrand, createVigorTimelineRecorder, vigor as default, findInVigorErrorChain, findVigorAllError, findVigorFetchError, findVigorParseError, findVigorRetryError, isVigorAllError, isVigorDefault, isVigorEmpty, isVigorFetchError, isVigorInternalMiddleware, isVigorParseError, isVigorRetryError, markVigorInternal, readVigorParseBody, vigor };
5527
+ export { VigorAll, type VigorAllAfterContextSchema, VigorAllBase, type VigorAllBeforeContextSchema, type VigorAllCastNaturalResult, VigorAllContextBase, type VigorAllContextSchema, VigorAllEachContextBase, type VigorAllEachContextSchema, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorCodesWithOptionalContext, type VigorAllErrorCodesWithoutContext, type VigorAllErrorContext, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllErrors, type VigorAllErrorsIn, type VigorAllNaturalResult, type VigorAllOnResultContextSchema, type VigorAllPipeResult, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllProcessHandler, type VigorAllRequestError, type VigorAllResult, type VigorAllResultContextSchema, type VigorAllSchema, type VigorAllSettled, type VigorAllTask, type VigorAllTaskError, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorAllTimeline, type VigorAllTimelineEvents, type VigorAllTimelineSnapshot, type VigorApiFailure, type VigorApiKeys, type VigorApiMap, type VigorApiMapSlot, type VigorApiMatch, type VigorApiMatched, type VigorApiMethod, type VigorApiNoMatchType, type VigorApiParamValue, type VigorApiRequestIssue, type VigorApiRequestIssues, type VigorApiResponse, type VigorApiRoute, type VigorApiRouteKey, type VigorApiRouteOf, type VigorApiStatusClass, type VigorApiSuccess, type VigorBrand, type VigorBuiltin, VigorCastPlaceholder, type VigorCastPlaceholderType, type VigorCastResult, type VigorConcat, type VigorContextApply, type VigorContextChanges, type VigorContextReset, type VigorContextStage, type VigorDeepMerge, type VigorDeepPartial, VigorDefault, type VigorDefaultType, VigorEmpty, type VigorEmptyType, VigorError, type VigorErrorContext, type VigorErrorOptions, type VigorExcludeDefault, type VigorExcludeEmpty, VigorFetch, type VigorFetchAfterContextSchema, VigorFetchBase, type VigorFetchBeforeContextSchema, type VigorFetchBodyFor, VigorFetchContextBase, type VigorFetchContextSchema, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorCodesWithOptionalContext, type VigorFetchErrorCodesWithoutContext, type VigorFetchErrorContext, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchErrorPipeResult, type VigorFetchErrors, type VigorFetchErrorsIn, type VigorFetchExtraOptions, type VigorFetchFailedData, type VigorFetchInferResult, type VigorFetchMethodFor, type VigorFetchNaturalFor, type VigorFetchNaturalResult, type VigorFetchOnErrorContextSchema, type VigorFetchOnResultContextSchema, type VigorFetchOptions, type VigorFetchParseSource, type VigorFetchParsedResult, type VigorFetchPipeResult, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchProcessHandler, type VigorFetchRequestError, type VigorFetchRequestThis, type VigorFetchResult, type VigorFetchResultContextSchema, type VigorFetchRouteKeys, type VigorFetchSchema, type VigorFetchTimeline, type VigorFetchTimelineEvents, type VigorFetchTimelineSnapshot, type VigorFetchVerboseResult, type VigorHttpFailureStatus, type VigorHttpStatusOf, type VigorHttpSuccessStatus, type VigorInstance, type VigorIsSame, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, type VigorNoExtraKeys, VigorParse, type VigorParseAfterContextSchema, VigorParseBase, type VigorParseBeforeContextSchema, type VigorParseBody, VigorParseContentTypeStrategy, VigorParseContextBase, type VigorParseContextSchema, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorCodesWithOptionalContext, type VigorParseErrorCodesWithoutContext, type VigorParseErrorContext, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParseErrorPipeResult, type VigorParseErrors, type VigorParseErrorsIn, type VigorParseNaturalResult, type VigorParseOnErrorContextSchema, type VigorParseOnResultContextSchema, type VigorParsePipeResult, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseProcessHandler, type VigorParseRequestError, type VigorParseResult, type VigorParseResultContextSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorParseTimeline, type VigorParseTimelineEvents, type VigorParseTimelineSnapshot, type VigorPathList, type VigorPathSegments, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, type VigorResolvedMethod, type VigorResultError, type VigorResultOf, VigorRetry, type VigorRetryAfterContextSchema, VigorRetryBase, type VigorRetryBeforeContextSchema, VigorRetryContextBase, type VigorRetryContextSchema, type VigorRetryDecisionReason, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorCodesWithOptionalContext, type VigorRetryErrorCodesWithoutContext, type VigorRetryErrorContext, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryErrorPipeResult, type VigorRetryErrors, type VigorRetryErrorsIn, type VigorRetryNaturalResult, type VigorRetryOnErrorContextSchema, type VigorRetryOnResultContextSchema, type VigorRetryOnRetryContextSchema, type VigorRetryPipeResult, 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 VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetryProcessHandler, type VigorRetryRequestError, type VigorRetryResult, type VigorRetryResultContextSchema, type VigorRetryRetryIfContextSchema, type VigorRetrySchema, type VigorRetryTimeline, type VigorRetryTimelineEvents, type VigorRetryTimelineSnapshot, type VigorReturnType, type VigorRouteMethod, type VigorRouteParams, type VigorRoutePath, type VigorRoutePathList, type VigorRouteWithParams, type VigorRouteWithoutParams, type VigorSimplify, VigorStatus, type VigorStringable, type VigorTimeline, type VigorTimelineEndEvents, type VigorTimelineItem, type VigorTimelineMiddlewareEvents, type VigorTimelineOutcome, type VigorTimelineProcessEvents, type VigorTimelineSnapshot, adoptVigorFetchError, createBrand, createVigorTimelineRecorder, vigor as default, findInVigorErrorChain, isVigorAllError, isVigorDefault, isVigorEmpty, isVigorFetchError, isVigorInternalMiddleware, isVigorParseError, isVigorRetryError, markVigorInternal, readVigorParseBody, runVigorGuard, vigor };
package/dist/index.js CHANGED
@@ -238,6 +238,13 @@ function findInVigorErrorChain(error, match) {
238
238
  };
239
239
  return visit(error);
240
240
  }
241
+ function runVigorGuard(error, args, is) {
242
+ const callback = args[args.length - 1];
243
+ if (typeof callback !== "function") return is(error, args);
244
+ const codes = Array.isArray(args[0]) ? args[0] : [args[0]];
245
+ const found = findInVigorErrorChain(error, (e) => is(e, codes));
246
+ return found === void 0 ? void 0 : callback(found);
247
+ }
241
248
 
242
249
  // src/all/error.ts
243
250
  var VigorAllErrorMessageFuncs = {
@@ -254,12 +261,8 @@ var VigorAllError = class extends VigorError {
254
261
  super(code, messageFn(options.data), options);
255
262
  }
256
263
  };
257
- function isVigorAllError(error, ...codes) {
258
- return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
259
- }
260
- function findVigorAllError(error, ...codes) {
261
- const found = findInVigorErrorChain(error, (e) => isVigorAllError(e, ...codes));
262
- return found === void 0 ? null : found;
264
+ function isVigorAllError(error, ...args) {
265
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorAllError && (codes.length === 0 || codes.includes(e.code)));
263
266
  }
264
267
 
265
268
  // src/core/timeline.ts
@@ -775,12 +778,8 @@ var VigorRetryError = class extends VigorError {
775
778
  super(code, messageFn(options.data), options);
776
779
  }
777
780
  };
778
- function isVigorRetryError(error, ...codes) {
779
- return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
780
- }
781
- function findVigorRetryError(error, ...codes) {
782
- const found = findInVigorErrorChain(error, (e) => isVigorRetryError(e, ...codes));
783
- return found === void 0 ? null : found;
781
+ function isVigorRetryError(error, ...args) {
782
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorRetryError && (codes.length === 0 || codes.includes(e.code)));
784
783
  }
785
784
 
786
785
  // src/retry/algorithms.ts
@@ -1483,12 +1482,8 @@ var VigorParseError = class extends VigorError {
1483
1482
  super(code, messageFn(options.data), options);
1484
1483
  }
1485
1484
  };
1486
- function isVigorParseError(error, ...codes) {
1487
- return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1488
- }
1489
- function findVigorParseError(error, ...codes) {
1490
- const found = findInVigorErrorChain(error, (e) => isVigorParseError(e, ...codes));
1491
- return found === void 0 ? null : found;
1485
+ function isVigorParseError(error, ...args) {
1486
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorParseError && (codes.length === 0 || codes.includes(e.code)));
1492
1487
  }
1493
1488
 
1494
1489
  // src/parse/strategies.ts
@@ -1979,12 +1974,8 @@ var VigorFetchError = class extends VigorError {
1979
1974
  super(code, messageFn(options.data), options);
1980
1975
  }
1981
1976
  };
1982
- function isVigorFetchError(error, ...codes) {
1983
- return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
1984
- }
1985
- function findVigorFetchError(error, ...codes) {
1986
- const found = findInVigorErrorChain(error, (e) => isVigorFetchError(e, ...codes));
1987
- return found === void 0 ? null : found;
1977
+ function isVigorFetchError(error, ...args) {
1978
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorFetchError && (codes.length === 0 || codes.includes(e.code)));
1988
1979
  }
1989
1980
  function adoptVigorFetchError(error, context) {
1990
1981
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
@@ -2557,7 +2548,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
2557
2548
  };
2558
2549
 
2559
2550
  // src/entry/main.ts
2560
- var guardWithFind = (guard, find) => Object.assign(((...args) => guard(...args)), { find });
2561
2551
  function retryWithTarget(task) {
2562
2552
  return new VigorRetry().target(task);
2563
2553
  }
@@ -2602,10 +2592,10 @@ var vigorBase = {
2602
2592
  }
2603
2593
  },
2604
2594
  guards: {
2605
- retry: guardWithFind(isVigorRetryError, findVigorRetryError),
2606
- parse: guardWithFind(isVigorParseError, findVigorParseError),
2607
- fetch: guardWithFind(isVigorFetchError, findVigorFetchError),
2608
- all: guardWithFind(isVigorAllError, findVigorAllError)
2595
+ retry: isVigorRetryError,
2596
+ parse: isVigorParseError,
2597
+ fetch: isVigorFetchError,
2598
+ all: isVigorAllError
2609
2599
  }
2610
2600
  };
2611
2601
  var cloneVigor = (v) => ({
@@ -2700,10 +2690,6 @@ export {
2700
2690
  createVigorTimelineRecorder,
2701
2691
  index_default as default,
2702
2692
  findInVigorErrorChain,
2703
- findVigorAllError,
2704
- findVigorFetchError,
2705
- findVigorParseError,
2706
- findVigorRetryError,
2707
2693
  isVigorAllError,
2708
2694
  isVigorDefault,
2709
2695
  isVigorEmpty,
@@ -2713,5 +2699,6 @@ export {
2713
2699
  isVigorRetryError,
2714
2700
  markVigorInternal,
2715
2701
  readVigorParseBody,
2702
+ runVigorGuard,
2716
2703
  vigor
2717
2704
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vigor-fetch",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "description": "Smart, zero-dependency HTTP client with self-healing retries for rate-limited servers.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",