@capture.dev/event-logger 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE.txt +7 -0
  2. package/dist/event-logger.d.ts +25 -0
  3. package/dist/event-logger.d.ts.map +1 -0
  4. package/dist/event-logger.js +42 -0
  5. package/dist/event-sink.d.ts +11 -0
  6. package/dist/event-sink.d.ts.map +1 -0
  7. package/dist/event-sink.js +32 -0
  8. package/dist/global-state.d.ts +14 -0
  9. package/dist/global-state.d.ts.map +1 -0
  10. package/dist/global-state.js +28 -0
  11. package/dist/index-internal.d.ts +20 -0
  12. package/dist/index-internal.d.ts.map +1 -0
  13. package/dist/index-internal.js +18 -0
  14. package/dist/index.d.ts +5 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +4 -0
  17. package/dist/register-logger.d.ts +8 -0
  18. package/dist/register-logger.d.ts.map +1 -0
  19. package/dist/register-logger.js +24 -0
  20. package/dist/register-state-logger.d.ts +5 -0
  21. package/dist/register-state-logger.d.ts.map +1 -0
  22. package/dist/register-state-logger.js +5 -0
  23. package/dist/snapshot-event-to-operation.d.ts +5 -0
  24. package/dist/snapshot-event-to-operation.d.ts.map +1 -0
  25. package/dist/snapshot-event-to-operation.js +7 -0
  26. package/dist/state-logger.d.ts +37 -0
  27. package/dist/state-logger.d.ts.map +1 -0
  28. package/dist/state-logger.js +90 -0
  29. package/dist/to-json/__tests__/serialize-class.test.d.ts +2 -0
  30. package/dist/to-json/__tests__/serialize-class.test.d.ts.map +1 -0
  31. package/dist/to-json/__tests__/serialize-class.test.js +79 -0
  32. package/dist/to-json/__tests__/serialize-date.test.d.ts +2 -0
  33. package/dist/to-json/__tests__/serialize-date.test.d.ts.map +1 -0
  34. package/dist/to-json/__tests__/serialize-date.test.js +20 -0
  35. package/dist/to-json/__tests__/serialize-error.test.d.ts +2 -0
  36. package/dist/to-json/__tests__/serialize-error.test.d.ts.map +1 -0
  37. package/dist/to-json/__tests__/serialize-error.test.js +71 -0
  38. package/dist/to-json/__tests__/serialize-function.test.d.ts +2 -0
  39. package/dist/to-json/__tests__/serialize-function.test.d.ts.map +1 -0
  40. package/dist/to-json/__tests__/serialize-function.test.js +84 -0
  41. package/dist/to-json/__tests__/serialize-map.test.d.ts +2 -0
  42. package/dist/to-json/__tests__/serialize-map.test.d.ts.map +1 -0
  43. package/dist/to-json/__tests__/serialize-map.test.js +90 -0
  44. package/dist/to-json/__tests__/serialize-object.test.d.ts +2 -0
  45. package/dist/to-json/__tests__/serialize-object.test.d.ts.map +1 -0
  46. package/dist/to-json/__tests__/serialize-object.test.js +138 -0
  47. package/dist/to-json/__tests__/serialize-regex.test.d.ts +2 -0
  48. package/dist/to-json/__tests__/serialize-regex.test.d.ts.map +1 -0
  49. package/dist/to-json/__tests__/serialize-regex.test.js +64 -0
  50. package/dist/to-json/__tests__/serialize-set.test.d.ts +2 -0
  51. package/dist/to-json/__tests__/serialize-set.test.d.ts.map +1 -0
  52. package/dist/to-json/__tests__/serialize-set.test.js +74 -0
  53. package/dist/to-json/__tests__/to-json.test.d.ts +2 -0
  54. package/dist/to-json/__tests__/to-json.test.d.ts.map +1 -0
  55. package/dist/to-json/__tests__/to-json.test.js +356 -0
  56. package/dist/to-json/serialize-class.d.ts +4 -0
  57. package/dist/to-json/serialize-class.d.ts.map +1 -0
  58. package/dist/to-json/serialize-class.js +14 -0
  59. package/dist/to-json/serialize-date.d.ts +3 -0
  60. package/dist/to-json/serialize-date.d.ts.map +1 -0
  61. package/dist/to-json/serialize-date.js +8 -0
  62. package/dist/to-json/serialize-error.d.ts +3 -0
  63. package/dist/to-json/serialize-error.d.ts.map +1 -0
  64. package/dist/to-json/serialize-error.js +22 -0
  65. package/dist/to-json/serialize-function.d.ts +3 -0
  66. package/dist/to-json/serialize-function.d.ts.map +1 -0
  67. package/dist/to-json/serialize-function.js +7 -0
  68. package/dist/to-json/serialize-map.d.ts +4 -0
  69. package/dist/to-json/serialize-map.d.ts.map +1 -0
  70. package/dist/to-json/serialize-map.js +10 -0
  71. package/dist/to-json/serialize-object.d.ts +4 -0
  72. package/dist/to-json/serialize-object.d.ts.map +1 -0
  73. package/dist/to-json/serialize-object.js +17 -0
  74. package/dist/to-json/serialize-regex.d.ts +3 -0
  75. package/dist/to-json/serialize-regex.d.ts.map +1 -0
  76. package/dist/to-json/serialize-regex.js +6 -0
  77. package/dist/to-json/serialize-set.d.ts +4 -0
  78. package/dist/to-json/serialize-set.d.ts.map +1 -0
  79. package/dist/to-json/serialize-set.js +10 -0
  80. package/dist/to-json/serialized-markers.d.ts +23 -0
  81. package/dist/to-json/serialized-markers.d.ts.map +1 -0
  82. package/dist/to-json/serialized-markers.js +22 -0
  83. package/dist/to-json/serialized-types.d.ts +55 -0
  84. package/dist/to-json/serialized-types.d.ts.map +1 -0
  85. package/dist/to-json/serialized-types.js +39 -0
  86. package/dist/to-json/to-json.constants.d.ts +11 -0
  87. package/dist/to-json/to-json.constants.d.ts.map +1 -0
  88. package/dist/to-json/to-json.constants.js +10 -0
  89. package/dist/to-json/to-json.d.ts +14 -0
  90. package/dist/to-json/to-json.d.ts.map +1 -0
  91. package/dist/to-json/to-json.js +141 -0
  92. package/package.json +51 -0
