vigor-fetch 5.1.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,6 +145,17 @@ vigor.guards.fetch(err) // isVigorFetchError
145
145
  vigor.guards.all(err) // isVigorAllError
146
146
  ```
147
147
 
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
+
150
+ ```ts
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
155
+ ```
156
+
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?".
158
+
148
159
  ---
149
160
 
150
161
  ## `vigor.fetch`
@@ -820,7 +831,7 @@ try {
820
831
 
821
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.
822
833
 
823
- Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`):
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)):
824
835
 
825
836
  ```ts
826
837
  const res = await vigor.retry(task).requestVerbose();
@@ -905,10 +916,11 @@ With an [API map](#route-descriptions) route that declares failure `responses`,
905
916
  ```ts
906
917
  const res = await api.route("POST /users").body("overwrite", { name: "a" }).requestVerbose()
907
918
  if (!res.success) {
908
- const err = isVigorFetchError(res.error, "RETRY_EXHAUSTED") ? res.error.data.error : res.error
909
- if (isVigorFetchError(err, "FETCH_FAILED") && err.data.status === 422) {
910
- err.data.parsed // { fields: Record<string, string> } | undefined
911
- }
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
+ })
912
924
  }
913
925
  ```
914
926
 
package/dist/index.cjs CHANGED
@@ -85,6 +85,7 @@ __export(index_exports, {
85
85
  createBrand: () => createBrand,
86
86
  createVigorTimelineRecorder: () => createVigorTimelineRecorder,
87
87
  default: () => index_default,
88
+ findInVigorErrorChain: () => findInVigorErrorChain,
88
89
  isVigorAllError: () => isVigorAllError,
89
90
  isVigorDefault: () => isVigorDefault,
90
91
  isVigorEmpty: () => isVigorEmpty,
@@ -94,6 +95,7 @@ __export(index_exports, {
94
95
  isVigorRetryError: () => isVigorRetryError,
95
96
  markVigorInternal: () => markVigorInternal,
96
97
  readVigorParseBody: () => readVigorParseBody,
98
+ runVigorGuard: () => runVigorGuard,
97
99
  vigor: () => vigor
98
100
  });
99
101
  module.exports = __toCommonJS(index_exports);
@@ -322,6 +324,29 @@ var VigorError = class extends Error {
322
324
  Error.captureStackTrace?.(this, new.target);
323
325
  }
324
326
  };
327
+ function findInVigorErrorChain(error, match) {
328
+ const seen = /* @__PURE__ */ new Set();
329
+ const visit = (current) => {
330
+ if (current === null || current === void 0 || seen.has(current)) return void 0;
331
+ seen.add(current);
332
+ if (match(current)) return current;
333
+ if (typeof current !== "object") return void 0;
334
+ const data = current.data;
335
+ if (current instanceof VigorError && data !== null && typeof data === "object" && "error" in data) {
336
+ const found = visit(data.error);
337
+ if (found !== void 0) return found;
338
+ }
339
+ return visit(current.cause);
340
+ };
341
+ return visit(error);
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
+ }
325
350
 
326
351
  // src/all/error.ts
327
352
  var VigorAllErrorMessageFuncs = {
@@ -338,8 +363,8 @@ var VigorAllError = class extends VigorError {
338
363
  super(code, messageFn(options.data), options);
339
364
  }
340
365
  };
341
- function isVigorAllError(error, ...codes) {
342
- return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
366
+ function isVigorAllError(error, ...args) {
367
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorAllError && (codes.length === 0 || codes.includes(e.code)));
343
368
  }
344
369
 
345
370
  // src/core/timeline.ts
@@ -855,8 +880,8 @@ var VigorRetryError = class extends VigorError {
855
880
  super(code, messageFn(options.data), options);
856
881
  }
857
882
  };
858
- function isVigorRetryError(error, ...codes) {
859
- return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
883
+ function isVigorRetryError(error, ...args) {
884
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorRetryError && (codes.length === 0 || codes.includes(e.code)));
860
885
  }
861
886
 
862
887
  // src/retry/algorithms.ts
@@ -1559,8 +1584,8 @@ var VigorParseError = class extends VigorError {
1559
1584
  super(code, messageFn(options.data), options);
1560
1585
  }
1561
1586
  };
1562
- function isVigorParseError(error, ...codes) {
1563
- return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1587
+ function isVigorParseError(error, ...args) {
1588
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorParseError && (codes.length === 0 || codes.includes(e.code)));
1564
1589
  }
1565
1590
 
1566
1591
  // src/parse/strategies.ts
@@ -2051,8 +2076,8 @@ var VigorFetchError = class extends VigorError {
2051
2076
  super(code, messageFn(options.data), options);
2052
2077
  }
2053
2078
  };
2054
- function isVigorFetchError(error, ...codes) {
2055
- return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
2079
+ function isVigorFetchError(error, ...args) {
2080
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorFetchError && (codes.length === 0 || codes.includes(e.code)));
2056
2081
  }
2057
2082
  function adoptVigorFetchError(error, context) {
2058
2083
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
@@ -2766,6 +2791,7 @@ var index_default = vigor;
2766
2791
  adoptVigorFetchError,
2767
2792
  createBrand,
2768
2793
  createVigorTimelineRecorder,
2794
+ findInVigorErrorChain,
2769
2795
  isVigorAllError,
2770
2796
  isVigorDefault,
2771
2797
  isVigorEmpty,
@@ -2775,5 +2801,6 @@ var index_default = vigor;
2775
2801
  isVigorRetryError,
2776
2802
  markVigorInternal,
2777
2803
  readVigorParseBody,
2804
+ runVigorGuard,
2778
2805
  vigor
2779
2806
  });
package/dist/index.d.cts CHANGED
@@ -758,6 +758,27 @@ declare abstract class VigorError<C extends string, D, T = unknown> extends Erro
758
758
  */
759
759
  constructor(code: C, message: string, options: VigorErrorOptions<D, T>);
760
760
  }
761
+ /**
762
+ * Finds the first error in `error`'s chain that `match` accepts, from the
763
+ * outside in: the error itself, then the error it wraps (`data.error` of
764
+ * `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`), then its `cause`. Each wrapped
765
+ * error is searched fully before moving on. Cycles are skipped.
766
+ *
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
+ */
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;
761
782
 
762
783
  declare const VigorParseErrorMessageFuncs: {
763
784
  readonly VALUE_REQUIRED: ({ key }: {
@@ -840,7 +861,21 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
840
861
  * if (isVigorParseError(error, "PARSER_NOT_FOUND")) {
841
862
  * error.data // that code's payload
842
863
  * }
864
+ *
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.)
872
+ *
873
+ * @example
874
+ * isVigorParseError(error, "PARSER_NOT_FOUND", error => {
875
+ * error.data.expected // found even when wrapped in RETRY_EXHAUSTED
876
+ * })
843
877
  */
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;
844
879
  declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
845
880
  declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
846
881
 
@@ -1711,7 +1746,21 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1711
1746
  * if (isVigorRetryError(error, "TIMED_OUT")) {
1712
1747
  * error.data // that code's payload
1713
1748
  * }
1749
+ *
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.)
1757
+ *
1758
+ * @example
1759
+ * isVigorRetryError(error, "TIMED_OUT", error => {
1760
+ * error.data.limit // found even when wrapped in RETRY_EXHAUSTED
1761
+ * })
1714
1762
  */
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;
1715
1764
  declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1716
1765
  declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1717
1766
 
@@ -2481,7 +2530,21 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2481
2530
  * if (isVigorAllError(error, "TIMED_OUT")) {
2482
2531
  * error.data // that code's payload
2483
2532
  * }
2533
+ *
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.)
2541
+ *
2542
+ * @example
2543
+ * isVigorAllError(error, "TIMED_OUT", error => {
2544
+ * error.data.index // found even when wrapped in RETRY_EXHAUSTED
2545
+ * })
2484
2546
  */
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;
2485
2548
  declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2486
2549
  declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2487
2550
 
@@ -4011,7 +4074,21 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4011
4074
  * if (isVigorFetchError(error, "FETCH_FAILED")) {
4012
4075
  * error.data // that code's payload
4013
4076
  * }
4077
+ *
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.)
4085
+ *
4086
+ * @example
4087
+ * isVigorFetchError(error, "FETCH_FAILED", error => {
4088
+ * error.data.status // found even when wrapped in RETRY_EXHAUSTED
4089
+ * })
4014
4090
  */
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;
4015
4092
  declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4016
4093
  declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4017
4094
  /**
@@ -5447,4 +5524,4 @@ type VigorPlugin<O extends {
5447
5524
  };
5448
5525
  declare const vigor: VigorInstance;
5449
5526
 
5450
- 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, 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
@@ -758,6 +758,27 @@ declare abstract class VigorError<C extends string, D, T = unknown> extends Erro
758
758
  */
759
759
  constructor(code: C, message: string, options: VigorErrorOptions<D, T>);
760
760
  }
761
+ /**
762
+ * Finds the first error in `error`'s chain that `match` accepts, from the
763
+ * outside in: the error itself, then the error it wraps (`data.error` of
764
+ * `RETRY_EXHAUSTED` / `RESTART_EXHAUSTED`), then its `cause`. Each wrapped
765
+ * error is searched fully before moving on. Cycles are skipped.
766
+ *
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
+ */
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;
761
782
 
762
783
  declare const VigorParseErrorMessageFuncs: {
763
784
  readonly VALUE_REQUIRED: ({ key }: {
@@ -840,7 +861,21 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
840
861
  * if (isVigorParseError(error, "PARSER_NOT_FOUND")) {
841
862
  * error.data // that code's payload
842
863
  * }
864
+ *
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.)
872
+ *
873
+ * @example
874
+ * isVigorParseError(error, "PARSER_NOT_FOUND", error => {
875
+ * error.data.expected // found even when wrapped in RETRY_EXHAUSTED
876
+ * })
843
877
  */
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;
844
879
  declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
845
880
  declare function isVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorParseErrorsIn<E, C>;
846
881
 
@@ -1711,7 +1746,21 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1711
1746
  * if (isVigorRetryError(error, "TIMED_OUT")) {
1712
1747
  * error.data // that code's payload
1713
1748
  * }
1749
+ *
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.)
1757
+ *
1758
+ * @example
1759
+ * isVigorRetryError(error, "TIMED_OUT", error => {
1760
+ * error.data.limit // found even when wrapped in RETRY_EXHAUSTED
1761
+ * })
1714
1762
  */
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;
1715
1764
  declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1716
1765
  declare function isVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorRetryErrorsIn<E, C>;
1717
1766
 
@@ -2481,7 +2530,21 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2481
2530
  * if (isVigorAllError(error, "TIMED_OUT")) {
2482
2531
  * error.data // that code's payload
2483
2532
  * }
2533
+ *
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.)
2541
+ *
2542
+ * @example
2543
+ * isVigorAllError(error, "TIMED_OUT", error => {
2544
+ * error.data.index // found even when wrapped in RETRY_EXHAUSTED
2545
+ * })
2484
2546
  */
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;
2485
2548
  declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2486
2549
  declare function isVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorAllErrorsIn<E, C>;
2487
2550
 
@@ -4011,7 +4074,21 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4011
4074
  * if (isVigorFetchError(error, "FETCH_FAILED")) {
4012
4075
  * error.data // that code's payload
4013
4076
  * }
4077
+ *
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.)
4085
+ *
4086
+ * @example
4087
+ * isVigorFetchError(error, "FETCH_FAILED", error => {
4088
+ * error.data.status // found even when wrapped in RETRY_EXHAUSTED
4089
+ * })
4014
4090
  */
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;
4015
4092
  declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4016
4093
  declare function isVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): error is E & VigorFetchErrorsIn<E, C>;
4017
4094
  /**
@@ -5447,4 +5524,4 @@ type VigorPlugin<O extends {
5447
5524
  };
5448
5525
  declare const vigor: VigorInstance;
5449
5526
 
5450
- 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, 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
@@ -222,6 +222,29 @@ var VigorError = class extends Error {
222
222
  Error.captureStackTrace?.(this, new.target);
223
223
  }
224
224
  };
225
+ function findInVigorErrorChain(error, match) {
226
+ const seen = /* @__PURE__ */ new Set();
227
+ const visit = (current) => {
228
+ if (current === null || current === void 0 || seen.has(current)) return void 0;
229
+ seen.add(current);
230
+ if (match(current)) return current;
231
+ if (typeof current !== "object") return void 0;
232
+ const data = current.data;
233
+ if (current instanceof VigorError && data !== null && typeof data === "object" && "error" in data) {
234
+ const found = visit(data.error);
235
+ if (found !== void 0) return found;
236
+ }
237
+ return visit(current.cause);
238
+ };
239
+ return visit(error);
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
+ }
225
248
 
226
249
  // src/all/error.ts
227
250
  var VigorAllErrorMessageFuncs = {
@@ -238,8 +261,8 @@ var VigorAllError = class extends VigorError {
238
261
  super(code, messageFn(options.data), options);
239
262
  }
240
263
  };
241
- function isVigorAllError(error, ...codes) {
242
- return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
264
+ function isVigorAllError(error, ...args) {
265
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorAllError && (codes.length === 0 || codes.includes(e.code)));
243
266
  }
244
267
 
245
268
  // src/core/timeline.ts
@@ -755,8 +778,8 @@ var VigorRetryError = class extends VigorError {
755
778
  super(code, messageFn(options.data), options);
756
779
  }
757
780
  };
758
- function isVigorRetryError(error, ...codes) {
759
- return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
781
+ function isVigorRetryError(error, ...args) {
782
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorRetryError && (codes.length === 0 || codes.includes(e.code)));
760
783
  }
761
784
 
762
785
  // src/retry/algorithms.ts
@@ -1459,8 +1482,8 @@ var VigorParseError = class extends VigorError {
1459
1482
  super(code, messageFn(options.data), options);
1460
1483
  }
1461
1484
  };
1462
- function isVigorParseError(error, ...codes) {
1463
- return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1485
+ function isVigorParseError(error, ...args) {
1486
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorParseError && (codes.length === 0 || codes.includes(e.code)));
1464
1487
  }
1465
1488
 
1466
1489
  // src/parse/strategies.ts
@@ -1951,8 +1974,8 @@ var VigorFetchError = class extends VigorError {
1951
1974
  super(code, messageFn(options.data), options);
1952
1975
  }
1953
1976
  };
1954
- function isVigorFetchError(error, ...codes) {
1955
- return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
1977
+ function isVigorFetchError(error, ...args) {
1978
+ return runVigorGuard(error, args, (e, codes) => e instanceof VigorFetchError && (codes.length === 0 || codes.includes(e.code)));
1956
1979
  }
1957
1980
  function adoptVigorFetchError(error, context) {
1958
1981
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
@@ -2666,6 +2689,7 @@ export {
2666
2689
  createBrand,
2667
2690
  createVigorTimelineRecorder,
2668
2691
  index_default as default,
2692
+ findInVigorErrorChain,
2669
2693
  isVigorAllError,
2670
2694
  isVigorDefault,
2671
2695
  isVigorEmpty,
@@ -2675,5 +2699,6 @@ export {
2675
2699
  isVigorRetryError,
2676
2700
  markVigorInternal,
2677
2701
  readVigorParseBody,
2702
+ runVigorGuard,
2678
2703
  vigor
2679
2704
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vigor-fetch",
3
- "version": "5.1.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",