@buoy-gg/events 7.0.28 → 7.0.30
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/lib/commonjs/components/EventsModal.js +2 -1
- package/lib/commonjs/components/EventsModal.js.map +1 -1
- package/lib/module/components/EventsModal.js +2 -1
- package/lib/module/components/EventsModal.js.map +1 -1
- package/lib/typescript/components/EventsModal.d.ts.map +1 -1
- package/package.json +7 -8
- package/src/components/EventsCopySettingsView.tsx +0 -781
- package/src/components/EventsModal.tsx +0 -536
- package/src/components/ReactQueryEventDetail.tsx +0 -418
- package/src/components/UnifiedEventDetail.tsx +0 -596
- package/src/components/UnifiedEventFilters.tsx +0 -226
- package/src/components/UnifiedEventItem.tsx +0 -467
- package/src/components/UnifiedEventList.tsx +0 -216
- package/src/components/UnifiedEventViewer.tsx +0 -133
- package/src/hooks/useUnifiedEvents.ts +0 -573
- package/src/index.tsx +0 -128
- package/src/preset.tsx +0 -57
- package/src/sources/sourceIds.ts +0 -25
- package/src/stores/unifiedEventStore.ts +0 -686
- package/src/sync/__tests__/eventsSyncAdapter.test.ts +0 -471
- package/src/sync/eventsSyncAdapter.ts +0 -391
- package/src/types/copySettings.ts +0 -299
- package/src/types/index.ts +0 -101
- package/src/utils/autoDiscoverEventSources.ts +0 -1087
- package/src/utils/badgeSelectionStorage.ts +0 -81
- package/src/utils/copySettingsStorage.ts +0 -61
- package/src/utils/correlationUtils.ts +0 -146
- package/src/utils/eventExportFormatter.ts +0 -2066
- package/src/utils/eventTransformers.ts +0 -567
|
@@ -1,686 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified Event Store
|
|
3
|
-
*
|
|
4
|
-
* Central store that aggregates events from all DevTools sources
|
|
5
|
-
* into a single chronological timeline.
|
|
6
|
-
*
|
|
7
|
-
* Uses auto-discovery to find installed tool packages - no hard dependencies required!
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type {
|
|
11
|
-
UnifiedEvent,
|
|
12
|
-
UnifiedEventListener,
|
|
13
|
-
EventSource,
|
|
14
|
-
} from "../types";
|
|
15
|
-
import {
|
|
16
|
-
getCachedDiscovery,
|
|
17
|
-
getAggregatedSubscriberCounts,
|
|
18
|
-
type DiscoveredEventSource,
|
|
19
|
-
type AggregatedSubscriberCounts,
|
|
20
|
-
} from "../utils/autoDiscoverEventSources";
|
|
21
|
-
import { EVENT_SOURCE_TO_DISCOVERY_ID } from "../sources/sourceIds";
|
|
22
|
-
|
|
23
|
-
const MAX_EVENTS = 200;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Source IDs that subscribeToAll() must NOT auto-subscribe to.
|
|
27
|
-
*
|
|
28
|
-
* These are high-frequency sources the UI excludes from DEFAULT_ENABLED_SOURCES
|
|
29
|
-
* (see useUnifiedEvents.ts). "render" (highlight-updates) fires on every
|
|
30
|
-
* component render — tens of events per second — which floods the shared store
|
|
31
|
-
* (capped at MAX_EVENTS), shoves real events out, and shows up as hidden noise
|
|
32
|
-
* ("1 of 100"). subscribeToAll() is the dashboard-watch path; it must mirror
|
|
33
|
-
* the on-device default of leaving render OFF unless the user opts in.
|
|
34
|
-
*/
|
|
35
|
-
const SUBSCRIBE_ALL_EXCLUDED_SOURCE_IDS = new Set<string>(["render"]);
|
|
36
|
-
|
|
37
|
-
class UnifiedEventStore {
|
|
38
|
-
private events: UnifiedEvent[] = [];
|
|
39
|
-
private listeners: Set<UnifiedEventListener> = new Set();
|
|
40
|
-
private activeSources: Set<EventSource> = new Set();
|
|
41
|
-
private clearListeners: Set<() => void> = new Set();
|
|
42
|
-
private remoteAvailableSources: Set<EventSource> | null = null;
|
|
43
|
-
|
|
44
|
-
// Track which sources are currently subscribed, ref-counted so independent
|
|
45
|
-
// consumers (the on-device EventsModal and the remote dashboard) can each
|
|
46
|
-
// request a source and the underlying capture only stops when the LAST one
|
|
47
|
-
// drops it. Presence of a key still means "subscribed".
|
|
48
|
-
private sourceUnsubscribers: Map<
|
|
49
|
-
string,
|
|
50
|
-
{ unsubscribe: () => void; refCount: number }
|
|
51
|
-
> = new Map();
|
|
52
|
-
|
|
53
|
-
// Discovery IDs the remote dashboard (sync adapter) currently wants. Tracked
|
|
54
|
-
// separately so the remote consumer can be diffed/cleared independently of
|
|
55
|
-
// the on-device consumer's subscriptions.
|
|
56
|
-
private remoteDiscoveryIds: Set<string> = new Set();
|
|
57
|
-
|
|
58
|
-
// Map network event IDs to unified event IDs for updates
|
|
59
|
-
private networkEventIdMap: Map<string, string> = new Map();
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get all discovered event sources
|
|
63
|
-
*/
|
|
64
|
-
getDiscoveredSources(): DiscoveredEventSource[] {
|
|
65
|
-
return getCachedDiscovery().sources;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Get which event source types are available. In remote mirror mode this
|
|
70
|
-
* reflects the synced device's availability instead of local discovery.
|
|
71
|
-
*/
|
|
72
|
-
getAvailableEventSources(): Set<EventSource> {
|
|
73
|
-
if (this.remoteAvailableSources) {
|
|
74
|
-
return this.remoteAvailableSources;
|
|
75
|
-
}
|
|
76
|
-
return getCachedDiscovery().availableEventSources;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ===========================================================================
|
|
80
|
-
// REMOTE MIRROR MODE
|
|
81
|
-
// ===========================================================================
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Override source availability with the synced device's (auto-discovery
|
|
85
|
-
* finds nothing on the dashboard — the tool packages live on the device).
|
|
86
|
-
* Pass null to restore local discovery.
|
|
87
|
-
*
|
|
88
|
-
* Notifies listeners when the set actually changes so consumers
|
|
89
|
-
* (useUnifiedEvents) can refresh their available-source list — this is the
|
|
90
|
-
* only signal the dashboard's filter badge bar gets when capture is OFF and
|
|
91
|
-
* no events are flowing to trigger replaceEvents().
|
|
92
|
-
*/
|
|
93
|
-
setRemoteAvailableSources(sources: EventSource[] | null): void {
|
|
94
|
-
const next = sources ? new Set(sources) : null;
|
|
95
|
-
const prev = this.remoteAvailableSources;
|
|
96
|
-
const unchanged =
|
|
97
|
-
(prev === null && next === null) ||
|
|
98
|
-
(!!prev &&
|
|
99
|
-
!!next &&
|
|
100
|
-
prev.size === next.size &&
|
|
101
|
-
[...next].every((s) => prev.has(s)));
|
|
102
|
-
this.remoteAvailableSources = next;
|
|
103
|
-
if (!unchanged) {
|
|
104
|
-
this.notifyListeners();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Replace the entire event list and notify listeners. Used in remote
|
|
110
|
-
* mirror mode where full snapshots arrive from a synced device.
|
|
111
|
-
*/
|
|
112
|
-
replaceEvents(events: UnifiedEvent[]): void {
|
|
113
|
-
this.events = events.slice(0, MAX_EVENTS);
|
|
114
|
-
this.activeSources = new Set(events.map((event) => event.source));
|
|
115
|
-
this.notifyListeners();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Listen for clearEvents() calls. Used in remote mirror mode to forward a
|
|
120
|
-
* clear performed in the dashboard UI to the synced device.
|
|
121
|
-
*/
|
|
122
|
-
onClear(listener: () => void): () => void {
|
|
123
|
-
this.clearListeners.add(listener);
|
|
124
|
-
return () => {
|
|
125
|
-
this.clearListeners.delete(listener);
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Subscribe to all available event sources
|
|
131
|
-
*/
|
|
132
|
-
async subscribeToAll(): Promise<void> {
|
|
133
|
-
const { sources } = getCachedDiscovery();
|
|
134
|
-
|
|
135
|
-
for (const source of sources) {
|
|
136
|
-
// Skip high-frequency sources the UI leaves off by default (e.g. render).
|
|
137
|
-
// Subscribing to them here would flood the timeline with events that are
|
|
138
|
-
// then filtered out of the display — see SUBSCRIBE_ALL_EXCLUDED_SOURCE_IDS.
|
|
139
|
-
if (SUBSCRIBE_ALL_EXCLUDED_SOURCE_IDS.has(source.id)) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
await this.subscribeToSource(source);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Subscribe to a specific event source by ID
|
|
148
|
-
*/
|
|
149
|
-
async subscribeToSource(source: DiscoveredEventSource): Promise<void> {
|
|
150
|
-
const existing = this.sourceUnsubscribers.get(source.id);
|
|
151
|
-
if (existing) {
|
|
152
|
-
existing.refCount++; // Another consumer wants it — just count.
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Reserve the slot synchronously (refCount 1) so concurrent subscribe calls
|
|
157
|
-
// for the same source ref-count instead of double-subscribing during the
|
|
158
|
-
// awaits below.
|
|
159
|
-
const entry = { unsubscribe: () => {}, refCount: 1 };
|
|
160
|
-
this.sourceUnsubscribers.set(source.id, entry);
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
// Run setup if needed
|
|
164
|
-
if (source.setup) {
|
|
165
|
-
await source.setup();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Subscribe and track the unsubscriber
|
|
169
|
-
const unsubscribe = await source.subscribe((event) => {
|
|
170
|
-
this.addEvent(event);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
if (unsubscribe) {
|
|
174
|
-
entry.unsubscribe = unsubscribe;
|
|
175
|
-
}
|
|
176
|
-
} catch {
|
|
177
|
-
// Failed - source may not be available. Drop the reservation unless other
|
|
178
|
-
// consumers incremented it while we were awaiting.
|
|
179
|
-
if (this.sourceUnsubscribers.get(source.id) === entry && entry.refCount <= 1) {
|
|
180
|
-
this.sourceUnsubscribers.delete(source.id);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Unsubscribe from a specific source by ID. Ref-counted: the real teardown
|
|
187
|
-
* only runs when the last consumer drops it.
|
|
188
|
-
*/
|
|
189
|
-
unsubscribeFromSource(sourceId: string): void {
|
|
190
|
-
const entry = this.sourceUnsubscribers.get(sourceId);
|
|
191
|
-
if (!entry) return;
|
|
192
|
-
entry.refCount--;
|
|
193
|
-
if (entry.refCount <= 0) {
|
|
194
|
-
entry.unsubscribe();
|
|
195
|
-
this.sourceUnsubscribers.delete(sourceId);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Subscribe to storage events (if @buoy-gg/storage is installed)
|
|
201
|
-
*/
|
|
202
|
-
async subscribeToStorage(): Promise<void> {
|
|
203
|
-
const { sources } = getCachedDiscovery();
|
|
204
|
-
const storageSource = sources.find((s) => s.id === "storage");
|
|
205
|
-
if (storageSource) {
|
|
206
|
-
await this.subscribeToSource(storageSource);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Unsubscribe from storage events
|
|
212
|
-
*/
|
|
213
|
-
unsubscribeFromStorage(): void {
|
|
214
|
-
this.unsubscribeFromSource("storage");
|
|
215
|
-
this.activeSources.delete("storage-async");
|
|
216
|
-
this.activeSources.delete("storage-mmkv");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Subscribe to Redux actions (if @buoy-gg/redux is installed)
|
|
221
|
-
*/
|
|
222
|
-
subscribeToRedux(): void {
|
|
223
|
-
const { sources } = getCachedDiscovery();
|
|
224
|
-
const reduxSource = sources.find((s) => s.id === "redux");
|
|
225
|
-
if (reduxSource) {
|
|
226
|
-
this.subscribeToSource(reduxSource);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Unsubscribe from Redux actions
|
|
232
|
-
*/
|
|
233
|
-
unsubscribeFromRedux(): void {
|
|
234
|
-
this.unsubscribeFromSource("redux");
|
|
235
|
-
this.activeSources.delete("redux");
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Subscribe to network events (if @buoy-gg/network is installed)
|
|
240
|
-
*/
|
|
241
|
-
subscribeToNetwork(): void {
|
|
242
|
-
const { sources } = getCachedDiscovery();
|
|
243
|
-
const networkSource = sources.find((s) => s.id === "network");
|
|
244
|
-
if (networkSource) {
|
|
245
|
-
this.subscribeToSource(networkSource);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Unsubscribe from network events
|
|
251
|
-
*/
|
|
252
|
-
unsubscribeFromNetwork(): void {
|
|
253
|
-
this.unsubscribeFromSource("network");
|
|
254
|
-
this.activeSources.delete("network");
|
|
255
|
-
// Don't clear networkEventIdMap - it's needed to deduplicate events
|
|
256
|
-
// when resubscribing while requests are still in flight
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Subscribe to React Query events (if @buoy-gg/react-query is installed)
|
|
261
|
-
*/
|
|
262
|
-
subscribeToReactQuery(): void {
|
|
263
|
-
const { sources } = getCachedDiscovery();
|
|
264
|
-
const rqSource = sources.find((s) => s.id === "react-query");
|
|
265
|
-
if (rqSource) {
|
|
266
|
-
this.subscribeToSource(rqSource);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Unsubscribe from React Query events
|
|
272
|
-
*/
|
|
273
|
-
unsubscribeFromReactQuery(): void {
|
|
274
|
-
this.unsubscribeFromSource("react-query");
|
|
275
|
-
this.activeSources.delete("react-query");
|
|
276
|
-
this.activeSources.delete("react-query-query");
|
|
277
|
-
this.activeSources.delete("react-query-mutation");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Subscribe to route events (if @buoy-gg/route-events is installed)
|
|
282
|
-
*/
|
|
283
|
-
subscribeToRoutes(): void {
|
|
284
|
-
const { sources } = getCachedDiscovery();
|
|
285
|
-
const routeSource = sources.find((s) => s.id === "route-events");
|
|
286
|
-
if (routeSource) {
|
|
287
|
-
this.subscribeToSource(routeSource);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Unsubscribe from route events
|
|
293
|
-
*/
|
|
294
|
-
unsubscribeFromRoutes(): void {
|
|
295
|
-
this.unsubscribeFromSource("route-events");
|
|
296
|
-
this.activeSources.delete("route");
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Subscribe to Zustand state changes (if @buoy-gg/zustand is installed)
|
|
301
|
-
*/
|
|
302
|
-
subscribeToZustand(): void {
|
|
303
|
-
const { sources } = getCachedDiscovery();
|
|
304
|
-
const zustandSource = sources.find((s) => s.id === "zustand");
|
|
305
|
-
if (zustandSource) {
|
|
306
|
-
this.subscribeToSource(zustandSource);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Unsubscribe from Zustand state changes
|
|
312
|
-
*/
|
|
313
|
-
unsubscribeFromZustand(): void {
|
|
314
|
-
this.unsubscribeFromSource("zustand");
|
|
315
|
-
this.activeSources.delete("zustand");
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Subscribe to Jotai atom changes (if @buoy-gg/jotai is installed)
|
|
320
|
-
*/
|
|
321
|
-
subscribeToJotai(): void {
|
|
322
|
-
const { sources } = getCachedDiscovery();
|
|
323
|
-
const jotaiSource = sources.find((s) => s.id === "jotai");
|
|
324
|
-
if (jotaiSource) {
|
|
325
|
-
this.subscribeToSource(jotaiSource);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Unsubscribe from Jotai atom changes
|
|
331
|
-
*/
|
|
332
|
-
unsubscribeFromJotai(): void {
|
|
333
|
-
this.unsubscribeFromSource("jotai");
|
|
334
|
-
this.activeSources.delete("jotai");
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Subscribe to render events (if @buoy-gg/highlight-updates is installed)
|
|
339
|
-
*/
|
|
340
|
-
subscribeToRender(): void {
|
|
341
|
-
const { sources } = getCachedDiscovery();
|
|
342
|
-
const renderSource = sources.find((s) => s.id === "render");
|
|
343
|
-
if (renderSource) {
|
|
344
|
-
this.subscribeToSource(renderSource);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Unsubscribe from render events
|
|
350
|
-
*/
|
|
351
|
-
unsubscribeFromRender(): void {
|
|
352
|
-
this.unsubscribeFromSource("render");
|
|
353
|
-
this.activeSources.delete("render");
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Add an event to the store
|
|
358
|
-
*/
|
|
359
|
-
private addEvent(event: UnifiedEvent): void {
|
|
360
|
-
// Handle network event updates (same network request completing)
|
|
361
|
-
if (event.source === "network") {
|
|
362
|
-
const originalEvent = event.originalEvent as { id?: string };
|
|
363
|
-
if (originalEvent?.id) {
|
|
364
|
-
const existingUnifiedId = this.networkEventIdMap.get(originalEvent.id);
|
|
365
|
-
if (existingUnifiedId) {
|
|
366
|
-
// Update existing event
|
|
367
|
-
const existingIndex = this.events.findIndex((e) => e.id === existingUnifiedId);
|
|
368
|
-
if (existingIndex >= 0) {
|
|
369
|
-
event.id = existingUnifiedId; // Keep same unified ID
|
|
370
|
-
this.events = [
|
|
371
|
-
...this.events.slice(0, existingIndex),
|
|
372
|
-
event,
|
|
373
|
-
...this.events.slice(existingIndex + 1),
|
|
374
|
-
];
|
|
375
|
-
this.notifyListeners();
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
// Track new network event
|
|
380
|
-
this.networkEventIdMap.set(originalEvent.id, event.id);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// Add to beginning (newest first) and trim to max size
|
|
385
|
-
this.events = [event, ...this.events].slice(0, MAX_EVENTS);
|
|
386
|
-
|
|
387
|
-
// Track active source
|
|
388
|
-
this.activeSources.add(event.source);
|
|
389
|
-
|
|
390
|
-
// Notify listeners
|
|
391
|
-
this.notifyListeners();
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Get all events, optionally filtered
|
|
396
|
-
*/
|
|
397
|
-
getEvents(enabledSources?: Set<EventSource>): UnifiedEvent[] {
|
|
398
|
-
if (!enabledSources || enabledSources.size === 0) {
|
|
399
|
-
return this.events;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return this.events.filter((event) => enabledSources.has(event.source));
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Get sources that have at least one event
|
|
407
|
-
*/
|
|
408
|
-
getActiveSources(): EventSource[] {
|
|
409
|
-
return Array.from(this.activeSources);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Get count of events per source
|
|
414
|
-
*/
|
|
415
|
-
getSourceCounts(): Record<EventSource, number> {
|
|
416
|
-
const counts: Record<EventSource, number> = {
|
|
417
|
-
"storage-async": 0,
|
|
418
|
-
"storage-mmkv": 0,
|
|
419
|
-
redux: 0,
|
|
420
|
-
network: 0,
|
|
421
|
-
"react-query": 0,
|
|
422
|
-
"react-query-query": 0,
|
|
423
|
-
"react-query-mutation": 0,
|
|
424
|
-
route: 0,
|
|
425
|
-
zustand: 0,
|
|
426
|
-
jotai: 0,
|
|
427
|
-
render: 0,
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
for (const event of this.events) {
|
|
431
|
-
counts[event.source]++;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return counts;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Clear all events
|
|
439
|
-
*/
|
|
440
|
-
clearEvents(): void {
|
|
441
|
-
this.events = [];
|
|
442
|
-
this.activeSources.clear();
|
|
443
|
-
this.networkEventIdMap.clear();
|
|
444
|
-
this.notifyListeners();
|
|
445
|
-
this.clearListeners.forEach((listener) => {
|
|
446
|
-
try {
|
|
447
|
-
listener();
|
|
448
|
-
} catch {
|
|
449
|
-
// Ignore listener errors
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* Subscribe to store changes
|
|
456
|
-
*/
|
|
457
|
-
subscribe(listener: UnifiedEventListener): () => void {
|
|
458
|
-
this.listeners.add(listener);
|
|
459
|
-
|
|
460
|
-
// Immediately call with current events
|
|
461
|
-
listener(this.events);
|
|
462
|
-
|
|
463
|
-
// Return unsubscribe function
|
|
464
|
-
return () => {
|
|
465
|
-
this.listeners.delete(listener);
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Notify all listeners of changes
|
|
471
|
-
*/
|
|
472
|
-
private notifyListeners(): void {
|
|
473
|
-
const events = this.events;
|
|
474
|
-
this.listeners.forEach((listener) => listener(events));
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Get total event count
|
|
479
|
-
*/
|
|
480
|
-
getEventCount(): number {
|
|
481
|
-
return this.events.length;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Unsubscribe from all sources
|
|
486
|
-
*/
|
|
487
|
-
unsubscribeAll(): void {
|
|
488
|
-
// Hard reset: tear down every tracked source regardless of ref-count.
|
|
489
|
-
for (const [, entry] of this.sourceUnsubscribers) {
|
|
490
|
-
entry.unsubscribe();
|
|
491
|
-
}
|
|
492
|
-
this.sourceUnsubscribers.clear();
|
|
493
|
-
|
|
494
|
-
// Clear active + remote source bookkeeping (all subscriptions are gone).
|
|
495
|
-
this.activeSources.clear();
|
|
496
|
-
this.remoteDiscoveryIds.clear();
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Remote-consumer channel: the dashboard sync adapter declares which event
|
|
501
|
-
* sources it wants the device to capture. Diffed against the previous remote
|
|
502
|
-
* set so only changed sources are (un)subscribed; ref-counting keeps the
|
|
503
|
-
* on-device EventsModal's own subscriptions intact. Pass "all" to capture
|
|
504
|
-
* every discovered source except the high-frequency excluded ones.
|
|
505
|
-
*/
|
|
506
|
-
async setRemoteEnabledSources(
|
|
507
|
-
sources: EventSource[] | "all"
|
|
508
|
-
): Promise<void> {
|
|
509
|
-
const { sources: discovered } = getCachedDiscovery();
|
|
510
|
-
|
|
511
|
-
let nextIds: Set<string>;
|
|
512
|
-
if (sources === "all") {
|
|
513
|
-
nextIds = new Set(
|
|
514
|
-
discovered
|
|
515
|
-
.map((s) => s.id)
|
|
516
|
-
.filter((id) => !SUBSCRIBE_ALL_EXCLUDED_SOURCE_IDS.has(id))
|
|
517
|
-
);
|
|
518
|
-
} else {
|
|
519
|
-
nextIds = new Set<string>();
|
|
520
|
-
for (const src of sources) {
|
|
521
|
-
const id = EVENT_SOURCE_TO_DISCOVERY_ID[src];
|
|
522
|
-
if (id) nextIds.add(id);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// Swap the tracked set SYNCHRONOUSLY (before the awaits) so a watch's
|
|
527
|
-
// ensureRemoteSourcesDefault() that runs in between sees the new selection
|
|
528
|
-
// and won't re-broaden to "all".
|
|
529
|
-
const prevIds = this.remoteDiscoveryIds;
|
|
530
|
-
this.remoteDiscoveryIds = nextIds;
|
|
531
|
-
|
|
532
|
-
// Subscribe newly-requested sources.
|
|
533
|
-
for (const id of nextIds) {
|
|
534
|
-
if (!prevIds.has(id)) {
|
|
535
|
-
const source = discovered.find((s) => s.id === id);
|
|
536
|
-
if (source) await this.subscribeToSource(source);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
// Release sources the remote no longer wants.
|
|
540
|
-
for (const id of prevIds) {
|
|
541
|
-
if (!nextIds.has(id)) {
|
|
542
|
-
this.unsubscribeFromSource(id);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Called by the sync adapter when a dashboard starts watching: default to all
|
|
549
|
-
* sources, but ONLY if the dashboard hasn't already declared a selection for
|
|
550
|
-
* this watch session (the setEnabledSources action can arrive before the
|
|
551
|
-
* watch). Keeps backward compatibility with dashboards that never narrow.
|
|
552
|
-
*/
|
|
553
|
-
ensureRemoteSourcesDefault(): void {
|
|
554
|
-
if (this.remoteDiscoveryIds.size === 0) {
|
|
555
|
-
void this.setRemoteEnabledSources("all");
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Release all of the remote consumer's source subscriptions (e.g. when the
|
|
561
|
-
* dashboard stops watching the events tool). Ref-counting means sources the
|
|
562
|
-
* on-device EventsModal also wants stay subscribed.
|
|
563
|
-
*/
|
|
564
|
-
clearRemoteSources(): void {
|
|
565
|
-
for (const id of this.remoteDiscoveryIds) {
|
|
566
|
-
this.unsubscribeFromSource(id);
|
|
567
|
-
}
|
|
568
|
-
this.remoteDiscoveryIds.clear();
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Check if a specific source is currently subscribed
|
|
573
|
-
*/
|
|
574
|
-
isSourceSubscribed(source: EventSource): boolean {
|
|
575
|
-
// Map EventSource to source IDs
|
|
576
|
-
switch (source) {
|
|
577
|
-
case "storage-async":
|
|
578
|
-
case "storage-mmkv":
|
|
579
|
-
return this.sourceUnsubscribers.has("storage");
|
|
580
|
-
case "redux":
|
|
581
|
-
return this.sourceUnsubscribers.has("redux");
|
|
582
|
-
case "network":
|
|
583
|
-
return this.sourceUnsubscribers.has("network");
|
|
584
|
-
case "react-query":
|
|
585
|
-
case "react-query-query":
|
|
586
|
-
case "react-query-mutation":
|
|
587
|
-
return this.sourceUnsubscribers.has("react-query");
|
|
588
|
-
case "route":
|
|
589
|
-
return this.sourceUnsubscribers.has("route-events");
|
|
590
|
-
case "zustand":
|
|
591
|
-
return this.sourceUnsubscribers.has("zustand");
|
|
592
|
-
case "jotai":
|
|
593
|
-
return this.sourceUnsubscribers.has("jotai");
|
|
594
|
-
case "render":
|
|
595
|
-
return this.sourceUnsubscribers.has("render");
|
|
596
|
-
default:
|
|
597
|
-
return false;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Get subscription status for all sources
|
|
603
|
-
*/
|
|
604
|
-
getSubscriptionStatus(): Record<EventSource, boolean> {
|
|
605
|
-
return {
|
|
606
|
-
"storage-async": this.sourceUnsubscribers.has("storage"),
|
|
607
|
-
"storage-mmkv": this.sourceUnsubscribers.has("storage"),
|
|
608
|
-
redux: this.sourceUnsubscribers.has("redux"),
|
|
609
|
-
network: this.sourceUnsubscribers.has("network"),
|
|
610
|
-
"react-query": this.sourceUnsubscribers.has("react-query"),
|
|
611
|
-
"react-query-query": this.sourceUnsubscribers.has("react-query"),
|
|
612
|
-
"react-query-mutation": this.sourceUnsubscribers.has("react-query"),
|
|
613
|
-
route: this.sourceUnsubscribers.has("route-events"),
|
|
614
|
-
zustand: this.sourceUnsubscribers.has("zustand"),
|
|
615
|
-
jotai: this.sourceUnsubscribers.has("jotai"),
|
|
616
|
-
render: this.sourceUnsubscribers.has("render"),
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Get subscriber counts from all underlying event stores.
|
|
622
|
-
* Useful for debugging the event system.
|
|
623
|
-
*/
|
|
624
|
-
getSubscriberCounts(): AggregatedSubscriberCounts {
|
|
625
|
-
return getAggregatedSubscriberCounts();
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// Singleton instance
|
|
630
|
-
export const unifiedEventStore = new UnifiedEventStore();
|
|
631
|
-
|
|
632
|
-
// Convenience exports
|
|
633
|
-
export const subscribeToStorage = (): Promise<void> =>
|
|
634
|
-
unifiedEventStore.subscribeToStorage();
|
|
635
|
-
export const unsubscribeFromStorage = () =>
|
|
636
|
-
unifiedEventStore.unsubscribeFromStorage();
|
|
637
|
-
export const subscribeToRedux = () =>
|
|
638
|
-
unifiedEventStore.subscribeToRedux();
|
|
639
|
-
export const unsubscribeFromRedux = () =>
|
|
640
|
-
unifiedEventStore.unsubscribeFromRedux();
|
|
641
|
-
export const subscribeToNetwork = () =>
|
|
642
|
-
unifiedEventStore.subscribeToNetwork();
|
|
643
|
-
export const unsubscribeFromNetwork = () =>
|
|
644
|
-
unifiedEventStore.unsubscribeFromNetwork();
|
|
645
|
-
export const subscribeToReactQuery = () =>
|
|
646
|
-
unifiedEventStore.subscribeToReactQuery();
|
|
647
|
-
export const unsubscribeFromReactQuery = () =>
|
|
648
|
-
unifiedEventStore.unsubscribeFromReactQuery();
|
|
649
|
-
export const subscribeToRoutes = () =>
|
|
650
|
-
unifiedEventStore.subscribeToRoutes();
|
|
651
|
-
export const unsubscribeFromRoutes = () =>
|
|
652
|
-
unifiedEventStore.unsubscribeFromRoutes();
|
|
653
|
-
export const subscribeToZustand = () =>
|
|
654
|
-
unifiedEventStore.subscribeToZustand();
|
|
655
|
-
export const unsubscribeFromZustand = () =>
|
|
656
|
-
unifiedEventStore.unsubscribeFromZustand();
|
|
657
|
-
export const subscribeToJotai = () =>
|
|
658
|
-
unifiedEventStore.subscribeToJotai();
|
|
659
|
-
export const unsubscribeFromJotai = () =>
|
|
660
|
-
unifiedEventStore.unsubscribeFromJotai();
|
|
661
|
-
export const subscribeToRender = () =>
|
|
662
|
-
unifiedEventStore.subscribeToRender();
|
|
663
|
-
export const unsubscribeFromRender = () =>
|
|
664
|
-
unifiedEventStore.unsubscribeFromRender();
|
|
665
|
-
export const getEvents = (enabledSources?: Set<EventSource>) =>
|
|
666
|
-
unifiedEventStore.getEvents(enabledSources);
|
|
667
|
-
export const getActiveSources = () => unifiedEventStore.getActiveSources();
|
|
668
|
-
export const getSourceCounts = () => unifiedEventStore.getSourceCounts();
|
|
669
|
-
export const clearEvents = () => unifiedEventStore.clearEvents();
|
|
670
|
-
export const subscribe = (listener: UnifiedEventListener) =>
|
|
671
|
-
unifiedEventStore.subscribe(listener);
|
|
672
|
-
export const getEventCount = () => unifiedEventStore.getEventCount();
|
|
673
|
-
export const isSourceSubscribed = (source: EventSource) =>
|
|
674
|
-
unifiedEventStore.isSourceSubscribed(source);
|
|
675
|
-
export const getSubscriptionStatus = () =>
|
|
676
|
-
unifiedEventStore.getSubscriptionStatus();
|
|
677
|
-
export const unsubscribeAll = () => unifiedEventStore.unsubscribeAll();
|
|
678
|
-
|
|
679
|
-
// New exports for auto-discovery
|
|
680
|
-
export const getDiscoveredSources = () => unifiedEventStore.getDiscoveredSources();
|
|
681
|
-
export const getAvailableEventSources = () => unifiedEventStore.getAvailableEventSources();
|
|
682
|
-
export const subscribeToAll = () => unifiedEventStore.subscribeToAll();
|
|
683
|
-
export const getSubscriberCounts = () => unifiedEventStore.getSubscriberCounts();
|
|
684
|
-
|
|
685
|
-
// Re-export type for convenience
|
|
686
|
-
export type { AggregatedSubscriberCounts } from "../utils/autoDiscoverEventSources";
|