@@ -0,0 +1,356 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { BIG_INT, CIRCULAR_REFERENCE, MAX_DEPTH_REACHED, PROMISE, TOO_LARGE, UNDEFINED, } from "../to-json.constants.js";
3
+ import { toJSON } from "../to-json.js";
4
+ describe("toJSON", () => {
5
+ describe("primitives", () => {
6
+ it("serializes null", () => {
7
+ expect(toJSON(null)).toBe(null);
8
+ });
9
+ it("serializes booleans", () => {
10
+ expect(toJSON(true)).toBe(true);
11
+ expect(toJSON(false)).toBe(false);
12
+ });
13
+ it("serializes numbers", () => {
14
+ expect(toJSON(42)).toBe(42);
15
+ expect(toJSON(3.14)).toBe(3.14);
16
+ expect(toJSON(-100)).toBe(-100);
17
+ });
18
+ it("serializes strings", () => {
19
+ expect(toJSON("hello")).toBe("hello");
20
+ expect(toJSON("")).toBe("");
21
+ });
22
+ it("serializes undefined as marker", () => {
23
+ expect(toJSON(undefined)).toBe(UNDEFINED);
24
+ });
25
+ it("serializes safe bigint as number", () => {
26
+ expect(toJSON(BigInt(42))).toBe(42);
27
+ });
28
+ it("serializes unsafe bigint as marker", () => {
29
+ expect(toJSON(BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1))).toBe(BIG_INT);
30
+ });
31
+ it("serializes symbol as string", () => {
32
+ expect(toJSON(Symbol("test"))).toBe("Symbol(test)");
33
+ expect(toJSON(Symbol.for("global"))).toBe("Symbol(global)");
34
+ });
35
+ });
36
+ describe("functions", () => {
37
+ it("serializes named function", () => {
38
+ function myFunc() { }
39
+ const result = toJSON(myFunc);
40
+ expect(result).toEqual({
41
+ __CAPTURE_TYPE__: "function",
42
+ name: "myFunc",
43
+ });
44
+ });
45
+ it("serializes arrow function", () => {
46
+ const arrow = () => { };
47
+ const result = toJSON(arrow);
48
+ expect(result).toEqual({
49
+ __CAPTURE_TYPE__: "function",
50
+ name: "arrow",
51
+ });
52
+ });
53
+ });
54
+ describe("classes", () => {
55
+ it("serializes a class", () => {
56
+ class MyClass {
57
+ }
58
+ const result = toJSON(MyClass);
59
+ expect(result).toEqual({
60
+ __CAPTURE_TYPE__: "classConstructor",
61
+ name: "MyClass",
62
+ });
63
+ });
64
+ it("serializes an extended class", () => {
65
+ class Parent {
66
+ }
67
+ class Child extends Parent {
68
+ }
69
+ const result = toJSON(Child);
70
+ expect(result).toEqual({
71
+ __CAPTURE_TYPE__: "classConstructor",
72
+ name: "Child",
73
+ });
74
+ });
75
+ });
76
+ describe("dates", () => {
77
+ it("serializes date as timestamp", () => {
78
+ const date = new Date("2024-01-15T12:00:00.000Z");
79
+ expect(toJSON(date)).toMatchObject({
80
+ __CAPTURE_TYPE__: "date",
81
+ value: 1705320000000,
82
+ });
83
+ });
84
+ });
85
+ describe("errors", () => {
86
+ it("serializes error with name and message", () => {
87
+ const error = new Error("Test error");
88
+ const result = toJSON(error);
89
+ expect(result).toMatchObject({
90
+ __CAPTURE_TYPE__: "error",
91
+ error: {
92
+ name: "Error",
93
+ message: "Test error",
94
+ },
95
+ });
96
+ });
97
+ it("serializes TypeError", () => {
98
+ const error = new TypeError("Type mismatch");
99
+ const result = toJSON(error);
100
+ expect(result).toMatchObject({
101
+ __CAPTURE_TYPE__: "error",
102
+ error: {
103
+ name: "TypeError",
104
+ message: "Type mismatch",
105
+ },
106
+ });
107
+ });
108
+ });
109
+ describe("regex", () => {
110
+ it("serializes regex with pattern", () => {
111
+ const regex = /test/gi;
112
+ const result = toJSON(regex);
113
+ expect(result).toEqual({
114
+ __CAPTURE_TYPE__: "regex",
115
+ pattern: "/test/gi",
116
+ });
117
+ });
118
+ });
119
+ describe("promises", () => {
120
+ it("serializes promise as marker", () => {
121
+ const promise = Promise.resolve(42);
122
+ expect(toJSON(promise)).toBe(PROMISE);
123
+ });
124
+ it("serializes pending promise as marker", () => {
125
+ const promise = new Promise(() => { });
126
+ expect(toJSON(promise)).toBe(PROMISE);
127
+ });
128
+ });
129
+ describe("arrays", () => {
130
+ it("serializes empty array", () => {
131
+ expect(toJSON([])).toEqual([]);
132
+ });
133
+ it("serializes array of primitives", () => {
134
+ expect(toJSON([1, "two", true, null])).toEqual([1, "two", true, null]);
135
+ });
136
+ it("serializes nested arrays", () => {
137
+ expect(toJSON([
138
+ [1, 2],
139
+ [3, 4],
140
+ ])).toEqual([
141
+ [1, 2],
142
+ [3, 4],
143
+ ]);
144
+ });
145
+ it("serializes array with mixed types", () => {
146
+ const result = toJSON([1, undefined, () => { }, new Map([["a", 1]])]);
147
+ expect(result).toEqual([
148
+ 1,
149
+ UNDEFINED,
150
+ { __CAPTURE_TYPE__: "function", name: "(anonymous)" },
151
+ {
152
+ __CAPTURE_TYPE__: "map",
153
+ entries: [["a", 1]],
154
+ },
155
+ ]);
156
+ });
157
+ });
158
+ describe("maps", () => {
159
+ it("serializes empty map", () => {
160
+ const result = toJSON(new Map());
161
+ expect(result).toEqual({
162
+ __CAPTURE_TYPE__: "map",
163
+ entries: [],
164
+ });
165
+ });
166
+ it("serializes map with entries", () => {
167
+ const map = new Map([
168
+ ["a", 1],
169
+ ["b", 2],
170
+ ]);
171
+ const result = toJSON(map);
172
+ expect(result).toEqual({
173
+ __CAPTURE_TYPE__: "map",
174
+ entries: [
175
+ ["a", 1],
176
+ ["b", 2],
177
+ ],
178
+ });
179
+ });
180
+ });
181
+ describe("sets", () => {
182
+ it("serializes empty set", () => {
183
+ const result = toJSON(new Set());
184
+ expect(result).toEqual({
185
+ __CAPTURE_TYPE__: "set",
186
+ values: [],
187
+ });
188
+ });
189
+ it("serializes set with values", () => {
190
+ const set = new Set([1, 2, 3]);
191
+ const result = toJSON(set);
192
+ expect(result).toEqual({
193
+ __CAPTURE_TYPE__: "set",
194
+ values: [1, 2, 3],
195
+ });
196
+ });
197
+ });
198
+ describe("plain objects", () => {
199
+ it("serializes empty object", () => {
200
+ expect(toJSON({})).toEqual({});
201
+ });
202
+ it("serializes object with properties", () => {
203
+ expect(toJSON({ a: 1, b: "two" })).toEqual({ a: 1, b: "two" });
204
+ });
205
+ it("serializes nested objects", () => {
206
+ expect(toJSON({ outer: { inner: "value" } })).toEqual({
207
+ outer: { inner: "value" },
208
+ });
209
+ });
210
+ it("respects toJSON method", () => {
211
+ const obj = {
212
+ secret: "hidden",
213
+ toJSON() {
214
+ return { public: "visible" };
215
+ },
216
+ };
217
+ expect(toJSON(obj)).toEqual({ public: "visible" });
218
+ });
219
+ });
220
+ describe("class instances", () => {
221
+ it("serializes class instance with name", () => {
222
+ class User {
223
+ name = "Alice";
224
+ }
225
+ const result = toJSON(new User());
226
+ expect(result).toEqual({
227
+ __CAPTURE_TYPE__: "object",
228
+ name: "User",
229
+ properties: { name: "Alice" },
230
+ });
231
+ });
232
+ it("serializes inherited class", () => {
233
+ class Animal {
234
+ type = "animal";
235
+ }
236
+ class Dog extends Animal {
237
+ breed = "labrador";
238
+ }
239
+ const result = toJSON(new Dog());
240
+ expect(result).toMatchObject({
241
+ __CAPTURE_TYPE__: "object",
242
+ name: "Dog",
243
+ });
244
+ });
245
+ });
246
+ describe("circular references", () => {
247
+ it("handles circular object reference", () => {
248
+ const obj = { a: 1 };
249
+ obj.self = obj;
250
+ const result = toJSON(obj);
251
+ expect(result).toEqual({
252
+ a: 1,
253
+ self: CIRCULAR_REFERENCE,
254
+ });
255
+ });
256
+ it("handles circular array reference", () => {
257
+ const arr = [1, 2];
258
+ arr.push(arr);
259
+ const result = toJSON(arr);
260
+ expect(result).toEqual([1, 2, CIRCULAR_REFERENCE]);
261
+ });
262
+ it("handles deeply nested circular reference", () => {
263
+ const obj = {
264
+ level1: {
265
+ level2: {
266
+ level3: {},
267
+ },
268
+ },
269
+ };
270
+ obj.level1.level2.level3 = obj;
271
+ const result = toJSON(obj);
272
+ expect(result.level1.level2).toMatchObject({
273
+ level3: CIRCULAR_REFERENCE,
274
+ });
275
+ });
276
+ });
277
+ describe("depth limiting", () => {
278
+ it("returns marker when max depth exceeded", () => {
279
+ const deep = { l1: { l2: { l3: { l4: "value" } } } };
280
+ const result = toJSON(deep, { maxDepth: 2 });
281
+ expect(result).toEqual({
282
+ l1: {
283
+ l2: {
284
+ l3: MAX_DEPTH_REACHED,
285
+ },
286
+ },
287
+ });
288
+ });
289
+ });
290
+ describe("size limiting (partial truncation)", () => {
291
+ it("returns partial object with TOO_LARGE marker when size exceeded", () => {
292
+ const large = {
293
+ first: "a".repeat(100),
294
+ second: "b".repeat(100),
295
+ third: "c".repeat(100),
296
+ };
297
+ const result = toJSON(large, { maxSize: 250 });
298
+ expect(result).toMatchObject({
299
+ first: expect.any(String),
300
+ });
301
+ expect(Object.values(result)).toContain(TOO_LARGE);
302
+ });
303
+ it("preserves data before truncation point", () => {
304
+ const obj = {
305
+ small: "hello",
306
+ large: "x".repeat(1000000),
307
+ };
308
+ const result = toJSON(obj, { maxSize: 100 });
309
+ expect(result.small).toBe("hello");
310
+ expect(result.large).toBe(TOO_LARGE);
311
+ });
312
+ });
313
+ describe("string truncation", () => {
314
+ it("truncates long strings", () => {
315
+ const longString = "a".repeat(200);
316
+ const result = toJSON(longString, { maxStringLength: 50 });
317
+ expect(result).toBe("a".repeat(50) + " [Output truncated due to length]");
318
+ });
319
+ it("does not truncate strings under limit", () => {
320
+ const shortString = "hello";
321
+ const result = toJSON(shortString, { maxStringLength: 50 });
322
+ expect(result).toBe("hello");
323
+ });
324
+ });
325
+ describe("edge cases", () => {
326
+ it("handles unknown value type", () => {
327
+ // Proxy that masquerades as non-object
328
+ const weird = Object.create(null);
329
+ Object.setPrototypeOf(weird, null);
330
+ const result = toJSON(weird);
331
+ expect(result).toMatchObject({
332
+ __CAPTURE_TYPE__: "object",
333
+ });
334
+ });
335
+ it("handles getter that throws", () => {
336
+ const obj = {
337
+ get throwing() {
338
+ throw new Error("Oops");
339
+ },
340
+ normal: "value",
341
+ };
342
+ const result = toJSON(obj);
343
+ expect(result.normal).toBe("value");
344
+ expect(result.throwing).toContain("[Throws:");
345
+ });
346
+ it("handles toJSON that throws", () => {
347
+ const obj = {
348
+ toJSON() {
349
+ throw new Error("toJSON failed");
350
+ },
351
+ };
352
+ const result = toJSON(obj);
353
+ expect(result).toContain("[Throws:");
354
+ });
355
+ });
356
+ });
@@ -0,0 +1,4 @@
1
+ import type { SerializedClassConstructor } from "./serialized-types.js";
2
+ export declare function isClass(fn: Function): boolean;
3
+ export declare function serializeClass(fn: Function): SerializedClassConstructor;
4
+ //# sourceMappingURL=serialize-class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-class.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-class.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAM7C;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,QAAQ,GAAG,0BAA0B,CAKvE"}
@@ -0,0 +1,14 @@
1
+ export function isClass(fn) {
2
+ try {
3
+ return /^class\s/.test(fn.toString());
4
+ }
5
+ catch {
6
+ return false;
7
+ }
8
+ }
9
+ export function serializeClass(fn) {
10
+ return {
11
+ __CAPTURE_TYPE__: "classConstructor",
12
+ name: fn.name || "(anonymous)",
13
+ };
14
+ }
@@ -0,0 +1,3 @@
1
+ import type { SerializedDate } from "./serialized-types.js";
2
+ export declare function serializeDate(date: Date): SerializedDate;
3
+ //# sourceMappingURL=serialize-date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-date.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,cAAc,CAOxD"}
@@ -0,0 +1,8 @@
1
+ export function serializeDate(date) {
2
+ const time = date.getTime();
3
+ const isInvalid = Number.isNaN(time);
4
+ return {
5
+ __CAPTURE_TYPE__: "date",
6
+ value: isInvalid ? null : time,
7
+ };
8
+ }
@@ -0,0 +1,3 @@
1
+ import type { SerializedError } from "./serialized-types.js";
2
+ export declare function serializeError(error: Error): SerializedError;
3
+ //# sourceMappingURL=serialize-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-error.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAqB/B,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CAK5D"}
@@ -0,0 +1,22 @@
1
+ function serializeErrorObject(error) {
2
+ const result = {
3
+ name: error.name,
4
+ message: error.message,
5
+ };
6
+ if (error.stack) {
7
+ result.stack = error.stack;
8
+ }
9
+ if (error.cause instanceof Error) {
10
+ result.cause = serializeErrorObject(error.cause);
11
+ }
12
+ else if (error.cause !== undefined) {
13
+ result.cause = null;
14
+ }
15
+ return result;
16
+ }
17
+ export function serializeError(error) {
18
+ return {
19
+ __CAPTURE_TYPE__: "error",
20
+ error: serializeErrorObject(error),
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ import type { SerializedFunction } from "./serialized-types.js";
2
+ export declare function serializeFunction(fn: Function): SerializedFunction;
3
+ //# sourceMappingURL=serialize-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-function.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-function.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGhE,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,GAAG,kBAAkB,CAKlE"}
@@ -0,0 +1,7 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
2
+ export function serializeFunction(fn) {
3
+ return {
4
+ __CAPTURE_TYPE__: "function",
5
+ name: fn.name || "(anonymous)",
6
+ };
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { SerializedMap } from "./serialized-types.js";
2
+ import type { VisitorFn } from "./to-json.js";
3
+ export declare function serializeMap(map: Map<unknown, unknown>, visit: VisitorFn): SerializedMap;
4
+ //# sourceMappingURL=serialize-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-map.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAC1B,KAAK,EAAE,SAAS,GACf,aAAa,CAWf"}
@@ -0,0 +1,10 @@
1
+ export function serializeMap(map, visit) {
2
+ const entries = [];
3
+ for (const [key, value] of map) {
4
+ entries.push([visit(key), visit(value)]);
5
+ }
6
+ return {
7
+ __CAPTURE_TYPE__: "map",
8
+ entries,
9
+ };
10
+ }
@@ -0,0 +1,4 @@
1
+ import type { SerializedObject } from "./serialized-types.js";
2
+ import type { VisitorFn } from "./to-json.js";
3
+ export declare function serializeObject(obj: object, visit: VisitorFn): SerializedObject;
4
+ //# sourceMappingURL=serialize-object.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-object.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,GACf,gBAAgB,CAiBlB"}
@@ -0,0 +1,17 @@
1
+ export function serializeObject(obj, visit) {
2
+ const name = obj.constructor?.name || "Object";
3
+ const properties = {};
4
+ for (const key of Object.keys(obj)) {
5
+ try {
6
+ properties[key] = visit(obj[key]);
7
+ }
8
+ catch {
9
+ properties[key] = "[Throws]";
10
+ }
11
+ }
12
+ return {
13
+ __CAPTURE_TYPE__: "object",
14
+ name,
15
+ properties,
16
+ };
17
+ }
@@ -0,0 +1,3 @@
1
+ import type { SerializedRegex } from "./serialized-types.js";
2
+ export declare function serializeRegex(regex: RegExp): SerializedRegex;
3
+ //# sourceMappingURL=serialize-regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-regex.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-regex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAK7D"}
@@ -0,0 +1,6 @@
1
+ export function serializeRegex(regex) {
2
+ return {
3
+ __CAPTURE_TYPE__: "regex",
4
+ pattern: regex.toString(),
5
+ };
6
+ }
@@ -0,0 +1,4 @@
1
+ import type { SerializedSet } from "./serialized-types.js";
2
+ import type { VisitorFn } from "./to-json.js";
3
+ export declare function serializeSet(set: Set<unknown>, visit: VisitorFn): SerializedSet;
4
+ //# sourceMappingURL=serialize-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize-set.d.ts","sourceRoot":"","sources":["../../src/to-json/serialize-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,EACjB,KAAK,EAAE,SAAS,GACf,aAAa,CAWf"}
@@ -0,0 +1,10 @@
1
+ export function serializeSet(set, visit) {
2
+ const values = [];
3
+ for (const value of set) {
4
+ values.push(visit(value));
5
+ }
6
+ return {
7
+ __CAPTURE_TYPE__: "set",
8
+ values,
9
+ };
10
+ }
@@ -0,0 +1,23 @@
1
+ export declare const REDACTED = "$REDACTED$";
2
+ export declare const UNDEFINED = "$UNDEFINED$";
3
+ export declare const BIG_INT = "$BIGINT$";
4
+ export declare const FUNCTION = "$FUNCTION$";
5
+ export declare const PROMISE = "$PROMISE$";
6
+ export declare const CIRCULAR_REFERENCE = "$CIRCULAR_REFERENCE$";
7
+ export declare const UNKNOWN = "$UNKNOWN$";
8
+ export declare const TOO_LARGE = "$TOO_LARGE$";
9
+ export declare const MAX_DEPTH_REACHED = "$MAX_DEPTH_REACHED$";
10
+ export declare const SERIALIZATION_ERROR = "$SERIALIZATION_ERROR$";
11
+ export declare const SerializedMarker: {
12
+ readonly REDACTED: "$REDACTED$";
13
+ readonly UNDEFINED: "$UNDEFINED$";
14
+ readonly BIG_INT: "$BIGINT$";
15
+ readonly FUNCTION: "$FUNCTION$";
16
+ readonly PROMISE: "$PROMISE$";
17
+ readonly CIRCULAR_REFERENCE: "$CIRCULAR_REFERENCE$";
18
+ readonly UNKNOWN: "$UNKNOWN$";
19
+ readonly TOO_LARGE: "$TOO_LARGE$";
20
+ readonly MAX_DEPTH_REACHED: "$MAX_DEPTH_REACHED$";
21
+ readonly SERIALIZATION_ERROR: "$SERIALIZATION_ERROR$";
22
+ };
23
+ //# sourceMappingURL=serialized-markers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized-markers.d.ts","sourceRoot":"","sources":["../../src/to-json/serialized-markers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,eAAe,CAAC;AACrC,eAAO,MAAM,SAAS,gBAAgB,CAAC;AACvC,eAAO,MAAM,OAAO,aAAa,CAAC;AAClC,eAAO,MAAM,QAAQ,eAAe,CAAC;AACrC,eAAO,MAAM,OAAO,cAAc,CAAC;AACnC,eAAO,MAAM,kBAAkB,yBAAyB,CAAC;AACzD,eAAO,MAAM,OAAO,cAAc,CAAC;AACnC,eAAO,MAAM,SAAS,gBAAgB,CAAC;AACvC,eAAO,MAAM,iBAAiB,wBAAwB,CAAC;AACvD,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D,eAAO,MAAM,gBAAgB;;;;;;;;;;;CAWnB,CAAC"}
@@ -0,0 +1,22 @@
1
+ export const REDACTED = "$REDACTED$";
2
+ export const UNDEFINED = "$UNDEFINED$";
3
+ export const BIG_INT = "$BIGINT$";
4
+ export const FUNCTION = "$FUNCTION$";
5
+ export const PROMISE = "$PROMISE$";
6
+ export const CIRCULAR_REFERENCE = "$CIRCULAR_REFERENCE$";
7
+ export const UNKNOWN = "$UNKNOWN$";
8
+ export const TOO_LARGE = "$TOO_LARGE$";
9
+ export const MAX_DEPTH_REACHED = "$MAX_DEPTH_REACHED$";
10
+ export const SERIALIZATION_ERROR = "$SERIALIZATION_ERROR$";
11
+ export const SerializedMarker = {
12
+ REDACTED,
13
+ UNDEFINED,
14
+ BIG_INT,
15
+ FUNCTION,
16
+ PROMISE,
17
+ CIRCULAR_REFERENCE,
18
+ UNKNOWN,
19
+ TOO_LARGE,
20
+ MAX_DEPTH_REACHED,
21
+ SERIALIZATION_ERROR,
22
+ };
@@ -0,0 +1,55 @@
1
+ export type SerializedValue = string | number | boolean | null | SerializedValue[] | {
2
+ [key: string]: SerializedValue;
3
+ } | SerializedError | SerializedMap | SerializedSet | SerializedRegex | SerializedFunction | SerializedClassConstructor | SerializedObject;
4
+ export type SerializedPlainObject = Record<string, SerializedValue>;
5
+ export type SerializedArray = SerializedValue[];
6
+ export declare const isSerializedPlainObject: (value: SerializedValue) => value is SerializedPlainObject;
7
+ export declare const isSerializedArray: (value: SerializedValue) => value is SerializedArray;
8
+ export type SerializedErrorObject = {
9
+ name: string;
10
+ message: string;
11
+ stack?: string;
12
+ cause?: SerializedErrorObject | null;
13
+ };
14
+ export type SerializedError = {
15
+ __CAPTURE_TYPE__: "error";
16
+ error: SerializedErrorObject;
17
+ };
18
+ export declare const isSerializedError: (value: SerializedValue) => value is SerializedError;
19
+ export type SerializedMap = {
20
+ __CAPTURE_TYPE__: "map";
21
+ entries: [SerializedValue, SerializedValue][];
22
+ };
23
+ export declare const isSerializedMap: (value: SerializedValue) => value is SerializedMap;
24
+ export type SerializedSet = {
25
+ __CAPTURE_TYPE__: "set";
26
+ values: SerializedValue[];
27
+ };
28
+ export declare const isSerializedSet: (value: SerializedValue) => value is SerializedSet;
29
+ export type SerializedRegex = {
30
+ __CAPTURE_TYPE__: "regex";
31
+ pattern: string;
32
+ };
33
+ export declare const isSerializedRegex: (value: SerializedValue) => value is SerializedRegex;
34
+ export type SerializedFunction = {
35
+ __CAPTURE_TYPE__: "function";
36
+ name: string;
37
+ };
38
+ export declare const isSerializedFunction: (value: SerializedValue) => value is SerializedFunction;
39
+ export type SerializedClassConstructor = {
40
+ __CAPTURE_TYPE__: "classConstructor";
41
+ name: string;
42
+ };
43
+ export declare const isSerializedClassConstructor: (value: SerializedValue) => value is SerializedClassConstructor;
44
+ export type SerializedObject = {
45
+ __CAPTURE_TYPE__: "object";
46
+ name: string;
47
+ properties: Record<string, SerializedValue>;
48
+ };
49
+ export declare const isSerializedObject: (value: SerializedValue) => value is SerializedObject;
50
+ export type SerializedDate = {
51
+ __CAPTURE_TYPE__: "date";
52
+ value: number | null;
53
+ };
54
+ export declare const isSerializedDate: (value: SerializedValue) => value is SerializedDate;
55
+ //# sourceMappingURL=serialized-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialized-types.d.ts","sourceRoot":"","sources":["../../src/to-json/serialized-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,eAAe,EAAE,GACjB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAE,GAClC,eAAe,GACf,aAAa,GACb,aAAa,GACb,eAAe,GACf,kBAAkB,GAClB,0BAA0B,GAC1B,gBAAgB,CAAC;AAErB,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,eAAe,EAAE,CAAC;AAchD,eAAO,MAAM,uBAAuB,GAClC,OAAO,eAAe,KACrB,KAAK,IAAI,qBAOX,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,eAAe,KACrB,KAAK,IAAI,eAEX,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,KAAK,EAAE,qBAAqB,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,eAAe,KACrB,KAAK,IAAI,eAEX,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,gBAAgB,EAAE,KAAK,CAAC;IACxB,OAAO,EAAE,CAAC,eAAe,EAAE,eAAe,CAAC,EAAE,CAAC;CAC/C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,OAAO,eAAe,KACrB,KAAK,IAAI,aAEX,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,gBAAgB,EAAE,KAAK,CAAC;IACxB,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,OAAO,eAAe,KACrB,KAAK,IAAI,aAEX,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,eAAe,KACrB,KAAK,IAAI,eAEX,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gBAAgB,EAAE,UAAU,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,OAAO,eAAe,KACrB,KAAK,IAAI,kBAEX,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,gBAAgB,EAAE,kBAAkB,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,OAAO,eAAe,KACrB,KAAK,IAAI,0BAEX,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,EAAE,QAAQ,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,OAAO,eAAe,KACrB,KAAK,IAAI,gBAEX,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,OAAO,eAAe,KACrB,KAAK,IAAI,cAEX,CAAC"}