@zap-studio/retry 0.2.0 → 0.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/CHANGELOG.md +18 -0
- package/README.md +16 -4
- package/dist/abort.d.mts +30 -0
- package/dist/abort.d.mts.map +1 -0
- package/dist/abort.mjs +61 -0
- package/dist/abort.mjs.map +1 -0
- package/dist/errors-fWo_KyVO.d.mts +76 -0
- package/dist/errors-fWo_KyVO.d.mts.map +1 -0
- package/dist/errors.d.mts +2 -0
- package/dist/{error.mjs → errors.mjs} +21 -3
- package/dist/errors.mjs.map +1 -0
- package/dist/exponential-backoff.d.mts +18 -0
- package/dist/exponential-backoff.d.mts.map +1 -1
- package/dist/exponential-backoff.mjs +9 -0
- package/dist/exponential-backoff.mjs.map +1 -1
- package/dist/fixed-delay.d.mts +12 -0
- package/dist/fixed-delay.d.mts.map +1 -1
- package/dist/fixed-delay.mjs +6 -0
- package/dist/fixed-delay.mjs.map +1 -1
- package/dist/index.d.mts +3 -32
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -172
- package/dist/index.mjs.map +1 -1
- package/dist/result-mode.d.mts +24 -0
- package/dist/result-mode.d.mts.map +1 -0
- package/dist/result-mode.mjs +145 -0
- package/dist/result-mode.mjs.map +1 -0
- package/dist/sleep.d.mts +17 -0
- package/dist/sleep.d.mts.map +1 -0
- package/dist/sleep.mjs +21 -0
- package/dist/sleep.mjs.map +1 -0
- package/dist/throw-mode.d.mts +26 -0
- package/dist/throw-mode.d.mts.map +1 -0
- package/dist/throw-mode.mjs +50 -0
- package/dist/throw-mode.mjs.map +1 -0
- package/dist/types.d.mts +58 -3
- package/dist/types.d.mts.map +1 -1
- package/package.json +6 -2
- package/dist/error-CVW4I654.d.mts +0 -44
- package/dist/error-CVW4I654.d.mts.map +0 -1
- package/dist/error.d.mts +0 -2
- package/dist/error.mjs.map +0 -1
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as RetryError, t as AbortError } from "./errors-fWo_KyVO.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/**
|
|
@@ -28,25 +28,59 @@ interface RetryPolicy<TError = unknown, TData = unknown> {
|
|
|
28
28
|
* Decision returned by a retry policy for a specific attempt.
|
|
29
29
|
*/
|
|
30
30
|
interface RetryDecision {
|
|
31
|
+
/**
|
|
32
|
+
* When `true`, the runner may schedule another attempt (subject to
|
|
33
|
+
* `delayMs` and the runner's abort rules).
|
|
34
|
+
*/
|
|
31
35
|
readonly shouldRetry: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Milliseconds to wait before the next attempt when `shouldRetry` is `true`.
|
|
38
|
+
*/
|
|
32
39
|
readonly delayMs: number;
|
|
40
|
+
/**
|
|
41
|
+
* Optional machine-readable reason for the decision.
|
|
42
|
+
*/
|
|
33
43
|
readonly reason?: "retry" | "max-attempts-reached" | "policy-declined";
|
|
34
44
|
}
|
|
35
45
|
/**
|
|
36
46
|
* Input passed to `RetryPolicy.next(...)` for each failed attempt.
|
|
37
47
|
*/
|
|
38
48
|
interface RetryDecisionInput<TError = unknown, TData = unknown> {
|
|
49
|
+
/**
|
|
50
|
+
* One-based attempt number for the current failure.
|
|
51
|
+
*/
|
|
39
52
|
readonly attempt: number;
|
|
53
|
+
/**
|
|
54
|
+
* Optional policy-level maximum attempts, when a policy wants to pass it
|
|
55
|
+
* through to `next`.
|
|
56
|
+
*/
|
|
40
57
|
readonly maxAttempts?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Error raised by the most recent `execute(attempt)` call, when a failure
|
|
60
|
+
* occurred.
|
|
61
|
+
*/
|
|
41
62
|
readonly error?: TError;
|
|
63
|
+
/**
|
|
64
|
+
* Optional data captured alongside the failure, when a policy populates
|
|
65
|
+
* it.
|
|
66
|
+
*/
|
|
42
67
|
readonly data?: TData;
|
|
43
68
|
}
|
|
44
69
|
/**
|
|
45
70
|
* Input passed to `RetryPolicy.onExhausted(...)` when retries stop.
|
|
46
71
|
*/
|
|
47
72
|
interface RetryExhaustedInput<TError = unknown, TData = unknown> {
|
|
73
|
+
/**
|
|
74
|
+
* Count of completed attempts that led to stopping retries.
|
|
75
|
+
*/
|
|
48
76
|
readonly attempts: number;
|
|
77
|
+
/**
|
|
78
|
+
* Last execution error, when available.
|
|
79
|
+
*/
|
|
49
80
|
readonly error?: TError;
|
|
81
|
+
/**
|
|
82
|
+
* Last captured data, when a policy or runner supplies it.
|
|
83
|
+
*/
|
|
50
84
|
readonly data?: TData;
|
|
51
85
|
}
|
|
52
86
|
/**
|
|
@@ -70,19 +104,40 @@ interface RetryRunOptions {
|
|
|
70
104
|
*
|
|
71
105
|
* When `false`, the runner returns a `RetryRunResult` discriminated union.
|
|
72
106
|
*
|
|
73
|
-
* @default
|
|
107
|
+
* @default true
|
|
74
108
|
*/
|
|
75
109
|
readonly throwOnExhausted?: boolean;
|
|
76
110
|
}
|
|
77
111
|
/**
|
|
78
112
|
* Result union returned by non-throw runner mode.
|
|
113
|
+
*
|
|
114
|
+
* - Success: `ok: true` with the resolved `value`.
|
|
115
|
+
* - Failure: `ok: false` with terminal `error` and completed `attempts` count
|
|
116
|
+
* (exhaustion or abort).
|
|
79
117
|
*/
|
|
80
118
|
type RetryRunResult<T> = {
|
|
119
|
+
/**
|
|
120
|
+
* Discriminator for a successful run.
|
|
121
|
+
*/
|
|
81
122
|
ok: true;
|
|
123
|
+
/**
|
|
124
|
+
* Successful return value from the final attempt.
|
|
125
|
+
*/
|
|
82
126
|
value: T;
|
|
83
127
|
} | {
|
|
128
|
+
/**
|
|
129
|
+
* Discriminator for a failed or aborted run.
|
|
130
|
+
*/
|
|
84
131
|
ok: false;
|
|
85
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Terminal error: `RetryError` when retries are exhausted, or
|
|
134
|
+
* `AbortError` when the run is canceled (non-throw path uses the same
|
|
135
|
+
* instances as throw mode, not wrapped).
|
|
136
|
+
*/
|
|
137
|
+
error: RetryError | AbortError;
|
|
138
|
+
/**
|
|
139
|
+
* Number of attempts that completed before the terminal outcome.
|
|
140
|
+
*/
|
|
86
141
|
attempts: number;
|
|
87
142
|
};
|
|
88
143
|
//#endregion
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;UAiBiB,WAAA;;;;;;EAMf,IAAA,CAAK,KAAA,EAAO,kBAAA,CAAmB,MAAA,EAAQ,KAAA,IAAS,aAAA;;;;;;EAMhD,WAAA,CAAY,KAAA,EAAO,mBAAA,CAAoB,MAAA,EAAQ,KAAA,IAAS,UAAA;AAAA;AAM1D;;;AAAA,UAAiB,aAAA
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;;UAiBiB,WAAA;;;;;;EAMf,IAAA,CAAK,KAAA,EAAO,kBAAA,CAAmB,MAAA,EAAQ,KAAA,IAAS,aAAA;;;;;;EAMhD,WAAA,CAAY,KAAA,EAAO,mBAAA,CAAoB,MAAA,EAAQ,KAAA,IAAS,UAAA;AAAA;AAM1D;;;AAAA,UAAiB,aAAA;;;;;WAKN,WAAA;EAcX;;;EAAA,SAVW,OAAA;;;;WAIA,MAAA;AAAA;;;;UAMM,kBAAA;;;;WAIN,OAAA;;;;;WAKA,WAAA;;;AAkCX;;WA7BW,KAAA,GAAQ,MAAA;EAyCC;;;;EAAA,SApCT,IAAA,GAAO,KAAA;AAAA;;;;UAMD,mBAAA;;;;WAIN,QAAA;;;;WAIA,KAAA,GAAQ,MAAA;;;;WAIR,IAAA,GAAO,KAAA;AAAA;;;;UAMD,eAAA;;;;;;WAMN,KAAA,IAAS,OAAA,aAAoB,OAAA;;;;;;WAM7B,MAAA,GAAS,WAAA;;;;;;;;WAQT,gBAAA;AAAA;;;;;;;;KAUC,cAAA;;;;EAKN,EAAA;;;;EAIA,KAAA,EAAO,CAAA;AAAA;;;;EAMP,EAAA;;;;;;EAMA,KAAA,EAAO,UAAA,GAAa,UAAA;;;;EAIpB,QAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zap-studio/retry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Composable retry policies for resilient async operations.",
|
|
6
6
|
"keywords": [
|
|
@@ -30,9 +30,13 @@
|
|
|
30
30
|
"types": "./dist/index.d.mts",
|
|
31
31
|
"exports": {
|
|
32
32
|
".": "./dist/index.mjs",
|
|
33
|
-
"./
|
|
33
|
+
"./abort": "./dist/abort.mjs",
|
|
34
|
+
"./errors": "./dist/errors.mjs",
|
|
34
35
|
"./exponential-backoff": "./dist/exponential-backoff.mjs",
|
|
35
36
|
"./fixed-delay": "./dist/fixed-delay.mjs",
|
|
37
|
+
"./result-mode": "./dist/result-mode.mjs",
|
|
38
|
+
"./sleep": "./dist/sleep.mjs",
|
|
39
|
+
"./throw-mode": "./dist/throw-mode.mjs",
|
|
36
40
|
"./types": "./dist/types.mjs",
|
|
37
41
|
"./package.json": "./package.json"
|
|
38
42
|
},
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
//#region src/error.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Terminal error types used by retry policies and runners.
|
|
4
|
-
*
|
|
5
|
-
* @module @zap-studio/retry/error
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Context payload attached to `RetryError`.
|
|
9
|
-
*/
|
|
10
|
-
interface RetryErrorContext {
|
|
11
|
-
readonly attempts: number;
|
|
12
|
-
readonly lastError?: unknown;
|
|
13
|
-
readonly lastData?: unknown;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Error thrown when retries are exhausted.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* throw new RetryError("Retry exhausted", {
|
|
20
|
-
* attempts: 3,
|
|
21
|
-
* lastError: new Error("network"),
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
24
|
-
declare class RetryError extends Error {
|
|
25
|
-
/**
|
|
26
|
-
* Total attempts performed before exhaustion.
|
|
27
|
-
*/
|
|
28
|
-
readonly attempts: number;
|
|
29
|
-
/**
|
|
30
|
-
* Last captured error from execution.
|
|
31
|
-
*/
|
|
32
|
-
readonly lastError?: unknown;
|
|
33
|
-
/**
|
|
34
|
-
* Last captured data value, when available.
|
|
35
|
-
*/
|
|
36
|
-
readonly lastData?: unknown;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a RetryError with structured terminal context.
|
|
39
|
-
*/
|
|
40
|
-
constructor(message: string, context: RetryErrorContext);
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
export { RetryErrorContext as n, RetryError as t };
|
|
44
|
-
//# sourceMappingURL=error-CVW4I654.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-CVW4I654.d.mts","names":[],"sources":["../src/error.ts"],"mappings":";;AASA;;;;;;;UAAiB,iBAAA;EAAA,SACN,QAAA;EAAA,SACA,SAAA;EAAA,SACA,QAAA;AAAA;;;;;;;;;;cAYE,UAAA,SAAmB,KAAA;EAiBQ;;;EAAA,SAbtB,QAAA;;;;WAIA,SAAA;;;;WAIA,QAAA;;;;EAKhB,WAAA,CAAY,OAAA,UAAiB,OAAA,EAAS,iBAAA;AAAA"}
|
package/dist/error.d.mts
DELETED
package/dist/error.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.mjs","names":[],"sources":["../src/error.ts"],"sourcesContent":["/**\n * Terminal error types used by retry policies and runners.\n *\n * @module @zap-studio/retry/error\n */\n\n/**\n * Context payload attached to `RetryError`.\n */\nexport interface RetryErrorContext {\n readonly attempts: number;\n readonly lastError?: unknown;\n readonly lastData?: unknown;\n}\n\n/**\n * Error thrown when retries are exhausted.\n *\n * @example\n * throw new RetryError(\"Retry exhausted\", {\n * attempts: 3,\n * lastError: new Error(\"network\"),\n * });\n */\nexport class RetryError extends Error {\n /**\n * Total attempts performed before exhaustion.\n */\n public readonly attempts: number;\n /**\n * Last captured error from execution.\n */\n public readonly lastError?: unknown;\n /**\n * Last captured data value, when available.\n */\n public readonly lastData?: unknown;\n\n /**\n * Creates a RetryError with structured terminal context.\n */\n constructor(message: string, context: RetryErrorContext) {\n super(message);\n this.name = \"RetryError\";\n this.attempts = context.attempts;\n this.lastError = context.lastError;\n this.lastData = context.lastData;\n }\n}\n"],"mappings":";;;;;;;;;;AAwBA,IAAa,aAAb,cAAgC,MAAM;;;;CAIpC;;;;CAIA;;;;CAIA;;;;CAKA,YAAY,SAAiB,SAA4B;AACvD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,WAAW,QAAQ;AACxB,OAAK,YAAY,QAAQ;AACzB,OAAK,WAAW,QAAQ"}
|