vigor-fetch 5.1.0 → 5.2.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,15 @@ 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`:
149
+
150
+ ```ts
151
+ const failed = vigor.guards.fetch.find(err, "FETCH_FAILED") // same as findVigorFetchError(err, "FETCH_FAILED")
152
+ if (failed) failed.data.status
153
+ ```
154
+
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?").
156
+
148
157
  ---
149
158
 
150
159
  ## `vigor.fetch`
@@ -820,7 +829,7 @@ try {
820
829
 
821
830
  `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
831
 
823
- Narrow with the exported guards — `isVigorRetryError`, `isVigorParseError`, `isVigorFetchError`, `isVigorAllError` (or `vigor.guards.*`):
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)):
824
833
 
825
834
  ```ts
826
835
  const res = await vigor.retry(task).requestVerbose();
@@ -905,8 +914,8 @@ With an [API map](#route-descriptions) route that declares failure `responses`,
905
914
  ```ts
906
915
  const res = await api.route("POST /users").body("overwrite", { name: "a" }).requestVerbose()
907
916
  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) {
917
+ const err = findVigorFetchError(res.error, "FETCH_FAILED") // unwraps RETRY_EXHAUSTED if needed
918
+ if (err && err.data.status === 422) {
910
919
  err.data.parsed // { fields: Record<string, string> } | undefined
911
920
  }
912
921
  }
