@tanstack/solid-pacer 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +21 -6
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -15
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -5
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -7
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -9
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -5
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -7
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -7
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -7
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -9
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +24 -68
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -178
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -164
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -170
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -209
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -164
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -147
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -80
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -71
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -145
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -29
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -122
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -148
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -94
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -96
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -174
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -71
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -68
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -148
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -9
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -9
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
@@ -1,94 +0,0 @@
1
- import { SolidRateLimiter, SolidRateLimiterOptions } from "./createRateLimiter.cjs";
2
- import { Accessor, Setter } from "solid-js";
3
- import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
- //#region src/rate-limiter/createRateLimitedSignal.d.ts
6
- /**
7
- * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
8
- * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
9
- *
10
- * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
11
- * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
12
- * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
13
- *
14
- * The rate limiter supports two types of windows:
15
- * - 'fixed': A strict window that resets after the window period. All updates within the window count
16
- * towards the limit, and the window resets completely after the period.
17
- * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
18
- * consistent rate of updates over time.
19
- *
20
- * For smoother update patterns, consider:
21
- * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
22
- * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
23
- *
24
- * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
25
- *
26
- * The hook returns a tuple containing:
27
- * - The rate-limited state value accessor
28
- * - A rate-limited setter function that respects the configured limits
29
- * - The rateLimiter instance for additional control
30
- *
31
- * For more direct control over rate limiting without state management,
32
- * consider using the lower-level createRateLimiter hook instead.
33
- *
34
- * ## State Management and Selector
35
- *
36
- * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
37
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
38
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
39
- *
40
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
41
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
42
- * full control over when your component subscribes to state changes. Only when you provide a selector will
43
- * the reactive system track the selected state values.
44
- *
45
- * Available rate limiter state properties:
46
- * - `callsInWindow`: Number of calls made in the current window
47
- * - `remainingInWindow`: Number of calls remaining in the current window
48
- * - `windowStart`: Unix timestamp when the current window started
49
- * - `nextWindowStart`: Unix timestamp when the next window will start
50
- * - `msUntilNextWindow`: Milliseconds until the next window starts
51
- * - `isAtLimit`: Whether the call limit for the current window has been reached
52
- * - `status`: Current status ('disabled' | 'idle' | 'at-limit')
53
- *
54
- * @example
55
- * ```tsx
56
- * // Default behavior - no reactive state subscriptions
57
- * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
58
- * limit: 5,
59
- * window: 60000,
60
- * windowType: 'sliding'
61
- * });
62
- *
63
- * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
64
- * const [value, setValue, rateLimiter] = createRateLimitedSignal(
65
- * 0,
66
- * { limit: 5, window: 60000 },
67
- * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
68
- * );
69
- *
70
- * // With rejection callback and fixed window
71
- * const [value, setValue] = createRateLimitedSignal(0, {
72
- * limit: 3,
73
- * window: 5000,
74
- * windowType: 'fixed',
75
- * onReject: (rateLimiter) => {
76
- * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
77
- * }
78
- * });
79
- *
80
- * // Access rateLimiter state via signals
81
- * const handleSubmit = () => {
82
- * const remaining = rateLimiter.state().remainingInWindow;
83
- * if (remaining > 0) {
84
- * setValue(newValue);
85
- * } else {
86
- * showRateLimitWarning();
87
- * }
88
- * };
89
- * ```
90
- */
91
- declare function createRateLimitedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
92
- //#endregion
93
- export { createRateLimitedSignal };
94
- //# sourceMappingURL=createRateLimitedSignal.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRateLimitedSignal.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } 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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `callsInWindow`: Number of calls made in the current window\n * - `remainingInWindow`: Number of calls remaining in the current window\n * - `windowStart`: Unix timestamp when the current window started\n * - `nextWindowStart`: Unix timestamp when the next window will start\n * - `msUntilNextWindow`: Milliseconds until the next window starts\n * - `isAtLimit`: Whether the call limit for the current window has been reached\n * - `status`: Current status ('disabled' | 'idle' | 'at-limit')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(\n * 0,\n * { limit: 5, window: 60000 },\n * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })\n * );\n *\n * // With rejection callback and fixed window\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\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.state().remainingInWindow;\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, TSelected>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(\n setRateLimitedValue,\n initialOptions,\n selector,\n )\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8FA,SAAgB,wBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,kBAAkB,uBAAuB,aAAqB,MAAM;CAE3E,MAAM,cAAc,kBAClB,qBACA,gBACA,SACD;CAED,OAAO;EACL;EACA,YAAY;EACZ;EACD"}
@@ -1,102 +0,0 @@
1
- const require_createRateLimitedSignal = require('./createRateLimitedSignal.cjs');
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/rate-limiter/createRateLimitedValue.ts
5
- /**
6
- * 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.
7
- * This hook uses Solid's createSignal internally to manage the rate-limited state.
8
- *
9
- * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
10
- * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
11
- * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
12
- *
13
- * The rate limiter supports two types of windows:
14
- * - 'fixed': A strict window that resets after the window period. All updates within the window count
15
- * towards the limit, and the window resets completely after the period.
16
- * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
17
- * consistent rate of updates over time.
18
- *
19
- * For smoother update patterns, consider:
20
- * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
21
- * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
22
- *
23
- * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
24
- *
25
- * The hook returns a tuple containing:
26
- * - An accessor function that provides the rate-limited value
27
- * - The rate limiter instance with control methods
28
- *
29
- * For more direct control over rate limiting behavior without Solid state management,
30
- * consider using the lower-level createRateLimiter hook instead.
31
- *
32
- * ## State Management and Selector
33
- *
34
- * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
35
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
36
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
37
- *
38
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
39
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
40
- * full control over when your component subscribes to state changes. Only when you provide a selector will
41
- * the reactive system track the selected state values.
42
- *
43
- * Available rate limiter state properties:
44
- * - `executionCount`: Number of function executions that have been completed
45
- * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
46
- * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
47
- *
48
- * @example
49
- * ```tsx
50
- * // Default behavior - no reactive state subscriptions
51
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
52
- * limit: 5,
53
- * window: 60000,
54
- * windowType: 'sliding'
55
- * });
56
- *
57
- * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
58
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
59
- * rawValue,
60
- * { limit: 5, window: 60000, windowType: 'sliding' },
61
- * (state) => ({ executionCount: state.executionCount })
62
- * );
63
- *
64
- * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
65
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
66
- * rawValue,
67
- * { limit: 5, window: 60000, windowType: 'sliding' },
68
- * (state) => ({ rejectionCount: state.rejectionCount })
69
- * );
70
- *
71
- * // Opt-in to reactive updates when execution times change (optimized for window calculations)
72
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
73
- * rawValue,
74
- * { limit: 5, window: 60000, windowType: 'sliding' },
75
- * (state) => ({ executionTimes: state.executionTimes })
76
- * );
77
- *
78
- * // With rejection callback and fixed window
79
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
80
- * limit: 3,
81
- * window: 5000,
82
- * windowType: 'fixed',
83
- * onReject: (rateLimiter) => {
84
- * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
85
- * }
86
- * });
87
- *
88
- * // Access the selected rate limiter state (will be empty object {} unless selector provided)
89
- * const { executionCount, rejectionCount } = rateLimiter.state;
90
- * ```
91
- */
92
- function createRateLimitedValue(value, initialOptions, selector) {
93
- const [rateLimitedValue, setRateLimitedValue, rateLimiter] = require_createRateLimitedSignal.createRateLimitedSignal(value(), initialOptions, selector);
94
- (0, solid_js.createEffect)(() => {
95
- setRateLimitedValue(value());
96
- });
97
- return [rateLimitedValue, rateLimiter];
98
- }
99
-
100
- //#endregion
101
- exports.createRateLimitedValue = createRateLimitedValue;
102
- //# sourceMappingURL=createRateLimitedValue.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRateLimitedValue.cjs","names":["createRateLimitedSignal"],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } 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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5CA,wDAAwB,OAAO,EAAE,gBAAgB,SAAS;CAE5D,iCAAmB;EACjB,oBAAoB,OAAO,CAAQ;GACnC;CAEF,OAAO,CAAC,kBAAkB,YAAY"}
@@ -1,96 +0,0 @@
1
- import { SolidRateLimiter, SolidRateLimiterOptions } from "./createRateLimiter.cjs";
2
- import { Accessor, Setter } from "solid-js";
3
- import { RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
-
5
- //#region src/rate-limiter/createRateLimitedValue.d.ts
6
- /**
7
- * 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.
8
- * This hook uses Solid's createSignal internally to manage the rate-limited state.
9
- *
10
- * Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
11
- * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
12
- * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
13
- *
14
- * The rate limiter supports two types of windows:
15
- * - 'fixed': A strict window that resets after the window period. All updates within the window count
16
- * towards the limit, and the window resets completely after the period.
17
- * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
18
- * consistent rate of updates over time.
19
- *
20
- * For smoother update patterns, consider:
21
- * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
22
- * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
23
- *
24
- * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
25
- *
26
- * The hook returns a tuple containing:
27
- * - An accessor function that provides the rate-limited value
28
- * - The rate limiter instance with control methods
29
- *
30
- * For more direct control over rate limiting behavior without Solid state management,
31
- * consider using the lower-level createRateLimiter hook instead.
32
- *
33
- * ## State Management and Selector
34
- *
35
- * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
36
- * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
37
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
38
- *
39
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
40
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
41
- * full control over when your component subscribes to state changes. Only when you provide a selector will
42
- * the reactive system track the selected state values.
43
- *
44
- * Available rate limiter state properties:
45
- * - `executionCount`: Number of function executions that have been completed
46
- * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
47
- * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
48
- *
49
- * @example
50
- * ```tsx
51
- * // Default behavior - no reactive state subscriptions
52
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
53
- * limit: 5,
54
- * window: 60000,
55
- * windowType: 'sliding'
56
- * });
57
- *
58
- * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
59
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
60
- * rawValue,
61
- * { limit: 5, window: 60000, windowType: 'sliding' },
62
- * (state) => ({ executionCount: state.executionCount })
63
- * );
64
- *
65
- * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
66
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
67
- * rawValue,
68
- * { limit: 5, window: 60000, windowType: 'sliding' },
69
- * (state) => ({ rejectionCount: state.rejectionCount })
70
- * );
71
- *
72
- * // Opt-in to reactive updates when execution times change (optimized for window calculations)
73
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
74
- * rawValue,
75
- * { limit: 5, window: 60000, windowType: 'sliding' },
76
- * (state) => ({ executionTimes: state.executionTimes })
77
- * );
78
- *
79
- * // With rejection callback and fixed window
80
- * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
81
- * limit: 3,
82
- * window: 5000,
83
- * windowType: 'fixed',
84
- * onReject: (rateLimiter) => {
85
- * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
86
- * }
87
- * });
88
- *
89
- * // Access the selected rate limiter state (will be empty object {} unless selector provided)
90
- * const { executionCount, rejectionCount } = rateLimiter.state;
91
- * ```
92
- */
93
- declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
94
- //#endregion
95
- export { createRateLimitedValue };
96
- //# sourceMappingURL=createRateLimitedValue.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type {\n SolidRateLimiter,\n SolidRateLimiterOptions,\n} from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterState } 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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidRateLimiterOptions<Setter<TValue>, TSelected>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5C,wBAAwB,OAAO,EAAE,gBAAgB,SAAS;CAE5D,mBAAmB;EACjB,oBAAoB,OAAO,CAAQ;GACnC;CAEF,OAAO,CAAC,kBAAkB,YAAY"}
@@ -1,157 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_solid_store = require("@tanstack/solid-store");
4
- let _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
5
-
6
- //#region src/rate-limiter/createRateLimiter.ts
7
- /**
8
- * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
9
- *
10
- * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
11
- * you can integrate with any state management solution (createSignal, etc).
12
- *
13
- * Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
14
- * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
15
- * it does not attempt to space out or collapse executions intelligently.
16
- *
17
- * The rate limiter supports two types of windows:
18
- * - 'fixed': A strict window that resets after the window period. All executions within the window count
19
- * towards the limit, and the window resets completely after the period.
20
- * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
21
- * consistent rate of execution over time.
22
- *
23
- * For smoother execution patterns:
24
- * - Use throttling when you want consistent spacing between executions (e.g. UI updates)
25
- * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
26
- * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
27
- *
28
- * ## State Management and Selector
29
- *
30
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
31
- * in two ways:
32
- *
33
- * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
34
- *
35
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
36
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
37
- * in child components.
38
- *
39
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
40
- *
41
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
42
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
43
- * state changes occur.
44
- *
45
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
46
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
47
- * updates and gives you full control over when your component tracks state changes.
48
- *
49
- * Available state properties:
50
- * - `executionCount`: Number of function executions that have been completed
51
- * - `rejectionCount`: Number of function calls that were rejected due to rate limiting
52
- * - `remainingInWindow`: Number of executions remaining in the current window
53
- * - `nextWindowTime`: Timestamp when the next window begins
54
- * - `currentWindowStart`: Timestamp when the current window started
55
- *
56
- * @example
57
- * ```tsx
58
- * // Default behavior - no reactive state subscriptions
59
- * const rateLimiter = createRateLimiter(apiCall, {
60
- * limit: 5,
61
- * window: 60000,
62
- * windowType: 'sliding',
63
- * });
64
- *
65
- * // Subscribe to state changes deep in component tree using Subscribe component
66
- * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
67
- * {(state) => (
68
- * <div>Rejections: {state().rejectionCount}</div>
69
- * )}
70
- * </rateLimiter.Subscribe>
71
- *
72
- * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)
73
- * const rateLimiter = createRateLimiter(
74
- * apiCall,
75
- * {
76
- * limit: 5,
77
- * window: 60000,
78
- * windowType: 'sliding',
79
- * },
80
- * (state) => ({ executionCount: state.executionCount })
81
- * );
82
- *
83
- * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)
84
- * const rateLimiter = createRateLimiter(
85
- * apiCall,
86
- * {
87
- * limit: 5,
88
- * window: 60000,
89
- * windowType: 'sliding',
90
- * },
91
- * (state) => ({ rejectionCount: state.rejectionCount })
92
- * );
93
- *
94
- * // Opt-in to track execution times changes (optimized for window calculations)
95
- * const rateLimiter = createRateLimiter(
96
- * apiCall,
97
- * {
98
- * limit: 5,
99
- * window: 60000,
100
- * windowType: 'sliding',
101
- * },
102
- * (state) => ({ executionTimes: state.executionTimes })
103
- * );
104
- *
105
- * // Multiple state properties - track when any of these change
106
- * const rateLimiter = createRateLimiter(
107
- * apiCall,
108
- * {
109
- * limit: 5,
110
- * window: 60000,
111
- * windowType: 'sliding',
112
- * },
113
- * (state) => ({
114
- * executionCount: state.executionCount,
115
- * rejectionCount: state.rejectionCount
116
- * })
117
- * );
118
- *
119
- * // Monitor rate limit status
120
- * const handleClick = () => {
121
- * const remaining = rateLimiter.getRemainingInWindow();
122
- * if (remaining > 0) {
123
- * rateLimiter.maybeExecute(data);
124
- * } else {
125
- * showRateLimitWarning();
126
- * }
127
- * };
128
- *
129
- * // Access the selected state (will be empty object {} unless selector provided)
130
- * const { executionCount, rejectionCount } = rateLimiter.state();
131
- * ```
132
- */
133
- function createRateLimiter(fn, options, selector = () => ({})) {
134
- const mergedOptions = {
135
- ...require_PacerProvider.useDefaultPacerOptions().rateLimiter,
136
- ...options
137
- };
138
- const rateLimiter = new _tanstack_pacer_rate_limiter.RateLimiter(fn, mergedOptions);
139
- rateLimiter.Subscribe = function Subscribe(props) {
140
- const selected = (0, _tanstack_solid_store.useSelector)(rateLimiter.store, props.selector, { compare: _tanstack_solid_store.shallow });
141
- return typeof props.children === "function" ? props.children(selected) : props.children;
142
- };
143
- const state = (0, _tanstack_solid_store.useSelector)(rateLimiter.store, selector, { compare: _tanstack_solid_store.shallow });
144
- (0, solid_js.createEffect)(() => {
145
- (0, solid_js.onCleanup)(() => {
146
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(rateLimiter);
147
- });
148
- });
149
- return {
150
- ...rateLimiter,
151
- state
152
- };
153
- }
154
-
155
- //#endregion
156
- exports.createRateLimiter = createRateLimiter;
157
- //# sourceMappingURL=createRateLimiter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRateLimiter.cjs","names":["useDefaultPacerOptions","RateLimiter","shallow"],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\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 * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(rateLimiter.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(rateLimiter.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAIC,yCACtB,IACA,cACD;CAED,YAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,kDAAuB,YAAY,OAAO,MAAM,UAAU,EAC9D,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,YAAY,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;CAE5E,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,YAAY;IAEtC;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}