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