@buoy-gg/events 7.0.40 → 7.0.42

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 (126) hide show
  1. package/README.md +11 -60
  2. package/lib/commonjs/components/EventsCopySettingsView.js +1 -581
  3. package/lib/commonjs/components/EventsModal.js +1 -387
  4. package/lib/commonjs/components/ReactQueryEventDetail.js +1 -433
  5. package/lib/commonjs/components/UnifiedEventDetail.js +1 -556
  6. package/lib/commonjs/components/UnifiedEventFilters.js +1 -160
  7. package/lib/commonjs/components/UnifiedEventItem.js +1 -417
  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 -1065
  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 -383
  28. package/lib/module/components/ReactQueryEventDetail.js +1 -429
  29. package/lib/module/components/UnifiedEventDetail.js +1 -552
  30. package/lib/module/components/UnifiedEventFilters.js +1 -156
  31. package/lib/module/components/UnifiedEventItem.js +1 -413
  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 -1057
  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/typescript/components/EventsModal.d.ts +1 -7
  51. package/lib/typescript/components/UnifiedEventDetail.d.ts +2 -9
  52. package/lib/typescript/components/UnifiedEventItem.d.ts +0 -7
  53. package/lib/web/index.mjs +12 -0
  54. package/package.json +31 -11
  55. package/lib/commonjs/components/EventsCopySettingsView.js.map +0 -1
  56. package/lib/commonjs/components/EventsModal.js.map +0 -1
  57. package/lib/commonjs/components/ReactQueryEventDetail.js.map +0 -1
  58. package/lib/commonjs/components/UnifiedEventDetail.js.map +0 -1
  59. package/lib/commonjs/components/UnifiedEventFilters.js.map +0 -1
  60. package/lib/commonjs/components/UnifiedEventItem.js.map +0 -1
  61. package/lib/commonjs/components/UnifiedEventList.js.map +0 -1
  62. package/lib/commonjs/components/UnifiedEventViewer.js.map +0 -1
  63. package/lib/commonjs/hooks/useUnifiedEvents.js.map +0 -1
  64. package/lib/commonjs/index.js.map +0 -1
  65. package/lib/commonjs/preset.js.map +0 -1
  66. package/lib/commonjs/sources/sourceIds.js.map +0 -1
  67. package/lib/commonjs/stores/unifiedEventStore.js.map +0 -1
  68. package/lib/commonjs/sync/eventsSyncAdapter.js.map +0 -1
  69. package/lib/commonjs/types/copySettings.js.map +0 -1
  70. package/lib/commonjs/types/index.js.map +0 -1
  71. package/lib/commonjs/utils/autoDiscoverEventSources.js.map +0 -1
  72. package/lib/commonjs/utils/badgeSelectionStorage.js.map +0 -1
  73. package/lib/commonjs/utils/copySettingsStorage.js.map +0 -1
  74. package/lib/commonjs/utils/correlationUtils.js.map +0 -1
  75. package/lib/commonjs/utils/eventExportFormatter.js.map +0 -1
  76. package/lib/commonjs/utils/eventTransformers.js.map +0 -1
  77. package/lib/commonjs/utils/eventVisibility.js.map +0 -1
  78. package/lib/commonjs/utils/testIDs.js.map +0 -1
  79. package/lib/module/components/EventsCopySettingsView.js.map +0 -1
  80. package/lib/module/components/EventsModal.js.map +0 -1
  81. package/lib/module/components/ReactQueryEventDetail.js.map +0 -1
  82. package/lib/module/components/UnifiedEventDetail.js.map +0 -1
  83. package/lib/module/components/UnifiedEventFilters.js.map +0 -1
  84. package/lib/module/components/UnifiedEventItem.js.map +0 -1
  85. package/lib/module/components/UnifiedEventList.js.map +0 -1
  86. package/lib/module/components/UnifiedEventViewer.js.map +0 -1
  87. package/lib/module/hooks/useUnifiedEvents.js.map +0 -1
  88. package/lib/module/index.js.map +0 -1
  89. package/lib/module/preset.js.map +0 -1
  90. package/lib/module/sources/sourceIds.js.map +0 -1
  91. package/lib/module/stores/unifiedEventStore.js.map +0 -1
  92. package/lib/module/sync/eventsSyncAdapter.js.map +0 -1
  93. package/lib/module/types/copySettings.js.map +0 -1
  94. package/lib/module/types/index.js.map +0 -1
  95. package/lib/module/utils/autoDiscoverEventSources.js.map +0 -1
  96. package/lib/module/utils/badgeSelectionStorage.js.map +0 -1
  97. package/lib/module/utils/copySettingsStorage.js.map +0 -1
  98. package/lib/module/utils/correlationUtils.js.map +0 -1
  99. package/lib/module/utils/eventExportFormatter.js.map +0 -1
  100. package/lib/module/utils/eventTransformers.js.map +0 -1
  101. package/lib/module/utils/eventVisibility.js.map +0 -1
  102. package/lib/module/utils/testIDs.js.map +0 -1
  103. package/lib/typescript/components/EventsCopySettingsView.d.ts.map +0 -1
  104. package/lib/typescript/components/EventsModal.d.ts.map +0 -1
  105. package/lib/typescript/components/ReactQueryEventDetail.d.ts.map +0 -1
  106. package/lib/typescript/components/UnifiedEventDetail.d.ts.map +0 -1
  107. package/lib/typescript/components/UnifiedEventFilters.d.ts.map +0 -1
  108. package/lib/typescript/components/UnifiedEventItem.d.ts.map +0 -1
  109. package/lib/typescript/components/UnifiedEventList.d.ts.map +0 -1
  110. package/lib/typescript/components/UnifiedEventViewer.d.ts.map +0 -1
  111. package/lib/typescript/hooks/useUnifiedEvents.d.ts.map +0 -1
  112. package/lib/typescript/index.d.ts.map +0 -1
  113. package/lib/typescript/preset.d.ts.map +0 -1
  114. package/lib/typescript/sources/sourceIds.d.ts.map +0 -1
  115. package/lib/typescript/stores/unifiedEventStore.d.ts.map +0 -1
  116. package/lib/typescript/sync/eventsSyncAdapter.d.ts.map +0 -1
  117. package/lib/typescript/types/copySettings.d.ts.map +0 -1
  118. package/lib/typescript/types/index.d.ts.map +0 -1
  119. package/lib/typescript/utils/autoDiscoverEventSources.d.ts.map +0 -1
  120. package/lib/typescript/utils/badgeSelectionStorage.d.ts.map +0 -1
  121. package/lib/typescript/utils/copySettingsStorage.d.ts.map +0 -1
  122. package/lib/typescript/utils/correlationUtils.d.ts.map +0 -1
  123. package/lib/typescript/utils/eventExportFormatter.d.ts.map +0 -1
  124. package/lib/typescript/utils/eventTransformers.d.ts.map +0 -1
  125. package/lib/typescript/utils/eventVisibility.d.ts.map +0 -1
  126. package/lib/typescript/utils/testIDs.d.ts.map +0 -1
