@tanstack/pacer 0.22.0 → 0.23.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 +4 -4
- package/dist/async-batcher.d.ts +11 -13
- package/dist/async-batcher.js +185 -131
- package/dist/async-debouncer.d.ts +6 -8
- package/dist/async-debouncer.js +186 -142
- package/dist/async-queuer.d.ts +11 -13
- package/dist/async-queuer.js +383 -290
- package/dist/async-rate-limiter.d.ts +6 -8
- package/dist/async-rate-limiter.js +197 -143
- package/dist/async-retryer.d.ts +6 -8
- package/dist/async-retryer.js +209 -179
- package/dist/async-throttler.d.ts +6 -8
- package/dist/async-throttler.js +214 -157
- package/dist/batcher.d.ts +5 -7
- package/dist/batcher.js +107 -87
- package/dist/debouncer.d.ts +6 -8
- package/dist/debouncer.js +99 -86
- package/dist/event-client.d.ts +8 -10
- package/dist/event-client.js +1 -2
- package/dist/queuer.d.ts +7 -9
- package/dist/queuer.js +277 -212
- package/dist/rate-limiter.d.ts +6 -8
- package/dist/rate-limiter.js +127 -109
- package/dist/throttler.d.ts +6 -8
- package/dist/throttler.js +127 -90
- package/dist/types.d.ts +4 -6
- package/dist/utils.d.ts +3 -5
- package/dist/utils.js +1 -2
- package/package.json +21 -68
- package/dist/async-batcher.cjs +0 -337
- package/dist/async-batcher.cjs.map +0 -1
- package/dist/async-batcher.d.cts +0 -343
- package/dist/async-batcher.js.map +0 -1
- package/dist/async-debouncer.cjs +0 -327
- package/dist/async-debouncer.cjs.map +0 -1
- package/dist/async-debouncer.d.cts +0 -299
- package/dist/async-debouncer.js.map +0 -1
- package/dist/async-queuer.cjs +0 -516
- package/dist/async-queuer.cjs.map +0 -1
- package/dist/async-queuer.d.cts +0 -440
- package/dist/async-queuer.js.map +0 -1
- package/dist/async-rate-limiter.cjs +0 -370
- package/dist/async-rate-limiter.cjs.map +0 -1
- package/dist/async-rate-limiter.d.cts +0 -356
- package/dist/async-rate-limiter.js.map +0 -1
- package/dist/async-retryer.cjs +0 -365
- package/dist/async-retryer.cjs.map +0 -1
- package/dist/async-retryer.d.cts +0 -321
- package/dist/async-retryer.js.map +0 -1
- package/dist/async-throttler.cjs +0 -344
- package/dist/async-throttler.cjs.map +0 -1
- package/dist/async-throttler.d.cts +0 -319
- package/dist/async-throttler.js.map +0 -1
- package/dist/batcher.cjs +0 -200
- package/dist/batcher.cjs.map +0 -1
- package/dist/batcher.d.cts +0 -179
- package/dist/batcher.js.map +0 -1
- package/dist/debouncer.cjs +0 -203
- package/dist/debouncer.cjs.map +0 -1
- package/dist/debouncer.d.cts +0 -166
- package/dist/debouncer.js.map +0 -1
- package/dist/event-client.cjs +0 -64
- package/dist/event-client.cjs.map +0 -1
- package/dist/event-client.d.cts +0 -65
- package/dist/event-client.js.map +0 -1
- package/dist/index.cjs +0 -52
- package/dist/index.d.cts +0 -15
- package/dist/queuer.cjs +0 -406
- package/dist/queuer.cjs.map +0 -1
- package/dist/queuer.d.cts +0 -345
- package/dist/queuer.js.map +0 -1
- package/dist/rate-limiter.cjs +0 -263
- package/dist/rate-limiter.cjs.map +0 -1
- package/dist/rate-limiter.d.cts +0 -214
- package/dist/rate-limiter.js.map +0 -1
- package/dist/throttler.cjs +0 -215
- package/dist/throttler.cjs.map +0 -1
- package/dist/throttler.d.cts +0 -206
- package/dist/throttler.js.map +0 -1
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +0 -13
- package/dist/utils.cjs +0 -13
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -7
- package/dist/utils.js.map +0 -1
- package/src/async-batcher.ts +0 -594
- package/src/async-debouncer.ts +0 -566
- package/src/async-queuer.ts +0 -988
- package/src/async-rate-limiter.ts +0 -648
- package/src/async-retryer.ts +0 -673
- package/src/async-throttler.ts +0 -634
- package/src/batcher.ts +0 -329
- package/src/debouncer.ts +0 -334
- package/src/event-client.ts +0 -129
- package/src/index.ts +0 -24
- package/src/queuer.ts +0 -751
- package/src/rate-limiter.ts +0 -429
- package/src/throttler.ts +0 -380
- package/src/types.ts +0 -12
- package/src/utils.ts +0 -12
package/dist/async-retryer.d.cts
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { AnyAsyncFunction } from "./types.cjs";
|
|
2
|
-
import { Store } from "@tanstack/store";
|
|
3
|
-
//#region src/async-retryer.d.ts
|
|
4
|
-
interface AsyncRetryerState<TFn extends AnyAsyncFunction> {
|
|
5
|
-
/**
|
|
6
|
-
* The current retry attempt number (0 when not executing)
|
|
7
|
-
*/
|
|
8
|
-
currentAttempt: number;
|
|
9
|
-
/**
|
|
10
|
-
* Total number of completed executions (successful or failed)
|
|
11
|
-
*/
|
|
12
|
-
executionCount: number;
|
|
13
|
-
/**
|
|
14
|
-
* Whether the retryer is currently executing the function
|
|
15
|
-
*/
|
|
16
|
-
isExecuting: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* The most recent error encountered during execution
|
|
19
|
-
*/
|
|
20
|
-
lastError: Error | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Timestamp of the last execution completion in milliseconds
|
|
23
|
-
*/
|
|
24
|
-
lastExecutionTime: number;
|
|
25
|
-
/**
|
|
26
|
-
* The result from the most recent successful execution
|
|
27
|
-
*/
|
|
28
|
-
lastResult: Awaited<ReturnType<TFn>> | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* Current execution status - 'disabled' when not enabled, 'idle' when ready, 'executing' when running
|
|
31
|
-
*/
|
|
32
|
-
status: 'disabled' | 'idle' | 'executing' | 'retrying';
|
|
33
|
-
/**
|
|
34
|
-
* Total time spent executing (including retries) in milliseconds
|
|
35
|
-
*/
|
|
36
|
-
totalExecutionTime: number;
|
|
37
|
-
}
|
|
38
|
-
interface AsyncRetryerOptions<TFn extends AnyAsyncFunction> {
|
|
39
|
-
/**
|
|
40
|
-
* The backoff strategy for retry delays:
|
|
41
|
-
* - 'exponential': Wait time doubles with each attempt (1s, 2s, 4s, ...)
|
|
42
|
-
* - 'linear': Wait time increases linearly (1s, 2s, 3s, ...)
|
|
43
|
-
* - 'fixed': Same wait time for all attempts
|
|
44
|
-
* @default 'exponential'
|
|
45
|
-
*/
|
|
46
|
-
backoff?: 'linear' | 'exponential' | 'fixed';
|
|
47
|
-
/**
|
|
48
|
-
* Base wait time in milliseconds between retries, or a function that returns the wait time
|
|
49
|
-
* @default 1000
|
|
50
|
-
*/
|
|
51
|
-
baseWait?: number | ((retryer: AsyncRetryer<TFn>) => number);
|
|
52
|
-
/**
|
|
53
|
-
* Whether the retryer is enabled, or a function that determines if it's enabled
|
|
54
|
-
* @default true
|
|
55
|
-
*/
|
|
56
|
-
enabled?: boolean | ((retryer: AsyncRetryer<TFn>) => boolean);
|
|
57
|
-
/**
|
|
58
|
-
* Initial state to merge with the default state
|
|
59
|
-
*/
|
|
60
|
-
initialState?: Partial<AsyncRetryerState<TFn>>;
|
|
61
|
-
/**
|
|
62
|
-
* Jitter percentage to add to retry delays (0-1). Adds randomness to prevent thundering herd.
|
|
63
|
-
* @default 0
|
|
64
|
-
*/
|
|
65
|
-
jitter?: number;
|
|
66
|
-
/**
|
|
67
|
-
* Optional key to identify this async retryer instance.
|
|
68
|
-
* Note: async retryers are not currently surfaced in the devtools, so this key
|
|
69
|
-
* is only a plain identifier. Retryer instances are often created per-execution
|
|
70
|
-
* (including internally by the other async utilities), so they intentionally do
|
|
71
|
-
* not register with the devtools event bus.
|
|
72
|
-
*/
|
|
73
|
-
key?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Maximum number of retry attempts, or a function that returns the max attempts
|
|
76
|
-
* @default 3
|
|
77
|
-
*/
|
|
78
|
-
maxAttempts?: number | ((retryer: AsyncRetryer<TFn>) => number);
|
|
79
|
-
/**
|
|
80
|
-
* Maximum execution time in milliseconds for a single function call before aborting
|
|
81
|
-
* @default Infinity
|
|
82
|
-
*/
|
|
83
|
-
maxExecutionTime?: number;
|
|
84
|
-
/**
|
|
85
|
-
* Maximum total execution time in milliseconds for the entire retry operation before aborting
|
|
86
|
-
* @default Infinity
|
|
87
|
-
*/
|
|
88
|
-
maxTotalExecutionTime?: number;
|
|
89
|
-
/**
|
|
90
|
-
* Maximum wait time in milliseconds to cap retry delays, or a function that returns the max wait time
|
|
91
|
-
* @default Infinity
|
|
92
|
-
*/
|
|
93
|
-
maxWait?: number | ((retryer: AsyncRetryer<TFn>) => number);
|
|
94
|
-
/**
|
|
95
|
-
* Callback invoked when the execution is aborted (manually or due to timeouts)
|
|
96
|
-
*/
|
|
97
|
-
onAbort?: (reason: 'manual' | 'execution-timeout' | 'total-timeout' | 'new-execution', retryer: AsyncRetryer<TFn>) => void;
|
|
98
|
-
/**
|
|
99
|
-
* Callback invoked when any error occurs during execution (including retries)
|
|
100
|
-
*/
|
|
101
|
-
onError?: (error: Error, args: Parameters<TFn>, retryer: AsyncRetryer<TFn>) => void;
|
|
102
|
-
/**
|
|
103
|
-
* Callback invoked when a single execution attempt times out (maxExecutionTime exceeded)
|
|
104
|
-
*/
|
|
105
|
-
onExecutionTimeout?: (retryer: AsyncRetryer<TFn>) => void;
|
|
106
|
-
/**
|
|
107
|
-
* Callback invoked when the final error occurs after all retries are exhausted
|
|
108
|
-
*/
|
|
109
|
-
onLastError?: (error: Error, retryer: AsyncRetryer<TFn>) => void;
|
|
110
|
-
/**
|
|
111
|
-
* Callback invoked before each retry attempt
|
|
112
|
-
*/
|
|
113
|
-
onRetry?: (attempt: number, error: Error, retryer: AsyncRetryer<TFn>) => void;
|
|
114
|
-
/**
|
|
115
|
-
* Callback invoked after execution completes (success or failure) of each attempt
|
|
116
|
-
*/
|
|
117
|
-
onSettled?: (args: Parameters<TFn>, retryer: AsyncRetryer<TFn>) => void;
|
|
118
|
-
/**
|
|
119
|
-
* Callback invoked when execution succeeds
|
|
120
|
-
*/
|
|
121
|
-
onSuccess?: (result: Awaited<ReturnType<TFn>>, args: Parameters<TFn>, retryer: AsyncRetryer<TFn>) => void;
|
|
122
|
-
/**
|
|
123
|
-
* Callback invoked when the total execution time times out (maxTotalExecutionTime exceeded)
|
|
124
|
-
*/
|
|
125
|
-
onTotalExecutionTimeout?: (retryer: AsyncRetryer<TFn>) => void;
|
|
126
|
-
/**
|
|
127
|
-
* Controls when errors are thrown:
|
|
128
|
-
* - 'last': Only throw the final error after all retries are exhausted
|
|
129
|
-
* - true: Throw every error immediately (disables retrying)
|
|
130
|
-
* - false: Never throw errors, return undefined instead
|
|
131
|
-
* @default 'last'
|
|
132
|
-
*/
|
|
133
|
-
throwOnError?: boolean | 'last';
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Utility function for sharing common `AsyncRetryerOptions` options between different `AsyncRetryer` instances.
|
|
137
|
-
*/
|
|
138
|
-
declare function asyncRetryerOptions<TFn extends AnyAsyncFunction = AnyAsyncFunction, TOptions extends Partial<AsyncRetryerOptions<TFn>> = Partial<AsyncRetryerOptions<TFn>>>(options: TOptions): TOptions;
|
|
139
|
-
declare const defaultOptions: Omit<Required<AsyncRetryerOptions<any>>, 'initialState' | 'key' | 'onAbort' | 'onError' | 'onLastError' | 'onRetry' | 'onSettled' | 'onSuccess' | 'onExecutionTimeout' | 'onTotalExecutionTimeout'>;
|
|
140
|
-
/**
|
|
141
|
-
* Provides robust retry functionality for asynchronous functions, supporting configurable backoff strategies,
|
|
142
|
-
* attempt limits, timeout controls, and detailed state management. The AsyncRetryer class is designed to help you reliably
|
|
143
|
-
* execute async operations that may fail intermittently, such as network requests or database operations,
|
|
144
|
-
* by automatically retrying them according to your chosen policy.
|
|
145
|
-
*
|
|
146
|
-
* ## Retrying Concepts
|
|
147
|
-
*
|
|
148
|
-
* - **Retrying**: Automatically re-executes a failed async function up to a specified number of attempts.
|
|
149
|
-
* Useful for handling transient errors (e.g., network flakiness, rate limits, temporary server issues).
|
|
150
|
-
* - **Backoff Strategies**: Controls the delay between retry attempts (default: `'exponential'`):
|
|
151
|
-
* - `'exponential'`: Wait time doubles with each attempt (1s, 2s, 4s, ...) - **DEFAULT**
|
|
152
|
-
* - `'linear'`: Wait time increases linearly (1s, 2s, 3s, ...)
|
|
153
|
-
* - `'fixed'`: Waits a constant amount of time (`baseWait`) between each attempt
|
|
154
|
-
* - **Jitter**: Adds randomness to retry delays to prevent thundering herd problems (default: `0`).
|
|
155
|
-
* Set to a value between 0-1 to apply that percentage of random variation to each delay.
|
|
156
|
-
* - **Max Wait**: Caps the maximum wait time between retries (default: `Infinity`).
|
|
157
|
-
* Useful for preventing exponential backoff from growing too large (e.g., cap at 30s even if exponential would be 64s).
|
|
158
|
-
* - **Timeout Controls**: Set limits on execution time to prevent hanging operations:
|
|
159
|
-
* - `maxExecutionTime`: Maximum time for a single function call (default: `Infinity`)
|
|
160
|
-
* - `maxTotalExecutionTime`: Maximum time for the entire retry operation (default: `Infinity`)
|
|
161
|
-
* - **Abort & Cancellation**: Supports cancellation via an internal `AbortController`. Call `abort()` to stop retries.
|
|
162
|
-
* Use `getAbortSignal()` to make your async function actually cancellable (e.g., with fetch requests).
|
|
163
|
-
*
|
|
164
|
-
* ## State Management
|
|
165
|
-
*
|
|
166
|
-
* Uses TanStack Store for fine-grained reactivity. State can be accessed via the `store.state` property.
|
|
167
|
-
*
|
|
168
|
-
* Available state properties:
|
|
169
|
-
* - `currentAttempt`: The current retry attempt number (0 when not executing)
|
|
170
|
-
* - `executionCount`: Total number of completed executions (successful or failed)
|
|
171
|
-
* - `isExecuting`: Whether the retryer is currently executing the function
|
|
172
|
-
* - `lastError`: The most recent error encountered during execution
|
|
173
|
-
* - `lastExecutionTime`: Timestamp of the last execution completion in milliseconds
|
|
174
|
-
* - `lastResult`: The result from the most recent successful execution
|
|
175
|
-
* - `status`: Current execution status ('disabled' | 'idle' | 'executing' | 'retrying')
|
|
176
|
-
* - `totalExecutionTime`: Total time spent executing (including retries) in milliseconds
|
|
177
|
-
*
|
|
178
|
-
* ## Error Handling
|
|
179
|
-
*
|
|
180
|
-
* The `throwOnError` option controls when errors are thrown (default: `'last'`):
|
|
181
|
-
* - `'last'`: Only throws the final error after all retries are exhausted - **DEFAULT**
|
|
182
|
-
* - `true`: Throws every error immediately (disables retrying)
|
|
183
|
-
* - `false`: Never throws errors, returns `undefined` instead
|
|
184
|
-
*
|
|
185
|
-
* Callbacks for lifecycle management:
|
|
186
|
-
* - `onAbort`: Called when execution is aborted (manually or due to timeouts)
|
|
187
|
-
* - `onError`: Called for every error (including during retries)
|
|
188
|
-
* - `onLastError`: Called only for the final error after all retries fail
|
|
189
|
-
* - `onRetry`: Called before each retry attempt
|
|
190
|
-
* - `onSettled`: Called after execution completes (success or failure) of each attempt
|
|
191
|
-
* - `onSuccess`: Called when execution succeeds
|
|
192
|
-
* - `onExecutionTimeout`: Called when a single execution attempt times out
|
|
193
|
-
* - `onTotalExecutionTimeout`: Called when the total execution time times out
|
|
194
|
-
*
|
|
195
|
-
* ## Usage
|
|
196
|
-
*
|
|
197
|
-
* - Use for async operations that may fail transiently and benefit from retrying.
|
|
198
|
-
* - Configure `maxAttempts`, `backoff`, `baseWait`, `maxWait`, and `jitter` to control retry behavior.
|
|
199
|
-
* - Set `maxExecutionTime` and `maxTotalExecutionTime` to prevent hanging operations.
|
|
200
|
-
* - Use `onAbort`, `onError`, `onLastError`, `onRetry`, `onSettled`, `onSuccess`, `onExecutionTimeout`, and `onTotalExecutionTimeout` for custom side effects.
|
|
201
|
-
* - Call `abort()` to cancel ongoing execution and pending retries.
|
|
202
|
-
* - Call `reset()` to reset state and cancel execution.
|
|
203
|
-
* - Use `getAbortSignal()` to make your async function cancellable.
|
|
204
|
-
* - Use dynamic options (functions) for `maxAttempts`, `baseWait`, and `enabled` based on retryer state.
|
|
205
|
-
*
|
|
206
|
-
* **Important:** This class is designed for single-use execution. Calling `execute()` multiple times
|
|
207
|
-
* on the same instance will abort previous executions. For multiple calls, create a new instance
|
|
208
|
-
* each time.
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* ```typescript
|
|
212
|
-
* // Retry a fetch operation up to 5 times with exponential backoff, jitter, and timeouts
|
|
213
|
-
* const retryer = new AsyncRetryer(async (url: string) => {
|
|
214
|
-
* const signal = retryer.getAbortSignal()
|
|
215
|
-
* return await fetch(url, { signal })
|
|
216
|
-
* }, {
|
|
217
|
-
* maxAttempts: 5,
|
|
218
|
-
* backoff: 'exponential',
|
|
219
|
-
* baseWait: 1000,
|
|
220
|
-
* jitter: 0.1, // Add 10% random variation to prevent thundering herd
|
|
221
|
-
* maxExecutionTime: 5000, // Abort individual calls after 5 seconds
|
|
222
|
-
* maxTotalExecutionTime: 30000, // Abort entire operation after 30 seconds
|
|
223
|
-
* onRetry: (attempt, error) => console.log(`Retry attempt ${attempt} after error:`, error),
|
|
224
|
-
* onSuccess: (result) => console.log('Success:', result),
|
|
225
|
-
* onError: (error) => console.error('Error:', error),
|
|
226
|
-
* onLastError: (error) => console.error('All retries failed:', error),
|
|
227
|
-
* })
|
|
228
|
-
*
|
|
229
|
-
* const result = await retryer.execute('/api/data')
|
|
230
|
-
* ```
|
|
231
|
-
*
|
|
232
|
-
* @template TFn The async function type to be retried.
|
|
233
|
-
*/
|
|
234
|
-
declare class AsyncRetryer<TFn extends AnyAsyncFunction> {
|
|
235
|
-
#private;
|
|
236
|
-
fn: TFn;
|
|
237
|
-
readonly store: Store<Readonly<AsyncRetryerState<TFn>>>;
|
|
238
|
-
key: string | undefined;
|
|
239
|
-
options: AsyncRetryerOptions<TFn> & typeof defaultOptions;
|
|
240
|
-
/**
|
|
241
|
-
* Creates a new AsyncRetryer instance
|
|
242
|
-
* @param fn The async function to retry
|
|
243
|
-
* @param initialOptions Configuration options for the retryer
|
|
244
|
-
*/
|
|
245
|
-
constructor(fn: TFn, initialOptions?: AsyncRetryerOptions<TFn>);
|
|
246
|
-
/**
|
|
247
|
-
* Updates the retryer options
|
|
248
|
-
* @param newOptions Partial options to merge with existing options
|
|
249
|
-
*/
|
|
250
|
-
setOptions: (newOptions: Partial<AsyncRetryerOptions<TFn>>) => void;
|
|
251
|
-
/**
|
|
252
|
-
* Executes the function with retry logic
|
|
253
|
-
* @param args Arguments to pass to the function
|
|
254
|
-
* @returns The function result, or undefined if disabled or all retries failed (when throwOnError is false)
|
|
255
|
-
* @throws The last error if throwOnError is true and all retries fail
|
|
256
|
-
*/
|
|
257
|
-
execute: (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
|
|
258
|
-
/**
|
|
259
|
-
* Returns the current AbortSignal for the executing operation.
|
|
260
|
-
* Use this signal in your async function to make it cancellable.
|
|
261
|
-
* Returns null when not currently executing.
|
|
262
|
-
*
|
|
263
|
-
* @example
|
|
264
|
-
* ```typescript
|
|
265
|
-
* const retryer = new AsyncRetryer(async (userId: string) => {
|
|
266
|
-
* const signal = retryer.getAbortSignal()
|
|
267
|
-
* if (signal) {
|
|
268
|
-
* return fetch(`/api/users/${userId}`, { signal })
|
|
269
|
-
* }
|
|
270
|
-
* return fetch(`/api/users/${userId}`)
|
|
271
|
-
* })
|
|
272
|
-
*
|
|
273
|
-
* // Abort will now actually cancel the fetch
|
|
274
|
-
* retryer.abort()
|
|
275
|
-
* ```
|
|
276
|
-
*/
|
|
277
|
-
getAbortSignal: () => AbortSignal | null;
|
|
278
|
-
/**
|
|
279
|
-
* Cancels the current execution and any pending retries
|
|
280
|
-
* @param reason The reason for the abort (defaults to 'manual')
|
|
281
|
-
*/
|
|
282
|
-
abort: (reason?: "manual" | "execution-timeout" | "total-timeout" | "new-execution") => void;
|
|
283
|
-
/**
|
|
284
|
-
* Resets the retryer to its initial state
|
|
285
|
-
*/
|
|
286
|
-
reset: () => void;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Creates a retry-enabled version of an async function. This is a convenience wrapper
|
|
290
|
-
* around the AsyncRetryer class that returns the execute method.
|
|
291
|
-
*
|
|
292
|
-
* @param fn The async function to add retry functionality to
|
|
293
|
-
* @param initialOptions Configuration options for the retry behavior
|
|
294
|
-
* @returns A new function that executes the original with retry logic
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```typescript
|
|
298
|
-
* // Define your async function normally
|
|
299
|
-
* async function fetchData(url: string) {
|
|
300
|
-
* const response = await fetch(url)
|
|
301
|
-
* if (!response.ok) throw new Error('Request failed')
|
|
302
|
-
* return response.json()
|
|
303
|
-
* }
|
|
304
|
-
*
|
|
305
|
-
* // Create retry-enabled function
|
|
306
|
-
* const fetchWithRetry = asyncRetry(fetchData, {
|
|
307
|
-
* maxAttempts: 3,
|
|
308
|
-
* backoff: 'exponential',
|
|
309
|
-
* baseWait: 1000,
|
|
310
|
-
* jitter: 0.1
|
|
311
|
-
* })
|
|
312
|
-
*
|
|
313
|
-
* // Call it multiple times
|
|
314
|
-
* const data1 = await fetchWithRetry('/api/data1')
|
|
315
|
-
* const data2 = await fetchWithRetry('/api/data2')
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
declare function asyncRetry<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions?: AsyncRetryerOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
|
|
319
|
-
//#endregion
|
|
320
|
-
export { AsyncRetryer, AsyncRetryerOptions, AsyncRetryerState, asyncRetry, asyncRetryerOptions };
|
|
321
|
-
//# sourceMappingURL=async-retryer.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-retryer.js","names":["#getEnabled","#getBaseWait","#getMaxWait","#calculateJitter","#abortController","#setState","#getMaxAttempts","#calculateWait"],"sources":["../src/async-retryer.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { parseFunctionOrValue } from './utils'\nimport type { AnyAsyncFunction } from './types'\n\nexport interface AsyncRetryerState<TFn extends AnyAsyncFunction> {\n /**\n * The current retry attempt number (0 when not executing)\n */\n currentAttempt: number\n /**\n * Total number of completed executions (successful or failed)\n */\n executionCount: number\n /**\n * Whether the retryer is currently executing the function\n */\n isExecuting: boolean\n /**\n * The most recent error encountered during execution\n */\n lastError: Error | undefined\n /**\n * Timestamp of the last execution completion in milliseconds\n */\n lastExecutionTime: number\n /**\n * The result from the most recent successful execution\n */\n lastResult: Awaited<ReturnType<TFn>> | undefined\n /**\n * Current execution status - 'disabled' when not enabled, 'idle' when ready, 'executing' when running\n */\n status: 'disabled' | 'idle' | 'executing' | 'retrying'\n /**\n * Total time spent executing (including retries) in milliseconds\n */\n totalExecutionTime: number\n}\n\n/**\n * Creates the default initial state for an AsyncRetryer instance\n * @returns The default state with all values reset to initial values\n */\nfunction getDefaultAsyncRetryerState<\n TFn extends AnyAsyncFunction,\n>(): AsyncRetryerState<TFn> {\n return {\n currentAttempt: 0,\n executionCount: 0,\n isExecuting: false,\n lastError: undefined,\n lastExecutionTime: 0,\n lastResult: undefined,\n status: 'idle',\n totalExecutionTime: 0,\n }\n}\n\nexport interface AsyncRetryerOptions<TFn extends AnyAsyncFunction> {\n /**\n * The backoff strategy for retry delays:\n * - 'exponential': Wait time doubles with each attempt (1s, 2s, 4s, ...)\n * - 'linear': Wait time increases linearly (1s, 2s, 3s, ...)\n * - 'fixed': Same wait time for all attempts\n * @default 'exponential'\n */\n backoff?: 'linear' | 'exponential' | 'fixed'\n /**\n * Base wait time in milliseconds between retries, or a function that returns the wait time\n * @default 1000\n */\n baseWait?: number | ((retryer: AsyncRetryer<TFn>) => number)\n /**\n * Whether the retryer is enabled, or a function that determines if it's enabled\n * @default true\n */\n enabled?: boolean | ((retryer: AsyncRetryer<TFn>) => boolean)\n /**\n * Initial state to merge with the default state\n */\n initialState?: Partial<AsyncRetryerState<TFn>>\n /**\n * Jitter percentage to add to retry delays (0-1). Adds randomness to prevent thundering herd.\n * @default 0\n */\n jitter?: number\n /**\n * Optional key to identify this async retryer instance.\n * Note: async retryers are not currently surfaced in the devtools, so this key\n * is only a plain identifier. Retryer instances are often created per-execution\n * (including internally by the other async utilities), so they intentionally do\n * not register with the devtools event bus.\n */\n key?: string\n /**\n * Maximum number of retry attempts, or a function that returns the max attempts\n * @default 3\n */\n maxAttempts?: number | ((retryer: AsyncRetryer<TFn>) => number)\n /**\n * Maximum execution time in milliseconds for a single function call before aborting\n * @default Infinity\n */\n maxExecutionTime?: number\n /**\n * Maximum total execution time in milliseconds for the entire retry operation before aborting\n * @default Infinity\n */\n maxTotalExecutionTime?: number\n /**\n * Maximum wait time in milliseconds to cap retry delays, or a function that returns the max wait time\n * @default Infinity\n */\n maxWait?: number | ((retryer: AsyncRetryer<TFn>) => number)\n /**\n * Callback invoked when the execution is aborted (manually or due to timeouts)\n */\n onAbort?: (\n reason: 'manual' | 'execution-timeout' | 'total-timeout' | 'new-execution',\n retryer: AsyncRetryer<TFn>,\n ) => void\n /**\n * Callback invoked when any error occurs during execution (including retries)\n */\n onError?: (\n error: Error,\n args: Parameters<TFn>,\n retryer: AsyncRetryer<TFn>,\n ) => void\n /**\n * Callback invoked when a single execution attempt times out (maxExecutionTime exceeded)\n */\n onExecutionTimeout?: (retryer: AsyncRetryer<TFn>) => void\n /**\n * Callback invoked when the final error occurs after all retries are exhausted\n */\n onLastError?: (error: Error, retryer: AsyncRetryer<TFn>) => void\n /**\n * Callback invoked before each retry attempt\n */\n onRetry?: (attempt: number, error: Error, retryer: AsyncRetryer<TFn>) => void\n /**\n * Callback invoked after execution completes (success or failure) of each attempt\n */\n onSettled?: (args: Parameters<TFn>, retryer: AsyncRetryer<TFn>) => void\n /**\n * Callback invoked when execution succeeds\n */\n onSuccess?: (\n result: Awaited<ReturnType<TFn>>,\n args: Parameters<TFn>,\n retryer: AsyncRetryer<TFn>,\n ) => void\n /**\n * Callback invoked when the total execution time times out (maxTotalExecutionTime exceeded)\n */\n onTotalExecutionTimeout?: (retryer: AsyncRetryer<TFn>) => void\n /**\n * Controls when errors are thrown:\n * - 'last': Only throw the final error after all retries are exhausted\n * - true: Throw every error immediately (disables retrying)\n * - false: Never throw errors, return undefined instead\n * @default 'last'\n */\n throwOnError?: boolean | 'last'\n}\n\n/**\n * Utility function for sharing common `AsyncRetryerOptions` options between different `AsyncRetryer` instances.\n */\nexport function asyncRetryerOptions<\n TFn extends AnyAsyncFunction = AnyAsyncFunction,\n TOptions extends Partial<AsyncRetryerOptions<TFn>> = Partial<\n AsyncRetryerOptions<TFn>\n >,\n>(options: TOptions): TOptions {\n return options\n}\n\nconst defaultOptions: Omit<\n Required<AsyncRetryerOptions<any>>,\n | 'initialState'\n | 'key'\n | 'onAbort'\n | 'onError'\n | 'onLastError'\n | 'onRetry'\n | 'onSettled'\n | 'onSuccess'\n | 'onExecutionTimeout'\n | 'onTotalExecutionTimeout'\n> = {\n backoff: 'exponential',\n baseWait: 1000,\n maxWait: Infinity,\n enabled: true,\n jitter: 0,\n maxAttempts: 3,\n maxExecutionTime: Infinity,\n maxTotalExecutionTime: Infinity,\n throwOnError: 'last',\n}\n\n/**\n * Provides robust retry functionality for asynchronous functions, supporting configurable backoff strategies,\n * attempt limits, timeout controls, and detailed state management. The AsyncRetryer class is designed to help you reliably\n * execute async operations that may fail intermittently, such as network requests or database operations,\n * by automatically retrying them according to your chosen policy.\n *\n * ## Retrying Concepts\n *\n * - **Retrying**: Automatically re-executes a failed async function up to a specified number of attempts.\n * Useful for handling transient errors (e.g., network flakiness, rate limits, temporary server issues).\n * - **Backoff Strategies**: Controls the delay between retry attempts (default: `'exponential'`):\n * - `'exponential'`: Wait time doubles with each attempt (1s, 2s, 4s, ...) - **DEFAULT**\n * - `'linear'`: Wait time increases linearly (1s, 2s, 3s, ...)\n * - `'fixed'`: Waits a constant amount of time (`baseWait`) between each attempt\n * - **Jitter**: Adds randomness to retry delays to prevent thundering herd problems (default: `0`).\n * Set to a value between 0-1 to apply that percentage of random variation to each delay.\n * - **Max Wait**: Caps the maximum wait time between retries (default: `Infinity`).\n * Useful for preventing exponential backoff from growing too large (e.g., cap at 30s even if exponential would be 64s).\n * - **Timeout Controls**: Set limits on execution time to prevent hanging operations:\n * - `maxExecutionTime`: Maximum time for a single function call (default: `Infinity`)\n * - `maxTotalExecutionTime`: Maximum time for the entire retry operation (default: `Infinity`)\n * - **Abort & Cancellation**: Supports cancellation via an internal `AbortController`. Call `abort()` to stop retries.\n * Use `getAbortSignal()` to make your async function actually cancellable (e.g., with fetch requests).\n *\n * ## State Management\n *\n * Uses TanStack Store for fine-grained reactivity. State can be accessed via the `store.state` property.\n *\n * Available state properties:\n * - `currentAttempt`: The current retry attempt number (0 when not executing)\n * - `executionCount`: Total number of completed executions (successful or failed)\n * - `isExecuting`: Whether the retryer is currently executing the function\n * - `lastError`: The most recent error encountered during execution\n * - `lastExecutionTime`: Timestamp of the last execution completion in milliseconds\n * - `lastResult`: The result from the most recent successful execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'executing' | 'retrying')\n * - `totalExecutionTime`: Total time spent executing (including retries) in milliseconds\n *\n * ## Error Handling\n *\n * The `throwOnError` option controls when errors are thrown (default: `'last'`):\n * - `'last'`: Only throws the final error after all retries are exhausted - **DEFAULT**\n * - `true`: Throws every error immediately (disables retrying)\n * - `false`: Never throws errors, returns `undefined` instead\n *\n * Callbacks for lifecycle management:\n * - `onAbort`: Called when execution is aborted (manually or due to timeouts)\n * - `onError`: Called for every error (including during retries)\n * - `onLastError`: Called only for the final error after all retries fail\n * - `onRetry`: Called before each retry attempt\n * - `onSettled`: Called after execution completes (success or failure) of each attempt\n * - `onSuccess`: Called when execution succeeds\n * - `onExecutionTimeout`: Called when a single execution attempt times out\n * - `onTotalExecutionTimeout`: Called when the total execution time times out\n *\n * ## Usage\n *\n * - Use for async operations that may fail transiently and benefit from retrying.\n * - Configure `maxAttempts`, `backoff`, `baseWait`, `maxWait`, and `jitter` to control retry behavior.\n * - Set `maxExecutionTime` and `maxTotalExecutionTime` to prevent hanging operations.\n * - Use `onAbort`, `onError`, `onLastError`, `onRetry`, `onSettled`, `onSuccess`, `onExecutionTimeout`, and `onTotalExecutionTimeout` for custom side effects.\n * - Call `abort()` to cancel ongoing execution and pending retries.\n * - Call `reset()` to reset state and cancel execution.\n * - Use `getAbortSignal()` to make your async function cancellable.\n * - Use dynamic options (functions) for `maxAttempts`, `baseWait`, and `enabled` based on retryer state.\n *\n * **Important:** This class is designed for single-use execution. Calling `execute()` multiple times\n * on the same instance will abort previous executions. For multiple calls, create a new instance\n * each time.\n *\n * @example\n * ```typescript\n * // Retry a fetch operation up to 5 times with exponential backoff, jitter, and timeouts\n * const retryer = new AsyncRetryer(async (url: string) => {\n * const signal = retryer.getAbortSignal()\n * return await fetch(url, { signal })\n * }, {\n * maxAttempts: 5,\n * backoff: 'exponential',\n * baseWait: 1000,\n * jitter: 0.1, // Add 10% random variation to prevent thundering herd\n * maxExecutionTime: 5000, // Abort individual calls after 5 seconds\n * maxTotalExecutionTime: 30000, // Abort entire operation after 30 seconds\n * onRetry: (attempt, error) => console.log(`Retry attempt ${attempt} after error:`, error),\n * onSuccess: (result) => console.log('Success:', result),\n * onError: (error) => console.error('Error:', error),\n * onLastError: (error) => console.error('All retries failed:', error),\n * })\n *\n * const result = await retryer.execute('/api/data')\n * ```\n *\n * @template TFn The async function type to be retried.\n */\nexport class AsyncRetryer<TFn extends AnyAsyncFunction> {\n readonly store: Store<Readonly<AsyncRetryerState<TFn>>> = new Store(\n getDefaultAsyncRetryerState<TFn>(),\n )\n key: string | undefined\n options: AsyncRetryerOptions<TFn> & typeof defaultOptions\n #abortController: AbortController | null = null\n\n /**\n * Creates a new AsyncRetryer instance\n * @param fn The async function to retry\n * @param initialOptions Configuration options for the retryer\n */\n constructor(\n public fn: TFn,\n initialOptions: AsyncRetryerOptions<TFn> = {},\n ) {\n this.key = initialOptions.key\n this.options = {\n ...defaultOptions,\n ...initialOptions,\n throwOnError:\n initialOptions.throwOnError ??\n (initialOptions.onError ? false : defaultOptions.throwOnError),\n }\n this.#setState(this.options.initialState ?? {})\n }\n\n /**\n * Updates the retryer options\n * @param newOptions Partial options to merge with existing options\n */\n setOptions = (newOptions: Partial<AsyncRetryerOptions<TFn>>): void => {\n this.options = { ...this.options, ...newOptions }\n }\n\n #setState = (newState: Partial<AsyncRetryerState<TFn>>): void => {\n this.store.setState((state) => {\n const combinedState = {\n ...state,\n ...newState,\n }\n const { isExecuting, currentAttempt } = combinedState\n return {\n ...combinedState,\n status: !this.#getEnabled()\n ? 'disabled'\n : isExecuting && currentAttempt === 1\n ? 'executing'\n : isExecuting && currentAttempt > 1\n ? 'retrying'\n : 'idle',\n }\n })\n }\n\n #getEnabled = (): boolean => {\n return !!parseFunctionOrValue(this.options.enabled, this)\n }\n\n #getMaxAttempts = (): number => {\n return parseFunctionOrValue(this.options.maxAttempts, this)\n }\n\n #getBaseWait = (): number => {\n return parseFunctionOrValue(this.options.baseWait, this)\n }\n\n #getMaxWait = (): number => {\n return parseFunctionOrValue(this.options.maxWait, this)\n }\n\n #calculateJitter = (waitTime: number): number => {\n const jitterAmount = this.options.jitter\n if (jitterAmount <= 0) return 0\n\n try {\n const crypto =\n typeof globalThis !== 'undefined' ? globalThis.crypto : undefined\n if (crypto?.getRandomValues) {\n const array = new Uint32Array(1)\n crypto.getRandomValues(array)\n // Convert to 0-1 range and apply jitter percentage\n const randomFactor = (array[0]! / 0xffffffff) * 2 - 1 // -1 to 1\n return Math.floor(waitTime * jitterAmount * randomFactor)\n }\n } catch {\n // No crypto available\n }\n return 0\n }\n\n #calculateWait = (attempt: number): number => {\n const baseWait = this.#getBaseWait()\n let waitTime: number\n\n switch (this.options.backoff) {\n case 'linear':\n waitTime = baseWait * attempt\n break\n case 'exponential':\n waitTime = baseWait * Math.pow(2, attempt - 1)\n break\n case 'fixed':\n default:\n waitTime = baseWait\n break\n }\n\n waitTime = Math.min(waitTime, this.#getMaxWait())\n\n const jitter = this.#calculateJitter(waitTime)\n return Math.max(0, waitTime + jitter)\n }\n\n /**\n * Executes the function with retry logic\n * @param args Arguments to pass to the function\n * @returns The function result, or undefined if disabled or all retries failed (when throwOnError is false)\n * @throws The last error if throwOnError is true and all retries fail\n */\n execute = async (\n ...args: Parameters<TFn>\n ): Promise<Awaited<ReturnType<TFn>> | undefined> => {\n if (!this.#getEnabled()) {\n return undefined\n }\n\n // Cancel any existing execution\n this.abort('new-execution')\n\n const startTime = Date.now()\n let lastError: Error | undefined\n let result: Awaited<ReturnType<TFn>> | undefined\n\n this.#abortController = new AbortController()\n const signal = this.#abortController.signal\n\n this.#setState({\n isExecuting: true,\n currentAttempt: 0,\n lastError: undefined,\n })\n\n // Set up total execution timeout\n let totalTimeoutId: ReturnType<typeof setTimeout> | undefined\n if (this.options.maxTotalExecutionTime !== Infinity) {\n totalTimeoutId = setTimeout(() => {\n this.options.onTotalExecutionTimeout?.(this)\n this.abort('total-timeout')\n }, this.options.maxTotalExecutionTime)\n }\n\n let isLastAttempt = false\n for (let attempt = 1; attempt <= this.#getMaxAttempts(); attempt++) {\n isLastAttempt = attempt === this.#getMaxAttempts()\n this.#setState({ currentAttempt: attempt })\n\n try {\n if (signal.aborted) {\n return undefined\n }\n\n // Check if total execution time has been exceeded\n const currentTotalTime = Date.now() - startTime\n if (\n this.options.maxTotalExecutionTime !== Infinity &&\n currentTotalTime >= this.options.maxTotalExecutionTime\n ) {\n this.options.onTotalExecutionTimeout?.(this)\n this.abort('total-timeout')\n return undefined\n }\n\n // Execute with individual timeout if specified\n if (this.options.maxExecutionTime === Infinity) {\n result = (await this.fn(...args)) as Awaited<ReturnType<TFn>>\n } else {\n result = (await Promise.race([\n this.fn(...args),\n new Promise<never>((_, reject) => {\n const timeout = setTimeout(() => {\n this.options.onExecutionTimeout?.(this)\n this.abort('execution-timeout')\n reject(\n new Error(\n `Execution timeout: ${this.options.maxExecutionTime}ms exceeded`,\n ),\n )\n }, this.options.maxExecutionTime)\n\n signal.addEventListener(\n 'abort',\n () => {\n clearTimeout(timeout)\n reject(new Error('Aborted'))\n },\n { once: true },\n )\n }),\n ])) as Awaited<ReturnType<TFn>>\n }\n\n // Check if cancelled during execution\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (signal.aborted) {\n return undefined\n }\n\n const totalTime = Date.now() - startTime\n this.#setState({\n executionCount: this.store.state.executionCount + 1,\n isExecuting: false,\n lastExecutionTime: Date.now(),\n totalExecutionTime: totalTime,\n currentAttempt: 0,\n lastResult: result,\n })\n\n this.options.onSuccess?.(result as Awaited<ReturnType<TFn>>, args, this)\n\n return result\n } catch (error) {\n // Treat abort as a non-error cancellation outcome\n if (\n error &&\n typeof error === 'object' &&\n 'name' in error &&\n (error as Error).name === 'AbortError'\n ) {\n return undefined\n }\n lastError = error instanceof Error ? error : new Error(String(error))\n this.#setState({ lastError })\n\n // Call onError for every error (including during retries)\n this.options.onError?.(lastError, args, this)\n\n if (attempt < this.#getMaxAttempts()) {\n this.options.onRetry?.(attempt, lastError, this)\n\n const wait = this.#calculateWait(attempt)\n if (wait > 0) {\n // Eagerly reflect retrying status during the wait window\n this.#setState({ isExecuting: true, currentAttempt: attempt + 1 })\n await new Promise<void>((resolve) => {\n const timeout = setTimeout(() => {\n signal.removeEventListener('abort', onAbort)\n resolve()\n }, wait)\n const onAbort = () => {\n clearTimeout(timeout)\n signal.removeEventListener('abort', onAbort)\n resolve()\n }\n signal.addEventListener('abort', onAbort)\n })\n if (signal.aborted) {\n return undefined\n }\n }\n }\n } finally {\n this.options.onSettled?.(args, this)\n }\n }\n\n // Clean up total timeout\n if (totalTimeoutId) {\n clearTimeout(totalTimeoutId)\n }\n\n // Exhausted retries - finalize state\n this.#setState({ isExecuting: false })\n this.options.onLastError?.(lastError as Error, this)\n this.options.onSettled?.(args, this)\n\n if (\n (this.options.throwOnError === 'last' && isLastAttempt) ||\n this.options.throwOnError === true\n ) {\n throw lastError\n }\n\n return undefined\n }\n\n /**\n * Returns the current AbortSignal for the executing operation.\n * Use this signal in your async function to make it cancellable.\n * Returns null when not currently executing.\n *\n * @example\n * ```typescript\n * const retryer = new AsyncRetryer(async (userId: string) => {\n * const signal = retryer.getAbortSignal()\n * if (signal) {\n * return fetch(`/api/users/${userId}`, { signal })\n * }\n * return fetch(`/api/users/${userId}`)\n * })\n *\n * // Abort will now actually cancel the fetch\n * retryer.abort()\n * ```\n */\n getAbortSignal = (): AbortSignal | null => {\n return this.#abortController?.signal ?? null\n }\n\n /**\n * Cancels the current execution and any pending retries\n * @param reason The reason for the abort (defaults to 'manual')\n */\n abort = (\n reason:\n | 'manual'\n | 'execution-timeout'\n | 'total-timeout'\n | 'new-execution' = 'manual',\n ): void => {\n if (this.#abortController) {\n this.#abortController.abort()\n this.#abortController = null\n this.#setState({\n isExecuting: false,\n })\n this.options.onAbort?.(reason, this)\n }\n }\n\n /**\n * Resets the retryer to its initial state\n */\n reset = (): void => {\n this.#setState(getDefaultAsyncRetryerState<TFn>())\n }\n}\n\n/**\n * Creates a retry-enabled version of an async function. This is a convenience wrapper\n * around the AsyncRetryer class that returns the execute method.\n *\n * @param fn The async function to add retry functionality to\n * @param initialOptions Configuration options for the retry behavior\n * @returns A new function that executes the original with retry logic\n *\n * @example\n * ```typescript\n * // Define your async function normally\n * async function fetchData(url: string) {\n * const response = await fetch(url)\n * if (!response.ok) throw new Error('Request failed')\n * return response.json()\n * }\n *\n * // Create retry-enabled function\n * const fetchWithRetry = asyncRetry(fetchData, {\n * maxAttempts: 3,\n * backoff: 'exponential',\n * baseWait: 1000,\n * jitter: 0.1\n * })\n *\n * // Call it multiple times\n * const data1 = await fetchWithRetry('/api/data1')\n * const data2 = await fetchWithRetry('/api/data2')\n * ```\n */\nexport function asyncRetry<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncRetryerOptions<TFn> = {},\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const retryer = new AsyncRetryer(fn, initialOptions)\n return retryer.execute\n}\n"],"mappings":";;;;;;;;AA2CA,SAAS,8BAEmB;CAC1B,OAAO;EACL,gBAAgB;EAChB,gBAAgB;EAChB,aAAa;EACb,WAAW;EACX,mBAAmB;EACnB,YAAY;EACZ,QAAQ;EACR,oBAAoB;CACtB;AACF;;;;AAkHA,SAAgB,oBAKd,SAA6B;CAC7B,OAAO;AACT;AAEA,MAAM,iBAYF;CACF,SAAS;CACT,UAAU;CACV,SAAS;CACT,SAA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