@tanstack/pacer-lite 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/index.cjs +16 -0
  3. package/dist/index.d.cts +6 -0
  4. package/dist/index.d.ts +6 -0
  5. package/dist/{esm/index.js → index.js} +2 -13
  6. package/dist/lite-batcher.cjs +175 -0
  7. package/dist/lite-batcher.cjs.map +1 -0
  8. package/dist/{cjs/lite-batcher.d.cts → lite-batcher.d.cts} +89 -85
  9. package/dist/{esm/lite-batcher.d.ts → lite-batcher.d.ts} +89 -85
  10. package/dist/lite-batcher.js +173 -0
  11. package/dist/lite-batcher.js.map +1 -0
  12. package/dist/lite-debouncer.cjs +125 -0
  13. package/dist/lite-debouncer.cjs.map +1 -0
  14. package/dist/{cjs/lite-debouncer.d.cts → lite-debouncer.d.cts} +53 -47
  15. package/dist/{esm/lite-debouncer.d.ts → lite-debouncer.d.ts} +53 -47
  16. package/dist/lite-debouncer.js +123 -0
  17. package/dist/lite-debouncer.js.map +1 -0
  18. package/dist/lite-queuer.cjs +208 -0
  19. package/dist/lite-queuer.cjs.map +1 -0
  20. package/dist/lite-queuer.d.cts +243 -0
  21. package/dist/lite-queuer.d.ts +243 -0
  22. package/dist/lite-queuer.js +206 -0
  23. package/dist/lite-queuer.js.map +1 -0
  24. package/dist/lite-rate-limiter.cjs +149 -0
  25. package/dist/lite-rate-limiter.cjs.map +1 -0
  26. package/dist/{cjs/lite-rate-limiter.d.cts → lite-rate-limiter.d.cts} +73 -67
  27. package/dist/{esm/lite-rate-limiter.d.ts → lite-rate-limiter.d.ts} +73 -67
  28. package/dist/lite-rate-limiter.js +147 -0
  29. package/dist/lite-rate-limiter.js.map +1 -0
  30. package/dist/lite-throttler.cjs +127 -0
  31. package/dist/lite-throttler.cjs.map +1 -0
  32. package/dist/{cjs/lite-throttler.d.cts → lite-throttler.d.cts} +60 -54
  33. package/dist/{esm/lite-throttler.d.ts → lite-throttler.d.ts} +60 -54
  34. package/dist/lite-throttler.js +125 -0
  35. package/dist/lite-throttler.js.map +1 -0
  36. package/package.json +22 -59
  37. package/dist/cjs/index.cjs +0 -18
  38. package/dist/cjs/index.cjs.map +0 -1
  39. package/dist/cjs/index.d.cts +0 -5
  40. package/dist/cjs/lite-batcher.cjs +0 -92
  41. package/dist/cjs/lite-batcher.cjs.map +0 -1
  42. package/dist/cjs/lite-debouncer.cjs +0 -59
  43. package/dist/cjs/lite-debouncer.cjs.map +0 -1
  44. package/dist/cjs/lite-queuer.cjs +0 -171
  45. package/dist/cjs/lite-queuer.cjs.map +0 -1
  46. package/dist/cjs/lite-queuer.d.cts +0 -239
  47. package/dist/cjs/lite-rate-limiter.cjs +0 -95
  48. package/dist/cjs/lite-rate-limiter.cjs.map +0 -1
  49. package/dist/cjs/lite-throttler.cjs +0 -63
  50. package/dist/cjs/lite-throttler.cjs.map +0 -1
  51. package/dist/esm/index.d.ts +0 -5
  52. package/dist/esm/index.js.map +0 -1
  53. package/dist/esm/lite-batcher.js +0 -92
  54. package/dist/esm/lite-batcher.js.map +0 -1
  55. package/dist/esm/lite-debouncer.js +0 -59
  56. package/dist/esm/lite-debouncer.js.map +0 -1
  57. package/dist/esm/lite-queuer.d.ts +0 -239
  58. package/dist/esm/lite-queuer.js +0 -171
  59. package/dist/esm/lite-queuer.js.map +0 -1
  60. package/dist/esm/lite-rate-limiter.js +0 -95
  61. package/dist/esm/lite-rate-limiter.js.map +0 -1
  62. package/dist/esm/lite-throttler.js +0 -63
  63. package/dist/esm/lite-throttler.js.map +0 -1
package/README.md CHANGED
@@ -89,9 +89,9 @@ A lightweight timing and scheduling library for debouncing, throttling, rate lim
89
89
  > You may know **TanSack Pacer** by our adapter names, too!
90
90
  >
