@tanstack/angular-pacer 0.24.0 → 0.25.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.
- package/README.md +4 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.d.ts +2 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.js +1 -2
- package/dist/async-batcher/injectAsyncBatcher.d.ts +4 -6
- package/dist/async-batcher/injectAsyncBatcher.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.ts +2 -4
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js +1 -2
- package/dist/async-debouncer/injectAsyncDebouncer.d.ts +4 -6
- package/dist/async-debouncer/injectAsyncDebouncer.js +1 -2
- package/dist/async-queuer/injectAsyncQueuedSignal.d.ts +3 -5
- package/dist/async-queuer/injectAsyncQueuedSignal.js +1 -2
- package/dist/async-queuer/injectAsyncQueuer.d.ts +4 -6
- package/dist/async-queuer/injectAsyncQueuer.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.ts +2 -4
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js +1 -2
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.ts +4 -6
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js +1 -2
- package/dist/async-throttler/injectAsyncThrottledCallback.d.ts +2 -4
- package/dist/async-throttler/injectAsyncThrottledCallback.js +1 -2
- package/dist/async-throttler/injectAsyncThrottler.d.ts +4 -6
- package/dist/async-throttler/injectAsyncThrottler.js +1 -2
- package/dist/batcher/injectBatchedCallback.d.ts +2 -4
- package/dist/batcher/injectBatchedCallback.js +1 -2
- package/dist/batcher/injectBatcher.d.ts +4 -6
- package/dist/batcher/injectBatcher.js +1 -2
- package/dist/debouncer/injectDebouncedCallback.d.ts +2 -4
- package/dist/debouncer/injectDebouncedCallback.js +1 -2
- package/dist/debouncer/injectDebouncedSignal.d.ts +3 -5
- package/dist/debouncer/injectDebouncedSignal.js +1 -2
- package/dist/debouncer/injectDebouncedValue.d.ts +3 -5
- package/dist/debouncer/injectDebouncedValue.js +1 -2
- package/dist/debouncer/injectDebouncer.d.ts +4 -6
- package/dist/debouncer/injectDebouncer.js +1 -2
- package/dist/provider/pacer-context.d.ts +4 -6
- package/dist/provider/pacer-context.js +1 -2
- package/dist/provider/pacer-provider.d.ts +2 -4
- package/dist/provider/pacer-provider.js +1 -2
- package/dist/queuer/injectQueuedSignal.d.ts +3 -5
- package/dist/queuer/injectQueuedSignal.js +1 -2
- package/dist/queuer/injectQueuedValue.d.ts +3 -5
- package/dist/queuer/injectQueuedValue.js +1 -2
- package/dist/queuer/injectQueuer.d.ts +4 -6
- package/dist/queuer/injectQueuer.js +1 -2
- package/dist/rate-limiter/injectRateLimitedCallback.d.ts +2 -4
- package/dist/rate-limiter/injectRateLimitedCallback.js +1 -2
- package/dist/rate-limiter/injectRateLimitedSignal.d.ts +3 -5
- package/dist/rate-limiter/injectRateLimitedSignal.js +1 -2
- package/dist/rate-limiter/injectRateLimitedValue.d.ts +3 -5
- package/dist/rate-limiter/injectRateLimitedValue.js +1 -2
- package/dist/rate-limiter/injectRateLimiter.d.ts +4 -6
- package/dist/rate-limiter/injectRateLimiter.js +1 -2
- package/dist/throttler/injectThrottledCallback.d.ts +2 -4
- package/dist/throttler/injectThrottledCallback.js +1 -2
- package/dist/throttler/injectThrottledSignal.d.ts +3 -7
- package/dist/throttler/injectThrottledSignal.js +1 -4
- package/dist/throttler/injectThrottledValue.d.ts +3 -7
- package/dist/throttler/injectThrottledValue.js +1 -2
- package/dist/throttler/injectThrottler.d.ts +4 -8
- package/dist/throttler/injectThrottler.js +1 -4
- package/package.json +24 -71
- package/dist/async-batcher/index.cjs +0 -13
- package/dist/async-batcher/index.d.cts +0 -4
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs +0 -49
- package/dist/async-batcher/injectAsyncBatchedCallback.cjs.map +0 -1
- package/dist/async-batcher/injectAsyncBatchedCallback.d.cts +0 -44
- package/dist/async-batcher/injectAsyncBatchedCallback.js.map +0 -1
- package/dist/async-batcher/injectAsyncBatcher.cjs +0 -85
- package/dist/async-batcher/injectAsyncBatcher.cjs.map +0 -1
- package/dist/async-batcher/injectAsyncBatcher.d.cts +0 -84
- package/dist/async-batcher/injectAsyncBatcher.js.map +0 -1
- package/dist/async-debouncer/index.cjs +0 -13
- package/dist/async-debouncer/index.d.cts +0 -4
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs +0 -49
- package/dist/async-debouncer/injectAsyncDebouncedCallback.cjs.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncedCallback.d.cts +0 -42
- package/dist/async-debouncer/injectAsyncDebouncedCallback.js.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.cjs +0 -107
- package/dist/async-debouncer/injectAsyncDebouncer.cjs.map +0 -1
- package/dist/async-debouncer/injectAsyncDebouncer.d.cts +0 -107
- package/dist/async-debouncer/injectAsyncDebouncer.js.map +0 -1
- package/dist/async-queuer/index.cjs +0 -13
- package/dist/async-queuer/index.d.cts +0 -4
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs +0 -53
- package/dist/async-queuer/injectAsyncQueuedSignal.cjs.map +0 -1
- package/dist/async-queuer/injectAsyncQueuedSignal.d.cts +0 -49
- package/dist/async-queuer/injectAsyncQueuedSignal.js.map +0 -1
- package/dist/async-queuer/injectAsyncQueuer.cjs +0 -85
- package/dist/async-queuer/injectAsyncQueuer.cjs.map +0 -1
- package/dist/async-queuer/injectAsyncQueuer.d.cts +0 -84
- package/dist/async-queuer/injectAsyncQueuer.js.map +0 -1
- package/dist/async-rate-limiter/index.cjs +0 -13
- package/dist/async-rate-limiter/index.d.cts +0 -4
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs +0 -52
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.cjs.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.d.cts +0 -45
- package/dist/async-rate-limiter/injectAsyncRateLimitedCallback.js.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs +0 -69
- package/dist/async-rate-limiter/injectAsyncRateLimiter.cjs.map +0 -1
- package/dist/async-rate-limiter/injectAsyncRateLimiter.d.cts +0 -71
- package/dist/async-rate-limiter/injectAsyncRateLimiter.js.map +0 -1
- package/dist/async-retryer/index.cjs +0 -8
- package/dist/async-retryer/index.d.cts +0 -1
- package/dist/async-throttler/index.cjs +0 -13
- package/dist/async-throttler/index.d.cts +0 -4
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs +0 -50
- package/dist/async-throttler/injectAsyncThrottledCallback.cjs.map +0 -1
- package/dist/async-throttler/injectAsyncThrottledCallback.d.cts +0 -43
- package/dist/async-throttler/injectAsyncThrottledCallback.js.map +0 -1
- package/dist/async-throttler/injectAsyncThrottler.cjs +0 -86
- package/dist/async-throttler/injectAsyncThrottler.cjs.map +0 -1
- package/dist/async-throttler/injectAsyncThrottler.d.cts +0 -86
- package/dist/async-throttler/injectAsyncThrottler.js.map +0 -1
- package/dist/batcher/index.cjs +0 -13
- package/dist/batcher/index.d.cts +0 -4
- package/dist/batcher/injectBatchedCallback.cjs +0 -47
- package/dist/batcher/injectBatchedCallback.cjs.map +0 -1
- package/dist/batcher/injectBatchedCallback.d.cts +0 -42
- package/dist/batcher/injectBatchedCallback.js.map +0 -1
- package/dist/batcher/injectBatcher.cjs +0 -75
- package/dist/batcher/injectBatcher.cjs.map +0 -1
- package/dist/batcher/injectBatcher.d.cts +0 -76
- package/dist/batcher/injectBatcher.js.map +0 -1
- package/dist/debouncer/index.cjs +0 -17
- package/dist/debouncer/index.d.cts +0 -6
- package/dist/debouncer/injectDebouncedCallback.cjs +0 -46
- package/dist/debouncer/injectDebouncedCallback.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedCallback.d.cts +0 -42
- package/dist/debouncer/injectDebouncedCallback.js.map +0 -1
- package/dist/debouncer/injectDebouncedSignal.cjs +0 -68
- package/dist/debouncer/injectDebouncedSignal.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedSignal.d.cts +0 -59
- package/dist/debouncer/injectDebouncedSignal.js.map +0 -1
- package/dist/debouncer/injectDebouncedValue.cjs +0 -17
- package/dist/debouncer/injectDebouncedValue.cjs.map +0 -1
- package/dist/debouncer/injectDebouncedValue.d.cts +0 -75
- package/dist/debouncer/injectDebouncedValue.js.map +0 -1
- package/dist/debouncer/injectDebouncer.cjs +0 -95
- package/dist/debouncer/injectDebouncer.cjs.map +0 -1
- package/dist/debouncer/injectDebouncer.d.cts +0 -97
- package/dist/debouncer/injectDebouncer.js.map +0 -1
- package/dist/index.cjs +0 -65
- package/dist/index.d.cts +0 -30
- package/dist/provider/index.cjs +0 -7
- package/dist/provider/index.d.cts +0 -3
- package/dist/provider/pacer-context.cjs +0 -20
- package/dist/provider/pacer-context.cjs.map +0 -1
- package/dist/provider/pacer-context.d.cts +0 -20
- package/dist/provider/pacer-context.js.map +0 -1
- package/dist/provider/pacer-provider.cjs +0 -41
- package/dist/provider/pacer-provider.cjs.map +0 -1
- package/dist/provider/pacer-provider.d.cts +0 -35
- package/dist/provider/pacer-provider.js.map +0 -1
- package/dist/queuer/index.cjs +0 -15
- package/dist/queuer/index.d.cts +0 -5
- package/dist/queuer/injectQueuedSignal.cjs +0 -47
- package/dist/queuer/injectQueuedSignal.cjs.map +0 -1
- package/dist/queuer/injectQueuedSignal.d.cts +0 -43
- package/dist/queuer/injectQueuedSignal.js.map +0 -1
- package/dist/queuer/injectQueuedValue.cjs +0 -23
- package/dist/queuer/injectQueuedValue.cjs.map +0 -1
- package/dist/queuer/injectQueuedValue.d.cts +0 -33
- package/dist/queuer/injectQueuedValue.js.map +0 -1
- package/dist/queuer/injectQueuer.cjs +0 -80
- package/dist/queuer/injectQueuer.cjs.map +0 -1
- package/dist/queuer/injectQueuer.d.cts +0 -81
- package/dist/queuer/injectQueuer.js.map +0 -1
- package/dist/rate-limiter/index.cjs +0 -17
- package/dist/rate-limiter/index.d.cts +0 -6
- package/dist/rate-limiter/injectRateLimitedCallback.cjs +0 -45
- package/dist/rate-limiter/injectRateLimitedCallback.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedCallback.d.cts +0 -41
- package/dist/rate-limiter/injectRateLimitedCallback.js.map +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.cjs +0 -62
- package/dist/rate-limiter/injectRateLimitedSignal.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedSignal.d.cts +0 -53
- package/dist/rate-limiter/injectRateLimitedSignal.js.map +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.cjs +0 -17
- package/dist/rate-limiter/injectRateLimitedValue.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimitedValue.d.cts +0 -48
- package/dist/rate-limiter/injectRateLimitedValue.js.map +0 -1
- package/dist/rate-limiter/injectRateLimiter.cjs +0 -100
- package/dist/rate-limiter/injectRateLimiter.cjs.map +0 -1
- package/dist/rate-limiter/injectRateLimiter.d.cts +0 -102
- package/dist/rate-limiter/injectRateLimiter.js.map +0 -1
- package/dist/throttler/index.cjs +0 -17
- package/dist/throttler/index.d.cts +0 -6
- package/dist/throttler/injectThrottledCallback.cjs +0 -45
- package/dist/throttler/injectThrottledCallback.cjs.map +0 -1
- package/dist/throttler/injectThrottledCallback.d.cts +0 -41
- package/dist/throttler/injectThrottledCallback.js.map +0 -1
- package/dist/throttler/injectThrottledSignal.cjs +0 -69
- package/dist/throttler/injectThrottledSignal.cjs.map +0 -1
- package/dist/throttler/injectThrottledSignal.d.cts +0 -60
- package/dist/throttler/injectThrottledSignal.js.map +0 -1
- package/dist/throttler/injectThrottledValue.cjs +0 -17
- package/dist/throttler/injectThrottledValue.cjs.map +0 -1
- package/dist/throttler/injectThrottledValue.d.cts +0 -73
- package/dist/throttler/injectThrottledValue.js.map +0 -1
- package/dist/throttler/injectThrottler.cjs +0 -95
- package/dist/throttler/injectThrottler.cjs.map +0 -1
- package/dist/throttler/injectThrottler.d.cts +0 -97
- package/dist/throttler/injectThrottler.js.map +0 -1
- package/dist/types/index.cjs +0 -8
- package/dist/types/index.d.cts +0 -1
- package/dist/utils/index.cjs +0 -8
- package/dist/utils/index.d.cts +0 -1
- package/src/async-batcher/index.ts +0 -4
- package/src/async-batcher/injectAsyncBatchedCallback.ts +0 -48
- package/src/async-batcher/injectAsyncBatcher.ts +0 -126
- package/src/async-debouncer/index.ts +0 -4
- package/src/async-debouncer/injectAsyncDebouncedCallback.ts +0 -50
- package/src/async-debouncer/injectAsyncDebouncer.ts +0 -152
- package/src/async-queuer/index.ts +0 -4
- package/src/async-queuer/injectAsyncQueuedSignal.ts +0 -74
- package/src/async-queuer/injectAsyncQueuer.ts +0 -126
- package/src/async-rate-limiter/index.ts +0 -4
- package/src/async-rate-limiter/injectAsyncRateLimitedCallback.ts +0 -52
- package/src/async-rate-limiter/injectAsyncRateLimiter.ts +0 -115
- package/src/async-retryer/index.ts +0 -1
- package/src/async-throttler/index.ts +0 -4
- package/src/async-throttler/injectAsyncThrottledCallback.ts +0 -50
- package/src/async-throttler/injectAsyncThrottler.ts +0 -131
- package/src/batcher/index.ts +0 -4
- package/src/batcher/injectBatchedCallback.ts +0 -46
- package/src/batcher/injectBatcher.ts +0 -114
- package/src/debouncer/index.ts +0 -6
- package/src/debouncer/injectDebouncedCallback.ts +0 -46
- package/src/debouncer/injectDebouncedSignal.ts +0 -94
- package/src/debouncer/injectDebouncedValue.ts +0 -125
- package/src/debouncer/injectDebouncer.ts +0 -137
- package/src/index.ts +0 -40
- package/src/provider/index.ts +0 -2
- package/src/provider/pacer-context.ts +0 -46
- package/src/provider/pacer-provider.ts +0 -38
- package/src/queuer/index.ts +0 -5
- package/src/queuer/injectQueuedSignal.ts +0 -65
- package/src/queuer/injectQueuedValue.ts +0 -99
- package/src/queuer/injectQueuer.ts +0 -118
- package/src/rate-limiter/index.ts +0 -6
- package/src/rate-limiter/injectRateLimitedCallback.ts +0 -45
- package/src/rate-limiter/injectRateLimitedSignal.ts +0 -88
- package/src/rate-limiter/injectRateLimitedValue.ts +0 -98
- package/src/rate-limiter/injectRateLimiter.ts +0 -140
- package/src/throttler/index.ts +0 -6
- package/src/throttler/injectThrottledCallback.ts +0 -45
- package/src/throttler/injectThrottledSignal.ts +0 -95
- package/src/throttler/injectThrottledValue.ts +0 -123
- package/src/throttler/injectThrottler.ts +0 -137
- package/src/types/index.ts +0 -1
- package/src/utils/index.ts +0 -1
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
-
let _angular_core = require("@angular/core");
|
|
3
|
-
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
4
|
-
let _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
5
|
-
|
|
6
|
-
//#region src/async-queuer/injectAsyncQueuer.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages an AsyncQueuer instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the AsyncQueuer's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* The AsyncQueuer processes items asynchronously with support for concurrent execution,
|
|
14
|
-
* promise-based processing, error handling, retry capabilities, and abort support.
|
|
15
|
-
*
|
|
16
|
-
* ## State Management and Selector
|
|
17
|
-
*
|
|
18
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
19
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
20
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
21
|
-
*
|
|
22
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
23
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
24
|
-
* full control over when your component tracks state changes.
|
|
25
|
-
*
|
|
26
|
-
* ## Cleanup on Destroy
|
|
27
|
-
*
|
|
28
|
-
* By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
|
|
29
|
-
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
30
|
-
*
|
|
31
|
-
* ```ts
|
|
32
|
-
* const queuer = injectAsyncQueuer(fn, {
|
|
33
|
-
* concurrency: 2,
|
|
34
|
-
* onUnmount: (q) => q.flush()
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* // Default behavior - no reactive state subscriptions
|
|
43
|
-
* const queuer = injectAsyncQueuer(
|
|
44
|
-
* async (item: Data) => {
|
|
45
|
-
* const response = await fetch('/api/process', {
|
|
46
|
-
* method: 'POST',
|
|
47
|
-
* body: JSON.stringify(item)
|
|
48
|
-
* });
|
|
49
|
-
* return response.json();
|
|
50
|
-
* },
|
|
51
|
-
* { concurrency: 2, wait: 1000 }
|
|
52
|
-
* );
|
|
53
|
-
*
|
|
54
|
-
* // Add items
|
|
55
|
-
* queuer.addItem(data1);
|
|
56
|
-
* queuer.addItem(data2);
|
|
57
|
-
*
|
|
58
|
-
* // Access the selected state
|
|
59
|
-
* const { items, isExecuting } = queuer.state();
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
function injectAsyncQueuer(fn, options = {}, selector = () => ({})) {
|
|
63
|
-
const mergedOptions = {
|
|
64
|
-
...require_pacer_context.injectPacerOptions().asyncQueuer,
|
|
65
|
-
...options
|
|
66
|
-
};
|
|
67
|
-
const queuer = new _tanstack_pacer_async_queuer.AsyncQueuer(fn, mergedOptions);
|
|
68
|
-
const state = (0, _tanstack_angular_store.injectSelector)(queuer.store, selector);
|
|
69
|
-
const result = {
|
|
70
|
-
...queuer,
|
|
71
|
-
state
|
|
72
|
-
};
|
|
73
|
-
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
74
|
-
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
75
|
-
else {
|
|
76
|
-
queuer.stop();
|
|
77
|
-
queuer.abort();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
//#endregion
|
|
84
|
-
exports.injectAsyncQueuer = injectAsyncQueuer;
|
|
85
|
-
//# sourceMappingURL=injectAsyncQueuer.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncQueuer.cjs","names":["injectPacerOptions","AsyncQueuer","injectSelector","inject","DestroyRef"],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, 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 * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queuer = injectAsyncQueuer(fn, {\n * concurrency: 2,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AngularAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AngularAsyncQueuerOptions<TValue, TSelected>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n queuer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,kBACd,IACA,UAAwD,CAAC,GACzD,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,SAAS,IAAIC,yCAAoB,IAAI,aAAa;CACxD,MAAM,YAAQC,wCAAe,OAAO,OAAO,QAAQ;CAEnD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OACzB;GACL,OAAO,KAAK;GACZ,OAAO,MAAM;EACf;CACF,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/angular-store";
|
|
3
|
-
import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
|
|
4
|
-
//#region src/async-queuer/injectAsyncQueuer.d.ts
|
|
5
|
-
interface AngularAsyncQueuerOptions<TValue, TSelected = {}> extends AsyncQueuerOptions<TValue> {
|
|
6
|
-
/**
|
|
7
|
-
* Optional callback invoked when the component is destroyed. Receives the queuer instance.
|
|
8
|
-
* When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.
|
|
9
|
-
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
10
|
-
*/
|
|
11
|
-
onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void;
|
|
12
|
-
}
|
|
13
|
-
interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
|
|
14
|
-
/**
|
|
15
|
-
* Reactive state signal that will be updated when the async queuer state changes
|
|
16
|
-
*
|
|
17
|
-
* Use this instead of `queuer.store.state`
|
|
18
|
-
*/
|
|
19
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
22
|
-
* The state on the store object is not reactive in Angular signals.
|
|
23
|
-
*/
|
|
24
|
-
readonly store: Store<Readonly<AsyncQueuerState<TValue>>>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* An Angular function that creates and manages an AsyncQueuer instance.
|
|
28
|
-
*
|
|
29
|
-
* This is a lower-level function that provides direct access to the AsyncQueuer's functionality.
|
|
30
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
31
|
-
*
|
|
32
|
-
* The AsyncQueuer processes items asynchronously with support for concurrent execution,
|
|
33
|
-
* promise-based processing, error handling, retry capabilities, and abort support.
|
|
34
|
-
*
|
|
35
|
-
* ## State Management and Selector
|
|
36
|
-
*
|
|
37
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
38
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
39
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
40
|
-
*
|
|
41
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
42
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
43
|
-
* full control over when your component tracks state changes.
|
|
44
|
-
*
|
|
45
|
-
* ## Cleanup on Destroy
|
|
46
|
-
*
|
|
47
|
-
* By default, the function stops the queuer and aborts in-flight work when the component is destroyed.
|
|
48
|
-
* Use the `onUnmount` option to customize this. For example, to flush pending items instead:
|
|
49
|
-
*
|
|
50
|
-
* ```ts
|
|
51
|
-
* const queuer = injectAsyncQueuer(fn, {
|
|
52
|
-
* concurrency: 2,
|
|
53
|
-
* onUnmount: (q) => q.flush()
|
|
54
|
-
* });
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* When using onUnmount with flush, guard your callbacks since the component may already be destroyed.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* // Default behavior - no reactive state subscriptions
|
|
62
|
-
* const queuer = injectAsyncQueuer(
|
|
63
|
-
* async (item: Data) => {
|
|
64
|
-
* const response = await fetch('/api/process', {
|
|
65
|
-
* method: 'POST',
|
|
66
|
-
* body: JSON.stringify(item)
|
|
67
|
-
* });
|
|
68
|
-
* return response.json();
|
|
69
|
-
* },
|
|
70
|
-
* { concurrency: 2, wait: 1000 }
|
|
71
|
-
* );
|
|
72
|
-
*
|
|
73
|
-
* // Add items
|
|
74
|
-
* queuer.addItem(data1);
|
|
75
|
-
* queuer.addItem(data2);
|
|
76
|
-
*
|
|
77
|
-
* // Access the selected state
|
|
78
|
-
* const { items, isExecuting } = queuer.state();
|
|
79
|
-
* ```
|
|
80
|
-
*/
|
|
81
|
-
declare function injectAsyncQueuer<TValue, TSelected = {}>(fn: (value: TValue) => Promise<any>, options?: AngularAsyncQueuerOptions<TValue, TSelected>, selector?: (state: AsyncQueuerState<TValue>) => TSelected): AngularAsyncQueuer<TValue, TSelected>;
|
|
82
|
-
//#endregion
|
|
83
|
-
export { AngularAsyncQueuer, AngularAsyncQueuerOptions, injectAsyncQueuer };
|
|
84
|
-
//# sourceMappingURL=injectAsyncQueuer.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/injectAsyncQueuer.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } from '@tanstack/angular-store'\nimport { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { injectPacerOptions } from '../provider/pacer-context'\nimport type { Signal } from '@angular/core'\nimport type { Store } from '@tanstack/angular-store'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface AngularAsyncQueuerOptions<\n TValue,\n TSelected = {},\n> extends AsyncQueuerOptions<TValue> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop + abort); use it to call flush(), stop(), add logging, etc.\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n */\n onUnmount?: (queuer: AngularAsyncQueuer<TValue, TSelected>) => void\n}\n\nexport interface AngularAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state signal that will be updated when the async queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Signal<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * An Angular function that creates and manages an AsyncQueuer instance.\n *\n * This is a lower-level function that provides direct access to the AsyncQueuer's functionality.\n * This allows you to integrate it with any state management solution you prefer.\n *\n * The AsyncQueuer processes items asynchronously with support for concurrent execution,\n * promise-based processing, error handling, 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 * ## Cleanup on Destroy\n *\n * By default, the function stops the queuer and aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```ts\n * const queuer = injectAsyncQueuer(fn, {\n * concurrency: 2,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * When using onUnmount with flush, guard your callbacks since the component may already be destroyed.\n *\n * @example\n * ```ts\n * // Default behavior - no reactive state subscriptions\n * const queuer = injectAsyncQueuer(\n * async (item: Data) => {\n * const response = await fetch('/api/process', {\n * method: 'POST',\n * body: JSON.stringify(item)\n * });\n * return response.json();\n * },\n * { concurrency: 2, wait: 1000 }\n * );\n *\n * // Add items\n * queuer.addItem(data1);\n * queuer.addItem(data2);\n *\n * // Access the selected state\n * const { items, isExecuting } = queuer.state();\n * ```\n */\nexport function injectAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AngularAsyncQueuerOptions<TValue, TSelected> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncQueuer,\n ...options,\n } as AngularAsyncQueuerOptions<TValue, TSelected>\n\n const queuer = new AsyncQueuer<TValue>(fn, mergedOptions)\n const state = injectSelector(queuer.store, selector)\n\n const result = {\n ...queuer,\n state,\n } as AngularAsyncQueuer<TValue, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n queuer.stop()\n queuer.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FA,SAAgB,kBACd,IACA,UAAwD,CAAC,GACzD,kBACG,CAAC,IACmC;CACvC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,SAAS,IAAI,YAAoB,IAAI,aAAa;CACxD,MAAM,QAAQ,eAAe,OAAO,OAAO,QAAQ;CAEnD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OACzB;GACL,OAAO,KAAK;GACZ,OAAO,MAAM;EACf;CACF,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_injectAsyncRateLimiter = require('./injectAsyncRateLimiter.cjs');
|
|
3
|
-
const require_injectAsyncRateLimitedCallback = require('./injectAsyncRateLimitedCallback.cjs');
|
|
4
|
-
|
|
5
|
-
exports.injectAsyncRateLimitedCallback = require_injectAsyncRateLimitedCallback.injectAsyncRateLimitedCallback;
|
|
6
|
-
exports.injectAsyncRateLimiter = require_injectAsyncRateLimiter.injectAsyncRateLimiter;
|
|
7
|
-
var _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
|
|
8
|
-
Object.keys(_tanstack_pacer_async_rate_limiter).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_rate_limiter[k]; }
|
|
12
|
-
});
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { injectAsyncRateLimitedCallback } from "./injectAsyncRateLimitedCallback.cjs";
|
|
2
|
-
import { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter } from "./injectAsyncRateLimiter.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/async-rate-limiter";
|
|
4
|
-
export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimitedCallback, injectAsyncRateLimiter };
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,OAAO;CACtD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,YAAY,aAAa,GAAG,IAAI;EACrD,OAAO,WAAW,SAAY,MAAM,SAAS;CAC/C;AACF"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
2
|
-
import { AsyncRateLimiterOptions } from "@tanstack/pacer/async-rate-limiter";
|
|
3
|
-
//#region src/async-rate-limiter/injectAsyncRateLimitedCallback.d.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
|
-
declare function injectAsyncRateLimitedCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncRateLimiterOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
|
|
43
|
-
//#endregion
|
|
44
|
-
export { injectAsyncRateLimitedCallback };
|
|
45
|
-
//# sourceMappingURL=injectAsyncRateLimitedCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,OAAO;CACtD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,YAAY,aAAa,GAAG,IAAI;EACrD,OAAO,WAAW,SAAY,MAAM,SAAS;CAC/C;AACF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const require_pacer_context = require('../provider/pacer-context.cjs');
|
|
2
|
-
let _angular_core = require("@angular/core");
|
|
3
|
-
let _tanstack_angular_store = require("@tanstack/angular-store");
|
|
4
|
-
let _tanstack_pacer_async_rate_limiter = require("@tanstack/pacer/async-rate-limiter");
|
|
5
|
-
|
|
6
|
-
//#region src/async-rate-limiter/injectAsyncRateLimiter.ts
|
|
7
|
-
/**
|
|
8
|
-
* An Angular function that creates and manages an AsyncRateLimiter instance.
|
|
9
|
-
*
|
|
10
|
-
* This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
|
|
11
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
12
|
-
*
|
|
13
|
-
* This function provides async rate limiting functionality with promise support, error handling,
|
|
14
|
-
* retry capabilities, and abort support.
|
|
15
|
-
*
|
|
16
|
-
* ## State Management and Selector
|
|
17
|
-
*
|
|
18
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
19
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
20
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
21
|
-
*
|
|
22
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
23
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
24
|
-
* full control over when your component tracks state changes.
|
|
25
|
-
*
|
|
26
|
-
* ## Cleanup on Destroy
|
|
27
|
-
*
|
|
28
|
-
* By default, the function aborts in-flight work when the component is destroyed.
|
|
29
|
-
* Use the `onUnmount` option to customize this.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* // Default behavior - no reactive state subscriptions
|
|
34
|
-
* const rateLimiter = injectAsyncRateLimiter(
|
|
35
|
-
* async (id: string) => {
|
|
36
|
-
* const response = await fetch(`/api/data/${id}`);
|
|
37
|
-
* return response.json();
|
|
38
|
-
* },
|
|
39
|
-
* { limit: 5, window: 60000, windowType: 'sliding' }
|
|
40
|
-
* );
|
|
41
|
-
*
|
|
42
|
-
* // In an event handler
|
|
43
|
-
* const handleRequest = async (id: string) => {
|
|
44
|
-
* const result = await rateLimiter.maybeExecute(id);
|
|
45
|
-
* console.log('Result:', result);
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
function injectAsyncRateLimiter(fn, options, selector = () => ({})) {
|
|
50
|
-
const mergedOptions = {
|
|
51
|
-
...require_pacer_context.injectPacerOptions().asyncRateLimiter,
|
|
52
|
-
...options
|
|
53
|
-
};
|
|
54
|
-
const rateLimiter = new _tanstack_pacer_async_rate_limiter.AsyncRateLimiter(fn, mergedOptions);
|
|
55
|
-
const state = (0, _tanstack_angular_store.injectSelector)(rateLimiter.store, selector);
|
|
56
|
-
const result = {
|
|
57
|
-
...rateLimiter,
|
|
58
|
-
state
|
|
59
|
-
};
|
|
60
|
-
(0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true })?.onDestroy(() => {
|
|
61
|
-
if (mergedOptions.onUnmount) mergedOptions.onUnmount(result);
|
|
62
|
-
else rateLimiter.abort();
|
|
63
|
-
});
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
exports.injectAsyncRateLimiter = injectAsyncRateLimiter;
|
|
69
|
-
//# sourceMappingURL=injectAsyncRateLimiter.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncRateLimiter.cjs","names":["injectPacerOptions","AsyncRateLimiter","injectSelector","inject","DestroyRef"],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort).\n */\n onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void\n}\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 * ## Cleanup on Destroy\n *\n * By default, the function aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this.\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: AngularAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AngularAsyncRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n rateLimiter.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,uBAId,IACA,SACA,kBACG,CAAC,IACqC;CACzC,MAAM,gBAAgB;EACpB,GAAGA,yCAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,cAAc,IAAIC,oDAAsB,IAAI,aAAa;CAC/D,MAAM,YAAQC,wCAAe,YAAY,OAAO,QAAQ;CAExD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,IADmBC,sBAAOC,0BAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,YAAY,MAAM;CAEtB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { Signal } from "@angular/core";
|
|
2
|
-
import { Store } from "@tanstack/angular-store";
|
|
3
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
4
|
-
import { AsyncRateLimiter, AsyncRateLimiterOptions, AsyncRateLimiterState } from "@tanstack/pacer/async-rate-limiter";
|
|
5
|
-
//#region src/async-rate-limiter/injectAsyncRateLimiter.d.ts
|
|
6
|
-
interface AngularAsyncRateLimiterOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncRateLimiterOptions<TFn> {
|
|
7
|
-
/**
|
|
8
|
-
* Optional callback invoked when the component is destroyed. Receives the rate limiter instance.
|
|
9
|
-
* When provided, replaces the default cleanup (abort).
|
|
10
|
-
*/
|
|
11
|
-
onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void;
|
|
12
|
-
}
|
|
13
|
-
interface AngularAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncRateLimiter<TFn>, 'store'> {
|
|
14
|
-
/**
|
|
15
|
-
* Reactive state signal that will be updated when the async rate limiter state changes
|
|
16
|
-
*
|
|
17
|
-
* Use this instead of `rateLimiter.store.state`
|
|
18
|
-
*/
|
|
19
|
-
readonly state: Signal<Readonly<TSelected>>;
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
22
|
-
* The state on the store object is not reactive in Angular signals.
|
|
23
|
-
*/
|
|
24
|
-
readonly store: Store<Readonly<AsyncRateLimiterState<TFn>>>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* An Angular function that creates and manages an AsyncRateLimiter instance.
|
|
28
|
-
*
|
|
29
|
-
* This is a lower-level function that provides direct access to the AsyncRateLimiter's functionality.
|
|
30
|
-
* This allows you to integrate it with any state management solution you prefer.
|
|
31
|
-
*
|
|
32
|
-
* This function provides async rate limiting functionality with promise support, error handling,
|
|
33
|
-
* retry capabilities, and abort support.
|
|
34
|
-
*
|
|
35
|
-
* ## State Management and Selector
|
|
36
|
-
*
|
|
37
|
-
* The function uses TanStack Store for state management and wraps it with Angular signals.
|
|
38
|
-
* The `selector` parameter allows you to specify which state changes will trigger signal updates,
|
|
39
|
-
* optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
|
|
40
|
-
*
|
|
41
|
-
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
42
|
-
* tracking by providing a selector function. This prevents unnecessary updates and gives you
|
|
43
|
-
* full control over when your component tracks state changes.
|
|
44
|
-
*
|
|
45
|
-
* ## Cleanup on Destroy
|
|
46
|
-
*
|
|
47
|
-
* By default, the function aborts in-flight work when the component is destroyed.
|
|
48
|
-
* Use the `onUnmount` option to customize this.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```ts
|
|
52
|
-
* // Default behavior - no reactive state subscriptions
|
|
53
|
-
* const rateLimiter = injectAsyncRateLimiter(
|
|
54
|
-
* async (id: string) => {
|
|
55
|
-
* const response = await fetch(`/api/data/${id}`);
|
|
56
|
-
* return response.json();
|
|
57
|
-
* },
|
|
58
|
-
* { limit: 5, window: 60000, windowType: 'sliding' }
|
|
59
|
-
* );
|
|
60
|
-
*
|
|
61
|
-
* // In an event handler
|
|
62
|
-
* const handleRequest = async (id: string) => {
|
|
63
|
-
* const result = await rateLimiter.maybeExecute(id);
|
|
64
|
-
* console.log('Result:', result);
|
|
65
|
-
* };
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function injectAsyncRateLimiter<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: AngularAsyncRateLimiterOptions<TFn, TSelected>, selector?: (state: AsyncRateLimiterState<TFn>) => TSelected): AngularAsyncRateLimiter<TFn, TSelected>;
|
|
69
|
-
//#endregion
|
|
70
|
-
export { AngularAsyncRateLimiter, AngularAsyncRateLimiterOptions, injectAsyncRateLimiter };
|
|
71
|
-
//# sourceMappingURL=injectAsyncRateLimiter.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncRateLimiter.js","names":[],"sources":["../../src/async-rate-limiter/injectAsyncRateLimiter.ts"],"sourcesContent":["import { DestroyRef, inject } from '@angular/core'\nimport { injectSelector } 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/angular-store'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncRateLimiterOptions,\n AsyncRateLimiterState,\n} from '@tanstack/pacer/async-rate-limiter'\n\nexport interface AngularAsyncRateLimiterOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncRateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the component is destroyed. Receives the rate limiter instance.\n * When provided, replaces the default cleanup (abort).\n */\n onUnmount?: (rateLimiter: AngularAsyncRateLimiter<TFn, TSelected>) => void\n}\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 * ## Cleanup on Destroy\n *\n * By default, the function aborts in-flight work when the component is destroyed.\n * Use the `onUnmount` option to customize this.\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: AngularAsyncRateLimiterOptions<TFn, TSelected>,\n selector: (state: AsyncRateLimiterState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): AngularAsyncRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...injectPacerOptions().asyncRateLimiter,\n ...options,\n } as AngularAsyncRateLimiterOptions<TFn, TSelected>\n\n const rateLimiter = new AsyncRateLimiter<TFn>(fn, mergedOptions)\n const state = injectSelector(rateLimiter.store, selector)\n\n const result = {\n ...rateLimiter,\n state,\n } as AngularAsyncRateLimiter<TFn, TSelected>\n\n const destroyRef = inject(DestroyRef, { optional: true })\n destroyRef?.onDestroy(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(result)\n } else {\n rateLimiter.abort()\n }\n })\n\n return result\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,SAAgB,uBAId,IACA,SACA,kBACG,CAAC,IACqC;CACzC,MAAM,gBAAgB;EACpB,GAAG,mBAAmB,CAAC,CAAC;EACxB,GAAG;CACL;CAEA,MAAM,cAAc,IAAI,iBAAsB,IAAI,aAAa;CAC/D,MAAM,QAAQ,eAAe,YAAY,OAAO,QAAQ;CAExD,MAAM,SAAS;EACb,GAAG;EACH;CACF;CAGA,AADmB,OAAO,YAAY,EAAE,UAAU,KAAK,CAC9C,CAAC,EAAE,gBAAgB;EAC1B,IAAI,cAAc,WAChB,cAAc,UAAU,MAAM;OAE9B,YAAY,MAAM;CAEtB,CAAC;CAED,OAAO;AACT"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var _tanstack_pacer_async_retryer = require("@tanstack/pacer/async-retryer");
|
|
3
|
-
Object.keys(_tanstack_pacer_async_retryer).forEach(function (k) {
|
|
4
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
5
|
-
enumerable: true,
|
|
6
|
-
get: function () { return _tanstack_pacer_async_retryer[k]; }
|
|
7
|
-
});
|
|
8
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "@tanstack/pacer/async-retryer";
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { injectAsyncThrottledCallback } from "./injectAsyncThrottledCallback.cjs";
|
|
2
|
-
import { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottler } from "./injectAsyncThrottler.cjs";
|
|
3
|
-
export * from "@tanstack/pacer/async-throttler";
|
|
4
|
-
export { AngularAsyncThrottler, AngularAsyncThrottlerOptions, injectAsyncThrottledCallback, injectAsyncThrottler };
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,OAAO;CAClD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,UAAU,aAAa,GAAG,IAAI;EACnD,OAAO,WAAW,SAAY,MAAM,SAAS;CAC/C;AACF"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
2
|
-
import { AsyncThrottlerOptions } from "@tanstack/pacer/async-throttler";
|
|
3
|
-
//#region src/async-throttler/injectAsyncThrottledCallback.d.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
|
-
declare function injectAsyncThrottledCallback<TFn extends AnyAsyncFunction>(fn: TFn, options: AsyncThrottlerOptions<TFn>): (...args: Parameters<TFn>) => Promise<Awaited<ReturnType<TFn>> | undefined>;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { injectAsyncThrottledCallback };
|
|
43
|
-
//# sourceMappingURL=injectAsyncThrottledCallback.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectAsyncThrottledCallback.js","names":[],"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,YAAY,qBAAqB,IAAI,OAAO;CAClD,OAAO,OAAO,GAAG,SAA0B;EACzC,MAAM,SAAS,MAAM,UAAU,aAAa,GAAG,IAAI;EACnD,OAAO,WAAW,SAAY,MAAM,SAAS;CAC/C;AACF"}
|