@buoy-gg/events 7.0.17 → 7.0.18

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.
@@ -104,6 +104,72 @@ const STATE_TREE_OMITTED = {
104
104
  note: "prevState/nextState stay on the device (use get_redux_state / the on-device tool).",
105
105
  } as const;
106
106
 
107
+ /** Marker replacing oversized / unserializable react-query payloads. */
108
+ const QUERY_PAYLOAD_OMITTED = {
109
+ __buoyOmitted: "query-payload",
110
+ note: "Query/mutation data stays on the device (open the Query tool or the on-device Events detail).",
111
+ } as const;
112
+
113
+ const NETWORK_BODY_OMITTED = {
114
+ __buoyOmitted: "network-body",
115
+ note: "Request/response body stays on the device (open the Network tool or the on-device Events detail).",
116
+ } as const;
117
+
118
+ const NETWORK_HEADERS_OMITTED = {
119
+ __buoyOmitted: "network-headers",
120
+ note: "Request/response headers stay on the device (open the Network tool or the on-device Events detail).",
121
+ } as const;
122
+
123
+ const GRAPHQL_VARS_OMITTED = {
124
+ __buoyOmitted: "graphql-variables",
125
+ note: "GraphQL variables stay on the device (open the Network tool or the on-device Events detail).",
126
+ } as const;
127
+
128
+ const STORAGE_VALUE_OMITTED = {
129
+ __buoyOmitted: "storage-value",
130
+ note: "Storage value stays on the device (open the Storage tool or the on-device Events detail).",
131
+ } as const;
132
+
133
+ const ROUTE_PARAMS_OMITTED = {
134
+ __buoyOmitted: "route-params",
135
+ note: "Navigation params stay on the device (open the Routes tool or the on-device Events detail).",
136
+ } as const;
137
+
138
+ function isReactQuerySource(source?: string): boolean {
139
+ return (
140
+ source === "react-query" ||
141
+ source === "react-query-query" ||
142
+ source === "react-query-mutation"
143
+ );
144
+ }
145
+
146
+ function omitIfHeavy(
147
+ value: unknown,
148
+ marker: { __buoyOmitted: string; note: string },
149
+ ): unknown {
150
+ if (value === undefined) return undefined;
151
+ try {
152
+ JSON.stringify(value);
153
+ } catch {
154
+ return { ...marker };
155
+ }
156
+ const { over, cyclic } = approxSizeOver(value, MAX_SYNC_ORIGINAL_EVENT_BYTES);
157
+ if (over || cyclic) return { ...marker };
158
+ return value;
159
+ }
160
+
161
+ function wireQueryPayload(value: unknown): unknown {
162
+ return omitIfHeavy(value, QUERY_PAYLOAD_OMITTED);
163
+ }
164
+
165
+ function wireError(value: unknown): unknown {
166
+ if (value == null) return value;
167
+ if (value instanceof Error) {
168
+ return { name: value.name, message: value.message };
169
+ }
170
+ return wireQueryPayload(value);
171
+ }
172
+
107
173
  // Events are immutable once created, so compaction is computed once per event
108
174
  // object and drops out of the cache when the store evicts the event.
109
175
  const compactionCache = new WeakMap<object, unknown>();