package/dist/index.cjs CHANGED
@@ -85,6 +85,11 @@ __export(index_exports, {
85
85
  createBrand: () => createBrand,
86
86
  createVigorTimelineRecorder: () => createVigorTimelineRecorder,
87
87
  default: () => index_default,
88
+ findInVigorErrorChain: () => findInVigorErrorChain,
89
+ findVigorAllError: () => findVigorAllError,
90
+ findVigorFetchError: () => findVigorFetchError,
91
+ findVigorParseError: () => findVigorParseError,
92
+ findVigorRetryError: () => findVigorRetryError,
88
93
  isVigorAllError: () => isVigorAllError,
89
94
  isVigorDefault: () => isVigorDefault,
90
95
  isVigorEmpty: () => isVigorEmpty,
@@ -322,6 +327,22 @@ var VigorError = class extends Error {
322
327
  Error.captureStackTrace?.(this, new.target);
323
328
  }
324
329
  };
330
+ function findInVigorErrorChain(error, match) {
331
+ const seen = /* @__PURE__ */ new Set();
332
+ const visit = (current) => {
333
+ if (current === null || current === void 0 || seen.has(current)) return void 0;
334
+ seen.add(current);
335
+ if (match(current)) return current;
336
+ if (typeof current !== "object") return void 0;
337
+ const data = current.data;
338
+ if (current instanceof VigorError && data !== null && typeof data === "object" && "error" in data) {
339
+ const found = visit(data.error);
340
+ if (found !== void 0) return found;
341
+ }
342
+ return visit(current.cause);
343
+ };
344
+ return visit(error);
345
+ }
325
346
 
326
347
  // src/all/error.ts
327
348
  var VigorAllErrorMessageFuncs = {
@@ -341,6 +362,10 @@ var VigorAllError = class extends VigorError {
341
362
  function isVigorAllError(error, ...codes) {
342
363
  return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
343
364
  }
365
+ function findVigorAllError(error, ...codes) {
366
+ const found = findInVigorErrorChain(error, (e) => isVigorAllError(e, ...codes));
367
+ return found === void 0 ? null : found;
368
+ }
344
369
 
345
370
  // src/core/timeline.ts
346
371
  var internalMiddlewares = /* @__PURE__ */ new WeakSet();
@@ -858,6 +883,10 @@ var VigorRetryError = class extends VigorError {
858
883
  function isVigorRetryError(error, ...codes) {
859
884
  return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
860
885
  }
886
+ function findVigorRetryError(error, ...codes) {
887
+ const found = findInVigorErrorChain(error, (e) => isVigorRetryError(e, ...codes));
888
+ return found === void 0 ? null : found;
889
+ }
861
890
 
862
891
  // src/retry/algorithms.ts
863
892
  function VigorJitter(jitter) {
@@ -1562,6 +1591,10 @@ var VigorParseError = class extends VigorError {
1562
1591
  function isVigorParseError(error, ...codes) {
1563
1592
  return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1564
1593
  }
1594
+ function findVigorParseError(error, ...codes) {
1595
+ const found = findInVigorErrorChain(error, (e) => isVigorParseError(e, ...codes));
1596
+ return found === void 0 ? null : found;
1597
+ }
1565
1598
 
1566
1599
  // src/parse/strategies.ts
1567
1600
  var VigorParsePolicyStrategiesBase = {
@@ -2054,6 +2087,10 @@ var VigorFetchError = class extends VigorError {
2054
2087
  function isVigorFetchError(error, ...codes) {
2055
2088
  return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
2056
2089
  }
2090
+ function findVigorFetchError(error, ...codes) {
2091
+ const found = findInVigorErrorChain(error, (e) => isVigorFetchError(e, ...codes));
2092
+ return found === void 0 ? null : found;
2093
+ }
2057
2094
  function adoptVigorFetchError(error, context) {
2058
2095
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
2059
2096
  const data = error.data;
@@ -2625,6 +2662,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
2625
2662
  };
2626
2663
 
2627
2664
  // src/entry/main.ts
2665
+ var guardWithFind = (guard, find) => Object.assign(((...args) => guard(...args)), { find });
2628
2666
  function retryWithTarget(task) {
2629
2667
  return new VigorRetry().target(task);
2630
2668
  }
@@ -2669,10 +2707,10 @@ var vigorBase = {
2669
2707
  }
2670
2708
  },
2671
2709
  guards: {
2672
- retry: isVigorRetryError,
2673
- parse: isVigorParseError,
2674
- fetch: isVigorFetchError,
2675
- all: isVigorAllError
2710
+ retry: guardWithFind(isVigorRetryError, findVigorRetryError),
2711
+ parse: guardWithFind(isVigorParseError, findVigorParseError),
2712
+ fetch: guardWithFind(isVigorFetchError, findVigorFetchError),
2713
+ all: guardWithFind(isVigorAllError, findVigorAllError)
2676
2714
  }
2677
2715
  };
2678
2716
  var cloneVigor = (v) => ({
@@ -2766,6 +2804,11 @@ var index_default = vigor;
2766
2804
  adoptVigorFetchError,
2767
2805
  createBrand,
2768
2806
  createVigorTimelineRecorder,
2807
+ findInVigorErrorChain,
2808
+ findVigorAllError,
2809
+ findVigorFetchError,
2810
+ findVigorParseError,
2811
+ findVigorRetryError,
2769
2812
  isVigorAllError,
2770
2813
  isVigorDefault,
2771
2814
  isVigorEmpty,
package/dist/index.d.cts CHANGED
@@ -758,6 +758,17 @@ 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 `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.
770
+ */
771
+ declare function findInVigorErrorChain(error: unknown, match: (error: unknown) => boolean): unknown;
761
772
 
762
773
  declare const VigorParseErrorMessageFuncs: {
763
774
  readonly VALUE_REQUIRED: ({ key }: {
@@ -843,6 +854,20 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
843
854
  */
844
855
  declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
845
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
+ *
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
+ *
866
+ * @example
867
+ * const notFound = findVigorParseError(error, "PARSER_NOT_FOUND")
868
+ * if (notFound) notFound.data.expected
869
+ */
870
+ declare function findVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorParseErrorsIn<E, C> | null;
846
871
 
847
872
  type VigorParsePolicySchema<T extends VigorParseSchema<T>> = {
848
873
  __brand: VigorBrand<"Parse", "Policy<Schema">;
@@ -1714,6 +1739,20 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1714
1739
  */
1715
1740
  declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1716
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
+ *
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
+ *
1751
+ * @example
1752
+ * const timedOut = findVigorRetryError(error, "TIMED_OUT")
1753
+ * if (timedOut) timedOut.data.limit
1754
+ */
1755
+ declare function findVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorRetryErrorsIn<E, C> | null;
1717
1756
 
1718
1757
  type VigorRetryPolicySchema<T extends VigorRetrySchema<T>> = {
1719
1758
  __brand: VigorBrand<"Retry", "Policy<Schema">;
@@ -2484,6 +2523,20 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2484
2523
  */
2485
2524
  declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2486
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
+ *
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
+ *
2535
+ * @example
2536
+ * const timedOut = findVigorAllError(error, "TIMED_OUT")
2537
+ * if (timedOut) timedOut.data.index
2538
+ */
2539
+ declare function findVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorAllErrorsIn<E, C> | null;
2487
2540
 
2488
2541
  /**
2489
2542
  * A single task. It receives an `AbortSignal` that fires when the task's
@@ -4014,6 +4067,20 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4014
4067
  */
4015
4068
  declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4016
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
+ *
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
+ *
4079
+ * @example
4080
+ * const failed = findVigorFetchError(error, "FETCH_FAILED")
4081
+ * if (failed) failed.data.status
4082
+ */
4083
+ declare function findVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorFetchErrorsIn<E, C> | null;
4017
4084
  /**
4018
4085
  * Re-raises an error of the nested retry/parse engine as a `VigorFetchError`
4019
4086
  * with the same `code`, `data`, and `method`, keeping the original as
@@ -5414,10 +5481,18 @@ declare const vigorBase: {
5414
5481
  };
5415
5482
  };
5416
5483
  guards: {
5417
- retry: typeof isVigorRetryError;
5418
- parse: typeof isVigorParseError;
5419
- fetch: typeof isVigorFetchError;
5420
- all: typeof isVigorAllError;
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
+ };
5421
5496
  };
5422
5497
  };
5423
5498
  /** `A` with `B`'s properties replacing same-named ones, like `{ ...A, ...B }`. */
@@ -5447,4 +5522,4 @@ type VigorPlugin<O extends {
5447
5522
  };
5448
5523
  declare const vigor: VigorInstance;
5449
5524
 
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 };
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 };
package/dist/index.d.ts CHANGED
@@ -758,6 +758,17 @@ 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 `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.
770
+ */
771
+ declare function findInVigorErrorChain(error: unknown, match: (error: unknown) => boolean): unknown;
761
772
 
762
773
  declare const VigorParseErrorMessageFuncs: {
763
774
  readonly VALUE_REQUIRED: ({ key }: {
@@ -843,6 +854,20 @@ type VigorParseErrorsIn<E, C extends VigorParseErrorCodes = VigorParseErrorCodes
843
854
  */
844
855
  declare function isVigorParseError<E>(error: E): error is E & VigorParseErrorsIn<E>;
845
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
+ *
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
+ *
866
+ * @example
867
+ * const notFound = findVigorParseError(error, "PARSER_NOT_FOUND")
868
+ * if (notFound) notFound.data.expected
869
+ */
870
+ declare function findVigorParseError<E, const C extends VigorParseErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorParseErrorsIn<E, C> | null;
846
871
 
847
872
  type VigorParsePolicySchema<T extends VigorParseSchema<T>> = {
848
873
  __brand: VigorBrand<"Parse", "Policy<Schema">;
@@ -1714,6 +1739,20 @@ type VigorRetryErrorsIn<E, C extends VigorRetryErrorCodes = VigorRetryErrorCodes
1714
1739
  */
1715
1740
  declare function isVigorRetryError<E>(error: E): error is E & VigorRetryErrorsIn<E>;
1716
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
+ *
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
+ *
1751
+ * @example
1752
+ * const timedOut = findVigorRetryError(error, "TIMED_OUT")
1753
+ * if (timedOut) timedOut.data.limit
1754
+ */
1755
+ declare function findVigorRetryError<E, const C extends VigorRetryErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorRetryErrorsIn<E, C> | null;
1717
1756
 
1718
1757
  type VigorRetryPolicySchema<T extends VigorRetrySchema<T>> = {
1719
1758
  __brand: VigorBrand<"Retry", "Policy<Schema">;
@@ -2484,6 +2523,20 @@ type VigorAllErrorsIn<E, C extends VigorAllErrorCodes = VigorAllErrorCodes> = [
2484
2523
  */
2485
2524
  declare function isVigorAllError<E>(error: E): error is E & VigorAllErrorsIn<E>;
2486
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
+ *
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
+ *
2535
+ * @example
2536
+ * const timedOut = findVigorAllError(error, "TIMED_OUT")
2537
+ * if (timedOut) timedOut.data.index
2538
+ */
2539
+ declare function findVigorAllError<E, const C extends VigorAllErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorAllErrorsIn<E, C> | null;
2487
2540
 
2488
2541
  /**
2489
2542
  * A single task. It receives an `AbortSignal` that fires when the task's
@@ -4014,6 +4067,20 @@ type VigorFetchErrorsIn<E, C extends VigorFetchErrorCodes = VigorFetchErrorCodes
4014
4067
  */
4015
4068
  declare function isVigorFetchError<E>(error: E): error is E & VigorFetchErrorsIn<E>;
4016
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
+ *
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
+ *
4079
+ * @example
4080
+ * const failed = findVigorFetchError(error, "FETCH_FAILED")
4081
+ * if (failed) failed.data.status
4082
+ */
4083
+ declare function findVigorFetchError<E, const C extends VigorFetchErrorCodes>(error: E, ...codes: [C, ...C[]]): VigorFetchErrorsIn<E, C> | null;
4017
4084
  /**
4018
4085
  * Re-raises an error of the nested retry/parse engine as a `VigorFetchError`
4019
4086
  * with the same `code`, `data`, and `method`, keeping the original as
@@ -5414,10 +5481,18 @@ declare const vigorBase: {
5414
5481
  };
5415
5482
  };
5416
5483
  guards: {
5417
- retry: typeof isVigorRetryError;
5418
- parse: typeof isVigorParseError;
5419
- fetch: typeof isVigorFetchError;
5420
- all: typeof isVigorAllError;
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
+ };
5421
5496
  };
5422
5497
  };
5423
5498
  /** `A` with `B`'s properties replacing same-named ones, like `{ ...A, ...B }`. */
@@ -5447,4 +5522,4 @@ type VigorPlugin<O extends {
5447
5522
  };
5448
5523
  declare const vigor: VigorInstance;
5449
5524
 
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 };
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 };
package/dist/index.js CHANGED
@@ -222,6 +222,22 @@ 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
+ }
225
241
 
226
242
  // src/all/error.ts
227
243
  var VigorAllErrorMessageFuncs = {
@@ -241,6 +257,10 @@ var VigorAllError = class extends VigorError {
241
257
  function isVigorAllError(error, ...codes) {
242
258
  return error instanceof VigorAllError && (codes.length === 0 || codes.includes(error.code));
243
259
  }
260
+ function findVigorAllError(error, ...codes) {
261
+ const found = findInVigorErrorChain(error, (e) => isVigorAllError(e, ...codes));
262
+ return found === void 0 ? null : found;
263
+ }
244
264
 
245
265
  // src/core/timeline.ts
246
266
  var internalMiddlewares = /* @__PURE__ */ new WeakSet();
@@ -758,6 +778,10 @@ var VigorRetryError = class extends VigorError {
758
778
  function isVigorRetryError(error, ...codes) {
759
779
  return error instanceof VigorRetryError && (codes.length === 0 || codes.includes(error.code));
760
780
  }
781
+ function findVigorRetryError(error, ...codes) {
782
+ const found = findInVigorErrorChain(error, (e) => isVigorRetryError(e, ...codes));
783
+ return found === void 0 ? null : found;
784
+ }
761
785
 
762
786
  // src/retry/algorithms.ts
763
787
  function VigorJitter(jitter) {
@@ -1462,6 +1486,10 @@ var VigorParseError = class extends VigorError {
1462
1486
  function isVigorParseError(error, ...codes) {
1463
1487
  return error instanceof VigorParseError && (codes.length === 0 || codes.includes(error.code));
1464
1488
  }
1489
+ function findVigorParseError(error, ...codes) {
1490
+ const found = findInVigorErrorChain(error, (e) => isVigorParseError(e, ...codes));
1491
+ return found === void 0 ? null : found;
1492
+ }
1465
1493
 
1466
1494
  // src/parse/strategies.ts
1467
1495
  var VigorParsePolicyStrategiesBase = {
@@ -1954,6 +1982,10 @@ var VigorFetchError = class extends VigorError {
1954
1982
  function isVigorFetchError(error, ...codes) {
1955
1983
  return error instanceof VigorFetchError && (codes.length === 0 || codes.includes(error.code));
1956
1984
  }
1985
+ function findVigorFetchError(error, ...codes) {
1986
+ const found = findInVigorErrorChain(error, (e) => isVigorFetchError(e, ...codes));
1987
+ return found === void 0 ? null : found;
1988
+ }
1957
1989
  function adoptVigorFetchError(error, context) {
1958
1990
  if (!(error instanceof VigorRetryError) && !(error instanceof VigorParseError)) return error;
1959
1991
  const data = error.data;
@@ -2525,6 +2557,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
2525
2557
  };
2526
2558
 
2527
2559
  // src/entry/main.ts
2560
+ var guardWithFind = (guard, find) => Object.assign(((...args) => guard(...args)), { find });
2528
2561
  function retryWithTarget(task) {
2529
2562
  return new VigorRetry().target(task);
2530
2563
  }
@@ -2569,10 +2602,10 @@ var vigorBase = {
2569
2602
  }
2570
2603
  },
2571
2604
  guards: {
2572
- retry: isVigorRetryError,
2573
- parse: isVigorParseError,
2574
- fetch: isVigorFetchError,
2575
- all: isVigorAllError
2605
+ retry: guardWithFind(isVigorRetryError, findVigorRetryError),
2606
+ parse: guardWithFind(isVigorParseError, findVigorParseError),
2607
+ fetch: guardWithFind(isVigorFetchError, findVigorFetchError),
2608
+ all: guardWithFind(isVigorAllError, findVigorAllError)
2576
2609
  }
2577
2610
  };
2578
2611
  var cloneVigor = (v) => ({
@@ -2666,6 +2699,11 @@ export {
2666
2699
  createBrand,
2667
2700
  createVigorTimelineRecorder,
2668
2701
  index_default as default,
2702
+ findInVigorErrorChain,
2703
+ findVigorAllError,
2704
+ findVigorFetchError,
2705
+ findVigorParseError,
2706
+ findVigorRetryError,
2669
2707
  isVigorAllError,
2670
2708
  isVigorDefault,
2671
2709
  isVigorEmpty,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vigor-fetch",
3
- "version": "5.1.0",
3
+ "version": "5.2.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",