@tanstack/pacer 0.21.1 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -6
- package/dist/async-batcher.d.ts +11 -14
- package/dist/async-batcher.js +186 -132
- package/dist/async-debouncer.d.ts +10 -13
- package/dist/async-debouncer.js +187 -146
- package/dist/async-queuer.d.ts +12 -14
- package/dist/async-queuer.js +384 -259
- package/dist/async-rate-limiter.d.ts +9 -12
- package/dist/async-rate-limiter.js +198 -147
- package/dist/async-retryer.d.ts +10 -10
- package/dist/async-retryer.js +209 -188
- package/dist/async-throttler.d.ts +10 -13
- package/dist/async-throttler.js +215 -161
- package/dist/batcher.d.ts +5 -8
- package/dist/batcher.js +107 -87
- package/dist/debouncer.d.ts +6 -9
- package/dist/debouncer.js +99 -86
- package/dist/event-client.d.ts +8 -11
- package/dist/event-client.js +1 -2
- package/dist/index.js +1 -1
- package/dist/queuer.d.ts +8 -10
- package/dist/queuer.js +277 -207
- package/dist/rate-limiter.d.ts +6 -9
- package/dist/rate-limiter.js +127 -109
- package/dist/throttler.d.ts +6 -9
- package/dist/throttler.js +127 -90
- package/dist/types.d.ts +4 -6
- package/dist/utils.d.ts +3 -6
- package/dist/utils.js +1 -2
- package/package.json +23 -70
- package/dist/async-batcher.cjs +0 -337
- package/dist/async-batcher.cjs.map +0 -1
- package/dist/async-batcher.d.cts +0 -344
- package/dist/async-batcher.js.map +0 -1
- package/dist/async-debouncer.cjs +0 -330
- package/dist/async-debouncer.cjs.map +0 -1
- package/dist/async-debouncer.d.cts +0 -300
- package/dist/async-debouncer.js.map +0 -1
- package/dist/async-queuer.cjs +0 -484
- package/dist/async-queuer.cjs.map +0 -1
- package/dist/async-queuer.d.cts +0 -440
- package/dist/async-queuer.js.map +0 -1
- package/dist/async-rate-limiter.cjs +0 -373
- package/dist/async-rate-limiter.cjs.map +0 -1
- package/dist/async-rate-limiter.d.cts +0 -357
- package/dist/async-rate-limiter.js.map +0 -1
- package/dist/async-retryer.cjs +0 -374
- package/dist/async-retryer.cjs.map +0 -1
- package/dist/async-retryer.d.cts +0 -319
- package/dist/async-retryer.js.map +0 -1
- package/dist/async-throttler.cjs +0 -347
- package/dist/async-throttler.cjs.map +0 -1
- package/dist/async-throttler.d.cts +0 -320
- package/dist/async-throttler.js.map +0 -1
- package/dist/batcher.cjs +0 -200
- package/dist/batcher.cjs.map +0 -1
- package/dist/batcher.d.cts +0 -180
- package/dist/batcher.js.map +0 -1
- package/dist/debouncer.cjs +0 -203
- package/dist/debouncer.cjs.map +0 -1
- package/dist/debouncer.d.cts +0 -167
- package/dist/debouncer.js.map +0 -1
- package/dist/event-client.cjs +0 -64
- package/dist/event-client.cjs.map +0 -1
- package/dist/event-client.d.cts +0 -66
- package/dist/event-client.js.map +0 -1
- package/dist/index.cjs +0 -52
- package/dist/index.d.cts +0 -15
- package/dist/queuer.cjs +0 -401
- package/dist/queuer.cjs.map +0 -1
- package/dist/queuer.d.cts +0 -345
- package/dist/queuer.js.map +0 -1
- package/dist/rate-limiter.cjs +0 -263
- package/dist/rate-limiter.cjs.map +0 -1
- package/dist/rate-limiter.d.cts +0 -215
- package/dist/rate-limiter.js.map +0 -1
- package/dist/throttler.cjs +0 -215
- package/dist/throttler.cjs.map +0 -1
- package/dist/throttler.d.cts +0 -207
- package/dist/throttler.js.map +0 -1
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +0 -13
- package/dist/utils.cjs +0 -14
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -8
- package/dist/utils.js.map +0 -1
- package/src/async-batcher.ts +0 -594
- package/src/async-debouncer.ts +0 -565
- package/src/async-queuer.ts +0 -925
- package/src/async-rate-limiter.ts +0 -647
- package/src/async-retryer.ts +0 -684
- package/src/async-throttler.ts +0 -633
- package/src/batcher.ts +0 -329
- package/src/debouncer.ts +0 -334
- package/src/event-client.ts +0 -129
- package/src/index.ts +0 -24
- package/src/queuer.ts +0 -740
- package/src/rate-limiter.ts +0 -429
- package/src/throttler.ts +0 -380
- package/src/types.ts +0 -12
- package/src/utils.ts +0 -12
package/src/event-client.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { EventClient } from '@tanstack/devtools-event-client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Payload on the devtools event bus must be JSON-serializable: `ClientEventBus`
|
|
5
|
-
* always stringifies events for `emitToServer` and `BroadcastChannel`, so live
|
|
6
|
-
* util instances (with reactive `store` graphs) cannot be sent as-is.
|
|
7
|
-
*
|
|
8
|
-
* Live instances are kept in {@link pacerDevtoolsInstancesByKey} for the panel.
|
|
9
|
-
*/
|
|
10
|
-
export interface PacerDevtoolsWirePayload {
|
|
11
|
-
key: string
|
|
12
|
-
store: { state: unknown }
|
|
13
|
-
options: unknown
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const pacerDevtoolsInstancesByKey = new Map<string, unknown>()
|
|
17
|
-
|
|
18
|
-
export function registerPacerDevtoolsInstance(
|
|
19
|
-
key: string,
|
|
20
|
-
instance: unknown,
|
|
21
|
-
): void {
|
|
22
|
-
pacerDevtoolsInstancesByKey.set(key, instance)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function getPacerDevtoolsInstance(key: string): unknown {
|
|
26
|
-
return pacerDevtoolsInstancesByKey.get(key)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function cloneJsonSafe(value: unknown): unknown {
|
|
30
|
-
if (value === undefined) {
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return JSON.parse(JSON.stringify(value)) as unknown
|
|
35
|
-
} catch {
|
|
36
|
-
return null
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readStoreSnapshot(store: {
|
|
41
|
-
get?: () => unknown
|
|
42
|
-
state?: unknown
|
|
43
|
-
}): unknown {
|
|
44
|
-
if (typeof store.get === 'function') {
|
|
45
|
-
return store.get()
|
|
46
|
-
}
|
|
47
|
-
return store.state
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function toPacerDevtoolsWirePayload(instance: {
|
|
51
|
-
key: string
|
|
52
|
-
store: { get?: () => unknown; state?: unknown }
|
|
53
|
-
options: unknown
|
|
54
|
-
}): PacerDevtoolsWirePayload {
|
|
55
|
-
return {
|
|
56
|
-
key: instance.key,
|
|
57
|
-
store: { state: cloneJsonSafe(readStoreSnapshot(instance.store)) },
|
|
58
|
-
options: cloneJsonSafe(instance.options),
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Suffix-only keys: {@link EventClient} prepends `pluginId:` (`pacer:`) at runtime
|
|
64
|
-
* for `emit` / `on`. Wire `type` values are `pacer:${key}`.
|
|
65
|
-
*/
|
|
66
|
-
export interface PacerEventMap {
|
|
67
|
-
'd-AsyncBatcher': PacerDevtoolsWirePayload
|
|
68
|
-
'd-AsyncDebouncer': PacerDevtoolsWirePayload
|
|
69
|
-
'd-AsyncQueuer': PacerDevtoolsWirePayload
|
|
70
|
-
'd-AsyncRateLimiter': PacerDevtoolsWirePayload
|
|
71
|
-
'd-AsyncRetryer': PacerDevtoolsWirePayload
|
|
72
|
-
'd-AsyncThrottler': PacerDevtoolsWirePayload
|
|
73
|
-
'd-Batcher': PacerDevtoolsWirePayload
|
|
74
|
-
'd-Debouncer': PacerDevtoolsWirePayload
|
|
75
|
-
'd-Queuer': PacerDevtoolsWirePayload
|
|
76
|
-
'd-RateLimiter': PacerDevtoolsWirePayload
|
|
77
|
-
'd-Throttler': PacerDevtoolsWirePayload
|
|
78
|
-
AsyncBatcher: PacerDevtoolsWirePayload
|
|
79
|
-
AsyncDebouncer: PacerDevtoolsWirePayload
|
|
80
|
-
AsyncQueuer: PacerDevtoolsWirePayload
|
|
81
|
-
AsyncRateLimiter: PacerDevtoolsWirePayload
|
|
82
|
-
AsyncRetryer: PacerDevtoolsWirePayload
|
|
83
|
-
AsyncThrottler: PacerDevtoolsWirePayload
|
|
84
|
-
Batcher: PacerDevtoolsWirePayload
|
|
85
|
-
Debouncer: PacerDevtoolsWirePayload
|
|
86
|
-
Queuer: PacerDevtoolsWirePayload
|
|
87
|
-
RateLimiter: PacerDevtoolsWirePayload
|
|
88
|
-
Throttler: PacerDevtoolsWirePayload
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export type PacerEventName = keyof PacerEventMap
|
|
92
|
-
|
|
93
|
-
type PacerUtilEmitSource = {
|
|
94
|
-
key?: string
|
|
95
|
-
store: { get?: () => unknown; state?: unknown }
|
|
96
|
-
options: unknown
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
class PacerEventClient extends EventClient<PacerEventMap> {
|
|
100
|
-
constructor(props?: { debug: boolean }) {
|
|
101
|
-
super({
|
|
102
|
-
pluginId: 'pacer',
|
|
103
|
-
debug: props?.debug,
|
|
104
|
-
/**
|
|
105
|
-
* TanStack Devtools starts `ClientEventBus` inside an async dynamic import
|
|
106
|
-
* after the first commit. Pacer utils often emit during the first render
|
|
107
|
-
* (constructor → store sync). `EventClient` only retries `tanstack-connect`
|
|
108
|
-
* `#maxRetries` times at `reconnectEveryMs` before it gives up and drops
|
|
109
|
-
* all queued events permanently. Default 300ms × 5 ≈ 1.5s is often too
|
|
110
|
-
* short; Form uses 1000ms here for the same reason.
|
|
111
|
-
*/
|
|
112
|
-
reconnectEveryMs: 1000,
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export const emitChange = <TEvent extends keyof PacerEventMap>(
|
|
118
|
-
event: TEvent,
|
|
119
|
-
instance: PacerUtilEmitSource,
|
|
120
|
-
) => {
|
|
121
|
-
const key = instance.key
|
|
122
|
-
if (!key) {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
registerPacerDevtoolsInstance(key, instance)
|
|
126
|
-
pacerEventClient.emit(event, toPacerDevtoolsWirePayload({ ...instance, key }))
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const pacerEventClient = new PacerEventClient()
|
package/src/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from './async-batcher'
|
|
2
|
-
export * from './async-debouncer'
|
|
3
|
-
export * from './async-queuer'
|
|
4
|
-
export * from './async-rate-limiter'
|
|
5
|
-
export * from './async-retryer'
|
|
6
|
-
export * from './async-throttler'
|
|
7
|
-
export * from './batcher'
|
|
8
|
-
export * from './debouncer'
|
|
9
|
-
export * from './queuer'
|
|
10
|
-
export * from './rate-limiter'
|
|
11
|
-
export * from './throttler'
|
|
12
|
-
export * from './types'
|
|
13
|
-
export * from './utils'
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
emitChange,
|
|
17
|
-
getPacerDevtoolsInstance,
|
|
18
|
-
pacerEventClient,
|
|
19
|
-
} from './event-client'
|
|
20
|
-
export type {
|
|
21
|
-
PacerDevtoolsWirePayload,
|
|
22
|
-
PacerEventMap,
|
|
23
|
-
PacerEventName,
|
|
24
|
-
} from './event-client'
|