@buoy-gg/events 7.0.29 → 7.0.31
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/lib/commonjs/components/EventsCopySettingsView.js +15 -1
- package/lib/commonjs/components/EventsCopySettingsView.js.map +1 -1
- package/lib/commonjs/components/EventsModal.js +28 -7
- package/lib/commonjs/components/EventsModal.js.map +1 -1
- package/lib/commonjs/components/UnifiedEventDetail.js +23 -3
- package/lib/commonjs/components/UnifiedEventDetail.js.map +1 -1
- package/lib/commonjs/components/UnifiedEventFilters.js +15 -0
- package/lib/commonjs/components/UnifiedEventFilters.js.map +1 -1
- package/lib/commonjs/components/UnifiedEventItem.js +23 -6
- package/lib/commonjs/components/UnifiedEventItem.js.map +1 -1
- package/lib/commonjs/components/UnifiedEventList.js +13 -1
- package/lib/commonjs/components/UnifiedEventList.js.map +1 -1
- package/lib/commonjs/hooks/useUnifiedEvents.js +118 -117
- package/lib/commonjs/hooks/useUnifiedEvents.js.map +1 -1
- package/lib/commonjs/index.js +25 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/stores/unifiedEventStore.js +57 -3
- package/lib/commonjs/stores/unifiedEventStore.js.map +1 -1
- package/lib/commonjs/utils/autoDiscoverEventSources.js +54 -0
- package/lib/commonjs/utils/autoDiscoverEventSources.js.map +1 -1
- package/lib/commonjs/utils/badgeSelectionStorage.js +36 -0
- package/lib/commonjs/utils/badgeSelectionStorage.js.map +1 -1
- package/lib/commonjs/utils/testIDs.js +91 -0
- package/lib/commonjs/utils/testIDs.js.map +1 -0
- package/lib/module/components/EventsCopySettingsView.js +15 -1
- package/lib/module/components/EventsCopySettingsView.js.map +1 -1
- package/lib/module/components/EventsModal.js +30 -8
- package/lib/module/components/EventsModal.js.map +1 -1
- package/lib/module/components/UnifiedEventDetail.js +23 -3
- package/lib/module/components/UnifiedEventDetail.js.map +1 -1
- package/lib/module/components/UnifiedEventFilters.js +15 -0
- package/lib/module/components/UnifiedEventFilters.js.map +1 -1
- package/lib/module/components/UnifiedEventItem.js +23 -6
- package/lib/module/components/UnifiedEventItem.js.map +1 -1
- package/lib/module/components/UnifiedEventList.js +13 -1
- package/lib/module/components/UnifiedEventList.js.map +1 -1
- package/lib/module/hooks/useUnifiedEvents.js +120 -119
- package/lib/module/hooks/useUnifiedEvents.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/stores/unifiedEventStore.js +54 -1
- package/lib/module/stores/unifiedEventStore.js.map +1 -1
- package/lib/module/utils/autoDiscoverEventSources.js +54 -0
- package/lib/module/utils/autoDiscoverEventSources.js.map +1 -1
- package/lib/module/utils/badgeSelectionStorage.js +34 -0
- package/lib/module/utils/badgeSelectionStorage.js.map +1 -1
- package/lib/module/utils/testIDs.js +83 -0
- package/lib/module/utils/testIDs.js.map +1 -0
- package/lib/typescript/components/EventsCopySettingsView.d.ts.map +1 -1
- package/lib/typescript/components/EventsModal.d.ts.map +1 -1
- package/lib/typescript/components/UnifiedEventDetail.d.ts.map +1 -1
- package/lib/typescript/components/UnifiedEventFilters.d.ts.map +1 -1
- package/lib/typescript/components/UnifiedEventItem.d.ts.map +1 -1
- package/lib/typescript/components/UnifiedEventList.d.ts.map +1 -1
- package/lib/typescript/hooks/useUnifiedEvents.d.ts +10 -1
- package/lib/typescript/hooks/useUnifiedEvents.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/stores/unifiedEventStore.d.ts +13 -0
- package/lib/typescript/stores/unifiedEventStore.d.ts.map +1 -1
- package/lib/typescript/utils/autoDiscoverEventSources.d.ts.map +1 -1
- package/lib/typescript/utils/badgeSelectionStorage.d.ts +9 -0
- package/lib/typescript/utils/badgeSelectionStorage.d.ts.map +1 -1
- package/lib/typescript/utils/testIDs.d.ts +45 -0
- package/lib/typescript/utils/testIDs.d.ts.map +1 -0
- package/package.json +7 -8
- package/src/components/EventsCopySettingsView.tsx +0 -781
- package/src/components/EventsModal.tsx +0 -537
- package/src/components/ReactQueryEventDetail.tsx +0 -418
- package/src/components/UnifiedEventDetail.tsx +0 -596
- package/src/components/UnifiedEventFilters.tsx +0 -226
- package/src/components/UnifiedEventItem.tsx +0 -467
- package/src/components/UnifiedEventList.tsx +0 -216
- package/src/components/UnifiedEventViewer.tsx +0 -133
- package/src/hooks/useUnifiedEvents.ts +0 -573
- package/src/index.tsx +0 -128
- package/src/preset.tsx +0 -57
- package/src/sources/sourceIds.ts +0 -25
- package/src/stores/unifiedEventStore.ts +0 -686
- package/src/sync/__tests__/eventsSyncAdapter.test.ts +0 -471
- package/src/sync/eventsSyncAdapter.ts +0 -391
- package/src/types/copySettings.ts +0 -299
- package/src/types/index.ts +0 -101
- package/src/utils/autoDiscoverEventSources.ts +0 -1087
- package/src/utils/badgeSelectionStorage.ts +0 -81
- package/src/utils/copySettingsStorage.ts +0 -61
- package/src/utils/correlationUtils.ts +0 -146
- package/src/utils/eventExportFormatter.ts +0 -2066
- package/src/utils/eventTransformers.ts +0 -567
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { UnifiedEvent } from "../../types";
|
|
3
|
-
import { unifiedEventStore } from "../../stores/unifiedEventStore";
|
|
4
|
-
import { eventsSyncAdapter } from "../eventsSyncAdapter";
|
|
5
|
-
|
|
6
|
-
function jsonClone<T>(value: T): T {
|
|
7
|
-
return JSON.parse(JSON.stringify(value)) as T;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function makeEvent(overrides: Partial<UnifiedEvent> = {}): UnifiedEvent {
|
|
11
|
-
return {
|
|
12
|
-
id: "evt-1",
|
|
13
|
-
source: "network",
|
|
14
|
-
timestamp: Date.now(),
|
|
15
|
-
title: "GET /users",
|
|
16
|
-
subtitle: "200",
|
|
17
|
-
status: "success",
|
|
18
|
-
originalEvent: { url: "/users" },
|
|
19
|
-
...overrides,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
unifiedEventStore.clearEvents();
|
|
25
|
-
// Skip package auto-discovery (would load RN storage/network in Node).
|
|
26
|
-
unifiedEventStore.setRemoteAvailableSources(["network", "redux"]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
unifiedEventStore.clearEvents();
|
|
31
|
-
unifiedEventStore.setRemoteAvailableSources(null);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("eventsSyncAdapter", () => {
|
|
35
|
-
it("exposes version 2 and the listed actions", () => {
|
|
36
|
-
expect(eventsSyncAdapter.version).toBe(2);
|
|
37
|
-
expect(Object.keys(eventsSyncAdapter.actions)).toEqual(
|
|
38
|
-
expect.arrayContaining(["clearEvents", "setEnabledSources", "exportEvents"]),
|
|
39
|
-
);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("snapshots { events, availableSources } as JSON", () => {
|
|
43
|
-
unifiedEventStore.replaceEvents([makeEvent()]);
|
|
44
|
-
const snapshot = eventsSyncAdapter.getSnapshot();
|
|
45
|
-
expect(snapshot.events).toHaveLength(1);
|
|
46
|
-
expect(snapshot.availableSources).toEqual(
|
|
47
|
-
expect.arrayContaining(["network", "redux"]),
|
|
48
|
-
);
|
|
49
|
-
expect(() => JSON.stringify(snapshot)).not.toThrow();
|
|
50
|
-
expect(jsonClone(snapshot).events[0]?.id).toBe(snapshot.events[0]?.id);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("truncates oversized originalEvent payloads", () => {
|
|
54
|
-
unifiedEventStore.replaceEvents([
|
|
55
|
-
makeEvent({
|
|
56
|
-
id: "huge",
|
|
57
|
-
originalEvent: { body: "x".repeat(20 * 1024) },
|
|
58
|
-
}),
|
|
59
|
-
]);
|
|
60
|
-
const [event] = eventsSyncAdapter.getSnapshot().events;
|
|
61
|
-
expect(event?.originalEvent).toEqual(
|
|
62
|
-
expect.objectContaining({ __buoyTruncated: true }),
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("omits redux, zustand, and jotai state trees from the wire copy", () => {
|
|
67
|
-
unifiedEventStore.replaceEvents([
|
|
68
|
-
makeEvent({
|
|
69
|
-
id: "redux-1",
|
|
70
|
-
source: "redux",
|
|
71
|
-
title: "user/set",
|
|
72
|
-
originalEvent: {
|
|
73
|
-
type: "user/set",
|
|
74
|
-
payload: { name: "Ada" },
|
|
75
|
-
prevState: { user: { name: "old" } },
|
|
76
|
-
nextState: { user: { name: "Ada" } },
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
79
|
-
]);
|
|
80
|
-
const reduxOriginal = eventsSyncAdapter.getSnapshot().events[0]
|
|
81
|
-
?.originalEvent as Record<string, unknown>;
|
|
82
|
-
expect(reduxOriginal.prevState).toEqual(
|
|
83
|
-
expect.objectContaining({ __buoyOmitted: "state-tree" }),
|
|
84
|
-
);
|
|
85
|
-
expect(reduxOriginal.payload).toEqual({ name: "Ada" });
|
|
86
|
-
|
|
87
|
-
unifiedEventStore.replaceEvents([
|
|
88
|
-
makeEvent({
|
|
89
|
-
id: "zustand-1",
|
|
90
|
-
source: "zustand",
|
|
91
|
-
title: "counter",
|
|
92
|
-
originalEvent: {
|
|
93
|
-
storeName: "counter",
|
|
94
|
-
partial: { count: 1 },
|
|
95
|
-
prevState: { count: 0 },
|
|
96
|
-
nextState: { count: 1 },
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
]);
|
|
100
|
-
const zustandOriginal = eventsSyncAdapter.getSnapshot().events[0]
|
|
101
|
-
?.originalEvent as Record<string, unknown>;
|
|
102
|
-
expect(zustandOriginal.prevState).toEqual(
|
|
103
|
-
expect.objectContaining({ __buoyOmitted: "state-tree" }),
|
|
104
|
-
);
|
|
105
|
-
expect(zustandOriginal.partial).toEqual(
|
|
106
|
-
expect.objectContaining({ __buoyOmitted: "state-tree" }),
|
|
107
|
-
);
|
|
108
|
-
expect(zustandOriginal.storeName).toBe("counter");
|
|
109
|
-
|
|
110
|
-
unifiedEventStore.replaceEvents([
|
|
111
|
-
makeEvent({
|
|
112
|
-
id: "jotai-1",
|
|
113
|
-
source: "jotai",
|
|
114
|
-
title: "count",
|
|
115
|
-
originalEvent: {
|
|
116
|
-
atomLabel: "count",
|
|
117
|
-
prevValue: 0,
|
|
118
|
-
nextValue: 1,
|
|
119
|
-
},
|
|
120
|
-
}),
|
|
121
|
-
]);
|
|
122
|
-
const jotaiOriginal = eventsSyncAdapter.getSnapshot().events[0]
|
|
123
|
-
?.originalEvent as Record<string, unknown>;
|
|
124
|
-
expect(jotaiOriginal.prevValue).toEqual(
|
|
125
|
-
expect.objectContaining({ __buoyOmitted: "state-tree" }),
|
|
126
|
-
);
|
|
127
|
-
expect(jotaiOriginal.atomLabel).toBe("count");
|
|
128
|
-
|
|
129
|
-
unifiedEventStore.replaceEvents([
|
|
130
|
-
makeEvent({
|
|
131
|
-
id: "render-1",
|
|
132
|
-
source: "render",
|
|
133
|
-
title: "View",
|
|
134
|
-
originalEvent: {
|
|
135
|
-
event: {
|
|
136
|
-
id: "1-1",
|
|
137
|
-
timestamp: Date.now(),
|
|
138
|
-
renderNumber: 3,
|
|
139
|
-
capturedProps: { user: { name: "Ada" } },
|
|
140
|
-
cause: {
|
|
141
|
-
type: "hooks",
|
|
142
|
-
hookChanges: [{ index: 0, type: "useState", currentValue: { big: true } }],
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
render: {
|
|
146
|
-
nativeTag: 1,
|
|
147
|
-
displayName: "View",
|
|
148
|
-
renderHistory: [{ id: "1-1", timestamp: 1, renderNumber: 1, cause: { type: "mount" } }],
|
|
149
|
-
lastRenderCause: {
|
|
150
|
-
type: "hooks",
|
|
151
|
-
hookChanges: [{ index: 0, currentValue: { nested: true } }],
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
}),
|
|
156
|
-
]);
|
|
157
|
-
const renderOriginal = eventsSyncAdapter.getSnapshot().events[0]
|
|
158
|
-
?.originalEvent as {
|
|
159
|
-
event?: { capturedProps?: unknown; cause?: { hookChanges?: unknown } };
|
|
160
|
-
render?: { renderHistory?: unknown; lastRenderCause?: { hookChanges?: unknown } };
|
|
161
|
-
};
|
|
162
|
-
expect(renderOriginal.render?.renderHistory).toBeUndefined();
|
|
163
|
-
expect(renderOriginal.render?.lastRenderCause?.hookChanges).toBeUndefined();
|
|
164
|
-
expect(renderOriginal.event?.capturedProps).toBeUndefined();
|
|
165
|
-
expect(renderOriginal.event?.cause?.hookChanges).toBeUndefined();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("keeps react-query type/key when the live Query object is cyclic", () => {
|
|
169
|
-
const cyclic: { self?: unknown } = {};
|
|
170
|
-
cyclic.self = cyclic;
|
|
171
|
-
unifiedEventStore.replaceEvents([
|
|
172
|
-
makeEvent({
|
|
173
|
-
id: "rq-1",
|
|
174
|
-
source: "react-query-query",
|
|
175
|
-
title: "users",
|
|
176
|
-
originalEvent: {
|
|
177
|
-
type: "query-fetch-success",
|
|
178
|
-
queryKey: ["users"],
|
|
179
|
-
queryHash: "abc",
|
|
180
|
-
duration: 12,
|
|
181
|
-
queryData: { id: 1 },
|
|
182
|
-
query: cyclic,
|
|
183
|
-
},
|
|
184
|
-
}),
|
|
185
|
-
]);
|
|
186
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
187
|
-
?.originalEvent as Record<string, unknown>;
|
|
188
|
-
expect(original.type).toBe("query-fetch-success");
|
|
189
|
-
expect(original.queryKey).toEqual(["users"]);
|
|
190
|
-
expect(original.duration).toBe(12);
|
|
191
|
-
expect(original.query).toBeUndefined();
|
|
192
|
-
expect(original.queryData).toEqual({ id: 1 });
|
|
193
|
-
expect(original.__buoyTruncated).toBeUndefined();
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("omits oversized react-query cache data from the wire copy", () => {
|
|
197
|
-
unifiedEventStore.replaceEvents([
|
|
198
|
-
makeEvent({
|
|
199
|
-
id: "rq-big",
|
|
200
|
-
source: "react-query-query",
|
|
201
|
-
title: "users",
|
|
202
|
-
originalEvent: {
|
|
203
|
-
type: "query-fetch-success",
|
|
204
|
-
queryKey: ["users"],
|
|
205
|
-
queryData: { blob: "x".repeat(20 * 1024) },
|
|
206
|
-
},
|
|
207
|
-
}),
|
|
208
|
-
]);
|
|
209
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
210
|
-
?.originalEvent as Record<string, unknown>;
|
|
211
|
-
expect(original.type).toBe("query-fetch-success");
|
|
212
|
-
expect(original.queryKey).toEqual(["users"]);
|
|
213
|
-
expect(original.queryData).toEqual(
|
|
214
|
-
expect.objectContaining({ __buoyOmitted: "query-payload" }),
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("keeps network method/url when the body is oversized", () => {
|
|
219
|
-
unifiedEventStore.replaceEvents([
|
|
220
|
-
makeEvent({
|
|
221
|
-
id: "net-1",
|
|
222
|
-
source: "network",
|
|
223
|
-
title: "GET /users",
|
|
224
|
-
originalEvent: {
|
|
225
|
-
method: "GET",
|
|
226
|
-
url: "https://api.example.com/users",
|
|
227
|
-
status: 200,
|
|
228
|
-
requestHeaders: {},
|
|
229
|
-
responseHeaders: {},
|
|
230
|
-
responseData: "x".repeat(20 * 1024),
|
|
231
|
-
responseSize: 20 * 1024,
|
|
232
|
-
},
|
|
233
|
-
}),
|
|
234
|
-
]);
|
|
235
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
236
|
-
?.originalEvent as Record<string, unknown>;
|
|
237
|
-
expect(original.method).toBe("GET");
|
|
238
|
-
expect(original.url).toBe("https://api.example.com/users");
|
|
239
|
-
expect(original.status).toBe(200);
|
|
240
|
-
expect(original.responseData).toEqual(
|
|
241
|
-
expect.objectContaining({ __buoyOmitted: "network-body" }),
|
|
242
|
-
);
|
|
243
|
-
expect(original.__buoyTruncated).toBeUndefined();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("keeps network method/url when graphqlVariables are oversized", () => {
|
|
247
|
-
unifiedEventStore.replaceEvents([
|
|
248
|
-
makeEvent({
|
|
249
|
-
id: "gql-1",
|
|
250
|
-
source: "network",
|
|
251
|
-
title: "GetPokemon",
|
|
252
|
-
originalEvent: {
|
|
253
|
-
method: "POST",
|
|
254
|
-
url: "https://api.example.com/graphql",
|
|
255
|
-
status: 200,
|
|
256
|
-
requestClient: "graphql",
|
|
257
|
-
operationName: "GetPokemon",
|
|
258
|
-
graphqlVariables: {
|
|
259
|
-
id: "Sandshrew",
|
|
260
|
-
file: "x".repeat(20 * 1024),
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
}),
|
|
264
|
-
]);
|
|
265
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
266
|
-
?.originalEvent as Record<string, unknown>;
|
|
267
|
-
expect(original.method).toBe("POST");
|
|
268
|
-
expect(original.operationName).toBe("GetPokemon");
|
|
269
|
-
expect(original.graphqlVariables).toEqual(
|
|
270
|
-
expect.objectContaining({ __buoyOmitted: "graphql-variables" }),
|
|
271
|
-
);
|
|
272
|
-
expect(original.__buoyTruncated).toBeUndefined();
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("keeps network method/url when headers are oversized", () => {
|
|
276
|
-
unifiedEventStore.replaceEvents([
|
|
277
|
-
makeEvent({
|
|
278
|
-
id: "net-headers",
|
|
279
|
-
source: "network",
|
|
280
|
-
title: "GET /users",
|
|
281
|
-
originalEvent: {
|
|
282
|
-
method: "GET",
|
|
283
|
-
url: "https://api.example.com/users",
|
|
284
|
-
status: 200,
|
|
285
|
-
requestHeaders: { cookie: "session=" + "a".repeat(20 * 1024) },
|
|
286
|
-
responseHeaders: {},
|
|
287
|
-
},
|
|
288
|
-
}),
|
|
289
|
-
]);
|
|
290
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
291
|
-
?.originalEvent as Record<string, unknown>;
|
|
292
|
-
expect(original.method).toBe("GET");
|
|
293
|
-
expect(original.url).toBe("https://api.example.com/users");
|
|
294
|
-
expect(original.status).toBe(200);
|
|
295
|
-
expect(original.requestHeaders).toEqual(
|
|
296
|
-
expect.objectContaining({ __buoyOmitted: "network-headers" }),
|
|
297
|
-
);
|
|
298
|
-
expect(original.__buoyTruncated).toBeUndefined();
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("keeps storage action/key when the value is oversized", () => {
|
|
302
|
-
unifiedEventStore.replaceEvents([
|
|
303
|
-
makeEvent({
|
|
304
|
-
id: "st-1",
|
|
305
|
-
source: "storage-async",
|
|
306
|
-
title: "Set Item",
|
|
307
|
-
originalEvent: {
|
|
308
|
-
action: "setItem",
|
|
309
|
-
data: { key: "session", value: "x".repeat(20 * 1024) },
|
|
310
|
-
},
|
|
311
|
-
}),
|
|
312
|
-
]);
|
|
313
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
314
|
-
?.originalEvent as { action?: string; data?: { key?: string; value?: unknown } };
|
|
315
|
-
expect(original.action).toBe("setItem");
|
|
316
|
-
expect(original.data?.key).toBe("session");
|
|
317
|
-
expect(original.data?.value).toEqual(
|
|
318
|
-
expect.objectContaining({ __buoyOmitted: "storage-value" }),
|
|
319
|
-
);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("keeps route pathname when params are oversized", () => {
|
|
323
|
-
unifiedEventStore.replaceEvents([
|
|
324
|
-
makeEvent({
|
|
325
|
-
id: "route-1",
|
|
326
|
-
source: "route",
|
|
327
|
-
title: "/profile",
|
|
328
|
-
originalEvent: {
|
|
329
|
-
pathname: "/profile",
|
|
330
|
-
segments: ["profile"],
|
|
331
|
-
timestamp: Date.now(),
|
|
332
|
-
params: { user: { blob: "x".repeat(20 * 1024) } },
|
|
333
|
-
},
|
|
334
|
-
}),
|
|
335
|
-
]);
|
|
336
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
337
|
-
?.originalEvent as {
|
|
338
|
-
pathname?: string;
|
|
339
|
-
params?: { __buoyOmitted?: string };
|
|
340
|
-
};
|
|
341
|
-
expect(original.pathname).toBe("/profile");
|
|
342
|
-
expect(original.params).toEqual(
|
|
343
|
-
expect.objectContaining({ __buoyOmitted: "route-params" }),
|
|
344
|
-
);
|
|
345
|
-
expect(
|
|
346
|
-
(original as { __buoyTruncated?: boolean }).__buoyTruncated,
|
|
347
|
-
).toBeUndefined();
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
it("does not hang on empty action params", () => {
|
|
351
|
-
expect(eventsSyncAdapter.actions.setEnabledSources()).toEqual({
|
|
352
|
-
enabledSources: [],
|
|
353
|
-
});
|
|
354
|
-
const exported = eventsSyncAdapter.actions.exportEvents();
|
|
355
|
-
expect(exported).toEqual(
|
|
356
|
-
expect.objectContaining({
|
|
357
|
-
output: expect.any(String),
|
|
358
|
-
returned: 0,
|
|
359
|
-
totalAvailable: 0,
|
|
360
|
-
}),
|
|
361
|
-
);
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
it("keeps an event whose payload merely SHARES a reference twice", () => {
|
|
365
|
-
// Structural sharing is not a cycle. `{ user, currentUser }` pointing at
|
|
366
|
-
// the same object is ordinary in redux/react-query payloads, and it is
|
|
367
|
-
// perfectly JSON-serializable — stringify just writes it twice.
|
|
368
|
-
//
|
|
369
|
-
// The size walk cannot tell the two apart (it dedupes by identity to stay
|
|
370
|
-
// O(limit)), so treating "saw a repeat" as "cyclic" throws away the WHOLE
|
|
371
|
-
// event — type, title and all — for a payload that was always safe to send.
|
|
372
|
-
const user = { id: 7, name: "Ada" };
|
|
373
|
-
unifiedEventStore.replaceEvents([
|
|
374
|
-
makeEvent({
|
|
375
|
-
id: "shared-1",
|
|
376
|
-
source: "redux",
|
|
377
|
-
title: "user/select",
|
|
378
|
-
originalEvent: {
|
|
379
|
-
type: "user/select",
|
|
380
|
-
payload: { user, currentUser: user },
|
|
381
|
-
},
|
|
382
|
-
}),
|
|
383
|
-
]);
|
|
384
|
-
|
|
385
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
386
|
-
?.originalEvent as Record<string, unknown>;
|
|
387
|
-
expect(original.__buoyTruncated).toBeUndefined();
|
|
388
|
-
expect(original.type).toBe("user/select");
|
|
389
|
-
expect(original.payload).toEqual({ user, currentUser: user });
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it("still truncates a genuinely cyclic payload, and a bigint", () => {
|
|
393
|
-
// The relaxation above is only safe because a CONFIRMED failure still
|
|
394
|
-
// truncates. A real cycle reaching socket.emit makes stringify throw,
|
|
395
|
-
// safeEmit swallows it, and the timeline silently stops updating.
|
|
396
|
-
const cyclic: { self?: unknown; type: string } = { type: "boom" };
|
|
397
|
-
cyclic.self = cyclic;
|
|
398
|
-
unifiedEventStore.replaceEvents([
|
|
399
|
-
makeEvent({ id: "cyc", source: "redux", originalEvent: cyclic }),
|
|
400
|
-
makeEvent({
|
|
401
|
-
id: "big",
|
|
402
|
-
source: "redux",
|
|
403
|
-
originalEvent: { type: "n", payload: { n: BigInt(9007199254740993n) } },
|
|
404
|
-
}),
|
|
405
|
-
]);
|
|
406
|
-
|
|
407
|
-
const snapshot = eventsSyncAdapter.getSnapshot();
|
|
408
|
-
const byId = Object.fromEntries(snapshot.events.map((e) => [e.id, e]));
|
|
409
|
-
expect(
|
|
410
|
-
(byId.cyc.originalEvent as { __buoyTruncated?: boolean }).__buoyTruncated,
|
|
411
|
-
).toBe(true);
|
|
412
|
-
expect(
|
|
413
|
-
(byId.big.originalEvent as { __buoyTruncated?: boolean }).__buoyTruncated,
|
|
414
|
-
).toBe(true);
|
|
415
|
-
expect(() => JSON.stringify(snapshot)).not.toThrow();
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
// ---------------------------------------------------------------------
|
|
419
|
-
// Cost guards. This adapter compacts payloads from EVERY other tool, so it
|
|
420
|
-
// is the one most exposed to a fat field. These assert the mechanism, never
|
|
421
|
-
// wall-clock, so they cannot go flaky.
|
|
422
|
-
// ---------------------------------------------------------------------
|
|
423
|
-
|
|
424
|
-
it("never JSON.stringifies an oversized field to decide it is oversized", () => {
|
|
425
|
-
// `JSON.stringify` visits every node and calls `toJSON`; the O(limit) walk
|
|
426
|
-
// does not. Stringify-first is O(payload) — the freeze these guards exist
|
|
427
|
-
// to prevent.
|
|
428
|
-
const touched = vi.fn(() => "serialized");
|
|
429
|
-
unifiedEventStore.replaceEvents([
|
|
430
|
-
makeEvent({
|
|
431
|
-
id: "fat",
|
|
432
|
-
source: "network",
|
|
433
|
-
originalEvent: {
|
|
434
|
-
method: "GET",
|
|
435
|
-
url: "https://api.example.com/x",
|
|
436
|
-
responseData: {
|
|
437
|
-
pad: "x".repeat(20 * 1024),
|
|
438
|
-
nested: { deep: { toJSON: touched } },
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
}),
|
|
442
|
-
]);
|
|
443
|
-
|
|
444
|
-
const original = eventsSyncAdapter.getSnapshot().events[0]
|
|
445
|
-
?.originalEvent as Record<string, unknown>;
|
|
446
|
-
expect(original.method).toBe("GET");
|
|
447
|
-
expect(original.responseData).toEqual(
|
|
448
|
-
expect.objectContaining({ __buoyOmitted: "network-body" }),
|
|
449
|
-
);
|
|
450
|
-
expect(touched).not.toHaveBeenCalled();
|
|
451
|
-
});
|
|
452
|
-
|
|
453
|
-
it("reuses the compacted form of an unchanged event across snapshots", () => {
|
|
454
|
-
// Events are immutable once created, so compaction is computed once and
|
|
455
|
-
// drops out with the event. Without that, every snapshot re-walks all 200
|
|
456
|
-
// events' payloads, ~5x/sec.
|
|
457
|
-
unifiedEventStore.replaceEvents([
|
|
458
|
-
makeEvent({ id: "a", source: "network" }),
|
|
459
|
-
makeEvent({
|
|
460
|
-
id: "b",
|
|
461
|
-
source: "redux",
|
|
462
|
-
originalEvent: { type: "x", prevState: { a: 1 }, nextState: { a: 2 } },
|
|
463
|
-
}),
|
|
464
|
-
]);
|
|
465
|
-
|
|
466
|
-
const first = eventsSyncAdapter.getSnapshot().events;
|
|
467
|
-
const second = eventsSyncAdapter.getSnapshot().events;
|
|
468
|
-
expect(second[0]).toBe(first[0]);
|
|
469
|
-
expect(second[1]).toBe(first[1]);
|
|
470
|
-
});
|
|
471
|
-
});
|