@tanstack/angular-pacer 0.20.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 (280) hide show
  1. package/README.md +165 -0
  2. package/dist/async-batcher/index.cjs +13 -0
  3. package/dist/async-batcher/index.d.cts +4 -0
  4. package/dist/async-batcher/index.d.ts +4 -0
  5. package/dist/async-batcher/index.js +6 -0
  6. package/dist/async-batcher/injectAsyncBatchedCallback.cjs +49 -0
  7. package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +1 -0
  8. package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +45 -0
  9. package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +45 -0
  10. package/dist/async-batcher/injectAsyncBatchedCallback.js +49 -0
  11. package/dist/async-batcher/injectAsyncBatchedCallback.js.map +1 -0
  12. package/dist/async-batcher/injectAsyncBatcher.cjs +61 -0
  13. package/dist/async-batcher/injectAsyncBatcher.cjs.map +1 -0
  14. package/dist/async-batcher/injectAsyncBatcher.d.cts +63 -0
  15. package/dist/async-batcher/injectAsyncBatcher.d.ts +63 -0
  16. package/dist/async-batcher/injectAsyncBatcher.js +61 -0
  17. package/dist/async-batcher/injectAsyncBatcher.js.map +1 -0
  18. package/dist/async-debouncer/index.cjs +13 -0
  19. package/dist/async-debouncer/index.d.cts +4 -0
  20. package/dist/async-debouncer/index.d.ts +4 -0
  21. package/dist/async-debouncer/index.js +6 -0
  22. package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +49 -0
  23. package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +1 -0
  24. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +43 -0
  25. package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +43 -0
  26. package/dist/async-debouncer/injectAsyncDebouncedCallback.js +49 -0
  27. package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +1 -0
  28. package/dist/async-debouncer/injectAsyncDebouncer.cjs +83 -0
  29. package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +1 -0
  30. package/dist/async-debouncer/injectAsyncDebouncer.d.cts +86 -0
  31. package/dist/async-debouncer/injectAsyncDebouncer.d.ts +86 -0
  32. package/dist/async-debouncer/injectAsyncDebouncer.js +83 -0
  33. package/dist/async-debouncer/injectAsyncDebouncer.js.map +1 -0
  34. package/dist/async-queuer/index.cjs +13 -0
  35. package/dist/async-queuer/index.d.cts +4 -0
  36. package/dist/async-queuer/index.d.ts +4 -0
  37. package/dist/async-queuer/index.js +6 -0
  38. package/dist/async-queuer/injectAsyncQueuedSignal.cjs +53 -0
  39. package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +1 -0
  40. package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +55 -0
  41. package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +55 -0
  42. package/dist/async-queuer/injectAsyncQueuedSignal.js +53 -0
  43. package/dist/async-queuer/injectAsyncQueuedSignal.js.map +1 -0
  44. package/dist/async-queuer/injectAsyncQueuer.cjs +61 -0
  45. package/dist/async-queuer/injectAsyncQueuer.cjs.map +1 -0
  46. package/dist/async-queuer/injectAsyncQueuer.d.cts +63 -0
  47. package/dist/async-queuer/injectAsyncQueuer.d.ts +63 -0
  48. package/dist/async-queuer/injectAsyncQueuer.js +61 -0
  49. package/dist/async-queuer/injectAsyncQueuer.js.map +1 -0
  50. package/dist/async-rate-limiter/index.cjs +13 -0
  51. package/dist/async-rate-limiter/index.d.cts +4 -0
  52. package/dist/async-rate-limiter/index.d.ts +4 -0
  53. package/dist/async-rate-limiter/index.js +6 -0
  54. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +52 -0
  55. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +1 -0
  56. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +46 -0
  57. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +46 -0
  58. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +52 -0
  59. package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +1 -0
  60. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +57 -0
  61. package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +1 -0
  62. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +60 -0
  63. package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +60 -0
  64. package/dist/async-rate-limiter/injectAsyncRateLimiter.js +57 -0
  65. package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +1 -0
  66. package/dist/async-retryer/index.cjs +9 -0
  67. package/dist/async-retryer/index.d.cts +1 -0
  68. package/dist/async-retryer/index.d.ts +1 -0
  69. package/dist/async-retryer/index.js +3 -0
  70. package/dist/async-throttler/index.cjs +13 -0
  71. package/dist/async-throttler/index.d.cts +4 -0
  72. package/dist/async-throttler/index.d.ts +4 -0
  73. package/dist/async-throttler/index.js +6 -0
  74. package/dist/async-throttler/injectAsyncThrottledCallback.cjs +50 -0
  75. package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +1 -0
  76. package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +44 -0
  77. package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +44 -0
  78. package/dist/async-throttler/injectAsyncThrottledCallback.js +50 -0
  79. package/dist/async-throttler/injectAsyncThrottledCallback.js.map +1 -0
  80. package/dist/async-throttler/injectAsyncThrottler.cjs +62 -0
  81. package/dist/async-throttler/injectAsyncThrottler.cjs.map +1 -0
  82. package/dist/async-throttler/injectAsyncThrottler.d.cts +65 -0
  83. package/dist/async-throttler/injectAsyncThrottler.d.ts +65 -0
  84. package/dist/async-throttler/injectAsyncThrottler.js +62 -0
  85. package/dist/async-throttler/injectAsyncThrottler.js.map +1 -0
  86. package/dist/batcher/index.cjs +13 -0
  87. package/dist/batcher/index.d.cts +4 -0
  88. package/dist/batcher/index.d.ts +4 -0
  89. package/dist/batcher/index.js +6 -0
  90. package/dist/batcher/injectBatchedCallback.cjs +47 -0
  91. package/dist/batcher/injectBatchedCallback.cjs.map +1 -0
  92. package/dist/batcher/injectBatchedCallback.d.cts +43 -0
  93. package/dist/batcher/injectBatchedCallback.d.ts +43 -0
  94. package/dist/batcher/injectBatchedCallback.js +47 -0
  95. package/dist/batcher/injectBatchedCallback.js.map +1 -0
  96. package/dist/batcher/injectBatcher.cjs +56 -0
  97. package/dist/batcher/injectBatcher.cjs.map +1 -0
  98. package/dist/batcher/injectBatcher.d.cts +58 -0
  99. package/dist/batcher/injectBatcher.d.ts +58 -0
  100. package/dist/batcher/injectBatcher.js +56 -0
  101. package/dist/batcher/injectBatcher.js.map +1 -0
  102. package/dist/debouncer/index.cjs +17 -0
  103. package/dist/debouncer/index.d.cts +6 -0
  104. package/dist/debouncer/index.d.ts +6 -0
  105. package/dist/debouncer/index.js +8 -0
  106. package/dist/debouncer/injectDebouncedCallback.cjs +46 -0
  107. package/dist/debouncer/injectDebouncedCallback.cjs.map +1 -0
  108. package/dist/debouncer/injectDebouncedCallback.d.cts +43 -0
  109. package/dist/debouncer/injectDebouncedCallback.d.ts +43 -0
  110. package/dist/debouncer/injectDebouncedCallback.js +46 -0
  111. package/dist/debouncer/injectDebouncedCallback.js.map +1 -0
  112. package/dist/debouncer/injectDebouncedSignal.cjs +68 -0
  113. package/dist/debouncer/injectDebouncedSignal.cjs.map +1 -0
  114. package/dist/debouncer/injectDebouncedSignal.d.cts +65 -0
  115. package/dist/debouncer/injectDebouncedSignal.d.ts +65 -0
  116. package/dist/debouncer/injectDebouncedSignal.js +68 -0
  117. package/dist/debouncer/injectDebouncedSignal.js.map +1 -0
  118. package/dist/debouncer/injectDebouncedValue.cjs +17 -0
  119. package/dist/debouncer/injectDebouncedValue.cjs.map +1 -0
  120. package/dist/debouncer/injectDebouncedValue.d.cts +76 -0
  121. package/dist/debouncer/injectDebouncedValue.d.ts +76 -0
  122. package/dist/debouncer/injectDebouncedValue.js +17 -0
  123. package/dist/debouncer/injectDebouncedValue.js.map +1 -0
  124. package/dist/debouncer/injectDebouncer.cjs +76 -0
  125. package/dist/debouncer/injectDebouncer.cjs.map +1 -0
  126. package/dist/debouncer/injectDebouncer.d.cts +79 -0
  127. package/dist/debouncer/injectDebouncer.d.ts +79 -0
  128. package/dist/debouncer/injectDebouncer.js +76 -0
  129. package/dist/debouncer/injectDebouncer.js.map +1 -0
  130. package/dist/index.cjs +65 -0
  131. package/dist/index.d.cts +30 -0
  132. package/dist/index.d.ts +30 -0
  133. package/dist/index.js +32 -0
  134. package/dist/provider/index.cjs +7 -0
  135. package/dist/provider/index.d.cts +3 -0
  136. package/dist/provider/index.d.ts +3 -0
  137. package/dist/provider/index.js +4 -0
  138. package/dist/provider/pacer-context.cjs +20 -0
  139. package/dist/provider/pacer-context.cjs.map +1 -0
  140. package/dist/provider/pacer-context.d.cts +21 -0
  141. package/dist/provider/pacer-context.d.ts +21 -0
  142. package/dist/provider/pacer-context.js +19 -0
  143. package/dist/provider/pacer-context.js.map +1 -0
  144. package/dist/provider/pacer-provider.cjs +41 -0
  145. package/dist/provider/pacer-provider.cjs.map +1 -0
  146. package/dist/provider/pacer-provider.d.cts +36 -0
  147. package/dist/provider/pacer-provider.d.ts +36 -0
  148. package/dist/provider/pacer-provider.js +41 -0
  149. package/dist/provider/pacer-provider.js.map +1 -0
  150. package/dist/queuer/index.cjs +15 -0
  151. package/dist/queuer/index.d.cts +5 -0
  152. package/dist/queuer/index.d.ts +5 -0
  153. package/dist/queuer/index.js +7 -0
  154. package/dist/queuer/injectQueuedSignal.cjs +47 -0
  155. package/dist/queuer/injectQueuedSignal.cjs.map +1 -0
  156. package/dist/queuer/injectQueuedSignal.d.cts +49 -0
  157. package/dist/queuer/injectQueuedSignal.d.ts +49 -0
  158. package/dist/queuer/injectQueuedSignal.js +47 -0
  159. package/dist/queuer/injectQueuedSignal.js.map +1 -0
  160. package/dist/queuer/injectQueuedValue.cjs +23 -0
  161. package/dist/queuer/injectQueuedValue.cjs.map +1 -0
  162. package/dist/queuer/injectQueuedValue.d.cts +34 -0
  163. package/dist/queuer/injectQueuedValue.d.ts +34 -0
  164. package/dist/queuer/injectQueuedValue.js +23 -0
  165. package/dist/queuer/injectQueuedValue.js.map +1 -0
  166. package/dist/queuer/injectQueuer.cjs +61 -0
  167. package/dist/queuer/injectQueuer.cjs.map +1 -0
  168. package/dist/queuer/injectQueuer.d.cts +63 -0
  169. package/dist/queuer/injectQueuer.d.ts +63 -0
  170. package/dist/queuer/injectQueuer.js +61 -0
  171. package/dist/queuer/injectQueuer.js.map +1 -0
  172. package/dist/rate-limiter/index.cjs +17 -0
  173. package/dist/rate-limiter/index.d.cts +6 -0
  174. package/dist/rate-limiter/index.d.ts +6 -0
  175. package/dist/rate-limiter/index.js +8 -0
  176. package/dist/rate-limiter/injectRateLimitedCallback.cjs +45 -0
  177. package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +1 -0
  178. package/dist/rate-limiter/injectRateLimitedCallback.d.cts +42 -0
  179. package/dist/rate-limiter/injectRateLimitedCallback.d.ts +42 -0
  180. package/dist/rate-limiter/injectRateLimitedCallback.js +45 -0
  181. package/dist/rate-limiter/injectRateLimitedCallback.js.map +1 -0
  182. package/dist/rate-limiter/injectRateLimitedSignal.cjs +62 -0
  183. package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +1 -0
  184. package/dist/rate-limiter/injectRateLimitedSignal.d.cts +59 -0
  185. package/dist/rate-limiter/injectRateLimitedSignal.d.ts +59 -0
  186. package/dist/rate-limiter/injectRateLimitedSignal.js +62 -0
  187. package/dist/rate-limiter/injectRateLimitedSignal.js.map +1 -0
  188. package/dist/rate-limiter/injectRateLimitedValue.cjs +17 -0
  189. package/dist/rate-limiter/injectRateLimitedValue.cjs.map +1 -0
  190. package/dist/rate-limiter/injectRateLimitedValue.d.cts +49 -0
  191. package/dist/rate-limiter/injectRateLimitedValue.d.ts +49 -0
  192. package/dist/rate-limiter/injectRateLimitedValue.js +17 -0
  193. package/dist/rate-limiter/injectRateLimitedValue.js.map +1 -0
  194. package/dist/rate-limiter/injectRateLimiter.cjs +90 -0
  195. package/dist/rate-limiter/injectRateLimiter.cjs.map +1 -0
  196. package/dist/rate-limiter/injectRateLimiter.d.cts +93 -0
  197. package/dist/rate-limiter/injectRateLimiter.d.ts +93 -0
  198. package/dist/rate-limiter/injectRateLimiter.js +90 -0
  199. package/dist/rate-limiter/injectRateLimiter.js.map +1 -0
  200. package/dist/throttler/index.cjs +17 -0
  201. package/dist/throttler/index.d.cts +6 -0
  202. package/dist/throttler/index.d.ts +6 -0
  203. package/dist/throttler/index.js +8 -0
  204. package/dist/throttler/injectThrottledCallback.cjs +45 -0
  205. package/dist/throttler/injectThrottledCallback.cjs.map +1 -0
  206. package/dist/throttler/injectThrottledCallback.d.cts +42 -0
  207. package/dist/throttler/injectThrottledCallback.d.ts +42 -0
  208. package/dist/throttler/injectThrottledCallback.js +45 -0
  209. package/dist/throttler/injectThrottledCallback.js.map +1 -0
  210. package/dist/throttler/injectThrottledSignal.cjs +69 -0
  211. package/dist/throttler/injectThrottledSignal.cjs.map +1 -0
  212. package/dist/throttler/injectThrottledSignal.d.cts +66 -0
  213. package/dist/throttler/injectThrottledSignal.d.ts +66 -0
  214. package/dist/throttler/injectThrottledSignal.js +69 -0
  215. package/dist/throttler/injectThrottledSignal.js.map +1 -0
  216. package/dist/throttler/injectThrottledValue.cjs +17 -0
  217. package/dist/throttler/injectThrottledValue.cjs.map +1 -0
  218. package/dist/throttler/injectThrottledValue.d.cts +74 -0
  219. package/dist/throttler/injectThrottledValue.d.ts +74 -0
  220. package/dist/throttler/injectThrottledValue.js +17 -0
  221. package/dist/throttler/injectThrottledValue.js.map +1 -0
  222. package/dist/throttler/injectThrottler.cjs +76 -0
  223. package/dist/throttler/injectThrottler.cjs.map +1 -0
  224. package/dist/throttler/injectThrottler.d.cts +79 -0
  225. package/dist/throttler/injectThrottler.d.ts +79 -0
  226. package/dist/throttler/injectThrottler.js +76 -0
  227. package/dist/throttler/injectThrottler.js.map +1 -0
  228. package/dist/types/index.cjs +9 -0
  229. package/dist/types/index.d.cts +1 -0
  230. package/dist/types/index.d.ts +1 -0
  231. package/dist/types/index.js +3 -0
  232. package/dist/utils/index.cjs +9 -0
  233. package/dist/utils/index.d.cts +1 -0
  234. package/dist/utils/index.d.ts +1 -0
  235. package/dist/utils/index.js +3 -0
  236. package/package.json +121 -0
  237. package/src/async-batcher/index.ts +4 -0
  238. package/src/async-batcher/injectAsyncBatchedCallback.ts +48 -0
  239. package/src/async-batcher/injectAsyncBatcher.ts +87 -0
  240. package/src/async-debouncer/index.ts +4 -0
  241. package/src/async-debouncer/injectAsyncDebouncedCallback.ts +50 -0
  242. package/src/async-debouncer/injectAsyncDebouncer.ts +113 -0
  243. package/src/async-queuer/index.ts +4 -0
  244. package/src/async-queuer/injectAsyncQueuedSignal.ts +82 -0
  245. package/src/async-queuer/injectAsyncQueuer.ts +87 -0
  246. package/src/async-rate-limiter/index.ts +4 -0
  247. package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +52 -0
  248. package/src/async-rate-limiter/injectAsyncRateLimiter.ts +87 -0
  249. package/src/async-retryer/index.ts +1 -0
  250. package/src/async-throttler/index.ts +4 -0
  251. package/src/async-throttler/injectAsyncThrottledCallback.ts +50 -0
  252. package/src/async-throttler/injectAsyncThrottler.ts +92 -0
  253. package/src/batcher/index.ts +4 -0
  254. package/src/batcher/injectBatchedCallback.ts +46 -0
  255. package/src/batcher/injectBatcher.ts +79 -0
  256. package/src/debouncer/index.ts +6 -0
  257. package/src/debouncer/injectDebouncedCallback.ts +46 -0
  258. package/src/debouncer/injectDebouncedSignal.ts +101 -0
  259. package/src/debouncer/injectDebouncedValue.ts +126 -0
  260. package/src/debouncer/injectDebouncer.ts +102 -0
  261. package/src/index.ts +40 -0
  262. package/src/provider/index.ts +2 -0
  263. package/src/provider/pacer-context.ts +46 -0
  264. package/src/provider/pacer-provider.ts +38 -0
  265. package/src/queuer/index.ts +5 -0
  266. package/src/queuer/injectQueuedSignal.ts +70 -0
  267. package/src/queuer/injectQueuedValue.ts +101 -0
  268. package/src/queuer/injectQueuer.ts +83 -0
  269. package/src/rate-limiter/index.ts +6 -0
  270. package/src/rate-limiter/injectRateLimitedCallback.ts +45 -0
  271. package/src/rate-limiter/injectRateLimitedSignal.ts +95 -0
  272. package/src/rate-limiter/injectRateLimitedValue.ts +99 -0
  273. package/src/rate-limiter/injectRateLimiter.ts +116 -0
  274. package/src/throttler/index.ts +6 -0
  275. package/src/throttler/injectThrottledCallback.ts +45 -0
  276. package/src/throttler/injectThrottledSignal.ts +102 -0
  277. package/src/throttler/injectThrottledValue.ts +124 -0
  278. package/src/throttler/injectThrottler.ts +102 -0
  279. package/src/types/index.ts +1 -0
  280. package/src/utils/index.ts +1 -0