91
91
  > - [**React Pacer**](https://tanstack.com/pacer/latest/docs/framework/react/react-pacer)
92
+ > - [**Preact Pacer**](https://tanstack.com/pacer/latest/docs/framework/preact/preact-pacer)
92
93
  > - [**Solid Pacer**](https://tanstack.com/pacer/latest/docs/framework/solid/solid-pacer)
93
94
  > - Angular Pacer - needs a contributor!
94
- > - Preact Pacer - Coming soon! (After React Pacer is more fleshed out)
95
95
  > - Svelte Pacer - needs a contributor!
96
96
  > - Vue Pacer - needs a contributor!
97
97
 
package/dist/index.cjs ADDED
@@ -0,0 +1,16 @@
1
+ const require_lite_debouncer = require('./lite-debouncer.cjs');
2
+ const require_lite_throttler = require('./lite-throttler.cjs');
3
+ const require_lite_rate_limiter = require('./lite-rate-limiter.cjs');
4
+ const require_lite_queuer = require('./lite-queuer.cjs');
5
+ const require_lite_batcher = require('./lite-batcher.cjs');
6
+
7
+ exports.LiteBatcher = require_lite_batcher.LiteBatcher;
8
+ exports.LiteDebouncer = require_lite_debouncer.LiteDebouncer;
9
+ exports.LiteQueuer = require_lite_queuer.LiteQueuer;
10
+ exports.LiteRateLimiter = require_lite_rate_limiter.LiteRateLimiter;
11
+ exports.LiteThrottler = require_lite_throttler.LiteThrottler;
12
+ exports.liteBatch = require_lite_batcher.liteBatch;
13
+ exports.liteDebounce = require_lite_debouncer.liteDebounce;
14
+ exports.liteQueue = require_lite_queuer.liteQueue;
15
+ exports.liteRateLimit = require_lite_rate_limiter.liteRateLimit;
16
+ exports.liteThrottle = require_lite_throttler.liteThrottle;
@@ -0,0 +1,6 @@
1
+ import { LiteDebouncer, LiteDebouncerOptions, liteDebounce } from "./lite-debouncer.cjs";
2
+ import { LiteThrottler, LiteThrottlerOptions, liteThrottle } from "./lite-throttler.cjs";
3
+ import { LiteRateLimiter, LiteRateLimiterOptions, liteRateLimit } from "./lite-rate-limiter.cjs";
4
+ import { LiteQueuer, LiteQueuerOptions, QueuePosition, liteQueue } from "./lite-queuer.cjs";
5
+ import { LiteBatcher, LiteBatcherOptions, liteBatch } from "./lite-batcher.cjs";
6
+ export { LiteBatcher, LiteBatcherOptions, LiteDebouncer, LiteDebouncerOptions, LiteQueuer, LiteQueuerOptions, LiteRateLimiter, LiteRateLimiterOptions, LiteThrottler, LiteThrottlerOptions, QueuePosition, liteBatch, liteDebounce, liteQueue, liteRateLimit, liteThrottle };
@@ -0,0 +1,6 @@
1
+ import { LiteDebouncer, LiteDebouncerOptions, liteDebounce } from "./lite-debouncer.js";
2
+ import { LiteThrottler, LiteThrottlerOptions, liteThrottle } from "./lite-throttler.js";
3
+ import { LiteRateLimiter, LiteRateLimiterOptions, liteRateLimit } from "./lite-rate-limiter.js";
4
+ import { LiteQueuer, LiteQueuerOptions, QueuePosition, liteQueue } from "./lite-queuer.js";
5
+ import { LiteBatcher, LiteBatcherOptions, liteBatch } from "./lite-batcher.js";
6
+ export { LiteBatcher, LiteBatcherOptions, LiteDebouncer, LiteDebouncerOptions, LiteQueuer, LiteQueuerOptions, LiteRateLimiter, LiteRateLimiterOptions, LiteThrottler, LiteThrottlerOptions, QueuePosition, liteBatch, liteDebounce, liteQueue, liteRateLimit, liteThrottle };
@@ -3,16 +3,5 @@ import { LiteThrottler, liteThrottle } from "./lite-throttler.js";
3
3
  import { LiteRateLimiter, liteRateLimit } from "./lite-rate-limiter.js";
4
4
  import { LiteQueuer, liteQueue } from "./lite-queuer.js";
5
5
  import { LiteBatcher, liteBatch } from "./lite-batcher.js";
6
- export {
7
- LiteBatcher,
8
- LiteDebouncer,
9
- LiteQueuer,
10
- LiteRateLimiter,
11
- LiteThrottler,
12
- liteBatch,
13
- liteDebounce,
14
- liteQueue,
15
- liteRateLimit,
16
- liteThrottle
17
- };
18
- //# sourceMappingURL=index.js.map
6
+
7
+ export { LiteBatcher, LiteDebouncer, LiteQueuer, LiteRateLimiter, LiteThrottler, liteBatch, liteDebounce, liteQueue, liteRateLimit, liteThrottle };
@@ -0,0 +1,175 @@
1
+
2
+ //#region src/lite-batcher.ts
3
+ /**
4
+ * A lightweight class that collects items and processes them in batches.
5
+ *
6
+ * This is an alternative to the Batcher in the core @tanstack/pacer package, but is more
7
+ * suitable for libraries and npm packages that need minimal overhead. Unlike the core Batcher,
8
+ * this version does not use TanStack Store for state management, has no devtools integration,
9
+ * no callbacks, and provides only essential batching functionality.
10
+ *
11
+ * Batching is a technique for grouping multiple operations together to be processed as a single unit.
12
+ * This synchronous version is lighter weight and often all you need.
13
+ *
14
+ * The Batcher provides a flexible way to implement batching with configurable:
15
+ * - Maximum batch size (number of items per batch)
16
+ * - Time-based batching (process after X milliseconds)
17
+ * - Custom batch processing logic via getShouldExecute
18
+ *
19
+ * Features included:
20
+ * - Core batching functionality (addItem, flush, clear, cancel)
21
+ * - Size-based batching (maxSize)
22
+ * - Time-based batching (wait timeout)
23
+ * - Custom condition batching (getShouldExecute)
24
+ * - Manual processing controls
25
+ * - Public mutable options
26
+ * - Callback support for monitoring batch execution and state changes
27
+ *
28
+ * Features NOT included (compared to core Batcher):
29
+ * - No TanStack Store state management
30
+ * - No devtools integration
31
+ * - No complex state tracking (execution counts, etc.)
32
+ * - No reactive state management
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // Basic batching
37
+ * const batcher = new LiteBatcher<number>(
38
+ * (items) => console.log('Processing batch:', items),
39
+ * {
40
+ * maxSize: 5,
41
+ * wait: 2000,
42
+ * onExecute: (batch, batcher) => {
43
+ * console.log('Batch executed with', batch.length, 'items');
44
+ * },
45
+ * onItemsChange: (batcher) => {
46
+ * console.log('Batch size changed to:', batcher.size);
47
+ * }
48
+ * }
49
+ * );
50
+ *
51
+ * batcher.addItem(1);
52
+ * batcher.addItem(2);
53
+ * // After 2 seconds or when 5 items are added, whichever comes first,
54
+ * // the batch will be processed
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Custom condition batching
60
+ * const batcher = new LiteBatcher<Task>(
61
+ * (items) => processTasks(items),
62
+ * {
63
+ * getShouldExecute: (items) => items.some(task => task.urgent),
64
+ * maxSize: 10,
65
+ * }
66
+ * );
67
+ *
68
+ * batcher.addItem({ name: 'normal', urgent: false });
69
+ * batcher.addItem({ name: 'urgent', urgent: true }); // Triggers immediate processing
70
+ * ```
71
+ */
72
+ var LiteBatcher = class {
73
+ constructor(fn, options = {}) {
74
+ this.fn = fn;
75
+ this.options = options;
76
+ this.items = [];
77
+ this.timeoutId = null;
78
+ this._isPending = false;
79
+ this.addItem = (item) => {
80
+ this.items.push(item);
81
+ this._isPending = this.options.wait !== Infinity;
82
+ this.options.onItemsChange?.(this);
83
+ if (this.items.length >= this.options.maxSize || this.options.getShouldExecute(this.items, this)) this.execute();
84
+ else if (this.options.wait !== Infinity) {
85
+ this.clearTimeout();
86
+ this.timeoutId = setTimeout(() => this.execute(), this.getWait());
87
+ }
88
+ };
89
+ this.execute = () => {
90
+ if (this.items.length === 0) return;
91
+ const batch = this.peekAllItems();
92
+ this.clear();
93
+ this.fn(batch);
94
+ this.options.onExecute?.(batch, this);
95
+ };
96
+ this.flush = () => {
97
+ this.clearTimeout();
98
+ this.execute();
99
+ };
100
+ this.peekAllItems = () => {
101
+ return [...this.items];
102
+ };
103
+ this.clearTimeout = () => {
104
+ if (this.timeoutId) {
105
+ clearTimeout(this.timeoutId);
106
+ this.timeoutId = null;
107
+ }
108
+ };
109
+ this.clear = () => {
110
+ const hadItems = this.items.length > 0;
111
+ this.items = [];
112
+ this._isPending = false;
113
+ if (hadItems) this.options.onItemsChange?.(this);
114
+ };
115
+ this.cancel = () => {
116
+ this.clearTimeout();
117
+ this._isPending = false;
118
+ };
119
+ this.options.maxSize = this.options.maxSize ?? Infinity;
120
+ this.options.started = this.options.started ?? true;
121
+ this.options.wait = this.options.wait ?? Infinity;
122
+ this.options.getShouldExecute = this.options.getShouldExecute ?? (() => false);
123
+ }
124
+ /**
125
+ * Number of items currently in the batch
126
+ */
127
+ get size() {
128
+ return this.items.length;
129
+ }
130
+ /**
131
+ * Whether the batch has no items to process (items array is empty)
132
+ */
133
+ get isEmpty() {
134
+ return this.items.length === 0;
135
+ }
136
+ /**
137
+ * Whether the batcher is waiting for the timeout to trigger batch processing
138
+ */
139
+ get isPending() {
140
+ return this._isPending;
141
+ }
142
+ getWait() {
143
+ if (typeof this.options.wait === "function") return this.options.wait(this);
144
+ return this.options.wait;
145
+ }
146
+ };
147
+ /**
148
+ * Creates a batcher that processes items in batches.
149
+ *
150
+ * This is an alternative to the batch function in the core @tanstack/pacer package, but is more
151
+ * suitable for libraries and npm packages that need minimal overhead. Unlike the core version,
152
+ * this function creates a batcher with no external dependencies, devtools integration, or reactive state.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const batchItems = liteBatch<number>(
157
+ * (items) => console.log('Processing:', items),
158
+ * {
159
+ * maxSize: 3,
160
+ * }
161
+ * );
162
+ *
163
+ * batchItems(1);
164
+ * batchItems(2);
165
+ * batchItems(3); // Triggers batch processing
166
+ * ```
167
+ */
168
+ function liteBatch(fn, options = {}) {
169
+ return new LiteBatcher(fn, options).addItem;
170
+ }
171
+
172
+ //#endregion
173
+ exports.LiteBatcher = LiteBatcher;
174
+ exports.liteBatch = liteBatch;
175
+ //# sourceMappingURL=lite-batcher.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lite-batcher.cjs","names":["fn: (items: Array<TValue>) => void","options: LiteBatcherOptions<TValue>"],"sources":["../src/lite-batcher.ts"],"sourcesContent":["/**\n * Options for configuring a lite batcher instance\n */\nexport interface LiteBatcherOptions<TValue> {\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: LiteBatcher<TValue>,\n ) => boolean\n /**\n * Maximum number of items in a batch\n * @default Infinity\n */\n maxSize?: number\n /**\n * Callback fired after a batch is processed\n */\n onExecute?: (batch: Array<TValue>, batcher: LiteBatcher<TValue>) => void\n /**\n * Callback fired after items are added to the batcher\n */\n onItemsChange?: (batcher: LiteBatcher<TValue>) => void\n /**\n * Whether the batcher should start processing immediately\n * @default true\n */\n started?: 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 | ((batcher: LiteBatcher<TValue>) => number)\n}\n\n/**\n * A lightweight class that collects items and processes them in batches.\n *\n * This is an alternative to the Batcher in the core @tanstack/pacer package, but is more\n * suitable for libraries and npm packages that need minimal overhead. Unlike the core Batcher,\n * this version does not use TanStack Store for state management, has no devtools integration,\n * no callbacks, and provides only essential batching functionality.\n *\n * Batching is a technique for grouping multiple operations together to be processed as a single unit.\n * This synchronous version is lighter weight and often all you need.\n *\n * The Batcher provides a flexible way to implement 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 *\n * Features included:\n * - Core batching functionality (addItem, flush, clear, cancel)\n * - Size-based batching (maxSize)\n * - Time-based batching (wait timeout)\n * - Custom condition batching (getShouldExecute)\n * - Manual processing controls\n * - Public mutable options\n * - Callback support for monitoring batch execution and state changes\n *\n * Features NOT included (compared to core Batcher):\n * - No TanStack Store state management\n * - No devtools integration\n * - No complex state tracking (execution counts, etc.)\n * - No reactive state management\n *\n * @example\n * ```ts\n * // Basic batching\n * const batcher = new LiteBatcher<number>(\n * (items) => console.log('Processing batch:', items),\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batch, batcher) => {\n * console.log('Batch executed with', batch.length, 'items');\n * },\n * onItemsChange: (batcher) => {\n * console.log('Batch size changed to:', batcher.size);\n * }\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\n * ```\n *\n * @example\n * ```ts\n * // Custom condition batching\n * const batcher = new LiteBatcher<Task>(\n * (items) => processTasks(items),\n * {\n * getShouldExecute: (items) => items.some(task => task.urgent),\n * maxSize: 10,\n * }\n * );\n *\n * batcher.addItem({ name: 'normal', urgent: false });\n * batcher.addItem({ name: 'urgent', urgent: true }); // Triggers immediate processing\n * ```\n */\nexport class LiteBatcher<TValue> {\n private items: Array<TValue> = []\n private timeoutId: NodeJS.Timeout | null = null\n private _isPending = false\n\n constructor(\n public fn: (items: Array<TValue>) => void,\n public options: LiteBatcherOptions<TValue> = {},\n ) {\n // Set defaults\n this.options.maxSize = this.options.maxSize ?? Infinity\n this.options.started = this.options.started ?? true\n this.options.wait = this.options.wait ?? Infinity\n this.options.getShouldExecute =\n this.options.getShouldExecute ?? (() => false)\n }\n\n /**\n * Number of items currently in the batch\n */\n get size(): number {\n return this.items.length\n }\n\n /**\n * Whether the batch has no items to process (items array is empty)\n */\n get isEmpty(): boolean {\n return this.items.length === 0\n }\n\n /**\n * Whether the batcher is waiting for the timeout to trigger batch processing\n */\n get isPending(): boolean {\n return this._isPending\n }\n\n private getWait(): number {\n if (typeof this.options.wait === 'function') {\n return this.options.wait(this)\n }\n return this.options.wait!\n }\n\n /**\n * Adds an item to the batcher\n * If the batch size is reached, timeout occurs, or getShouldExecute returns true, the batch will be processed\n */\n addItem = (item: TValue): void => {\n this.items.push(item)\n this._isPending = this.options.wait !== Infinity\n this.options.onItemsChange?.(this)\n\n const shouldProcess =\n this.items.length >= this.options.maxSize! ||\n this.options.getShouldExecute!(this.items, this)\n\n if (shouldProcess) {\n 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 }\n }\n\n /**\n * Processes the current batch of items.\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 private execute = (): void => {\n if (this.items.length === 0) {\n return\n }\n\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\n this.fn(batch) // EXECUTE\n this.options.onExecute?.(batch, this)\n }\n\n /**\n * Processes the current batch of items immediately\n */\n flush = (): void => {\n this.clearTimeout() // clear any pending timeout\n this.execute() // execute immediately\n }\n\n /**\n * Returns a copy of all items in the batcher\n */\n peekAllItems = (): Array<TValue> => {\n return [...this.items]\n }\n\n private clearTimeout = (): void => {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId)\n this.timeoutId = null\n }\n }\n\n /**\n * Removes all items from the batcher\n */\n clear = (): void => {\n const hadItems = this.items.length > 0\n this.items = []\n this._isPending = false\n if (hadItems) {\n this.options.onItemsChange?.(this)\n }\n }\n\n /**\n * Cancels any pending execution that was scheduled.\n * Does NOT clear out the items.\n */\n cancel = (): void => {\n this.clearTimeout()\n this._isPending = false\n }\n}\n\n/**\n * Creates a batcher that processes items in batches.\n *\n * This is an alternative to the batch function in the core @tanstack/pacer package, but is more\n * suitable for libraries and npm packages that need minimal overhead. Unlike the core version,\n * this function creates a batcher with no external dependencies, devtools integration, or reactive state.\n *\n * @example\n * ```ts\n * const batchItems = liteBatch<number>(\n * (items) => console.log('Processing:', items),\n * {\n * maxSize: 3,\n * }\n * );\n *\n * batchItems(1);\n * batchItems(2);\n * batchItems(3); // Triggers batch processing\n * ```\n */\nexport function liteBatch<TValue>(\n fn: (items: Array<TValue>) => void,\n options: LiteBatcherOptions<TValue> = {},\n): (item: TValue) => void {\n const batcher = new LiteBatcher<TValue>(fn, options)\n return batcher.addItem\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,IAAa,cAAb,MAAiC;CAK/B,YACE,AAAOA,IACP,AAAOC,UAAsC,EAAE,EAC/C;EAFO;EACA;eANsB,EAAE;mBACU;oBACtB;kBA8CV,SAAuB;AAChC,QAAK,MAAM,KAAK,KAAK;AACrB,QAAK,aAAa,KAAK,QAAQ,SAAS;AACxC,QAAK,QAAQ,gBAAgB,KAAK;AAMlC,OAHE,KAAK,MAAM,UAAU,KAAK,QAAQ,WAClC,KAAK,QAAQ,iBAAkB,KAAK,OAAO,KAAK,CAGhD,MAAK,SAAS;YACL,KAAK,QAAQ,SAAS,UAAU;AACzC,SAAK,cAAc;AACnB,SAAK,YAAY,iBAAiB,KAAK,SAAS,EAAE,KAAK,SAAS,CAAC;;;uBAavC;AAC5B,OAAI,KAAK,MAAM,WAAW,EACxB;GAGF,MAAM,QAAQ,KAAK,cAAc;AACjC,QAAK,OAAO;AAEZ,QAAK,GAAG,MAAM;AACd,QAAK,QAAQ,YAAY,OAAO,KAAK;;qBAMnB;AAClB,QAAK,cAAc;AACnB,QAAK,SAAS;;4BAMoB;AAClC,UAAO,CAAC,GAAG,KAAK,MAAM;;4BAGW;AACjC,OAAI,KAAK,WAAW;AAClB,iBAAa,KAAK,UAAU;AAC5B,SAAK,YAAY;;;qBAOD;GAClB,MAAM,WAAW,KAAK,MAAM,SAAS;AACrC,QAAK,QAAQ,EAAE;AACf,QAAK,aAAa;AAClB,OAAI,SACF,MAAK,QAAQ,gBAAgB,KAAK;;sBAQjB;AACnB,QAAK,cAAc;AACnB,QAAK,aAAa;;AArHlB,OAAK,QAAQ,UAAU,KAAK,QAAQ,WAAW;AAC/C,OAAK,QAAQ,UAAU,KAAK,QAAQ,WAAW;AAC/C,OAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ;AACzC,OAAK,QAAQ,mBACX,KAAK,QAAQ,2BAA2B;;;;;CAM5C,IAAI,OAAe;AACjB,SAAO,KAAK,MAAM;;;;;CAMpB,IAAI,UAAmB;AACrB,SAAO,KAAK,MAAM,WAAW;;;;;CAM/B,IAAI,YAAqB;AACvB,SAAO,KAAK;;CAGd,AAAQ,UAAkB;AACxB,MAAI,OAAO,KAAK,QAAQ,SAAS,WAC/B,QAAO,KAAK,QAAQ,KAAK,KAAK;AAEhC,SAAO,KAAK,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;AA8GxB,SAAgB,UACd,IACA,UAAsC,EAAE,EAChB;AAExB,QADgB,IAAI,YAAoB,IAAI,QAAQ,CACrC"}
@@ -1,37 +1,38 @@
1
+ //#region src/lite-batcher.d.ts
1
2
  /**
2
3
  * Options for configuring a lite batcher instance
3
4
  */
4
- export interface LiteBatcherOptions<TValue> {
5
- /**
6
- * Custom function to determine if a batch should be processed
7
- * Return true to process the batch immediately
8
- */
9
- getShouldExecute?: (items: Array<TValue>, batcher: LiteBatcher<TValue>) => boolean;
10
- /**
11
- * Maximum number of items in a batch
12
- * @default Infinity
13
- */
14
- maxSize?: number;
15
- /**
16
- * Callback fired after a batch is processed
17
- */
18
- onExecute?: (batch: Array<TValue>, batcher: LiteBatcher<TValue>) => void;
19
- /**
20
- * Callback fired after items are added to the batcher
21
- */
22
- onItemsChange?: (batcher: LiteBatcher<TValue>) => void;
23
- /**
24
- * Whether the batcher should start processing immediately
25
- * @default true
26
- */
27
- started?: boolean;
28
- /**
29
- * Maximum time in milliseconds to wait before processing a batch.
30
- * If the wait duration has elapsed, the batch will be processed.
31
- * If not provided, the batch will not be triggered by a timeout.
32
- * @default Infinity
33
- */
34
- wait?: number | ((batcher: LiteBatcher<TValue>) => number);
5
+ interface LiteBatcherOptions<TValue> {
6
+ /**
7
+ * Custom function to determine if a batch should be processed
8
+ * Return true to process the batch immediately
9
+ */
10
+ getShouldExecute?: (items: Array<TValue>, batcher: LiteBatcher<TValue>) => boolean;
11
+ /**
12
+ * Maximum number of items in a batch
13
+ * @default Infinity
14
+ */
15
+ maxSize?: number;
16
+ /**
17
+ * Callback fired after a batch is processed
18
+ */
19
+ onExecute?: (batch: Array<TValue>, batcher: LiteBatcher<TValue>) => void;
20
+ /**
21
+ * Callback fired after items are added to the batcher
22
+ */
23
+ onItemsChange?: (batcher: LiteBatcher<TValue>) => void;
24
+ /**
25
+ * Whether the batcher should start processing immediately
26
+ * @default true
27
+ */
28
+ started?: boolean;
29
+ /**
30
+ * Maximum time in milliseconds to wait before processing a batch.
31
+ * If the wait duration has elapsed, the batch will be processed.
32
+ * If not provided, the batch will not be triggered by a timeout.
33
+ * @default Infinity
34
+ */
35
+ wait?: number | ((batcher: LiteBatcher<TValue>) => number);
35
36
  }
36
37
  /**
37
38
  * A lightweight class that collects items and processes them in batches.
@@ -102,59 +103,59 @@ export interface LiteBatcherOptions<TValue> {
102
103
  * batcher.addItem({ name: 'urgent', urgent: true }); // Triggers immediate processing
103
104
  * ```
104
105
  */
105
- export declare class LiteBatcher<TValue> {
106
- fn: (items: Array<TValue>) => void;
107
- options: LiteBatcherOptions<TValue>;
108
- private items;
109
- private timeoutId;
110
- private _isPending;
111
- constructor(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>);
112
- /**
113
- * Number of items currently in the batch
114
- */
115
- get size(): number;
116
- /**
117
- * Whether the batch has no items to process (items array is empty)
118
- */
119
- get isEmpty(): boolean;
120
- /**
121
- * Whether the batcher is waiting for the timeout to trigger batch processing
122
- */
123
- get isPending(): boolean;
124
- private getWait;
125
- /**
126
- * Adds an item to the batcher
127
- * If the batch size is reached, timeout occurs, or getShouldExecute returns true, the batch will be processed
128
- */
129
- addItem: (item: TValue) => void;
130
- /**
131
- * Processes the current batch of items.
132
- * This method will automatically be triggered if the batcher is running and any of these conditions are met:
133
- * - The number of items reaches maxSize
134
- * - The wait duration has elapsed
135
- * - The getShouldExecute function returns true upon adding an item
136
- *
137
- * You can also call this method manually to process the current batch at any time.
138
- */
139
- private execute;
140
- /**
141
- * Processes the current batch of items immediately
142
- */
143
- flush: () => void;
144
- /**
145
- * Returns a copy of all items in the batcher
146
- */
147
- peekAllItems: () => Array<TValue>;
148
- private clearTimeout;
149
- /**
150
- * Removes all items from the batcher
151
- */
152
- clear: () => void;
153
- /**
154
- * Cancels any pending execution that was scheduled.
155
- * Does NOT clear out the items.
156
- */
157
- cancel: () => void;
106
+ declare class LiteBatcher<TValue> {
107
+ fn: (items: Array<TValue>) => void;
108
+ options: LiteBatcherOptions<TValue>;
109
+ private items;
110
+ private timeoutId;
111
+ private _isPending;
112
+ constructor(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>);
113
+ /**
114
+ * Number of items currently in the batch
115
+ */
116
+ get size(): number;
117
+ /**
118
+ * Whether the batch has no items to process (items array is empty)
119
+ */
120
+ get isEmpty(): boolean;
121
+ /**
122
+ * Whether the batcher is waiting for the timeout to trigger batch processing
123
+ */
124
+ get isPending(): boolean;
125
+ private getWait;
126
+ /**
127
+ * Adds an item to the batcher
128
+ * If the batch size is reached, timeout occurs, or getShouldExecute returns true, the batch will be processed
129
+ */
130
+ addItem: (item: TValue) => void;
131
+ /**
132
+ * Processes the current batch of items.
133
+ * This method will automatically be triggered if the batcher is running and any of these conditions are met:
134
+ * - The number of items reaches maxSize
135
+ * - The wait duration has elapsed
136
+ * - The getShouldExecute function returns true upon adding an item
137
+ *
138
+ * You can also call this method manually to process the current batch at any time.
139
+ */
140
+ private execute;
141
+ /**
142
+ * Processes the current batch of items immediately
143
+ */
144
+ flush: () => void;
145
+ /**
146
+ * Returns a copy of all items in the batcher
147
+ */
148
+ peekAllItems: () => Array<TValue>;
149
+ private clearTimeout;
150
+ /**
151
+ * Removes all items from the batcher
152
+ */
153
+ clear: () => void;
154
+ /**
155
+ * Cancels any pending execution that was scheduled.
156
+ * Does NOT clear out the items.
157
+ */
158
+ cancel: () => void;
158
159
  }
159
160
  /**
160
161
  * Creates a batcher that processes items in batches.
@@ -177,4 +178,7 @@ export declare class LiteBatcher<TValue> {
177
178
  * batchItems(3); // Triggers batch processing
178
179
  * ```
179
180
  */
180
- export declare function liteBatch<TValue>(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>): (item: TValue) => void;
181
+ declare function liteBatch<TValue>(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>): (item: TValue) => void;
182
+ //#endregion
183
+ export { LiteBatcher, LiteBatcherOptions, liteBatch };
184
+ //# sourceMappingURL=lite-batcher.d.cts.map
@@ -1,37 +1,38 @@
1
+ //#region src/lite-batcher.d.ts
1
2
  /**
2
3
  * Options for configuring a lite batcher instance
3
4
  */
4
- export interface LiteBatcherOptions<TValue> {
5
- /**
6
- * Custom function to determine if a batch should be processed
7
- * Return true to process the batch immediately
8
- */
9
- getShouldExecute?: (items: Array<TValue>, batcher: LiteBatcher<TValue>) => boolean;
10
- /**
11
- * Maximum number of items in a batch
12
- * @default Infinity
13
- */
14
- maxSize?: number;
15
- /**
16
- * Callback fired after a batch is processed
17
- */
18
- onExecute?: (batch: Array<TValue>, batcher: LiteBatcher<TValue>) => void;
19
- /**
20
- * Callback fired after items are added to the batcher
21
- */
22
- onItemsChange?: (batcher: LiteBatcher<TValue>) => void;
23
- /**
24
- * Whether the batcher should start processing immediately
25
- * @default true
26
- */
27
- started?: boolean;
28
- /**
29
- * Maximum time in milliseconds to wait before processing a batch.
30
- * If the wait duration has elapsed, the batch will be processed.
31
- * If not provided, the batch will not be triggered by a timeout.
32
- * @default Infinity
33
- */
34
- wait?: number | ((batcher: LiteBatcher<TValue>) => number);
5
+ interface LiteBatcherOptions<TValue> {
6
+ /**
7
+ * Custom function to determine if a batch should be processed
8
+ * Return true to process the batch immediately
9
+ */
10
+ getShouldExecute?: (items: Array<TValue>, batcher: LiteBatcher<TValue>) => boolean;
11
+ /**
12
+ * Maximum number of items in a batch
13
+ * @default Infinity
14
+ */
15
+ maxSize?: number;
16
+ /**
17
+ * Callback fired after a batch is processed
18
+ */
19
+ onExecute?: (batch: Array<TValue>, batcher: LiteBatcher<TValue>) => void;
20
+ /**
21
+ * Callback fired after items are added to the batcher
22
+ */
23
+ onItemsChange?: (batcher: LiteBatcher<TValue>) => void;
24
+ /**
25
+ * Whether the batcher should start processing immediately
26
+ * @default true
27
+ */
28
+ started?: boolean;
29
+ /**
30
+ * Maximum time in milliseconds to wait before processing a batch.
31
+ * If the wait duration has elapsed, the batch will be processed.
32
+ * If not provided, the batch will not be triggered by a timeout.
33
+ * @default Infinity
34
+ */
35
+ wait?: number | ((batcher: LiteBatcher<TValue>) => number);
35
36
  }
36
37
  /**
37
38
  * A lightweight class that collects items and processes them in batches.
@@ -102,59 +103,59 @@ export interface LiteBatcherOptions<TValue> {
102
103
  * batcher.addItem({ name: 'urgent', urgent: true }); // Triggers immediate processing
103
104
  * ```
104
105
  */
105
- export declare class LiteBatcher<TValue> {
106
- fn: (items: Array<TValue>) => void;
107
- options: LiteBatcherOptions<TValue>;
108
- private items;
109
- private timeoutId;
110
- private _isPending;
111
- constructor(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>);
112
- /**
113
- * Number of items currently in the batch
114
- */
115
- get size(): number;
116
- /**
117
- * Whether the batch has no items to process (items array is empty)
118
- */
119
- get isEmpty(): boolean;
120
- /**
121
- * Whether the batcher is waiting for the timeout to trigger batch processing
122
- */
123
- get isPending(): boolean;
124
- private getWait;
125
- /**
126
- * Adds an item to the batcher
127
- * If the batch size is reached, timeout occurs, or getShouldExecute returns true, the batch will be processed
128
- */
129
- addItem: (item: TValue) => void;
130
- /**
131
- * Processes the current batch of items.
132
- * This method will automatically be triggered if the batcher is running and any of these conditions are met:
133
- * - The number of items reaches maxSize
134
- * - The wait duration has elapsed
135
- * - The getShouldExecute function returns true upon adding an item
136
- *
137
- * You can also call this method manually to process the current batch at any time.
138
- */
139
- private execute;
140
- /**
141
- * Processes the current batch of items immediately
142
- */
143
- flush: () => void;
144
- /**
145
- * Returns a copy of all items in the batcher
146
- */
147
- peekAllItems: () => Array<TValue>;
148
- private clearTimeout;
149
- /**
150
- * Removes all items from the batcher
151
- */
152
- clear: () => void;
153
- /**
154
- * Cancels any pending execution that was scheduled.
155
- * Does NOT clear out the items.
156
- */
157
- cancel: () => void;
106
+ declare class LiteBatcher<TValue> {
107
+ fn: (items: Array<TValue>) => void;
108
+ options: LiteBatcherOptions<TValue>;
109
+ private items;
110
+ private timeoutId;
111
+ private _isPending;
112
+ constructor(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>);
113
+ /**
114
+ * Number of items currently in the batch
115
+ */
116
+ get size(): number;
117
+ /**
118
+ * Whether the batch has no items to process (items array is empty)
119
+ */
120
+ get isEmpty(): boolean;
121
+ /**
122
+ * Whether the batcher is waiting for the timeout to trigger batch processing
123
+ */
124
+ get isPending(): boolean;
125
+ private getWait;
126
+ /**
127
+ * Adds an item to the batcher
128
+ * If the batch size is reached, timeout occurs, or getShouldExecute returns true, the batch will be processed
129
+ */
130
+ addItem: (item: TValue) => void;
131
+ /**
132
+ * Processes the current batch of items.
133
+ * This method will automatically be triggered if the batcher is running and any of these conditions are met:
134
+ * - The number of items reaches maxSize
135
+ * - The wait duration has elapsed
136
+ * - The getShouldExecute function returns true upon adding an item
137
+ *
138
+ * You can also call this method manually to process the current batch at any time.
139
+ */
140
+ private execute;
141
+ /**
142
+ * Processes the current batch of items immediately
143
+ */
144
+ flush: () => void;
145
+ /**
146
+ * Returns a copy of all items in the batcher
147
+ */
148
+ peekAllItems: () => Array<TValue>;
149
+ private clearTimeout;
150
+ /**
151
+ * Removes all items from the batcher
152
+ */
153
+ clear: () => void;
154
+ /**
155
+ * Cancels any pending execution that was scheduled.
156
+ * Does NOT clear out the items.
157
+ */
158
+ cancel: () => void;
158
159
  }
159
160
  /**
160
161
  * Creates a batcher that processes items in batches.
@@ -177,4 +178,7 @@ export declare class LiteBatcher<TValue> {
177
178
  * batchItems(3); // Triggers batch processing
178
179
  * ```
179
180
  */
180
- export declare function liteBatch<TValue>(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>): (item: TValue) => void;
181
+ declare function liteBatch<TValue>(fn: (items: Array<TValue>) => void, options?: LiteBatcherOptions<TValue>): (item: TValue) => void;
182
+ //#endregion
183
+ export { LiteBatcher, LiteBatcherOptions, liteBatch };
184
+ //# sourceMappingURL=lite-batcher.d.ts.map