@tanstack/solid-pacer 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 (184) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +32 -0
  3. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -0
  4. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +42 -0
  5. package/dist/cjs/async-debouncer/index.cjs +12 -0
  6. package/dist/cjs/async-debouncer/index.cjs.map +1 -0
  7. package/dist/cjs/async-debouncer/index.d.cts +2 -0
  8. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +69 -0
  9. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -0
  10. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +90 -0
  11. package/dist/cjs/async-queuer/index.cjs +12 -0
  12. package/dist/cjs/async-queuer/index.cjs.map +1 -0
  13. package/dist/cjs/async-queuer/index.d.cts +2 -0
  14. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +50 -0
  15. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -0
  16. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +46 -0
  17. package/dist/cjs/async-rate-limiter/index.cjs +12 -0
  18. package/dist/cjs/async-rate-limiter/index.cjs.map +1 -0
  19. package/dist/cjs/async-rate-limiter/index.d.cts +2 -0
  20. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +42 -0
  21. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -0
  22. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +46 -0
  23. package/dist/cjs/async-throttler/index.cjs +12 -0
  24. package/dist/cjs/async-throttler/index.cjs.map +1 -0
  25. package/dist/cjs/async-throttler/index.d.cts +2 -0
  26. package/dist/cjs/compare/index.cjs +10 -0
  27. package/dist/cjs/compare/index.cjs.map +1 -0
  28. package/dist/cjs/compare/index.d.cts +1 -0
  29. package/dist/cjs/debouncer/createDebouncedSignal.cjs +11 -0
  30. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -0
  31. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +47 -0
  32. package/dist/cjs/debouncer/createDebouncedValue.cjs +19 -0
  33. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -0
  34. package/dist/cjs/debouncer/createDebouncedValue.d.cts +44 -0
  35. package/dist/cjs/debouncer/createDebouncer.cjs +32 -0
  36. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -0
  37. package/dist/cjs/debouncer/createDebouncer.d.cts +47 -0
  38. package/dist/cjs/debouncer/index.cjs +16 -0
  39. package/dist/cjs/debouncer/index.cjs.map +1 -0
  40. package/dist/cjs/debouncer/index.d.cts +4 -0
  41. package/dist/cjs/index.cjs +38 -0
  42. package/dist/cjs/index.cjs.map +1 -0
  43. package/dist/cjs/index.d.cts +18 -0
  44. package/dist/cjs/queuer/createQueuer.cjs +66 -0
  45. package/dist/cjs/queuer/createQueuer.cjs.map +1 -0
  46. package/dist/cjs/queuer/createQueuer.d.cts +82 -0
  47. package/dist/cjs/queuer/index.cjs +12 -0
  48. package/dist/cjs/queuer/index.cjs.map +1 -0
  49. package/dist/cjs/queuer/index.d.cts +2 -0
  50. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +15 -0
  51. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -0
  52. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +58 -0
  53. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +13 -0
  54. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -0
  55. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +51 -0
  56. package/dist/cjs/rate-limiter/createRateLimiter.cjs +50 -0
  57. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -0
  58. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +49 -0
  59. package/dist/cjs/rate-limiter/index.cjs +16 -0
  60. package/dist/cjs/rate-limiter/index.cjs.map +1 -0
  61. package/dist/cjs/rate-limiter/index.d.cts +4 -0
  62. package/dist/cjs/throttler/createThrottledSignal.cjs +11 -0
  63. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -0
  64. package/dist/cjs/throttler/createThrottledSignal.d.cts +42 -0
  65. package/dist/cjs/throttler/createThrottledValue.cjs +19 -0
  66. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -0
  67. package/dist/cjs/throttler/createThrottledValue.d.cts +36 -0
  68. package/dist/cjs/throttler/createThrottler.cjs +42 -0
  69. package/dist/cjs/throttler/createThrottler.cjs.map +1 -0
  70. package/dist/cjs/throttler/createThrottler.d.cts +47 -0
  71. package/dist/cjs/throttler/index.cjs +16 -0
  72. package/dist/cjs/throttler/index.cjs.map +1 -0
  73. package/dist/cjs/throttler/index.d.cts +4 -0
  74. package/dist/cjs/types/index.cjs +10 -0
  75. package/dist/cjs/types/index.cjs.map +1 -0
  76. package/dist/cjs/types/index.d.cts +1 -0
  77. package/dist/cjs/utils/index.cjs +10 -0
  78. package/dist/cjs/utils/index.cjs.map +1 -0
  79. package/dist/cjs/utils/index.d.cts +1 -0
  80. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +42 -0
  81. package/dist/esm/async-debouncer/createAsyncDebouncer.js +32 -0
  82. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -0
  83. package/dist/esm/async-debouncer/index.d.ts +2 -0
  84. package/dist/esm/async-debouncer/index.js +6 -0
  85. package/dist/esm/async-debouncer/index.js.map +1 -0
  86. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +90 -0
  87. package/dist/esm/async-queuer/createAsyncQueuer.js +69 -0
  88. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -0
  89. package/dist/esm/async-queuer/index.d.ts +2 -0
  90. package/dist/esm/async-queuer/index.js +6 -0
  91. package/dist/esm/async-queuer/index.js.map +1 -0
  92. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +46 -0
  93. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +50 -0
  94. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -0
  95. package/dist/esm/async-rate-limiter/index.d.ts +2 -0
  96. package/dist/esm/async-rate-limiter/index.js +6 -0
  97. package/dist/esm/async-rate-limiter/index.js.map +1 -0
  98. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +46 -0
  99. package/dist/esm/async-throttler/createAsyncThrottler.js +42 -0
  100. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -0
  101. package/dist/esm/async-throttler/index.d.ts +2 -0
  102. package/dist/esm/async-throttler/index.js +6 -0
  103. package/dist/esm/async-throttler/index.js.map +1 -0
  104. package/dist/esm/compare/index.d.ts +1 -0
  105. package/dist/esm/compare/index.js +2 -0
  106. package/dist/esm/compare/index.js.map +1 -0
  107. package/dist/esm/debouncer/createDebouncedSignal.d.ts +47 -0
  108. package/dist/esm/debouncer/createDebouncedSignal.js +11 -0
  109. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -0
  110. package/dist/esm/debouncer/createDebouncedValue.d.ts +44 -0
  111. package/dist/esm/debouncer/createDebouncedValue.js +19 -0
  112. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -0
  113. package/dist/esm/debouncer/createDebouncer.d.ts +47 -0
  114. package/dist/esm/debouncer/createDebouncer.js +32 -0
  115. package/dist/esm/debouncer/createDebouncer.js.map +1 -0
  116. package/dist/esm/debouncer/index.d.ts +4 -0
  117. package/dist/esm/debouncer/index.js +10 -0
  118. package/dist/esm/debouncer/index.js.map +1 -0
  119. package/dist/esm/index.d.ts +18 -0
  120. package/dist/esm/index.js +32 -0
  121. package/dist/esm/index.js.map +1 -0
  122. package/dist/esm/queuer/createQueuer.d.ts +82 -0
  123. package/dist/esm/queuer/createQueuer.js +66 -0
  124. package/dist/esm/queuer/createQueuer.js.map +1 -0
  125. package/dist/esm/queuer/index.d.ts +2 -0
  126. package/dist/esm/queuer/index.js +6 -0
  127. package/dist/esm/queuer/index.js.map +1 -0
  128. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +58 -0
  129. package/dist/esm/rate-limiter/createRateLimitedSignal.js +15 -0
  130. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -0
  131. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +51 -0
  132. package/dist/esm/rate-limiter/createRateLimitedValue.js +13 -0
  133. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -0
  134. package/dist/esm/rate-limiter/createRateLimiter.d.ts +49 -0
  135. package/dist/esm/rate-limiter/createRateLimiter.js +50 -0
  136. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -0
  137. package/dist/esm/rate-limiter/index.d.ts +4 -0
  138. package/dist/esm/rate-limiter/index.js +10 -0
  139. package/dist/esm/rate-limiter/index.js.map +1 -0
  140. package/dist/esm/throttler/createThrottledSignal.d.ts +42 -0
  141. package/dist/esm/throttler/createThrottledSignal.js +11 -0
  142. package/dist/esm/throttler/createThrottledSignal.js.map +1 -0
  143. package/dist/esm/throttler/createThrottledValue.d.ts +36 -0
  144. package/dist/esm/throttler/createThrottledValue.js +19 -0
  145. package/dist/esm/throttler/createThrottledValue.js.map +1 -0
  146. package/dist/esm/throttler/createThrottler.d.ts +47 -0
  147. package/dist/esm/throttler/createThrottler.js +42 -0
  148. package/dist/esm/throttler/createThrottler.js.map +1 -0
  149. package/dist/esm/throttler/index.d.ts +4 -0
  150. package/dist/esm/throttler/index.js +10 -0
  151. package/dist/esm/throttler/index.js.map +1 -0
  152. package/dist/esm/types/index.d.ts +1 -0
  153. package/dist/esm/types/index.js +2 -0
  154. package/dist/esm/types/index.js.map +1 -0
  155. package/dist/esm/utils/index.d.ts +1 -0
  156. package/dist/esm/utils/index.js +2 -0
  157. package/dist/esm/utils/index.js.map +1 -0
  158. package/package.json +163 -0
  159. package/src/async-debouncer/createAsyncDebouncer.ts +89 -0
  160. package/src/async-debouncer/index.ts +4 -0
  161. package/src/async-queuer/createAsyncQueuer.ts +175 -0
  162. package/src/async-queuer/index.ts +3 -0
  163. package/src/async-rate-limiter/createAsyncRateLimiter.ts +116 -0
  164. package/src/async-rate-limiter/index.ts +4 -0
  165. package/src/async-throttler/createAsyncThrottler.ts +106 -0
  166. package/src/async-throttler/index.ts +4 -0
  167. package/src/compare/index.ts +1 -0
  168. package/src/debouncer/createDebouncedSignal.ts +59 -0
  169. package/src/debouncer/createDebouncedValue.ts +64 -0
  170. package/src/debouncer/createDebouncer.ts +90 -0
  171. package/src/debouncer/index.ts +6 -0
  172. package/src/index.ts +36 -0
  173. package/src/queuer/createQueuer.ts +167 -0
  174. package/src/queuer/index.ts +3 -0
  175. package/src/rate-limiter/createRateLimitedSignal.ts +74 -0
  176. package/src/rate-limiter/createRateLimitedValue.ts +66 -0
  177. package/src/rate-limiter/createRateLimiter.ts +115 -0
  178. package/src/rate-limiter/index.ts +5 -0
  179. package/src/throttler/createThrottledSignal.ts +52 -0
  180. package/src/throttler/createThrottledValue.ts +56 -0
  181. package/src/throttler/createThrottler.ts +106 -0
  182. package/src/throttler/index.ts +6 -0
  183. package/src/types/index.ts +1 -0
  184. package/src/utils/index.ts +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncDebouncer = require("@tanstack/pacer/async-debouncer");
