@tanstack/solid-pacer 0.2.0 → 0.3.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 (89) hide show
  1. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +22 -7
  2. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  3. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +6 -3
  4. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  5. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +5 -1
  6. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +20 -9
  7. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  8. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +5 -3
  9. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +32 -10
  10. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  11. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +7 -3
  12. package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -1
  13. package/dist/cjs/debouncer/createDebouncedSignal.d.cts +1 -5
  14. package/dist/cjs/debouncer/createDebouncedValue.cjs +0 -3
  15. package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -1
  16. package/dist/cjs/debouncer/createDebouncedValue.d.cts +5 -11
  17. package/dist/cjs/debouncer/createDebouncer.cjs +7 -2
  18. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  19. package/dist/cjs/debouncer/createDebouncer.d.cts +2 -2
  20. package/dist/cjs/queuer/createQueuer.cjs +2 -2
  21. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  22. package/dist/cjs/queuer/createQueuer.d.cts +4 -0
  23. package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
  24. package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +1 -5
  25. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  26. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +9 -20
  27. package/dist/cjs/rate-limiter/createRateLimiter.cjs +4 -2
  28. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  29. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +2 -2
  30. package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -1
  31. package/dist/cjs/throttler/createThrottledSignal.d.cts +1 -5
  32. package/dist/cjs/throttler/createThrottledValue.cjs +0 -3
  33. package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -1
  34. package/dist/cjs/throttler/createThrottledValue.d.cts +10 -14
  35. package/dist/cjs/throttler/createThrottler.cjs +7 -2
  36. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  37. package/dist/cjs/throttler/createThrottler.d.cts +2 -2
  38. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +6 -3
  39. package/dist/esm/async-debouncer/createAsyncDebouncer.js +22 -7
  40. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  41. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +5 -1
  42. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  43. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +5 -3
  44. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +20 -9
  45. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  46. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +7 -3
  47. package/dist/esm/async-throttler/createAsyncThrottler.js +32 -10
  48. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  49. package/dist/esm/debouncer/createDebouncedSignal.d.ts +1 -5
  50. package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -1
  51. package/dist/esm/debouncer/createDebouncedValue.d.ts +5 -11
  52. package/dist/esm/debouncer/createDebouncedValue.js +1 -4
  53. package/dist/esm/debouncer/createDebouncedValue.js.map +1 -1
  54. package/dist/esm/debouncer/createDebouncer.d.ts +2 -2
  55. package/dist/esm/debouncer/createDebouncer.js +8 -3
  56. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  57. package/dist/esm/queuer/createQueuer.d.ts +4 -0
  58. package/dist/esm/queuer/createQueuer.js +2 -2
  59. package/dist/esm/queuer/createQueuer.js.map +1 -1
  60. package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +1 -5
  61. package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -1
  62. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +9 -20
  63. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  64. package/dist/esm/rate-limiter/createRateLimiter.d.ts +2 -2
  65. package/dist/esm/rate-limiter/createRateLimiter.js +4 -2
  66. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  67. package/dist/esm/throttler/createThrottledSignal.d.ts +1 -5
  68. package/dist/esm/throttler/createThrottledSignal.js.map +1 -1
  69. package/dist/esm/throttler/createThrottledValue.d.ts +10 -14
  70. package/dist/esm/throttler/createThrottledValue.js +1 -4
  71. package/dist/esm/throttler/createThrottledValue.js.map +1 -1
  72. package/dist/esm/throttler/createThrottler.d.ts +2 -2
  73. package/dist/esm/throttler/createThrottler.js +8 -3
  74. package/dist/esm/throttler/createThrottler.js.map +1 -1
  75. package/package.json +2 -2
  76. package/src/async-debouncer/createAsyncDebouncer.ts +40 -24
  77. package/src/async-queuer/createAsyncQueuer.ts +6 -2
  78. package/src/async-rate-limiter/createAsyncRateLimiter.ts +34 -26
  79. package/src/async-throttler/createAsyncThrottler.ts +49 -24
  80. package/src/debouncer/createDebouncedSignal.ts +2 -6
  81. package/src/debouncer/createDebouncedValue.ts +7 -16
  82. package/src/debouncer/createDebouncer.ts +16 -15
  83. package/src/queuer/createQueuer.ts +7 -3
  84. package/src/rate-limiter/createRateLimitedSignal.ts +2 -6
  85. package/src/rate-limiter/createRateLimitedValue.ts +10 -21
  86. package/src/rate-limiter/createRateLimiter.ts +14 -15
  87. package/src/throttler/createThrottledSignal.ts +2 -6
  88. package/src/throttler/createThrottledValue.ts +12 -19
  89. package/src/throttler/createThrottler.ts +17 -16
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedSignal.cjs","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAwDgB,SAAA,wBACd,OACA,gBAKA;AACA,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimitedSignal.cjs","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAwDgB,SAAA,wBACd,OACA,gBACsE;AACtE,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
@@ -51,8 +51,4 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
51
51
  * };
