@tanstack/solid-pacer 0.15.3 → 0.16.1
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 +165 -0
- package/dist/async-batcher/createAsyncBatcher.cjs +122 -0
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -0
- package/dist/{cjs/async-batcher → async-batcher}/createAsyncBatcher.d.cts +22 -17
- package/dist/{esm/async-batcher → async-batcher}/createAsyncBatcher.d.ts +22 -17
- package/dist/async-batcher/createAsyncBatcher.js +122 -0
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -0
- package/dist/async-batcher/index.cjs +10 -0
- package/dist/async-batcher/index.d.cts +3 -0
- package/dist/async-batcher/index.d.ts +3 -0
- package/dist/async-batcher/index.js +5 -0
- package/dist/async-debouncer/createAsyncDebouncer.cjs +114 -0
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -0
- package/dist/{cjs/async-debouncer → async-debouncer}/createAsyncDebouncer.d.cts +23 -18
- package/dist/{esm/async-debouncer → async-debouncer}/createAsyncDebouncer.d.ts +23 -18
- package/dist/async-debouncer/createAsyncDebouncer.js +114 -0
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -0
- package/dist/async-debouncer/index.cjs +10 -0
- package/dist/async-debouncer/index.d.cts +3 -0
- package/dist/async-debouncer/index.d.ts +3 -0
- package/dist/async-debouncer/index.js +5 -0
- package/dist/async-queuer/createAsyncQueuer.cjs +114 -0
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -0
- package/dist/{cjs/async-queuer → async-queuer}/createAsyncQueuer.d.cts +22 -17
- package/dist/{esm/async-queuer → async-queuer}/createAsyncQueuer.d.ts +22 -17
- package/dist/async-queuer/createAsyncQueuer.js +114 -0
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -0
- package/dist/async-queuer/index.cjs +10 -0
- package/dist/async-queuer/index.d.cts +3 -0
- package/dist/async-queuer/index.d.ts +3 -0
- package/dist/async-queuer/index.js +5 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +120 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -0
- package/dist/{cjs/async-rate-limiter → async-rate-limiter}/createAsyncRateLimiter.d.cts +23 -18
- package/dist/{esm/async-rate-limiter → async-rate-limiter}/createAsyncRateLimiter.d.ts +23 -18
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +120 -0
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -0
- package/dist/async-rate-limiter/index.cjs +10 -0
- package/dist/async-rate-limiter/index.d.cts +3 -0
- package/dist/async-rate-limiter/index.d.ts +3 -0
- package/dist/async-rate-limiter/index.js +5 -0
- package/dist/async-throttler/createAsyncThrottler.cjs +108 -0
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -0
- package/dist/{cjs/async-throttler → async-throttler}/createAsyncThrottler.d.cts +23 -18
- package/dist/{esm/async-throttler → async-throttler}/createAsyncThrottler.d.ts +23 -18
- package/dist/async-throttler/createAsyncThrottler.js +108 -0
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -0
- package/dist/async-throttler/index.cjs +10 -0
- package/dist/async-throttler/index.d.cts +3 -0
- package/dist/async-throttler/index.d.ts +3 -0
- package/dist/async-throttler/index.js +5 -0
- package/dist/batcher/createBatcher.cjs +97 -0
- package/dist/batcher/createBatcher.cjs.map +1 -0
- package/dist/{cjs/batcher → batcher}/createBatcher.d.cts +22 -17
- package/dist/{esm/batcher → batcher}/createBatcher.d.ts +22 -17
- package/dist/batcher/createBatcher.js +97 -0
- package/dist/batcher/createBatcher.js.map +1 -0
- package/dist/batcher/index.cjs +10 -0
- package/dist/batcher/index.d.cts +3 -0
- package/dist/batcher/index.d.ts +3 -0
- package/dist/batcher/index.js +5 -0
- package/dist/debouncer/createDebouncedSignal.cjs +88 -0
- package/dist/debouncer/createDebouncedSignal.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncedSignal.d.cts +10 -8
- package/dist/{esm/debouncer → debouncer}/createDebouncedSignal.d.ts +10 -8
- package/dist/debouncer/createDebouncedSignal.js +88 -0
- package/dist/debouncer/createDebouncedSignal.js.map +1 -0
- package/dist/debouncer/createDebouncedValue.cjs +77 -0
- package/dist/debouncer/createDebouncedValue.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncedValue.d.cts +10 -4
- package/dist/{esm/debouncer → debouncer}/createDebouncedValue.d.ts +10 -4
- package/dist/debouncer/createDebouncedValue.js +77 -0
- package/dist/debouncer/createDebouncedValue.js.map +1 -0
- package/dist/debouncer/createDebouncer.cjs +101 -0
- package/dist/debouncer/createDebouncer.cjs.map +1 -0
- package/dist/{cjs/debouncer → debouncer}/createDebouncer.d.cts +23 -18
- package/dist/{esm/debouncer → debouncer}/createDebouncer.d.ts +23 -18
- package/dist/debouncer/createDebouncer.js +101 -0
- package/dist/debouncer/createDebouncer.js.map +1 -0
- package/dist/debouncer/index.cjs +14 -0
- package/dist/debouncer/index.d.cts +5 -0
- package/dist/debouncer/index.d.ts +5 -0
- package/dist/{esm/debouncer → debouncer}/index.js +5 -8
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/{esm/index.js → index.js} +8 -22
- package/dist/provider/PacerProvider.cjs +27 -0
- package/dist/provider/PacerProvider.cjs.map +1 -0
- package/dist/provider/PacerProvider.d.cts +29 -0
- package/dist/provider/PacerProvider.d.ts +29 -0
- package/dist/provider/PacerProvider.js +25 -0
- package/dist/provider/PacerProvider.js.map +1 -0
- package/dist/provider/index.cjs +5 -0
- package/dist/provider/index.d.cts +2 -0
- package/dist/provider/index.d.ts +2 -0
- package/dist/provider/index.js +3 -0
- package/dist/queuer/createQueuedSignal.cjs +129 -0
- package/dist/queuer/createQueuedSignal.cjs.map +1 -0
- package/dist/queuer/createQueuedSignal.d.cts +123 -0
- package/dist/queuer/createQueuedSignal.d.ts +123 -0
- package/dist/queuer/createQueuedSignal.js +129 -0
- package/dist/queuer/createQueuedSignal.js.map +1 -0
- package/dist/queuer/createQueuer.cjs +98 -0
- package/dist/queuer/createQueuer.cjs.map +1 -0
- package/dist/{cjs/queuer → queuer}/createQueuer.d.cts +22 -17
- package/dist/{esm/queuer → queuer}/createQueuer.d.ts +22 -17
- package/dist/queuer/createQueuer.js +98 -0
- package/dist/queuer/createQueuer.js.map +1 -0
- package/dist/queuer/index.cjs +12 -0
- package/dist/queuer/index.d.cts +4 -0
- package/dist/queuer/index.d.ts +4 -0
- package/dist/queuer/index.js +6 -0
- package/dist/rate-limiter/createRateLimitedSignal.cjs +102 -0
- package/dist/rate-limiter/createRateLimitedSignal.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimitedSignal.d.cts +10 -8
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimitedSignal.d.ts +10 -8
- package/dist/rate-limiter/createRateLimitedSignal.js +102 -0
- package/dist/rate-limiter/createRateLimitedSignal.js.map +1 -0
- package/dist/rate-limiter/createRateLimitedValue.cjs +102 -0
- package/dist/rate-limiter/createRateLimitedValue.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimitedValue.d.cts +40 -20
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimitedValue.d.ts +40 -20
- package/dist/rate-limiter/createRateLimitedValue.js +102 -0
- package/dist/rate-limiter/createRateLimitedValue.js.map +1 -0
- package/dist/rate-limiter/createRateLimiter.cjs +95 -0
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -0
- package/dist/{cjs/rate-limiter → rate-limiter}/createRateLimiter.d.cts +23 -18
- package/dist/{esm/rate-limiter → rate-limiter}/createRateLimiter.d.ts +23 -18
- package/dist/rate-limiter/createRateLimiter.js +95 -0
- package/dist/rate-limiter/createRateLimiter.js.map +1 -0
- package/dist/rate-limiter/index.cjs +14 -0
- package/dist/rate-limiter/index.d.cts +5 -0
- package/dist/rate-limiter/index.d.ts +5 -0
- package/dist/{esm/rate-limiter → rate-limiter}/index.js +4 -7
- package/dist/throttler/createThrottledSignal.cjs +79 -0
- package/dist/throttler/createThrottledSignal.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottledSignal.d.cts +10 -8
- package/dist/{esm/throttler → throttler}/createThrottledSignal.d.ts +10 -8
- package/dist/throttler/createThrottledSignal.js +79 -0
- package/dist/throttler/createThrottledSignal.js.map +1 -0
- package/dist/throttler/createThrottledValue.cjs +74 -0
- package/dist/throttler/createThrottledValue.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottledValue.d.cts +10 -4
- package/dist/{esm/throttler → throttler}/createThrottledValue.d.ts +10 -4
- package/dist/throttler/createThrottledValue.js +74 -0
- package/dist/throttler/createThrottledValue.js.map +1 -0
- package/dist/throttler/createThrottler.cjs +97 -0
- package/dist/throttler/createThrottler.cjs.map +1 -0
- package/dist/{cjs/throttler → throttler}/createThrottler.d.cts +23 -18
- package/dist/{esm/throttler → throttler}/createThrottler.d.ts +23 -18
- package/dist/throttler/createThrottler.js +97 -0
- package/dist/throttler/createThrottler.js.map +1 -0
- package/dist/throttler/index.cjs +14 -0
- package/dist/throttler/index.d.cts +5 -0
- package/dist/throttler/index.d.ts +5 -0
- package/dist/{esm/throttler → throttler}/index.js +5 -8
- package/dist/types/index.cjs +9 -0
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +3 -0
- package/dist/utils/index.cjs +9 -0
- package/dist/utils/index.d.cts +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +37 -106
- package/src/async-batcher/createAsyncBatcher.ts +12 -4
- package/src/async-debouncer/createAsyncDebouncer.ts +8 -2
- package/src/async-queuer/createAsyncQueuer.ts +12 -4
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +8 -2
- package/src/async-throttler/createAsyncThrottler.ts +8 -2
- package/src/batcher/createBatcher.ts +12 -4
- package/src/debouncer/createDebouncer.ts +12 -4
- package/src/index.ts +4 -0
- package/src/provider/PacerProvider.tsx +63 -0
- package/src/provider/index.ts +1 -0
- package/src/queuer/createQueuedSignal.ts +138 -0
- package/src/queuer/createQueuer.ts +12 -4
- package/src/queuer/index.ts +1 -0
- package/src/rate-limiter/createRateLimitedValue.ts +30 -16
- package/src/rate-limiter/createRateLimiter.ts +12 -4
- package/src/throttler/createThrottler.ts +12 -4
- package/dist/cjs/async-batcher/createAsyncBatcher.cjs +0 -14
- package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +0 -1
- package/dist/cjs/async-batcher/index.cjs +0 -12
- package/dist/cjs/async-batcher/index.cjs.map +0 -1
- package/dist/cjs/async-batcher/index.d.cts +0 -2
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +0 -20
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
- package/dist/cjs/async-debouncer/index.cjs +0 -12
- package/dist/cjs/async-debouncer/index.cjs.map +0 -1
- package/dist/cjs/async-debouncer/index.d.cts +0 -2
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs +0 -14
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +0 -1
- package/dist/cjs/async-queuer/index.cjs +0 -12
- package/dist/cjs/async-queuer/index.cjs.map +0 -1
- package/dist/cjs/async-queuer/index.d.cts +0 -2
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +0 -14
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
- package/dist/cjs/async-rate-limiter/index.cjs +0 -12
- package/dist/cjs/async-rate-limiter/index.cjs.map +0 -1
- package/dist/cjs/async-rate-limiter/index.d.cts +0 -2
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs +0 -14
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +0 -1
- package/dist/cjs/async-throttler/index.cjs +0 -12
- package/dist/cjs/async-throttler/index.cjs.map +0 -1
- package/dist/cjs/async-throttler/index.d.cts +0 -2
- package/dist/cjs/batcher/createBatcher.cjs +0 -14
- package/dist/cjs/batcher/createBatcher.cjs.map +0 -1
- package/dist/cjs/batcher/index.cjs +0 -12
- package/dist/cjs/batcher/index.cjs.map +0 -1
- package/dist/cjs/batcher/index.d.cts +0 -2
- package/dist/cjs/debouncer/createDebouncedSignal.cjs +0 -11
- package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +0 -1
- package/dist/cjs/debouncer/createDebouncedValue.cjs +0 -17
- package/dist/cjs/debouncer/createDebouncedValue.cjs.map +0 -1
- package/dist/cjs/debouncer/createDebouncer.cjs +0 -20
- package/dist/cjs/debouncer/createDebouncer.cjs.map +0 -1
- package/dist/cjs/debouncer/index.cjs +0 -16
- package/dist/cjs/debouncer/index.cjs.map +0 -1
- package/dist/cjs/debouncer/index.d.cts +0 -4
- package/dist/cjs/index.cjs +0 -42
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -20
- package/dist/cjs/queuer/createQueuer.cjs +0 -14
- package/dist/cjs/queuer/createQueuer.cjs.map +0 -1
- package/dist/cjs/queuer/index.cjs +0 -12
- package/dist/cjs/queuer/index.cjs.map +0 -1
- package/dist/cjs/queuer/index.d.cts +0 -2
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +0 -19
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +0 -13
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +0 -1
- package/dist/cjs/rate-limiter/createRateLimiter.cjs +0 -14
- package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +0 -1
- package/dist/cjs/rate-limiter/index.cjs +0 -16
- package/dist/cjs/rate-limiter/index.cjs.map +0 -1
- package/dist/cjs/rate-limiter/index.d.cts +0 -4
- package/dist/cjs/throttler/createThrottledSignal.cjs +0 -11
- package/dist/cjs/throttler/createThrottledSignal.cjs.map +0 -1
- package/dist/cjs/throttler/createThrottledValue.cjs +0 -17
- package/dist/cjs/throttler/createThrottledValue.cjs.map +0 -1
- package/dist/cjs/throttler/createThrottler.cjs +0 -20
- package/dist/cjs/throttler/createThrottler.cjs.map +0 -1
- package/dist/cjs/throttler/index.cjs +0 -16
- package/dist/cjs/throttler/index.cjs.map +0 -1
- package/dist/cjs/throttler/index.d.cts +0 -4
- package/dist/cjs/types/index.cjs +0 -10
- package/dist/cjs/types/index.cjs.map +0 -1
- package/dist/cjs/types/index.d.cts +0 -1
- package/dist/cjs/utils/index.cjs +0 -10
- package/dist/cjs/utils/index.cjs.map +0 -1
- package/dist/cjs/utils/index.d.cts +0 -1
- package/dist/esm/async-batcher/createAsyncBatcher.js +0 -14
- package/dist/esm/async-batcher/createAsyncBatcher.js.map +0 -1
- package/dist/esm/async-batcher/index.d.ts +0 -2
- package/dist/esm/async-batcher/index.js +0 -6
- package/dist/esm/async-batcher/index.js.map +0 -1
- package/dist/esm/async-debouncer/createAsyncDebouncer.js +0 -20
- package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +0 -1
- package/dist/esm/async-debouncer/index.d.ts +0 -2
- package/dist/esm/async-debouncer/index.js +0 -6
- package/dist/esm/async-debouncer/index.js.map +0 -1
- package/dist/esm/async-queuer/createAsyncQueuer.js +0 -14
- package/dist/esm/async-queuer/createAsyncQueuer.js.map +0 -1
- package/dist/esm/async-queuer/index.d.ts +0 -2
- package/dist/esm/async-queuer/index.js +0 -6
- package/dist/esm/async-queuer/index.js.map +0 -1
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +0 -14
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
- package/dist/esm/async-rate-limiter/index.d.ts +0 -2
- package/dist/esm/async-rate-limiter/index.js +0 -6
- package/dist/esm/async-rate-limiter/index.js.map +0 -1
- package/dist/esm/async-throttler/createAsyncThrottler.js +0 -14
- package/dist/esm/async-throttler/createAsyncThrottler.js.map +0 -1
- package/dist/esm/async-throttler/index.d.ts +0 -2
- package/dist/esm/async-throttler/index.js +0 -6
- package/dist/esm/async-throttler/index.js.map +0 -1
- package/dist/esm/batcher/createBatcher.js +0 -14
- package/dist/esm/batcher/createBatcher.js.map +0 -1
- package/dist/esm/batcher/index.d.ts +0 -2
- package/dist/esm/batcher/index.js +0 -6
- package/dist/esm/batcher/index.js.map +0 -1
- package/dist/esm/debouncer/createDebouncedSignal.js +0 -11
- package/dist/esm/debouncer/createDebouncedSignal.js.map +0 -1
- package/dist/esm/debouncer/createDebouncedValue.js +0 -17
- package/dist/esm/debouncer/createDebouncedValue.js.map +0 -1
- package/dist/esm/debouncer/createDebouncer.js +0 -20
- package/dist/esm/debouncer/createDebouncer.js.map +0 -1
- package/dist/esm/debouncer/index.d.ts +0 -4
- package/dist/esm/debouncer/index.js.map +0 -1
- package/dist/esm/index.d.ts +0 -20
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/queuer/createQueuer.js +0 -14
- package/dist/esm/queuer/createQueuer.js.map +0 -1
- package/dist/esm/queuer/index.d.ts +0 -2
- package/dist/esm/queuer/index.js +0 -6
- package/dist/esm/queuer/index.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimitedSignal.js +0 -19
- package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimitedValue.js +0 -13
- package/dist/esm/rate-limiter/createRateLimitedValue.js.map +0 -1
- package/dist/esm/rate-limiter/createRateLimiter.js +0 -14
- package/dist/esm/rate-limiter/createRateLimiter.js.map +0 -1
- package/dist/esm/rate-limiter/index.d.ts +0 -4
- package/dist/esm/rate-limiter/index.js.map +0 -1
- package/dist/esm/throttler/createThrottledSignal.js +0 -11
- package/dist/esm/throttler/createThrottledSignal.js.map +0 -1
- package/dist/esm/throttler/createThrottledValue.js +0 -17
- package/dist/esm/throttler/createThrottledValue.js.map +0 -1
- package/dist/esm/throttler/createThrottler.js +0 -20
- package/dist/esm/throttler/createThrottler.js.map +0 -1
- package/dist/esm/throttler/index.d.ts +0 -4
- package/dist/esm/throttler/index.js.map +0 -1
- package/dist/esm/types/index.d.ts +0 -1
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/index.js.map +0 -1
- package/dist/esm/utils/index.d.ts +0 -1
- package/dist/esm/utils/index.js +0 -2
- package/dist/esm/utils/index.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_createRateLimitedSignal = require('./createRateLimitedSignal.cjs');
|
|
2
|
+
let solid_js = require("solid-js");
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/createRateLimitedValue.ts
|
|
5
|
+
/**
|
|
6
|
+
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
7
|
+
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
|
|
12
|
+
*
|
|
13
|
+
* The rate limiter supports two types of windows:
|
|
14
|
+
* - 'fixed': A strict window that resets after the window period. All updates within the window count
|
|
15
|
+
* towards the limit, and the window resets completely after the period.
|
|
16
|
+
* - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
|
|
17
|
+
* consistent rate of updates over time.
|
|
18
|
+
*
|
|
19
|
+
* For smoother update patterns, consider:
|
|
20
|
+
* - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
|
|
21
|
+
* - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
|
|
22
|
+
*
|
|
23
|
+
* Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
|
|
24
|
+
*
|
|
25
|
+
* The hook returns a tuple containing:
|
|
26
|
+
* - An accessor function that provides the rate-limited value
|
|
27
|
+
* - The rate limiter instance with control methods
|
|
28
|
+
*
|
|
29
|
+
* For more direct control over rate limiting behavior without Solid state management,
|
|
30
|
+
* consider using the lower-level createRateLimiter hook instead.
|
|
31
|
+
*
|
|
32
|
+
* ## State Management and Selector
|
|
33
|
+
*
|
|
34
|
+
* The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
35
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
|
|
36
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
37
|
+
*
|
|
38
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
39
|
+
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
40
|
+
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
41
|
+
* the reactive system track the selected state values.
|
|
42
|
+
*
|
|
43
|
+
* Available rate limiter state properties:
|
|
44
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
45
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
46
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // Default behavior - no reactive state subscriptions
|
|
51
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
52
|
+
* limit: 5,
|
|
53
|
+
* window: 60000,
|
|
54
|
+
* windowType: 'sliding'
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
|
|
58
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
59
|
+
* rawValue,
|
|
60
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
61
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
62
|
+
* );
|
|
63
|
+
*
|
|
64
|
+
* // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
|
|
65
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
66
|
+
* rawValue,
|
|
67
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
68
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* // Opt-in to reactive updates when execution times change (optimized for window calculations)
|
|
72
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
73
|
+
* rawValue,
|
|
74
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
75
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // With rejection callback and fixed window
|
|
79
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
80
|
+
* limit: 3,
|
|
81
|
+
* window: 5000,
|
|
82
|
+
* windowType: 'fixed',
|
|
83
|
+
* onReject: (rateLimiter) => {
|
|
84
|
+
* console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
85
|
+
* }
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Access the selected rate limiter state (will be empty object {} unless selector provided)
|
|
89
|
+
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function createRateLimitedValue(value, initialOptions, selector) {
|
|
93
|
+
const [rateLimitedValue, setRateLimitedValue, rateLimiter] = require_createRateLimitedSignal.createRateLimitedSignal(value(), initialOptions, selector);
|
|
94
|
+
(0, solid_js.createEffect)(() => {
|
|
95
|
+
setRateLimitedValue(value());
|
|
96
|
+
});
|
|
97
|
+
return [rateLimitedValue, rateLimiter];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
exports.createRateLimitedValue = createRateLimitedValue;
|
|
102
|
+
//# sourceMappingURL=createRateLimitedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedValue.cjs","names":["createRateLimitedSignal"],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5CA,wDAAwB,OAAO,EAAE,gBAAgB,SAAS;AAE5D,kCAAmB;AACjB,sBAAoB,OAAO,CAAQ;GACnC;AAEF,QAAO,CAAC,kBAAkB,YAAY"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { SolidRateLimiter } from
|
|
2
|
-
import { Accessor, Setter } from
|
|
3
|
-
import { RateLimiterOptions, RateLimiterState } from
|
|
1
|
+
import { SolidRateLimiter } from "./createRateLimiter.cjs";
|
|
2
|
+
import { Accessor, Setter } from "solid-js";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/createRateLimitedValue.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
6
9
|
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
@@ -40,13 +43,9 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
40
43
|
* the reactive system track the selected state values.
|
|
41
44
|
*
|
|
42
45
|
* Available rate limiter state properties:
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
45
|
-
* - `
|
|
46
|
-
* - `nextWindowStart`: Unix timestamp when the next window will start
|
|
47
|
-
* - `msUntilNextWindow`: Milliseconds until the next window starts
|
|
48
|
-
* - `isAtLimit`: Whether the call limit for the current window has been reached
|
|
49
|
-
* - `status`: Current status ('disabled' | 'idle' | 'at-limit')
|
|
46
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
47
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
48
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
50
49
|
*
|
|
51
50
|
* @example
|
|
52
51
|
* ```tsx
|
|
@@ -57,21 +56,42 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
57
56
|
* windowType: 'sliding'
|
|
58
57
|
* });
|
|
59
58
|
*
|
|
60
|
-
* // Opt-in to reactive updates when
|
|
59
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
|
|
61
60
|
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
62
61
|
* rawValue,
|
|
63
|
-
* { limit: 5, window: 60000 },
|
|
64
|
-
* (state) => ({
|
|
62
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
63
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
65
64
|
* );
|
|
66
65
|
*
|
|
67
|
-
* //
|
|
68
|
-
*
|
|
66
|
+
* // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
|
|
67
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
68
|
+
* rawValue,
|
|
69
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
70
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
71
|
+
* );
|
|
69
72
|
*
|
|
70
|
-
* //
|
|
71
|
-
*
|
|
73
|
+
* // Opt-in to reactive updates when execution times change (optimized for window calculations)
|
|
74
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
75
|
+
* rawValue,
|
|
76
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
77
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
78
|
+
* );
|
|
79
|
+
*
|
|
80
|
+
* // With rejection callback and fixed window
|
|
81
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
82
|
+
* limit: 3,
|
|
83
|
+
* window: 5000,
|
|
84
|
+
* windowType: 'fixed',
|
|
85
|
+
* onReject: (rateLimiter) => {
|
|
86
|
+
* console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
72
89
|
*
|
|
73
|
-
* //
|
|
74
|
-
*
|
|
90
|
+
* // Access the selected rate limiter state (will be empty object {} unless selector provided)
|
|
91
|
+
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
75
92
|
* ```
|
|
76
93
|
*/
|
|
77
|
-
|
|
94
|
+
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createRateLimitedValue };
|
|
97
|
+
//# sourceMappingURL=createRateLimitedValue.d.cts.map
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { SolidRateLimiter } from
|
|
2
|
-
import { Accessor, Setter } from
|
|
3
|
-
import { RateLimiterOptions, RateLimiterState } from
|
|
1
|
+
import { SolidRateLimiter } from "./createRateLimiter.js";
|
|
2
|
+
import { Accessor, Setter } from "solid-js";
|
|
3
|
+
import { RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/createRateLimitedValue.d.ts
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
6
9
|
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
@@ -40,13 +43,9 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
40
43
|
* the reactive system track the selected state values.
|
|
41
44
|
*
|
|
42
45
|
* Available rate limiter state properties:
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
45
|
-
* - `
|
|
46
|
-
* - `nextWindowStart`: Unix timestamp when the next window will start
|
|
47
|
-
* - `msUntilNextWindow`: Milliseconds until the next window starts
|
|
48
|
-
* - `isAtLimit`: Whether the call limit for the current window has been reached
|
|
49
|
-
* - `status`: Current status ('disabled' | 'idle' | 'at-limit')
|
|
46
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
47
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
48
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
50
49
|
*
|
|
51
50
|
* @example
|
|
52
51
|
* ```tsx
|
|
@@ -57,21 +56,42 @@ import { RateLimiterOptions, RateLimiterState } from '@tanstack/pacer/rate-limit
|
|
|
57
56
|
* windowType: 'sliding'
|
|
58
57
|
* });
|
|
59
58
|
*
|
|
60
|
-
* // Opt-in to reactive updates when
|
|
59
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
|
|
61
60
|
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
62
61
|
* rawValue,
|
|
63
|
-
* { limit: 5, window: 60000 },
|
|
64
|
-
* (state) => ({
|
|
62
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
63
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
65
64
|
* );
|
|
66
65
|
*
|
|
67
|
-
* //
|
|
68
|
-
*
|
|
66
|
+
* // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
|
|
67
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
68
|
+
* rawValue,
|
|
69
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
70
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
71
|
+
* );
|
|
69
72
|
*
|
|
70
|
-
* //
|
|
71
|
-
*
|
|
73
|
+
* // Opt-in to reactive updates when execution times change (optimized for window calculations)
|
|
74
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
75
|
+
* rawValue,
|
|
76
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
77
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
78
|
+
* );
|
|
79
|
+
*
|
|
80
|
+
* // With rejection callback and fixed window
|
|
81
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
82
|
+
* limit: 3,
|
|
83
|
+
* window: 5000,
|
|
84
|
+
* windowType: 'fixed',
|
|
85
|
+
* onReject: (rateLimiter) => {
|
|
86
|
+
* console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
72
89
|
*
|
|
73
|
-
* //
|
|
74
|
-
*
|
|
90
|
+
* // Access the selected rate limiter state (will be empty object {} unless selector provided)
|
|
91
|
+
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
75
92
|
* ```
|
|
76
93
|
*/
|
|
77
|
-
|
|
94
|
+
declare function createRateLimitedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: RateLimiterOptions<Setter<TValue>>, selector?: (state: RateLimiterState) => TSelected): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>];
|
|
95
|
+
//#endregion
|
|
96
|
+
export { createRateLimitedValue };
|
|
97
|
+
//# sourceMappingURL=createRateLimitedValue.d.ts.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRateLimitedSignal } from "./createRateLimitedSignal.js";
|
|
2
|
+
import { createEffect } from "solid-js";
|
|
3
|
+
|
|
4
|
+
//#region src/rate-limiter/createRateLimitedValue.ts
|
|
5
|
+
/**
|
|
6
|
+
* A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.
|
|
7
|
+
* This hook uses Solid's createSignal internally to manage the rate-limited state.
|
|
8
|
+
*
|
|
9
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
10
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
11
|
+
* or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
|
|
12
|
+
*
|
|
13
|
+
* The rate limiter supports two types of windows:
|
|
14
|
+
* - 'fixed': A strict window that resets after the window period. All updates within the window count
|
|
15
|
+
* towards the limit, and the window resets completely after the period.
|
|
16
|
+
* - 'sliding': A rolling window that allows updates as old ones expire. This provides a more
|
|
17
|
+
* consistent rate of updates over time.
|
|
18
|
+
*
|
|
19
|
+
* For smoother update patterns, consider:
|
|
20
|
+
* - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)
|
|
21
|
+
* - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)
|
|
22
|
+
*
|
|
23
|
+
* Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
|
|
24
|
+
*
|
|
25
|
+
* The hook returns a tuple containing:
|
|
26
|
+
* - An accessor function that provides the rate-limited value
|
|
27
|
+
* - The rate limiter instance with control methods
|
|
28
|
+
*
|
|
29
|
+
* For more direct control over rate limiting behavior without Solid state management,
|
|
30
|
+
* consider using the lower-level createRateLimiter hook instead.
|
|
31
|
+
*
|
|
32
|
+
* ## State Management and Selector
|
|
33
|
+
*
|
|
34
|
+
* The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.
|
|
35
|
+
* The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,
|
|
36
|
+
* optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
|
|
37
|
+
*
|
|
38
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
39
|
+
* tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
|
|
40
|
+
* full control over when your component subscribes to state changes. Only when you provide a selector will
|
|
41
|
+
* the reactive system track the selected state values.
|
|
42
|
+
*
|
|
43
|
+
* Available rate limiter state properties:
|
|
44
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
45
|
+
* - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
|
|
46
|
+
* - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // Default behavior - no reactive state subscriptions
|
|
51
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
52
|
+
* limit: 5,
|
|
53
|
+
* window: 60000,
|
|
54
|
+
* windowType: 'sliding'
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
|
|
58
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
59
|
+
* rawValue,
|
|
60
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
61
|
+
* (state) => ({ executionCount: state.executionCount })
|
|
62
|
+
* );
|
|
63
|
+
*
|
|
64
|
+
* // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
|
|
65
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
66
|
+
* rawValue,
|
|
67
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
68
|
+
* (state) => ({ rejectionCount: state.rejectionCount })
|
|
69
|
+
* );
|
|
70
|
+
*
|
|
71
|
+
* // Opt-in to reactive updates when execution times change (optimized for window calculations)
|
|
72
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
|
|
73
|
+
* rawValue,
|
|
74
|
+
* { limit: 5, window: 60000, windowType: 'sliding' },
|
|
75
|
+
* (state) => ({ executionTimes: state.executionTimes })
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* // With rejection callback and fixed window
|
|
79
|
+
* const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
|
|
80
|
+
* limit: 3,
|
|
81
|
+
* window: 5000,
|
|
82
|
+
* windowType: 'fixed',
|
|
83
|
+
* onReject: (rateLimiter) => {
|
|
84
|
+
* console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
85
|
+
* }
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Access the selected rate limiter state (will be empty object {} unless selector provided)
|
|
89
|
+
* const { executionCount, rejectionCount } = rateLimiter.state;
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
function createRateLimitedValue(value, initialOptions, selector) {
|
|
93
|
+
const [rateLimitedValue, setRateLimitedValue, rateLimiter] = createRateLimitedSignal(value(), initialOptions, selector);
|
|
94
|
+
createEffect(() => {
|
|
95
|
+
setRateLimitedValue(value());
|
|
96
|
+
});
|
|
97
|
+
return [rateLimitedValue, rateLimiter];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createRateLimitedValue };
|
|
102
|
+
//# sourceMappingURL=createRateLimitedValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedValue.js","names":[],"sources":["../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All updates within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows updates as old ones expire. This provides a more\n * consistent rate of updates over time.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the rate-limited value\n * - The rate limiter instance with control methods\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying rate limiter instance.\n * The `selector` parameter allows you to specify which rate limiter state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available rate limiter state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations\n * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding'\n * });\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to reactive updates when execution times change (optimized for window calculations)\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(\n * rawValue,\n * { limit: 5, window: 60000, windowType: 'sliding' },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // With rejection callback and fixed window\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * windowType: 'fixed',\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access the selected rate limiter state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state;\n * ```\n */\nexport function createRateLimitedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>>,\n selector?: (state: RateLimiterState) => TSelected,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, TSelected>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions, selector)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,SAAgB,uBACd,OACA,gBACA,UACiE;CACjE,MAAM,CAAC,kBAAkB,qBAAqB,eAC5C,wBAAwB,OAAO,EAAE,gBAAgB,SAAS;AAE5D,oBAAmB;AACjB,sBAAoB,OAAO,CAAQ;GACnC;AAEF,QAAO,CAAC,kBAAkB,YAAY"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
+
let __tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
let __tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
|
|
4
|
+
|
|
5
|
+
//#region src/rate-limiter/createRateLimiter.ts
|
|
6
|
+
/**
|
|
7
|
+
* A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
|
|
8
|
+
*
|
|
9
|
+
* This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that
|
|
10
|
+
* you can integrate with any state management solution (createSignal, etc).
|
|
11
|
+
*
|
|
12
|
+
* Rate limiting is a simple "hard limit" approach that allows executions until a maximum count is reached within
|
|
13
|
+
* a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,
|
|
14
|
+
* it does not attempt to space out or collapse executions intelligently.
|
|
15
|
+
*
|
|
16
|
+
* The rate limiter supports two types of windows:
|
|
17
|
+
* - 'fixed': A strict window that resets after the window period. All executions within the window count
|
|
18
|
+
* towards the limit, and the window resets completely after the period.
|
|
19
|
+
* - 'sliding': A rolling window that allows executions as old ones expire. This provides a more
|
|
20
|
+
* consistent rate of execution over time.
|
|
21
|
+
*
|
|
22
|
+
* For smoother execution patterns:
|
|
23
|
+
* - Use throttling when you want consistent spacing between executions (e.g. UI updates)
|
|
24
|
+
* - Use debouncing when you want to collapse rapid-fire events (e.g. search input)
|
|
25
|
+
* - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)
|
|
26
|
+
*
|
|
27
|
+
* ## State Management and Selector
|
|
28
|
+
*
|
|
29
|
+
* The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
30
|
+
* to specify which state changes will trigger a re-render, optimizing performance by preventing
|
|
31
|
+
* unnecessary re-renders when irrelevant state changes occur.
|
|
32
|
+
*
|
|
33
|
+
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
34
|
+
* tracking by providing a selector function. This prevents unnecessary re-renders and gives you
|
|
35
|
+
* full control over when your component updates. Only when you provide a selector will the
|
|
36
|
+
* component re-render when the selected state values change.
|
|
37
|
+
*
|
|
38
|
+
* Available state properties:
|
|
39
|
+
* - `executionCount`: Number of function executions that have been completed
|
|
40
|
+
* - `rejectionCount`: Number of function calls that were rejected due to rate limiting
|
|
41
|
+
* - `remainingInWindow`: Number of executions remaining in the current window
|
|
42
|
+
* - `nextWindowTime`: Timestamp when the next window begins
|
|
43
|
+
* - `currentWindowStart`: Timestamp when the current window started
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* // Default behavior - no reactive state subscriptions
|
|
48
|
+
* const rateLimiter = createRateLimiter(apiCall, {
|
|
49
|
+
* limit: 5,
|
|
50
|
+
* window: 60000,
|
|
51
|
+
* windowType: 'sliding',
|
|
52
|
+
* onReject: (rateLimiter) => {
|
|
53
|
+
* console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // Opt-in to re-render when rate limit state changes (optimized for UI feedback)
|
|
58
|
+
* const rateLimiter = createRateLimiter(
|
|
59
|
+
* apiCall,
|
|
60
|
+
* { limit: 5, window: 60000 },
|
|
61
|
+
* (state) => ({
|
|
62
|
+
* remainingInWindow: state.remainingInWindow,
|
|
63
|
+
* rejectionCount: state.rejectionCount
|
|
64
|
+
* })
|
|
65
|
+
* );
|
|
66
|
+
*
|
|
67
|
+
* // Opt-in to re-render when execution metrics change (optimized for tracking progress)
|
|
68
|
+
* const rateLimiter = createRateLimiter(
|
|
69
|
+
* apiCall,
|
|
70
|
+
* { limit: 5, window: 60000 },
|
|
71
|
+
* (state) => ({
|
|
72
|
+
* executionCount: state.executionCount,
|
|
73
|
+
* nextWindowTime: state.nextWindowTime
|
|
74
|
+
* })
|
|
75
|
+
* );
|
|
76
|
+
*
|
|
77
|
+
* // Access the selected state (will be empty object {} unless selector provided)
|
|
78
|
+
* const { remainingInWindow, rejectionCount } = rateLimiter.state();
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
function createRateLimiter(fn, options, selector = () => ({})) {
|
|
82
|
+
const rateLimiter = new __tanstack_pacer_rate_limiter.RateLimiter(fn, {
|
|
83
|
+
...require_PacerProvider.useDefaultPacerOptions().rateLimiter,
|
|
84
|
+
...options
|
|
85
|
+
});
|
|
86
|
+
const state = (0, __tanstack_solid_store.useStore)(rateLimiter.store, selector);
|
|
87
|
+
return {
|
|
88
|
+
...rateLimiter,
|
|
89
|
+
state
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.createRateLimiter = createRateLimiter;
|
|
95
|
+
//# sourceMappingURL=createRateLimiter.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimiter.cjs","names":["RateLimiter","useDefaultPacerOptions"],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * onReject: (rateLimiter) => {\n * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * remainingInWindow: state.remainingInWindow,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * nextWindowTime: state.nextWindowTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { remainingInWindow, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n\n const state = useStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAMlC,MAAM,cAAc,IAAIA,0CAAiB,IALnB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE0D;CAE3D,MAAM,6CAAiB,YAAY,OAAO,SAAS;AAEnD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { Store } from "@tanstack/solid-store";
|
|
2
|
+
import { Accessor } from "solid-js";
|
|
3
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
4
|
+
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
5
|
+
|
|
6
|
+
//#region src/rate-limiter/createRateLimiter.d.ts
|
|
7
|
+
interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state that will be updated when the rate limiter state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `rateLimiter.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Accessor<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, as it has not been wrapped in a `useStore` hook internally.
|
|
17
|
+
* Although, you can make the state reactive by using the `useStore` in your own usage.
|
|
18
|
+
*/
|
|
19
|
+
readonly store: Store<Readonly<RateLimiterState>>;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
|
|
@@ -91,4 +93,7 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> exten
|
|
|
91
93
|
* const { remainingInWindow, rejectionCount } = rateLimiter.state();
|
|
92
94
|
* ```
|
|
93
95
|
*/
|
|
94
|
-
|
|
96
|
+
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { SolidRateLimiter, createRateLimiter };
|
|
99
|
+
//# sourceMappingURL=createRateLimiter.d.cts.map
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Store } from
|
|
3
|
-
import {
|
|
4
|
-
import { AnyFunction } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { Accessor } from "solid-js";
|
|
2
|
+
import { Store } from "@tanstack/solid-store";
|
|
3
|
+
import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
|
|
4
|
+
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
|
+
|
|
6
|
+
//#region src/rate-limiter/createRateLimiter.d.ts
|
|
7
|
+
interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* Reactive state that will be updated when the rate limiter state changes
|
|
10
|
+
*
|
|
11
|
+
* Use this instead of `rateLimiter.store.state`
|
|
12
|
+
*/
|
|
13
|
+
readonly state: Accessor<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, as it has not been wrapped in a `useStore` hook internally.
|
|
17
|
+
* Although, you can make the state reactive by using the `useStore` in your own usage.
|
|
18
|
+
*/
|
|
19
|
+
readonly store: Store<Readonly<RateLimiterState>>;
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.
|
|
@@ -91,4 +93,7 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> exten
|
|
|
91
93
|
* const { remainingInWindow, rejectionCount } = rateLimiter.state();
|
|
92
94
|
* ```
|
|
93
95
|
*/
|
|
94
|
-
|
|
96
|
+
declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { SolidRateLimiter, createRateLimiter };
|
|
99
|
+
//# sourceMappingURL=createRateLimiter.d.ts.map
|