@buoy-gg/events 7.0.5 → 7.0.6
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/sync/eventsSyncAdapter.js +51 -1
- package/lib/commonjs/sync/eventsSyncAdapter.js.map +1 -1
- package/lib/module/sync/eventsSyncAdapter.js +51 -1
- package/lib/module/sync/eventsSyncAdapter.js.map +1 -1
- package/lib/typescript/sync/eventsSyncAdapter.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/sync/eventsSyncAdapter.ts +58 -1
|
@@ -7,6 +7,56 @@ exports.eventsSyncAdapter = void 0;
|
|
|
7
7
|
var _unifiedEventStore = require("../stores/unifiedEventStore");
|
|
8
8
|
var _eventExportFormatter = require("../utils/eventExportFormatter");
|
|
9
9
|
var _copySettings = require("../types/copySettings");
|
|
10
|
+
// ==========================================================================
|
|
11
|
+
// Snapshot compaction — keep the device→broker socket healthy.
|
|
12
|
+
//
|
|
13
|
+
// Each UnifiedEvent carries `originalEvent` (full network bodies, query
|
|
14
|
+
// payloads, redux prev/next state trees) for the on-device detail view. The
|
|
15
|
+
// sync snapshot re-sends ALL events on every change (throttled to 200ms), and
|
|
16
|
+
// measured sessions hit 4–6MB per push — a socket firehose that starves the
|
|
17
|
+
// broker and the device's JS thread. Cap the per-event payload for the WIRE
|
|
18
|
+
// only; the on-device modal reads the store directly and keeps full detail.
|
|
19
|
+
// ==========================================================================
|
|
20
|
+
|
|
21
|
+
/** Max serialized bytes of one event's originalEvent on the wire. */
|
|
22
|
+
const MAX_SYNC_ORIGINAL_EVENT_BYTES = 16 * 1024;
|
|
23
|
+
// Events are immutable once created, so compaction is computed once per event
|
|
24
|
+
// object and drops out of the cache when the store evicts the event.
|
|
25
|
+
const compactionCache = new WeakMap();
|
|
26
|
+
function compactEventForSync(event) {
|
|
27
|
+
const original = event.originalEvent;
|
|
28
|
+
if (typeof original !== "object" || original === null) return event;
|
|
29
|
+
const cached = compactionCache.get(event);
|
|
30
|
+
if (cached !== undefined) return cached;
|
|
31
|
+
let result = event;
|
|
32
|
+
try {
|
|
33
|
+
const size = JSON.stringify(original)?.length ?? 0;
|
|
34
|
+
if (size > MAX_SYNC_ORIGINAL_EVENT_BYTES) {
|
|
35
|
+
const truncated = {
|
|
36
|
+
__buoyTruncated: true,
|
|
37
|
+
approxBytes: size,
|
|
38
|
+
note: `Payload (${(size / 1024).toFixed(0)}KB) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`
|
|
39
|
+
};
|
|
40
|
+
result = {
|
|
41
|
+
...event,
|
|
42
|
+
originalEvent: truncated
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
// Unserializable payloads would break the socket emit anyway — replace.
|
|
47
|
+
result = {
|
|
48
|
+
...event,
|
|
49
|
+
originalEvent: {
|
|
50
|
+
__buoyTruncated: true,
|
|
51
|
+
approxBytes: -1,
|
|
52
|
+
note: "Payload is not JSON-serializable and stayed on the device."
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
compactionCache.set(event, result);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
10
60
|
/**
|
|
11
61
|
* Sync adapter for the events tool, consumed by @buoy-gg/external-sync's
|
|
12
62
|
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
@@ -26,7 +76,7 @@ var _copySettings = require("../types/copySettings");
|
|
|
26
76
|
const eventsSyncAdapter = exports.eventsSyncAdapter = {
|
|
27
77
|
version: 2,
|
|
28
78
|
getSnapshot: () => ({
|
|
29
|
-
events: _unifiedEventStore.unifiedEventStore.getEvents(),
|
|
79
|
+
events: _unifiedEventStore.unifiedEventStore.getEvents().map(compactEventForSync),
|
|
30
80
|
availableSources: Array.from(_unifiedEventStore.unifiedEventStore.getAvailableEventSources())
|
|
31
81
|
}),
|
|
32
82
|
subscribe: onChange => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_unifiedEventStore","require","_eventExportFormatter","_copySettings","eventsSyncAdapter","exports","version","getSnapshot","events","unifiedEventStore","getEvents","availableSources","Array","from","getAvailableEventSources","subscribe","onChange","ensureRemoteSourcesDefault","unsubscribe","clearRemoteSources","actions","clearEvents","setEnabledSources","params","sources","setRemoteEnabledSources","enabledSources","exportEvents","p","base","preset","COPY_PRESETS","DEFAULT_COPY_SETTINGS","settings","all","limit","
|
|
1
|
+
{"version":3,"names":["_unifiedEventStore","require","_eventExportFormatter","_copySettings","MAX_SYNC_ORIGINAL_EVENT_BYTES","compactionCache","WeakMap","compactEventForSync","event","original","originalEvent","cached","get","undefined","result","size","JSON","stringify","length","truncated","__buoyTruncated","approxBytes","note","toFixed","set","eventsSyncAdapter","exports","version","getSnapshot","events","unifiedEventStore","getEvents","map","availableSources","Array","from","getAvailableEventSources","subscribe","onChange","ensureRemoteSourcesDefault","unsubscribe","clearRemoteSources","actions","clearEvents","setEnabledSources","params","sources","setRemoteEnabledSources","enabledSources","exportEvents","p","base","preset","COPY_PRESETS","DEFAULT_COPY_SETTINGS","settings","all","limit","slice","output","generateExport","returned","totalAvailable","includedData","includeEventData","format"],"sourceRoot":"../../../src","sources":["sync/eventsSyncAdapter.ts"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAEA,IAAAC,qBAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMG,6BAA6B,GAAG,EAAE,GAAG,IAAI;AAQ/C;AACA;AACA,MAAMC,eAAe,GAAG,IAAIC,OAAO,CAAkB,CAAC;AAEtD,SAASC,mBAAmBA,CAAuCC,KAAQ,EAAK;EAC9E,MAAMC,QAAQ,GAAGD,KAAK,CAACE,aAAa;EACpC,IAAI,OAAOD,QAAQ,KAAK,QAAQ,IAAIA,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AG,CAACtC,MAAM;MACnE,MAAMW,MAAM,GAAG2B,GAAG,CAACE,KAAK,CAAC,CAAC,EAAED,KAAK,CAAC,CAAC,CAAC;MACpC,OAAO;QACLE,MAAM,EAAE,IAAAC,oCAAc,EAAC/B,MAAM,EAAE0B,QAAQ,CAAC;QACxCM,QAAQ,EAAEhC,MAAM,CAACX,MAAM;QACvB4C,cAAc,EAAEN,GAAG,CAACtC,MAAM;QAC1B6C,YAAY,EAAER,QAAQ,CAACS,gBAAgB;QACvCC,MAAM,EAAEV,QAAQ,CAACU;MACnB,CAAC;IACH;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -3,6 +3,56 @@
|
|
|
3
3
|
import { unifiedEventStore } from "../stores/unifiedEventStore";
|
|
4
4
|
import { generateExport } from "../utils/eventExportFormatter";
|
|
5
5
|
import { DEFAULT_COPY_SETTINGS, COPY_PRESETS } from "../types/copySettings";
|
|
6
|
+
// ==========================================================================
|
|
7
|
+
// Snapshot compaction — keep the device→broker socket healthy.
|
|
8
|
+
//
|
|
9
|
+
// Each UnifiedEvent carries `originalEvent` (full network bodies, query
|
|
10
|
+
// payloads, redux prev/next state trees) for the on-device detail view. The
|
|
11
|
+
// sync snapshot re-sends ALL events on every change (throttled to 200ms), and
|
|
12
|
+
// measured sessions hit 4–6MB per push — a socket firehose that starves the
|
|
13
|
+
// broker and the device's JS thread. Cap the per-event payload for the WIRE
|
|
14
|
+
// only; the on-device modal reads the store directly and keeps full detail.
|
|
15
|
+
// ==========================================================================
|
|
16
|
+
|
|
17
|
+
/** Max serialized bytes of one event's originalEvent on the wire. */
|
|
18
|
+
const MAX_SYNC_ORIGINAL_EVENT_BYTES = 16 * 1024;
|
|
19
|
+
// Events are immutable once created, so compaction is computed once per event
|
|
20
|
+
// object and drops out of the cache when the store evicts the event.
|
|
21
|
+
const compactionCache = new WeakMap();
|
|
22
|
+
function compactEventForSync(event) {
|
|
23
|
+
const original = event.originalEvent;
|
|
24
|
+
if (typeof original !== "object" || original === null) return event;
|
|
25
|
+
const cached = compactionCache.get(event);
|
|
26
|
+
if (cached !== undefined) return cached;
|
|
27
|
+
let result = event;
|
|
28
|
+
try {
|
|
29
|
+
const size = JSON.stringify(original)?.length ?? 0;
|
|
30
|
+
if (size > MAX_SYNC_ORIGINAL_EVENT_BYTES) {
|
|
31
|
+
const truncated = {
|
|
32
|
+
__buoyTruncated: true,
|
|
33
|
+
approxBytes: size,
|
|
34
|
+
note: `Payload (${(size / 1024).toFixed(0)}KB) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`
|
|
35
|
+
};
|
|
36
|
+
result = {
|
|
37
|
+
...event,
|
|
38
|
+
originalEvent: truncated
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
// Unserializable payloads would break the socket emit anyway — replace.
|
|
43
|
+
result = {
|
|
44
|
+
...event,
|
|
45
|
+
originalEvent: {
|
|
46
|
+
__buoyTruncated: true,
|
|
47
|
+
approxBytes: -1,
|
|
48
|
+
note: "Payload is not JSON-serializable and stayed on the device."
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
compactionCache.set(event, result);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
6
56
|
/**
|
|
7
57
|
* Sync adapter for the events tool, consumed by @buoy-gg/external-sync's
|
|
8
58
|
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
@@ -22,7 +72,7 @@ import { DEFAULT_COPY_SETTINGS, COPY_PRESETS } from "../types/copySettings";
|
|
|
22
72
|
export const eventsSyncAdapter = {
|
|
23
73
|
version: 2,
|
|
24
74
|
getSnapshot: () => ({
|
|
25
|
-
events: unifiedEventStore.getEvents(),
|
|
75
|
+
events: unifiedEventStore.getEvents().map(compactEventForSync),
|
|
26
76
|
availableSources: Array.from(unifiedEventStore.getAvailableEventSources())
|
|
27
77
|
}),
|
|
28
78
|
subscribe: onChange => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["unifiedEventStore","generateExport","DEFAULT_COPY_SETTINGS","COPY_PRESETS","eventsSyncAdapter","version","getSnapshot","events","getEvents","availableSources","Array","from","getAvailableEventSources","subscribe","onChange","ensureRemoteSourcesDefault","unsubscribe","clearRemoteSources","actions","clearEvents","setEnabledSources","params","sources","setRemoteEnabledSources","enabledSources","exportEvents","p","base","preset","settings","all","limit","
|
|
1
|
+
{"version":3,"names":["unifiedEventStore","generateExport","DEFAULT_COPY_SETTINGS","COPY_PRESETS","MAX_SYNC_ORIGINAL_EVENT_BYTES","compactionCache","WeakMap","compactEventForSync","event","original","originalEvent","cached","get","undefined","result","size","JSON","stringify","length","truncated","__buoyTruncated","approxBytes","note","toFixed","set","eventsSyncAdapter","version","getSnapshot","events","getEvents","map","availableSources","Array","from","getAvailableEventSources","subscribe","onChange","ensureRemoteSourcesDefault","unsubscribe","clearRemoteSources","actions","clearEvents","setEnabledSources","params","sources","setRemoteEnabledSources","enabledSources","exportEvents","p","base","preset","settings","all","limit","slice","output","returned","totalAvailable","includedData","includeEventData","format"],"sourceRoot":"../../../src","sources":["sync/eventsSyncAdapter.ts"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,6BAA6B;AAE/D,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SACEC,qBAAqB,EACrBC,YAAY,QAGP,uBAAuB;AAW9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA,MAAMC,6BAA6B,GAAG,EAAE,GAAG,IAAI;AAQ/C;AACA;AACA,MAAMC,eAAe,GAAG,IAAIC,OAAO,CAAkB,CAAC;AAEtD,SAASC,mBAAmBA,CAAuCC,KAAQ,EAAK;EAC9E,MAAMC,QAAQ,GAAGD,KAAK,CAACE,aAAa;EACpC,IAAI,OAAOD,QAAQ,KAAK,QAAQ,IAAIA,QAAQ,KAAK,IAAI,EAAE,OAAOD,KAAK;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GAAGwB,GAAG,CAACE,KAAK,CAAC,CAAC,EAAED,KAAK,CAAC,CAAC,CAAC;MACpC,OAAO;QACLE,MAAM,EAAEtD,cAAc,CAAC2B,MAAM,EAAEuB,QAAQ,CAAC;QACxCK,QAAQ,EAAE5B,MAAM,CAACV,MAAM;QACvBuC,cAAc,EAAEL,GAAG,CAAClC,MAAM;QAC1BwC,YAAY,EAAEP,QAAQ,CAACQ,gBAAgB;QACvCC,MAAM,EAAET,QAAQ,CAACS;MACnB,CAAC;IACH;EACF;AACF,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventsSyncAdapter.d.ts","sourceRoot":"","sources":["../../../src/sync/eventsSyncAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"eventsSyncAdapter.d.ts","sourceRoot":"","sources":["../../../src/sync/eventsSyncAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA2E5C;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB;;;;;;0BAMN,MAAM,IAAI;;;QAkB9B;;;;WAIG;oCACyB,OAAO;;;QAMnC;;;;;;;WAOG;+BACoB,OAAO;;;;;;;;CAoBjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buoy-gg/events",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.6",
|
|
4
4
|
"description": "One timeline across every Buoy devtool, with LLM-ready export presets. Part of Buoy devtools.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
],
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@buoy-gg/floating-tools-core": "7.0.
|
|
31
|
-
"@buoy-gg/shared-ui": "7.0.
|
|
30
|
+
"@buoy-gg/floating-tools-core": "7.0.6",
|
|
31
|
+
"@buoy-gg/shared-ui": "7.0.6"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"react": "*",
|
|
@@ -17,6 +17,63 @@ interface ExportEventsParams {
|
|
|
17
17
|
limit?: number;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// ==========================================================================
|
|
21
|
+
// Snapshot compaction — keep the device→broker socket healthy.
|
|
22
|
+
//
|
|
23
|
+
// Each UnifiedEvent carries `originalEvent` (full network bodies, query
|
|
24
|
+
// payloads, redux prev/next state trees) for the on-device detail view. The
|
|
25
|
+
// sync snapshot re-sends ALL events on every change (throttled to 200ms), and
|
|
26
|
+
// measured sessions hit 4–6MB per push — a socket firehose that starves the
|
|
27
|
+
// broker and the device's JS thread. Cap the per-event payload for the WIRE
|
|
28
|
+
// only; the on-device modal reads the store directly and keeps full detail.
|
|
29
|
+
// ==========================================================================
|
|
30
|
+
|
|
31
|
+
/** Max serialized bytes of one event's originalEvent on the wire. */
|
|
32
|
+
const MAX_SYNC_ORIGINAL_EVENT_BYTES = 16 * 1024;
|
|
33
|
+
|
|
34
|
+
interface TruncatedOriginalEvent {
|
|
35
|
+
__buoyTruncated: true;
|
|
36
|
+
approxBytes: number;
|
|
37
|
+
note: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Events are immutable once created, so compaction is computed once per event
|
|
41
|
+
// object and drops out of the cache when the store evicts the event.
|
|
42
|
+
const compactionCache = new WeakMap<object, unknown>();
|
|
43
|
+
|
|
44
|
+
function compactEventForSync<T extends { originalEvent: unknown }>(event: T): T {
|
|
45
|
+
const original = event.originalEvent;
|
|
46
|
+
if (typeof original !== "object" || original === null) return event;
|
|
47
|
+
|
|
48
|
+
const cached = compactionCache.get(event as object);
|
|
49
|
+
if (cached !== undefined) return cached as T;
|
|
50
|
+
|
|
51
|
+
let result: T = event;
|
|
52
|
+
try {
|
|
53
|
+
const size = JSON.stringify(original)?.length ?? 0;
|
|
54
|
+
if (size > MAX_SYNC_ORIGINAL_EVENT_BYTES) {
|
|
55
|
+
const truncated: TruncatedOriginalEvent = {
|
|
56
|
+
__buoyTruncated: true,
|
|
57
|
+
approxBytes: size,
|
|
58
|
+
note: `Payload (${(size / 1024).toFixed(0)}KB) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`,
|
|
59
|
+
};
|
|
60
|
+
result = { ...event, originalEvent: truncated };
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
// Unserializable payloads would break the socket emit anyway — replace.
|
|
64
|
+
result = {
|
|
65
|
+
...event,
|
|
66
|
+
originalEvent: {
|
|
67
|
+
__buoyTruncated: true,
|
|
68
|
+
approxBytes: -1,
|
|
69
|
+
note: "Payload is not JSON-serializable and stayed on the device.",
|
|
70
|
+
} satisfies TruncatedOriginalEvent,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
compactionCache.set(event as object, result);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
20
77
|
/**
|
|
21
78
|
* Sync adapter for the events tool, consumed by @buoy-gg/external-sync's
|
|
22
79
|
* `useExternalSync` (structurally matches its ToolSyncAdapter interface so
|
|
@@ -36,7 +93,7 @@ interface ExportEventsParams {
|
|
|
36
93
|
export const eventsSyncAdapter = {
|
|
37
94
|
version: 2,
|
|
38
95
|
getSnapshot: () => ({
|
|
39
|
-
events: unifiedEventStore.getEvents(),
|
|
96
|
+
events: unifiedEventStore.getEvents().map(compactEventForSync),
|
|
40
97
|
availableSources: Array.from(unifiedEventStore.getAvailableEventSources()),
|
|
41
98
|
}),
|
|
42
99
|
subscribe: (onChange: () => void) => {
|