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