@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/pacer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Utilities for debouncing, throttling, rate-limiting, queuing, and more.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,79 +23,31 @@
|
|
|
23
23
|
"pacer"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
26
|
-
"
|
|
27
|
-
"module": "./dist/index.js",
|
|
28
|
-
"types": "./dist/index.d.cts",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
29
27
|
"exports": {
|
|
30
|
-
".":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"./async-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"./
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"./
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
"./async-rate-limiter": {
|
|
47
|
-
"import": "./dist/async-rate-limiter.js",
|
|
48
|
-
"require": "./dist/async-rate-limiter.cjs"
|
|
49
|
-
},
|
|
50
|
-
"./async-retryer": {
|
|
51
|
-
"import": "./dist/async-retryer.js",
|
|
52
|
-
"require": "./dist/async-retryer.cjs"
|
|
53
|
-
},
|
|
54
|
-
"./async-throttler": {
|
|
55
|
-
"import": "./dist/async-throttler.js",
|
|
56
|
-
"require": "./dist/async-throttler.cjs"
|
|
57
|
-
},
|
|
58
|
-
"./batcher": {
|
|
59
|
-
"import": "./dist/batcher.js",
|
|
60
|
-
"require": "./dist/batcher.cjs"
|
|
61
|
-
},
|
|
62
|
-
"./debouncer": {
|
|
63
|
-
"import": "./dist/debouncer.js",
|
|
64
|
-
"require": "./dist/debouncer.cjs"
|
|
65
|
-
},
|
|
66
|
-
"./event-client": {
|
|
67
|
-
"import": "./dist/event-client.js",
|
|
68
|
-
"require": "./dist/event-client.cjs"
|
|
69
|
-
},
|
|
70
|
-
"./queuer": {
|
|
71
|
-
"import": "./dist/queuer.js",
|
|
72
|
-
"require": "./dist/queuer.cjs"
|
|
73
|
-
},
|
|
74
|
-
"./rate-limiter": {
|
|
75
|
-
"import": "./dist/rate-limiter.js",
|
|
76
|
-
"require": "./dist/rate-limiter.cjs"
|
|
77
|
-
},
|
|
78
|
-
"./throttler": {
|
|
79
|
-
"import": "./dist/throttler.js",
|
|
80
|
-
"require": "./dist/throttler.cjs"
|
|
81
|
-
},
|
|
82
|
-
"./types": {
|
|
83
|
-
"import": "./dist/types.js",
|
|
84
|
-
"require": "./dist/types.cjs"
|
|
85
|
-
},
|
|
86
|
-
"./utils": {
|
|
87
|
-
"import": "./dist/utils.js",
|
|
88
|
-
"require": "./dist/utils.cjs"
|
|
89
|
-
},
|
|
28
|
+
".": "./dist/index.js",
|
|
29
|
+
"./async-batcher": "./dist/async-batcher.js",
|
|
30
|
+
"./async-debouncer": "./dist/async-debouncer.js",
|
|
31
|
+
"./async-queuer": "./dist/async-queuer.js",
|
|
32
|
+
"./async-rate-limiter": "./dist/async-rate-limiter.js",
|
|
33
|
+
"./async-retryer": "./dist/async-retryer.js",
|
|
34
|
+
"./async-throttler": "./dist/async-throttler.js",
|
|
35
|
+
"./batcher": "./dist/batcher.js",
|
|
36
|
+
"./debouncer": "./dist/debouncer.js",
|
|
37
|
+
"./event-client": "./dist/event-client.js",
|
|
38
|
+
"./queuer": "./dist/queuer.js",
|
|
39
|
+
"./rate-limiter": "./dist/rate-limiter.js",
|
|
40
|
+
"./throttler": "./dist/throttler.js",
|
|
41
|
+
"./types": "./dist/types.js",
|
|
42
|
+
"./utils": "./dist/utils.js",
|
|
90
43
|
"./package.json": "./package.json"
|
|
91
44
|
},
|
|
92
45
|
"sideEffects": false,
|
|
93
46
|
"engines": {
|
|
94
|
-
"node": ">=
|
|
47
|
+
"node": ">=20"
|
|
95
48
|
},
|
|
96
49
|
"files": [
|
|
97
|
-
"dist
|
|
98
|
-
"src"
|
|
50
|
+
"dist"
|
|
99
51
|
],
|
|
100
52
|
"dependencies": {
|
|
101
53
|
"@tanstack/devtools-event-client": "^0.5.0",
|
|
@@ -108,6 +60,7 @@
|
|
|
108
60
|
"test:lib": "vitest",
|
|
109
61
|
"test:lib:dev": "pnpm test:lib --watch",
|
|
110
62
|
"test:types": "tsc",
|
|
111
|
-
"build": "tsdown"
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"test:build": "publint --strict && node ../../scripts/verify-package.ts"
|
|
112
65
|
}
|
|
113
66
|
}
|
package/dist/async-batcher.cjs
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_utils = require('./utils.cjs');
|
|
3
|
-
const require_async_retryer = require('./async-retryer.cjs');
|
|
4
|
-
const require_event_client = require('./event-client.cjs');
|
|
5
|
-
let _tanstack_store = require("@tanstack/store");
|
|
6
|
-
|
|
7
|
-
//#region src/async-batcher.ts
|
|
8
|
-
function getDefaultAsyncBatcherState() {
|
|
9
|
-
return {
|
|
10
|
-
errorCount: 0,
|
|
11
|
-
executeCount: 0,
|
|
12
|
-
failedItems: [],
|
|
13
|
-
isEmpty: true,
|
|
14
|
-
isExecuting: false,
|
|
15
|
-
isPending: false,
|
|
16
|
-
items: [],
|
|
17
|
-
lastResult: void 0,
|
|
18
|
-
settleCount: 0,
|
|
19
|
-
size: 0,
|
|
20
|
-
status: "idle",
|
|
21
|
-
successCount: 0,
|
|
22
|
-
totalItemsProcessed: 0,
|
|
23
|
-
totalItemsFailed: 0
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Utility function for sharing common `AsyncBatcherOptions` options between different `AsyncBatcher` instances.
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
function asyncBatcherOptions(options) {
|
|
31
|
-
return options;
|
|
32
|
-
}
|
|
33
|
-
const defaultOptions = {
|
|
34
|
-
asyncRetryerOptions: { maxAttempts: 1 },
|
|
35
|
-
getShouldExecute: () => false,
|
|
36
|
-
maxSize: Infinity,
|
|
37
|
-
started: true,
|
|
38
|
-
throwOnError: true,
|
|
39
|
-
wait: Infinity
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A class that collects items and processes them in batches asynchronously.
|
|
43
|
-
*
|
|
44
|
-
* Async vs Sync Versions:
|
|
45
|
-
* The async version provides advanced features over the sync Batcher:
|
|
46
|
-
* - Returns promises that can be awaited for batch results
|
|
47
|
-
* - Built-in retry support via AsyncRetryer integration
|
|
48
|
-
* - Abort support to cancel in-flight batch executions
|
|
49
|
-
* - Cancel support to prevent pending batches from starting
|
|
50
|
-
* - Comprehensive error handling with onError callbacks and throwOnError control
|
|
51
|
-
* - Detailed execution tracking (success/error/settle counts)
|
|
52
|
-
*
|
|
53
|
-
* The sync Batcher is lighter weight and simpler when you don't need async features,
|
|
54
|
-
* return values, or execution control.
|
|
55
|
-
*
|
|
56
|
-
* What is Batching?
|
|
57
|
-
* Batching is a technique for grouping multiple operations together to be processed as a single unit.
|
|
58
|
-
*
|
|
59
|
-
* The AsyncBatcher provides a flexible way to implement async batching with configurable:
|
|
60
|
-
* - Maximum batch size (number of items per batch)
|
|
61
|
-
* - Time-based batching (process after X milliseconds)
|
|
62
|
-
* - Custom batch processing logic via getShouldExecute
|
|
63
|
-
* - Event callbacks for monitoring batch operations
|
|
64
|
-
* - Error handling for failed batch operations
|
|
65
|
-
*
|
|
66
|
-
* Error Handling:
|
|
67
|
-
* - If an `onError` handler is provided, it will be called with the error, the batch of items that failed, and batcher instance
|
|
68
|
-
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
69
|
-
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
70
|
-
* - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
|
|
71
|
-
* - The error state can be checked using the AsyncBatcher instance
|
|
72
|
-
*
|
|
73
|
-
* State Management:
|
|
74
|
-
* - Uses TanStack Store for reactive state management
|
|
75
|
-
* - Use `initialState` to provide initial state values when creating the async batcher
|
|
76
|
-
* - Use `onSuccess` callback to react to successful batch execution and implement custom logic
|
|
77
|
-
* - Use `onError` callback to react to batch execution errors and implement custom error handling
|
|
78
|
-
* - Use `onSettled` callback to react to batch execution completion (success or error) and implement custom logic
|
|
79
|
-
* - Use `onExecute` callback to react to batch execution and implement custom logic
|
|
80
|
-
* - Use `onItemsChange` callback to react to items being added or removed from the batcher
|
|
81
|
-
* - The state includes total items processed, success/error counts, and execution status
|
|
82
|
-
* - State can be accessed via `asyncBatcher.store.state` when using the class directly
|
|
83
|
-
* - When using framework adapters (React/Solid), state is accessed from `asyncBatcher.state`
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const batcher = new AsyncBatcher<number>(
|
|
88
|
-
* async (items) => {
|
|
89
|
-
* const result = await processItems(items);
|
|
90
|
-
* console.log('Processing batch:', items);
|
|
91
|
-
* return result;
|
|
92
|
-
* },
|
|
93
|
-
* {
|
|
94
|
-
* maxSize: 5,
|
|
95
|
-
* wait: 2000,
|
|
96
|
-
* onSuccess: (result) => console.log('Batch succeeded:', result),
|
|
97
|
-
* onError: (error) => console.error('Batch failed:', error)
|
|
98
|
-
* }
|
|
99
|
-
* );
|
|
100
|
-
*
|
|
101
|
-
* batcher.addItem(1);
|
|
102
|
-
* batcher.addItem(2);
|
|
103
|
-
* // After 2 seconds or when 5 items are added, whichever comes first,
|
|
104
|
-
* // the batch will be processed and the result will be available
|
|
105
|
-
* // batcher.execute() // manually trigger a batch
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
var AsyncBatcher = class {
|
|
109
|
-
#timeoutId;
|
|
110
|
-
constructor(fn, initialOptions) {
|
|
111
|
-
this.fn = fn;
|
|
112
|
-
this.store = new _tanstack_store.Store(getDefaultAsyncBatcherState());
|
|
113
|
-
this.asyncRetryers = /* @__PURE__ */ new Map();
|
|
114
|
-
this.#timeoutId = null;
|
|
115
|
-
this.setOptions = (newOptions) => {
|
|
116
|
-
this.options = {
|
|
117
|
-
...this.options,
|
|
118
|
-
...newOptions
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
this.#setState = (newState) => {
|
|
122
|
-
this.store.setState((state) => {
|
|
123
|
-
const combinedState = {
|
|
124
|
-
...state,
|
|
125
|
-
...newState
|
|
126
|
-
};
|
|
127
|
-
const { isExecuting, isPending, items } = combinedState;
|
|
128
|
-
const size = items.length;
|
|
129
|
-
const isEmpty = size === 0;
|
|
130
|
-
return {
|
|
131
|
-
...combinedState,
|
|
132
|
-
isEmpty,
|
|
133
|
-
size,
|
|
134
|
-
status: isExecuting ? "executing" : isPending ? "pending" : isEmpty ? "idle" : "populated"
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
require_event_client.emitChange("AsyncBatcher", this);
|
|
138
|
-
};
|
|
139
|
-
this.#getWait = () => {
|
|
140
|
-
return require_utils.parseFunctionOrValue(this.options.wait, this);
|
|
141
|
-
};
|
|
142
|
-
this.addItem = async (item) => {
|
|
143
|
-
this.#setState({
|
|
144
|
-
items: [...this.store.state.items, item],
|
|
145
|
-
isPending: this.options.wait !== Infinity
|
|
146
|
-
});
|
|
147
|
-
this.options.onItemsChange?.(this);
|
|
148
|
-
if (this.store.state.items.length >= this.options.maxSize || this.options.getShouldExecute(this.store.state.items, this)) return await this.#execute();
|
|
149
|
-
else if (this.options.wait !== Infinity) {
|
|
150
|
-
this.#clearTimeout();
|
|
151
|
-
this.#timeoutId = setTimeout(() => this.#execute(), this.#getWait());
|
|
152
|
-
await new Promise((resolve) => setTimeout(resolve, this.#getWait()));
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
this.#execute = async () => {
|
|
156
|
-
if (this.store.state.items.length === 0) return;
|
|
157
|
-
const currentExecuteCount = this.store.state.executeCount + 1;
|
|
158
|
-
const batch = this.peekAllItems();
|
|
159
|
-
this.clear();
|
|
160
|
-
this.options.onItemsChange?.(this);
|
|
161
|
-
this.#setState({
|
|
162
|
-
isExecuting: true,
|
|
163
|
-
executeCount: currentExecuteCount
|
|
164
|
-
});
|
|
165
|
-
try {
|
|
166
|
-
const currentAsyncRetryer = new require_async_retryer.AsyncRetryer(this.fn, this.options.asyncRetryerOptions);
|
|
167
|
-
this.asyncRetryers.set(currentExecuteCount, currentAsyncRetryer);
|
|
168
|
-
const result = await currentAsyncRetryer.execute(batch);
|
|
169
|
-
this.#setState({
|
|
170
|
-
totalItemsProcessed: this.store.state.totalItemsProcessed + batch.length,
|
|
171
|
-
lastResult: result,
|
|
172
|
-
successCount: this.store.state.successCount + 1
|
|
173
|
-
});
|
|
174
|
-
this.options.onSuccess?.(result, batch, this);
|
|
175
|
-
return result;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
this.#setState({
|
|
178
|
-
errorCount: this.store.state.errorCount + 1,
|
|
179
|
-
failedItems: [...this.store.state.failedItems, ...batch],
|
|
180
|
-
totalItemsFailed: this.store.state.totalItemsFailed + batch.length
|
|
181
|
-
});
|
|
182
|
-
this.options.onError?.(error, batch, this);
|
|
183
|
-
if (this.options.throwOnError) throw error;
|
|
184
|
-
return;
|
|
185
|
-
} finally {
|
|
186
|
-
this.asyncRetryers.delete(currentExecuteCount);
|
|
187
|
-
this.#setState({
|
|
188
|
-
isExecuting: false,
|
|
189
|
-
settleCount: this.store.state.settleCount + 1
|
|
190
|
-
});
|
|
191
|
-
this.options.onSettled?.(batch, this);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
this.flush = async () => {
|
|
195
|
-
this.#clearTimeout();
|
|
196
|
-
return await this.#execute();
|
|
197
|
-
};
|
|
198
|
-
this.peekAllItems = () => {
|
|
199
|
-
return [...this.store.state.items];
|
|
200
|
-
};
|
|
201
|
-
this.peekFailedItems = () => {
|
|
202
|
-
return [...this.store.state.failedItems];
|
|
203
|
-
};
|
|
204
|
-
this.#clearTimeout = () => {
|
|
205
|
-
if (this.#timeoutId) {
|
|
206
|
-
clearTimeout(this.#timeoutId);
|
|
207
|
-
this.#timeoutId = null;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
this.clear = () => {
|
|
211
|
-
this.#setState({
|
|
212
|
-
items: [],
|
|
213
|
-
failedItems: [],
|
|
214
|
-
isPending: false
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
this.getAbortSignal = (executeCount) => {
|
|
218
|
-
const count = executeCount ?? this.store.state.executeCount;
|
|
219
|
-
return this.asyncRetryers.get(count)?.getAbortSignal() ?? null;
|
|
220
|
-
};
|
|
221
|
-
this.abort = () => {
|
|
222
|
-
this.asyncRetryers.forEach((retryer) => retryer.abort());
|
|
223
|
-
this.asyncRetryers.clear();
|
|
224
|
-
this.#setState({ isExecuting: false });
|
|
225
|
-
};
|
|
226
|
-
this.cancel = () => {
|
|
227
|
-
this.#clearTimeout();
|
|
228
|
-
this.#setState({ isPending: false });
|
|
229
|
-
};
|
|
230
|
-
this.reset = () => {
|
|
231
|
-
this.#setState(getDefaultAsyncBatcherState());
|
|
232
|
-
this.options.onItemsChange?.(this);
|
|
233
|
-
this.asyncRetryers.forEach((retryer) => retryer.reset());
|
|
234
|
-
};
|
|
235
|
-
this.key = initialOptions.key;
|
|
236
|
-
this.options = {
|
|
237
|
-
...defaultOptions,
|
|
238
|
-
...initialOptions,
|
|
239
|
-
throwOnError: initialOptions.throwOnError ?? !initialOptions.onError
|
|
240
|
-
};
|
|
241
|
-
this.#setState(this.options.initialState ?? {});
|
|
242
|
-
if (this.key) require_event_client.pacerEventClient.on("d-AsyncBatcher", (event) => {
|
|
243
|
-
if (event.payload.key !== this.key) return;
|
|
244
|
-
this.#setState(event.payload.store.state);
|
|
245
|
-
this.setOptions(event.payload.options);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
#setState;
|
|
249
|
-
#getWait;
|
|
250
|
-
/**
|
|
251
|
-
* Processes the current batch of items asynchronously.
|
|
252
|
-
* This method will automatically be triggered if the batcher is running and any of these conditions are met:
|
|
253
|
-
* - The number of items reaches maxSize
|
|
254
|
-
* - The wait duration has elapsed
|
|
255
|
-
* - The getShouldExecute function returns true upon adding an item
|
|
256
|
-
*
|
|
257
|
-
* You can also call this method manually to process the current batch at any time.
|
|
258
|
-
*
|
|
259
|
-
* @returns A promise that resolves with the result of the batch function, or undefined if an error occurred and was handled by onError
|
|
260
|
-
* @throws The error from the batch function if no onError handler is configured or throwOnError is true
|
|
261
|
-
*/
|
|
262
|
-
#execute;
|
|
263
|
-
#clearTimeout;
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* Creates an async batcher that processes items in batches.
|
|
267
|
-
*
|
|
268
|
-
* Async vs Sync Versions:
|
|
269
|
-
* The async version provides advanced features over the sync batch function:
|
|
270
|
-
* - Returns promises that can be awaited for batch results
|
|
271
|
-
* - Built-in retry support via AsyncRetryer integration
|
|
272
|
-
* - Abort support to cancel in-flight batch executions
|
|
273
|
-
* - Cancel support to prevent pending batches from starting
|
|
274
|
-
* - Comprehensive error handling with onError callbacks and throwOnError control
|
|
275
|
-
* - Detailed execution tracking (success/error/settle counts)
|
|
276
|
-
*
|
|
277
|
-
* The sync batch function is lighter weight and simpler when you don't need async features,
|
|
278
|
-
* return values, or execution control.
|
|
279
|
-
*
|
|
280
|
-
* What is Batching?
|
|
281
|
-
* Batching is a technique for grouping multiple operations together to be processed as a single unit.
|
|
282
|
-
*
|
|
283
|
-
* Configuration Options:
|
|
284
|
-
* - `maxSize`: Maximum number of items per batch (default: Infinity)
|
|
285
|
-
* - `wait`: Time to wait before processing batch (default: Infinity)
|
|
286
|
-
* - `getShouldExecute`: Custom logic to trigger batch processing
|
|
287
|
-
* - `asyncRetryerOptions`: Configure retry behavior for batch executions
|
|
288
|
-
* - `started`: Whether to start processing immediately (default: true)
|
|
289
|
-
*
|
|
290
|
-
* Error Handling:
|
|
291
|
-
* - If an `onError` handler is provided, it will be called with the error, the batch of items that failed, and batcher instance
|
|
292
|
-
* - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
|
|
293
|
-
* - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
|
|
294
|
-
* - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
|
|
295
|
-
* - The error state can be checked using the underlying AsyncBatcher instance
|
|
296
|
-
*
|
|
297
|
-
* State Management:
|
|
298
|
-
* - Uses TanStack Store for reactive state management
|
|
299
|
-
* - Use `initialState` to provide initial state values when creating the async batcher
|
|
300
|
-
* - Use `onSuccess` callback to react to successful batch execution and implement custom logic
|
|
301
|
-
* - Use `onError` callback to react to batch execution errors and implement custom error handling
|
|
302
|
-
* - Use `onSettled` callback to react to batch execution completion (success or error) and implement custom logic
|
|
303
|
-
* - Use `onItemsChange` callback to react to items being added or removed from the batcher
|
|
304
|
-
* - The state includes total items processed, success/error counts, and execution status
|
|
305
|
-
* - State can be accessed via the underlying AsyncBatcher instance's `store.state` property
|
|
306
|
-
* - When using framework adapters (React/Solid), state is accessed from the hook's state property
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```ts
|
|
310
|
-
* const batchItems = asyncBatch<number>(
|
|
311
|
-
* async (items) => {
|
|
312
|
-
* const result = await processApiCall(items);
|
|
313
|
-
* console.log('Processing:', items);
|
|
314
|
-
* return result;
|
|
315
|
-
* },
|
|
316
|
-
* {
|
|
317
|
-
* maxSize: 3,
|
|
318
|
-
* wait: 1000,
|
|
319
|
-
* onSuccess: (result) => console.log('Batch succeeded:', result),
|
|
320
|
-
* onError: (error) => console.error('Batch failed:', error)
|
|
321
|
-
* }
|
|
322
|
-
* );
|
|
323
|
-
*
|
|
324
|
-
* batchItems(1);
|
|
325
|
-
* batchItems(2);
|
|
326
|
-
* batchItems(3); // Triggers batch processing
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
function asyncBatch(fn, options) {
|
|
330
|
-
return new AsyncBatcher(fn, options).addItem;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
//#endregion
|
|
334
|
-
exports.AsyncBatcher = AsyncBatcher;
|
|
335
|
-
exports.asyncBatch = asyncBatch;
|
|
336
|
-
exports.asyncBatcherOptions = asyncBatcherOptions;
|
|
337
|
-
//# sourceMappingURL=async-batcher.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-batcher.cjs","names":["Store","parseFunctionOrValue","#setState","#execute","#clearTimeout","#timeoutId","#getWait","AsyncRetryer"],"sources":["../src/async-batcher.ts"],"sourcesContent":["import { Store } from '@tanstack/store'\nimport { AsyncRetryer } from './async-retryer'\nimport { parseFunctionOrValue } from './utils'\nimport { emitChange, pacerEventClient } from './event-client'\nimport type { AsyncRetryerOptions } from './async-retryer'\nimport type { OptionalKeys } from './types'\n\nexport interface AsyncBatcherState<TValue> {\n /**\n * Number of batch executions that have resulted in errors\n */\n errorCount: number\n /**\n * Number of batch executions that have been executed\n */\n executeCount: number\n /**\n * Array of items that failed during batch processing\n */\n failedItems: Array<TValue>\n /**\n * Whether the batcher has no items to process (items array is empty)\n */\n isEmpty: boolean\n /**\n * Whether a batch is currently being processed asynchronously\n */\n isExecuting: boolean\n /**\n * Whether the batcher is waiting for the timeout to trigger batch processing\n */\n isPending: boolean\n /**\n * Array of items currently queued for batch processing\n */\n items: Array<TValue>\n /**\n * The result from the most recent batch execution\n */\n lastResult: any\n /**\n * Number of batch executions that have completed (either successfully or with errors)\n */\n settleCount: number\n /**\n * Number of items currently in the batch queue\n */\n size: number\n /**\n * Current processing status - 'idle' when not processing, 'pending' when waiting for timeout, 'executing' when processing, 'populated' when items are present, but no wait is configured\n */\n status: 'idle' | 'pending' | 'executing' | 'populated'\n /**\n * Number of batch executions that have completed successfully\n */\n successCount: number\n /**\n * Total number of items that have failed processing across all batches\n */\n totalItemsFailed: number\n /**\n * Total number of items that have been processed across all batches\n */\n totalItemsProcessed: number\n}\n\nfunction getDefaultAsyncBatcherState<TValue>(): AsyncBatcherState<TValue> {\n return {\n errorCount: 0,\n executeCount: 0,\n failedItems: [],\n isEmpty: true,\n isExecuting: false,\n isPending: false,\n items: [],\n lastResult: undefined,\n settleCount: 0,\n size: 0,\n status: 'idle',\n successCount: 0,\n totalItemsProcessed: 0,\n totalItemsFailed: 0,\n }\n}\n\n/**\n * Options for configuring an AsyncBatcher instance\n */\nexport interface AsyncBatcherOptions<TValue> {\n /**\n * Options for configuring the underlying async retryer\n */\n asyncRetryerOptions?: AsyncRetryerOptions<\n (items: Array<TValue>) => Promise<any>\n >\n /**\n * Custom function to determine if a batch should be processed\n * Return true to process the batch immediately\n */\n getShouldExecute?: (\n items: Array<TValue>,\n batcher: AsyncBatcher<TValue>,\n ) => boolean\n /**\n * Initial state for the async batcher\n */\n initialState?: Partial<AsyncBatcherState<TValue>>\n /**\n * Optional key to identify this async batcher instance.\n * If provided, the async batcher will be identified by this key in the devtools and PacerProvider if applicable.\n */\n key?: string\n /**\n * Maximum number of items in a batch\n * @default Infinity\n */\n maxSize?: number\n /**\n * Optional error handler for when the batch function throws.\n * If provided, the handler will be called with the error, the batch of items that failed, and batcher instance.\n * This can be used alongside throwOnError - the handler will be called before any error is thrown.\n */\n onError?: (\n error: Error,\n batch: Array<TValue>,\n batcher: AsyncBatcher<TValue>,\n ) => void\n /**\n * Callback fired after items are added to the batcher\n */\n onItemsChange?: (batcher: AsyncBatcher<TValue>) => void\n /**\n * Optional callback to call when a batch is settled (completed or failed)\n */\n onSettled?: (batch: Array<TValue>, batcher: AsyncBatcher<TValue>) => void\n /**\n * Optional callback to call when a batch succeeds\n */\n onSuccess?: (\n result: any,\n batch: Array<TValue>,\n batcher: AsyncBatcher<TValue>,\n ) => void\n /**\n * Whether the batcher should start processing immediately\n * @default true\n */\n started?: boolean\n /**\n * Whether to throw errors when they occur.\n * Defaults to true if no onError handler is provided, false if an onError handler is provided.\n * Can be explicitly set to override these defaults.\n */\n throwOnError?: boolean\n /**\n * Maximum time in milliseconds to wait before processing a batch.\n * If the wait duration has elapsed, the batch will be processed.\n * If not provided, the batch will not be triggered by a timeout.\n * @default Infinity\n */\n wait?: number | ((asyncBatcher: AsyncBatcher<TValue>) => number)\n}\n\n/**\n * Utility function for sharing common `AsyncBatcherOptions` options between different `AsyncBatcher` instances.\n *\n */\nexport function asyncBatcherOptions<\n TValue = any,\n TOptions extends Partial<AsyncBatcherOptions<TValue>> = Partial<\n AsyncBatcherOptions<TValue>\n >,\n>(options: TOptions): TOptions {\n return options\n}\n\ntype AsyncBatcherOptionsWithOptionalCallbacks<TValue> = OptionalKeys<\n Required<AsyncBatcherOptions<TValue>>,\n | 'initialState'\n | 'onError'\n | 'onItemsChange'\n | 'onSettled'\n | 'onSuccess'\n | 'key'\n>\n\nconst defaultOptions: AsyncBatcherOptionsWithOptionalCallbacks<any> = {\n asyncRetryerOptions: {\n maxAttempts: 1,\n },\n getShouldExecute: () => false,\n maxSize: Infinity,\n started: true,\n throwOnError: true,\n wait: Infinity,\n}\n\n/**\n * A class that collects items and processes them in batches asynchronously.\n *\n * Async vs Sync Versions:\n * The async version provides advanced features over the sync Batcher:\n * - Returns promises that can be awaited for batch results\n * - Built-in retry support via AsyncRetryer integration\n * - Abort support to cancel in-flight batch executions\n * - Cancel support to prevent pending batches from starting\n * - Comprehensive error handling with onError callbacks and throwOnError control\n * - Detailed execution tracking (success/error/settle counts)\n *\n * The sync Batcher is lighter weight and simpler when you don't need async features,\n * return values, or execution control.\n *\n * What is Batching?\n * Batching is a technique for grouping multiple operations together to be processed as a single unit.\n *\n * The AsyncBatcher provides a flexible way to implement async batching with configurable:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error, the batch of items that failed, and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the AsyncBatcher instance\n *\n * State Management:\n * - Uses TanStack Store for reactive state management\n * - Use `initialState` to provide initial state values when creating the async batcher\n * - Use `onSuccess` callback to react to successful batch execution and implement custom logic\n * - Use `onError` callback to react to batch execution errors and implement custom error handling\n * - Use `onSettled` callback to react to batch execution completion (success or error) and implement custom logic\n * - Use `onExecute` callback to react to batch execution and implement custom logic\n * - Use `onItemsChange` callback to react to items being added or removed from the batcher\n * - The state includes total items processed, success/error counts, and execution status\n * - State can be accessed via `asyncBatcher.store.state` when using the class directly\n * - When using framework adapters (React/Solid), state is accessed from `asyncBatcher.state`\n *\n * @example\n * ```ts\n * const batcher = new AsyncBatcher<number>(\n * async (items) => {\n * const result = await processItems(items);\n * console.log('Processing batch:', items);\n * return result;\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onSuccess: (result) => console.log('Batch succeeded:', result),\n * onError: (error) => console.error('Batch failed:', error)\n * }\n * );\n *\n * batcher.addItem(1);\n * batcher.addItem(2);\n * // After 2 seconds or when 5 items are added, whichever comes first,\n * // the batch will be processed and the result will be available\n * // batcher.execute() // manually trigger a batch\n * ```\n */\nexport class AsyncBatcher<TValue> {\n readonly store: Store<Readonly<AsyncBatcherState<TValue>>> = new Store(\n getDefaultAsyncBatcherState<TValue>(),\n )\n key: string | undefined\n options: AsyncBatcherOptionsWithOptionalCallbacks<TValue>\n asyncRetryers = new Map<\n number,\n AsyncRetryer<(items: Array<TValue>) => Promise<any>>\n >()\n #timeoutId: ReturnType<typeof setTimeout> | null = null\n\n constructor(\n public fn: (items: Array<TValue>) => Promise<any>,\n initialOptions: AsyncBatcherOptions<TValue>,\n ) {\n this.key = initialOptions.key\n this.options = {\n ...defaultOptions,\n ...initialOptions,\n throwOnError: initialOptions.throwOnError ?? !initialOptions.onError,\n }\n this.#setState(this.options.initialState ?? {})\n\n if (this.key) {\n pacerEventClient.on('d-AsyncBatcher', (event) => {\n if (event.payload.key !== this.key) return\n this.#setState(\n event.payload.store.state as Partial<AsyncBatcherState<TValue>>,\n )\n this.setOptions(\n event.payload.options as Partial<AsyncBatcherOptions<TValue>>,\n )\n })\n }\n }\n\n /**\n * Updates the async batcher options\n */\n setOptions = (newOptions: Partial<AsyncBatcherOptions<TValue>>): void => {\n this.options = { ...this.options, ...newOptions }\n }\n\n #setState = (newState: Partial<AsyncBatcherState<TValue>>): void => {\n this.store.setState((state) => {\n const combinedState = {\n ...state,\n ...newState,\n }\n const { isExecuting, isPending, items } = combinedState\n const size = items.length\n const isEmpty = size === 0\n return {\n ...combinedState,\n isEmpty,\n size,\n status: isExecuting\n ? 'executing'\n : isPending\n ? 'pending'\n : isEmpty\n ? 'idle'\n : 'populated',\n }\n })\n emitChange('AsyncBatcher', this)\n }\n\n #getWait = (): number => {\n return parseFunctionOrValue(this.options.wait, this)\n }\n\n /**\n * Adds an item to the async batcher\n * If the batch size is reached, timeout occurs, or shouldProcess returns true, the batch will be processed\n *\n * @returns The result from the batch function, or undefined if an error occurred and was handled by onError\n *\n * @throws The error from the batch function if no onError handler is configured or throwOnError is true\n */\n addItem = async (item: TValue): Promise<any> => {\n this.#setState({\n items: [...this.store.state.items, item],\n isPending: this.options.wait !== Infinity,\n })\n this.options.onItemsChange?.(this)\n\n const shouldProcess =\n this.store.state.items.length >= this.options.maxSize ||\n this.options.getShouldExecute(this.store.state.items, this)\n\n if (shouldProcess) {\n return await this.#execute()\n } else if (this.options.wait !== Infinity) {\n this.#clearTimeout() // clear any pending timeout to replace it with a new one\n this.#timeoutId = setTimeout(() => this.#execute(), this.#getWait())\n await new Promise((resolve) => setTimeout(resolve, this.#getWait()))\n }\n }\n\n /**\n * Processes the current batch of items asynchronously.\n * This method will automatically be triggered if the batcher is running and any of these conditions are met:\n * - The number of items reaches maxSize\n * - The wait duration has elapsed\n * - The getShouldExecute function returns true upon adding an item\n *\n * You can also call this method manually to process the current batch at any time.\n *\n * @returns A promise that resolves with the result of the batch function, or undefined if an error occurred and was handled by onError\n * @throws The error from the batch function if no onError handler is configured or throwOnError is true\n */\n #execute = async (): Promise<any> => {\n if (this.store.state.items.length === 0) {\n return undefined\n }\n\n const currentExecuteCount = this.store.state.executeCount + 1\n const batch = this.peekAllItems() // copy of the items to be processed (to prevent race conditions)\n this.clear() // Clear items before processing to prevent race conditions\n this.options.onItemsChange?.(this)\n\n this.#setState({ isExecuting: true, executeCount: currentExecuteCount })\n\n try {\n const currentAsyncRetryer = new AsyncRetryer(\n this.fn,\n this.options.asyncRetryerOptions,\n )\n this.asyncRetryers.set(currentExecuteCount, currentAsyncRetryer)\n const result = await currentAsyncRetryer.execute(batch) // EXECUTE\n this.#setState({\n totalItemsProcessed:\n this.store.state.totalItemsProcessed + batch.length,\n lastResult: result,\n successCount: this.store.state.successCount + 1,\n })\n this.options.onSuccess?.(result, batch, this)\n return result\n } catch (error) {\n this.#setState({\n errorCount: this.store.state.errorCount + 1,\n failedItems: [...this.store.state.failedItems, ...batch],\n totalItemsFailed: this.store.state.totalItemsFailed + batch.length,\n })\n this.options.onError?.(error as Error, batch, this)\n if (this.options.throwOnError) {\n throw error\n }\n return undefined\n } finally {\n this.asyncRetryers.delete(currentExecuteCount) // dispose retryer\n this.#setState({\n isExecuting: false,\n settleCount: this.store.state.settleCount + 1,\n })\n this.options.onSettled?.(batch, this)\n }\n }\n\n /**\n * Processes the current batch of items immediately\n */\n flush = async (): Promise<any> => {\n this.#clearTimeout() // clear any pending timeout\n return await this.#execute()\n }\n\n /**\n * Returns a copy of all items in the async batcher\n */\n peekAllItems = (): Array<TValue> => {\n return [...this.store.state.items]\n }\n\n peekFailedItems = (): Array<TValue> => {\n return [...this.store.state.failedItems]\n }\n\n #clearTimeout = (): void => {\n if (this.#timeoutId) {\n clearTimeout(this.#timeoutId)\n this.#timeoutId = null\n }\n }\n\n /**\n * Removes all items from the async batcher\n */\n clear = (): void => {\n this.#setState({ items: [], failedItems: [], isPending: false })\n }\n\n /**\n * Returns the AbortSignal for a specific execution.\n * If no executeCount is provided, returns the signal for the most recent execution.\n * Returns null if no execution is found or not currently executing.\n *\n * @param executeCount - Optional specific execution to get signal for\n * @example\n * ```typescript\n * const batcher = new AsyncBatcher(\n * async (items: string[]) => {\n * const signal = batcher.getAbortSignal()\n * if (signal) {\n * const response = await fetch('/api/batch', {\n * method: 'POST',\n * body: JSON.stringify(items),\n * signal\n * })\n * return response.json()\n * }\n * },\n * { maxSize: 10, wait: 100 }\n * )\n * ```\n */\n getAbortSignal = (executeCount?: number): AbortSignal | null => {\n const count = executeCount ?? this.store.state.executeCount\n const retryer = this.asyncRetryers.get(count)\n return retryer?.getAbortSignal() ?? null\n }\n\n /**\n * Aborts all ongoing executions with the internal abort controllers.\n * Does NOT cancel any pending execution that have not started yet.\n * Does NOT clear out the items.\n */\n abort = (): void => {\n this.asyncRetryers.forEach((retryer) => retryer.abort())\n this.asyncRetryers.clear()\n this.#setState({\n isExecuting: false,\n })\n }\n\n /**\n * Cancels any pending execution that have not started yet.\n * Does NOT abort any execution already in progress.\n * Does NOT clear out the items.\n */\n cancel = (): void => {\n this.#clearTimeout()\n this.#setState({\n isPending: false,\n })\n }\n\n /**\n * Resets the async batcher state to its default values\n */\n reset = (): void => {\n this.#setState(getDefaultAsyncBatcherState<TValue>())\n this.options.onItemsChange?.(this)\n this.asyncRetryers.forEach((retryer) => retryer.reset())\n }\n}\n\n/**\n * Creates an async batcher that processes items in batches.\n *\n * Async vs Sync Versions:\n * The async version provides advanced features over the sync batch function:\n * - Returns promises that can be awaited for batch results\n * - Built-in retry support via AsyncRetryer integration\n * - Abort support to cancel in-flight batch executions\n * - Cancel support to prevent pending batches from starting\n * - Comprehensive error handling with onError callbacks and throwOnError control\n * - Detailed execution tracking (success/error/settle counts)\n *\n * The sync batch function is lighter weight and simpler when you don't need async features,\n * return values, or execution control.\n *\n * What is Batching?\n * Batching is a technique for grouping multiple operations together to be processed as a single unit.\n *\n * Configuration Options:\n * - `maxSize`: Maximum number of items per batch (default: Infinity)\n * - `wait`: Time to wait before processing batch (default: Infinity)\n * - `getShouldExecute`: Custom logic to trigger batch processing\n * - `asyncRetryerOptions`: Configure retry behavior for batch executions\n * - `started`: Whether to start processing immediately (default: true)\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error, the batch of items that failed, and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * State Management:\n * - Uses TanStack Store for reactive state management\n * - Use `initialState` to provide initial state values when creating the async batcher\n * - Use `onSuccess` callback to react to successful batch execution and implement custom logic\n * - Use `onError` callback to react to batch execution errors and implement custom error handling\n * - Use `onSettled` callback to react to batch execution completion (success or error) and implement custom logic\n * - Use `onItemsChange` callback to react to items being added or removed from the batcher\n * - The state includes total items processed, success/error counts, and execution status\n * - State can be accessed via the underlying AsyncBatcher instance's `store.state` property\n * - When using framework adapters (React/Solid), state is accessed from the hook's state property\n *\n * @example\n * ```ts\n * const batchItems = asyncBatch<number>(\n * async (items) => {\n * const result = await processApiCall(items);\n * console.log('Processing:', items);\n * return result;\n * },\n * {\n * maxSize: 3,\n * wait: 1000,\n * onSuccess: (result) => console.log('Batch succeeded:', result),\n * onError: (error) => console.error('Batch failed:', error)\n * }\n * );\n *\n * batchItems(1);\n * batchItems(2);\n * batchItems(3); // Triggers batch processing\n * ```\n */\nexport function asyncBatch<TValue>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue>,\n) {\n const batcher = new AsyncBatcher<TValue>(fn, options)\n return batcher.addItem\n}\n"],"mappings":";;;;;;;AAkEA,SAAS,8BAAiE;CACxE,OAAO;EACL,YAAY;EACZ,cAAc;EACd,aAAa,CAAC;EACd,SAAS;EACT,aAAa;EACb,WAAW;EACX,OAAO,C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