@@ -0,0 +1,4 @@
1
+ import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.cjs";
2
+ import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.cjs";
3
+ export * from "@tanstack/pacer/async-rate-limiter";
4
+ export { AngularAsyncRateLimiter, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
@@ -0,0 +1,4 @@
1
+ import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.js";
2
+ import { AngularAsyncRateLimiter, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.js";
3
+ export * from "@tanstack/pacer/async-rate-limiter";
4
+ export { AngularAsyncRateLimiter, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
@@ -0,0 +1,6 @@
1
+ import { injectAsyncRateLimiter } from "./injectAsyncRateLimiter.js";
2
+ import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.js";
3
+
4
+ export * from "@tanstack/pacer/async-rate-limiter"
5
+
6
+ export { injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
@@ -0,0 +1,52 @@
1
+ const require_injectAsyncRateLimiter = require('./injectAsyncRateLimiter.cjs');
2
+
3
+ //#region src/async-rate-limiter/injectAsyncRateLimitedCallback.ts
4
+ /**
5
+ * An Angular function that creates an async rate-limited version of a callback function.
6
+ * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides
7
+ * a simplified API for basic async rate limiting needs.
8
+ *
9
+ * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic
10
+ * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.
11
+ *
12
+ * For advanced usage requiring features like:
13
+ * - Manual cancellation/reset
14
+ * - Access to execution counts
15
+ * - Error handling callbacks
16
+ * - Retry support
17
+ *
18
+ * Consider using the `injectAsyncRateLimiter` function instead.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Rate limit API calls
23
+ * const makeApiCall = injectAsyncRateLimitedCallback(
24
+ * async (data: ApiData) => {
25
+ * const response = await fetch('/api/endpoint', {
26
+ * method: 'POST',
27
+ * body: JSON.stringify(data)
28
+ * });
29
+ * return response.json();
30
+ * },
31
+ * {
32
+ * limit: 5,
33
+ * window: 60000,
34
+ * windowType: 'sliding',
35
+ * }
36
+ * );
37
+ *
38
+ * // Use in event handler
39
+ * const result = await makeApiCall(apiData);
40
+ * ```
41
+ */
42
+ function injectAsyncRateLimitedCallback(fn, options) {
43
+ const rateLimiter = require_injectAsyncRateLimiter.injectAsyncRateLimiter(fn, options);
44
+ return async (...args) => {
45
+ const result = await rateLimiter.maybeExecute(...args);
46
+ return result !== void 0 ? await result : void 0;
47
+ };
48
+ }
49
+
50
+ //#endregion
51
+ exports.injectAsyncRateLimitedCallback = injectAsyncRateLimitedCallback;
52
+ //# sourceMappingURL=injectAsyncRateLimitedCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectAsyncRateLimitedCallback.cjs","names":["injectAsyncRateLimiter"],"sources":["../../src/async-rate-limiter/injectAsyncRateLimitedCallback.ts"],"sourcesContent":["import { injectAsyncRateLimiter } from './injectAsyncRateLimiter'\nimport type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates an async rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides\n * a simplified API for basic async rate limiting needs.\n *\n * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic\n * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls\n * const makeApiCall = injectAsyncRateLimitedCallback(\n * async (data: ApiData) => {\n * const response = await fetch('/api/endpoint', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * }\n * );\n *\n * // Use in event handler\n * const result = await makeApiCall(apiData);\n * ```\n */\nexport function injectAsyncRateLimitedCallback<TFn extends AnyAsyncFunction>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const rateLimiter = injectAsyncRateLimiter(fn, options)\n return async (...args: Parameters<TFn>) => {\n const result = await rateLimiter.maybeExecute(...args)\n return result !== undefined ? await result : undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,+BACd,IACA,SAC6E;CAC7E,MAAM,cAAcA,sDAAuB,IAAI,QAAQ;AACvD,QAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,YAAY,aAAa,GAAG,KAAK;AACtD,SAAO,WAAW,SAAY,MAAM,SAAS"}
@@ -0,0 +1,46 @@
1
+ import { AnyAsyncFunction } from "@tanstack/pacer/types";
2
+ import { AsyncRateLimiterOptions } from "@tanstack/pacer/async-rate-limiter";
3
+
4
+ //#region src/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts
5
+ /**
6
+ * An Angular function that creates an async rate-limited version of a callback function.
7
+ * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides
8
+ * a simplified API for basic async rate limiting needs.
9
+ *
10
+ * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic
11
+ * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.
12
+ *
13
+ * For advanced usage requiring features like:
14
+ * - Manual cancellation/reset
15
+ * - Access to execution counts
16
+ * - Error handling callbacks
17
+ * - Retry support
18
+ *
19
+ * Consider using the `injectAsyncRateLimiter` function instead.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Rate limit API calls
24
+ * const makeApiCall = injectAsyncRateLimitedCallback(
25
+ * async (data: ApiData) => {
26
+ * const response = await fetch('/api/endpoint', {
27
+ * method: 'POST',
28
+ * body: JSON.stringify(data)
29
+ * });
30
+ * return response.json();
31
+ * },
32
+ * {
33
+ * limit: 5,
34
+ * window: 60000,
35
+ * windowType: 'sliding',
36
+ * }
37
+ * );
38
+ *
39
+ * // Use in event handler
40
+ * const result = await makeApiCall(apiData);
41
+ * ```
42
+ */
43
+ declare function injectAsyncRateLimitedCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncRateLimiterOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
44
+ //#endregion
45
+ export { injectAsyncRateLimitedCallback };
46
+ //# sourceMappingURL=injectAsyncRateLimitedCallback.d.cts.map
@@ -0,0 +1,46 @@
1
+ import { AsyncRateLimiterOptions } from "@tanstack/pacer/async-rate-limiter";
2
+ import { AnyAsyncFunction } from "@tanstack/pacer/types";
3
+
4
+ //#region src/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts
5
+ /**
6
+ * An Angular function that creates an async rate-limited version of a callback function.
7
+ * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides
8
+ * a simplified API for basic async rate limiting needs.
9
+ *
10
+ * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic
11
+ * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.
12
+ *
13
+ * For advanced usage requiring features like:
14
+ * - Manual cancellation/reset
15
+ * - Access to execution counts
16
+ * - Error handling callbacks
17
+ * - Retry support
18
+ *
19
+ * Consider using the `injectAsyncRateLimiter` function instead.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * // Rate limit API calls
24
+ * const makeApiCall = injectAsyncRateLimitedCallback(
25
+ * async (data: ApiData) => {
26
+ * const response = await fetch('/api/endpoint', {
27
+ * method: 'POST',
28
+ * body: JSON.stringify(data)
29
+ * });
30
+ * return response.json();
31
+ * },
32
+ * {
33
+ * limit: 5,
34
+ * window: 60000,
35
+ * windowType: 'sliding',
36
+ * }
37
+ * );
38
+ *
39
+ * // Use in event handler
40
+ * const result = await makeApiCall(apiData);
41
+ * ```
42
+ */
43
+ declare function injectAsyncRateLimitedCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncRateLimiterOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
44
+ //#endregion
45
+ export { injectAsyncRateLimitedCallback };
46
+ //# sourceMappingURL=injectAsyncRateLimitedCallback.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { injectAsyncRateLimiter } from "./injectAsyncRateLimiter.js";
2
+
3
+ //#region src/async-rate-limiter/injectAsyncRateLimitedCallback.ts
4
+ /**
5
+ * An Angular function that creates an async rate-limited version of a callback function.
6
+ * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides
7
+ * a simplified API for basic async rate limiting needs.
8
+ *
9
+ * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic
10
+ * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.
11
+ *
12
+ * For advanced usage requiring features like:
13
+ * - Manual cancellation/reset
14
+ * - Access to execution counts
15
+ * - Error handling callbacks
16
+ * - Retry support
17
+ *
18
+ * Consider using the `injectAsyncRateLimiter` function instead.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // Rate limit API calls
23
+ * const makeApiCall = injectAsyncRateLimitedCallback(
24
+ * async (data: ApiData) => {
25
+ * const response = await fetch('/api/endpoint', {
26
+ * method: 'POST',
27
+ * body: JSON.stringify(data)
28
+ * });
29
+ * return response.json();
30
+ * },
31
+ * {
32
+ * limit: 5,
33
+ * window: 60000,
34
+ * windowType: 'sliding',
35
+ * }
36
+ * );
37
+ *
38
+ * // Use in event handler
39
+ * const result = await makeApiCall(apiData);
40
+ * ```
41
+ */
42
+ function injectAsyncRateLimitedCallback(fn, options) {
43
+ const rateLimiter = injectAsyncRateLimiter(fn, options);
44
+ return async (...args) => {
45
+ const result = await rateLimiter.maybeExecute(...args);
46
+ return result !== void 0 ? await result : void 0;
47
+ };
48
+ }
49
+
50
+ //#endregion
51
+ export { injectAsyncRateLimitedCallback };
52
+ //# sourceMappingURL=injectAsyncRateLimitedCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectAsyncRateLimitedCallback.js","names":[],"sources":["../../src/async-rate-limiter/injectAsyncRateLimitedCallback.ts"],"sourcesContent":["import { injectAsyncRateLimiter } from './injectAsyncRateLimiter'\nimport type { AsyncRateLimiterOptions } from '@tanstack/pacer/async-rate-limiter'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates an async rate-limited version of a callback function.\n * This function is essentially a wrapper around `injectAsyncRateLimiter` that provides\n * a simplified API for basic async rate limiting needs.\n *\n * This function provides a simpler API compared to `injectAsyncRateLimiter`, making it ideal for basic\n * async rate limiting needs. However, it does not expose the underlying AsyncRateLimiter instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation/reset\n * - Access to execution counts\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncRateLimiter` function instead.\n *\n * @example\n * ```ts\n * // Rate limit API calls\n * const makeApiCall = injectAsyncRateLimitedCallback(\n * async (data: ApiData) => {\n * const response = await fetch('/api/endpoint', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * }\n * );\n *\n * // Use in event handler\n * const result = await makeApiCall(apiData);\n * ```\n */\nexport function injectAsyncRateLimitedCallback<TFn extends AnyAsyncFunction>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const rateLimiter = injectAsyncRateLimiter(fn, options)\n return async (...args: Parameters<TFn>) => {\n const result = await rateLimiter.maybeExecute(...args)\n return result !== undefined ? await result : undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,+BACd,IACA,SAC6E;CAC7E,MAAM,cAAc,uBAAuB,IAAI,QAAQ;AACvD,QAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,YAAY,aAAa,GAAG,KAAK;AACtD,SAAO,WAAW,SAAY,MAAM,SAAS"}
@@ -0,0 +1,57 @@
1
+ const require_pacer_context = require('../provider/pacer-context.cjs');
2
+ let _tanstack_angular_store = require("@tanstack/angular-store");
3
+ let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
4
+
5
+ //#region src/async-rate-limiter/injectAsyncRateLimiter.ts
6
+ /**
7
+ * An Angular function that creates and manages an AsyncRateLimiter instance.
8
+ *
9
+ * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
10
+ * This allows you to integrate it with any state management solution you prefer.
11
+ *
12
+ * This function provides async rate limiting functionality with promise support, error handling,
13
+ * retry capabilities, and abort support.
14
+ *
15
+ * ## State Management and Selector
16
+ *
17
+ * The function uses TanStack Store for state management and wraps it with Angular signals.
18
+ * The `selector` parameter allows you to specify which state changes will trigger signal updates,
19
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
20
+ *
21
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
22
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
+ * full control over when your component tracks state changes.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // Default behavior - no reactive state subscriptions
28
+ * const rateLimiter = injectAsyncRateLimiter(
29
+ * async (id: string) => {
30
+ * const response = await fetch(`/api/data/${id}`);
31
+ * return response.json();
32
+ * },
33
+ * { limit: 5, window: 60000, windowType: 'sliding' }
34
+ * );
35
+ *
36
+ * // In an event handler
37
+ * const handleRequest = async (id: string) => {
38
+ * const result = await rateLimiter.maybeExecute(id);
39
+ * console.log('Result:', result);
40
+ * };
41
+ * ```
42
+ */
43
+ function injectAsyncRateLimiter(fn, options, selector = () => ({})) {
44
+ const rateLimiter = new _tanstack_pacer_async_rate_limiter.AsyncRateLimiter(fn, {
45
+ ...require_pacer_context.injectPacerOptions().asyncRateLimiter,
46
+ ...options
47
+ });
48
+ const state = (0, _tanstack_angular_store.injectStore)(rateLimiter.store, selector);
49
+ return {
50
+ ...rateLimiter,
51
+ state
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ exports.injectAsyncRateLimiter = injectAsyncRateLimiter;
57
+ //# sourceMappingURL=injectAsyncRateLimiter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectAsyncRateLimiter.cjs","names":["AsyncRateLimiter","injectPacerOptions"],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CAMzC,MAAM,cAAc,IAAIA,oDAAsB,IALxB;EACpB,GAAGC,0CAAoB,CAAC;EACxB,GAAG;EACJ,CAE+D;CAChE,MAAM,iDAAoB,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
@@ -0,0 +1,60 @@
1
+ import { Signal } from "@angular/core";
2
+ import { Store } from "@tanstack/store";
3
+ import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
+ import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
5
+
6
+ //#region src/async-rate-limiter/injectAsyncRateLimiter.d.ts
7
+ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
8
+ /**
9
+ * Reactive state signal that will be updated when the async rate limiter state changes
10
+ *
11
+ * Use this instead of `rateLimiter.store.state`
12
+ */
13
+ readonly state: Signal<Readonly<TSelected>>;
14
+ /**
15
+ * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
16
+ * The state on the store object is not reactive in Angular signals.
17
+ */
18
+ readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>;
19
+ }
20
+ /**
21
+ * An Angular function that creates and manages an AsyncRateLimiter instance.
22
+ *
23
+ * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
24
+ * This allows you to integrate it with any state management solution you prefer.
25
+ *
26
+ * This function provides async rate limiting functionality with promise support, error handling,
27
+ * retry capabilities, and abort support.
28
+ *
29
+ * ## State Management and Selector
30
+ *
31
+ * The function uses TanStack Store for state management and wraps it with Angular signals.
32
+ * The `selector` parameter allows you to specify which state changes will trigger signal updates,
33
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
34
+ *
35
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
36
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
37
+ * full control over when your component tracks state changes.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // Default behavior - no reactive state subscriptions
42
+ * const rateLimiter = injectAsyncRateLimiter(
43
+ * async (id: string) => {
44
+ * const response = await fetch(`/api/data/${id}`);
45
+ * return response.json();
46
+ * },
47
+ * { limit: 5, window: 60000, windowType: 'sliding' }
48
+ * );
49
+ *
50
+ * // In an event handler
51
+ * const handleRequest = async (id: string) => {
52
+ * const result = await rateLimiter.maybeExecute(id);
53
+ * console.log('Result:', result);
54
+ * };
55
+ * ```
56
+ */
57
+ declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncRateLimiterOptions<TFn>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
58
+ //#endregion
59
+ export { AngularAsyncRateLimiter, injectAsyncRateLimiter };
60
+ //# sourceMappingURL=injectAsyncRateLimiter.d.cts.map
@@ -0,0 +1,60 @@
1
+ import { Signal } from "@angular/core";
2
+ import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
3
+ import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
+ import { Store } from "@tanstack/store";
5
+
6
+ //#region src/async-rate-limiter/injectAsyncRateLimiter.d.ts
7
+ interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
8
+ /**
9
+ * Reactive state signal that will be updated when the async rate limiter state changes
10
+ *
11
+ * Use this instead of `rateLimiter.store.state`
12
+ */
13
+ readonly state: Signal<Readonly<TSelected>>;
14
+ /**
15
+ * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
16
+ * The state on the store object is not reactive in Angular signals.
17
+ */
18
+ readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>;
19
+ }
20
+ /**
21
+ * An Angular function that creates and manages an AsyncRateLimiter instance.
22
+ *
23
+ * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
24
+ * This allows you to integrate it with any state management solution you prefer.
25
+ *
26
+ * This function provides async rate limiting functionality with promise support, error handling,
27
+ * retry capabilities, and abort support.
28
+ *
29
+ * ## State Management and Selector
30
+ *
31
+ * The function uses TanStack Store for state management and wraps it with Angular signals.
32
+ * The `selector` parameter allows you to specify which state changes will trigger signal updates,
33
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
34
+ *
35
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
36
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
37
+ * full control over when your component tracks state changes.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // Default behavior - no reactive state subscriptions
42
+ * const rateLimiter = injectAsyncRateLimiter(
43
+ * async (id: string) => {
44
+ * const response = await fetch(`/api/data/${id}`);
45
+ * return response.json();
46
+ * },
47
+ * { limit: 5, window: 60000, windowType: 'sliding' }
48
+ * );
49
+ *
50
+ * // In an event handler
51
+ * const handleRequest = async (id: string) => {
52
+ * const result = await rateLimiter.maybeExecute(id);
53
+ * console.log('Result:', result);
54
+ * };
55
+ * ```
56
+ */
57
+ declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AsyncRateLimiterOptions<TFn>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
58
+ //#endregion
59
+ export { AngularAsyncRateLimiter, injectAsyncRateLimiter };
60
+ //# sourceMappingURL=injectAsyncRateLimiter.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { injectPacerOptions } from "../provider/pacer-context.js";
2
+ import { injectStore } from "@tanstack/angular-store";
3
+ import { AsyncRateLimiter } from "@tanstack/pacer/async-rate-limiter";
4
+
5
+ //#region src/async-rate-limiter/injectAsyncRateLimiter.ts
6
+ /**
7
+ * An Angular function that creates and manages an AsyncRateLimiter instance.
8
+ *
9
+ * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
10
+ * This allows you to integrate it with any state management solution you prefer.
11
+ *
12
+ * This function provides async rate limiting functionality with promise support, error handling,
13
+ * retry capabilities, and abort support.
14
+ *
15
+ * ## State Management and Selector
16
+ *
17
+ * The function uses TanStack Store for state management and wraps it with Angular signals.
18
+ * The `selector` parameter allows you to specify which state changes will trigger signal updates,
19
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
20
+ *
21
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
22
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
23
+ * full control over when your component tracks state changes.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * // Default behavior - no reactive state subscriptions
28
+ * const rateLimiter = injectAsyncRateLimiter(
29
+ * async (id: string) => {
30
+ * const response = await fetch(`/api/data/${id}`);
31
+ * return response.json();
32
+ * },
33
+ * { limit: 5, window: 60000, windowType: 'sliding' }
34
+ * );
35
+ *
36
+ * // In an event handler
37
+ * const handleRequest = async (id: string) => {
38
+ * const result = await rateLimiter.maybeExecute(id);
39
+ * console.log('Result:', result);
40
+ * };
41
+ * ```
42
+ */
43
+ function injectAsyncRateLimiter(fn, options, selector = () => ({})) {
44
+ const rateLimiter = new AsyncRateLimiter(fn, {
45
+ ...injectPacerOptions().asyncRateLimiter,
46
+ ...options
47
+ });
48
+ const state = injectStore(rateLimiter.store, selector);
49
+ return {
50
+ ...rateLimiter,
51
+ state
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ export { injectAsyncRateLimiter };
57
+ //# sourceMappingURL=injectAsyncRateLimiter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { injectStore } from '@tanstack/angular-store'\nimport { AsyncRateLimiter } from '@tanstack/pacer/async-rate-limiter'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncRateLimiter<TFn>, 'store'> {\n /**\n * Reactive state signal that will be updated when the async rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Signal<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 in Angular signals.\n */\n readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncRateLimiter instance.\n *\n * This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * This function provides async rate limiting functionality with promise support, error handling,\n * retry capabilities, and abort support.\n *\n * ## State Management and Selector\n *\n * The function uses TanStack Store for state management and wraps it with Angular signals.\n * The `selector` parameter allows you to specify which state changes will trigger signal updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = injectAsyncRateLimiter(\n * async (id: string) => {\n * const response = await fetch(`/api/data/${id}`);\n * return response.json();\n * },\n * { limit: 5, window: 60000, windowType: 'sliding' }\n * );\n *\n * // In an event handler\n * const handleRequest = async (id: string) => {\n * const result = await rateLimiter.maybeExecute(id);\n * console.log('Result:', result);\n * };\n * ```\n */\nexport function injectAsyncRateLimiter<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncRateLimiterOptions<TFn>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AsyncRateLimiterOptions<TFn>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,SAAgB,uBAId,IACA,SACA,kBACG,EAAE,GACoC;CAMzC,MAAM,cAAc,IAAI,iBAAsB,IALxB;EACpB,GAAG,oBAAoB,CAAC;EACxB,GAAG;EACJ,CAE+D;CAChE,MAAM,QAAQ,YAAY,YAAY,OAAO,SAAS;AAEtD,QAAO;EACL,GAAG;EACH;EACD"}
@@ -0,0 +1,9 @@
1
+
2
+
3
+ var _tanstack_pacer_async_retryer = require("@tanstack/pacer/async-retryer");
4
+ Object.keys(_tanstack_pacer_async_retryer).forEach(function (k) {
5
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
6
+ enumerable: true,
7
+ get: function () { return _tanstack_pacer_async_retryer[k]; }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "@tanstack/pacer/async-retryer";
@@ -0,0 +1 @@
1
+ export * from "@tanstack/pacer/async-retryer";
@@ -0,0 +1,3 @@
1
+ export * from "@tanstack/pacer/async-retryer"
2
+
3
+ export { };
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_injectAsyncThrottler = require('./injectAsyncThrottler.cjs');
3
+ const require_injectAsyncThrottledCallback = require('./injectAsyncThrottledCallback.cjs');
4
+
5
+ exports.injectAsyncThrottledCallback = require_injectAsyncThrottledCallback.injectAsyncThrottledCallback;
6
+ exports.injectAsyncThrottler = require_injectAsyncThrottler.injectAsyncThrottler;
7
+ var _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
8
+ Object.keys(_tanstack_pacer_async_throttler).forEach(function (k) {
9
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
10
+ enumerable: true,
11
+ get: function () { return _tanstack_pacer_async_throttler[k]; }
12
+ });
13
+ });
@@ -0,0 +1,4 @@
1
+ import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.cjs";
2
+ import { AngularAsyncThrottler, injectAsyncThrottler } from "./injectAsyncThrottler.cjs";
3
+ export * from "@tanstack/pacer/async-throttler";
4
+ export { AngularAsyncThrottler, injectAsyncThrottledCallback, injectAsyncThrottler };
@@ -0,0 +1,4 @@
1
+ import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.js";
2
+ import { AngularAsyncThrottler, injectAsyncThrottler } from "./injectAsyncThrottler.js";
3
+ export * from "@tanstack/pacer/async-throttler";
4
+ export { AngularAsyncThrottler, injectAsyncThrottledCallback, injectAsyncThrottler };
@@ -0,0 +1,6 @@
1
+ import { injectAsyncThrottler } from "./injectAsyncThrottler.js";
2
+ import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.js";
3
+
4
+ export * from "@tanstack/pacer/async-throttler"
5
+
6
+ export { injectAsyncThrottledCallback, injectAsyncThrottler };
@@ -0,0 +1,50 @@
1
+ const require_injectAsyncThrottler = require('./injectAsyncThrottler.cjs');
2
+
3
+ //#region src/async-throttler/injectAsyncThrottledCallback.ts
4
+ /**
5
+ * An Angular function that creates an async throttled version of a callback function.
6
+ * This function is essentially a wrapper around `injectAsyncThrottler` that provides
7
+ * a simplified API for basic async throttling needs.
8
+ *
9
+ * The throttled function will execute at most once within the specified wait time.
10
+ *
11
+ * This function provides a simpler API compared to `injectAsyncThrottler`, making it ideal for basic
12
+ * async throttling needs. However, it does not expose the underlying AsyncThrottler instance.
13
+ *
14
+ * For advanced usage requiring features like:
15
+ * - Manual cancellation
16
+ * - Access to execution counts
17
+ * - Error handling callbacks
18
+ * - Retry support
19
+ *
20
+ * Consider using the `injectAsyncThrottler` function instead.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * // Throttle an async update handler
25
+ * const handleUpdate = injectAsyncThrottledCallback(
26
+ * async (data: Data) => {
27
+ * const response = await fetch('/api/update', {
28
+ * method: 'POST',
29
+ * body: JSON.stringify(data)
30
+ * });
31
+ * return response.json();
32
+ * },
33
+ * { wait: 1000 }
34
+ * );
35
+ *
36
+ * // Use in an event handler
37
+ * const result = await handleUpdate(updateData);
38
+ * ```
39
+ */
40
+ function injectAsyncThrottledCallback(fn, options) {
41
+ const throttler = require_injectAsyncThrottler.injectAsyncThrottler(fn, options);
42
+ return async (...args) => {
43
+ const result = await throttler.maybeExecute(...args);
44
+ return result !== void 0 ? await result : void 0;
45
+ };
46
+ }
47
+
48
+ //#endregion
49
+ exports.injectAsyncThrottledCallback = injectAsyncThrottledCallback;
50
+ //# sourceMappingURL=injectAsyncThrottledCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectAsyncThrottledCallback.cjs","names":["injectAsyncThrottler"],"sources":["../../src/async-throttler/injectAsyncThrottledCallback.ts"],"sourcesContent":["import { injectAsyncThrottler } from './injectAsyncThrottler'\nimport type { AsyncThrottlerOptions } from '@tanstack/pacer/async-throttler'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\n/**\n * An Angular function that creates an async throttled version of a callback function.\n * This function is essentially a wrapper around `injectAsyncThrottler` that provides\n * a simplified API for basic async throttling needs.\n *\n * The throttled function will execute at most once within the specified wait time.\n *\n * This function provides a simpler API compared to `injectAsyncThrottler`, making it ideal for basic\n * async throttling needs. However, it does not expose the underlying AsyncThrottler instance.\n *\n * For advanced usage requiring features like:\n * - Manual cancellation\n * - Access to execution counts\n * - Error handling callbacks\n * - Retry support\n *\n * Consider using the `injectAsyncThrottler` function instead.\n *\n * @example\n * ```ts\n * // Throttle an async update handler\n * const handleUpdate = injectAsyncThrottledCallback(\n * async (data: Data) => {\n * const response = await fetch('/api/update', {\n * method: 'POST',\n * body: JSON.stringify(data)\n * });\n * return response.json();\n * },\n * { wait: 1000 }\n * );\n *\n * // Use in an event handler\n * const result = await handleUpdate(updateData);\n * ```\n */\nexport function injectAsyncThrottledCallback<TFn extends AnyAsyncFunction>(\n fn: TFn,\n options: AsyncThrottlerOptions<TFn>,\n): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined> {\n const throttler = injectAsyncThrottler(fn, options)\n return async (...args: Parameters<TFn>) => {\n const result = await throttler.maybeExecute(...args)\n return result !== undefined ? await result : undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,6BACd,IACA,SAC6E;CAC7E,MAAM,YAAYA,kDAAqB,IAAI,QAAQ;AACnD,QAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,UAAU,aAAa,GAAG,KAAK;AACpD,SAAO,WAAW,SAAY,MAAM,SAAS"}
@@ -0,0 +1,44 @@
1
+ import { AnyAsyncFunction } from "@tanstack/pacer/types";
2
+ import { AsyncThrottlerOptions } from "@tanstack/pacer/async-throttler";
3
+
4
+ //#region src/async-throttler/injectAsyncThrottledCallback.d.ts
5
+ /**
6
+ * An Angular function that creates an async throttled version of a callback function.
7
+ * This function is essentially a wrapper around `injectAsyncThrottler` that provides
8
+ * a simplified API for basic async throttling needs.
9
+ *
10
+ * The throttled function will execute at most once within the specified wait time.
11
+ *
12
+ * This function provides a simpler API compared to `injectAsyncThrottler`, making it ideal for basic
13
+ * async throttling needs. However, it does not expose the underlying AsyncThrottler instance.
14
+ *
15
+ * For advanced usage requiring features like:
16
+ * - Manual cancellation
17
+ * - Access to execution counts
18
+ * - Error handling callbacks
19
+ * - Retry support
20
+ *
21
+ * Consider using the `injectAsyncThrottler` function instead.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * // Throttle an async update handler
26
+ * const handleUpdate = injectAsyncThrottledCallback(
27
+ * async (data: Data) => {
28
+ * const response = await fetch('/api/update', {
29
+ * method: 'POST',
30
+ * body: JSON.stringify(data)
31
+ * });
32
+ * return response.json();
33
+ * },
34
+ * { wait: 1000 }
35
+ * );
36
+ *
37
+ * // Use in an event handler
38
+ * const result = await handleUpdate(updateData);
39
+ * ```
40
+ */
41
+ declare function injectAsyncThrottledCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncThrottlerOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
42
+ //#endregion
43
+ export { injectAsyncThrottledCallback };
44
+ //# sourceMappingURL=injectAsyncThrottledCallback.d.cts.map