4
+ const solidJs = require("solid-js");
5
+ const utils = require("@tanstack/pacer/utils");
6
+ function createAsyncDebouncer(fn, initialOptions) {
7
+ const asyncDebouncer$1 = new asyncDebouncer.AsyncDebouncer(fn, initialOptions);
8
+ const [executionCount, setExecutionCount] = solidJs.createSignal(
9
+ asyncDebouncer$1.getExecutionCount()
10
+ );
11
+ const [isPending, setIsPending] = solidJs.createSignal(asyncDebouncer$1.getIsPending());
12
+ function setOptions(newOptions) {
13
+ asyncDebouncer$1.setOptions({
14
+ ...newOptions,
15
+ onExecute: (asyncDebouncer2) => {
16
+ setExecutionCount(asyncDebouncer2.getExecutionCount());
17
+ setIsPending(asyncDebouncer2.getIsPending());
18
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
19
+ onExecute == null ? void 0 : onExecute(asyncDebouncer2);
20
+ }
21
+ });
22
+ }
23
+ setOptions(initialOptions);
24
+ return {
25
+ ...utils.bindInstanceMethods(asyncDebouncer$1),
26
+ executionCount,
27
+ isPending,
28
+ setOptions
29
+ };
30
+ }
31
+ exports.createAsyncDebouncer = createAsyncDebouncer;
32
+ //# sourceMappingURL=createAsyncDebouncer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAsyncDebouncer.cjs","sources":["../../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { Accessor } from 'solid-js'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n AsyncDebouncer<TFn, TArgs>,\n 'getExecutionCount' | 'getIsPending'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * This is useful for handling fast-changing inputs like search fields, form validation, or any scenario where you want to\n * wait for user input to settle before making expensive async calls.\n *\n * @example\n * ```tsx\n * // Basic API call debouncing\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // With state management\n * const [results, setResults] = createSignal([]);\n * const { maybeExecute } = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * setResults(data);\n * },\n * {\n * wait: 300,\n * }\n * );\n * ```\n */\n\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncDebouncerOptions<TFn, TArgs>,\n): SolidAsyncDebouncer<TFn, TArgs> {\n const asyncDebouncer = new AsyncDebouncer<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncDebouncer.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending())\n\n function setOptions(newOptions: Partial<AsyncDebouncerOptions<TFn, TArgs>>) {\n asyncDebouncer.setOptions({\n ...newOptions,\n onExecute: (asyncDebouncer) => {\n setExecutionCount(asyncDebouncer.getExecutionCount())\n setIsPending(asyncDebouncer.getIsPending())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(asyncDebouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncDebouncer),\n executionCount,\n isPending,\n setOptions,\n }\n}\n"],"names":["asyncDebouncer","AsyncDebouncer","createSignal","bindInstanceMethods"],"mappings":";;;;;AAqDgB,SAAA,qBAId,IACA,gBACiC;AACjC,QAAMA,mBAAiB,IAAIC,8BAA2B,IAAI,cAAc;AAElE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,iBAAe,kBAAkB;AAAA,EACnC;AACA,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,iBAAe,cAAc;AAE5E,WAAS,WAAW,YAAwD;AAC1EA,qBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAACA,oBAAmB;AACXA,0BAAAA,gBAAe,mBAAmB;AACvCA,qBAAAA,gBAAe,cAAc;AAEpC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAc;AAAA,IAC5B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,gBAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -0,0 +1,42 @@
1
+ import { AsyncDebouncer, AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer';
2
+ import { AnyAsyncFunction } from '@tanstack/pacer/types';
3
+ import { Accessor } from 'solid-js';
4
+ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>> extends Omit<AsyncDebouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {
5
+ executionCount: Accessor<number>;
6
+ isPending: Accessor<boolean>;
7
+ }
8
+ /**
9
+ * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
10
+ *
11
+ * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that
12
+ * you can integrate with any state management solution (createSignal, etc).
13
+ *
14
+ * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.
15
+ * This is useful for handling fast-changing inputs like search fields, form validation, or any scenario where you want to
16
+ * wait for user input to settle before making expensive async calls.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * // Basic API call debouncing
21
+ * const { maybeExecute } = createAsyncDebouncer(
22
+ * async (query: string) => {
23
+ * const results = await api.search(query);
24
+ * return results;
25
+ * },
26
+ * { wait: 500 }
27
+ * );
28
+ *
29
+ * // With state management
30
+ * const [results, setResults] = createSignal([]);
31
+ * const { maybeExecute } = createAsyncDebouncer(
32
+ * async (searchTerm) => {
33
+ * const data = await searchAPI(searchTerm);
34
+ * setResults(data);
35
+ * },
36
+ * {
37
+ * wait: 300,
38
+ * }
39
+ * );
40
+ * ```
41
+ */
42
+ export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn, TArgs>): SolidAsyncDebouncer<TFn, TArgs>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncDebouncer = require("@tanstack/pacer/async-debouncer");
4
+ const createAsyncDebouncer = require("./createAsyncDebouncer.cjs");
5
+ exports.createAsyncDebouncer = createAsyncDebouncer.createAsyncDebouncer;
6
+ Object.keys(asyncDebouncer).forEach((k) => {
7
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
+ enumerable: true,
9
+ get: () => asyncDebouncer[k]
10
+ });
11
+ });
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/async-debouncer';
2
+ export * from './createAsyncDebouncer.cjs';
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncQueuer = require("@tanstack/pacer/async-queuer");
4
+ const solidJs = require("solid-js");
5
+ const utils = require("@tanstack/pacer/utils");
6
+ function createAsyncQueuer(initialOptions = {}) {
7
+ const asyncQueuer$1 = new asyncQueuer.AsyncQueuer(initialOptions);
8
+ const [executionCount, setExecutionCount] = solidJs.createSignal(
9
+ asyncQueuer$1.getExecutionCount()
10
+ );
11
+ const [rejectionCount, setRejectionCount] = solidJs.createSignal(
12
+ asyncQueuer$1.getRejectionCount()
13
+ );
14
+ const [isEmpty, setIsEmpty] = solidJs.createSignal(asyncQueuer$1.getIsEmpty());
15
+ const [isFull, setIsFull] = solidJs.createSignal(asyncQueuer$1.getIsFull());
16
+ const [isIdle, setIsIdle] = solidJs.createSignal(asyncQueuer$1.getIsIdle());
17
+ const [isRunning, setIsRunning] = solidJs.createSignal(asyncQueuer$1.getIsRunning());
18
+ const [allItems, setAllItems] = solidJs.createSignal(
19
+ asyncQueuer$1.getAllItems()
20
+ );
21
+ const [activeItems, setActiveItems] = solidJs.createSignal(asyncQueuer$1.getActiveItems());
22
+ const [pendingItems, setPendingItems] = solidJs.createSignal(asyncQueuer$1.getPendingItems());
23
+ const [peek, setPeek] = solidJs.createSignal(
24
+ asyncQueuer$1.getPeek()
25
+ );
26
+ const [size, setSize] = solidJs.createSignal(asyncQueuer$1.getSize());
27
+ asyncQueuer$1.setOptions({
28
+ onItemsChange: (queuer) => {
29
+ var _a;
30
+ setExecutionCount(queuer.getExecutionCount());
31
+ setIsEmpty(queuer.getIsEmpty());
32
+ setIsFull(queuer.getIsFull());
33
+ setIsIdle(queuer.getIsIdle());
34
+ setAllItems(queuer.getAllItems());
35
+ setActiveItems(queuer.getActiveItems());
36
+ setPendingItems(queuer.getPendingItems());
37
+ setPeek(() => queuer.getPeek());
38
+ setSize(queuer.getSize());
39
+ (_a = initialOptions.onItemsChange) == null ? void 0 : _a.call(initialOptions, queuer);
40
+ },
41
+ onIsRunningChange: (queuer) => {
42
+ var _a;
43
+ setIsRunning(queuer.getIsRunning());
44
+ setIsIdle(queuer.getIsIdle());
45
+ (_a = initialOptions.onIsRunningChange) == null ? void 0 : _a.call(initialOptions, queuer);
46
+ },
47
+ onReject: (item, queuer) => {
48
+ var _a;
49
+ setRejectionCount(queuer.getRejectionCount());
50
+ (_a = initialOptions.onReject) == null ? void 0 : _a.call(initialOptions, item, queuer);
51
+ }
52
+ });
53
+ return {
54
+ ...utils.bindInstanceMethods(asyncQueuer$1),
55
+ activeItems,
56
+ executionCount,
57
+ isEmpty,
58
+ isFull,
59
+ isIdle,
60
+ isRunning,
61
+ allItems,
62
+ peek,
63
+ pendingItems,
64
+ rejectionCount,
65
+ size
66
+ };
67
+ }
68
+ exports.createAsyncQueuer = createAsyncQueuer;
69
+ //# sourceMappingURL=createAsyncQueuer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAsyncQueuer.cjs","sources":["../../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AsyncQueuerOptions } from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue>\n extends Omit<\n AsyncQueuer<TValue>,\n | 'getActiveItems'\n | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getPendingItems'\n | 'getSize'\n > {\n /**\n * Signal version of `getActiveItems`\n */\n activeItems: Accessor<Array<() => Promise<TValue>>>\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<() => Promise<TValue>>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getPendingItems`\n */\n pendingItems: Accessor<Array<() => Promise<TValue>>>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A lower-level React hook that creates an `AsyncQueuer` instance for managing an async queue of items.\n *\n * This hook provides a flexible, state-management agnostic way to handle queued async operations.\n * It returns a queuer instance with methods to add items, control queue execution, and monitor queue state.\n *\n * The queue can be configured with:\n * - Maximum concurrent operations\n * - Maximum queue size\n * - Processing function for queue items\n * - Various lifecycle callbacks\n *\n * The hook returns an object containing methods to:\n * - Add/remove items from the queue\n * - Start/stop queue processing\n * - Get queue status and items\n * - Register event handlers\n * - Control execution throttling\n *\n * @example\n * ```tsx\n * // Basic async queuer for API requests\n * const asyncQueuer = createAsyncQueuer({\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * });\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Handle results\n * asyncQueuer.onSuccess((result) => {\n * console.log('Item processed:', result);\n * });\n *\n * asyncQueuer.onError((error) => {\n * console.error('Processing failed:', error);\n * });\n * ```\n */\nexport function createAsyncQueuer<TValue>(\n initialOptions: AsyncQueuerOptions<TValue> = {},\n): SolidAsyncQueuer<TValue> {\n const asyncQueuer = new AsyncQueuer<TValue>(initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncQueuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncQueuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(asyncQueuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(asyncQueuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(asyncQueuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(asyncQueuer.getIsRunning())\n const [allItems, setAllItems] = createSignal<Array<() => Promise<TValue>>>(\n asyncQueuer.getAllItems(),\n )\n const [activeItems, setActiveItems] = createSignal<\n Array<() => Promise<TValue>>\n >(asyncQueuer.getActiveItems())\n const [pendingItems, setPendingItems] = createSignal<\n Array<() => Promise<TValue>>\n >(asyncQueuer.getPendingItems())\n const [peek, setPeek] = createSignal<(() => Promise<TValue>) | undefined>(\n asyncQueuer.getPeek(),\n )\n const [size, setSize] = createSignal(asyncQueuer.getSize())\n\n asyncQueuer.setOptions({\n onItemsChange: (queuer) => {\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setAllItems(queuer.getAllItems())\n setActiveItems(queuer.getActiveItems())\n setPendingItems(queuer.getPendingItems())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n initialOptions.onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n initialOptions.onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n initialOptions.onReject?.(item, queuer)\n },\n })\n\n return {\n ...bindInstanceMethods(asyncQueuer),\n activeItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n allItems,\n peek,\n pendingItems,\n rejectionCount,\n size,\n }\n}\n"],"names":["asyncQueuer","AsyncQueuer","createSignal","bindInstanceMethods"],"mappings":";;;;;AA2GgB,SAAA,kBACd,iBAA6C,IACnB;AACpB,QAAAA,gBAAc,IAAIC,YAAA,YAAoB,cAAc;AAEpD,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,cAAY,kBAAkB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAIE,QAAAA,aAAaF,cAAY,YAAY;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,cAAY,WAAW;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,cAAY,WAAW;AAChE,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,cAAY,cAAc;AACnE,QAAA,CAAC,UAAU,WAAW,IAAIE,QAAA;AAAA,IAC9BF,cAAY,YAAY;AAAA,EAC1B;AACA,QAAM,CAAC,aAAa,cAAc,IAAIE,QAAAA,aAEpCF,cAAY,gBAAgB;AAC9B,QAAM,CAAC,cAAc,eAAe,IAAIE,QAAAA,aAEtCF,cAAY,iBAAiB;AACzB,QAAA,CAAC,MAAM,OAAO,IAAIE,QAAA;AAAA,IACtBF,cAAY,QAAQ;AAAA,EACtB;AACA,QAAM,CAAC,MAAM,OAAO,IAAIE,QAAAA,aAAaF,cAAY,SAAS;AAE1DA,gBAAY,WAAW;AAAA,IACrB,eAAe,CAAC,WAAW;;AACP,wBAAA,OAAO,mBAAmB;AACjC,iBAAA,OAAO,YAAY;AACpB,gBAAA,OAAO,WAAW;AAClB,gBAAA,OAAO,WAAW;AAChB,kBAAA,OAAO,aAAa;AACjB,qBAAA,OAAO,gBAAgB;AACtB,sBAAA,OAAO,iBAAiB;AAChC,cAAA,MAAM,OAAO,SAAS;AACtB,cAAA,OAAO,SAAS;AACxB,2BAAe,kBAAf,wCAA+B;AAAA,IACjC;AAAA,IACA,mBAAmB,CAAC,WAAW;;AAChB,mBAAA,OAAO,cAAc;AACxB,gBAAA,OAAO,WAAW;AAC5B,2BAAe,sBAAf,wCAAmC;AAAA,IACrC;AAAA,IACA,UAAU,CAAC,MAAM,WAAW;;AACR,wBAAA,OAAO,mBAAmB;AAC7B,2BAAA,aAAA,wCAAW,MAAM;AAAA,IAAM;AAAA,EACxC,CACD;AAEM,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,aAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -0,0 +1,90 @@
1
+ import { AsyncQueuer, AsyncQueuerOptions } from '@tanstack/pacer/async-queuer';
2
+ import { Accessor } from 'solid-js';
3
+ export interface SolidAsyncQueuer<TValue> extends Omit<AsyncQueuer<TValue>, 'getActiveItems' | 'getAllItems' | 'getExecutionCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getPeek' | 'getPendingItems' | 'getSize'> {
4
+ /**
5
+ * Signal version of `getActiveItems`
6
+ */
7
+ activeItems: Accessor<Array<() => Promise<TValue>>>;
8
+ /**
9
+ * Signal version of `getAllItems`
10
+ */
11
+ allItems: Accessor<Array<() => Promise<TValue>>>;
12
+ /**
13
+ * Signal version of `getExecutionCount`
14
+ */
15
+ executionCount: Accessor<number>;
16
+ /**
17
+ * Signal version of `getIsEmpty`
18
+ */
19
+ isEmpty: Accessor<boolean>;
20
+ /**
21
+ * Signal version of `getIsFull`
22
+ */
23
+ isFull: Accessor<boolean>;
24
+ /**
25
+ * Signal version of `getIsIdle`
26
+ */
27
+ isIdle: Accessor<boolean>;
28
+ /**
29
+ * Signal version of `getIsRunning`
30
+ */
31
+ isRunning: Accessor<boolean>;
32
+ /**
33
+ * Signal version of `getPeek`
34
+ */
35
+ peek: Accessor<TValue | undefined>;
36
+ /**
37
+ * Signal version of `getPendingItems`
38
+ */
39
+ pendingItems: Accessor<Array<() => Promise<TValue>>>;
40
+ /**
41
+ * Signal version of `getSize`
42
+ */
43
+ size: Accessor<number>;
44
+ }
45
+ /**
46
+ * A lower-level React hook that creates an `AsyncQueuer` instance for managing an async queue of items.
47
+ *
48
+ * This hook provides a flexible, state-management agnostic way to handle queued async operations.
49
+ * It returns a queuer instance with methods to add items, control queue execution, and monitor queue state.
50
+ *
51
+ * The queue can be configured with:
52
+ * - Maximum concurrent operations
53
+ * - Maximum queue size
54
+ * - Processing function for queue items
55
+ * - Various lifecycle callbacks
56
+ *
57
+ * The hook returns an object containing methods to:
58
+ * - Add/remove items from the queue
59
+ * - Start/stop queue processing
60
+ * - Get queue status and items
61
+ * - Register event handlers
62
+ * - Control execution throttling
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * // Basic async queuer for API requests
67
+ * const asyncQueuer = createAsyncQueuer({
68
+ * initialItems: [],
69
+ * concurrency: 2,
70
+ * maxSize: 100,
71
+ * started: false,
72
+ * });
73
+ *
74
+ * // Add items to queue
75
+ * asyncQueuer.addItem(newItem);
76
+ *
77
+ * // Start processing
78
+ * asyncQueuer.start();
79
+ *
80
+ * // Handle results
81
+ * asyncQueuer.onSuccess((result) => {
82
+ * console.log('Item processed:', result);
83
+ * });
84
+ *
85
+ * asyncQueuer.onError((error) => {
86
+ * console.error('Processing failed:', error);
87
+ * });
88
+ * ```
89
+ */
90
+ export declare function createAsyncQueuer<TValue>(initialOptions?: AsyncQueuerOptions<TValue>): SolidAsyncQueuer<TValue>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncQueuer = require("@tanstack/pacer/async-queuer");
4
+ const createAsyncQueuer = require("./createAsyncQueuer.cjs");
5
+ exports.createAsyncQueuer = createAsyncQueuer.createAsyncQueuer;
6
+ Object.keys(asyncQueuer).forEach((k) => {
7
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
+ enumerable: true,
9
+ get: () => asyncQueuer[k]
10
+ });
11
+ });
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/async-queuer';
2
+ export * from './createAsyncQueuer.cjs';
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncRateLimiter = require("@tanstack/pacer/async-rate-limiter");
4
+ const solidJs = require("solid-js");
5
+ const utils = require("@tanstack/pacer/utils");
6
+ function createAsyncRateLimiter(fn, initialOptions) {
7
+ const asyncRateLimiter$1 = new asyncRateLimiter.AsyncRateLimiter(fn, initialOptions);
8
+ const [executionCount, setExecutionCount] = solidJs.createSignal(
9
+ asyncRateLimiter$1.getExecutionCount()
10
+ );
11
+ const [rejectionCount, setRejectionCount] = solidJs.createSignal(
12
+ asyncRateLimiter$1.getRejectionCount()
13
+ );
14
+ const [remainingInWindow, setRemainingInWindow] = solidJs.createSignal(
15
+ asyncRateLimiter$1.getRemainingInWindow()
16
+ );
17
+ const [msUntilNextWindow, setMsUntilNextWindow] = solidJs.createSignal(
18
+ asyncRateLimiter$1.getMsUntilNextWindow()
19
+ );
20
+ function setOptions(newOptions) {
21
+ asyncRateLimiter$1.setOptions({
22
+ ...newOptions,
23
+ onExecute: (rateLimiter) => {
24
+ setExecutionCount(rateLimiter.getExecutionCount());
25
+ setRemainingInWindow(rateLimiter.getRemainingInWindow());
26
+ setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow());
27
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
28
+ onExecute == null ? void 0 : onExecute(rateLimiter);
29
+ },
30
+ onReject: (rateLimiter) => {
31
+ setRejectionCount(rateLimiter.getRejectionCount());
32
+ setRemainingInWindow(rateLimiter.getRemainingInWindow());
33
+ setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow());
34
+ const onReject = newOptions.onReject ?? initialOptions.onReject;
35
+ onReject == null ? void 0 : onReject(rateLimiter);
36
+ }
37
+ });
38
+ }
39
+ setOptions(initialOptions);
40
+ return {
41
+ ...utils.bindInstanceMethods(asyncRateLimiter$1),
42
+ executionCount,
43
+ rejectionCount,
44
+ remainingInWindow,
45
+ msUntilNextWindow,
46
+ setOptions
47
+ };
48
+ }
49
+ exports.createAsyncRateLimiter = createAsyncRateLimiter;
50
+ //# sourceMappingURL=createAsyncRateLimiter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAsyncRateLimiter.cjs","sources":["../../../src/async-rate-limiter/createAsyncRateLimiter.ts"],"sourcesContent":["import { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter'\n\nexport interface SolidAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n AsyncRateLimiter<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n | 'getMsUntilNextWindow'\n > {\n executionCount: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n msUntilNextWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting allows an async function to execute up to a specified limit within a time window,\n * then blocks subsequent calls until the window passes. This is useful for respecting API rate limits,\n * managing resource constraints, or controlling bursts of async operations.\n *\n * @example\n * ```tsx\n * // Basic API call rate limiting\n * const { maybeExecute } = createAsyncRateLimiter(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { limit: 5, window: 1000 } // 5 calls per second\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncRateLimiter(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * limit: 10,\n * window: 60000, // 10 calls per minute\n * onReject: (info) => console.log(`Rate limit exceeded: ${info.nextValidTime - Date.now()}ms until next window`)\n * }\n * );\n * ```\n */\nexport function createAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncRateLimiterOptions<TFn, TArgs>,\n): SolidAsyncRateLimiter<TFn, TArgs> {\n const asyncRateLimiter = new AsyncRateLimiter<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncRateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncRateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n asyncRateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n asyncRateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(\n newOptions: Partial<AsyncRateLimiterOptions<TFn, TArgs>>,\n ) {\n asyncRateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(rateLimiter)\n },\n onReject: (rateLimiter) => {\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncRateLimiter),\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n }\n}\n"],"names":["asyncRateLimiter","AsyncRateLimiter","createSignal","bindInstanceMethods"],"mappings":";;;;;AA2DgB,SAAA,uBAId,IACA,gBACmC;AACnC,QAAMA,qBAAmB,IAAIC,kCAA6B,IAAI,cAAc;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,mBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,mBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,mBAAiB,qBAAqB;AAAA,EACxC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,mBAAiB,qBAAqB;AAAA,EACxC;AAEA,WAAS,WACP,YACA;AACAA,uBAAiB,WAAW;AAAA,MAC1B,GAAG;AAAA,MACH,WAAW,CAAC,gBAAgB;AACR,0BAAA,YAAY,mBAAmB;AAC5B,6BAAA,YAAY,sBAAsB;AAClC,6BAAA,YAAY,sBAAsB;AAEjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MACd;AAAA,MACA,UAAU,CAAC,gBAAgB;AACP,0BAAA,YAAY,mBAAmB;AAC5B,6BAAA,YAAY,sBAAsB;AAClC,6BAAA,YAAY,sBAAsB;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW;AAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,kBAAgB;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -0,0 +1,46 @@
1
+ import { AsyncRateLimiter, AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter';
2
+ import { Accessor } from 'solid-js';
3
+ import { AnyAsyncFunction } from '@tanstack/pacer/types';
4
+ export interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>> extends Omit<AsyncRateLimiter<TFn, TArgs>, 'getExecutionCount' | 'getRejectionCount' | 'getRemainingInWindow' | 'getMsUntilNextWindow'> {
5
+ executionCount: Accessor<number>;
6
+ rejectionCount: Accessor<number>;
7
+ remainingInWindow: Accessor<number>;
8
+ msUntilNextWindow: Accessor<number>;
9
+ }
10
+ /**
11
+ * A low-level Solid hook that creates an `AsyncRateLimiter` instance to limit how many times an async function can execute within a time window.
12
+ *
13
+ * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
14
+ * you can integrate with any state management solution (createSignal, etc).
15
+ *
16
+ * Rate limiting allows an async function to execute up to a specified limit within a time window,
17
+ * then blocks subsequent calls until the window passes. This is useful for respecting API rate limits,
18
+ * managing resource constraints, or controlling bursts of async operations.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * // Basic API call rate limiting
23
+ * const { maybeExecute } = createAsyncRateLimiter(
24
+ * async (id: string) => {
25
+ * const data = await api.fetchData(id);
26
+ * return data;
27
+ * },
28
+ * { limit: 5, window: 1000 } // 5 calls per second
29
+ * );
30
+ *
31
+ * // With state management
32
+ * const [data, setData] = createSignal(null);
33
+ * const { maybeExecute } = createAsyncRateLimiter(
34
+ * async (query) => {
35
+ * const result = await searchAPI(query);
36
+ * setData(result);
37
+ * },
38
+ * {
39
+ * limit: 10,
40
+ * window: 60000, // 10 calls per minute
41
+ * onReject: (info) => console.log(`Rate limit exceeded: ${info.nextValidTime - Date.now()}ms until next window`)
42
+ * }
43
+ * );
44
+ * ```
45
+ */
46
+ export declare function createAsyncRateLimiter<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncRateLimiterOptions<TFn, TArgs>): SolidAsyncRateLimiter<TFn, TArgs>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncRateLimiter = require("@tanstack/pacer/async-rate-limiter");
4
+ const createAsyncRateLimiter = require("./createAsyncRateLimiter.cjs");
5
+ exports.createAsyncRateLimiter = createAsyncRateLimiter.createAsyncRateLimiter;
6
+ Object.keys(asyncRateLimiter).forEach((k) => {
7
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
+ enumerable: true,
9
+ get: () => asyncRateLimiter[k]
10
+ });
11
+ });
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/async-rate-limiter';
2
+ export * from './createAsyncRateLimiter.cjs';
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncThrottler = require("@tanstack/pacer/async-throttler");
4
+ const solidJs = require("solid-js");
5
+ const utils = require("@tanstack/pacer/utils");
6
+ function createAsyncThrottler(fn, initialOptions) {
7
+ const asyncThrottler$1 = new asyncThrottler.AsyncThrottler(fn, initialOptions);
8
+ const [executionCount, setExecutionCount] = solidJs.createSignal(
9
+ asyncThrottler$1.getExecutionCount()
10
+ );
11
+ const [isPending, setIsPending] = solidJs.createSignal(asyncThrottler$1.getIsPending());
12
+ const [lastExecutionTime, setLastExecutionTime] = solidJs.createSignal(
13
+ asyncThrottler$1.getLastExecutionTime()
14
+ );
15
+ const [nextExecutionTime, setNextExecutionTime] = solidJs.createSignal(
16
+ asyncThrottler$1.getNextExecutionTime()
17
+ );
18
+ function setOptions(newOptions) {
19
+ asyncThrottler$1.setOptions({
20
+ ...newOptions,
21
+ onExecute: (throttler) => {
22
+ setExecutionCount(throttler.getExecutionCount());
23
+ setIsPending(throttler.getIsPending());
24
+ setLastExecutionTime(throttler.getLastExecutionTime());
25
+ setNextExecutionTime(throttler.getNextExecutionTime());
26
+ const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
27
+ onExecute == null ? void 0 : onExecute(throttler);
28
+ }
29
+ });
30
+ }
31
+ setOptions(initialOptions);
32
+ return {
33
+ ...utils.bindInstanceMethods(asyncThrottler$1),
34
+ executionCount,
35
+ isPending,
36
+ lastExecutionTime,
37
+ nextExecutionTime,
38
+ setOptions
39
+ };
40
+ }
41
+ exports.createAsyncThrottler = createAsyncThrottler;
42
+ //# sourceMappingURL=createAsyncThrottler.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createAsyncThrottler.cjs","sources":["../../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { AsyncThrottler } from '@tanstack/pacer/async-throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n AsyncThrottler<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getIsPending'\n | 'getLastExecutionTime'\n | 'getNextExecutionTime'\n > {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n lastExecutionTime: Accessor<number>\n nextExecutionTime: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async throttling ensures an async function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,\n * database operations, or other async tasks.\n *\n * @example\n * ```tsx\n * // Basic API call throttling\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // With state management\n * const [data, setData] = createSignal(null);\n * const { maybeExecute } = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * setData(result);\n * },\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n * ```\n */\n\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: AsyncThrottlerOptions<TFn, TArgs>,\n): SolidAsyncThrottler<TFn, TArgs> {\n const asyncThrottler = new AsyncThrottler<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n asyncThrottler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncThrottler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n asyncThrottler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n asyncThrottler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<AsyncThrottlerOptions<TFn, TArgs>>) {\n asyncThrottler.setOptions({\n ...newOptions,\n onExecute: (throttler) => {\n setExecutionCount(throttler.getExecutionCount())\n setIsPending(throttler.getIsPending())\n setLastExecutionTime(throttler.getLastExecutionTime())\n setNextExecutionTime(throttler.getNextExecutionTime())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(throttler)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncThrottler),\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n }\n}\n"],"names":["asyncThrottler","AsyncThrottler","createSignal","bindInstanceMethods"],"mappings":";;;;;AA4DgB,SAAA,qBAId,IACA,gBACiC;AACjC,QAAMA,mBAAiB,IAAIC,8BAA2B,IAAI,cAAc;AAElE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,iBAAe,kBAAkB;AAAA,EACnC;AACA,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,iBAAe,cAAc;AACtE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,iBAAe,qBAAqB;AAAA,EACtC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,iBAAe,qBAAqB;AAAA,EACtC;AAEA,WAAS,WAAW,YAAwD;AAC1EA,qBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAAC,cAAc;AACN,0BAAA,UAAU,mBAAmB;AAClC,qBAAA,UAAU,cAAc;AAChB,6BAAA,UAAU,sBAAsB;AAChC,6BAAA,UAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAY;AAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,gBAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -0,0 +1,46 @@
1
+ import { AsyncThrottler, AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler';
2
+ import { Accessor } from 'solid-js';
3
+ import { AnyAsyncFunction } from '@tanstack/pacer/types';
4
+ export interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>> extends Omit<AsyncThrottler<TFn, TArgs>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
5
+ executionCount: Accessor<number>;
6
+ isPending: Accessor<boolean>;
7
+ lastExecutionTime: Accessor<number>;
8
+ nextExecutionTime: Accessor<number>;
9
+ }
10
+ /**
11
+ * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
12
+ *
13
+ * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that
14
+ * you can integrate with any state management solution (createSignal, etc).
15
+ *
16
+ * Async throttling ensures an async function executes at most once within a specified time window,
17
+ * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
18
+ * database operations, or other async tasks.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * // Basic API call throttling
23
+ * const { maybeExecute } = createAsyncThrottler(
24
+ * async (id: string) => {
25
+ * const data = await api.fetchData(id);
26
+ * return data;
27
+ * },
28
+ * { wait: 1000 }
29
+ * );
30
+ *
31
+ * // With state management
32
+ * const [data, setData] = createSignal(null);
33
+ * const { maybeExecute } = createAsyncThrottler(
34
+ * async (query) => {
35
+ * const result = await searchAPI(query);
36
+ * setData(result);
37
+ * },
38
+ * {
39
+ * wait: 2000,
40
+ * leading: true, // Execute immediately on first call
41
+ * trailing: false // Skip trailing edge updates
42
+ * }
43
+ * );
44
+ * ```
45
+ */
46
+ export declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncThrottlerOptions<TFn, TArgs>): SolidAsyncThrottler<TFn, TArgs>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const asyncThrottler = require("@tanstack/pacer/async-throttler");
4
+ const createAsyncThrottler = require("./createAsyncThrottler.cjs");
5
+ exports.createAsyncThrottler = createAsyncThrottler.createAsyncThrottler;
6
+ Object.keys(asyncThrottler).forEach((k) => {
7
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
+ enumerable: true,
9
+ get: () => asyncThrottler[k]
10
+ });
11
+ });
12
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ export * from '@tanstack/pacer/async-throttler';
2
+ export * from './createAsyncThrottler.cjs';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const compare = require("@tanstack/pacer/compare");
4
+ Object.keys(compare).forEach((k) => {
5
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: () => compare[k]
8
+ });
9
+ });
10
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
@@ -0,0 +1 @@
1
+ export * from '@tanstack/pacer/compare';
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const solidJs = require("solid-js");
4
+ const createDebouncer = require("./createDebouncer.cjs");
5
+ function createDebouncedSignal(value, initialOptions) {
6
+ const [debouncedValue, setDebouncedValue] = solidJs.createSignal(value);
7
+ const debouncer = createDebouncer.createDebouncer(setDebouncedValue, initialOptions);
8
+ return [debouncedValue, debouncer.maybeExecute, debouncer];
9
+ }
10
+ exports.createDebouncedSignal = createDebouncedSignal;
11
+ //# sourceMappingURL=createDebouncedSignal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDebouncedSignal.cjs","sources":["../../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounced search input\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue>(\n value: TValue,\n initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"names":["createSignal","createDebouncer"],"mappings":";;;;AA6CgB,SAAA,sBACd,OACA,gBAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAEhE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AAEnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}