@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.
- package/README.md +11 -64
- package/lib/commonjs/components/EventsCopySettingsView.js +1 -581
- package/lib/commonjs/components/EventsModal.js +1 -378
- package/lib/commonjs/components/ReactQueryEventDetail.js +1 -433
- package/lib/commonjs/components/UnifiedEventDetail.js +1 -565
- package/lib/commonjs/components/UnifiedEventFilters.js +1 -160
- package/lib/commonjs/components/UnifiedEventItem.js +1 -416
- package/lib/commonjs/components/UnifiedEventList.js +1 -187
- package/lib/commonjs/components/UnifiedEventViewer.js +1 -130
- package/lib/commonjs/hooks/useUnifiedEvents.js +1 -419
- package/lib/commonjs/index.js +1 -282
- package/lib/commonjs/preset.js +1 -60
- package/lib/commonjs/sources/sourceIds.js +1 -30
- package/lib/commonjs/stores/unifiedEventStore.js +1 -712
- package/lib/commonjs/sync/eventsSyncAdapter.js +1 -358
- package/lib/commonjs/types/copySettings.js +1 -249
- package/lib/commonjs/types/index.js +1 -17
- package/lib/commonjs/utils/autoDiscoverEventSources.js +1 -1068
- package/lib/commonjs/utils/badgeSelectionStorage.js +1 -126
- package/lib/commonjs/utils/copySettingsStorage.js +1 -43
- package/lib/commonjs/utils/correlationUtils.js +1 -130
- package/lib/commonjs/utils/eventExportFormatter.js +1 -1912
- package/lib/commonjs/utils/eventTransformers.js +1 -496
- package/lib/commonjs/utils/eventVisibility.js +1 -76
- package/lib/commonjs/utils/testIDs.js +1 -91
- package/lib/module/components/EventsCopySettingsView.js +1 -577
- package/lib/module/components/EventsModal.js +1 -374
- package/lib/module/components/ReactQueryEventDetail.js +1 -429
- package/lib/module/components/UnifiedEventDetail.js +1 -561
- package/lib/module/components/UnifiedEventFilters.js +1 -156
- package/lib/module/components/UnifiedEventItem.js +1 -412
- package/lib/module/components/UnifiedEventList.js +1 -183
- package/lib/module/components/UnifiedEventViewer.js +1 -126
- package/lib/module/hooks/useUnifiedEvents.js +1 -416
- package/lib/module/index.js +1 -102
- package/lib/module/preset.js +1 -57
- package/lib/module/sources/sourceIds.js +1 -26
- package/lib/module/stores/unifiedEventStore.js +1 -678
- package/lib/module/sync/eventsSyncAdapter.js +1 -354
- package/lib/module/types/copySettings.js +1 -244
- package/lib/module/types/index.js +1 -37
- package/lib/module/utils/autoDiscoverEventSources.js +1 -1060
- package/lib/module/utils/badgeSelectionStorage.js +1 -116
- package/lib/module/utils/copySettingsStorage.js +1 -37
- package/lib/module/utils/correlationUtils.js +1 -120
- package/lib/module/utils/eventExportFormatter.js +1 -1901
- package/lib/module/utils/eventTransformers.js +1 -487
- package/lib/module/utils/eventVisibility.js +1 -70
- package/lib/module/utils/testIDs.js +1 -83
- package/lib/web/index.mjs +9 -10
- package/package.json +3 -3
- package/lib/commonjs/components/EventsCopySettingsView.js.map +0 -1
- package/lib/commonjs/components/EventsModal.js.map +0 -1
- package/lib/commonjs/components/ReactQueryEventDetail.js.map +0 -1
- package/lib/commonjs/components/UnifiedEventDetail.js.map +0 -1
- package/lib/commonjs/components/UnifiedEventFilters.js.map +0 -1
- package/lib/commonjs/components/UnifiedEventItem.js.map +0 -1
- package/lib/commonjs/components/UnifiedEventList.js.map +0 -1
- package/lib/commonjs/components/UnifiedEventViewer.js.map +0 -1
- package/lib/commonjs/hooks/useUnifiedEvents.js.map +0 -1
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/preset.js.map +0 -1
- package/lib/commonjs/sources/sourceIds.js.map +0 -1
- package/lib/commonjs/stores/unifiedEventStore.js.map +0 -1
- package/lib/commonjs/sync/eventsSyncAdapter.js.map +0 -1
- package/lib/commonjs/types/copySettings.js.map +0 -1
- package/lib/commonjs/types/index.js.map +0 -1
- package/lib/commonjs/utils/autoDiscoverEventSources.js.map +0 -1
- package/lib/commonjs/utils/badgeSelectionStorage.js.map +0 -1
- package/lib/commonjs/utils/copySettingsStorage.js.map +0 -1
- package/lib/commonjs/utils/correlationUtils.js.map +0 -1
- package/lib/commonjs/utils/eventExportFormatter.js.map +0 -1
- package/lib/commonjs/utils/eventTransformers.js.map +0 -1
- package/lib/commonjs/utils/eventVisibility.js.map +0 -1
- package/lib/commonjs/utils/testIDs.js.map +0 -1
- package/lib/module/components/EventsCopySettingsView.js.map +0 -1
- package/lib/module/components/EventsModal.js.map +0 -1
- package/lib/module/components/ReactQueryEventDetail.js.map +0 -1
- package/lib/module/components/UnifiedEventDetail.js.map +0 -1
- package/lib/module/components/UnifiedEventFilters.js.map +0 -1
- package/lib/module/components/UnifiedEventItem.js.map +0 -1
- package/lib/module/components/UnifiedEventList.js.map +0 -1
- package/lib/module/components/UnifiedEventViewer.js.map +0 -1
- package/lib/module/hooks/useUnifiedEvents.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/preset.js.map +0 -1
- package/lib/module/sources/sourceIds.js.map +0 -1
- package/lib/module/stores/unifiedEventStore.js.map +0 -1
- package/lib/module/sync/eventsSyncAdapter.js.map +0 -1
- package/lib/module/types/copySettings.js.map +0 -1
- package/lib/module/types/index.js.map +0 -1
- package/lib/module/utils/autoDiscoverEventSources.js.map +0 -1
- package/lib/module/utils/badgeSelectionStorage.js.map +0 -1
- package/lib/module/utils/copySettingsStorage.js.map +0 -1
- package/lib/module/utils/correlationUtils.js.map +0 -1
- package/lib/module/utils/eventExportFormatter.js.map +0 -1
- package/lib/module/utils/eventTransformers.js.map +0 -1
- package/lib/module/utils/eventVisibility.js.map +0 -1
- package/lib/module/utils/testIDs.js.map +0 -1
- package/lib/typescript/components/EventsCopySettingsView.d.ts.map +0 -1
- package/lib/typescript/components/EventsModal.d.ts.map +0 -1
- package/lib/typescript/components/ReactQueryEventDetail.d.ts.map +0 -1
- package/lib/typescript/components/UnifiedEventDetail.d.ts.map +0 -1
- package/lib/typescript/components/UnifiedEventFilters.d.ts.map +0 -1
- package/lib/typescript/components/UnifiedEventItem.d.ts.map +0 -1
- package/lib/typescript/components/UnifiedEventList.d.ts.map +0 -1
- package/lib/typescript/components/UnifiedEventViewer.d.ts.map +0 -1
- package/lib/typescript/hooks/useUnifiedEvents.d.ts.map +0 -1
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/preset.d.ts.map +0 -1
- package/lib/typescript/sources/sourceIds.d.ts.map +0 -1
- package/lib/typescript/stores/unifiedEventStore.d.ts.map +0 -1
- package/lib/typescript/sync/eventsSyncAdapter.d.ts.map +0 -1
- package/lib/typescript/types/copySettings.d.ts.map +0 -1
- package/lib/typescript/types/index.d.ts.map +0 -1
- package/lib/typescript/utils/autoDiscoverEventSources.d.ts.map +0 -1
- package/lib/typescript/utils/badgeSelectionStorage.d.ts.map +0 -1
- package/lib/typescript/utils/copySettingsStorage.d.ts.map +0 -1
- package/lib/typescript/utils/correlationUtils.d.ts.map +0 -1
- package/lib/typescript/utils/eventExportFormatter.d.ts.map +0 -1
- package/lib/typescript/utils/eventTransformers.d.ts.map +0 -1
- package/lib/typescript/utils/eventVisibility.d.ts.map +0 -1
- package/lib/typescript/utils/testIDs.d.ts.map +0 -1
|
@@ -1,1912 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.estimateExportSize = estimateExportSize;
|
|
7
|
-
exports.filterEvents = filterEvents;
|
|
8
|
-
exports.generateExport = generateExport;
|
|
9
|
-
exports.generateJsonExport = generateJsonExport;
|
|
10
|
-
exports.generateMarkdownExport = generateMarkdownExport;
|
|
11
|
-
exports.generateMermaidExport = generateMermaidExport;
|
|
12
|
-
exports.generatePlaintextExport = generatePlaintextExport;
|
|
13
|
-
exports.getExportSummary = getExportSummary;
|
|
14
|
-
/**
|
|
15
|
-
* Event Export Formatter
|
|
16
|
-
*
|
|
17
|
-
* Utilities for generating formatted exports of unified events.
|
|
18
|
-
* Optimized for LLM consumption with smart JSON parsing and diff support.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Export summary statistics
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Status icons for display
|
|
27
|
-
*/
|
|
28
|
-
const STATUS_ICONS = {
|
|
29
|
-
success: "\u2705",
|
|
30
|
-
// ✅
|
|
31
|
-
pending: "\u23F3",
|
|
32
|
-
// ⏳
|
|
33
|
-
error: "\u274C",
|
|
34
|
-
// ❌
|
|
35
|
-
neutral: "\u2796" // ➖
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Status icons for plaintext (ASCII-safe)
|
|
40
|
-
*/
|
|
41
|
-
const STATUS_ICONS_ASCII = {
|
|
42
|
-
success: "[OK]",
|
|
43
|
-
pending: "[...]",
|
|
44
|
-
error: "[ERR]",
|
|
45
|
-
neutral: "[-]"
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Source labels for display
|
|
50
|
-
*/
|
|
51
|
-
const SOURCE_LABELS = {
|
|
52
|
-
"storage-async": "Storage",
|
|
53
|
-
"storage-mmkv": "MMKV",
|
|
54
|
-
redux: "Redux",
|
|
55
|
-
network: "Network",
|
|
56
|
-
"react-query": "Query",
|
|
57
|
-
"react-query-query": "Query",
|
|
58
|
-
"react-query-mutation": "Mutation",
|
|
59
|
-
route: "Route",
|
|
60
|
-
zustand: "Zustand",
|
|
61
|
-
jotai: "Jotai",
|
|
62
|
-
render: "Render"
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// ============================================================================
|
|
66
|
-
// SMART JSON PARSING UTILITIES
|
|
67
|
-
// ============================================================================
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Try to parse a string as JSON, return original if not valid JSON
|
|
71
|
-
*/
|
|
72
|
-
function tryParseJson(value) {
|
|
73
|
-
if (typeof value !== "string") return value;
|
|
74
|
-
|
|
75
|
-
// Check if it looks like JSON (starts with { or [)
|
|
76
|
-
const trimmed = value.trim();
|
|
77
|
-
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return value;
|
|
78
|
-
try {
|
|
79
|
-
return JSON.parse(value);
|
|
80
|
-
} catch {
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Recursively parse JSON strings within an object
|
|
87
|
-
*/
|
|
88
|
-
function deepParseJsonStrings(obj) {
|
|
89
|
-
if (obj === null || obj === undefined) return obj;
|
|
90
|
-
if (typeof obj === "string") {
|
|
91
|
-
return tryParseJson(obj);
|
|
92
|
-
}
|
|
93
|
-
if (Array.isArray(obj)) {
|
|
94
|
-
return obj.map(deepParseJsonStrings);
|
|
95
|
-
}
|
|
96
|
-
if (typeof obj === "object") {
|
|
97
|
-
const result = {};
|
|
98
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
99
|
-
result[key] = deepParseJsonStrings(value);
|
|
100
|
-
}
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
return obj;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Fields to strip when stripVerboseFields is enabled
|
|
108
|
-
* These add noise to LLM analysis without providing actionable info
|
|
109
|
-
*/
|
|
110
|
-
const VERBOSE_FIELDS = new Set(["image", "imageUrl", "imageURL", "image_url", "thumbnail", "thumbnailUrl", "thumbnail_url", "icon", "iconUrl", "avatar", "avatarUrl", "photo", "photoUrl", "picture", "pictureUrl", "description", "desc", "longDescription", "shortDescription", "meta_description"]);
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Recursively strip verbose fields from an object
|
|
114
|
-
*/
|
|
115
|
-
function stripVerboseFieldsFromObject(obj) {
|
|
116
|
-
if (obj === null || obj === undefined) return obj;
|
|
117
|
-
if (Array.isArray(obj)) {
|
|
118
|
-
return obj.map(stripVerboseFieldsFromObject);
|
|
119
|
-
}
|
|
120
|
-
if (typeof obj === "object") {
|
|
121
|
-
const result = {};
|
|
122
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
123
|
-
// Skip verbose fields
|
|
124
|
-
if (VERBOSE_FIELDS.has(key)) continue;
|
|
125
|
-
|
|
126
|
-
// Skip fields that look like image URLs
|
|
127
|
-
if (typeof value === "string" && isImageUrl(value)) continue;
|
|
128
|
-
result[key] = stripVerboseFieldsFromObject(value);
|
|
129
|
-
}
|
|
130
|
-
return result;
|
|
131
|
-
}
|
|
132
|
-
return obj;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Check if a string looks like an image URL
|
|
137
|
-
*/
|
|
138
|
-
function isImageUrl(value) {
|
|
139
|
-
if (!value.startsWith("http")) return false;
|
|
140
|
-
const lower = value.toLowerCase();
|
|
141
|
-
return lower.includes("/photo") || lower.includes("/image") || lower.includes("unsplash.com") || lower.includes("cloudinary.com") || lower.includes("imgur.com") || /\.(jpg|jpeg|png|gif|webp|svg|bmp)(\?|$)/i.test(value);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Format timestamp - convert Date objects to ISO strings
|
|
146
|
-
*/
|
|
147
|
-
function formatTimestampValue(value) {
|
|
148
|
-
if (value instanceof Date) {
|
|
149
|
-
return value.toISOString();
|
|
150
|
-
}
|
|
151
|
-
// Check if it's a date-like object that serializes to {}
|
|
152
|
-
if (value && typeof value === "object" && Object.keys(value).length === 0) {
|
|
153
|
-
return undefined; // Remove empty objects (failed Date serialization)
|
|
154
|
-
}
|
|
155
|
-
return value;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Compute array diff - return only added/removed items for cleaner output
|
|
160
|
-
*/
|
|
161
|
-
function computeArrayDiff(prevArray, newArray) {
|
|
162
|
-
// Get identifiers for comparison
|
|
163
|
-
const getId = item => {
|
|
164
|
-
if (typeof item !== "object" || item === null) return null;
|
|
165
|
-
const obj = item;
|
|
166
|
-
if (typeof obj.id === "string") return obj.id;
|
|
167
|
-
if (typeof obj.orderId === "string") return obj.orderId;
|
|
168
|
-
if (typeof obj.key === "string") return obj.key;
|
|
169
|
-
return null;
|
|
170
|
-
};
|
|
171
|
-
const prevIds = new Set(prevArray.map(getId).filter(Boolean));
|
|
172
|
-
const newIds = new Set(newArray.map(getId).filter(Boolean));
|
|
173
|
-
|
|
174
|
-
// Can't diff without IDs
|
|
175
|
-
if (prevIds.size === 0 && newIds.size === 0) return null;
|
|
176
|
-
const added = newArray.filter(item => {
|
|
177
|
-
const id = getId(item);
|
|
178
|
-
return id && !prevIds.has(id);
|
|
179
|
-
});
|
|
180
|
-
const removed = prevArray.filter(item => {
|
|
181
|
-
const id = getId(item);
|
|
182
|
-
return id && !newIds.has(id);
|
|
183
|
-
});
|
|
184
|
-
const unchanged = newArray.length - added.length;
|
|
185
|
-
|
|
186
|
-
// Only return diff if it's simpler than showing full arrays
|
|
187
|
-
if (added.length + removed.length < prevArray.length && added.length + removed.length < newArray.length) {
|
|
188
|
-
return {
|
|
189
|
-
added,
|
|
190
|
-
removed,
|
|
191
|
-
unchanged
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Format Storage event data with smart parsing
|
|
199
|
-
*/
|
|
200
|
-
function formatStorageData(data, settings) {
|
|
201
|
-
const result = {};
|
|
202
|
-
|
|
203
|
-
// Copy fields, fixing timestamps
|
|
204
|
-
if (data.action) result.action = data.action;
|
|
205
|
-
if (data.storageType) result.storageType = data.storageType;
|
|
206
|
-
|
|
207
|
-
// Fix timestamp serialization
|
|
208
|
-
if (data.timestamp !== undefined) {
|
|
209
|
-
const formattedTs = formatTimestampValue(data.timestamp);
|
|
210
|
-
if (formattedTs !== undefined) {
|
|
211
|
-
result.timestamp = formattedTs;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (data.data) {
|
|
215
|
-
const innerData = {
|
|
216
|
-
...data.data
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// Parse value and prevValue if they're JSON strings
|
|
220
|
-
if (settings.smartJsonParsing) {
|
|
221
|
-
if (innerData.value !== undefined) {
|
|
222
|
-
innerData.value = tryParseJson(innerData.value);
|
|
223
|
-
}
|
|
224
|
-
if (innerData.prevValue !== undefined) {
|
|
225
|
-
innerData.prevValue = tryParseJson(innerData.prevValue);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// For array values, try to show just the diff
|
|
230
|
-
if (settings.showStorageDiff && Array.isArray(innerData.value) && Array.isArray(innerData.prevValue)) {
|
|
231
|
-
const diff = computeArrayDiff(innerData.prevValue, innerData.value);
|
|
232
|
-
if (diff) {
|
|
233
|
-
// Replace full arrays with diff
|
|
234
|
-
const diffData = {
|
|
235
|
-
key: innerData.key
|
|
236
|
-
};
|
|
237
|
-
if (diff.added.length > 0) {
|
|
238
|
-
diffData.added = diff.added;
|
|
239
|
-
}
|
|
240
|
-
if (diff.removed.length > 0) {
|
|
241
|
-
diffData.removed = diff.removed;
|
|
242
|
-
}
|
|
243
|
-
if (diff.unchanged > 0) {
|
|
244
|
-
diffData.unchangedCount = diff.unchanged;
|
|
245
|
-
}
|
|
246
|
-
result.data = diffData;
|
|
247
|
-
return result;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
result.data = innerData;
|
|
251
|
-
}
|
|
252
|
-
return result;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Format Redux event data - filter to only changed slices
|
|
257
|
-
*/
|
|
258
|
-
function formatReduxData(data, settings) {
|
|
259
|
-
if (!settings.reduxChangedOnly) {
|
|
260
|
-
return settings.smartJsonParsing ? deepParseJsonStrings(data) : data;
|
|
261
|
-
}
|
|
262
|
-
const result = {};
|
|
263
|
-
|
|
264
|
-
// Always include action info
|
|
265
|
-
if (data.type) result.type = data.type;
|
|
266
|
-
if (data.payload) result.payload = settings.smartJsonParsing ? deepParseJsonStrings(data.payload) : data.payload;
|
|
267
|
-
if (data.sliceName) result.sliceName = data.sliceName;
|
|
268
|
-
if (data.actionName) result.actionName = data.actionName;
|
|
269
|
-
if (data.duration) result.duration = data.duration;
|
|
270
|
-
|
|
271
|
-
// Include state change info
|
|
272
|
-
if (data.hasStateChange !== undefined) result.hasStateChange = data.hasStateChange;
|
|
273
|
-
if (data.diffSummary) result.diffSummary = data.diffSummary;
|
|
274
|
-
if (data.changedKeysCount !== undefined) result.changedKeysCount = data.changedKeysCount;
|
|
275
|
-
|
|
276
|
-
// Only include state if there were changes
|
|
277
|
-
if (data.hasStateChange === true) {
|
|
278
|
-
// Try to extract only the changed slice
|
|
279
|
-
const sliceName = data.sliceName;
|
|
280
|
-
if (sliceName && data.prevState && data.nextState) {
|
|
281
|
-
const prevState = data.prevState;
|
|
282
|
-
const nextState = data.nextState;
|
|
283
|
-
if (prevState[sliceName] !== undefined || nextState[sliceName] !== undefined) {
|
|
284
|
-
result.stateChange = {
|
|
285
|
-
slice: sliceName,
|
|
286
|
-
before: prevState[sliceName],
|
|
287
|
-
after: nextState[sliceName]
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Get item identifier (name, id, or key) from an object
|
|
297
|
-
*/
|
|
298
|
-
function getItemIdentifier(item) {
|
|
299
|
-
if (typeof item !== "object" || item === null) return null;
|
|
300
|
-
const obj = item;
|
|
301
|
-
if (typeof obj.name === "string") return obj.name;
|
|
302
|
-
if (typeof obj.id === "string") return obj.id;
|
|
303
|
-
if (typeof obj.key === "string") return obj.key;
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Generate a simple diff summary for storage values
|
|
309
|
-
*/
|
|
310
|
-
function generateStorageDiffSummary(prevValue, newValue) {
|
|
311
|
-
// Parse if strings
|
|
312
|
-
const prev = typeof prevValue === "string" ? tryParseJson(prevValue) : prevValue;
|
|
313
|
-
const next = typeof newValue === "string" ? tryParseJson(newValue) : newValue;
|
|
314
|
-
|
|
315
|
-
// Handle null/undefined cases
|
|
316
|
-
if ((prev === null || prev === undefined) && next !== null && next !== undefined) return "Created";
|
|
317
|
-
if (prev !== null && prev !== undefined && (next === null || next === undefined)) return "Deleted";
|
|
318
|
-
|
|
319
|
-
// Handle arrays (common for cart-like data)
|
|
320
|
-
if (Array.isArray(prev) && Array.isArray(next)) {
|
|
321
|
-
const prevLen = prev.length;
|
|
322
|
-
const nextLen = next.length;
|
|
323
|
-
|
|
324
|
-
// Get identifiers for comparison
|
|
325
|
-
const prevIds = prev.map(getItemIdentifier).filter(Boolean);
|
|
326
|
-
const nextIds = next.map(getItemIdentifier).filter(Boolean);
|
|
327
|
-
|
|
328
|
-
// Check if items were replaced (same count but different items)
|
|
329
|
-
if (prevLen === nextLen && prevLen > 0) {
|
|
330
|
-
const prevSet = new Set(prevIds);
|
|
331
|
-
const nextSet = new Set(nextIds);
|
|
332
|
-
const kept = prevIds.filter(id => nextSet.has(id));
|
|
333
|
-
if (kept.length === 0 && prevIds.length > 0 && nextIds.length > 0) {
|
|
334
|
-
// Complete replacement!
|
|
335
|
-
return `⚠️ Replaced: [${prevIds.join(", ")}] → [${nextIds.join(", ")}]`;
|
|
336
|
-
}
|
|
337
|
-
if (kept.length < prevLen) {
|
|
338
|
-
const removed = prevIds.filter(id => !nextSet.has(id));
|
|
339
|
-
const added = nextIds.filter(id => !prevSet.has(id));
|
|
340
|
-
return `Changed: -${removed.join(", ")} +${added.join(", ")}`;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
if (prevLen === 0 && nextLen > 0) {
|
|
344
|
-
if (nextIds.length > 0) {
|
|
345
|
-
return `Added: [${nextIds.join(", ")}]`;
|
|
346
|
-
}
|
|
347
|
-
return `Added ${nextLen} item${nextLen > 1 ? "s" : ""}`;
|
|
348
|
-
}
|
|
349
|
-
if (prevLen > 0 && nextLen === 0) {
|
|
350
|
-
if (prevIds.length > 0) {
|
|
351
|
-
return `Removed all: [${prevIds.join(", ")}]`;
|
|
352
|
-
}
|
|
353
|
-
return `Removed all ${prevLen} item${prevLen > 1 ? "s" : ""}`;
|
|
354
|
-
}
|
|
355
|
-
if (nextLen > prevLen) {
|
|
356
|
-
const prevSet = new Set(prevIds);
|
|
357
|
-
const added = nextIds.filter(id => !prevSet.has(id));
|
|
358
|
-
if (added.length > 0) {
|
|
359
|
-
return `Added: [${added.join(", ")}] (${prevLen} → ${nextLen})`;
|
|
360
|
-
}
|
|
361
|
-
return `Added ${nextLen - prevLen} item${nextLen - prevLen > 1 ? "s" : ""} (${prevLen} → ${nextLen})`;
|
|
362
|
-
}
|
|
363
|
-
if (nextLen < prevLen) {
|
|
364
|
-
const nextSet = new Set(nextIds);
|
|
365
|
-
const removed = prevIds.filter(id => !nextSet.has(id));
|
|
366
|
-
if (removed.length > 0) {
|
|
367
|
-
return `Removed: [${removed.join(", ")}] (${prevLen} → ${nextLen})`;
|
|
368
|
-
}
|
|
369
|
-
return `Removed ${prevLen - nextLen} item${prevLen - nextLen > 1 ? "s" : ""} (${prevLen} → ${nextLen})`;
|
|
370
|
-
}
|
|
371
|
-
return `Updated (${nextLen} item${nextLen > 1 ? "s" : ""})`;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// Handle objects
|
|
375
|
-
if (typeof prev === "object" && typeof next === "object" && prev && next) {
|
|
376
|
-
const prevKeys = Object.keys(prev);
|
|
377
|
-
const nextKeys = Object.keys(next);
|
|
378
|
-
const addedKeys = nextKeys.filter(k => !prevKeys.includes(k));
|
|
379
|
-
const removedKeys = prevKeys.filter(k => !nextKeys.includes(k));
|
|
380
|
-
if (addedKeys.length > 0 && removedKeys.length > 0) {
|
|
381
|
-
return `+${addedKeys.length} -${removedKeys.length} keys`;
|
|
382
|
-
}
|
|
383
|
-
if (addedKeys.length > 0) return `Added: ${addedKeys.join(", ")}`;
|
|
384
|
-
if (removedKeys.length > 0) return `Removed: ${removedKeys.join(", ")}`;
|
|
385
|
-
return "Updated";
|
|
386
|
-
}
|
|
387
|
-
return null;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Format React Query event data - remove verbose internal state
|
|
392
|
-
*/
|
|
393
|
-
function formatReactQueryData(data, settings) {
|
|
394
|
-
const result = {};
|
|
395
|
-
|
|
396
|
-
// Core identifiers
|
|
397
|
-
if (data.id) result.id = data.id;
|
|
398
|
-
if (data.type) result.type = data.type;
|
|
399
|
-
if (data.timestamp) result.timestamp = data.timestamp;
|
|
400
|
-
|
|
401
|
-
// Query-specific fields
|
|
402
|
-
if (data.queryKey) result.queryKey = data.queryKey;
|
|
403
|
-
if (data.mutationKey) result.mutationKey = data.mutationKey;
|
|
404
|
-
if (data.mutationId) result.mutationId = data.mutationId;
|
|
405
|
-
if (data.duration) result.duration = data.duration;
|
|
406
|
-
|
|
407
|
-
// For success events, include the data (not duplicated)
|
|
408
|
-
if (data.queryData !== undefined) {
|
|
409
|
-
result.data = settings.smartJsonParsing ? deepParseJsonStrings(data.queryData) : data.queryData;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// For mutation events, include variables
|
|
413
|
-
if (data.variables !== undefined) {
|
|
414
|
-
result.variables = settings.smartJsonParsing ? deepParseJsonStrings(data.variables) : data.variables;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// For errors, include error info (try to extract message)
|
|
418
|
-
if (data.queryError !== undefined) {
|
|
419
|
-
const error = data.queryError;
|
|
420
|
-
if (error && typeof error === "object") {
|
|
421
|
-
result.error = error.message || error.name || error;
|
|
422
|
-
} else {
|
|
423
|
-
result.error = data.queryError;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
if (data.mutationError !== undefined) {
|
|
427
|
-
const error = data.mutationError;
|
|
428
|
-
if (error && typeof error === "object") {
|
|
429
|
-
result.error = error.message || error.name || error;
|
|
430
|
-
} else {
|
|
431
|
-
result.error = data.mutationError;
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// Include status from query/mutation state if available
|
|
436
|
-
if (data.query && typeof data.query === "object") {
|
|
437
|
-
const query = data.query;
|
|
438
|
-
if (query.state && typeof query.state === "object") {
|
|
439
|
-
const state = query.state;
|
|
440
|
-
if (state.status) result.status = state.status;
|
|
441
|
-
if (state.fetchStatus) result.fetchStatus = state.fetchStatus;
|
|
442
|
-
if (state.error) {
|
|
443
|
-
const stateError = state.error;
|
|
444
|
-
if (stateError && typeof stateError === "object") {
|
|
445
|
-
result.error = stateError.message || stateError.name || stateError;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (data.mutation && typeof data.mutation === "object") {
|
|
451
|
-
const mutation = data.mutation;
|
|
452
|
-
if (mutation.state && typeof mutation.state === "object") {
|
|
453
|
-
const state = mutation.state;
|
|
454
|
-
if (state.status) result.status = state.status;
|
|
455
|
-
if (state.failureCount) result.failureCount = state.failureCount;
|
|
456
|
-
if (state.error) {
|
|
457
|
-
const stateError = state.error;
|
|
458
|
-
if (stateError && typeof stateError === "object") {
|
|
459
|
-
result.error = stateError.message || stateError.name || stateError;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if (state.failureReason) {
|
|
463
|
-
const reason = state.failureReason;
|
|
464
|
-
if (reason && typeof reason === "object") {
|
|
465
|
-
result.failureReason = reason.message || reason.name || reason;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
return result;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Format event data based on source type and settings
|
|
475
|
-
*/
|
|
476
|
-
function formatEventData(event, settings) {
|
|
477
|
-
const data = event.originalEvent;
|
|
478
|
-
if (!data) return null;
|
|
479
|
-
let result;
|
|
480
|
-
|
|
481
|
-
// Storage events
|
|
482
|
-
if (event.source === "storage-async" || event.source === "storage-mmkv") {
|
|
483
|
-
result = formatStorageData(data, settings);
|
|
484
|
-
}
|
|
485
|
-
// Redux events
|
|
486
|
-
else if (event.source === "redux") {
|
|
487
|
-
result = formatReduxData(data, settings);
|
|
488
|
-
}
|
|
489
|
-
// React Query events
|
|
490
|
-
else if (event.source === "react-query" || event.source === "react-query-query" || event.source === "react-query-mutation") {
|
|
491
|
-
result = formatReactQueryData(data, settings);
|
|
492
|
-
}
|
|
493
|
-
// Other events - just apply smart parsing
|
|
494
|
-
else if (settings.smartJsonParsing) {
|
|
495
|
-
result = deepParseJsonStrings(data);
|
|
496
|
-
} else {
|
|
497
|
-
result = data;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Strip verbose fields if enabled
|
|
501
|
-
if (settings.stripVerboseFields && result) {
|
|
502
|
-
result = stripVerboseFieldsFromObject(result);
|
|
503
|
-
}
|
|
504
|
-
return result;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Get summary statistics for events
|
|
509
|
-
*/
|
|
510
|
-
function getExportSummary(events) {
|
|
511
|
-
const summary = {
|
|
512
|
-
totalEvents: events.length,
|
|
513
|
-
success: 0,
|
|
514
|
-
pending: 0,
|
|
515
|
-
error: 0,
|
|
516
|
-
neutral: 0,
|
|
517
|
-
durationMs: 0,
|
|
518
|
-
sources: new Set()
|
|
519
|
-
};
|
|
520
|
-
if (events.length === 0) return summary;
|
|
521
|
-
let minTimestamp = Infinity;
|
|
522
|
-
let maxTimestamp = -Infinity;
|
|
523
|
-
for (const event of events) {
|
|
524
|
-
// Count by status
|
|
525
|
-
summary[event.status]++;
|
|
526
|
-
|
|
527
|
-
// Track sources
|
|
528
|
-
summary.sources.add(event.source);
|
|
529
|
-
|
|
530
|
-
// Track time range
|
|
531
|
-
if (event.timestamp < minTimestamp) minTimestamp = event.timestamp;
|
|
532
|
-
if (event.timestamp > maxTimestamp) maxTimestamp = event.timestamp;
|
|
533
|
-
}
|
|
534
|
-
summary.durationMs = maxTimestamp - minTimestamp;
|
|
535
|
-
return summary;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Filter events based on settings
|
|
540
|
-
*/
|
|
541
|
-
function filterEvents(events, settings) {
|
|
542
|
-
let filtered = [...events];
|
|
543
|
-
|
|
544
|
-
// Filter by status
|
|
545
|
-
if (settings.filterMode !== "all") {
|
|
546
|
-
filtered = filtered.filter(event => {
|
|
547
|
-
switch (settings.filterMode) {
|
|
548
|
-
case "errors":
|
|
549
|
-
return event.status === "error";
|
|
550
|
-
case "success":
|
|
551
|
-
return event.status === "success";
|
|
552
|
-
case "pending":
|
|
553
|
-
return event.status === "pending";
|
|
554
|
-
default:
|
|
555
|
-
return true;
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// Filter by sources
|
|
561
|
-
if (settings.filterSources.length > 0) {
|
|
562
|
-
const sourceSet = new Set(settings.filterSources);
|
|
563
|
-
filtered = filtered.filter(event => sourceSet.has(event.source));
|
|
564
|
-
}
|
|
565
|
-
return filtered;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Format relative timestamp
|
|
570
|
-
*/
|
|
571
|
-
function formatRelativeTime(ms) {
|
|
572
|
-
if (ms < 1000) return `+${ms}ms`;
|
|
573
|
-
if (ms < 60000) return `+${(ms / 1000).toFixed(1)}s`;
|
|
574
|
-
return `+${(ms / 60000).toFixed(1)}m`;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Format absolute timestamp
|
|
579
|
-
*/
|
|
580
|
-
function formatAbsoluteTime(timestamp) {
|
|
581
|
-
const date = new Date(timestamp);
|
|
582
|
-
return date.toISOString();
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
* Format timestamp based on settings
|
|
587
|
-
*/
|
|
588
|
-
function formatTimestamp(timestamp, baseTimestamp, format) {
|
|
589
|
-
const relative = formatRelativeTime(timestamp - baseTimestamp);
|
|
590
|
-
const absolute = formatAbsoluteTime(timestamp);
|
|
591
|
-
switch (format) {
|
|
592
|
-
case "relative":
|
|
593
|
-
return relative;
|
|
594
|
-
case "absolute":
|
|
595
|
-
return absolute;
|
|
596
|
-
case "both":
|
|
597
|
-
return `${relative} (${absolute})`;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Early-aborting JSON-size probe: approximate byte count, bailing as soon as
|
|
603
|
-
* `limit` is exceeded — O(limit), never O(payload). Measuring with
|
|
604
|
-
* JSON.stringify(data).length meant enforcing a 5KB cap could serialize a
|
|
605
|
-
* 190MB state tree first, blocking the JS thread for seconds per event.
|
|
606
|
-
*/
|
|
607
|
-
function approxJsonBytesOver(value, limit) {
|
|
608
|
-
let bytes = 0;
|
|
609
|
-
const stack = [value];
|
|
610
|
-
const seen = new Set();
|
|
611
|
-
while (stack.length > 0) {
|
|
612
|
-
if (bytes > limit) return {
|
|
613
|
-
over: true,
|
|
614
|
-
approxBytes: bytes
|
|
615
|
-
};
|
|
616
|
-
const v = stack.pop();
|
|
617
|
-
if (v === null || v === undefined) bytes += 4;else if (typeof v === "string") bytes += v.length + 2;else if (typeof v === "number") bytes += 8;else if (typeof v === "boolean") bytes += 5;else if (typeof v === "object") {
|
|
618
|
-
if (seen.has(v)) continue;
|
|
619
|
-
seen.add(v);
|
|
620
|
-
if (Array.isArray(v)) {
|
|
621
|
-
bytes += 2 + v.length;
|
|
622
|
-
for (let i = 0; i < v.length; i++) stack.push(v[i]);
|
|
623
|
-
} else {
|
|
624
|
-
bytes += 2;
|
|
625
|
-
for (const k in v) {
|
|
626
|
-
bytes += k.length + 4;
|
|
627
|
-
stack.push(v[k]);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
} else bytes += 4;
|
|
631
|
-
}
|
|
632
|
-
return {
|
|
633
|
-
over: bytes > limit,
|
|
634
|
-
approxBytes: bytes
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Truncate data based on size threshold
|
|
640
|
-
*/
|
|
641
|
-
function truncateData(data, thresholdKB) {
|
|
642
|
-
if (thresholdKB === -1) {
|
|
643
|
-
return {
|
|
644
|
-
data,
|
|
645
|
-
truncated: false
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
// Cheap probe first — never serialize a payload just to learn it's huge.
|
|
650
|
-
const {
|
|
651
|
-
over,
|
|
652
|
-
approxBytes
|
|
653
|
-
} = approxJsonBytesOver(data, thresholdKB * 1024);
|
|
654
|
-
if (over) {
|
|
655
|
-
return {
|
|
656
|
-
data: `[Data truncated - ≥${(approxBytes / 1024).toFixed(1)}KB exceeds ${thresholdKB}KB limit]`,
|
|
657
|
-
truncated: true
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
try {
|
|
661
|
-
// Under the cap: a real stringify is bounded by the threshold and also
|
|
662
|
-
// validates serializability (cycles etc.).
|
|
663
|
-
JSON.stringify(data);
|
|
664
|
-
return {
|
|
665
|
-
data,
|
|
666
|
-
truncated: false
|
|
667
|
-
};
|
|
668
|
-
} catch {
|
|
669
|
-
return {
|
|
670
|
-
data: "[Unable to serialize data]",
|
|
671
|
-
truncated: true
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
/**
|
|
677
|
-
* Estimate export size in bytes
|
|
678
|
-
*/
|
|
679
|
-
function estimateExportSize(events, settings) {
|
|
680
|
-
let size = 0;
|
|
681
|
-
for (const event of events) {
|
|
682
|
-
// Basic event info
|
|
683
|
-
if (settings.includeSource) size += 20;
|
|
684
|
-
if (settings.includeStatus) size += 10;
|
|
685
|
-
if (settings.includeTitle) size += (event.title?.length || 0) + 10;
|
|
686
|
-
if (settings.includeSubtitle) size += (event.subtitle?.length || 0) + 10;
|
|
687
|
-
if (settings.includeCorrelation) size += 20;
|
|
688
|
-
if (settings.includeDuration) size += 15;
|
|
689
|
-
size += 30; // Timestamp
|
|
690
|
-
|
|
691
|
-
// Event data — probe with an early-abort cap instead of fully
|
|
692
|
-
// serializing (an estimate never justifies an O(payload) stringify).
|
|
693
|
-
if (settings.includeEventData && event.originalEvent) {
|
|
694
|
-
const cap = settings.dataSizeThreshold === -1 ? 1024 * 1024 // no threshold: cap the ESTIMATE at 1MB per event
|
|
695
|
-
: settings.dataSizeThreshold * 1024;
|
|
696
|
-
const {
|
|
697
|
-
approxBytes
|
|
698
|
-
} = approxJsonBytesOver(event.originalEvent, cap);
|
|
699
|
-
size += Math.min(approxBytes, cap);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Summary header
|
|
704
|
-
if (settings.includeSummaryHeader) size += 100;
|
|
705
|
-
if (settings.includeTotalDuration) size += 50;
|
|
706
|
-
|
|
707
|
-
// Format overhead
|
|
708
|
-
if (settings.format === "markdown") size *= 1.2;
|
|
709
|
-
if (settings.format === "json") size *= 1.3;
|
|
710
|
-
return Math.round(size);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Generate a compact one-liner for an event
|
|
715
|
-
*/
|
|
716
|
-
function formatCompactEvent(event, baseTimestamp, settings) {
|
|
717
|
-
const parts = [];
|
|
718
|
-
|
|
719
|
-
// Timestamp
|
|
720
|
-
const timestamp = formatTimestamp(event.timestamp, baseTimestamp, settings.timestampFormat);
|
|
721
|
-
parts.push(`\`${timestamp}\``);
|
|
722
|
-
|
|
723
|
-
// Status icon
|
|
724
|
-
if (settings.includeStatus) {
|
|
725
|
-
parts.push(STATUS_ICONS[event.status]);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
// Source
|
|
729
|
-
if (settings.includeSource) {
|
|
730
|
-
parts.push(`**${SOURCE_LABELS[event.source]}**`);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
// Title
|
|
734
|
-
if (settings.includeTitle) {
|
|
735
|
-
parts.push(event.title);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// For storage events, add a brief summary
|
|
739
|
-
if (settings.showStorageDiff && (event.source === "storage-async" || event.source === "storage-mmkv")) {
|
|
740
|
-
const data = event.originalEvent;
|
|
741
|
-
if (data?.data) {
|
|
742
|
-
const innerData = data.data;
|
|
743
|
-
const diff = generateStorageDiffSummary(innerData.prevValue, innerData.value);
|
|
744
|
-
if (diff) {
|
|
745
|
-
parts.push(`→ ${diff}`);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// For Redux, show if there was a state change
|
|
751
|
-
if (event.source === "redux") {
|
|
752
|
-
const data = event.originalEvent;
|
|
753
|
-
if (data?.hasStateChange === false) {
|
|
754
|
-
parts.push("(no state change)");
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
// Subtitle as brief context
|
|
759
|
-
if (settings.includeSubtitle && event.subtitle) {
|
|
760
|
-
parts.push(`- ${event.subtitle}`);
|
|
761
|
-
}
|
|
762
|
-
return parts.join(" ");
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
/**
|
|
766
|
-
* Generate storage diff block for markdown
|
|
767
|
-
*/
|
|
768
|
-
function generateStorageDiffBlock(event, settings) {
|
|
769
|
-
const lines = [];
|
|
770
|
-
const data = event.originalEvent;
|
|
771
|
-
if (!data?.data) return lines;
|
|
772
|
-
const innerData = data.data;
|
|
773
|
-
const prevValue = settings.smartJsonParsing ? tryParseJson(innerData.prevValue) : innerData.prevValue;
|
|
774
|
-
const newValue = settings.smartJsonParsing ? tryParseJson(innerData.value) : innerData.value;
|
|
775
|
-
|
|
776
|
-
// Generate diff summary
|
|
777
|
-
const diffSummary = generateStorageDiffSummary(innerData.prevValue, innerData.value);
|
|
778
|
-
if (diffSummary) {
|
|
779
|
-
lines.push(` **Change:** ${diffSummary}`);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// Show before/after for arrays
|
|
783
|
-
if (Array.isArray(prevValue) && Array.isArray(newValue)) {
|
|
784
|
-
// Show item names if available
|
|
785
|
-
const prevNames = prevValue.map(item => {
|
|
786
|
-
if (typeof item === "object" && item && "name" in item) return item.name;
|
|
787
|
-
return null;
|
|
788
|
-
}).filter(Boolean);
|
|
789
|
-
const newNames = newValue.map(item => {
|
|
790
|
-
if (typeof item === "object" && item && "name" in item) return item.name;
|
|
791
|
-
return null;
|
|
792
|
-
}).filter(Boolean);
|
|
793
|
-
if (prevNames.length > 0 || newNames.length > 0) {
|
|
794
|
-
if (prevNames.length > 0) {
|
|
795
|
-
lines.push(` Before: [${prevNames.join(", ")}]`);
|
|
796
|
-
}
|
|
797
|
-
lines.push(` After: [${newNames.join(", ")}]`);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
return lines;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Generate Markdown export
|
|
805
|
-
*/
|
|
806
|
-
function generateMarkdownExport(events, settings) {
|
|
807
|
-
const filtered = filterEvents(events, settings);
|
|
808
|
-
if (filtered.length === 0) return "No events to export.";
|
|
809
|
-
|
|
810
|
-
// Sort by timestamp (oldest first for timeline)
|
|
811
|
-
const sorted = [...filtered].sort((a, b) => a.timestamp - b.timestamp);
|
|
812
|
-
const baseTimestamp = sorted[0].timestamp;
|
|
813
|
-
const summary = getExportSummary(sorted);
|
|
814
|
-
const lines = [];
|
|
815
|
-
|
|
816
|
-
// Header
|
|
817
|
-
lines.push("## Event Flow");
|
|
818
|
-
|
|
819
|
-
// Summary line
|
|
820
|
-
if (settings.includeSummaryHeader || settings.includeTotalDuration) {
|
|
821
|
-
const parts = [];
|
|
822
|
-
if (settings.includeTotalDuration) {
|
|
823
|
-
parts.push(`**Duration:** ${formatRelativeTime(summary.durationMs).replace("+", "")}`);
|
|
824
|
-
}
|
|
825
|
-
parts.push(`**Events:** ${summary.totalEvents}`);
|
|
826
|
-
if (settings.includeSummaryHeader) {
|
|
827
|
-
const statusParts = [];
|
|
828
|
-
if (summary.success > 0) statusParts.push(`${summary.success} ${STATUS_ICONS.success}`);
|
|
829
|
-
if (summary.pending > 0) statusParts.push(`${summary.pending} ${STATUS_ICONS.pending}`);
|
|
830
|
-
if (summary.error > 0) statusParts.push(`${summary.error} ${STATUS_ICONS.error}`);
|
|
831
|
-
if (summary.neutral > 0) statusParts.push(`${summary.neutral} ${STATUS_ICONS.neutral}`);
|
|
832
|
-
if (statusParts.length > 0) {
|
|
833
|
-
parts.push(`**Status:** ${statusParts.join(" ")}`);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
lines.push(parts.join(" | "));
|
|
837
|
-
}
|
|
838
|
-
lines.push("");
|
|
839
|
-
lines.push("### Timeline");
|
|
840
|
-
lines.push("");
|
|
841
|
-
|
|
842
|
-
// Compact mode: one line per event
|
|
843
|
-
if (settings.compactMode) {
|
|
844
|
-
sorted.forEach((event, index) => {
|
|
845
|
-
lines.push(`${index + 1}. ${formatCompactEvent(event, baseTimestamp, settings)}`);
|
|
846
|
-
});
|
|
847
|
-
return lines.join("\n");
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
// Full mode: detailed events
|
|
851
|
-
sorted.forEach((event, index) => {
|
|
852
|
-
const parts = [];
|
|
853
|
-
|
|
854
|
-
// Line number and timestamp
|
|
855
|
-
const timestamp = formatTimestamp(event.timestamp, baseTimestamp, settings.timestampFormat);
|
|
856
|
-
parts.push(`${index + 1}. \`${timestamp}\``);
|
|
857
|
-
|
|
858
|
-
// Status icon
|
|
859
|
-
if (settings.includeStatus) {
|
|
860
|
-
parts.push(STATUS_ICONS[event.status]);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
// Source
|
|
864
|
-
if (settings.includeSource) {
|
|
865
|
-
parts.push(`**${SOURCE_LABELS[event.source]}**`);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
// Title
|
|
869
|
-
if (settings.includeTitle) {
|
|
870
|
-
parts.push(event.title);
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
// Correlation
|
|
874
|
-
if (settings.includeCorrelation && event.correlationId && event.sequenceInGroup) {
|
|
875
|
-
parts.push(`(${event.sequenceInGroup})`);
|
|
876
|
-
}
|
|
877
|
-
lines.push(parts.join(" "));
|
|
878
|
-
|
|
879
|
-
// Subtitle on next line
|
|
880
|
-
if (settings.includeSubtitle && event.subtitle) {
|
|
881
|
-
lines.push(` \u2514\u2500 ${event.subtitle}`);
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// Storage diff summary (if enabled and no full data)
|
|
885
|
-
if (settings.showStorageDiff && !settings.includeEventData) {
|
|
886
|
-
if (event.source === "storage-async" || event.source === "storage-mmkv") {
|
|
887
|
-
const diffLines = generateStorageDiffBlock(event, settings);
|
|
888
|
-
lines.push(...diffLines);
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
// Event data (formatted with smart parsing)
|
|
893
|
-
if (settings.includeEventData && event.originalEvent) {
|
|
894
|
-
// Use smart formatting
|
|
895
|
-
const formattedData = formatEventData(event, settings);
|
|
896
|
-
const {
|
|
897
|
-
data,
|
|
898
|
-
truncated
|
|
899
|
-
} = truncateData(formattedData, settings.dataSizeThreshold);
|
|
900
|
-
if (truncated) {
|
|
901
|
-
lines.push(` \u2514\u2500 ${data}`);
|
|
902
|
-
} else {
|
|
903
|
-
// Add storage diff annotation before the JSON block
|
|
904
|
-
if (settings.showStorageDiff && (event.source === "storage-async" || event.source === "storage-mmkv")) {
|
|
905
|
-
const originalData = event.originalEvent;
|
|
906
|
-
if (originalData?.data) {
|
|
907
|
-
const innerData = originalData.data;
|
|
908
|
-
const diffSummary = generateStorageDiffSummary(innerData.prevValue, innerData.value);
|
|
909
|
-
if (diffSummary) {
|
|
910
|
-
lines.push(` **Change:** ${diffSummary}`);
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
lines.push(" ```json");
|
|
915
|
-
lines.push(` ${JSON.stringify(data, null, 2).split("\n").join("\n ")}`);
|
|
916
|
-
lines.push(" ```");
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
lines.push("");
|
|
920
|
-
});
|
|
921
|
-
|
|
922
|
-
// Error details section
|
|
923
|
-
const errors = sorted.filter(e => e.status === "error");
|
|
924
|
-
if (errors.length > 0 && settings.includeEventData) {
|
|
925
|
-
lines.push("---");
|
|
926
|
-
lines.push("");
|
|
927
|
-
lines.push("### Errors");
|
|
928
|
-
lines.push("");
|
|
929
|
-
for (const error of errors) {
|
|
930
|
-
const timestamp = formatTimestamp(error.timestamp, baseTimestamp, settings.timestampFormat);
|
|
931
|
-
lines.push(`**${error.title}** (${timestamp})`);
|
|
932
|
-
if (error.originalEvent) {
|
|
933
|
-
const formattedData = formatEventData(error, settings);
|
|
934
|
-
const {
|
|
935
|
-
data,
|
|
936
|
-
truncated
|
|
937
|
-
} = truncateData(formattedData, settings.dataSizeThreshold);
|
|
938
|
-
if (!truncated) {
|
|
939
|
-
lines.push("```json");
|
|
940
|
-
lines.push(JSON.stringify(data, null, 2));
|
|
941
|
-
lines.push("```");
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
lines.push("");
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
return lines.join("\n");
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* Generate JSON export
|
|
952
|
-
*/
|
|
953
|
-
function generateJsonExport(events, settings) {
|
|
954
|
-
const filtered = filterEvents(events, settings);
|
|
955
|
-
if (filtered.length === 0) return "[]";
|
|
956
|
-
|
|
957
|
-
// Sort by timestamp (oldest first)
|
|
958
|
-
const sorted = [...filtered].sort((a, b) => a.timestamp - b.timestamp);
|
|
959
|
-
const baseTimestamp = sorted[0].timestamp;
|
|
960
|
-
const summary = getExportSummary(sorted);
|
|
961
|
-
const exportData = {
|
|
962
|
-
exportedAt: new Date().toISOString()
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
// Summary
|
|
966
|
-
if (settings.includeSummaryHeader) {
|
|
967
|
-
exportData.summary = {
|
|
968
|
-
totalEvents: summary.totalEvents,
|
|
969
|
-
success: summary.success,
|
|
970
|
-
pending: summary.pending,
|
|
971
|
-
error: summary.error,
|
|
972
|
-
neutral: summary.neutral,
|
|
973
|
-
durationMs: summary.durationMs,
|
|
974
|
-
sources: Array.from(summary.sources)
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// Events
|
|
979
|
-
exportData.events = sorted.map(event => {
|
|
980
|
-
const eventData = {};
|
|
981
|
-
|
|
982
|
-
// Timestamp
|
|
983
|
-
eventData.timestamp = formatAbsoluteTime(event.timestamp);
|
|
984
|
-
if (settings.timestampFormat === "relative" || settings.timestampFormat === "both") {
|
|
985
|
-
eventData.relativeMs = event.timestamp - baseTimestamp;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
// Event info
|
|
989
|
-
if (settings.includeSource) eventData.source = event.source;
|
|
990
|
-
if (settings.includeStatus) eventData.status = event.status;
|
|
991
|
-
if (settings.includeTitle) eventData.title = event.title;
|
|
992
|
-
if (settings.includeSubtitle) eventData.subtitle = event.subtitle;
|
|
993
|
-
if (settings.includeCorrelation && event.correlationId) {
|
|
994
|
-
eventData.correlationId = event.correlationId;
|
|
995
|
-
eventData.sequenceInGroup = event.sequenceInGroup;
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
// Event data (with smart formatting)
|
|
999
|
-
if (settings.includeEventData && event.originalEvent) {
|
|
1000
|
-
const formattedData = formatEventData(event, settings);
|
|
1001
|
-
const {
|
|
1002
|
-
data,
|
|
1003
|
-
truncated
|
|
1004
|
-
} = truncateData(formattedData, settings.dataSizeThreshold);
|
|
1005
|
-
eventData.data = data;
|
|
1006
|
-
if (truncated) eventData.dataTruncated = true;
|
|
1007
|
-
|
|
1008
|
-
// Add diff summary for storage events
|
|
1009
|
-
if (settings.showStorageDiff && (event.source === "storage-async" || event.source === "storage-mmkv")) {
|
|
1010
|
-
const originalData = event.originalEvent;
|
|
1011
|
-
if (originalData?.data) {
|
|
1012
|
-
const innerData = originalData.data;
|
|
1013
|
-
const diffSummary = generateStorageDiffSummary(innerData.prevValue, innerData.value);
|
|
1014
|
-
if (diffSummary) {
|
|
1015
|
-
eventData.changeSummary = diffSummary;
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
return eventData;
|
|
1021
|
-
});
|
|
1022
|
-
return JSON.stringify(exportData, null, 2);
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* Generate plaintext export
|
|
1027
|
-
*/
|
|
1028
|
-
function generatePlaintextExport(events, settings) {
|
|
1029
|
-
const filtered = filterEvents(events, settings);
|
|
1030
|
-
if (filtered.length === 0) return "No events to export.";
|
|
1031
|
-
|
|
1032
|
-
// Sort by timestamp (oldest first)
|
|
1033
|
-
const sorted = [...filtered].sort((a, b) => a.timestamp - b.timestamp);
|
|
1034
|
-
const baseTimestamp = sorted[0].timestamp;
|
|
1035
|
-
const summary = getExportSummary(sorted);
|
|
1036
|
-
const lines = [];
|
|
1037
|
-
|
|
1038
|
-
// Header
|
|
1039
|
-
if (settings.includeSummaryHeader || settings.includeTotalDuration) {
|
|
1040
|
-
const parts = [`Event Flow (${summary.totalEvents} events`];
|
|
1041
|
-
if (settings.includeTotalDuration) {
|
|
1042
|
-
parts[0] += `, ${formatRelativeTime(summary.durationMs).replace("+", "")}`;
|
|
1043
|
-
}
|
|
1044
|
-
parts[0] += ")";
|
|
1045
|
-
lines.push(parts[0]);
|
|
1046
|
-
if (settings.includeSummaryHeader) {
|
|
1047
|
-
const statusParts = [];
|
|
1048
|
-
if (summary.success > 0) statusParts.push(`${summary.success} success`);
|
|
1049
|
-
if (summary.pending > 0) statusParts.push(`${summary.pending} pending`);
|
|
1050
|
-
if (summary.error > 0) statusParts.push(`${summary.error} error`);
|
|
1051
|
-
if (summary.neutral > 0) statusParts.push(`${summary.neutral} neutral`);
|
|
1052
|
-
if (statusParts.length > 0) {
|
|
1053
|
-
lines.push(statusParts.join(", "));
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
lines.push("");
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// Events
|
|
1060
|
-
for (const event of sorted) {
|
|
1061
|
-
const parts = [];
|
|
1062
|
-
|
|
1063
|
-
// Timestamp
|
|
1064
|
-
const timestamp = formatTimestamp(event.timestamp, baseTimestamp, settings.timestampFormat);
|
|
1065
|
-
parts.push(timestamp.padEnd(12));
|
|
1066
|
-
|
|
1067
|
-
// Status
|
|
1068
|
-
if (settings.includeStatus) {
|
|
1069
|
-
parts.push(STATUS_ICONS_ASCII[event.status]);
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
// Source
|
|
1073
|
-
if (settings.includeSource) {
|
|
1074
|
-
parts.push(`${SOURCE_LABELS[event.source]}:`);
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
// Title
|
|
1078
|
-
if (settings.includeTitle) {
|
|
1079
|
-
parts.push(event.title);
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
// For storage events, add diff summary
|
|
1083
|
-
if (settings.showStorageDiff && (event.source === "storage-async" || event.source === "storage-mmkv")) {
|
|
1084
|
-
const data = event.originalEvent;
|
|
1085
|
-
if (data?.data) {
|
|
1086
|
-
const innerData = data.data;
|
|
1087
|
-
const diff = generateStorageDiffSummary(innerData.prevValue, innerData.value);
|
|
1088
|
-
if (diff) {
|
|
1089
|
-
parts.push(`-> ${diff}`);
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
// For Redux, note if no state change
|
|
1095
|
-
if (event.source === "redux") {
|
|
1096
|
-
const data = event.originalEvent;
|
|
1097
|
-
if (data?.hasStateChange === false) {
|
|
1098
|
-
parts.push("(no change)");
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
// Subtitle
|
|
1103
|
-
if (settings.includeSubtitle && event.subtitle) {
|
|
1104
|
-
parts.push(`- ${event.subtitle}`);
|
|
1105
|
-
}
|
|
1106
|
-
lines.push(parts.join(" "));
|
|
1107
|
-
|
|
1108
|
-
// Event data (with smart formatting)
|
|
1109
|
-
if (settings.includeEventData && event.originalEvent) {
|
|
1110
|
-
const formattedData = formatEventData(event, settings);
|
|
1111
|
-
const {
|
|
1112
|
-
data,
|
|
1113
|
-
truncated
|
|
1114
|
-
} = truncateData(formattedData, settings.dataSizeThreshold);
|
|
1115
|
-
if (truncated) {
|
|
1116
|
-
lines.push(` ${data}`);
|
|
1117
|
-
} else {
|
|
1118
|
-
lines.push(` Data: ${JSON.stringify(data)}`);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return lines.join("\n");
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
// ============================================================================
|
|
1126
|
-
// MERMAID SEQUENCE DIAGRAM EXPORT
|
|
1127
|
-
// ============================================================================
|
|
1128
|
-
|
|
1129
|
-
/**
|
|
1130
|
-
* Participant configuration for Mermaid sequence diagrams
|
|
1131
|
-
*/
|
|
1132
|
-
|
|
1133
|
-
/**
|
|
1134
|
-
* Participant definitions - map event sources to diagram actors
|
|
1135
|
-
* Organized by client vs server for grouping
|
|
1136
|
-
* Note: Storage types are split for clarity
|
|
1137
|
-
*/
|
|
1138
|
-
const MERMAID_PARTICIPANTS = [
|
|
1139
|
-
// Client-side
|
|
1140
|
-
{
|
|
1141
|
-
id: "U",
|
|
1142
|
-
icon: "👤",
|
|
1143
|
-
label: "User",
|
|
1144
|
-
sources: [],
|
|
1145
|
-
group: "client"
|
|
1146
|
-
}, {
|
|
1147
|
-
id: "App",
|
|
1148
|
-
icon: "📱",
|
|
1149
|
-
label: "App",
|
|
1150
|
-
sources: ["route", "render"],
|
|
1151
|
-
group: "client"
|
|
1152
|
-
}, {
|
|
1153
|
-
id: "Async",
|
|
1154
|
-
icon: "💾",
|
|
1155
|
-
label: "AsyncStorage",
|
|
1156
|
-
sources: ["storage-async"],
|
|
1157
|
-
group: "client"
|
|
1158
|
-
}, {
|
|
1159
|
-
id: "MMKV",
|
|
1160
|
-
icon: "⚡",
|
|
1161
|
-
label: "MMKV",
|
|
1162
|
-
sources: ["storage-mmkv"],
|
|
1163
|
-
group: "client"
|
|
1164
|
-
}, {
|
|
1165
|
-
id: "Redux",
|
|
1166
|
-
icon: "🔄",
|
|
1167
|
-
label: "Redux",
|
|
1168
|
-
sources: ["redux"],
|
|
1169
|
-
group: "client"
|
|
1170
|
-
},
|
|
1171
|
-
// Server-side / External
|
|
1172
|
-
{
|
|
1173
|
-
id: "API",
|
|
1174
|
-
icon: "🌐",
|
|
1175
|
-
label: "API",
|
|
1176
|
-
sources: ["network"],
|
|
1177
|
-
group: "server"
|
|
1178
|
-
}, {
|
|
1179
|
-
id: "Cache",
|
|
1180
|
-
icon: "📦",
|
|
1181
|
-
label: "QueryCache",
|
|
1182
|
-
sources: ["react-query", "react-query-query", "react-query-mutation"],
|
|
1183
|
-
group: "server"
|
|
1184
|
-
}];
|
|
1185
|
-
|
|
1186
|
-
/**
|
|
1187
|
-
* Get the Mermaid participant ID for an event source
|
|
1188
|
-
*/
|
|
1189
|
-
function getParticipantId(source) {
|
|
1190
|
-
const participant = MERMAID_PARTICIPANTS.find(p => p.sources.includes(source));
|
|
1191
|
-
return participant?.id || "App";
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
/**
|
|
1195
|
-
* Detect which participants are needed based on events
|
|
1196
|
-
*/
|
|
1197
|
-
function detectParticipants(events) {
|
|
1198
|
-
const sourcesInUse = new Set();
|
|
1199
|
-
for (const event of events) {
|
|
1200
|
-
sourcesInUse.add(event.source);
|
|
1201
|
-
}
|
|
1202
|
-
const participants = [];
|
|
1203
|
-
|
|
1204
|
-
// Always include User and App
|
|
1205
|
-
participants.push(MERMAID_PARTICIPANTS[0]); // User
|
|
1206
|
-
participants.push(MERMAID_PARTICIPANTS[1]); // App
|
|
1207
|
-
|
|
1208
|
-
// Add other participants based on event sources present
|
|
1209
|
-
for (const participant of MERMAID_PARTICIPANTS.slice(2)) {
|
|
1210
|
-
if (participant.sources.some(s => sourcesInUse.has(s))) {
|
|
1211
|
-
participants.push(participant);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return participants;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
/**
|
|
1218
|
-
* Check if we should use participant grouping (boxes)
|
|
1219
|
-
*/
|
|
1220
|
-
function shouldUseGroups(participants) {
|
|
1221
|
-
const hasClient = participants.some(p => p.group === "client");
|
|
1222
|
-
const hasServer = participants.some(p => p.group === "server");
|
|
1223
|
-
return hasClient && hasServer && participants.length >= 3;
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
/**
|
|
1227
|
-
* Format duration for Mermaid notes
|
|
1228
|
-
*/
|
|
1229
|
-
function formatMermaidDuration(ms) {
|
|
1230
|
-
if (ms < 1000) return `${ms}ms`;
|
|
1231
|
-
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
|
|
1232
|
-
return `${(ms / 60000).toFixed(1)}m`;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
* Escape text for Mermaid (handle special characters)
|
|
1237
|
-
*/
|
|
1238
|
-
function escapeMermaidText(text) {
|
|
1239
|
-
return text.replace(/[#;:]/g, " ") // Remove characters with special meaning
|
|
1240
|
-
.replace(/[\n\r]/g, " ") // Replace newlines with spaces
|
|
1241
|
-
.replace(/"/g, "'") // Replace double quotes with single
|
|
1242
|
-
.replace(/\s+/g, " ") // Collapse multiple spaces
|
|
1243
|
-
.trim();
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
/**
|
|
1247
|
-
* Check if a storage key is internal/devtools tracking
|
|
1248
|
-
* Be conservative - only filter obvious internal keys
|
|
1249
|
-
*/
|
|
1250
|
-
function isInternalStorageKey(key) {
|
|
1251
|
-
const internalPatterns = ["last-route", "@dev/last", "__debug", "_persist", "devtools/internal"];
|
|
1252
|
-
const lowerKey = key.toLowerCase();
|
|
1253
|
-
return internalPatterns.some(p => lowerKey.includes(p));
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Format bytes to human readable size
|
|
1258
|
-
*/
|
|
1259
|
-
function formatBytes(bytes) {
|
|
1260
|
-
if (bytes < 1024) return `${bytes}B`;
|
|
1261
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
1262
|
-
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
/**
|
|
1266
|
-
* Estimate size of data in bytes (early-abort probe, capped at 1MB — a size
|
|
1267
|
-
* label never justifies an O(payload) stringify).
|
|
1268
|
-
*/
|
|
1269
|
-
function estimateDataSize(data) {
|
|
1270
|
-
return approxJsonBytesOver(data, 1024 * 1024).approxBytes;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
/**
|
|
1274
|
-
* Get canonical URL for duplicate detection (strip timestamps, debug params)
|
|
1275
|
-
*/
|
|
1276
|
-
function getCanonicalUrl(url) {
|
|
1277
|
-
try {
|
|
1278
|
-
const urlObj = new URL(url, "http://localhost");
|
|
1279
|
-
// Remove common cache-busting/debug params
|
|
1280
|
-
const paramsToRemove = ["timestamp", "t", "_t", "debug", "client", "version", "cache", "_"];
|
|
1281
|
-
paramsToRemove.forEach(p => urlObj.searchParams.delete(p));
|
|
1282
|
-
return urlObj.pathname + (urlObj.searchParams.toString() ? "?" + urlObj.searchParams.toString() : "");
|
|
1283
|
-
} catch {
|
|
1284
|
-
return url;
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
/**
|
|
1289
|
-
* Get a readable short name from a storage key
|
|
1290
|
-
*/
|
|
1291
|
-
function getStorageKeyName(key) {
|
|
1292
|
-
// Remove common prefixes
|
|
1293
|
-
let name = key.replace(/^@[\w-]+\//, "") // Remove @prefix/
|
|
1294
|
-
.replace(/^devtools\//, "").replace(/^dev\//, "").replace(/^buoy\//, "").replace(/^pokemon\//, ""); // Remove pokemon/ prefix for this app
|
|
1295
|
-
|
|
1296
|
-
// Get last meaningful segment
|
|
1297
|
-
const segments = name.split("/").filter(Boolean);
|
|
1298
|
-
if (segments.length > 1) {
|
|
1299
|
-
name = segments.slice(-1).join("/"); // Just the last segment
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
// Humanize common patterns
|
|
1303
|
-
name = name.replace(/-/g, " ").replace(/_/g, " ");
|
|
1304
|
-
|
|
1305
|
-
// Title case
|
|
1306
|
-
name = name.split(" ").map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
1307
|
-
|
|
1308
|
-
// Common renames for clarity
|
|
1309
|
-
if (name.toLowerCase() === "saved") name = "Favorites";
|
|
1310
|
-
return name.substring(0, 20);
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
/**
|
|
1314
|
-
* Extract entity name from URL path (e.g., /pokemon/charizard -> Charizard)
|
|
1315
|
-
*/
|
|
1316
|
-
function extractEntityFromPath(url) {
|
|
1317
|
-
// Strip query params first
|
|
1318
|
-
let path = url;
|
|
1319
|
-
try {
|
|
1320
|
-
const urlObj = new URL(url, "http://localhost");
|
|
1321
|
-
path = urlObj.pathname;
|
|
1322
|
-
} catch {
|
|
1323
|
-
// If URL parsing fails, try to strip query params manually
|
|
1324
|
-
const queryIndex = path.indexOf("?");
|
|
1325
|
-
if (queryIndex > 0) {
|
|
1326
|
-
path = path.substring(0, queryIndex);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
// Common patterns: /resource/:id, /resource/:name
|
|
1331
|
-
const segments = path.split("/").filter(Boolean);
|
|
1332
|
-
if (segments.length >= 2) {
|
|
1333
|
-
const lastSegment = segments[segments.length - 1];
|
|
1334
|
-
// If it looks like an ID (number or uuid), use the resource name
|
|
1335
|
-
if (/^\d+$/.test(lastSegment) || /^[a-f0-9-]{36}$/i.test(lastSegment)) {
|
|
1336
|
-
return null;
|
|
1337
|
-
}
|
|
1338
|
-
// Humanize the last segment (e.g., charizard -> Charizard)
|
|
1339
|
-
return lastSegment.charAt(0).toUpperCase() + lastSegment.slice(1);
|
|
1340
|
-
}
|
|
1341
|
-
if (segments.length === 1) {
|
|
1342
|
-
return segments[0].charAt(0).toUpperCase() + segments[0].slice(1);
|
|
1343
|
-
}
|
|
1344
|
-
return null;
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
/**
|
|
1348
|
-
* Get human-readable action from HTTP method + path
|
|
1349
|
-
*/
|
|
1350
|
-
function getHumanReadableApiAction(method, url) {
|
|
1351
|
-
try {
|
|
1352
|
-
const urlObj = new URL(url, "http://localhost");
|
|
1353
|
-
let path = urlObj.pathname;
|
|
1354
|
-
|
|
1355
|
-
// Handle GraphQL specially
|
|
1356
|
-
if (path.includes("graphql")) {
|
|
1357
|
-
return "GraphQL Request";
|
|
1358
|
-
}
|
|
1359
|
-
|
|
1360
|
-
// Remove API prefixes
|
|
1361
|
-
path = path.replace(/^\/api\/v\d+/, "").replace(/^\/api/, "");
|
|
1362
|
-
const entity = extractEntityFromPath(path);
|
|
1363
|
-
const segments = path.split("/").filter(Boolean);
|
|
1364
|
-
const resource = segments[0] ? segments[0].charAt(0).toUpperCase() + segments[0].slice(1) : "Data";
|
|
1365
|
-
|
|
1366
|
-
// Check for search/query patterns
|
|
1367
|
-
const hasSearchQuery = urlObj.searchParams.has("q") || urlObj.searchParams.has("query") || urlObj.searchParams.has("search");
|
|
1368
|
-
|
|
1369
|
-
// Generate human-readable action based on method
|
|
1370
|
-
switch (method.toUpperCase()) {
|
|
1371
|
-
case "GET":
|
|
1372
|
-
if (hasSearchQuery) {
|
|
1373
|
-
const query = urlObj.searchParams.get("q") || urlObj.searchParams.get("query") || urlObj.searchParams.get("search");
|
|
1374
|
-
if (query) return `Search "${query}"`;
|
|
1375
|
-
return `Search ${resource}`;
|
|
1376
|
-
}
|
|
1377
|
-
if (entity) return `Fetch ${entity}`;
|
|
1378
|
-
return `Fetch ${resource}`;
|
|
1379
|
-
case "POST":
|
|
1380
|
-
if (path.includes("search")) return `Search ${resource}`;
|
|
1381
|
-
if (entity) return `Create ${entity}`;
|
|
1382
|
-
return `Create ${resource}`;
|
|
1383
|
-
case "PUT":
|
|
1384
|
-
case "PATCH":
|
|
1385
|
-
if (entity) return `Update ${entity}`;
|
|
1386
|
-
return `Update ${resource}`;
|
|
1387
|
-
case "DELETE":
|
|
1388
|
-
if (entity) return `Delete ${entity}`;
|
|
1389
|
-
return `Delete ${resource}`;
|
|
1390
|
-
default:
|
|
1391
|
-
return `${method} ${resource}`;
|
|
1392
|
-
}
|
|
1393
|
-
} catch {
|
|
1394
|
-
return `${method} request`;
|
|
1395
|
-
}
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
/**
|
|
1399
|
-
* Get human-readable route label
|
|
1400
|
-
*/
|
|
1401
|
-
function getHumanReadableRoute(pathname) {
|
|
1402
|
-
if (pathname === "/" || pathname === "") return "Home";
|
|
1403
|
-
const segments = pathname.split("/").filter(Boolean);
|
|
1404
|
-
if (segments.length === 0) return "Home";
|
|
1405
|
-
|
|
1406
|
-
// Handle common patterns
|
|
1407
|
-
if (segments.length === 1) {
|
|
1408
|
-
// /pokemon -> Pokemon List
|
|
1409
|
-
const name = segments[0].charAt(0).toUpperCase() + segments[0].slice(1);
|
|
1410
|
-
return `${name} List`;
|
|
1411
|
-
}
|
|
1412
|
-
if (segments.length >= 2) {
|
|
1413
|
-
// /pokemon/charizard -> Charizard Details
|
|
1414
|
-
const entity = segments[segments.length - 1];
|
|
1415
|
-
// Check if it's a numeric ID
|
|
1416
|
-
if (/^\d+$/.test(entity)) {
|
|
1417
|
-
const resource = segments[0].charAt(0).toUpperCase() + segments[0].slice(1);
|
|
1418
|
-
return `${resource} #${entity}`;
|
|
1419
|
-
}
|
|
1420
|
-
const entityName = entity.charAt(0).toUpperCase() + entity.slice(1);
|
|
1421
|
-
return `${entityName} Details`;
|
|
1422
|
-
}
|
|
1423
|
-
return pathname;
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
/**
|
|
1427
|
-
* Format a single event as Mermaid sequence messages
|
|
1428
|
-
* Returns both the messages and any notes to add
|
|
1429
|
-
* Returns null if the event should be skipped (internal/devtools)
|
|
1430
|
-
*/
|
|
1431
|
-
function formatMermaidEvent(event, _settings, baseTimestamp) {
|
|
1432
|
-
const messages = [];
|
|
1433
|
-
const notes = [];
|
|
1434
|
-
const relativeTime = formatMermaidDuration(event.timestamp - baseTimestamp);
|
|
1435
|
-
switch (event.source) {
|
|
1436
|
-
case "route":
|
|
1437
|
-
{
|
|
1438
|
-
const data = event.originalEvent;
|
|
1439
|
-
const pathname = String(data?.pathname || event.title);
|
|
1440
|
-
const previousPathname = data?.previousPathname;
|
|
1441
|
-
const timeSincePrevious = data?.timeSincePrevious;
|
|
1442
|
-
const routeLabel = getHumanReadableRoute(pathname);
|
|
1443
|
-
const fromLabel = previousPathname ? getHumanReadableRoute(previousPathname) : null;
|
|
1444
|
-
|
|
1445
|
-
// Show navigation with clear from → to pattern
|
|
1446
|
-
if (fromLabel) {
|
|
1447
|
-
messages.push(`U->>App: ${fromLabel} → ${routeLabel}`);
|
|
1448
|
-
// Show how long user spent on previous screen
|
|
1449
|
-
if (timeSincePrevious && timeSincePrevious > 0) {
|
|
1450
|
-
notes.push(`Note right of App: ${formatMermaidDuration(timeSincePrevious)} on ${fromLabel}`);
|
|
1451
|
-
}
|
|
1452
|
-
} else {
|
|
1453
|
-
messages.push(`U->>App: Open ${routeLabel}`);
|
|
1454
|
-
}
|
|
1455
|
-
break;
|
|
1456
|
-
}
|
|
1457
|
-
case "network":
|
|
1458
|
-
{
|
|
1459
|
-
const data = event.originalEvent;
|
|
1460
|
-
const method = data?.method || "GET";
|
|
1461
|
-
const url = data?.url || "";
|
|
1462
|
-
const status = data?.status;
|
|
1463
|
-
const duration = data?.duration;
|
|
1464
|
-
const responseData = data?.response || data?.data || data?.body;
|
|
1465
|
-
// Try to get size from various possible fields
|
|
1466
|
-
const responseSize = data?.responseSize || data?.size || data?.contentLength;
|
|
1467
|
-
|
|
1468
|
-
// Get human-readable action
|
|
1469
|
-
const action = getHumanReadableApiAction(method, url);
|
|
1470
|
-
const entity = extractEntityFromPath(url);
|
|
1471
|
-
|
|
1472
|
-
// Request with activation
|
|
1473
|
-
messages.push(`App->>+API: ${action}`);
|
|
1474
|
-
|
|
1475
|
-
// Response with entity context if available
|
|
1476
|
-
if (event.status === "error") {
|
|
1477
|
-
const statusText = status ? `${status} Error` : "Failed";
|
|
1478
|
-
messages.push(`API--x-App: ${statusText}`);
|
|
1479
|
-
} else {
|
|
1480
|
-
let response = entity ? `✓ ${entity}` : "✓ Success";
|
|
1481
|
-
messages.push(`API-->>-App: ${response}`);
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
// Build note with duration and size
|
|
1485
|
-
const noteParts = [];
|
|
1486
|
-
if (duration) {
|
|
1487
|
-
noteParts.push(formatMermaidDuration(duration));
|
|
1488
|
-
}
|
|
1489
|
-
// Add response size - try explicit size first, then estimate
|
|
1490
|
-
if (responseSize && responseSize > 0) {
|
|
1491
|
-
noteParts.push(formatBytes(responseSize));
|
|
1492
|
-
} else if (responseData) {
|
|
1493
|
-
const size = estimateDataSize(responseData);
|
|
1494
|
-
if (size > 1024) {
|
|
1495
|
-
// Only show if > 1KB
|
|
1496
|
-
noteParts.push(formatBytes(size));
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
if (noteParts.length > 0) {
|
|
1500
|
-
notes.push(`Note right of API: ${noteParts.join(" · ")}`);
|
|
1501
|
-
}
|
|
1502
|
-
break;
|
|
1503
|
-
}
|
|
1504
|
-
case "storage-async":
|
|
1505
|
-
case "storage-mmkv":
|
|
1506
|
-
{
|
|
1507
|
-
const data = event.originalEvent;
|
|
1508
|
-
const innerData = data?.data;
|
|
1509
|
-
const action = data?.action || "access";
|
|
1510
|
-
const key = innerData?.key || "data";
|
|
1511
|
-
|
|
1512
|
-
// Skip internal devtools storage
|
|
1513
|
-
if (isInternalStorageKey(key)) {
|
|
1514
|
-
return {
|
|
1515
|
-
messages: [],
|
|
1516
|
-
notes: [],
|
|
1517
|
-
skip: true
|
|
1518
|
-
};
|
|
1519
|
-
}
|
|
1520
|
-
const keyName = getStorageKeyName(key);
|
|
1521
|
-
const storeId = event.source === "storage-mmkv" ? "MMKV" : "Async";
|
|
1522
|
-
|
|
1523
|
-
// Helper to get item identifier (handles both objects and strings)
|
|
1524
|
-
const getItemId = item => {
|
|
1525
|
-
if (typeof item === "string") return item;
|
|
1526
|
-
if (typeof item === "number") return String(item);
|
|
1527
|
-
if (typeof item === "object" && item) {
|
|
1528
|
-
if ("name" in item) return String(item.name);
|
|
1529
|
-
if ("id" in item) return String(item.id);
|
|
1530
|
-
}
|
|
1531
|
-
return null;
|
|
1532
|
-
};
|
|
1533
|
-
|
|
1534
|
-
// Helper to capitalize first letter
|
|
1535
|
-
const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1);
|
|
1536
|
-
|
|
1537
|
-
// Analyze the change to determine action and entity
|
|
1538
|
-
let actionIcon = "";
|
|
1539
|
-
let actionVerb = "";
|
|
1540
|
-
let entityName = "";
|
|
1541
|
-
let countInfo = "";
|
|
1542
|
-
const prevValue = innerData?.prevValue;
|
|
1543
|
-
const newValue = innerData?.value;
|
|
1544
|
-
|
|
1545
|
-
// Handle array comparisons (most common for collections)
|
|
1546
|
-
if (Array.isArray(prevValue) && Array.isArray(newValue)) {
|
|
1547
|
-
const prevLen = prevValue.length;
|
|
1548
|
-
const newLen = newValue.length;
|
|
1549
|
-
countInfo = `${prevLen} → ${newLen} items`;
|
|
1550
|
-
if (newLen > prevLen) {
|
|
1551
|
-
// Items were added
|
|
1552
|
-
actionIcon = "➕";
|
|
1553
|
-
actionVerb = "Add";
|
|
1554
|
-
// Find what was added
|
|
1555
|
-
const prevSet = new Set(prevValue.map(getItemId).filter(Boolean));
|
|
1556
|
-
for (const item of newValue) {
|
|
1557
|
-
const id = getItemId(item);
|
|
1558
|
-
if (id && !prevSet.has(id)) {
|
|
1559
|
-
entityName = capitalize(id);
|
|
1560
|
-
break;
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
} else if (newLen < prevLen) {
|
|
1564
|
-
// Items were removed
|
|
1565
|
-
actionIcon = "➖";
|
|
1566
|
-
actionVerb = "Remove";
|
|
1567
|
-
// Find what was removed
|
|
1568
|
-
const newSet = new Set(newValue.map(getItemId).filter(Boolean));
|
|
1569
|
-
for (const item of prevValue) {
|
|
1570
|
-
const id = getItemId(item);
|
|
1571
|
-
if (id && !newSet.has(id)) {
|
|
1572
|
-
entityName = capitalize(id);
|
|
1573
|
-
break;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
} else {
|
|
1577
|
-
// Same length - update
|
|
1578
|
-
actionIcon = "📝";
|
|
1579
|
-
actionVerb = "Update";
|
|
1580
|
-
}
|
|
1581
|
-
} else if (Array.isArray(newValue) && (!prevValue || Array.isArray(prevValue) && prevValue.length === 0)) {
|
|
1582
|
-
// Adding first item(s) - prevValue is null/undefined or empty array
|
|
1583
|
-
actionIcon = "➕";
|
|
1584
|
-
actionVerb = "Add";
|
|
1585
|
-
countInfo = `→ ${newValue.length} items`;
|
|
1586
|
-
if (newValue.length > 0) {
|
|
1587
|
-
const id = getItemId(newValue[0]);
|
|
1588
|
-
if (id) entityName = capitalize(id);
|
|
1589
|
-
}
|
|
1590
|
-
} else if (Array.isArray(prevValue) && (!newValue || Array.isArray(newValue) && newValue.length === 0)) {
|
|
1591
|
-
// Removing all items
|
|
1592
|
-
actionIcon = "➖";
|
|
1593
|
-
actionVerb = "Clear";
|
|
1594
|
-
countInfo = `${prevValue.length} → 0 items`;
|
|
1595
|
-
} else if (action === "getItem") {
|
|
1596
|
-
actionIcon = "📖";
|
|
1597
|
-
actionVerb = "Load";
|
|
1598
|
-
} else if (action === "removeItem") {
|
|
1599
|
-
actionIcon = "➖";
|
|
1600
|
-
actionVerb = "Remove";
|
|
1601
|
-
} else if (action === "clear") {
|
|
1602
|
-
actionIcon = "🗑️";
|
|
1603
|
-
actionVerb = "Clear";
|
|
1604
|
-
} else {
|
|
1605
|
-
// Default for setItem without prev/new comparison
|
|
1606
|
-
actionIcon = "💾";
|
|
1607
|
-
actionVerb = "Save";
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
// Build the message
|
|
1611
|
-
let message;
|
|
1612
|
-
if (entityName) {
|
|
1613
|
-
message = `App->>${storeId}: ${actionIcon} ${actionVerb} ${entityName} → ${keyName}`;
|
|
1614
|
-
} else {
|
|
1615
|
-
message = `App->>${storeId}: ${actionIcon} ${actionVerb} ${keyName}`;
|
|
1616
|
-
}
|
|
1617
|
-
messages.push(message);
|
|
1618
|
-
|
|
1619
|
-
// Add note with count info
|
|
1620
|
-
if (countInfo) {
|
|
1621
|
-
notes.push(`Note right of ${storeId}: ${countInfo}`);
|
|
1622
|
-
}
|
|
1623
|
-
break;
|
|
1624
|
-
}
|
|
1625
|
-
case "react-query":
|
|
1626
|
-
case "react-query-query":
|
|
1627
|
-
{
|
|
1628
|
-
const data = event.originalEvent;
|
|
1629
|
-
const type = data?.type || "";
|
|
1630
|
-
const queryKey = data?.queryKey;
|
|
1631
|
-
const duration = data?.duration;
|
|
1632
|
-
|
|
1633
|
-
// Format query key as human-readable
|
|
1634
|
-
let keyLabel = "data";
|
|
1635
|
-
if (Array.isArray(queryKey) && queryKey.length > 0) {
|
|
1636
|
-
// Try to make it readable: ["pokemon", "charizard"] -> "Charizard"
|
|
1637
|
-
const lastKey = queryKey[queryKey.length - 1];
|
|
1638
|
-
if (typeof lastKey === "string" && !/^\d+$/.test(lastKey)) {
|
|
1639
|
-
keyLabel = lastKey.charAt(0).toUpperCase() + lastKey.slice(1);
|
|
1640
|
-
} else if (queryKey.length > 1 && typeof queryKey[0] === "string") {
|
|
1641
|
-
keyLabel = queryKey[0].charAt(0).toUpperCase() + queryKey[0].slice(1);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
if (type.includes("start") || type.includes("fetch") || event.status === "pending") {
|
|
1645
|
-
messages.push(`App->>+Cache: Fetch ${keyLabel}`);
|
|
1646
|
-
} else if (event.status === "error") {
|
|
1647
|
-
messages.push(`Cache--x-App: Failed to load`);
|
|
1648
|
-
} else if (event.status === "success") {
|
|
1649
|
-
let response = `✓ ${keyLabel} ready`;
|
|
1650
|
-
if (duration) {
|
|
1651
|
-
response += ` (${formatMermaidDuration(duration)})`;
|
|
1652
|
-
}
|
|
1653
|
-
messages.push(`Cache-->>-App: ${response}`);
|
|
1654
|
-
} else if (type.includes("invalidate")) {
|
|
1655
|
-
messages.push(`App->>Cache: Refresh ${keyLabel}`);
|
|
1656
|
-
} else {
|
|
1657
|
-
messages.push(`Cache-->>App: ${escapeMermaidText(type)}`);
|
|
1658
|
-
}
|
|
1659
|
-
break;
|
|
1660
|
-
}
|
|
1661
|
-
case "react-query-mutation":
|
|
1662
|
-
{
|
|
1663
|
-
const data = event.originalEvent;
|
|
1664
|
-
const type = data?.type || "";
|
|
1665
|
-
const mutationKey = data?.mutationKey;
|
|
1666
|
-
const duration = data?.duration;
|
|
1667
|
-
let actionLabel = "Update";
|
|
1668
|
-
if (Array.isArray(mutationKey) && mutationKey.length > 0) {
|
|
1669
|
-
const key = String(mutationKey[0]);
|
|
1670
|
-
// Common mutation patterns
|
|
1671
|
-
if (key.includes("add") || key.includes("create")) actionLabel = "Add";else if (key.includes("delete") || key.includes("remove")) actionLabel = "Delete";else if (key.includes("update") || key.includes("edit")) actionLabel = "Update";else actionLabel = key.charAt(0).toUpperCase() + key.slice(1);
|
|
1672
|
-
}
|
|
1673
|
-
if (type.includes("start") || type.includes("loading") || event.status === "pending") {
|
|
1674
|
-
messages.push(`App->>+Cache: ${actionLabel}`);
|
|
1675
|
-
} else if (event.status === "error") {
|
|
1676
|
-
messages.push(`Cache--x-App: ${actionLabel} failed`);
|
|
1677
|
-
} else if (event.status === "success") {
|
|
1678
|
-
let response = `✓ ${actionLabel} complete`;
|
|
1679
|
-
if (duration) {
|
|
1680
|
-
response += ` (${formatMermaidDuration(duration)})`;
|
|
1681
|
-
}
|
|
1682
|
-
messages.push(`Cache-->>-App: ${response}`);
|
|
1683
|
-
}
|
|
1684
|
-
break;
|
|
1685
|
-
}
|
|
1686
|
-
case "redux":
|
|
1687
|
-
{
|
|
1688
|
-
const data = event.originalEvent;
|
|
1689
|
-
const actionType = data?.type || event.title;
|
|
1690
|
-
const hasChange = data?.hasStateChange;
|
|
1691
|
-
const diffSummary = data?.diffSummary;
|
|
1692
|
-
|
|
1693
|
-
// Parse action type into human-readable form
|
|
1694
|
-
// e.g., "cart/addItem" -> "Add Item to Cart"
|
|
1695
|
-
const parts = actionType.split("/");
|
|
1696
|
-
let actionLabel;
|
|
1697
|
-
if (parts.length >= 2) {
|
|
1698
|
-
const slice = parts[0].charAt(0).toUpperCase() + parts[0].slice(1);
|
|
1699
|
-
let action = parts[1].replace(/([A-Z])/g, " $1") // camelCase to spaces
|
|
1700
|
-
.replace(/(pending|fulfilled|rejected)$/i, "").trim();
|
|
1701
|
-
action = action.charAt(0).toUpperCase() + action.slice(1);
|
|
1702
|
-
actionLabel = `${action} (${slice})`;
|
|
1703
|
-
} else {
|
|
1704
|
-
actionLabel = escapeMermaidText(actionType).substring(0, 25);
|
|
1705
|
-
}
|
|
1706
|
-
messages.push(`App->>Redux: ${actionLabel}`);
|
|
1707
|
-
if (hasChange === false) {
|
|
1708
|
-
notes.push(`Note right of Redux: No change`);
|
|
1709
|
-
} else if (diffSummary) {
|
|
1710
|
-
notes.push(`Note right of Redux: ${escapeMermaidText(diffSummary).substring(0, 35)}`);
|
|
1711
|
-
}
|
|
1712
|
-
break;
|
|
1713
|
-
}
|
|
1714
|
-
case "render":
|
|
1715
|
-
{
|
|
1716
|
-
const data = event.originalEvent;
|
|
1717
|
-
const renderData = data?.renderData;
|
|
1718
|
-
const componentName = escapeMermaidText(event.title).substring(0, 20);
|
|
1719
|
-
const cause = renderData?.cause || "update";
|
|
1720
|
-
|
|
1721
|
-
// Make cause more human-readable
|
|
1722
|
-
const causeLabel = cause === "mount" ? "mounted" : cause === "props" ? "props changed" : cause === "state" ? "state changed" : cause === "context" ? "context changed" : cause === "parent" ? "parent re-rendered" : cause === "hooks" ? "hook changed" : cause;
|
|
1723
|
-
messages.push(`App->>App: Render ${componentName}`);
|
|
1724
|
-
notes.push(`Note right of App: ${causeLabel}`);
|
|
1725
|
-
break;
|
|
1726
|
-
}
|
|
1727
|
-
default:
|
|
1728
|
-
{
|
|
1729
|
-
messages.push(`App->>App: ${escapeMermaidText(event.title).substring(0, 30)}`);
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
return {
|
|
1733
|
-
messages,
|
|
1734
|
-
notes
|
|
1735
|
-
};
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
/**
|
|
1739
|
-
* Generate Mermaid sequence diagram export
|
|
1740
|
-
*/
|
|
1741
|
-
function generateMermaidExport(events, settings) {
|
|
1742
|
-
const filtered = filterEvents(events, settings);
|
|
1743
|
-
if (filtered.length === 0) {
|
|
1744
|
-
return "sequenceDiagram\n participant U as 👤 User\n participant App as 📱 App\n Note over U,App: No events captured";
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
// Sort by timestamp (oldest first for timeline)
|
|
1748
|
-
const sorted = [...filtered].sort((a, b) => a.timestamp - b.timestamp);
|
|
1749
|
-
const baseTimestamp = sorted[0].timestamp;
|
|
1750
|
-
|
|
1751
|
-
// Detect participants
|
|
1752
|
-
const participants = detectParticipants(sorted);
|
|
1753
|
-
const useGroups = shouldUseGroups(participants);
|
|
1754
|
-
const lines = ["sequenceDiagram"];
|
|
1755
|
-
lines.push(" autonumber");
|
|
1756
|
-
lines.push("");
|
|
1757
|
-
|
|
1758
|
-
// Add participants with optional grouping
|
|
1759
|
-
if (useGroups) {
|
|
1760
|
-
const clientParticipants = participants.filter(p => p.group === "client");
|
|
1761
|
-
const serverParticipants = participants.filter(p => p.group === "server");
|
|
1762
|
-
if (clientParticipants.length > 0) {
|
|
1763
|
-
lines.push(" box rgb(240, 248, 255) Client");
|
|
1764
|
-
for (const p of clientParticipants) {
|
|
1765
|
-
lines.push(` participant ${p.id} as ${p.icon} ${p.label}`);
|
|
1766
|
-
}
|
|
1767
|
-
lines.push(" end");
|
|
1768
|
-
}
|
|
1769
|
-
if (serverParticipants.length > 0) {
|
|
1770
|
-
lines.push(" box rgb(255, 248, 240) External");
|
|
1771
|
-
for (const p of serverParticipants) {
|
|
1772
|
-
lines.push(` participant ${p.id} as ${p.icon} ${p.label}`);
|
|
1773
|
-
}
|
|
1774
|
-
lines.push(" end");
|
|
1775
|
-
}
|
|
1776
|
-
} else {
|
|
1777
|
-
for (const p of participants) {
|
|
1778
|
-
lines.push(` participant ${p.id} as ${p.icon} ${p.label}`);
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
lines.push("");
|
|
1782
|
-
|
|
1783
|
-
// Calculate session summary stats
|
|
1784
|
-
const sessionDuration = sorted[sorted.length - 1].timestamp - baseTimestamp;
|
|
1785
|
-
const networkEvents = sorted.filter(e => e.source === "network");
|
|
1786
|
-
const totalBytes = networkEvents.reduce((sum, e) => {
|
|
1787
|
-
const data = e.originalEvent;
|
|
1788
|
-
const size = data?.responseSize || data?.size || 0;
|
|
1789
|
-
return sum + size;
|
|
1790
|
-
}, 0);
|
|
1791
|
-
const errorCount = sorted.filter(e => e.status === "error").length;
|
|
1792
|
-
|
|
1793
|
-
// Build summary parts
|
|
1794
|
-
const summaryParts = [];
|
|
1795
|
-
summaryParts.push(`⏱️ ${formatMermaidDuration(sessionDuration)}`);
|
|
1796
|
-
summaryParts.push(`📊 ${sorted.length} events`);
|
|
1797
|
-
if (networkEvents.length > 0) {
|
|
1798
|
-
summaryParts.push(`🌐 ${networkEvents.length} API calls`);
|
|
1799
|
-
}
|
|
1800
|
-
if (totalBytes > 0) {
|
|
1801
|
-
summaryParts.push(`📦 ${formatBytes(totalBytes)}`);
|
|
1802
|
-
}
|
|
1803
|
-
if (errorCount > 0) {
|
|
1804
|
-
summaryParts.push(`❌ ${errorCount} errors`);
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
// Add session summary header
|
|
1808
|
-
lines.push(` Note over U,API: ${summaryParts.join(" · ")}`);
|
|
1809
|
-
lines.push("");
|
|
1810
|
-
|
|
1811
|
-
// Track for duplicate detection - use canonical URLs (without cache-busting params)
|
|
1812
|
-
const recentNetworkUrls = new Map();
|
|
1813
|
-
|
|
1814
|
-
// Process events
|
|
1815
|
-
let skippedCount = 0;
|
|
1816
|
-
for (const event of sorted) {
|
|
1817
|
-
const result = formatMermaidEvent(event, settings, baseTimestamp);
|
|
1818
|
-
|
|
1819
|
-
// Skip internal/devtools events
|
|
1820
|
-
if (result.skip) {
|
|
1821
|
-
skippedCount++;
|
|
1822
|
-
continue;
|
|
1823
|
-
}
|
|
1824
|
-
const {
|
|
1825
|
-
messages,
|
|
1826
|
-
notes
|
|
1827
|
-
} = result;
|
|
1828
|
-
|
|
1829
|
-
// Check for duplicate network requests using canonical URL
|
|
1830
|
-
let isDuplicate = false;
|
|
1831
|
-
let duplicateInfo = "";
|
|
1832
|
-
if (event.source === "network") {
|
|
1833
|
-
const data = event.originalEvent;
|
|
1834
|
-
const url = data?.url;
|
|
1835
|
-
if (url) {
|
|
1836
|
-
const canonicalUrl = getCanonicalUrl(url);
|
|
1837
|
-
const existing = recentNetworkUrls.get(canonicalUrl);
|
|
1838
|
-
if (existing && event.timestamp - existing.timestamp < 30000) {
|
|
1839
|
-
// 30 second window
|
|
1840
|
-
isDuplicate = true;
|
|
1841
|
-
const timeSince = event.timestamp - existing.timestamp;
|
|
1842
|
-
const timeLabel = formatMermaidDuration(timeSince);
|
|
1843
|
-
duplicateInfo = `⚠️ Already fetched ${timeLabel} ago`;
|
|
1844
|
-
recentNetworkUrls.set(canonicalUrl, {
|
|
1845
|
-
timestamp: event.timestamp,
|
|
1846
|
-
count: existing.count + 1
|
|
1847
|
-
});
|
|
1848
|
-
} else {
|
|
1849
|
-
recentNetworkUrls.set(canonicalUrl, {
|
|
1850
|
-
timestamp: event.timestamp,
|
|
1851
|
-
count: 1
|
|
1852
|
-
});
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
|
|
1857
|
-
// Wrap duplicates or errors in highlighted rect
|
|
1858
|
-
if (isDuplicate) {
|
|
1859
|
-
lines.push(" rect rgb(255, 245, 230)");
|
|
1860
|
-
lines.push(` Note over App,API: ${duplicateInfo}`);
|
|
1861
|
-
for (const msg of messages) {
|
|
1862
|
-
lines.push(` ${msg}`);
|
|
1863
|
-
}
|
|
1864
|
-
for (const note of notes) {
|
|
1865
|
-
lines.push(` ${note}`);
|
|
1866
|
-
}
|
|
1867
|
-
lines.push(" end");
|
|
1868
|
-
} else if (event.status === "error") {
|
|
1869
|
-
lines.push(" rect rgb(255, 235, 235)");
|
|
1870
|
-
for (const msg of messages) {
|
|
1871
|
-
lines.push(` ${msg}`);
|
|
1872
|
-
}
|
|
1873
|
-
for (const note of notes) {
|
|
1874
|
-
lines.push(` ${note}`);
|
|
1875
|
-
}
|
|
1876
|
-
lines.push(" end");
|
|
1877
|
-
} else {
|
|
1878
|
-
for (const msg of messages) {
|
|
1879
|
-
lines.push(` ${msg}`);
|
|
1880
|
-
}
|
|
1881
|
-
for (const note of notes) {
|
|
1882
|
-
lines.push(` ${note}`);
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
// Add note about skipped internal events if any
|
|
1888
|
-
if (skippedCount > 0) {
|
|
1889
|
-
lines.push("");
|
|
1890
|
-
lines.push(` Note over App: ${skippedCount} internal events hidden`);
|
|
1891
|
-
}
|
|
1892
|
-
return lines.join("\n");
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
/**
|
|
1896
|
-
* Generate export based on settings format
|
|
1897
|
-
*/
|
|
1898
|
-
function generateExport(events, settings) {
|
|
1899
|
-
switch (settings.format) {
|
|
1900
|
-
case "markdown":
|
|
1901
|
-
return generateMarkdownExport(events, settings);
|
|
1902
|
-
case "json":
|
|
1903
|
-
return generateJsonExport(events, settings);
|
|
1904
|
-
case "plaintext":
|
|
1905
|
-
return generatePlaintextExport(events, settings);
|
|
1906
|
-
case "mermaid":
|
|
1907
|
-
return generateMermaidExport(events, settings);
|
|
1908
|
-
default:
|
|
1909
|
-
return generateMarkdownExport(events, settings);
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
//# sourceMappingURL=eventExportFormatter.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.estimateExportSize=estimateExportSize;exports.filterEvents=filterEvents;exports.generateExport=generateExport;exports.generateJsonExport=generateJsonExport;exports.generateMarkdownExport=generateMarkdownExport;exports.generateMermaidExport=generateMermaidExport;exports.generatePlaintextExport=generatePlaintextExport;exports.getExportSummary=getExportSummary;const STATUS_ICONS={success:"\u2705",pending:"\u23F3",error:"\u274C",neutral:"\u2796"};const STATUS_ICONS_ASCII={success:"[OK]",pending:"[...]",error:"[ERR]",neutral:"[-]"};const SOURCE_LABELS={"storage-async":"Storage","storage-mmkv":"MMKV",redux:"Redux",network:"Network","react-query":"Query","react-query-query":"Query","react-query-mutation":"Mutation",route:"Route",zustand:"Zustand",jotai:"Jotai",render:"Render"};function tryParseJson(e){if(typeof e!=="string")return e;const t=e.trim();if(!t.startsWith("{")&&!t.startsWith("["))return e;try{return JSON.parse(e)}catch{return e}}function deepParseJsonStrings(e){if(e===null||e===void 0)return e;if(typeof e==="string"){return tryParseJson(e)}if(Array.isArray(e)){return e.map(deepParseJsonStrings)}if(typeof e==="object"){const t={};for(const[n,r]of Object.entries(e)){t[n]=deepParseJsonStrings(r)}return t}return e}const VERBOSE_FIELDS=new Set(["image","imageUrl","imageURL","image_url","thumbnail","thumbnailUrl","thumbnail_url","icon","iconUrl","avatar","avatarUrl","photo","photoUrl","picture","pictureUrl","description","desc","longDescription","shortDescription","meta_description"]);function stripVerboseFieldsFromObject(e){if(e===null||e===void 0)return e;if(Array.isArray(e)){return e.map(stripVerboseFieldsFromObject)}if(typeof e==="object"){const t={};for(const[n,r]of Object.entries(e)){if(VERBOSE_FIELDS.has(n))continue;if(typeof r==="string"&&isImageUrl(r))continue;t[n]=stripVerboseFieldsFromObject(r)}return t}return e}function isImageUrl(e){if(!e.startsWith("http"))return false;const t=e.toLowerCase();return t.includes("/photo")||t.includes("/image")||t.includes("unsplash.com")||t.includes("cloudinary.com")||t.includes("imgur.com")||/\.(jpg|jpeg|png|gif|webp|svg|bmp)(\?|$)/i.test(e)}function formatTimestampValue(e){if(e instanceof Date){return e.toISOString()}if(e&&typeof e==="object"&&Object.keys(e).length===0){return void 0}return e}function computeArrayDiff(e,t){const n=s=>{if(typeof s!=="object"||s===null)return null;const c=s;if(typeof c.id==="string")return c.id;if(typeof c.orderId==="string")return c.orderId;if(typeof c.key==="string")return c.key;return null};const r=new Set(e.map(n).filter(Boolean));const u=new Set(t.map(n).filter(Boolean));if(r.size===0&&u.size===0)return null;const o=t.filter(s=>{const c=n(s);return c&&!r.has(c)});const a=e.filter(s=>{const c=n(s);return c&&!u.has(c)});const i=t.length-o.length;if(o.length+a.length<e.length&&o.length+a.length<t.length){return{added:o,removed:a,unchanged:i}}return null}function formatStorageData(e,t){const n={};if(e.action)n.action=e.action;if(e.storageType)n.storageType=e.storageType;if(e.timestamp!==void 0){const r=formatTimestampValue(e.timestamp);if(r!==void 0){n.timestamp=r}}if(e.data){const r={...e.data};if(t.smartJsonParsing){if(r.value!==void 0){r.value=tryParseJson(r.value)}if(r.prevValue!==void 0){r.prevValue=tryParseJson(r.prevValue)}}if(t.showStorageDiff&&Array.isArray(r.value)&&Array.isArray(r.prevValue)){const u=computeArrayDiff(r.prevValue,r.value);if(u){const o={key:r.key};if(u.added.length>0){o.added=u.added}if(u.removed.length>0){o.removed=u.removed}if(u.unchanged>0){o.unchangedCount=u.unchanged}n.data=o;return n}}n.data=r}return n}function formatReduxData(e,t){if(!t.reduxChangedOnly){return t.smartJsonParsing?deepParseJsonStrings(e):e}const n={};if(e.type)n.type=e.type;if(e.payload)n.payload=t.smartJsonParsing?deepParseJsonStrings(e.payload):e.payload;if(e.sliceName)n.sliceName=e.sliceName;if(e.actionName)n.actionName=e.actionName;if(e.duration)n.duration=e.duration;if(e.hasStateChange!==void 0)n.hasStateChange=e.hasStateChange;if(e.diffSummary)n.diffSummary=e.diffSummary;if(e.changedKeysCount!==void 0)n.changedKeysCount=e.changedKeysCount;if(e.hasStateChange===true){const r=e.sliceName;if(r&&e.prevState&&e.nextState){const u=e.prevState;const o=e.nextState;if(u[r]!==void 0||o[r]!==void 0){n.stateChange={slice:r,before:u[r],after:o[r]}}}}return n}function getItemIdentifier(e){if(typeof e!=="object"||e===null)return null;const t=e;if(typeof t.name==="string")return t.name;if(typeof t.id==="string")return t.id;if(typeof t.key==="string")return t.key;return null}function generateStorageDiffSummary(e,t){const n=typeof e==="string"?tryParseJson(e):e;const r=typeof t==="string"?tryParseJson(t):t;if((n===null||n===void 0)&&r!==null&&r!==void 0)return"Created";if(n!==null&&n!==void 0&&(r===null||r===void 0))return"Deleted";if(Array.isArray(n)&&Array.isArray(r)){const u=n.length;const o=r.length;const a=n.map(getItemIdentifier).filter(Boolean);const i=r.map(getItemIdentifier).filter(Boolean);if(u===o&&u>0){const s=new Set(a);const c=new Set(i);const l=a.filter(f=>c.has(f));if(l.length===0&&a.length>0&&i.length>0){return`\u26A0\uFE0F Replaced: [${a.join(", ")}] \u2192 [${i.join(", ")}]`}if(l.length<u){const f=a.filter(y=>!c.has(y));const d=i.filter(y=>!s.has(y));return`Changed: -${f.join(", ")} +${d.join(", ")}`}}if(u===0&&o>0){if(i.length>0){return`Added: [${i.join(", ")}]`}return`Added ${o} item${o>1?"s":""}`}if(u>0&&o===0){if(a.length>0){return`Removed all: [${a.join(", ")}]`}return`Removed all ${u} item${u>1?"s":""}`}if(o>u){const s=new Set(a);const c=i.filter(l=>!s.has(l));if(c.length>0){return`Added: [${c.join(", ")}] (${u} \u2192 ${o})`}return`Added ${o-u} item${o-u>1?"s":""} (${u} \u2192 ${o})`}if(o<u){const s=new Set(i);const c=a.filter(l=>!s.has(l));if(c.length>0){return`Removed: [${c.join(", ")}] (${u} \u2192 ${o})`}return`Removed ${u-o} item${u-o>1?"s":""} (${u} \u2192 ${o})`}return`Updated (${o} item${o>1?"s":""})`}if(typeof n==="object"&&typeof r==="object"&&n&&r){const u=Object.keys(n);const o=Object.keys(r);const a=o.filter(s=>!u.includes(s));const i=u.filter(s=>!o.includes(s));if(a.length>0&&i.length>0){return`+${a.length} -${i.length} keys`}if(a.length>0)return`Added: ${a.join(", ")}`;if(i.length>0)return`Removed: ${i.join(", ")}`;return"Updated"}return null}function formatReactQueryData(e,t){const n={};if(e.id)n.id=e.id;if(e.type)n.type=e.type;if(e.timestamp)n.timestamp=e.timestamp;if(e.queryKey)n.queryKey=e.queryKey;if(e.mutationKey)n.mutationKey=e.mutationKey;if(e.mutationId)n.mutationId=e.mutationId;if(e.duration)n.duration=e.duration;if(e.queryData!==void 0){n.data=t.smartJsonParsing?deepParseJsonStrings(e.queryData):e.queryData}if(e.variables!==void 0){n.variables=t.smartJsonParsing?deepParseJsonStrings(e.variables):e.variables}if(e.queryError!==void 0){const r=e.queryError;if(r&&typeof r==="object"){n.error=r.message||r.name||r}else{n.error=e.queryError}}if(e.mutationError!==void 0){const r=e.mutationError;if(r&&typeof r==="object"){n.error=r.message||r.name||r}else{n.error=e.mutationError}}if(e.query&&typeof e.query==="object"){const r=e.query;if(r.state&&typeof r.state==="object"){const u=r.state;if(u.status)n.status=u.status;if(u.fetchStatus)n.fetchStatus=u.fetchStatus;if(u.error){const o=u.error;if(o&&typeof o==="object"){n.error=o.message||o.name||o}}}}if(e.mutation&&typeof e.mutation==="object"){const r=e.mutation;if(r.state&&typeof r.state==="object"){const u=r.state;if(u.status)n.status=u.status;if(u.failureCount)n.failureCount=u.failureCount;if(u.error){const o=u.error;if(o&&typeof o==="object"){n.error=o.message||o.name||o}}if(u.failureReason){const o=u.failureReason;if(o&&typeof o==="object"){n.failureReason=o.message||o.name||o}}}}return n}function formatEventData(e,t){const n=e.originalEvent;if(!n)return null;let r;if(e.source==="storage-async"||e.source==="storage-mmkv"){r=formatStorageData(n,t)}else if(e.source==="redux"){r=formatReduxData(n,t)}else if(e.source==="react-query"||e.source==="react-query-query"||e.source==="react-query-mutation"){r=formatReactQueryData(n,t)}else if(t.smartJsonParsing){r=deepParseJsonStrings(n)}else{r=n}if(t.stripVerboseFields&&r){r=stripVerboseFieldsFromObject(r)}return r}function getExportSummary(e){const t={totalEvents:e.length,success:0,pending:0,error:0,neutral:0,durationMs:0,sources:new Set};if(e.length===0)return t;let n=Infinity;let r=-Infinity;for(const u of e){t[u.status]++;t.sources.add(u.source);if(u.timestamp<n)n=u.timestamp;if(u.timestamp>r)r=u.timestamp}t.durationMs=r-n;return t}function filterEvents(e,t){let n=[...e];if(t.filterMode!=="all"){n=n.filter(r=>{switch(t.filterMode){case"errors":return r.status==="error";case"success":return r.status==="success";case"pending":return r.status==="pending";default:return true}})}if(t.filterSources.length>0){const r=new Set(t.filterSources);n=n.filter(u=>r.has(u.source))}return n}function formatRelativeTime(e){if(e<1e3)return`+${e}ms`;if(e<6e4)return`+${(e/1e3).toFixed(1)}s`;return`+${(e/6e4).toFixed(1)}m`}function formatAbsoluteTime(e){const t=new Date(e);return t.toISOString()}function formatTimestamp(e,t,n){const r=formatRelativeTime(e-t);const u=formatAbsoluteTime(e);switch(n){case"relative":return r;case"absolute":return u;case"both":return`${r} (${u})`}}function approxJsonBytesOver(e,t){let n=0;const r=[e];const u=new Set;while(r.length>0){if(n>t)return{over:true,approxBytes:n};const o=r.pop();if(o===null||o===void 0)n+=4;else if(typeof o==="string")n+=o.length+2;else if(typeof o==="number")n+=8;else if(typeof o==="boolean")n+=5;else if(typeof o==="object"){if(u.has(o))continue;u.add(o);if(Array.isArray(o)){n+=2+o.length;for(let a=0;a<o.length;a++)r.push(o[a])}else{n+=2;for(const a in o){n+=a.length+4;r.push(o[a])}}}else n+=4}return{over:n>t,approxBytes:n}}function truncateData(e,t){if(t===-1){return{data:e,truncated:false}}const{over:n,approxBytes:r}=approxJsonBytesOver(e,t*1024);if(n){return{data:`[Data truncated - \u2265${(r/1024).toFixed(1)}KB exceeds ${t}KB limit]`,truncated:true}}try{JSON.stringify(e);return{data:e,truncated:false}}catch{return{data:"[Unable to serialize data]",truncated:true}}}function estimateExportSize(e,t){let n=0;for(const r of e){if(t.includeSource)n+=20;if(t.includeStatus)n+=10;if(t.includeTitle)n+=(r.title?.length||0)+10;if(t.includeSubtitle)n+=(r.subtitle?.length||0)+10;if(t.includeCorrelation)n+=20;if(t.includeDuration)n+=15;n+=30;if(t.includeEventData&&r.originalEvent){const u=t.dataSizeThreshold===-1?1024*1024:t.dataSizeThreshold*1024;const{approxBytes:o}=approxJsonBytesOver(r.originalEvent,u);n+=Math.min(o,u)}}if(t.includeSummaryHeader)n+=100;if(t.includeTotalDuration)n+=50;if(t.format==="markdown")n*=1.2;if(t.format==="json")n*=1.3;return Math.round(n)}function formatCompactEvent(e,t,n){const r=[];const u=formatTimestamp(e.timestamp,t,n.timestampFormat);r.push(`\`${u}\``);if(n.includeStatus){r.push(STATUS_ICONS[e.status])}if(n.includeSource){r.push(`**${SOURCE_LABELS[e.source]}**`)}if(n.includeTitle){r.push(e.title)}if(n.showStorageDiff&&(e.source==="storage-async"||e.source==="storage-mmkv")){const o=e.originalEvent;if(o?.data){const a=o.data;const i=generateStorageDiffSummary(a.prevValue,a.value);if(i){r.push(`\u2192 ${i}`)}}}if(e.source==="redux"){const o=e.originalEvent;if(o?.hasStateChange===false){r.push("(no state change)")}}if(n.includeSubtitle&&e.subtitle){r.push(`- ${e.subtitle}`)}return r.join(" ")}function generateStorageDiffBlock(e,t){const n=[];const r=e.originalEvent;if(!r?.data)return n;const u=r.data;const o=t.smartJsonParsing?tryParseJson(u.prevValue):u.prevValue;const a=t.smartJsonParsing?tryParseJson(u.value):u.value;const i=generateStorageDiffSummary(u.prevValue,u.value);if(i){n.push(` **Change:** ${i}`)}if(Array.isArray(o)&&Array.isArray(a)){const s=o.map(l=>{if(typeof l==="object"&&l&&"name"in l)return l.name;return null}).filter(Boolean);const c=a.map(l=>{if(typeof l==="object"&&l&&"name"in l)return l.name;return null}).filter(Boolean);if(s.length>0||c.length>0){if(s.length>0){n.push(` Before: [${s.join(", ")}]`)}n.push(` After: [${c.join(", ")}]`)}}return n}function generateMarkdownExport(e,t){const n=filterEvents(e,t);if(n.length===0)return"No events to export.";const r=[...n].sort((s,c)=>s.timestamp-c.timestamp);const u=r[0].timestamp;const o=getExportSummary(r);const a=[];a.push("## Event Flow");if(t.includeSummaryHeader||t.includeTotalDuration){const s=[];if(t.includeTotalDuration){s.push(`**Duration:** ${formatRelativeTime(o.durationMs).replace("+","")}`)}s.push(`**Events:** ${o.totalEvents}`);if(t.includeSummaryHeader){const c=[];if(o.success>0)c.push(`${o.success} ${STATUS_ICONS.success}`);if(o.pending>0)c.push(`${o.pending} ${STATUS_ICONS.pending}`);if(o.error>0)c.push(`${o.error} ${STATUS_ICONS.error}`);if(o.neutral>0)c.push(`${o.neutral} ${STATUS_ICONS.neutral}`);if(c.length>0){s.push(`**Status:** ${c.join(" ")}`)}}a.push(s.join(" | "))}a.push("");a.push("### Timeline");a.push("");if(t.compactMode){r.forEach((s,c)=>{a.push(`${c+1}. ${formatCompactEvent(s,u,t)}`)});return a.join("\n")}r.forEach((s,c)=>{const l=[];const f=formatTimestamp(s.timestamp,u,t.timestampFormat);l.push(`${c+1}. \`${f}\``);if(t.includeStatus){l.push(STATUS_ICONS[s.status])}if(t.includeSource){l.push(`**${SOURCE_LABELS[s.source]}**`)}if(t.includeTitle){l.push(s.title)}if(t.includeCorrelation&&s.correlationId&&s.sequenceInGroup){l.push(`(${s.sequenceInGroup})`)}a.push(l.join(" "));if(t.includeSubtitle&&s.subtitle){a.push(` \u2514\u2500 ${s.subtitle}`)}if(t.showStorageDiff&&!t.includeEventData){if(s.source==="storage-async"||s.source==="storage-mmkv"){const d=generateStorageDiffBlock(s,t);a.push(...d)}}if(t.includeEventData&&s.originalEvent){const d=formatEventData(s,t);const{data:y,truncated:$}=truncateData(d,t.dataSizeThreshold);if($){a.push(` \u2514\u2500 ${y}`)}else{if(t.showStorageDiff&&(s.source==="storage-async"||s.source==="storage-mmkv")){const p=s.originalEvent;if(p?.data){const g=p.data;const h=generateStorageDiffSummary(g.prevValue,g.value);if(h){a.push(` **Change:** ${h}`)}}}a.push(" ```json");a.push(` ${JSON.stringify(y,null,2).split("\n").join("\n ")}`);a.push(" ```")}}a.push("")});const i=r.filter(s=>s.status==="error");if(i.length>0&&t.includeEventData){a.push("---");a.push("");a.push("### Errors");a.push("");for(const s of i){const c=formatTimestamp(s.timestamp,u,t.timestampFormat);a.push(`**${s.title}** (${c})`);if(s.originalEvent){const l=formatEventData(s,t);const{data:f,truncated:d}=truncateData(l,t.dataSizeThreshold);if(!d){a.push("```json");a.push(JSON.stringify(f,null,2));a.push("```")}}a.push("")}}return a.join("\n")}function generateJsonExport(e,t){const n=filterEvents(e,t);if(n.length===0)return"[]";const r=[...n].sort((i,s)=>i.timestamp-s.timestamp);const u=r[0].timestamp;const o=getExportSummary(r);const a={exportedAt:new Date().toISOString()};if(t.includeSummaryHeader){a.summary={totalEvents:o.totalEvents,success:o.success,pending:o.pending,error:o.error,neutral:o.neutral,durationMs:o.durationMs,sources:Array.from(o.sources)}}a.events=r.map(i=>{const s={};s.timestamp=formatAbsoluteTime(i.timestamp);if(t.timestampFormat==="relative"||t.timestampFormat==="both"){s.relativeMs=i.timestamp-u}if(t.includeSource)s.source=i.source;if(t.includeStatus)s.status=i.status;if(t.includeTitle)s.title=i.title;if(t.includeSubtitle)s.subtitle=i.subtitle;if(t.includeCorrelation&&i.correlationId){s.correlationId=i.correlationId;s.sequenceInGroup=i.sequenceInGroup}if(t.includeEventData&&i.originalEvent){const c=formatEventData(i,t);const{data:l,truncated:f}=truncateData(c,t.dataSizeThreshold);s.data=l;if(f)s.dataTruncated=true;if(t.showStorageDiff&&(i.source==="storage-async"||i.source==="storage-mmkv")){const d=i.originalEvent;if(d?.data){const y=d.data;const $=generateStorageDiffSummary(y.prevValue,y.value);if($){s.changeSummary=$}}}}return s});return JSON.stringify(a,null,2)}function generatePlaintextExport(e,t){const n=filterEvents(e,t);if(n.length===0)return"No events to export.";const r=[...n].sort((i,s)=>i.timestamp-s.timestamp);const u=r[0].timestamp;const o=getExportSummary(r);const a=[];if(t.includeSummaryHeader||t.includeTotalDuration){const i=[`Event Flow (${o.totalEvents} events`];if(t.includeTotalDuration){i[0]+=`, ${formatRelativeTime(o.durationMs).replace("+","")}`}i[0]+=")";a.push(i[0]);if(t.includeSummaryHeader){const s=[];if(o.success>0)s.push(`${o.success} success`);if(o.pending>0)s.push(`${o.pending} pending`);if(o.error>0)s.push(`${o.error} error`);if(o.neutral>0)s.push(`${o.neutral} neutral`);if(s.length>0){a.push(s.join(", "))}}a.push("")}for(const i of r){const s=[];const c=formatTimestamp(i.timestamp,u,t.timestampFormat);s.push(c.padEnd(12));if(t.includeStatus){s.push(STATUS_ICONS_ASCII[i.status])}if(t.includeSource){s.push(`${SOURCE_LABELS[i.source]}:`)}if(t.includeTitle){s.push(i.title)}if(t.showStorageDiff&&(i.source==="storage-async"||i.source==="storage-mmkv")){const l=i.originalEvent;if(l?.data){const f=l.data;const d=generateStorageDiffSummary(f.prevValue,f.value);if(d){s.push(`-> ${d}`)}}}if(i.source==="redux"){const l=i.originalEvent;if(l?.hasStateChange===false){s.push("(no change)")}}if(t.includeSubtitle&&i.subtitle){s.push(`- ${i.subtitle}`)}a.push(s.join(" "));if(t.includeEventData&&i.originalEvent){const l=formatEventData(i,t);const{data:f,truncated:d}=truncateData(l,t.dataSizeThreshold);if(d){a.push(` ${f}`)}else{a.push(` Data: ${JSON.stringify(f)}`)}}}return a.join("\n")}const MERMAID_PARTICIPANTS=[{id:"U",icon:"\u{1F464}",label:"User",sources:[],group:"client"},{id:"App",icon:"\u{1F4F1}",label:"App",sources:["route","render"],group:"client"},{id:"Async",icon:"\u{1F4BE}",label:"AsyncStorage",sources:["storage-async"],group:"client"},{id:"MMKV",icon:"\u26A1",label:"MMKV",sources:["storage-mmkv"],group:"client"},{id:"Redux",icon:"\u{1F504}",label:"Redux",sources:["redux"],group:"client"},{id:"API",icon:"\u{1F310}",label:"API",sources:["network"],group:"server"},{id:"Cache",icon:"\u{1F4E6}",label:"QueryCache",sources:["react-query","react-query-query","react-query-mutation"],group:"server"}];function getParticipantId(e){const t=MERMAID_PARTICIPANTS.find(n=>n.sources.includes(e));return t?.id||"App"}function detectParticipants(e){const t=new Set;for(const r of e){t.add(r.source)}const n=[];n.push(MERMAID_PARTICIPANTS[0]);n.push(MERMAID_PARTICIPANTS[1]);for(const r of MERMAID_PARTICIPANTS.slice(2)){if(r.sources.some(u=>t.has(u))){n.push(r)}}return n}function shouldUseGroups(e){const t=e.some(r=>r.group==="client");const n=e.some(r=>r.group==="server");return t&&n&&e.length>=3}function formatMermaidDuration(e){if(e<1e3)return`${e}ms`;if(e<6e4)return`${(e/1e3).toFixed(1)}s`;return`${(e/6e4).toFixed(1)}m`}function escapeMermaidText(e){return e.replace(/[#;:]/g," ").replace(/[\n\r]/g," ").replace(/"/g,"'").replace(/\s+/g," ").trim()}function isInternalStorageKey(e){const t=["last-route","@dev/last","__debug","_persist","devtools/internal"];const n=e.toLowerCase();return t.some(r=>n.includes(r))}function formatBytes(e){if(e<1024)return`${e}B`;if(e<1024*1024)return`${(e/1024).toFixed(1)}KB`;return`${(e/(1024*1024)).toFixed(1)}MB`}function estimateDataSize(e){return approxJsonBytesOver(e,1024*1024).approxBytes}function getCanonicalUrl(e){try{const t=new URL(e,"http://localhost");const n=["timestamp","t","_t","debug","client","version","cache","_"];n.forEach(r=>t.searchParams.delete(r));return t.pathname+(t.searchParams.toString()?"?"+t.searchParams.toString():"")}catch{return e}}function getStorageKeyName(e){let t=e.replace(/^@[\w-]+\//,"").replace(/^devtools\//,"").replace(/^dev\//,"").replace(/^buoy\//,"").replace(/^pokemon\//,"");const n=t.split("/").filter(Boolean);if(n.length>1){t=n.slice(-1).join("/")}t=t.replace(/-/g," ").replace(/_/g," ");t=t.split(" ").map(r=>r.charAt(0).toUpperCase()+r.slice(1).toLowerCase()).join(" ");if(t.toLowerCase()==="saved")t="Favorites";return t.substring(0,20)}function extractEntityFromPath(e){let t=e;try{const r=new URL(e,"http://localhost");t=r.pathname}catch{const r=t.indexOf("?");if(r>0){t=t.substring(0,r)}}const n=t.split("/").filter(Boolean);if(n.length>=2){const r=n[n.length-1];if(/^\d+$/.test(r)||/^[a-f0-9-]{36}$/i.test(r)){return null}return r.charAt(0).toUpperCase()+r.slice(1)}if(n.length===1){return n[0].charAt(0).toUpperCase()+n[0].slice(1)}return null}function getHumanReadableApiAction(e,t){try{const n=new URL(t,"http://localhost");let r=n.pathname;if(r.includes("graphql")){return"GraphQL Request"}r=r.replace(/^\/api\/v\d+/,"").replace(/^\/api/,"");const u=extractEntityFromPath(r);const o=r.split("/").filter(Boolean);const a=o[0]?o[0].charAt(0).toUpperCase()+o[0].slice(1):"Data";const i=n.searchParams.has("q")||n.searchParams.has("query")||n.searchParams.has("search");switch(e.toUpperCase()){case"GET":if(i){const s=n.searchParams.get("q")||n.searchParams.get("query")||n.searchParams.get("search");if(s)return`Search "${s}"`;return`Search ${a}`}if(u)return`Fetch ${u}`;return`Fetch ${a}`;case"POST":if(r.includes("search"))return`Search ${a}`;if(u)return`Create ${u}`;return`Create ${a}`;case"PUT":case"PATCH":if(u)return`Update ${u}`;return`Update ${a}`;case"DELETE":if(u)return`Delete ${u}`;return`Delete ${a}`;default:return`${e} ${a}`}}catch{return`${e} request`}}function getHumanReadableRoute(e){if(e==="/"||e==="")return"Home";const t=e.split("/").filter(Boolean);if(t.length===0)return"Home";if(t.length===1){const n=t[0].charAt(0).toUpperCase()+t[0].slice(1);return`${n} List`}if(t.length>=2){const n=t[t.length-1];if(/^\d+$/.test(n)){const u=t[0].charAt(0).toUpperCase()+t[0].slice(1);return`${u} #${n}`}const r=n.charAt(0).toUpperCase()+n.slice(1);return`${r} Details`}return e}function formatMermaidEvent(e,t,n){const r=[];const u=[];const o=formatMermaidDuration(e.timestamp-n);switch(e.source){case"route":{const a=e.originalEvent;const i=String(a?.pathname||e.title);const s=a?.previousPathname;const c=a?.timeSincePrevious;const l=getHumanReadableRoute(i);const f=s?getHumanReadableRoute(s):null;if(f){r.push(`U->>App: ${f} \u2192 ${l}`);if(c&&c>0){u.push(`Note right of App: ${formatMermaidDuration(c)} on ${f}`)}}else{r.push(`U->>App: Open ${l}`)}break}case"network":{const a=e.originalEvent;const i=a?.method||"GET";const s=a?.url||"";const c=a?.status;const l=a?.duration;const f=a?.response||a?.data||a?.body;const d=a?.responseSize||a?.size||a?.contentLength;const y=getHumanReadableApiAction(i,s);const $=extractEntityFromPath(s);r.push(`App->>+API: ${y}`);if(e.status==="error"){const g=c?`${c} Error`:"Failed";r.push(`API--x-App: ${g}`)}else{let g=$?`\u2713 ${$}`:"\u2713 Success";r.push(`API-->>-App: ${g}`)}const p=[];if(l){p.push(formatMermaidDuration(l))}if(d&&d>0){p.push(formatBytes(d))}else if(f){const g=estimateDataSize(f);if(g>1024){p.push(formatBytes(g))}}if(p.length>0){u.push(`Note right of API: ${p.join(" \xB7 ")}`)}break}case"storage-async":case"storage-mmkv":{const a=e.originalEvent;const i=a?.data;const s=a?.action||"access";const c=i?.key||"data";if(isInternalStorageKey(c)){return{messages:[],notes:[],skip:true}}const l=getStorageKeyName(c);const f=e.source==="storage-mmkv"?"MMKV":"Async";const d=m=>{if(typeof m==="string")return m;if(typeof m==="number")return String(m);if(typeof m==="object"&&m){if("name"in m)return String(m.name);if("id"in m)return String(m.id)}return null};const y=m=>m.charAt(0).toUpperCase()+m.slice(1);let $="";let p="";let g="";let h="";const S=i?.prevValue;const A=i?.value;if(Array.isArray(S)&&Array.isArray(A)){const m=S.length;const D=A.length;h=`${m} \u2192 ${D} items`;if(D>m){$="\u2795";p="Add";const x=new Set(S.map(d).filter(Boolean));for(const E of A){const b=d(E);if(b&&!x.has(b)){g=y(b);break}}}else if(D<m){$="\u2796";p="Remove";const x=new Set(A.map(d).filter(Boolean));for(const E of S){const b=d(E);if(b&&!x.has(b)){g=y(b);break}}}else{$="\u{1F4DD}";p="Update"}}else if(Array.isArray(A)&&(!S||Array.isArray(S)&&S.length===0)){$="\u2795";p="Add";h=`\u2192 ${A.length} items`;if(A.length>0){const m=d(A[0]);if(m)g=y(m)}}else if(Array.isArray(S)&&(!A||Array.isArray(A)&&A.length===0)){$="\u2796";p="Clear";h=`${S.length} \u2192 0 items`}else if(s==="getItem"){$="\u{1F4D6}";p="Load"}else if(s==="removeItem"){$="\u2796";p="Remove"}else if(s==="clear"){$="\u{1F5D1}\uFE0F";p="Clear"}else{$="\u{1F4BE}";p="Save"}let v;if(g){v=`App->>${f}: ${$} ${p} ${g} \u2192 ${l}`}else{v=`App->>${f}: ${$} ${p} ${l}`}r.push(v);if(h){u.push(`Note right of ${f}: ${h}`)}break}case"react-query":case"react-query-query":{const a=e.originalEvent;const i=a?.type||"";const s=a?.queryKey;const c=a?.duration;let l="data";if(Array.isArray(s)&&s.length>0){const f=s[s.length-1];if(typeof f==="string"&&!/^\d+$/.test(f)){l=f.charAt(0).toUpperCase()+f.slice(1)}else if(s.length>1&&typeof s[0]==="string"){l=s[0].charAt(0).toUpperCase()+s[0].slice(1)}}if(i.includes("start")||i.includes("fetch")||e.status==="pending"){r.push(`App->>+Cache: Fetch ${l}`)}else if(e.status==="error"){r.push(`Cache--x-App: Failed to load`)}else if(e.status==="success"){let f=`\u2713 ${l} ready`;if(c){f+=` (${formatMermaidDuration(c)})`}r.push(`Cache-->>-App: ${f}`)}else if(i.includes("invalidate")){r.push(`App->>Cache: Refresh ${l}`)}else{r.push(`Cache-->>App: ${escapeMermaidText(i)}`)}break}case"react-query-mutation":{const a=e.originalEvent;const i=a?.type||"";const s=a?.mutationKey;const c=a?.duration;let l="Update";if(Array.isArray(s)&&s.length>0){const f=String(s[0]);if(f.includes("add")||f.includes("create"))l="Add";else if(f.includes("delete")||f.includes("remove"))l="Delete";else if(f.includes("update")||f.includes("edit"))l="Update";else l=f.charAt(0).toUpperCase()+f.slice(1)}if(i.includes("start")||i.includes("loading")||e.status==="pending"){r.push(`App->>+Cache: ${l}`)}else if(e.status==="error"){r.push(`Cache--x-App: ${l} failed`)}else if(e.status==="success"){let f=`\u2713 ${l} complete`;if(c){f+=` (${formatMermaidDuration(c)})`}r.push(`Cache-->>-App: ${f}`)}break}case"redux":{const a=e.originalEvent;const i=a?.type||e.title;const s=a?.hasStateChange;const c=a?.diffSummary;const l=i.split("/");let f;if(l.length>=2){const d=l[0].charAt(0).toUpperCase()+l[0].slice(1);let y=l[1].replace(/([A-Z])/g," $1").replace(/(pending|fulfilled|rejected)$/i,"").trim();y=y.charAt(0).toUpperCase()+y.slice(1);f=`${y} (${d})`}else{f=escapeMermaidText(i).substring(0,25)}r.push(`App->>Redux: ${f}`);if(s===false){u.push(`Note right of Redux: No change`)}else if(c){u.push(`Note right of Redux: ${escapeMermaidText(c).substring(0,35)}`)}break}case"render":{const a=e.originalEvent;const i=a?.renderData;const s=escapeMermaidText(e.title).substring(0,20);const c=i?.cause||"update";const l=c==="mount"?"mounted":c==="props"?"props changed":c==="state"?"state changed":c==="context"?"context changed":c==="parent"?"parent re-rendered":c==="hooks"?"hook changed":c;r.push(`App->>App: Render ${s}`);u.push(`Note right of App: ${l}`);break}default:{r.push(`App->>App: ${escapeMermaidText(e.title).substring(0,30)}`)}}return{messages:r,notes:u}}function generateMermaidExport(e,t){const n=filterEvents(e,t);if(n.length===0){return"sequenceDiagram\n participant U as \u{1F464} User\n participant App as \u{1F4F1} App\n Note over U,App: No events captured"}const r=[...n].sort((p,g)=>p.timestamp-g.timestamp);const u=r[0].timestamp;const o=detectParticipants(r);const a=shouldUseGroups(o);const i=["sequenceDiagram"];i.push(" autonumber");i.push("");if(a){const p=o.filter(h=>h.group==="client");const g=o.filter(h=>h.group==="server");if(p.length>0){i.push(" box rgb(240, 248, 255) Client");for(const h of p){i.push(` participant ${h.id} as ${h.icon} ${h.label}`)}i.push(" end")}if(g.length>0){i.push(" box rgb(255, 248, 240) External");for(const h of g){i.push(` participant ${h.id} as ${h.icon} ${h.label}`)}i.push(" end")}}else{for(const p of o){i.push(` participant ${p.id} as ${p.icon} ${p.label}`)}}i.push("");const s=r[r.length-1].timestamp-u;const c=r.filter(p=>p.source==="network");const l=c.reduce((p,g)=>{const h=g.originalEvent;const S=h?.responseSize||h?.size||0;return p+S},0);const f=r.filter(p=>p.status==="error").length;const d=[];d.push(`\u23F1\uFE0F ${formatMermaidDuration(s)}`);d.push(`\u{1F4CA} ${r.length} events`);if(c.length>0){d.push(`\u{1F310} ${c.length} API calls`)}if(l>0){d.push(`\u{1F4E6} ${formatBytes(l)}`)}if(f>0){d.push(`\u274C ${f} errors`)}i.push(` Note over U,API: ${d.join(" \xB7 ")}`);i.push("");const y=new Map;let $=0;for(const p of r){const g=formatMermaidEvent(p,t,u);if(g.skip){$++;continue}const{messages:h,notes:S}=g;let A=false;let v="";if(p.source==="network"){const m=p.originalEvent;const D=m?.url;if(D){const x=getCanonicalUrl(D);const E=y.get(x);if(E&&p.timestamp-E.timestamp<3e4){A=true;const b=p.timestamp-E.timestamp;const C=formatMermaidDuration(b);v=`\u26A0\uFE0F Already fetched ${C} ago`;y.set(x,{timestamp:p.timestamp,count:E.count+1})}else{y.set(x,{timestamp:p.timestamp,count:1})}}}if(A){i.push(" rect rgb(255, 245, 230)");i.push(` Note over App,API: ${v}`);for(const m of h){i.push(` ${m}`)}for(const m of S){i.push(` ${m}`)}i.push(" end")}else if(p.status==="error"){i.push(" rect rgb(255, 235, 235)");for(const m of h){i.push(` ${m}`)}for(const m of S){i.push(` ${m}`)}i.push(" end")}else{for(const m of h){i.push(` ${m}`)}for(const m of S){i.push(` ${m}`)}}}if($>0){i.push("");i.push(` Note over App: ${$} internal events hidden`)}return i.join("\n")}function generateExport(e,t){switch(t.format){case"markdown":return generateMarkdownExport(e,t);case"json":return generateJsonExport(e,t);case"plaintext":return generatePlaintextExport(e,t);case"mermaid":return generateMermaidExport(e,t);default:return generateMarkdownExport(e,t)}}
|