@@ -1,1065 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.autoDiscoverEventSources = autoDiscoverEventSources;
7
- exports.clearDiscoveryCache = clearDiscoveryCache;
8
- exports.getAggregatedSubscriberCounts = getAggregatedSubscriberCounts;
9
- exports.getCachedDiscovery = getCachedDiscovery;
10
- exports.getSourceDisplayConfig = getSourceDisplayConfig;
11
- /**
12
- * Auto-Discover Event Sources
13
- *
14
- * Automatically discovers and loads event stores from installed packages.
15
- * Uses try-catch pattern to safely handle missing packages - if a tool
16
- * isn't installed, it's silently skipped.
17
- *
18
- * This enables zero-config setup - just install the dev tool packages you
19
- * want and they'll automatically appear in the unified events timeline!
20
- */
21
-
22
- // ============================================================================
23
- // Types for discovered event sources
24
- // ============================================================================
25
-
26
- /**
27
- * Configuration for a discovered event source
28
- */
29
-
30
- /**
31
- * Result of auto-discovery
32
- */
33
-
34
- // ============================================================================
35
- // Event transformers (inline to avoid import dependencies)
36
- // ============================================================================
37
-
38
- let eventIdCounter = 0;
39
- function generateEventId(source) {
40
- return `${source}-${Date.now()}-${++eventIdCounter}`;
41
- }
42
-
43
- // ============================================================================
44
- // Storage Event Source Discovery
45
- // ============================================================================
46
-
47
- function tryLoadStorageSource() {
48
- try {
49
- // @ts-ignore - Dynamic import that may not exist
50
- const {
51
- storageEventStore
52
- } = require("@buoy-gg/storage");
53
- return {
54
- id: "storage",
55
- name: "Storage",
56
- eventSources: ["storage-async", "storage-mmkv"],
57
- available: true,
58
- // No setup needed - onEvent() auto-starts capturing via Subscribable pattern
59
- subscribe: onEvent => {
60
- return storageEventStore.onEvent(event => {
61
- // The store's initial scan synthesizes a `setItem` for every key
62
- // already on disk (so the STORAGE tool's state views include
63
- // pre-existing keys). In a TIMELINE those read as dozens of writes
64
- // that never happened — stamped with the scan moment, so the first
65
- // subscribe after a quiet boot (i.e. the user pressing the power
66
- // button on an empty, just-cleared list) instantly "captured" ~60
67
- // events. This timeline reports what happens, not what exists.
68
- const data = event?.data;
69
- if (data?.initialScan) return;
70
- const unifiedEvent = transformStorageEvent(event);
71
- onEvent(unifiedEvent);
72
- });
73
- }
74
- };
75
- } catch {
76
- return null;
77
- }
78
- }
79
- function transformStorageEvent(event) {
80
- const e = event;
81
- const source = e.storageType === "async" ? "storage-async" : "storage-mmkv";
82
-
83
- // Get action label
84
- let title = e.action;
85
- if (e.storageType === "async") {
86
- const labelMap = {
87
- setItem: "Set Item",
88
- removeItem: "Remove Item",
89
- mergeItem: "Merge Item",
90
- clear: "Clear All",
91
- multiSet: "Multi Set",
92
- multiRemove: "Multi Remove",
93
- multiMerge: "Multi Merge"
94
- };
95
- title = labelMap[e.action] || e.action;
96
- }
97
-
98
- // Get subtitle
99
- let subtitle = "";
100
- if (e.storageType === "async") {
101
- switch (e.action) {
102
- case "setItem":
103
- case "removeItem":
104
- case "mergeItem":
105
- subtitle = e.data?.key || "unknown key";
106
- break;
107
- case "multiSet":
108
- case "multiMerge":
109
- {
110
- const pairCount = e.data?.pairs?.length || 0;
111
- subtitle = `${pairCount} key${pairCount !== 1 ? "s" : ""}`;
112
- break;
113
- }
114
- case "multiRemove":
115
- {
116
- const keyCount = e.data?.keys?.length || 0;
117
- subtitle = `${keyCount} key${keyCount !== 1 ? "s" : ""}`;
118
- break;
119
- }
120
- case "clear":
121
- subtitle = "all keys";
122
- break;
123
- }
124
- } else {
125
- subtitle = e.data?.key || e.data?.instanceId || "unknown";
126
- }
127
-
128
- // Get status
129
- let status = "neutral";
130
- if (e.action.includes("set") || e.action.includes("Set") || e.action.includes("merge") || e.action.includes("Merge")) {
131
- status = "success";
132
- }
133
- return {
134
- id: generateEventId(source),
135
- source,
136
- timestamp: e.timestamp.getTime(),
137
- title,
138
- subtitle,
139
- status,
140
- originalEvent: event
141
- };
142
- }
143
-
144
- // ============================================================================
145
- // Redux Event Source Discovery
146
- // ============================================================================
147
-
148
- function tryLoadReduxSource() {
149
- try {
150
- // @ts-ignore - Dynamic import that may not exist
151
- const {
152
- reduxActionStore
153
- } = require("@buoy-gg/redux");
154
- let lastActionId = null;
155
- return {
156
- id: "redux",
157
- name: "Redux",
158
- eventSources: ["redux"],
159
- available: true,
160
- subscribe: onEvent => {
161
- return reduxActionStore.subscribe(actions => {
162
- if (actions.length > 0) {
163
- const latestAction = actions[0];
164
- if (latestAction.id !== lastActionId) {
165
- lastActionId = latestAction.id;
166
- const unifiedEvent = transformReduxAction(latestAction);
167
- onEvent(unifiedEvent);
168
- }
169
- }
170
- });
171
- }
172
- };
173
- } catch {
174
- return null;
175
- }
176
- }
177
- function transformReduxAction(action) {
178
- const a = action;
179
-
180
- // Get status
181
- let status = "neutral";
182
- switch (a.category) {
183
- case "fulfilled":
184
- status = "success";
185
- break;
186
- case "rejected":
187
- status = "error";
188
- break;
189
- case "pending":
190
- status = "pending";
191
- break;
192
- default:
193
- status = a.hasStateChange ? "success" : "neutral";
194
- }
195
-
196
- // Get subtitle
197
- let subtitle = "";
198
- if (a.payloadPreview) {
199
- subtitle = a.payloadPreview;
200
- } else if (a.hasStateChange && a.diffSummary) {
201
- subtitle = a.diffSummary;
202
- } else if (a.duration !== undefined) {
203
- subtitle = `${a.duration.toFixed(1)}ms`;
204
- } else {
205
- subtitle = a.sliceName || "";
206
- }
207
- return {
208
- id: generateEventId("redux"),
209
- source: "redux",
210
- timestamp: a.timestamp,
211
- title: a.type,
212
- subtitle,
213
- status,
214
- originalEvent: action
215
- };
216
- }
217
-
218
- // ============================================================================
219
- // Network Event Source Discovery
220
- // ============================================================================
221
-
222
- function tryLoadNetworkSource() {
223
- try {
224
- // @ts-ignore - Dynamic import that may not exist
225
- // Note: We use networkListener (the getter) instead of startNetworkListener
226
- // because startNetworkListener is not exported from the main package
227
- const {
228
- networkEventStore,
229
- networkListener,
230
- addNetworkListener
231
- } = require("@buoy-gg/network");
232
-
233
- // Map network event IDs to unified event IDs for updates (request -> response)
234
- const networkEventIdMap = new Map();
235
- return {
236
- id: "network",
237
- name: "Network",
238
- eventSources: ["network"],
239
- available: true,
240
- setup: () => {
241
- // Get the network listener singleton and start it if not already active
242
- const listener = networkListener();
243
- if (!listener.isActive) {
244
- listener.startListening();
245
- }
246
-
247
- // Ensure events flow into the store. The network panel does this via
248
- // addNetworkListener, but if events package loads first, we need to
249
- // set it up ourselves.
250
- if (listener.listenerCount === 0) {
251
- addNetworkListener(event => {
252
- networkEventStore.processNetworkEvent(event);
253
- });
254
- }
255
- },
256
- subscribe: onEvent => {
257
- // Use onEvent() pattern - same as storage
258
- // This fires for each individual event (request or response/error update)
259
- // Pass replayExisting=false to avoid replaying up to 500 buffered events
260
- // synchronously, which causes ~30s UI freezes from mass state updates.
261
- //
262
- // replayExisting=false is not the whole story though: the store's
263
- // boot-capture buffer parks raw interceptor events until the FIRST
264
- // consumer subscribes, then flushes them through addEvent — so a
265
- // subscribe can still be handed traffic from before it existed (three
266
- // boot requests landing as "live" rows the instant the power button
267
- // was pressed). The network TOOL wants that history; a timeline does
268
- // not. Both emissions of a request carry the request's start time, so
269
- // dropping NEW rows stamped before this subscription filters exactly
270
- // the history (an update to a row we already made still flows).
271
- const subscribedAt = Date.now();
272
- return networkEventStore.onEvent(event => {
273
- const ne = event;
274
- const existingUnifiedId = networkEventIdMap.get(ne.id);
275
- if (!existingUnifiedId) {
276
- if (typeof ne.timestamp === "number" && ne.timestamp < subscribedAt) {
277
- return; // pre-subscription history (boot buffer / paused gap)
278
- }
279
- // New event (request started)
280
- const unifiedEvent = transformNetworkEvent(event);
281
- networkEventIdMap.set(ne.id, unifiedEvent.id);
282
- onEvent(unifiedEvent);
283
- } else {
284
- // Existing event updated (response received or error)
285
- const unifiedEvent = transformNetworkEvent(event);
286
- unifiedEvent.id = existingUnifiedId; // Keep the same unified ID
287
- onEvent(unifiedEvent);
288
- }
289
- }, false);
290
- }
291
- };
292
- } catch {
293
- return null;
294
- }
295
- }
296
- function transformNetworkEvent(event) {
297
- const e = event;
298
-
299
- // Get status
300
- let status = "neutral";
301
- if (e.status === undefined) {
302
- status = "pending";
303
- } else if (e.error || e.status >= 400) {
304
- status = "error";
305
- } else if (e.status >= 200 && e.status < 400) {
306
- status = "success";
307
- }
308
-
309
- // Get title
310
- const title = e.operationName || `${e.method} ${e.path || e.url}`;
311
-
312
- // Get subtitle
313
- const parts = [];
314
- if (e.status !== undefined) {
315
- parts.push(`${e.status}`);
316
- } else if (e.error) {
317
- parts.push("Error");
318
- } else {
319
- parts.push("Pending");
320
- }
321
- if (e.duration !== undefined) {
322
- parts.push(`${e.duration.toFixed(0)}ms`);
323
- }
324
- if (e.host) {
325
- parts.push(e.host);
326
- }
327
- return {
328
- id: generateEventId("network"),
329
- source: "network",
330
- timestamp: e.timestamp,
331
- title,
332
- subtitle: parts.join(" · "),
333
- status,
334
- originalEvent: event
335
- };
336
- }
337
-
338
- // ============================================================================
339
- // React Query Event Source Discovery
340
- // ============================================================================
341
-
342
- function tryLoadReactQuerySource() {
343
- try {
344
- // @ts-ignore - Dynamic import that may not exist
345
- const {
346
- reactQueryEventStore
347
- } = require("@buoy-gg/react-query");
348
- let lastEventId = null;
349
- return {
350
- id: "react-query",
351
- name: "React Query",
352
- eventSources: ["react-query", "react-query-query", "react-query-mutation"],
353
- available: true,
354
- subscribe: onEvent => {
355
- // Unlike the redux/zustand/jotai stores, this store's subscribe()
356
- // SYNCHRONOUSLY replays its current buffer to the new listener — and
357
- // ReactQueryTracker feeds that buffer from app start, before anything
358
- // here listens. That first call is history; emitting its latest entry
359
- // made a boot-time fetch appear as a fresh event at every first
360
- // open / pause→resume. Prime the guard from it and emit nothing.
361
- let priming = true;
362
- // Starts seen by THIS subscription. A fetch is start + settle under
363
- // one hash, and a settle whose start predates the subscription is the
364
- // second half of history — a boot fetch on a slow network settling
365
- // seconds after the tool opened used to land as a bare "Success" the
366
- // moment capture began. Same rule the network source applies to a
367
- // request sent before its subscription.
368
- const seenStarts = new Set();
369
- const fetchIdentity = e => e.queryHash ?? (e.mutationId !== undefined ? `m-${e.mutationId}` : null);
370
- return reactQueryEventStore.subscribe(events => {
371
- if (priming) {
372
- priming = false;
373
- if (events.length > 0) {
374
- lastEventId = events[0].id;
375
- }
376
- return;
377
- }
378
- if (events.length > 0) {
379
- const latestEvent = events[0];
380
- if (latestEvent.id !== lastEventId) {
381
- lastEventId = latestEvent.id;
382
- const type = latestEvent.type ?? "";
383
- const identity = fetchIdentity(latestEvent);
384
- if (type === "query-fetch-start" || type === "mutation-start") {
385
- if (identity) seenStarts.add(identity);
386
- } else if (type === "query-fetch-success" || type === "query-fetch-error" || type === "mutation-success" || type === "mutation-error") {
387
- if (identity && !seenStarts.has(identity)) {
388
- return; // settle of a fetch begun before this subscription
389
- }
390
- }
391
- const unifiedEvent = transformReactQueryEvent(latestEvent);
392
- onEvent(unifiedEvent);
393
- }
394
- }
395
- });
396
- }
397
- };
398
- } catch {
399
- return null;
400
- }
401
- }
402
- function formatQueryKey(queryKey) {
403
- if (!queryKey || queryKey.length === 0) return "unknown";
404
- return queryKey.map(part => {
405
- if (typeof part === "string") return part;
406
- if (typeof part === "number") return String(part);
407
- if (typeof part === "object" && part !== null) {
408
- const obj = part;
409
- const firstValue = Object.values(obj)[0];
410
- if (typeof firstValue === "string" || typeof firstValue === "number") {
411
- return String(firstValue);
412
- }
413
- return JSON.stringify(part).slice(0, 20);
414
- }
415
- return String(part);
416
- }).join(" › ");
417
- }
418
- function transformReactQueryEvent(event) {
419
- const e = event;
420
- const isMutation = e.type.startsWith("mutation-");
421
- const source = isMutation ? "react-query-mutation" : "react-query-query";
422
-
423
- // Get status
424
- let status = "neutral";
425
- switch (e.type) {
426
- case "query-fetch-start":
427
- case "mutation-start":
428
- status = "pending";
429
- break;
430
- case "query-fetch-success":
431
- case "mutation-success":
432
- status = "success";
433
- break;
434
- case "query-fetch-error":
435
- case "mutation-error":
436
- status = "error";
437
- break;
438
- }
439
-
440
- // Get title
441
- let title = "";
442
- if (e.queryKey) {
443
- title = formatQueryKey(e.queryKey);
444
- } else if (e.mutationKey) {
445
- title = formatQueryKey(e.mutationKey);
446
- } else if (e.mutationId !== undefined) {
447
- title = `Mutation #${e.mutationId}`;
448
- } else {
449
- title = e.type.replace(/-/g, " ");
450
- }
451
-
452
- // Get subtitle
453
- const parts = [];
454
- switch (e.type) {
455
- case "query-fetch-start":
456
- parts.push("Fetching");
457
- break;
458
- case "query-fetch-success":
459
- parts.push("Success");
460
- break;
461
- case "query-fetch-error":
462
- parts.push("Error");
463
- break;
464
- case "query-invalidated":
465
- parts.push("Invalidated");
466
- break;
467
- case "mutation-start":
468
- parts.push("Mutating");
469
- break;
470
- case "mutation-success":
471
- parts.push("Success");
472
- break;
473
- case "mutation-error":
474
- parts.push("Error");
475
- break;
476
- }
477
- if (e.duration !== undefined) {
478
- parts.push(`${e.duration.toFixed(0)}ms`);
479
- }
480
-
481
- // Get correlation info
482
- let correlationId;
483
- if (e.queryHash) {
484
- correlationId = `rq-query-${e.queryHash}`;
485
- } else if (e.mutationId !== undefined) {
486
- correlationId = `rq-mutation-${e.mutationId}`;
487
- }
488
- let sequenceInGroup = 1;
489
- switch (e.type) {
490
- case "query-fetch-start":
491
- case "mutation-start":
492
- sequenceInGroup = 1;
493
- break;
494
- case "query-fetch-success":
495
- case "query-fetch-error":
496
- case "mutation-success":
497
- case "mutation-error":
498
- sequenceInGroup = 2;
499
- break;
500
- case "query-invalidated":
501
- sequenceInGroup = 3;
502
- break;
503
- }
504
- return {
505
- id: generateEventId(source),
506
- source,
507
- timestamp: e.timestamp,
508
- title,
509
- subtitle: parts.join(" · "),
510
- status,
511
- originalEvent: event,
512
- correlationId,
513
- sequenceInGroup
514
- };
515
- }
516
-
517
- // ============================================================================
518
- // Route Events Source Discovery
519
- // ============================================================================
520
-
521
- function tryLoadRouteEventsSource() {
522
- try {
523
- // @ts-ignore - Dynamic import that may not exist
524
- const {
525
- routeEventStore
526
- } = require("@buoy-gg/route-events");
527
- return {
528
- id: "route-events",
529
- name: "Routes",
530
- eventSources: ["route"],
531
- available: true,
532
- // No setup needed - onEvent() auto-starts listening via Subscribable pattern
533
- subscribe: onEvent => {
534
- return routeEventStore.onEvent(event => {
535
- const unifiedEvent = transformRouteEvent(event);
536
- onEvent(unifiedEvent);
537
- });
538
- }
539
- };
540
- } catch {
541
- return null;
542
- }
543
- }
544
- function transformRouteEvent(event) {
545
- const e = event;
546
-
547
- // Get status
548
- let status = "neutral";
549
- if (e.pathname === "/") {
550
- status = "success";
551
- } else if (Object.keys(e.params).length > 0) {
552
- status = "success";
553
- }
554
-
555
- // Get subtitle
556
- const parts = [];
557
- const paramCount = Object.keys(e.params).length;
558
- if (paramCount > 0) {
559
- parts.push(`${paramCount} param${paramCount !== 1 ? "s" : ""}`);
560
- }
561
- if (e.timeSincePrevious !== undefined && e.timeSincePrevious > 0) {
562
- if (e.timeSincePrevious < 1000) {
563
- parts.push(`${e.timeSincePrevious}ms`);
564
- } else {
565
- parts.push(`${(e.timeSincePrevious / 1000).toFixed(1)}s`);
566
- }
567
- }
568
- if (e.previousPathname && e.previousPathname !== e.pathname) {
569
- parts.push(`from ${e.previousPathname}`);
570
- }
571
- return {
572
- id: generateEventId("route"),
573
- source: "route",
574
- timestamp: e.timestamp,
575
- title: e.pathname || "/",
576
- subtitle: parts.join(" · ") || "navigation",
577
- status,
578
- originalEvent: event
579
- };
580
- }
581
-
582
- // ============================================================================
583
- // Zustand Event Source Discovery
584
- // ============================================================================
585
-
586
- function tryLoadZustandSource() {
587
- try {
588
- // @ts-ignore - Dynamic import that may not exist
589
- const {
590
- zustandStateStore
591
- } = require("@buoy-gg/zustand");
592
- let lastChangeId = null;
593
- return {
594
- id: "zustand",
595
- name: "Zustand",
596
- eventSources: ["zustand"],
597
- available: true,
598
- subscribe: onEvent => {
599
- return zustandStateStore.subscribe(changes => {
600
- if (changes.length > 0) {
601
- const latestChange = changes[0];
602
- if (latestChange.id !== lastChangeId) {
603
- lastChangeId = latestChange.id;
604
- const unifiedEvent = transformZustandChange(latestChange);
605
- onEvent(unifiedEvent);
606
- }
607
- }
608
- });
609
- }
610
- };
611
- } catch {
612
- return null;
613
- }
614
- }
615
- function transformZustandChange(change) {
616
- const c = change;
617
-
618
- // Get status
619
- let status = "neutral";
620
- if (c.isSlowUpdate) {
621
- status = "pending"; // Yellow for slow updates
622
- } else if (c.hasStateChange) {
623
- status = "success";
624
- }
625
-
626
- // Get subtitle
627
- const parts = [];
628
- if (c.changedKeys && c.changedKeys.length > 0) {
629
- const keys = c.changedKeys.slice(0, 3).join(", ");
630
- const more = c.changedKeys.length > 3 ? ` +${c.changedKeys.length - 3}` : "";
631
- parts.push(`${keys}${more}`);
632
- } else if (c.diffSummary) {
633
- parts.push(c.diffSummary);
634
- }
635
- if (c.duration !== undefined) {
636
- parts.push(`${c.duration.toFixed(1)}ms`);
637
- }
638
- if (c.category === "replace") {
639
- parts.push("replace");
640
- }
641
- return {
642
- id: generateEventId("zustand"),
643
- source: "zustand",
644
- timestamp: c.timestamp,
645
- title: c.storeName,
646
- subtitle: parts.join(" · ") || (c.hasStateChange ? "state changed" : "no change"),
647
- status,
648
- originalEvent: change
649
- };
650
- }
651
-
652
- // ============================================================================
653
- // Jotai Event Source Discovery
654
- // ============================================================================
655
-
656
- function tryLoadJotaiSource() {
657
- try {
658
- // @ts-ignore - Dynamic import that may not exist
659
- const {
660
- jotaiStateStore
661
- } = require("@buoy-gg/jotai");
662
- let lastChangeId = null;
663
- return {
664
- id: "jotai",
665
- name: "Jotai",
666
- eventSources: ["jotai"],
667
- available: true,
668
- subscribe: onEvent => {
669
- return jotaiStateStore.subscribe(changes => {
670
- if (changes.length > 0) {
671
- const latestChange = changes[0];
672
- if (latestChange.id !== lastChangeId) {
673
- lastChangeId = latestChange.id;
674
- const unifiedEvent = transformJotaiChange(latestChange);
675
- onEvent(unifiedEvent);
676
- }
677
- }
678
- });
679
- }
680
- };
681
- } catch {
682
- return null;
683
- }
684
- }
685
- function transformJotaiChange(change) {
686
- const c = change;
687
-
688
- // Get status
689
- let status = "neutral";
690
- if (c.category === "write" && c.hasValueChange) {
691
- status = "success";
692
- } else if (c.category === "read") {
693
- status = "neutral";
694
- }
695
-
696
- // Get subtitle
697
- const parts = [];
698
- if (c.valuePreview) {
699
- parts.push(c.valuePreview);
700
- } else if (c.diffSummary) {
701
- parts.push(c.diffSummary);
702
- }
703
- if (c.category) {
704
- parts.push(c.category);
705
- }
706
- return {
707
- id: generateEventId("jotai"),
708
- source: "jotai",
709
- timestamp: c.timestamp,
710
- title: c.atomLabel,
711
- subtitle: parts.join(" · ") || (c.hasValueChange ? "value changed" : "no change"),
712
- status,
713
- originalEvent: change
714
- };
715
- }
716
-
717
- // ============================================================================
718
- // Render Events Source Discovery (Highlight Updates)
719
- // ============================================================================
720
-
721
- function tryLoadHighlightUpdatesSource() {
722
- // Metro only treats a require() as optional when the statement sits DIRECTLY
723
- // inside a single-level try block — a require nested in a closure (even one
724
- // defined inside a try) fails the bundle when the package isn't installed.
725
- // So: require once here, and let the callbacks below close over the result.
726
- let highlightUpdates;
727
- try {
728
- // @ts-ignore - Dynamic import that may not exist
729
- highlightUpdates = require("@buoy-gg/highlight-updates");
730
- } catch {
731
- return null;
732
- }
733
- try {
734
- // Verify the required exports exist
735
- if (!highlightUpdates.RenderTracker || !highlightUpdates.HighlightUpdatesController) {
736
- return null;
737
- }
738
- const {
739
- RenderTracker,
740
- HighlightUpdatesController
741
- } = highlightUpdates;
742
- return {
743
- id: "render",
744
- name: "Render",
745
- eventSources: ["render"],
746
- available: true,
747
- setup: () => {
748
- // Enable background tracking (NOT the visual toggle) - this sets up render
749
- // interception without affecting the user's visual highlight toggle state
750
- if (HighlightUpdatesController) {
751
- HighlightUpdatesController.enableBackgroundTracking();
752
- }
753
- },
754
- subscribe: onEvent => {
755
- // Ensure background tracking is enabled (separate from visual toggle)
756
- if (HighlightUpdatesController && !HighlightUpdatesController.isBackgroundTrackingEnabled()) {
757
- HighlightUpdatesController.enableBackgroundTracking();
758
- }
759
- const unsubscribeCallback = RenderTracker.onRenderEvent((event, render) => {
760
- const unifiedEvent = transformRenderEvent(event, render);
761
- onEvent(unifiedEvent);
762
- });
763
-
764
- // Return a wrapped unsubscribe that also disables background tracking
765
- return () => {
766
- unsubscribeCallback();
767
- HighlightUpdatesController.disableBackgroundTracking();
768
- };
769
- }
770
- };
771
- } catch {
772
- return null;
773
- }
774
- }
775
- function transformRenderEvent(event, render) {
776
- const e = event;
777
- const r = render;
778
-
779
- // Use component name if available, otherwise display name (View, Text, etc.)
780
- const title = r.componentName || r.displayName || r.viewType;
781
-
782
- // Build subtitle from cause info
783
- const subtitleParts = [];
784
-
785
- // Add cause type
786
- const causeLabels = {
787
- mount: "mounted",
788
- props: "props changed",
789
- state: "state changed",
790
- hooks: "hooks changed",
791
- context: "context changed",
792
- parent: "parent re-rendered",
793
- unknown: "re-rendered"
794
- };
795
- subtitleParts.push(causeLabels[e.cause.type] || e.cause.type);
796
-
797
- // Add changed keys if props changed
798
- if (e.cause.type === "props" && e.cause.changedKeys?.length) {
799
- const keys = e.cause.changedKeys.slice(0, 3).join(", ");
800
- const more = e.cause.changedKeys.length > 3 ? ` +${e.cause.changedKeys.length - 3}` : "";
801
- subtitleParts.push(`[${keys}${more}]`);
802
- }
803
-
804
- // Add hook change description if available
805
- if (e.cause.hookChanges?.length) {
806
- const firstChange = e.cause.hookChanges[0];
807
- if (firstChange.description) {
808
- subtitleParts.push(firstChange.description);
809
- }
810
- }
811
-
812
- // Add render number
813
- subtitleParts.push(`#${e.renderNumber}`);
814
-
815
- // Determine status based on cause type
816
- let status = "neutral";
817
- switch (e.cause.type) {
818
- case "mount":
819
- status = "neutral"; // First render is expected
820
- break;
821
- case "props":
822
- case "state":
823
- case "hooks":
824
- case "context":
825
- status = "success"; // Intentional re-renders
826
- break;
827
- case "parent":
828
- status = "pending"; // Potentially wasteful (yellow highlight)
829
- break;
830
- default:
831
- status = "neutral";
832
- }
833
- return {
834
- id: generateEventId("render"),
835
- source: "render",
836
- timestamp: e.timestamp,
837
- title,
838
- subtitle: subtitleParts.join(" · "),
839
- status,
840
- originalEvent: {
841
- event: e,
842
- render: r
843
- }
844
- };
845
- }
846
-
847
- // ============================================================================
848
- // Main Auto-Discovery Function
849
- // ============================================================================
850
-
851
- /**
852
- * Automatically discovers which event source packages are installed.
853
- *
854
- * This function attempts to load event stores from known dev tool packages.
855
- * If a package is installed, its event source will be available.
856
- * If a package is not installed, it will be silently skipped.
857
- *
858
- * @returns Discovery result with all available sources
859
- *
860
- * @example
861
- * ```tsx
862
- * const { sources, availableEventSources } = autoDiscoverEventSources();
863
- *
864
- * // sources contains all available event source configs
865
- * // availableEventSources contains the Set of EventSource types available
866
- * ```
867
- */
868
- function autoDiscoverEventSources() {
869
- const sources = [];
870
- const availableEventSources = new Set();
871
-
872
- // Try to load each source
873
- const loaders = [tryLoadStorageSource, tryLoadReduxSource, tryLoadNetworkSource, tryLoadReactQuerySource, tryLoadRouteEventsSource, tryLoadZustandSource, tryLoadJotaiSource, tryLoadHighlightUpdatesSource];
874
- for (const loader of loaders) {
875
- const source = loader();
876
- if (source && source.available) {
877
- sources.push(source);
878
- source.eventSources.forEach(es => availableEventSources.add(es));
879
- }
880
- }
881
- return {
882
- sources,
883
- availableEventSources
884
- };
885
- }
886
-
887
- /**
888
- * Get display configuration for an event source.
889
- * Returns config even for unavailable sources (for consistent UI).
890
- */
891
- function getSourceDisplayConfig(source) {
892
- const configs = {
893
- "storage-async": {
894
- label: "Storage",
895
- color: "#8B5CF6",
896
- icon: "server-outline"
897
- },
898
- "storage-mmkv": {
899
- label: "MMKV",
900
- color: "#F59E0B",
901
- icon: "flash-outline"
902
- },
903
- redux: {
904
- label: "Redux",
905
- color: "#3B82F6",
906
- icon: "git-branch-outline"
907
- },
908
- network: {
909
- label: "Network",
910
- color: "#10B981",
911
- icon: "globe-outline"
912
- },
913
- "react-query": {
914
- label: "Query",
915
- color: "#EC4899",
916
- icon: "sync-outline"
917
- },
918
- "react-query-query": {
919
- label: "Query",
920
- color: "#EC4899",
921
- icon: "sync-outline"
922
- },
923
- "react-query-mutation": {
924
- label: "Mutation",
925
- color: "#F97316",
926
- icon: "flash-outline"
927
- },
928
- route: {
929
- label: "Route",
930
- color: "#06B6D4",
931
- icon: "navigate-outline"
932
- },
933
- zustand: {
934
- label: "Zustand",
935
- color: "#764ABC",
936
- icon: "cube-outline"
937
- },
938
- jotai: {
939
- label: "Jotai",
940
- color: "#14B8A6",
941
- icon: "ellipse-outline"
942
- },
943
- render: {
944
- label: "Render",
945
- color: "#F472B6",
946
- icon: "layers-outline"
947
- }
948
- };
949
- return configs[source] || {
950
- label: source,
951
- color: "#6B7280",
952
- icon: "help-outline"
953
- };
954
- }
955
-
956
- // Cache for discovered sources (singleton)
957
- let cachedDiscovery = null;
958
-
959
- /**
960
- * Get cached discovery result, or run discovery if not cached.
961
- * Use this for performance - avoids repeated require() calls.
962
- */
963
- function getCachedDiscovery() {
964
- if (!cachedDiscovery) {
965
- cachedDiscovery = autoDiscoverEventSources();
966
- }
967
- return cachedDiscovery;
968
- }
969
-
970
- /**
971
- * Clear the discovery cache (useful for testing or hot reload).
972
- */
973
- function clearDiscoveryCache() {
974
- cachedDiscovery = null;
975
- }
976
-
977
- // ============================================================================
978
- // Subscriber Count Aggregation
979
- // ============================================================================
980
-
981
- /**
982
- * Get subscriber counts from all discovered event stores.
983
- * Useful for debugging and monitoring the event system.
984
- */
985
- function getAggregatedSubscriberCounts() {
986
- const sources = [];
987
- let totalSubscribers = 0;
988
-
989
- // Try to get counts from storage store
990
- try {
991
- // @ts-ignore - Dynamic import that may not exist
992
- const {
993
- storageEventStore
994
- } = require("@buoy-gg/storage");
995
- const counts = storageEventStore.getSubscriberCounts();
996
- sources.push({
997
- sourceId: "storage",
998
- counts
999
- });
1000
- totalSubscribers += counts.total;
1001
- } catch {
1002
- // Package not installed
1003
- }
1004
-
1005
- // Try to get counts from network store
1006
- try {
1007
- // @ts-ignore - Dynamic import that may not exist
1008
- const {
1009
- networkEventStore
1010
- } = require("@buoy-gg/network");
1011
- const counts = networkEventStore.getSubscriberCounts();
1012
- sources.push({
1013
- sourceId: "network",
1014
- counts
1015
- });
1016
- totalSubscribers += counts.total;
1017
- } catch {
1018
- // Package not installed
1019
- }
1020
-
1021
- // Try to get counts from route events store
1022
- try {
1023
- // @ts-ignore - Dynamic import that may not exist
1024
- const {
1025
- routeEventStore
1026
- } = require("@buoy-gg/route-events");
1027
- const counts = routeEventStore.getSubscriberCounts();
1028
- sources.push({
1029
- sourceId: "route-events",
1030
- counts
1031
- });
1032
- totalSubscribers += counts.total;
1033
- } catch {
1034
- // Package not installed
1035
- }
1036
-
1037
- // Try to get counts from render tracker (highlight-updates)
1038
- try {
1039
- // @ts-ignore - Dynamic import that may not exist
1040
- const {
1041
- RenderTracker,
1042
- HighlightUpdatesController
1043
- } = require("@buoy-gg/highlight-updates");
1044
- const callbackCount = RenderTracker.getRenderEventCallbackCount();
1045
- // Also count the visual highlight tool as a subscriber when enabled
1046
- const visualToolEnabled = HighlightUpdatesController?.isEnabled?.() ? 1 : 0;
1047
- const counts = {
1048
- eventCallbacks: callbackCount,
1049
- arrayListeners: visualToolEnabled,
1050
- total: callbackCount + visualToolEnabled
1051
- };
1052
- sources.push({
1053
- sourceId: "render",
1054
- counts
1055
- });
1056
- totalSubscribers += counts.total;
1057
- } catch {
1058
- // Package not installed
1059
- }
1060
- return {
1061
- sources,
1062
- totalSubscribers
1063
- };
1064
- }
1065
- //# sourceMappingURL=autoDiscoverEventSources.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.autoDiscoverEventSources=autoDiscoverEventSources;exports.clearDiscoveryCache=clearDiscoveryCache;exports.getAggregatedSubscriberCounts=getAggregatedSubscriberCounts;exports.getCachedDiscovery=getCachedDiscovery;exports.getSourceDisplayConfig=getSourceDisplayConfig;var _utils=require("@buoy-gg/shared-ui/utils");let eventIdCounter=0;function generateEventId(r){return`${r}-${Date.now()}-${++eventIdCounter}`}function tryLoadStorageSource(){try{const{storageEventStore:r}=(0,_utils.loadToolModule)("@buoy-gg/storage");return{id:"storage",name:"Storage",eventSources:["storage-async","storage-mmkv"],available:true,subscribe:e=>{return r.onEvent(t=>{const n=t?.data;if(n?.initialScan)return;const s=transformStorageEvent(t);e(s)})}}}catch{return null}}function transformStorageEvent(r){const e=r;const t=e.storageType==="async"?"storage-async":"storage-mmkv";let n=e.action;if(e.storageType==="async"){const o={setItem:"Set Item",removeItem:"Remove Item",mergeItem:"Merge Item",clear:"Clear All",multiSet:"Multi Set",multiRemove:"Multi Remove",multiMerge:"Multi Merge"};n=o[e.action]||e.action}let s="";if(e.storageType==="async"){switch(e.action){case"setItem":case"removeItem":case"mergeItem":s=e.data?.key||"unknown key";break;case"multiSet":case"multiMerge":{const o=e.data?.pairs?.length||0;s=`${o} key${o!==1?"s":""}`;break}case"multiRemove":{const o=e.data?.keys?.length||0;s=`${o} key${o!==1?"s":""}`;break}case"clear":s="all keys";break}}else{s=e.data?.key||e.data?.instanceId||"unknown"}let a="neutral";if(e.action.includes("set")||e.action.includes("Set")||e.action.includes("merge")||e.action.includes("Merge")){a="success"}return{id:generateEventId(t),source:t,timestamp:e.timestamp.getTime(),title:n,subtitle:s,status:a,originalEvent:r}}function tryLoadReduxSource(){try{const{reduxActionStore:r}=(0,_utils.loadToolModule)("@buoy-gg/redux");let e=null;return{id:"redux",name:"Redux",eventSources:["redux"],available:true,subscribe:t=>{return r.subscribe(n=>{if(n.length>0){const s=n[0];if(s.id!==e){e=s.id;const a=transformReduxAction(s);t(a)}}})}}}catch{return null}}function transformReduxAction(r){const e=r;let t="neutral";switch(e.category){case"fulfilled":t="success";break;case"rejected":t="error";break;case"pending":t="pending";break;default:t=e.hasStateChange?"success":"neutral"}let n="";if(e.payloadPreview){n=e.payloadPreview}else if(e.hasStateChange&&e.diffSummary){n=e.diffSummary}else if(e.duration!==void 0){n=`${e.duration.toFixed(1)}ms`}else{n=e.sliceName||""}return{id:generateEventId("redux"),source:"redux",timestamp:e.timestamp,title:e.type,subtitle:n,status:t,originalEvent:r}}function tryLoadNetworkSource(){try{const{networkEventStore:r,networkListener:e,addNetworkListener:t}=(0,_utils.loadToolModule)("@buoy-gg/network");const n=new Map;return{id:"network",name:"Network",eventSources:["network"],available:true,setup:()=>{const s=e();if(!s.isActive){s.startListening()}if(s.listenerCount===0){t(a=>{r.processNetworkEvent(a)})}},subscribe:s=>{const a=Date.now();return r.onEvent(o=>{const u=o;const i=n.get(u.id);if(!i){if(typeof u.timestamp==="number"&&u.timestamp<a){return}const c=transformNetworkEvent(o);n.set(u.id,c.id);s(c)}else{const c=transformNetworkEvent(o);c.id=i;s(c)}},false)}}}catch{return null}}function transformNetworkEvent(r){const e=r;let t="neutral";if(e.status===void 0){t="pending"}else if(e.error||e.status>=400){t="error"}else if(e.status>=200&&e.status<400){t="success"}const n=e.operationName||`${e.method} ${e.path||e.url}`;const s=[];if(e.status!==void 0){s.push(`${e.status}`)}else if(e.error){s.push("Error")}else{s.push("Pending")}if(e.duration!==void 0){s.push(`${e.duration.toFixed(0)}ms`)}if(e.host){s.push(e.host)}return{id:generateEventId("network"),source:"network",timestamp:e.timestamp,title:n,subtitle:s.join(" \xB7 "),status:t,originalEvent:r}}function tryLoadReactQuerySource(){try{const{reactQueryEventStore:r}=(0,_utils.loadToolModule)("@buoy-gg/react-query");let e=null;return{id:"react-query",name:"React Query",eventSources:["react-query","react-query-query","react-query-mutation"],available:true,subscribe:t=>{let n=true;const s=new Set;const a=o=>o.queryHash??(o.mutationId!==void 0?`m-${o.mutationId}`:null);return r.subscribe(o=>{if(n){n=false;if(o.length>0){e=o[0].id}return}if(o.length>0){const u=o[0];if(u.id!==e){e=u.id;const i=u.type??"";const c=a(u);if(i==="query-fetch-start"||i==="mutation-start"){if(c)s.add(c)}else if(i==="query-fetch-success"||i==="query-fetch-error"||i==="mutation-success"||i==="mutation-error"){if(c&&!s.has(c)){return}}const l=transformReactQueryEvent(u);t(l)}}})}}}catch{return null}}function formatQueryKey(r){if(!r||r.length===0)return"unknown";return r.map(e=>{if(typeof e==="string")return e;if(typeof e==="number")return String(e);if(typeof e==="object"&&e!==null){const t=e;const n=Object.values(t)[0];if(typeof n==="string"||typeof n==="number"){return String(n)}return JSON.stringify(e).slice(0,20)}return String(e)}).join(" \u203A ")}function transformReactQueryEvent(r){const e=r;const t=e.type.startsWith("mutation-");const n=t?"react-query-mutation":"react-query-query";let s="neutral";switch(e.type){case"query-fetch-start":case"mutation-start":s="pending";break;case"query-fetch-success":case"mutation-success":s="success";break;case"query-fetch-error":case"mutation-error":s="error";break}let a="";if(e.queryKey){a=formatQueryKey(e.queryKey)}else if(e.mutationKey){a=formatQueryKey(e.mutationKey)}else if(e.mutationId!==void 0){a=`Mutation #${e.mutationId}`}else{a=e.type.replace(/-/g," ")}const o=[];switch(e.type){case"query-fetch-start":o.push("Fetching");break;case"query-fetch-success":o.push("Success");break;case"query-fetch-error":o.push("Error");break;case"query-invalidated":o.push("Invalidated");break;case"mutation-start":o.push("Mutating");break;case"mutation-success":o.push("Success");break;case"mutation-error":o.push("Error");break}if(e.duration!==void 0){o.push(`${e.duration.toFixed(0)}ms`)}let u;if(e.queryHash){u=`rq-query-${e.queryHash}`}else if(e.mutationId!==void 0){u=`rq-mutation-${e.mutationId}`}let i=1;switch(e.type){case"query-fetch-start":case"mutation-start":i=1;break;case"query-fetch-success":case"query-fetch-error":case"mutation-success":case"mutation-error":i=2;break;case"query-invalidated":i=3;break}return{id:generateEventId(n),source:n,timestamp:e.timestamp,title:a,subtitle:o.join(" \xB7 "),status:s,originalEvent:r,correlationId:u,sequenceInGroup:i}}function tryLoadRouteEventsSource(){try{const{routeEventStore:r}=(0,_utils.loadToolModule)("@buoy-gg/route-events");return{id:"route-events",name:"Routes",eventSources:["route"],available:true,subscribe:e=>{return r.onEvent(t=>{const n=transformRouteEvent(t);e(n)})}}}catch{return null}}function transformRouteEvent(r){const e=r;let t="neutral";if(e.pathname==="/"){t="success"}else if(Object.keys(e.params).length>0){t="success"}const n=[];const s=Object.keys(e.params).length;if(s>0){n.push(`${s} param${s!==1?"s":""}`)}if(e.timeSincePrevious!==void 0&&e.timeSincePrevious>0){if(e.timeSincePrevious<1e3){n.push(`${e.timeSincePrevious}ms`)}else{n.push(`${(e.timeSincePrevious/1e3).toFixed(1)}s`)}}if(e.previousPathname&&e.previousPathname!==e.pathname){n.push(`from ${e.previousPathname}`)}return{id:generateEventId("route"),source:"route",timestamp:e.timestamp,title:e.pathname||"/",subtitle:n.join(" \xB7 ")||"navigation",status:t,originalEvent:r}}function tryLoadZustandSource(){try{const{zustandStateStore:r}=(0,_utils.loadToolModule)("@buoy-gg/zustand");let e=null;return{id:"zustand",name:"Zustand",eventSources:["zustand"],available:true,subscribe:t=>{return r.subscribe(n=>{if(n.length>0){const s=n[0];if(s.id!==e){e=s.id;const a=transformZustandChange(s);t(a)}}})}}}catch{return null}}function transformZustandChange(r){const e=r;let t="neutral";if(e.isSlowUpdate){t="pending"}else if(e.hasStateChange){t="success"}const n=[];if(e.changedKeys&&e.changedKeys.length>0){const s=e.changedKeys.slice(0,3).join(", ");const a=e.changedKeys.length>3?` +${e.changedKeys.length-3}`:"";n.push(`${s}${a}`)}else if(e.diffSummary){n.push(e.diffSummary)}if(e.duration!==void 0){n.push(`${e.duration.toFixed(1)}ms`)}if(e.category==="replace"){n.push("replace")}return{id:generateEventId("zustand"),source:"zustand",timestamp:e.timestamp,title:e.storeName,subtitle:n.join(" \xB7 ")||(e.hasStateChange?"state changed":"no change"),status:t,originalEvent:r}}function tryLoadJotaiSource(){try{const{jotaiStateStore:r}=(0,_utils.loadToolModule)("@buoy-gg/jotai");let e=null;return{id:"jotai",name:"Jotai",eventSources:["jotai"],available:true,subscribe:t=>{return r.subscribe(n=>{if(n.length>0){const s=n[0];if(s.id!==e){e=s.id;const a=transformJotaiChange(s);t(a)}}})}}}catch{return null}}function transformJotaiChange(r){const e=r;let t="neutral";if(e.category==="write"&&e.hasValueChange){t="success"}else if(e.category==="read"){t="neutral"}const n=[];if(e.valuePreview){n.push(e.valuePreview)}else if(e.diffSummary){n.push(e.diffSummary)}if(e.category){n.push(e.category)}return{id:generateEventId("jotai"),source:"jotai",timestamp:e.timestamp,title:e.atomLabel,subtitle:n.join(" \xB7 ")||(e.hasValueChange?"value changed":"no change"),status:t,originalEvent:r}}function tryLoadHighlightUpdatesSource(){let r;try{r=(0,_utils.loadToolModule)("@buoy-gg/highlight-updates")}catch{return null}try{if(!r.RenderTracker||!r.HighlightUpdatesController){return null}const{RenderTracker:e,HighlightUpdatesController:t}=r;return{id:"render",name:"Render",eventSources:["render"],available:true,setup:()=>{if(t){t.enableBackgroundTracking()}},subscribe:n=>{if(t&&!t.isBackgroundTrackingEnabled()){t.enableBackgroundTracking()}const s=e.onRenderEvent((a,o)=>{const u=transformRenderEvent(a,o);n(u)});return()=>{s();t.disableBackgroundTracking()}}}}catch{return null}}function transformRenderEvent(r,e){const t=r;const n=e;const s=n.componentName||n.displayName||n.viewType;const a=[];const o={mount:"mounted",props:"props changed",state:"state changed",hooks:"hooks changed",context:"context changed",parent:"parent re-rendered",unknown:"re-rendered"};a.push(o[t.cause.type]||t.cause.type);if(t.cause.type==="props"&&t.cause.changedKeys?.length){const i=t.cause.changedKeys.slice(0,3).join(", ");const c=t.cause.changedKeys.length>3?` +${t.cause.changedKeys.length-3}`:"";a.push(`[${i}${c}]`)}if(t.cause.hookChanges?.length){const i=t.cause.hookChanges[0];if(i.description){a.push(i.description)}}a.push(`#${t.renderNumber}`);let u="neutral";switch(t.cause.type){case"mount":u="neutral";break;case"props":case"state":case"hooks":case"context":u="success";break;case"parent":u="pending";break;default:u="neutral"}return{id:generateEventId("render"),source:"render",timestamp:t.timestamp,title:s,subtitle:a.join(" \xB7 "),status:u,originalEvent:{event:t,render:n}}}function autoDiscoverEventSources(){const r=[];const e=new Set;const t=[tryLoadStorageSource,tryLoadReduxSource,tryLoadNetworkSource,tryLoadReactQuerySource,tryLoadRouteEventsSource,tryLoadZustandSource,tryLoadJotaiSource,tryLoadHighlightUpdatesSource];for(const n of t){const s=n();if(s&&s.available){r.push(s);s.eventSources.forEach(a=>e.add(a))}}return{sources:r,availableEventSources:e}}function getSourceDisplayConfig(r){const e={"storage-async":{label:"Storage",color:"#8B5CF6",icon:"server-outline"},"storage-mmkv":{label:"MMKV",color:"#F59E0B",icon:"flash-outline"},redux:{label:"Redux",color:"#3B82F6",icon:"git-branch-outline"},network:{label:"Network",color:"#10B981",icon:"globe-outline"},"react-query":{label:"Query",color:"#EC4899",icon:"sync-outline"},"react-query-query":{label:"Query",color:"#EC4899",icon:"sync-outline"},"react-query-mutation":{label:"Mutation",color:"#F97316",icon:"flash-outline"},route:{label:"Route",color:"#06B6D4",icon:"navigate-outline"},zustand:{label:"Zustand",color:"#764ABC",icon:"cube-outline"},jotai:{label:"Jotai",color:"#14B8A6",icon:"ellipse-outline"},render:{label:"Render",color:"#F472B6",icon:"layers-outline"}};return e[r]||{label:r,color:"#6B7280",icon:"help-outline"}}let cachedDiscovery=null;let discoveryVersion=-1;function getCachedDiscovery(){if(!cachedDiscovery||discoveryVersion!==(0,_utils.getToolModuleVersion)()){discoveryVersion=(0,_utils.getToolModuleVersion)();cachedDiscovery=autoDiscoverEventSources()}return cachedDiscovery}function clearDiscoveryCache(){cachedDiscovery=null}function getAggregatedSubscriberCounts(){const r=[];let e=0;try{const{storageEventStore:t}=(0,_utils.loadToolModule)("@buoy-gg/storage");const n=t.getSubscriberCounts();r.push({sourceId:"storage",counts:n});e+=n.total}catch{}try{const{networkEventStore:t}=(0,_utils.loadToolModule)("@buoy-gg/network");const n=t.getSubscriberCounts();r.push({sourceId:"network",counts:n});e+=n.total}catch{}try{const{routeEventStore:t}=(0,_utils.loadToolModule)("@buoy-gg/route-events");const n=t.getSubscriberCounts();r.push({sourceId:"route-events",counts:n});e+=n.total}catch{}try{const{RenderTracker:t,HighlightUpdatesController:n}=(0,_utils.loadToolModule)("@buoy-gg/highlight-updates");const s=t.getRenderEventCallbackCount();const a=n?.isEnabled?.()?1:0;const o={eventCallbacks:s,arrayListeners:a,total:s+a};r.push({sourceId:"render",counts:o});e+=o.total}catch{}return{sources:r,totalSubscribers:e}}