52
52
  * ```
53
53
  */
54
- export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [
55
- Accessor<TValue>,
56
- Setter<TValue>,
57
- SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>
58
- ];
54
+ export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimitedValue.cjs","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute\n * const [rateLimitedValue] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Optionally access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * console.log(`${remaining} updates remaining in this window`);\n * } else {\n * console.log('Rate limit reached for this window');\n * }\n * };\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAqDgB,SAAA,uBACd,OACA,gBAC0E;AACpE,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
1
+ {"version":3,"file":"createRateLimitedValue.cjs","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // Use the rate-limited value\n * console.log(rateLimitedValue()); // Access the current rate-limited value\n *\n * // Control the rate limiter\n * rateLimiter.reset(); // Reset the rate limit window\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AA0CgB,SAAA,uBACd,OACA,gBACsD;AAChD,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
@@ -15,7 +15,9 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
15
15
  *
16
16
  * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
17
17
  *
18
- * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.
18
+ * The hook returns a tuple containing:
19
+ * - An accessor function that provides the rate-limited value
20
+ * - The rate limiter instance with control methods
19
21
  *
20
22
  * For more direct control over rate limiting behavior without Solid state management,
21
23
  * consider using the lower-level createRateLimiter hook instead.
@@ -23,29 +25,16 @@ import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
23
25
  * @example
24
26
  * ```tsx
25
27
  * // Basic rate limiting - update at most 5 times per minute
26
- * const [rateLimitedValue] = createRateLimitedValue(rawValue, {
28
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
27
29
  * limit: 5,
28
30
  * window: 60000
29
31
  * });
30
32
  *
31
- * // With rejection callback
32
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
33
- * limit: 3,
34
- * window: 5000,
35
- * onReject: (rateLimiter) => {
36
- * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
37
- * }
38
- * });
33
+ * // Use the rate-limited value
34
+ * console.log(rateLimitedValue()); // Access the current rate-limited value
39
35
  *
