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