@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,419 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useUnifiedEvents = useUnifiedEvents;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _sharedUi = require("@buoy-gg/shared-ui");
|
|
9
|
-
var _unifiedEventStore = require("../stores/unifiedEventStore");
|
|
10
|
-
var _badgeSelectionStorage = require("../utils/badgeSelectionStorage");
|
|
11
|
-
var _autoDiscoverEventSources = require("../utils/autoDiscoverEventSources");
|
|
12
|
-
var _eventVisibility = require("../utils/eventVisibility");
|
|
13
|
-
/**
|
|
14
|
-
* useUnifiedEvents Hook
|
|
15
|
-
*
|
|
16
|
-
* Main hook for consuming unified events from all sources.
|
|
17
|
-
* Automatically discovers and subscribes to available event sources.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Match an event against the header search query. Searches the two fields the
|
|
22
|
-
* row actually renders (title/subtitle) plus a network event's full URL — the
|
|
23
|
-
* title only carries the path, so a query for the host or a query-string value
|
|
24
|
-
* would otherwise miss. `query` must already be lowercased and trimmed.
|
|
25
|
-
*/
|
|
26
|
-
function matchesSearch(event, query) {
|
|
27
|
-
if (event.title.toLowerCase().includes(query)) return true;
|
|
28
|
-
if (event.subtitle.toLowerCase().includes(query)) return true;
|
|
29
|
-
const url = event.originalEvent?.url;
|
|
30
|
-
return typeof url === "string" && url.toLowerCase().includes(query);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* All possible sources for display
|
|
35
|
-
*/
|
|
36
|
-
const ALL_DISPLAY_SOURCES = ["storage-async", "redux", "network", "react-query-query", "react-query-mutation", "route", "zustand", "jotai", "render"];
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Sources enabled by default on first load.
|
|
40
|
-
* "render" is excluded because high-frequency render tracking can cause
|
|
41
|
-
* performance issues or crashes in unoptimized apps.
|
|
42
|
-
*/
|
|
43
|
-
const DEFAULT_ENABLED_SOURCES = ALL_DISPLAY_SOURCES.filter(s => s !== "render");
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Map display sources to actual event sources they should match
|
|
47
|
-
*/
|
|
48
|
-
const SOURCE_TO_EVENT_SOURCES = {
|
|
49
|
-
"storage-async": ["storage-async", "storage-mmkv"],
|
|
50
|
-
"storage-mmkv": ["storage-mmkv"],
|
|
51
|
-
redux: ["redux"],
|
|
52
|
-
network: ["network"],
|
|
53
|
-
"react-query": ["react-query", "react-query-query"],
|
|
54
|
-
"react-query-query": ["react-query", "react-query-query"],
|
|
55
|
-
"react-query-mutation": ["react-query-mutation"],
|
|
56
|
-
route: ["route"],
|
|
57
|
-
zustand: ["zustand"],
|
|
58
|
-
jotai: ["jotai"],
|
|
59
|
-
render: ["render"]
|
|
60
|
-
};
|
|
61
|
-
function useUnifiedEvents(options) {
|
|
62
|
-
const {
|
|
63
|
-
isPro
|
|
64
|
-
} = (0, _sharedUi.useFeatureGate)();
|
|
65
|
-
const eventLimit = (0, _sharedUi.useLimit)("events.entries");
|
|
66
|
-
// Shared ignored-domain/URL patterns (same store as the Network tool). Network
|
|
67
|
-
// events matching these are hidden from the events list too, keeping both
|
|
68
|
-
// tools' filtering perfectly in sync.
|
|
69
|
-
const {
|
|
70
|
-
patterns: ignoredPatterns
|
|
71
|
-
} = (0, _sharedUi.useIgnoredPatterns)();
|
|
72
|
-
const [events, setEvents] = (0, _react.useState)([]);
|
|
73
|
-
const [enabledSources, setEnabledSources] = (0, _react.useState)(() => new Set(DEFAULT_ENABLED_SOURCES));
|
|
74
|
-
const [isCapturing, setIsCapturing] = (0, _react.useState)(true);
|
|
75
|
-
const [searchText, setSearchText] = (0, _react.useState)("");
|
|
76
|
-
const isStateRestoredRef = (0, _react.useRef)(false);
|
|
77
|
-
|
|
78
|
-
// Wall-clock windows during which capture was OFF. Releasing this hook's
|
|
79
|
-
// subscriptions is not enough to keep the list still: source subscriptions
|
|
80
|
-
// are ref-counted and a watching dashboard legitimately keeps capturing into
|
|
81
|
-
// the SHARED store while the device is paused. So events stamped inside a
|
|
82
|
-
// paused window stay hidden — and stay hidden AFTER resume too: the user was
|
|
83
|
-
// told the tool wasn't listening, and a resume that surfaces a backlog of
|
|
84
|
-
// "unheard" events reads as capture-while-off (pause → clear → tap around →
|
|
85
|
-
// resume must come back BLANK). The open window's start is persisted beside
|
|
86
|
-
// the capturing flag, so a remount or relaunch while paused keeps hiding
|
|
87
|
-
// from the ORIGINAL pause press, not from the reopen.
|
|
88
|
-
const effectiveCapturing = options?.capturingOverride ?? isCapturing;
|
|
89
|
-
const pausedAtRef = (0, _react.useRef)(null);
|
|
90
|
-
const pausedWindowsRef = (0, _react.useRef)([]);
|
|
91
|
-
// Bumped whenever a window opens or closes so the visibility memo re-runs.
|
|
92
|
-
const [pauseVersion, setPauseVersion] = (0, _react.useState)(0);
|
|
93
|
-
(0, _react.useEffect)(() => {
|
|
94
|
-
if (effectiveCapturing) {
|
|
95
|
-
if (pausedAtRef.current !== null) {
|
|
96
|
-
pausedWindowsRef.current = [...pausedWindowsRef.current, [pausedAtRef.current, Date.now()]];
|
|
97
|
-
pausedAtRef.current = null;
|
|
98
|
-
setPauseVersion(v => v + 1);
|
|
99
|
-
(0, _badgeSelectionStorage.savePausedAt)(null);
|
|
100
|
-
}
|
|
101
|
-
} else if (pausedAtRef.current === null) {
|
|
102
|
-
pausedAtRef.current = Date.now();
|
|
103
|
-
setPauseVersion(v => v + 1);
|
|
104
|
-
(0, _badgeSelectionStorage.savePausedAt)(pausedAtRef.current);
|
|
105
|
-
}
|
|
106
|
-
}, [effectiveCapturing]);
|
|
107
|
-
const isInPausedGap = (0, _react.useCallback)(timestamp => {
|
|
108
|
-
const pausedAt = pausedAtRef.current;
|
|
109
|
-
if (pausedAt !== null && timestamp > pausedAt) return true;
|
|
110
|
-
for (const [start, end] of pausedWindowsRef.current) {
|
|
111
|
-
if (timestamp > start && timestamp <= end) return true;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}, []);
|
|
115
|
-
|
|
116
|
-
// Get discovered sources (which packages are installed).
|
|
117
|
-
// Held in state, not a mount-only memo, because in remote mirror mode
|
|
118
|
-
// (desktop dashboard) the device's available sources arrive asynchronously
|
|
119
|
-
// via setRemoteAvailableSources() — after first paint. We refresh this from
|
|
120
|
-
// the store's notify path below so the filter badge bar appears once the
|
|
121
|
-
// first device snapshot lands. The reference is kept stable while the set is
|
|
122
|
-
// unchanged so dependent memos/effects don't re-run on every event.
|
|
123
|
-
const [discoveredSources, setDiscoveredSources] = (0, _react.useState)(() => (0, _unifiedEventStore.getAvailableEventSources)());
|
|
124
|
-
|
|
125
|
-
// Subscribe to subscriber count changes for instant UI updates (TanStack Query pattern)
|
|
126
|
-
const [subscriberCountVersion, setSubscriberCountVersion] = (0, _react.useState)(0);
|
|
127
|
-
(0, _react.useEffect)(() => {
|
|
128
|
-
return (0, _sharedUi.subscribeToSubscriberCountChanges)(() => {
|
|
129
|
-
setSubscriberCountVersion(v => v + 1);
|
|
130
|
-
});
|
|
131
|
-
}, []);
|
|
132
|
-
|
|
133
|
-
// Get available display sources (only show sources for installed packages)
|
|
134
|
-
const availableDisplaySources = (0, _react.useMemo)(() => {
|
|
135
|
-
return ALL_DISPLAY_SOURCES.filter(displaySource => {
|
|
136
|
-
const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource] || [displaySource];
|
|
137
|
-
// Check if any of the event sources for this display source are available
|
|
138
|
-
return eventSources.some(es => discoveredSources.has(es));
|
|
139
|
-
});
|
|
140
|
-
}, [discoveredSources]);
|
|
141
|
-
|
|
142
|
-
// Subscribe to store changes (always subscribe to get events when they come).
|
|
143
|
-
// Also refresh discoveredSources here: in remote mirror mode the device's
|
|
144
|
-
// availability is set right before replaceEvents() fires this listener, so
|
|
145
|
-
// this is where the badge bar first learns which sources exist. Keep the
|
|
146
|
-
// Set reference stable when membership is unchanged to avoid re-running the
|
|
147
|
-
// availableDisplaySources memo / restore-state effect on every event.
|
|
148
|
-
(0, _react.useEffect)(() => {
|
|
149
|
-
// Frame-coalesced: the aggregator hears EVERY tool's emissions, so
|
|
150
|
-
// bursts previously produced one whole-modal commit per event (see
|
|
151
|
-
// network tool-bench 2026-07-06 for the measured pattern).
|
|
152
|
-
let rafId = null;
|
|
153
|
-
const unsubscribe = (0, _unifiedEventStore.subscribe)(() => {
|
|
154
|
-
if (rafId != null) return;
|
|
155
|
-
rafId = requestAnimationFrame(() => {
|
|
156
|
-
rafId = null;
|
|
157
|
-
applyLatest();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
const applyLatest = () => {
|
|
161
|
-
const newEvents = (0, _unifiedEventStore.getEvents)();
|
|
162
|
-
setEvents(newEvents);
|
|
163
|
-
setDiscoveredSources(prev => {
|
|
164
|
-
const next = (0, _unifiedEventStore.getAvailableEventSources)();
|
|
165
|
-
if (prev.size === next.size && [...next].every(s => prev.has(s))) {
|
|
166
|
-
return prev;
|
|
167
|
-
}
|
|
168
|
-
return new Set(next);
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
return () => {
|
|
172
|
-
unsubscribe();
|
|
173
|
-
if (rafId != null) cancelAnimationFrame(rafId);
|
|
174
|
-
};
|
|
175
|
-
}, []);
|
|
176
|
-
|
|
177
|
-
// Restore saved state on mount (badge selection + capturing state)
|
|
178
|
-
(0, _react.useEffect)(() => {
|
|
179
|
-
const restoreState = async () => {
|
|
180
|
-
// Load badge selection
|
|
181
|
-
const savedSources = await (0, _badgeSelectionStorage.loadEnabledSources)();
|
|
182
|
-
let sourcesToEnable;
|
|
183
|
-
|
|
184
|
-
// Default enabled = available sources minus those excluded by default (e.g. render)
|
|
185
|
-
const defaultEnabledAvailable = availableDisplaySources.filter(s => DEFAULT_ENABLED_SOURCES.includes(s));
|
|
186
|
-
if (savedSources && savedSources.length > 0) {
|
|
187
|
-
// Filter to only include valid sources that still exist and are available
|
|
188
|
-
const validSources = savedSources.filter(s => availableDisplaySources.includes(s));
|
|
189
|
-
if (validSources.length > 0) {
|
|
190
|
-
sourcesToEnable = new Set(validSources);
|
|
191
|
-
} else {
|
|
192
|
-
// If no saved sources are valid, use defaults
|
|
193
|
-
sourcesToEnable = new Set(defaultEnabledAvailable);
|
|
194
|
-
}
|
|
195
|
-
} else {
|
|
196
|
-
// No saved state - use defaults (render disabled)
|
|
197
|
-
sourcesToEnable = new Set(defaultEnabledAvailable);
|
|
198
|
-
}
|
|
199
|
-
setEnabledSources(sourcesToEnable);
|
|
200
|
-
|
|
201
|
-
// Load capturing state (default to true if not saved)
|
|
202
|
-
const savedCapturing = await (0, _badgeSelectionStorage.loadCapturingState)();
|
|
203
|
-
const shouldCapture = savedCapturing !== null ? savedCapturing : true;
|
|
204
|
-
if (!shouldCapture && pausedAtRef.current === null) {
|
|
205
|
-
// Seed the open paused window from the ORIGINAL pause press before the
|
|
206
|
-
// pause effect can stamp mount time over it — events captured (for a
|
|
207
|
-
// watching dashboard) between that press and this mount stay hidden.
|
|
208
|
-
const savedPausedAt = await (0, _badgeSelectionStorage.loadPausedAt)();
|
|
209
|
-
pausedAtRef.current = savedPausedAt ?? Date.now();
|
|
210
|
-
setPauseVersion(v => v + 1);
|
|
211
|
-
}
|
|
212
|
-
setIsCapturing(shouldCapture);
|
|
213
|
-
isStateRestoredRef.current = true;
|
|
214
|
-
// Drive the first sync DIRECTLY rather than trusting the effect below to
|
|
215
|
-
// fire. The setStates above sit behind TWO awaits, so React can commit
|
|
216
|
-
// the sources update while the restored-guard is still down (effect
|
|
217
|
-
// skips), and a same-value setIsCapturing then bails out without another
|
|
218
|
-
// commit — leaving the effect nothing to fire on and the tool deaf until
|
|
219
|
-
// something else changes state. The store's ledger diff makes this call
|
|
220
|
-
// idempotent with the effect's.
|
|
221
|
-
void (0, _unifiedEventStore.setLocalEnabledSources)(shouldCapture ? Array.from(sourcesToEnable) : []);
|
|
222
|
-
};
|
|
223
|
-
restoreState();
|
|
224
|
-
}, [availableDisplaySources]);
|
|
225
|
-
|
|
226
|
-
// Keep the store's local-consumer subscriptions in sync with what this hook
|
|
227
|
-
// wants: the enabled sources while capturing, nothing while paused. The store
|
|
228
|
-
// diffs each declaration against what it already holds for the on-device
|
|
229
|
-
// consumer, so remounts and re-runs are idempotent — imperative
|
|
230
|
-
// subscribe/unsubscribe pairs here used to drift (a reopened tool stacked a
|
|
231
|
-
// second ref per source, leaving capture running after the power toggle
|
|
232
|
-
// released only one).
|
|
233
|
-
(0, _react.useEffect)(() => {
|
|
234
|
-
if (!isStateRestoredRef.current) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
void (0, _unifiedEventStore.setLocalEnabledSources)(isCapturing ? Array.from(enabledSources) : []);
|
|
238
|
-
}, [enabledSources, isCapturing]);
|
|
239
|
-
|
|
240
|
-
// Persist enabled sources whenever they change (after initial restoration)
|
|
241
|
-
(0, _react.useEffect)(() => {
|
|
242
|
-
if (!isStateRestoredRef.current) {
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
(0, _badgeSelectionStorage.saveEnabledSources)(Array.from(enabledSources));
|
|
246
|
-
}, [enabledSources]);
|
|
247
|
-
|
|
248
|
-
// Persist capturing state whenever it changes (after initial restoration)
|
|
249
|
-
(0, _react.useEffect)(() => {
|
|
250
|
-
if (!isStateRestoredRef.current) {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
(0, _badgeSelectionStorage.saveCapturingState)(isCapturing);
|
|
254
|
-
}, [isCapturing]);
|
|
255
|
-
|
|
256
|
-
// Build set of all event sources that should be shown
|
|
257
|
-
const allowedEventSources = (0, _react.useMemo)(() => {
|
|
258
|
-
const allowed = new Set();
|
|
259
|
-
enabledSources.forEach(displaySource => {
|
|
260
|
-
const eventSources = SOURCE_TO_EVENT_SOURCES[displaySource];
|
|
261
|
-
if (eventSources) {
|
|
262
|
-
eventSources.forEach(s => allowed.add(s));
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
return allowed;
|
|
266
|
-
}, [enabledSources]);
|
|
267
|
-
const normalizedSearch = searchText.trim().toLowerCase();
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Everything this tool is willing to SHOW, before the user's own choices.
|
|
271
|
-
*
|
|
272
|
-
* Buoy's housekeeping writes and the shared ignored-URL patterns are removed
|
|
273
|
-
* here rather than alongside the source filter and the search, because the
|
|
274
|
-
* two kinds of hiding are not the same thing. A source badge and a search box
|
|
275
|
-
* are the user narrowing a list, and "Showing X of Y" is there to say so.
|
|
276
|
-
* This filter is the tool declining to report on itself, and there is no
|
|
277
|
-
* affordance anywhere that explains it — so counting these would make the
|
|
278
|
-
* header read "74 captured" over a list of 68, and leave the storage badge
|
|
279
|
-
* advertising writes that cannot be reached by any combination of controls.
|
|
280
|
-
*/
|
|
281
|
-
const visibleEvents = (0, _react.useMemo)(() => events.filter(event => !isInPausedGap(event.timestamp) && !(0, _eventVisibility.isBuoyInternalEvent)(event) && !(0, _eventVisibility.isNetworkEventIgnored)(event, ignoredPatterns)),
|
|
282
|
-
// pauseVersion invalidates this when a paused window opens or closes —
|
|
283
|
-
// the predicate itself reads refs.
|
|
284
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
285
|
-
[events, ignoredPatterns, isInPausedGap, pauseVersion]);
|
|
286
|
-
|
|
287
|
-
// What the user's own filters leave: the enabled sources and the header
|
|
288
|
-
// search, applied to the events above.
|
|
289
|
-
const allFilteredEvents = (0, _react.useMemo)(() => {
|
|
290
|
-
if (allowedEventSources.size === 0) {
|
|
291
|
-
return [];
|
|
292
|
-
}
|
|
293
|
-
return visibleEvents.filter(event => allowedEventSources.has(event.source) && (normalizedSearch === "" || matchesSearch(event, normalizedSearch)));
|
|
294
|
-
}, [visibleEvents, allowedEventSources, normalizedSearch]);
|
|
295
|
-
|
|
296
|
-
// Pro is Infinity here, so slice() returns everything and the hidden count
|
|
297
|
-
// floors at 0 — no tier branching needed at the call site.
|
|
298
|
-
const filteredEvents = (0, _react.useMemo)(() => allFilteredEvents.slice(0, eventLimit), [allFilteredEvents, eventLimit]);
|
|
299
|
-
const hiddenEventsCount = (0, _react.useMemo)(() => Math.max(0, allFilteredEvents.length - eventLimit), [allFilteredEvents, eventLimit]);
|
|
300
|
-
|
|
301
|
-
// Get all available sources with counts, sorted: enabled first, disabled last
|
|
302
|
-
const availableSources = (0, _react.useMemo)(() => {
|
|
303
|
-
// Counted from the visible set for the same reason `totalCount` is: a badge
|
|
304
|
-
// reading 72 over a list that can only ever show 69 of them is not a filter,
|
|
305
|
-
// it is a mystery. (`getSourceCounts()` is the raw store tally — still what
|
|
306
|
-
// the sync adapter reports to a dashboard, which wants the unfiltered
|
|
307
|
-
// truth.)
|
|
308
|
-
const counts = visibleEvents.reduce((acc, event) => {
|
|
309
|
-
acc[event.source] = (acc[event.source] ?? 0) + 1;
|
|
310
|
-
return acc;
|
|
311
|
-
}, {});
|
|
312
|
-
const subscriberCounts = (0, _unifiedEventStore.getSubscriberCounts)();
|
|
313
|
-
|
|
314
|
-
// Build a map from source ID to subscriber count
|
|
315
|
-
const subscriberCountBySourceId = {};
|
|
316
|
-
for (const source of subscriberCounts.sources) {
|
|
317
|
-
subscriberCountBySourceId[source.sourceId] = source.counts.total;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Map display source to store source ID
|
|
321
|
-
const displaySourceToStoreId = {
|
|
322
|
-
"storage-async": "storage",
|
|
323
|
-
"storage-mmkv": "storage",
|
|
324
|
-
redux: "redux",
|
|
325
|
-
network: "network",
|
|
326
|
-
"react-query": "react-query",
|
|
327
|
-
"react-query-query": "react-query",
|
|
328
|
-
"react-query-mutation": "react-query",
|
|
329
|
-
route: "route-events",
|
|
330
|
-
zustand: "zustand",
|
|
331
|
-
jotai: "jotai",
|
|
332
|
-
render: "render"
|
|
333
|
-
};
|
|
334
|
-
const sources = availableDisplaySources.map(source => {
|
|
335
|
-
const eventSources = SOURCE_TO_EVENT_SOURCES[source] || [source];
|
|
336
|
-
const totalCount = eventSources.reduce((sum, s) => sum + (counts[s] || 0), 0);
|
|
337
|
-
const displayConfig = (0, _autoDiscoverEventSources.getSourceDisplayConfig)(source);
|
|
338
|
-
const storeId = displaySourceToStoreId[source];
|
|
339
|
-
// Only set subscriberCount if the source has subscriber tracking
|
|
340
|
-
// (undefined means no tracking, vs 0 which means tracked but no subscribers)
|
|
341
|
-
const subscriberCount = storeId && storeId in subscriberCountBySourceId ? subscriberCountBySourceId[storeId] : undefined;
|
|
342
|
-
return {
|
|
343
|
-
source,
|
|
344
|
-
...displayConfig,
|
|
345
|
-
count: totalCount,
|
|
346
|
-
enabled: enabledSources.has(source),
|
|
347
|
-
subscriberCount
|
|
348
|
-
};
|
|
349
|
-
});
|
|
350
|
-
|
|
351
|
-
// Sort: enabled first, then disabled
|
|
352
|
-
return sources.sort((a, b) => {
|
|
353
|
-
if (a.enabled && !b.enabled) return -1;
|
|
354
|
-
if (!a.enabled && b.enabled) return 1;
|
|
355
|
-
return 0;
|
|
356
|
-
});
|
|
357
|
-
}, [visibleEvents, enabledSources, availableDisplaySources, subscriberCountVersion]);
|
|
358
|
-
|
|
359
|
-
// Pure state change — the sync effect above translates the new selection
|
|
360
|
-
// into store subscriptions, correctly keeping a shared discovery source
|
|
361
|
-
// (react-query serves both the query and mutation badges) alive while
|
|
362
|
-
// either badge still wants it.
|
|
363
|
-
const toggleSource = (0, _react.useCallback)(source => {
|
|
364
|
-
setEnabledSources(prev => {
|
|
365
|
-
const next = new Set(prev);
|
|
366
|
-
if (next.has(source)) {
|
|
367
|
-
next.delete(source);
|
|
368
|
-
} else {
|
|
369
|
-
next.add(source);
|
|
370
|
-
}
|
|
371
|
-
return next;
|
|
372
|
-
});
|
|
373
|
-
}, []);
|
|
374
|
-
const enableAllSources = (0, _react.useCallback)(() => {
|
|
375
|
-
setEnabledSources(new Set(availableDisplaySources));
|
|
376
|
-
}, [availableDisplaySources]);
|
|
377
|
-
const clearEvents = (0, _react.useCallback)(() => {
|
|
378
|
-
(0, _unifiedEventStore.clearEvents)();
|
|
379
|
-
}, []);
|
|
380
|
-
|
|
381
|
-
// Pure state changes — the sync effect declares the resulting desired set to
|
|
382
|
-
// the store, which releases every subscription this consumer holds when
|
|
383
|
-
// capture turns off (a dashboard's own subscriptions stay ref-counted and
|
|
384
|
-
// untouched).
|
|
385
|
-
const startCapturing = (0, _react.useCallback)(() => {
|
|
386
|
-
setIsCapturing(true);
|
|
387
|
-
}, []);
|
|
388
|
-
const stopCapturing = (0, _react.useCallback)(() => {
|
|
389
|
-
setIsCapturing(false);
|
|
390
|
-
}, []);
|
|
391
|
-
const toggleCapturing = (0, _react.useCallback)(() => {
|
|
392
|
-
setIsCapturing(prev => !prev);
|
|
393
|
-
}, []);
|
|
394
|
-
|
|
395
|
-
// Get subscriber counts (recalculates on every render, but it's a cheap operation)
|
|
396
|
-
const totalSubscriberCount = (0, _unifiedEventStore.getSubscriberCounts)().totalSubscribers;
|
|
397
|
-
return {
|
|
398
|
-
events,
|
|
399
|
-
filteredEvents,
|
|
400
|
-
availableSources,
|
|
401
|
-
enabledSources,
|
|
402
|
-
searchText,
|
|
403
|
-
setSearchText,
|
|
404
|
-
toggleSource,
|
|
405
|
-
enableAllSources,
|
|
406
|
-
clearEvents,
|
|
407
|
-
totalCount: visibleEvents.length,
|
|
408
|
-
filteredCount: filteredEvents.length,
|
|
409
|
-
isCapturing,
|
|
410
|
-
startCapturing,
|
|
411
|
-
stopCapturing,
|
|
412
|
-
toggleCapturing,
|
|
413
|
-
discoveredSources,
|
|
414
|
-
hiddenEventsCount,
|
|
415
|
-
isPro,
|
|
416
|
-
totalSubscriberCount
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
//# sourceMappingURL=useUnifiedEvents.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.useUnifiedEvents=useUnifiedEvents;var _react=require("react");var _sharedUi=require("@buoy-gg/shared-ui");var _unifiedEventStore=require("../stores/unifiedEventStore");var _badgeSelectionStorage=require("../utils/badgeSelectionStorage");var _autoDiscoverEventSources=require("../utils/autoDiscoverEventSources");var _eventVisibility=require("../utils/eventVisibility");function matchesSearch(i,S){if(i.title.toLowerCase().includes(S))return true;if(i.subtitle.toLowerCase().includes(S))return true;const l=i.originalEvent?.url;return typeof l==="string"&&l.toLowerCase().includes(S)}const ALL_DISPLAY_SOURCES=["storage-async","redux","network","react-query-query","react-query-mutation","route","zustand","jotai","render"];const DEFAULT_ENABLED_SOURCES=ALL_DISPLAY_SOURCES.filter(i=>i!=="render");const SOURCE_TO_EVENT_SOURCES={"storage-async":["storage-async","storage-mmkv"],"storage-mmkv":["storage-mmkv"],redux:["redux"],network:["network"],"react-query":["react-query","react-query-query"],"react-query-query":["react-query","react-query-query"],"react-query-mutation":["react-query-mutation"],route:["route"],zustand:["zustand"],jotai:["jotai"],render:["render"]};function useUnifiedEvents(i){const{isPro:S}=(0,_sharedUi.useFeatureGate)();const l=(0,_sharedUi.useLimit)("events.entries");const{patterns:_}=(0,_sharedUi.useIgnoredPatterns)();const[y,P]=(0,_react.useState)([]);const[o,m]=(0,_react.useState)(()=>new Set(DEFAULT_ENABLED_SOURCES));const[f,g]=(0,_react.useState)(true);const[L,R]=(0,_react.useState)("");const E=(0,_react.useRef)(false);const x=i?.capturingOverride??f;const a=(0,_react.useRef)(null);const w=(0,_react.useRef)([]);const[z,q]=(0,_react.useState)(0);(0,_react.useEffect)(()=>{if(x){if(a.current!==null){w.current=[...w.current,[a.current,Date.now()]];a.current=null;q(e=>e+1);(0,_badgeSelectionStorage.savePausedAt)(null)}}else if(a.current===null){a.current=Date.now();q(e=>e+1);(0,_badgeSelectionStorage.savePausedAt)(a.current)}},[x]);const D=(0,_react.useCallback)(e=>{const s=a.current;if(s!==null&&e>s)return true;for(const[r,u]of w.current){if(e>r&&e<=u)return true}return false},[]);const[p,M]=(0,_react.useState)(()=>(0,_unifiedEventStore.getAvailableEventSources)());const[T,U]=(0,_react.useState)(0);(0,_react.useEffect)(()=>{return(0,_sharedUi.subscribeToSubscriberCountChanges)(()=>{U(e=>e+1)})},[]);const d=(0,_react.useMemo)(()=>{return ALL_DISPLAY_SOURCES.filter(e=>{const s=SOURCE_TO_EVENT_SOURCES[e]||[e];return s.some(r=>p.has(r))})},[p]);(0,_react.useEffect)(()=>{let e=null;const s=(0,_unifiedEventStore.subscribe)(()=>{if(e!=null)return;e=requestAnimationFrame(()=>{e=null;r()})});const r=()=>{const u=(0,_unifiedEventStore.getEvents)();P(u);M(c=>{const t=(0,_unifiedEventStore.getAvailableEventSources)();if(c.size===t.size&&[...t].every(n=>c.has(n))){return c}return new Set(t)})};return()=>{s();if(e!=null)cancelAnimationFrame(e)}},[]);(0,_react.useEffect)(()=>{const e=async()=>{const s=await(0,_badgeSelectionStorage.loadEnabledSources)();let r;const u=d.filter(n=>DEFAULT_ENABLED_SOURCES.includes(n));if(s&&s.length>0){const n=s.filter(v=>d.includes(v));if(n.length>0){r=new Set(n)}else{r=new Set(u)}}else{r=new Set(u)}m(r);const c=await(0,_badgeSelectionStorage.loadCapturingState)();const t=c!==null?c:true;if(!t&&a.current===null){const n=await(0,_badgeSelectionStorage.loadPausedAt)();a.current=n??Date.now();q(v=>v+1)}g(t);E.current=true;void(0,_unifiedEventStore.setLocalEnabledSources)(t?Array.from(r):[])};e()},[d]);(0,_react.useEffect)(()=>{if(!E.current){return}void(0,_unifiedEventStore.setLocalEnabledSources)(f?Array.from(o):[])},[o,f]);(0,_react.useEffect)(()=>{if(!E.current){return}(0,_badgeSelectionStorage.saveEnabledSources)(Array.from(o))},[o]);(0,_react.useEffect)(()=>{if(!E.current){return}(0,_badgeSelectionStorage.saveCapturingState)(f)},[f]);const h=(0,_react.useMemo)(()=>{const e=new Set;o.forEach(s=>{const r=SOURCE_TO_EVENT_SOURCES[s];if(r){r.forEach(u=>e.add(u))}});return e},[o]);const A=L.trim().toLowerCase();const b=(0,_react.useMemo)(()=>y.filter(e=>!D(e.timestamp)&&!(0,_eventVisibility.isBuoyInternalEvent)(e)&&!(0,_eventVisibility.isNetworkEventIgnored)(e,_)),[y,_,D,z]);const C=(0,_react.useMemo)(()=>{if(h.size===0){return[]}return b.filter(e=>h.has(e.source)&&(A===""||matchesSearch(e,A)))},[b,h,A]);const I=(0,_react.useMemo)(()=>C.slice(0,l),[C,l]);const O=(0,_react.useMemo)(()=>Math.max(0,C.length-l),[C,l]);const V=(0,_react.useMemo)(()=>{const e=b.reduce((t,n)=>{t[n.source]=(t[n.source]??0)+1;return t},{});const s=(0,_unifiedEventStore.getSubscriberCounts)();const r={};for(const t of s.sources){r[t.sourceId]=t.counts.total}const u={"storage-async":"storage","storage-mmkv":"storage",redux:"redux",network:"network","react-query":"react-query","react-query-query":"react-query","react-query-mutation":"react-query",route:"route-events",zustand:"zustand",jotai:"jotai",render:"render"};const c=d.map(t=>{const n=SOURCE_TO_EVENT_SOURCES[t]||[t];const v=n.reduce((K,Q)=>K+(e[Q]||0),0);const H=(0,_autoDiscoverEventSources.getSourceDisplayConfig)(t);const k=u[t];const J=k&&k in r?r[k]:void 0;return{source:t,...H,count:v,enabled:o.has(t),subscriberCount:J}});return c.sort((t,n)=>{if(t.enabled&&!n.enabled)return-1;if(!t.enabled&&n.enabled)return 1;return 0})},[b,o,d,T]);const j=(0,_react.useCallback)(e=>{m(s=>{const r=new Set(s);if(r.has(e)){r.delete(e)}else{r.add(e)}return r})},[]);const F=(0,_react.useCallback)(()=>{m(new Set(d))},[d]);const B=(0,_react.useCallback)(()=>{(0,_unifiedEventStore.clearEvents)()},[]);const N=(0,_react.useCallback)(()=>{g(true)},[]);const G=(0,_react.useCallback)(()=>{g(false)},[]);const W=(0,_react.useCallback)(()=>{g(e=>!e)},[]);const Y=(0,_unifiedEventStore.getSubscriberCounts)().totalSubscribers;return{events:y,filteredEvents:I,availableSources:V,enabledSources:o,searchText:L,setSearchText:R,toggleSource:j,enableAllSources:F,clearEvents:B,totalCount:b.length,filteredCount:I.length,isCapturing:f,startCapturing:N,stopCapturing:G,toggleCapturing:W,discoveredSources:p,hiddenEventsCount:O,isPro:S,totalSubscriberCount:Y}}
|