40
- * // Optionally access rateLimiter state via signals
41
- * const handleSubmit = () => {
42
- * const remaining = rateLimiter.remainingInWindow();
43
- * if (remaining > 0) {
44
- * console.log(`${remaining} updates remaining in this window`);
45
- * } else {
46
- * console.log('Rate limit reached for this window');
47
- * }
48
- * };
36
+ * // Control the rate limiter
37
+ * rateLimiter.reset(); // Reset the rate limit window
49
38
  * ```
50
39
  */
51
- export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>];
40
+ export declare function createRateLimitedValue<TValue>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>>];
@@ -4,7 +4,9 @@ const rateLimiter = require("@tanstack/pacer/rate-limiter");
4
4
  const solidJs = require("solid-js");
5
5
  const utils = require("@tanstack/pacer/utils");
6
6
  function createRateLimiter(fn, initialOptions) {
7
- const rateLimiter$1 = new rateLimiter.RateLimiter(fn, initialOptions);
7
+ const rateLimiter$1 = utils.bindInstanceMethods(
8
+ new rateLimiter.RateLimiter(fn, initialOptions)
9
+ );
8
10
  const [executionCount, setExecutionCount] = solidJs.createSignal(
9
11
  rateLimiter$1.getExecutionCount()
10
12
  );
@@ -38,7 +40,7 @@ function createRateLimiter(fn, initialOptions) {
38
40
  }
39
41
  setOptions(initialOptions);
40
42
  return {
41
- ...utils.bindInstanceMethods(rateLimiter$1),
43
+ ...rateLimiter$1,
42
44
  executionCount,
43
45
  rejectionCount,
44
46
  remainingInWindow,
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimiter.cjs","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n RateLimiter<TFn, TArgs>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\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 is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * });\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * if (rateLimiter.remainingInWindow() > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn, TArgs>,\n): SolidRateLimiter<TFn, TArgs> {\n const rateLimiter = new RateLimiter<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn, TArgs>>) {\n rateLimiter.setOptions({\n ...newOptions,\n onExecute: (rateLimiter) => {\n setExecutionCount(rateLimiter.getExecutionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\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 const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(rateLimiter)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(rateLimiter),\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n }\n}\n"],"names":["rateLimiter","RateLimiter","createSignal","bindInstanceMethods"],"mappings":";;;;;AA8DgB,SAAA,kBAId,IACA,gBAC8B;AAC9B,QAAMA,gBAAc,IAAIC,wBAAwB,IAAI,cAAc;AAE5D,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;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,cAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,cAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAAqD;AACvEA,kBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AACjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,aAAW;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createRateLimiter.cjs","sources":["../../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<TFn extends AnyFunction>\n extends Omit<\n RateLimiter<TFn>,\n | 'getExecutionCount'\n | 'getMsUntilNextWindow'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n > {\n executionCount: Accessor<number>\n msUntilNextWindow: Accessor<number>\n rejectionCount: Accessor<number>\n remainingInWindow: Accessor<number>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\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 is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * @example\n * ```tsx\n * // Basic rate limiting - max 5 calls per minute\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * });\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * if (rateLimiter.remainingInWindow() > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access rate limiter state via signals\n * console.log('Executions:', rateLimiter.executionCount());\n * console.log('Rejections:', rateLimiter.rejectionCount());\n * console.log('Remaining:', rateLimiter.remainingInWindow());\n * console.log('Next window in:', rateLimiter.msUntilNextWindow());\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: RateLimiterOptions<TFn>,\n): SolidRateLimiter<TFn> {\n const rateLimiter = bindInstanceMethods(\n new RateLimiter<TFn>(fn, initialOptions),\n )\n\n const [executionCount, setExecutionCount] = createSignal(\n rateLimiter.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n rateLimiter.getRejectionCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n rateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n rateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<RateLimiterOptions<TFn>>) {\n rateLimiter.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 ...rateLimiter,\n executionCount,\n rejectionCount,\n remainingInWindow,\n msUntilNextWindow,\n setOptions,\n } as SolidRateLimiter<TFn>\n}\n"],"names":["rateLimiter","bindInstanceMethods","RateLimiter","createSignal"],"mappings":";;;;;AA4DgB,SAAA,kBACd,IACA,gBACuB;AACvB,QAAMA,gBAAcC,MAAA;AAAA,IAClB,IAAIC,YAAAA,YAAiB,IAAI,cAAc;AAAA,EACzC;AAEM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIG,QAAA;AAAA,IAC1CH,cAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,cAAY,qBAAqB;AAAA,EACnC;AAEA,WAAS,WAAW,YAA8C;AAChEA,kBAAY,WAAW;AAAA,MACrB,GAAG;AAAA,MACH,WAAW,CAACA,iBAAgB;AACRA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MACd;AAAA,MACA,UAAU,CAACA,iBAAgB;AACPA,0BAAAA,aAAY,mBAAmB;AAC5BA,6BAAAA,aAAY,sBAAsB;AAClCA,6BAAAA,aAAY,sBAAsB;AAEjD,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAWA;AAAAA,MAAW;AAAA,IACxB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -1,7 +1,7 @@
1
1
  import { RateLimiter, RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
2
2
  import { Accessor } from 'solid-js';
3
3
  import { AnyFunction } from '@tanstack/pacer/types';
4
- export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<RateLimiter<TFn, TArgs>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
4
+ export interface SolidRateLimiter<TFn extends AnyFunction> extends Omit<RateLimiter<TFn>, 'getExecutionCount' | 'getMsUntilNextWindow' | 'getRejectionCount' | 'getRemainingInWindow'> {
5
5
  executionCount: Accessor<number>;
6
6
  msUntilNextWindow: Accessor<number>;
7
7
  rejectionCount: Accessor<number>;
@@ -46,4 +46,4 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TArgs extends Paramet
46
46
  * console.log('Next window in:', rateLimiter.msUntilNextWindow());
47
47
  * ```
48
48
  */
49
- export declare function createRateLimiter<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: RateLimiterOptions<TFn, TArgs>): SolidRateLimiter<TFn, TArgs>;
49
+ export declare function createRateLimiter<TFn extends AnyFunction>(fn: TFn, initialOptions: RateLimiterOptions<TFn>): SolidRateLimiter<TFn>;
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<TValue>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AAwCgB,SAAA,sBACd,OACA,gBAKA;AACA,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAChE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
1
+ {"version":3,"file":"createThrottledSignal.cjs","sources":["../../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update state at most once per second\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledSignal<TValue>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"names":["createSignal","createThrottler"],"mappings":";;;;AAwCgB,SAAA,sBACd,OACA,gBACoE;AACpE,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,QAAAA,aAAqB,KAAK;AAChE,QAAA,YAAYC,gBAAAA,gBAAgB,mBAAmB,cAAc;AACnE,SAAO,CAAC,gBAAgB,UAAU,cAAgC,SAAS;AAC7E;;"}
@@ -35,8 +35,4 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
35
35
  * console.log('Next execution:', throttler.nextExecutionTime());
36
36
  * ```
37
37
  */
38
- export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [
39
- Accessor<TValue>,
40
- Setter<TValue>,
41
- SolidThrottler<Setter<TValue>, [Accessor<TValue>]>
42
- ];
38
+ export declare function createThrottledSignal<TValue>(value: TValue, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, Setter<TValue>, SolidThrottler<Setter<TValue>>];
@@ -9,9 +9,6 @@ function createThrottledValue(value, initialOptions) {
9
9
  );
10
10
  solidJs.createEffect(() => {
11
11
  setThrottledValue(value());
12
- solidJs.onCleanup(() => {
13
- throttler.cancel();
14
- });
15
12
  });
16
13
  return [throttledValue, throttler];
17
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns both the throttled value and the underlying throttler instance for additional control.\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // With custom leading/trailing behavior\n * const [throttledValue, throttler] = createThrottledValue(rawValue, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.executionCount());\n * console.log('Is pending:', throttler.isPending());\n * console.log('Last execution:', throttler.lastExecutionTime());\n * console.log('Next execution:', throttler.nextExecutionTime());\n * ```\n */\nexport function createThrottledValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, [Accessor<TValue>]>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n onCleanup(() => {\n throttler.cancel()\n })\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect","onCleanup"],"mappings":";;;;AAsCgB,SAAA,qBACd,OACA,gBACwE;AACxE,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAChCC,YAAAA,UAAU,MAAM;AACd,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
1
+ {"version":3,"file":"createThrottledValue.cjs","sources":["../../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * @example\n * ```tsx\n * // Basic throttling - update at most once per second\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"names":["createThrottledSignal","createEffect"],"mappings":";;;;AAkCgB,SAAA,qBACd,OACA,gBACoD;AACpD,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAAA,EAAA,CACjC;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
@@ -8,7 +8,10 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
8
8
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
9
9
  * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
10
10
  *
11
- * The hook returns both the throttled value and the underlying throttler instance for additional control.
11
+ * The hook returns a tuple containing:
12
+ * - An accessor function that provides the throttled value
13
+ * - The throttler instance with control methods
14
+ *
12
15
  * The throttled value will update according to the leading/trailing edge behavior specified in the options.
13
16
  *
14
17
  * For more direct control over throttling behavior without Solid state management,
@@ -17,20 +20,13 @@ import { ThrottlerOptions } from '@tanstack/pacer/throttler';
17
20
  * @example
18
21
  * ```tsx
19
22
  * // Basic throttling - update at most once per second
20
- * const [throttledValue] = createThrottledValue(rawValue, { wait: 1000 });
23
+ * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });
21
24
  *
22
- * // With custom leading/trailing behavior
23
- * const [throttledValue, throttler] = createThrottledValue(rawValue, {
24
- * wait: 1000,
25
- * leading: true, // Update immediately on first change
26
- * trailing: false // Skip trailing edge updates
27
- * });
25
+ * // Use the throttled value
26
+ * console.log(throttledValue()); // Access the current throttled value
28
27
  *
29
- * // Access throttler state via signals
30
- * console.log('Executions:', throttler.executionCount());
31
- * console.log('Is pending:', throttler.isPending());
32
- * console.log('Last execution:', throttler.lastExecutionTime());
33
- * console.log('Next execution:', throttler.nextExecutionTime());
28
+ * // Control the throttler
29
+ * throttler.cancel(); // Cancel any pending updates
34
30
  * ```
35
31
  */
36
- export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidThrottler<Setter<TValue>, [Accessor<TValue>]>];
32
+ export declare function createThrottledValue<TValue>(value: Accessor<TValue>, initialOptions: ThrottlerOptions<Setter<TValue>>): [Accessor<TValue>, SolidThrottler<Setter<TValue>>];
@@ -4,7 +4,7 @@ const throttler = require("@tanstack/pacer/throttler");
4
4
  const solidJs = require("solid-js");
5
5
  const utils = require("@tanstack/pacer/utils");
6
6
  function createThrottler(fn, initialOptions) {
7
- const throttler$1 = new throttler.Throttler(fn, initialOptions);
7
+ const throttler$1 = utils.bindInstanceMethods(new throttler.Throttler(fn, initialOptions));
8
8
  const [executionCount, setExecutionCount] = solidJs.createSignal(
9
9
  throttler$1.getExecutionCount()
10
10
  );
@@ -29,8 +29,13 @@ function createThrottler(fn, initialOptions) {
29
29
  });
30
30
  }
31
31
  setOptions(initialOptions);
32
+ solidJs.createEffect(() => {
33
+ solidJs.onCleanup(() => {
34
+ throttler$1.cancel();
35
+ });
36
+ });
32
37
  return {
33
- ...utils.bindInstanceMethods(throttler$1),
38
+ ...throttler$1,
34
39
  executionCount,
35
40
  isPending,
36
41
  lastExecutionTime,
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler\n */\nexport interface SolidThrottler<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<\n Throttler<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 a `Throttler` instance that limits how often the provided 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, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a 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\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn, TArgs>,\n): SolidThrottler<TFn, TArgs> {\n const throttler = new Throttler<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n throttler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(throttler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n throttler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n throttler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<ThrottlerOptions<TFn, TArgs>>) {\n throttler.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(throttler),\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n }\n}\n"],"names":["throttler","Throttler","createSignal","bindInstanceMethods"],"mappings":";;;;;AA4DgB,SAAA,gBAId,IACA,gBAC4B;AAC5B,QAAMA,cAAY,IAAIC,oBAAsB,IAAI,cAAc;AAExD,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,YAAU,cAAc;AACjE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,YAAU,qBAAqB;AAAA,EACjC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIE,QAAA;AAAA,IAChDF,YAAU,qBAAqB;AAAA,EACjC;AAEA,WAAS,WAAW,YAAmD;AACrEA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAChBA,6BAAAA,WAAU,sBAAsB;AAChCA,6BAAAA,WAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,WAAS;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
1
+ {"version":3,"file":"createThrottler.cjs","sources":["../../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, createSignal, onCleanup } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { ThrottlerOptions } from '@tanstack/pacer/throttler'\n\n/**\n * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler\n */\nexport interface SolidThrottler<TFn extends AnyFunction>\n extends Omit<\n Throttler<TFn>,\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 a `Throttler` instance that limits how often the provided 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, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a 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\n * expensive operations or UI updates.\n *\n * @example\n * ```tsx\n * // Basic throttling with custom state\n * const [value, setValue] = createSignal(0);\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // With any state manager\n * const throttler = createThrottler(\n * (value) => stateManager.setState(value),\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * }\n * );\n *\n * // Access throttler state via signals\n * console.log(throttler.executionCount()); // number of times executed\n * console.log(throttler.isPending()); // whether throttled function is pending\n * console.log(throttler.lastExecutionTime()); // timestamp of last execution\n * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction>(\n fn: TFn,\n initialOptions: ThrottlerOptions<TFn>,\n): SolidThrottler<TFn> {\n const throttler = bindInstanceMethods(new Throttler<TFn>(fn, initialOptions))\n\n const [executionCount, setExecutionCount] = createSignal(\n throttler.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(throttler.getIsPending())\n const [lastExecutionTime, setLastExecutionTime] = createSignal(\n throttler.getLastExecutionTime(),\n )\n const [nextExecutionTime, setNextExecutionTime] = createSignal(\n throttler.getNextExecutionTime(),\n )\n\n function setOptions(newOptions: Partial<ThrottlerOptions<TFn>>) {\n throttler.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 createEffect(() => {\n onCleanup(() => {\n throttler.cancel()\n })\n })\n\n return {\n ...throttler,\n executionCount,\n isPending,\n lastExecutionTime,\n nextExecutionTime,\n setOptions,\n } as SolidThrottler<TFn>\n}\n"],"names":["throttler","bindInstanceMethods","Throttler","createSignal","createEffect","onCleanup"],"mappings":";;;;;AA0DgB,SAAA,gBACd,IACA,gBACqB;AACrB,QAAMA,cAAYC,MAAAA,oBAAoB,IAAIC,UAAe,UAAA,IAAI,cAAc,CAAC;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CH,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIG,QAAAA,aAAaH,YAAU,cAAc;AACjE,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAIG,QAAA;AAAA,IAChDH,YAAU,qBAAqB;AAAA,EACjC;AAEA,WAAS,WAAW,YAA4C;AAC9DA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAChBA,6BAAAA,WAAU,sBAAsB;AAChCA,6BAAAA,WAAU,sBAAsB;AAE/C,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAEzBI,UAAAA,aAAa,MAAM;AACjBC,YAAAA,UAAU,MAAM;AACdL,kBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA;AAAA,IACL,GAAGA;AAAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
@@ -4,7 +4,7 @@ import { AnyFunction } from '@tanstack/pacer/types';
4
4
  /**
5
5
  * An extension of the Throttler class that adds Solid signals to access the internal state of the throttler
6
6
  */
7
- export interface SolidThrottler<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<Throttler<TFn, TArgs>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
7
+ export interface SolidThrottler<TFn extends AnyFunction> extends Omit<Throttler<TFn>, 'getExecutionCount' | 'getIsPending' | 'getLastExecutionTime' | 'getNextExecutionTime'> {
8
8
  executionCount: Accessor<number>;
9
9
  isPending: Accessor<boolean>;
10
10
  lastExecutionTime: Accessor<number>;
@@ -44,4 +44,4 @@ export interface SolidThrottler<TFn extends AnyFunction, TArgs extends Parameter
44
44
  * console.log(throttler.nextExecutionTime()); // timestamp of next allowed execution
45
45
  * ```
46
46
  */
47
- export declare function createThrottler<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: ThrottlerOptions<TFn, TArgs>): SolidThrottler<TFn, TArgs>;
47
+ export declare function createThrottler<TFn extends AnyFunction>(fn: TFn, initialOptions: ThrottlerOptions<TFn>): SolidThrottler<TFn>;
@@ -1,9 +1,12 @@
1
1
  import { AsyncDebouncer, AsyncDebouncerOptions } from '@tanstack/pacer/async-debouncer';
2
2
  import { AnyAsyncFunction } from '@tanstack/pacer/types';
3
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>;
4
+ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction> extends Omit<AsyncDebouncer<TFn>, 'getErrorCount' | 'getIsPending' | 'getLastResult' | 'getSettleCount' | 'getSuccessCount'> {
5
+ errorCount: Accessor<number>;
6
6
  isPending: Accessor<boolean>;
7
+ lastResult: Accessor<ReturnType<TFn> | undefined>;
8
+ settleCount: Accessor<number>;
9
+ successCount: Accessor<number>;
7
10
  }
8
11
  /**
9
12
  * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.
@@ -39,4 +42,4 @@ export interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends
39
42
  * );
40
43
  * ```
41
44
  */
42
- export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn, TArgs>): SolidAsyncDebouncer<TFn, TArgs>;
45
+ export declare function createAsyncDebouncer<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncDebouncerOptions<TFn>): SolidAsyncDebouncer<TFn>;
@@ -3,26 +3,41 @@ import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createAsyncDebouncer(fn, initialOptions) {
5
5
  const asyncDebouncer = new AsyncDebouncer(fn, initialOptions);
6
- const [executionCount, setExecutionCount] = createSignal(
7
- asyncDebouncer.getExecutionCount()
6
+ const [errorCount, setErrorCount] = createSignal(
7
+ asyncDebouncer.getErrorCount()
8
+ );
9
+ const [settleCount, setSettleCount] = createSignal(
10
+ asyncDebouncer.getSettleCount()
11
+ );
12
+ const [successCount, setSuccessCount] = createSignal(
13
+ asyncDebouncer.getSuccessCount()
8
14
  );
9
15
  const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending());
16
+ const [lastResult, setLastResult] = createSignal(
17
+ asyncDebouncer.getLastResult()
18
+ );
10
19
  function setOptions(newOptions) {
11
20
  asyncDebouncer.setOptions({
12
21
  ...newOptions,
13
- onExecute: (asyncDebouncer2) => {
14
- setExecutionCount(asyncDebouncer2.getExecutionCount());
22
+ onSettled: (asyncDebouncer2) => {
23
+ setSuccessCount(asyncDebouncer2.getSuccessCount());
24
+ setErrorCount(asyncDebouncer2.getErrorCount());
25
+ setSettleCount(asyncDebouncer2.getSettleCount());
15
26
  setIsPending(asyncDebouncer2.getIsPending());
16
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
17
- onExecute == null ? void 0 : onExecute(asyncDebouncer2);
27
+ setLastResult(asyncDebouncer2.getLastResult());
28
+ const onSettled = newOptions.onSettled ?? initialOptions.onSettled;
29
+ onSettled == null ? void 0 : onSettled(asyncDebouncer2);
18
30
  }
19
31
  });
20
32
  }
21
33
  setOptions(initialOptions);
22
34
  return {
23
35
  ...bindInstanceMethods(asyncDebouncer),
24
- executionCount,
36
+ errorCount,
25
37
  isPending,
38
+ lastResult,
39
+ settleCount,
40
+ successCount,
26
41
  setOptions
27
42
  };
28
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncDebouncer.js","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"],"mappings":";;;AAqDgB,SAAA,qBAId,IACA,gBACiC;AACjC,QAAM,iBAAiB,IAAI,eAA2B,IAAI,cAAc;AAElE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,eAAe,kBAAkB;AAAA,EACnC;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AAE5E,WAAS,WAAW,YAAwD;AAC1E,mBAAe,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,GAAG,oBAAoB,cAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createAsyncDebouncer.js","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<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncDebouncer<TFn>,\n | 'getErrorCount'\n | 'getIsPending'\n | 'getLastResult'\n | 'getSettleCount'\n | 'getSuccessCount'\n > {\n errorCount: Accessor<number>\n isPending: Accessor<boolean>\n lastResult: Accessor<ReturnType<TFn> | undefined>\n settleCount: Accessor<number>\n successCount: Accessor<number>\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<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncDebouncerOptions<TFn>,\n): SolidAsyncDebouncer<TFn> {\n const asyncDebouncer = new AsyncDebouncer<TFn>(fn, initialOptions)\n\n const [errorCount, setErrorCount] = createSignal(\n asyncDebouncer.getErrorCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncDebouncer.getSettleCount(),\n )\n const [successCount, setSuccessCount] = createSignal(\n asyncDebouncer.getSuccessCount(),\n )\n const [isPending, setIsPending] = createSignal(asyncDebouncer.getIsPending())\n const [lastResult, setLastResult] = createSignal(\n asyncDebouncer.getLastResult(),\n )\n\n function setOptions(newOptions: Partial<AsyncDebouncerOptions<TFn>>) {\n asyncDebouncer.setOptions({\n ...newOptions,\n onSettled: (asyncDebouncer) => {\n setSuccessCount(asyncDebouncer.getSuccessCount())\n setErrorCount(asyncDebouncer.getErrorCount())\n setSettleCount(asyncDebouncer.getSettleCount())\n setIsPending(asyncDebouncer.getIsPending())\n setLastResult(asyncDebouncer.getLastResult())\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(asyncDebouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(asyncDebouncer),\n errorCount,\n isPending,\n lastResult,\n settleCount,\n successCount,\n setOptions,\n } as SolidAsyncDebouncer<TFn>\n}\n"],"names":["asyncDebouncer"],"mappings":";;;AA0DgB,SAAA,qBACd,IACA,gBAC0B;AAC1B,QAAM,iBAAiB,IAAI,eAAoB,IAAI,cAAc;AAE3D,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,eAAe,eAAe;AAAA,EAChC;AACM,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,eAAe,gBAAgB;AAAA,EACjC;AACA,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,eAAe,cAAc;AACtE,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,eAAe,cAAc;AAAA,EAC/B;AAEA,WAAS,WAAW,YAAiD;AACnE,mBAAe,WAAW;AAAA,MACxB,GAAG;AAAA,MACH,WAAW,CAACA,oBAAmB;AACbA,wBAAAA,gBAAe,iBAAiB;AAClCA,sBAAAA,gBAAe,eAAe;AAC7BA,uBAAAA,gBAAe,gBAAgB;AACjCA,qBAAAA,gBAAe,cAAc;AAC5BA,sBAAAA,gBAAe,eAAe;AACtC,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAc;AAAA,IAC5B,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAG,oBAAoB,cAAc;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -32,11 +32,15 @@ export interface SolidAsyncQueuer<TValue> extends Omit<AsyncQueuer<TValue>, 'get
32
32
  /**
33
33
  * Signal version of `getPeek`
34
34
  */
35
- peek: Accessor<TValue | undefined>;
35
+ peek: Accessor<(() => Promise<TValue>) | undefined>;
36
36
  /**
37
37
  * Signal version of `getPendingItems`
38
38
  */
39
39
  pendingItems: Accessor<Array<() => Promise<TValue>>>;
40
+ /**
41
+ * Signal version of `getRejectionCount`
42
+ */
43
+ rejectionCount: Accessor<number>;
40
44
  /**
41
45
  * Signal version of `getSize`
42
46
  */
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncQueuer.js","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":[],"mappings":";;;AA2GgB,SAAA,kBACd,iBAA6C,IACnB;AACpB,QAAA,cAAc,IAAI,YAAoB,cAAc;AAEpD,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,YAAY,YAAY;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,YAAY,cAAc;AACnE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,YAAY,YAAY;AAAA,EAC1B;AACA,QAAM,CAAC,aAAa,cAAc,IAAI,aAEpC,YAAY,gBAAgB;AAC9B,QAAM,CAAC,cAAc,eAAe,IAAI,aAEtC,YAAY,iBAAiB;AACzB,QAAA,CAAC,MAAM,OAAO,IAAI;AAAA,IACtB,YAAY,QAAQ;AAAA,EACtB;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,YAAY,SAAS;AAE1D,cAAY,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,GAAG,oBAAoB,WAAW;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;"}
1
+ {"version":3,"file":"createAsyncQueuer.js","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<(() => Promise<TValue>) | undefined>\n /**\n * Signal version of `getPendingItems`\n */\n pendingItems: Accessor<Array<() => Promise<TValue>>>\n /**\n * Signal version of `getRejectionCount`\n */\n rejectionCount: Accessor<number>\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 } as SolidAsyncQueuer<TValue>\n}\n"],"names":[],"mappings":";;;AA+GgB,SAAA,kBACd,iBAA6C,IACnB;AACpB,QAAA,cAAc,IAAI,YAAoB,cAAc;AAEpD,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,kBAAkB;AAAA,EAChC;AACA,QAAM,CAAC,SAAS,UAAU,IAAI,aAAa,YAAY,YAAY;AACnE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,QAAQ,SAAS,IAAI,aAAa,YAAY,WAAW;AAChE,QAAM,CAAC,WAAW,YAAY,IAAI,aAAa,YAAY,cAAc;AACnE,QAAA,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,YAAY,YAAY;AAAA,EAC1B;AACA,QAAM,CAAC,aAAa,cAAc,IAAI,aAEpC,YAAY,gBAAgB;AAC9B,QAAM,CAAC,cAAc,eAAe,IAAI,aAEtC,YAAY,iBAAiB;AACzB,QAAA,CAAC,MAAM,OAAO,IAAI;AAAA,IACtB,YAAY,QAAQ;AAAA,EACtB;AACA,QAAM,CAAC,MAAM,OAAO,IAAI,aAAa,YAAY,SAAS;AAE1D,cAAY,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,GAAG,oBAAoB,WAAW;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;"}
@@ -1,8 +1,10 @@
1
1
  import { AsyncRateLimiter, AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter';
2
2
  import { Accessor } from 'solid-js';
3
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>;
4
+ export interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction> extends Omit<AsyncRateLimiter<TFn>, 'getSuccessCount' | 'getSettleCount' | 'getErrorCount' | 'getRejectionCount' | 'getRemainingInWindow' | 'getMsUntilNextWindow'> {
5
+ successCount: Accessor<number>;
6
+ settleCount: Accessor<number>;
7
+ errorCount: Accessor<number>;
6
8
  rejectionCount: Accessor<number>;
7
9
  remainingInWindow: Accessor<number>;
8
10
  msUntilNextWindow: Accessor<number>;
@@ -43,4 +45,4 @@ export interface SolidAsyncRateLimiter<TFn extends AnyAsyncFunction, TArgs exten
43
45
  * );
44
46
  * ```
45
47
  */
46
- export declare function createAsyncRateLimiter<TFn extends AnyAsyncFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: AsyncRateLimiterOptions<TFn, TArgs>): SolidAsyncRateLimiter<TFn, TArgs>;
48
+ export declare function createAsyncRateLimiter<TFn extends AnyAsyncFunction>(fn: TFn, initialOptions: AsyncRateLimiterOptions<TFn>): SolidAsyncRateLimiter<TFn>;
@@ -3,12 +3,18 @@ import { createSignal } from "solid-js";
3
3
  import { bindInstanceMethods } from "@tanstack/pacer/utils";
4
4
  function createAsyncRateLimiter(fn, initialOptions) {
5
5
  const asyncRateLimiter = new AsyncRateLimiter(fn, initialOptions);
6
- const [executionCount, setExecutionCount] = createSignal(
7
- asyncRateLimiter.getExecutionCount()
6
+ const [successCount, setSuccessCount] = createSignal(
7
+ asyncRateLimiter.getSuccessCount()
8
8
  );
9
9
  const [rejectionCount, setRejectionCount] = createSignal(
10
10
  asyncRateLimiter.getRejectionCount()
11
11
  );
12
+ const [errorCount, setErrorCount] = createSignal(
13
+ asyncRateLimiter.getErrorCount()
14
+ );
15
+ const [settleCount, setSettleCount] = createSignal(
16
+ asyncRateLimiter.getSettleCount()
17
+ );
12
18
  const [remainingInWindow, setRemainingInWindow] = createSignal(
13
19
  asyncRateLimiter.getRemainingInWindow()
14
20
  );
@@ -18,12 +24,15 @@ function createAsyncRateLimiter(fn, initialOptions) {
18
24
  function setOptions(newOptions) {
19
25
  asyncRateLimiter.setOptions({
20
26
  ...newOptions,
21
- onExecute: (rateLimiter) => {
22
- setExecutionCount(rateLimiter.getExecutionCount());
27
+ onSettled: (rateLimiter) => {
28
+ setSuccessCount(rateLimiter.getSuccessCount());
29
+ setSettleCount(rateLimiter.getSettleCount());
30
+ setErrorCount(rateLimiter.getErrorCount());
31
+ setRejectionCount(rateLimiter.getRejectionCount());
23
32
  setRemainingInWindow(rateLimiter.getRemainingInWindow());
24
33
  setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow());
25
- const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
26
- onExecute == null ? void 0 : onExecute(rateLimiter);
34
+ const onSettled = newOptions.onSettled ?? initialOptions.onSettled;
35
+ onSettled == null ? void 0 : onSettled(rateLimiter);
27
36
  },
28
37
  onReject: (rateLimiter) => {
29
38
  setRejectionCount(rateLimiter.getRejectionCount());
@@ -37,11 +46,13 @@ function createAsyncRateLimiter(fn, initialOptions) {
37
46
  setOptions(initialOptions);
38
47
  return {
39
48
  ...bindInstanceMethods(asyncRateLimiter),
40
- executionCount,
41
- rejectionCount,
49
+ errorCount,
42
50
  remainingInWindow,
43
51
  msUntilNextWindow,
44
- setOptions
52
+ rejectionCount,
53
+ setOptions,
54
+ settleCount,
55
+ successCount
45
56
  };
46
57
  }
47
58
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncRateLimiter.js","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":[],"mappings":";;;AA2DgB,SAAA,uBAId,IACA,gBACmC;AACnC,QAAM,mBAAmB,IAAI,iBAA6B,IAAI,cAAc;AAEtE,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,iBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,iBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AAEA,WAAS,WACP,YACA;AACA,qBAAiB,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,GAAG,oBAAoB,gBAAgB;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"createAsyncRateLimiter.js","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<TFn extends AnyAsyncFunction>\n extends Omit<\n AsyncRateLimiter<TFn>,\n | 'getSuccessCount'\n | 'getSettleCount'\n | 'getErrorCount'\n | 'getRejectionCount'\n | 'getRemainingInWindow'\n | 'getMsUntilNextWindow'\n > {\n successCount: Accessor<number>\n settleCount: Accessor<number>\n errorCount: 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<TFn extends AnyAsyncFunction>(\n fn: TFn,\n initialOptions: AsyncRateLimiterOptions<TFn>,\n): SolidAsyncRateLimiter<TFn> {\n const asyncRateLimiter = new AsyncRateLimiter<TFn>(fn, initialOptions)\n\n const [successCount, setSuccessCount] = createSignal(\n asyncRateLimiter.getSuccessCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n asyncRateLimiter.getRejectionCount(),\n )\n const [errorCount, setErrorCount] = createSignal(\n asyncRateLimiter.getErrorCount(),\n )\n const [settleCount, setSettleCount] = createSignal(\n asyncRateLimiter.getSettleCount(),\n )\n const [remainingInWindow, setRemainingInWindow] = createSignal(\n asyncRateLimiter.getRemainingInWindow(),\n )\n const [msUntilNextWindow, setMsUntilNextWindow] = createSignal(\n asyncRateLimiter.getMsUntilNextWindow(),\n )\n\n function setOptions(newOptions: Partial<AsyncRateLimiterOptions<TFn>>) {\n asyncRateLimiter.setOptions({\n ...newOptions,\n onSettled: (rateLimiter) => {\n setSuccessCount(rateLimiter.getSuccessCount())\n setSettleCount(rateLimiter.getSettleCount())\n setErrorCount(rateLimiter.getErrorCount())\n setRejectionCount(rateLimiter.getRejectionCount())\n setRemainingInWindow(rateLimiter.getRemainingInWindow())\n setMsUntilNextWindow(rateLimiter.getMsUntilNextWindow())\n\n const onSettled = newOptions.onSettled ?? initialOptions.onSettled\n onSettled?.(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 errorCount,\n remainingInWindow,\n msUntilNextWindow,\n rejectionCount,\n setOptions,\n settleCount,\n successCount,\n } as SolidAsyncRateLimiter<TFn>\n}\n"],"names":[],"mappings":";;;AA6DgB,SAAA,uBACd,IACA,gBAC4B;AAC5B,QAAM,mBAAmB,IAAI,iBAAsB,IAAI,cAAc;AAE/D,QAAA,CAAC,cAAc,eAAe,IAAI;AAAA,IACtC,iBAAiB,gBAAgB;AAAA,EACnC;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,iBAAiB,kBAAkB;AAAA,EACrC;AACM,QAAA,CAAC,YAAY,aAAa,IAAI;AAAA,IAClC,iBAAiB,cAAc;AAAA,EACjC;AACM,QAAA,CAAC,aAAa,cAAc,IAAI;AAAA,IACpC,iBAAiB,eAAe;AAAA,EAClC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AACM,QAAA,CAAC,mBAAmB,oBAAoB,IAAI;AAAA,IAChD,iBAAiB,qBAAqB;AAAA,EACxC;AAEA,WAAS,WAAW,YAAmD;AACrE,qBAAiB,WAAW;AAAA,MAC1B,GAAG;AAAA,MACH,WAAW,CAAC,gBAAgB;AACV,wBAAA,YAAY,iBAAiB;AAC9B,uBAAA,YAAY,gBAAgB;AAC7B,sBAAA,YAAY,eAAe;AACvB,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,GAAG,oBAAoB,gBAAgB;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;"}