@buoy-gg/events 7.0.41 → 7.0.43

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