@@ -125,13 +191,142 @@ function compactEventForSync<T extends { source?: string; originalEvent: unknown
125
191
  // (type/payload/meta/diff) still makes it onto the wire when it fits.
126
192
  let candidate = original as Record<string, unknown>;
127
193
  if (
128
- event.source === "redux" &&
194
+ (event.source === "redux" || event.source === "zustand") &&
129
195
  ("prevState" in candidate || "nextState" in candidate)
130
196
  ) {
197
+ // Clone the sentinel per field. `approxSizeOver` flags a repeated object
198
+ // reference as cyclic, and a shared marker would truncate the whole
199
+ // originalEvent — dropping type/payload, which is the part we kept.
200
+ candidate = {
201
+ ...candidate,
202
+ prevState: { ...STATE_TREE_OMITTED },
203
+ nextState: { ...STATE_TREE_OMITTED },
204
+ ...(event.source === "zustand" && "partial" in candidate
205
+ ? { partial: { ...STATE_TREE_OMITTED } }
206
+ : {}),
207
+ };
208
+ result = { ...event, originalEvent: candidate };
209
+ } else if (
210
+ event.source === "jotai" &&
211
+ ("prevValue" in candidate || "nextValue" in candidate)
212
+ ) {
213
+ candidate = {
214
+ ...candidate,
215
+ prevValue: { ...STATE_TREE_OMITTED },
216
+ nextValue: { ...STATE_TREE_OMITTED },
217
+ };
218
+ result = { ...event, originalEvent: candidate };
219
+ } else if (event.source === "render") {
220
+ // Highlight-updates events embed the full TrackedRender (including
221
+ // renderHistory) plus the RenderEvent (captured props/state, hookChanges).
222
+ // Drop those trees so the timeline keeps title/cause type.
223
+ const render = candidate.render as Record<string, unknown> | undefined;
224
+ const nested = candidate.event as Record<string, unknown> | undefined;
225
+ const omitCause = (cause: unknown) => {
226
+ if (!cause || typeof cause !== "object") return cause;
227
+ const { hookChanges: _hookChanges, ...rest } = cause as Record<
228
+ string,
229
+ unknown
230
+ >;
231
+ return rest;
232
+ };
233
+ candidate = {
234
+ ...candidate,
235
+ render: render
236
+ ? {
237
+ ...render,
238
+ renderHistory: undefined,
239
+ lastRenderCause: omitCause(render.lastRenderCause),
240
+ }
241
+ : render,
242
+ event: nested
243
+ ? {
244
+ ...nested,
245
+ capturedProps: undefined,
246
+ capturedState: undefined,
247
+ cause: omitCause(nested.cause),
248
+ }
249
+ : nested,
250
+ };
251
+ result = { ...event, originalEvent: candidate };
252
+ } else if (isReactQuerySource(event.source)) {
253
+ // React Query events embed the live Query/Mutation objects (cyclic —
254
+ // observers point back at the query) plus full cache `queryData`.
255
+ // Walking those either flags cyclic and truncates the WHOLE originalEvent
256
+ // (losing type/queryKey/duration) or blows the 16KB cap. Drop the live
257
+ // objects unconditionally; keep light fields; replace heavy data.
258
+ const { query: _query, mutation: _mutation, ...rest } = candidate;
259
+ candidate = {
260
+ ...rest,
261
+ queryData: wireQueryPayload(rest.queryData),
262
+ mutationData: wireQueryPayload(rest.mutationData),
263
+ mutationVariables: wireQueryPayload(rest.mutationVariables),
264
+ queryError: wireError(rest.queryError),
265
+ mutationError: wireError(rest.mutationError),
266
+ };
267
+ result = { ...event, originalEvent: candidate };
268
+ } else if (event.source === "network") {
269
+ // Network events carry request/response bodies. A 20KB body blows the
270
+ // 16KB cap and truncates the WHOLE originalEvent — method/url/status
271
+ // never reach the dashboard. Strip heavy bodies first (same 16KB
272
+ // threshold as the network adapter).
273
+ const requestSize =
274
+ typeof candidate.requestSize === "number"
275
+ ? candidate.requestSize
276
+ : undefined;
277
+ const responseSize =
278
+ typeof candidate.responseSize === "number"
279
+ ? candidate.responseSize
280
+ : undefined;
281
+ candidate = {
282
+ ...candidate,
283
+ requestData:
284
+ requestSize !== undefined && requestSize > MAX_SYNC_ORIGINAL_EVENT_BYTES
285
+ ? { ...NETWORK_BODY_OMITTED }
286
+ : omitIfHeavy(candidate.requestData, NETWORK_BODY_OMITTED),
287
+ responseData:
288
+ responseSize !== undefined &&
289
+ responseSize > MAX_SYNC_ORIGINAL_EVENT_BYTES
290
+ ? { ...NETWORK_BODY_OMITTED }
291
+ : omitIfHeavy(candidate.responseData, NETWORK_BODY_OMITTED),
292
+ graphqlVariables: omitIfHeavy(
293
+ candidate.graphqlVariables,
294
+ GRAPHQL_VARS_OMITTED,
295
+ ),
296
+ requestHeaders: omitIfHeavy(
297
+ candidate.requestHeaders,
298
+ NETWORK_HEADERS_OMITTED,
299
+ ),
300
+ responseHeaders: omitIfHeavy(
301
+ candidate.responseHeaders,
302
+ NETWORK_HEADERS_OMITTED,
303
+ ),
304
+ };
305
+ result = { ...event, originalEvent: candidate };
306
+ } else if (
307
+ event.source === "storage-async" ||
308
+ event.source === "storage-mmkv"
309
+ ) {
310
+ const data = candidate.data as Record<string, unknown> | undefined;
311
+ if (data) {
312
+ candidate = {
313
+ ...candidate,
314
+ data: {
315
+ ...data,
316
+ value: omitIfHeavy(data.value, STORAGE_VALUE_OMITTED),
317
+ prevValue: omitIfHeavy(data.prevValue, STORAGE_VALUE_OMITTED),
318
+ pairs: omitIfHeavy(data.pairs, STORAGE_VALUE_OMITTED),
319
+ },
320
+ };
321
+ result = { ...event, originalEvent: candidate };
322
+ }
323
+ } else if (event.source === "route") {
324
+ // Route events embed navigate() params. A fat object (or a 20KB
325
+ // stringified payload) blows the 16KB cap and truncates the WHOLE
326
+ // originalEvent — pathname never reaches the dashboard.
131
327
  candidate = {
132
328
  ...candidate,
133
- prevState: STATE_TREE_OMITTED,
134
- nextState: STATE_TREE_OMITTED,
329
+ params: omitIfHeavy(candidate.params, ROUTE_PARAMS_OMITTED),
135
330
  };
136
331
  result = { ...event, originalEvent: candidate };
137
332
  }