cojson 0.6.7 → 0.7.0-alpha.0

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 (53) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/.turbo/turbo-build.log +2 -2
  3. package/CHANGELOG.md +3 -3
  4. package/dist/coValue.js.map +1 -1
  5. package/dist/coValueCore.js.map +1 -1
  6. package/dist/coValues/account.js +5 -5
  7. package/dist/coValues/account.js.map +1 -1
  8. package/dist/coValues/coList.js +39 -58
  9. package/dist/coValues/coList.js.map +1 -1
  10. package/dist/coValues/coMap.js +20 -61
  11. package/dist/coValues/coMap.js.map +1 -1
  12. package/dist/coValues/coStream.js +14 -64
  13. package/dist/coValues/coStream.js.map +1 -1
  14. package/dist/coValues/group.js +57 -59
  15. package/dist/coValues/group.js.map +1 -1
  16. package/dist/coreToCoValue.js +17 -12
  17. package/dist/coreToCoValue.js.map +1 -1
  18. package/dist/index.js +8 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/localNode.js +54 -38
  21. package/dist/localNode.js.map +1 -1
  22. package/dist/permissions.js +2 -2
  23. package/dist/permissions.js.map +1 -1
  24. package/dist/tests/testUtils.js +6 -11
  25. package/dist/tests/testUtils.js.map +1 -1
  26. package/dist/typeUtils/expectGroup.js +2 -2
  27. package/dist/typeUtils/expectGroup.js.map +1 -1
  28. package/dist/typeUtils/isCoValue.js +8 -8
  29. package/dist/typeUtils/isCoValue.js.map +1 -1
  30. package/package.json +3 -4
  31. package/src/coValue.ts +21 -21
  32. package/src/coValueCore.ts +8 -8
  33. package/src/coValues/account.ts +14 -26
  34. package/src/coValues/coList.ts +58 -97
  35. package/src/coValues/coMap.ts +27 -129
  36. package/src/coValues/coStream.ts +31 -137
  37. package/src/coValues/group.ts +52 -46
  38. package/src/coreToCoValue.ts +16 -12
  39. package/src/index.ts +27 -36
  40. package/src/jsonValue.ts +1 -1
  41. package/src/localNode.ts +88 -75
  42. package/src/media.ts +4 -4
  43. package/src/permissions.ts +2 -2
  44. package/src/tests/account.test.ts +12 -12
  45. package/src/tests/coValue.test.ts +149 -182
  46. package/src/tests/coValueCore.test.ts +8 -3
  47. package/src/tests/crypto.test.ts +7 -0
  48. package/src/tests/group.test.ts +13 -6
  49. package/src/tests/permissions.test.ts +648 -840
  50. package/src/tests/sync.test.ts +44 -68
  51. package/src/tests/testUtils.ts +6 -11
  52. package/src/typeUtils/expectGroup.ts +4 -4
  53. package/src/typeUtils/isCoValue.ts +11 -11
@@ -1,11 +1,18 @@
1
+ import { expect, test, beforeEach } from "vitest";
1
2
  import { expectList, expectMap, expectStream } from "../coValue.js";
2
- import { BinaryCoStream } from "../coValues/coStream.js";
3
+ import { RawBinaryCoStream } from "../coValues/coStream.js";
3
4
  import { createdNowUnique } from "../crypto.js";
4
5
  import { MAX_RECOMMENDED_TX_SIZE, cojsonReady } from "../index.js";
5
6
  import { LocalNode } from "../localNode.js";
6
7
  import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
7
8
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
8
9
 
10
+ import { webcrypto } from "node:crypto";
11
+ if (!("crypto" in globalThis)) {
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ (globalThis as any).crypto = webcrypto;
14
+ }
15
+
9
16
  beforeEach(async () => {
10
17
  await cojsonReady;
11
18
  });
@@ -41,15 +48,13 @@ test("Can insert and delete CoMap entries in edit()", () => {
41
48
 
42
49
  expect(content.type).toEqual("comap");
43
50
 
44
- content.edit((editable) => {
45
- editable.set("hello", "world", "trusting");
46
- expect(editable.get("hello")).toEqual("world");
47
- editable.set("foo", "bar", "trusting");
48
- expect(editable.get("foo")).toEqual("bar");
49
- expect([...editable.keys()]).toEqual(["hello", "foo"]);
50
- editable.delete("foo", "trusting");
51
- expect(editable.get("foo")).toEqual(undefined);
52
- });
51
+ content.set("hello", "world", "trusting");
52
+ expect(content.get("hello")).toEqual("world");
53
+ content.set("foo", "bar", "trusting");
54
+ expect(content.get("foo")).toEqual("bar");
55
+ expect([...content.keys()]).toEqual(["hello", "foo"]);
56
+ content.delete("foo", "trusting");
57
+ expect(content.get("foo")).toEqual(undefined);
53
58
  });
54
59
 
55
60
  test("Can get CoMap entry values at different points in time", () => {
@@ -66,22 +71,20 @@ test("Can get CoMap entry values at different points in time", () => {
66
71
 
67
72
  expect(content.type).toEqual("comap");
68
73
 
69
- content.edit((editable) => {
70
- const beforeA = Date.now();
71
- while (Date.now() < beforeA + 10) {}
72
- editable.set("hello", "A", "trusting");
73
- const beforeB = Date.now();
74
- while (Date.now() < beforeB + 10) {}
75
- editable.set("hello", "B", "trusting");
76
- const beforeC = Date.now();
77
- while (Date.now() < beforeC + 10) {}
78
- editable.set("hello", "C", "trusting");
79
- expect(editable.get("hello")).toEqual("C");
80
- expect(editable.atTime(Date.now()).get("hello")).toEqual("C");
81
- expect(editable.atTime(beforeA).get("hello")).toEqual(undefined);
82
- expect(editable.atTime(beforeB).get("hello")).toEqual("A");
83
- expect(editable.atTime(beforeC).get("hello")).toEqual("B");
84
- });
74
+ const beforeA = Date.now();
75
+ while (Date.now() < beforeA + 10) {}
76
+ content.set("hello", "A", "trusting");
77
+ const beforeB = Date.now();
78
+ while (Date.now() < beforeB + 10) {}
79
+ content.set("hello", "B", "trusting");
80
+ const beforeC = Date.now();
81
+ while (Date.now() < beforeC + 10) {}
82
+ content.set("hello", "C", "trusting");
83
+ expect(content.get("hello")).toEqual("C");
84
+ expect(content.atTime(Date.now()).get("hello")).toEqual("C");
85
+ expect(content.atTime(beforeA).get("hello")).toEqual(undefined);
86
+ expect(content.atTime(beforeB).get("hello")).toEqual("A");
87
+ expect(content.atTime(beforeC).get("hello")).toEqual("B");
85
88
  });
86
89
 
87
90
  test("Can get all historic values of key in CoMap", () => {
@@ -98,42 +101,40 @@ test("Can get all historic values of key in CoMap", () => {
98
101
 
99
102
  expect(content.type).toEqual("comap");
100
103
 
101
- content.edit((editable) => {
102
- editable.set("hello", "A", "trusting");
103
- const editA = editable.lastEditAt("hello");
104
- editable.set("hello", "B", "trusting");
105
- const editB = editable.lastEditAt("hello");
106
- editable.delete("hello", "trusting");
107
- const editDel = editable.lastEditAt("hello");
108
- editable.set("hello", "C", "trusting");
109
- const editC = editable.lastEditAt("hello");
110
- expect([...editable.editsAt("hello")]).toEqual([
111
- {
112
- tx: editA!.tx,
113
- by: node.account.id,
114
- value: "A",
115
- at: editA?.at,
116
- },
117
- {
118
- tx: editB!.tx,
119
- by: node.account.id,
120
- value: "B",
121
- at: editB?.at,
122
- },
123
- {
124
- tx: editDel!.tx,
125
- by: node.account.id,
126
- value: undefined,
127
- at: editDel?.at,
128
- },
129
- {
130
- tx: editC!.tx,
131
- by: node.account.id,
132
- value: "C",
133
- at: editC?.at,
134
- },
135
- ]);
136
- });
104
+ content.set("hello", "A", "trusting");
105
+ const editA = content.lastEditAt("hello");
106
+ content.set("hello", "B", "trusting");
107
+ const editB = content.lastEditAt("hello");
108
+ content.delete("hello", "trusting");
109
+ const editDel = content.lastEditAt("hello");
110
+ content.set("hello", "C", "trusting");
111
+ const editC = content.lastEditAt("hello");
112
+ expect([...content.editsAt("hello")]).toEqual([
113
+ {
114
+ tx: editA!.tx,
115
+ by: node.account.id,
116
+ value: "A",
117
+ at: editA?.at,
118
+ },
119
+ {
120
+ tx: editB!.tx,
121
+ by: node.account.id,
122
+ value: "B",
123
+ at: editB?.at,
124
+ },
125
+ {
126
+ tx: editDel!.tx,
127
+ by: node.account.id,
128
+ value: undefined,
129
+ at: editDel?.at,
130
+ },
131
+ {
132
+ tx: editC!.tx,
133
+ by: node.account.id,
134
+ value: "C",
135
+ at: editC?.at,
136
+ },
137
+ ]);
137
138
  });
138
139
 
139
140
  test("Can get last tx ID for a key in CoMap", () => {
@@ -150,19 +151,17 @@ test("Can get last tx ID for a key in CoMap", () => {
150
151
 
151
152
  expect(content.type).toEqual("comap");
152
153
 
153
- content.edit((editable) => {
154
- expect(editable.lastEditAt("hello")).toEqual(undefined);
155
- editable.set("hello", "A", "trusting");
156
- const sessionID = editable.lastEditAt("hello")?.tx.sessionID;
157
- expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
158
- node.account.id
159
- );
160
- expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(0);
161
- editable.set("hello", "B", "trusting");
162
- expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(1);
163
- editable.set("hello", "C", "trusting");
164
- expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(2);
165
- });
154
+ expect(content.lastEditAt("hello")).toEqual(undefined);
155
+ content.set("hello", "A", "trusting");
156
+ const sessionID = content.lastEditAt("hello")?.tx.sessionID;
157
+ expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
158
+ node.account.id
159
+ );
160
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(0);
161
+ content.set("hello", "B", "trusting");
162
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(1);
163
+ content.set("hello", "C", "trusting");
164
+ expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(2);
166
165
  });
167
166
 
168
167
  test("Empty CoList works", () => {
@@ -181,7 +180,7 @@ test("Empty CoList works", () => {
181
180
  expect(content.toJSON()).toEqual([]);
182
181
  });
183
182
 
184
- test("Can append, prepend and delete items to CoList", () => {
183
+ test("Can append, prepend, delete and replace items in CoList", () => {
185
184
  const node = new LocalNode(...randomAnonymousAccountAndSessionID());
186
185
 
187
186
  const coValue = node.createCoValue({
@@ -193,23 +192,18 @@ test("Can append, prepend and delete items to CoList", () => {
193
192
 
194
193
  const content = expectList(coValue.getCurrentContent());
195
194
 
196
- content.edit((editable) => {
197
- editable.append("hello", 0, "trusting");
198
- expect(editable.toJSON()).toEqual(["hello"]);
199
- editable.append("world", 0, "trusting");
200
- expect(editable.toJSON()).toEqual(["hello", "world"]);
201
- editable.prepend("beautiful", 1, "trusting");
202
- expect(editable.toJSON()).toEqual(["hello", "beautiful", "world"]);
203
- editable.prepend("hooray", 3, "trusting");
204
- expect(editable.toJSON()).toEqual([
205
- "hello",
206
- "beautiful",
207
- "world",
208
- "hooray",
209
- ]);
210
- editable.delete(2, "trusting");
211
- expect(editable.toJSON()).toEqual(["hello", "beautiful", "hooray"]);
212
- });
195
+ content.append("hello", 0, "trusting");
196
+ expect(content.toJSON()).toEqual(["hello"]);
197
+ content.append("world", 0, "trusting");
198
+ expect(content.toJSON()).toEqual(["hello", "world"]);
199
+ content.prepend("beautiful", 1, "trusting");
200
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "world"]);
201
+ content.prepend("hooray", 3, "trusting");
202
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "world", "hooray"]);
203
+ content.replace(2, "universe", "trusting");
204
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "universe", "hooray"]);
205
+ content.delete(2, "trusting");
206
+ expect(content.toJSON()).toEqual(["hello", "beautiful", "hooray"]);
213
207
  });
214
208
 
215
209
  test("Push is equivalent to append after last item", () => {
@@ -226,14 +220,12 @@ test("Push is equivalent to append after last item", () => {
226
220
 
227
221
  expect(content.type).toEqual("colist");
228
222
 
229
- content.edit((editable) => {
230
- editable.append("hello", 0, "trusting");
231
- expect(editable.toJSON()).toEqual(["hello"]);
232
- editable.append("world", undefined, "trusting");
233
- expect(editable.toJSON()).toEqual(["hello", "world"]);
234
- editable.append("hooray", undefined, "trusting");
235
- expect(editable.toJSON()).toEqual(["hello", "world", "hooray"]);
236
- });
223
+ content.append("hello", 0, "trusting");
224
+ expect(content.toJSON()).toEqual(["hello"]);
225
+ content.append("world", undefined, "trusting");
226
+ expect(content.toJSON()).toEqual(["hello", "world"]);
227
+ content.append("hooray", undefined, "trusting");
228
+ expect(content.toJSON()).toEqual(["hello", "world", "hooray"]);
237
229
  });
238
230
 
239
231
  test("Can push into empty list", () => {
@@ -250,10 +242,8 @@ test("Can push into empty list", () => {
250
242
 
251
243
  expect(content.type).toEqual("colist");
252
244
 
253
- content.edit((editable) => {
254
- editable.append("hello", undefined, "trusting");
255
- expect(editable.toJSON()).toEqual(["hello"]);
256
- });
245
+ content.append("hello", undefined, "trusting");
246
+ expect(content.toJSON()).toEqual(["hello"]);
257
247
  });
258
248
 
259
249
  test("Empty CoStream works", () => {
@@ -285,23 +275,21 @@ test("Can push into CoStream", () => {
285
275
 
286
276
  const content = expectStream(coValue.getCurrentContent());
287
277
 
288
- content.edit((editable) => {
289
- editable.push({ hello: "world" }, "trusting");
290
- expect(editable.toJSON()).toEqual({
291
- [node.currentSessionID]: [{ hello: "world" }],
292
- });
293
- editable.push({ foo: "bar" }, "trusting");
294
- expect(editable.toJSON()).toEqual({
295
- [node.currentSessionID]: [{ hello: "world" }, { foo: "bar" }],
296
- });
297
- expect(editable.getSingleStream()).toEqual([
298
- { hello: "world" },
299
- { foo: "bar" },
300
- ]);
278
+ content.push({ hello: "world" }, "trusting");
279
+ expect(content.toJSON()).toEqual({
280
+ [node.currentSessionID]: [{ hello: "world" }],
281
+ });
282
+ content.push({ foo: "bar" }, "trusting");
283
+ expect(content.toJSON()).toEqual({
284
+ [node.currentSessionID]: [{ hello: "world" }, { foo: "bar" }],
301
285
  });
286
+ expect(content.getSingleStream()).toEqual([
287
+ { hello: "world" },
288
+ { foo: "bar" },
289
+ ]);
302
290
  });
303
291
 
304
- test("Empty BinaryCoStream works", () => {
292
+ test("Empty RawBinaryCoStream works", () => {
305
293
  const node = new LocalNode(...randomAnonymousAccountAndSessionID());
306
294
 
307
295
  const coValue = node.createCoValue({
@@ -316,7 +304,7 @@ test("Empty BinaryCoStream works", () => {
316
304
  if (
317
305
  content.type !== "costream" ||
318
306
  content.headerMeta?.type !== "binary" ||
319
- !(content instanceof BinaryCoStream)
307
+ !(content instanceof RawBinaryCoStream)
320
308
  ) {
321
309
  throw new Error("Expected binary stream");
322
310
  }
@@ -327,7 +315,7 @@ test("Empty BinaryCoStream works", () => {
327
315
  expect(content.getBinaryChunks()).toEqual(undefined);
328
316
  });
329
317
 
330
- test("Can push into BinaryCoStream", () => {
318
+ test("Can push into RawBinaryCoStream", () => {
331
319
  const node = new LocalNode(...randomAnonymousAccountAndSessionID());
332
320
 
333
321
  const coValue = node.createCoValue({
@@ -342,45 +330,36 @@ test("Can push into BinaryCoStream", () => {
342
330
  if (
343
331
  content.type !== "costream" ||
344
332
  content.headerMeta?.type !== "binary" ||
345
- !(content instanceof BinaryCoStream)
333
+ !(content instanceof RawBinaryCoStream)
346
334
  ) {
347
335
  throw new Error("Expected binary stream");
348
336
  }
349
337
 
350
- content.edit((editable) => {
351
- editable.startBinaryStream(
352
- { mimeType: "text/plain", fileName: "test.txt" },
353
- "trusting"
354
- );
355
- expect(editable.getBinaryChunks(true)).toEqual({
356
- mimeType: "text/plain",
357
- fileName: "test.txt",
358
- chunks: [],
359
- finished: false,
360
- });
361
- editable.pushBinaryStreamChunk(new Uint8Array([1, 2, 3]), "trusting");
362
- expect(editable.getBinaryChunks(true)).toEqual({
363
- mimeType: "text/plain",
364
- fileName: "test.txt",
365
- chunks: [new Uint8Array([1, 2, 3])],
366
- finished: false,
367
- });
368
- editable.pushBinaryStreamChunk(new Uint8Array([4, 5, 6]), "trusting");
369
-
370
- expect(editable.getBinaryChunks(true)).toEqual({
371
- mimeType: "text/plain",
372
- fileName: "test.txt",
373
- chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
374
- finished: false,
375
- });
376
-
377
- editable.endBinaryStream("trusting");
378
- expect(editable.getBinaryChunks()).toEqual({
379
- mimeType: "text/plain",
380
- fileName: "test.txt",
381
- chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
382
- finished: true,
383
- });
338
+ content.startBinaryStream(
339
+ { mimeType: "text/plain", fileName: "test.txt" },
340
+ "trusting"
341
+ );
342
+ expect(content.getBinaryChunks(true)).toEqual({
343
+ mimeType: "text/plain",
344
+ fileName: "test.txt",
345
+ chunks: [],
346
+ finished: false,
347
+ });
348
+ content.pushBinaryStreamChunk(new Uint8Array([1, 2, 3]), "trusting");
349
+ expect(content.getBinaryChunks(true)).toEqual({
350
+ mimeType: "text/plain",
351
+ fileName: "test.txt",
352
+ chunks: [new Uint8Array([1, 2, 3])],
353
+ finished: false,
354
+ });
355
+ content.pushBinaryStreamChunk(new Uint8Array([4, 5, 6]), "trusting");
356
+
357
+ content.endBinaryStream("trusting");
358
+ expect(content.getBinaryChunks()).toEqual({
359
+ mimeType: "text/plain",
360
+ fileName: "test.txt",
361
+ chunks: [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])],
362
+ finished: true,
384
363
  });
385
364
  });
386
365
 
@@ -399,29 +378,23 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
399
378
  if (
400
379
  content.type !== "costream" ||
401
380
  content.headerMeta?.type !== "binary" ||
402
- !(content instanceof BinaryCoStream)
381
+ !(content instanceof RawBinaryCoStream)
403
382
  ) {
404
383
  throw new Error("Expected binary stream");
405
384
  }
406
385
 
407
- content.edit((editable) => {
408
- editable.startBinaryStream(
409
- { mimeType: "text/plain", fileName: "test.txt" },
410
- "trusting"
411
- );
412
- });
386
+ content.startBinaryStream(
387
+ { mimeType: "text/plain", fileName: "test.txt" },
388
+ "trusting"
389
+ );
413
390
 
414
391
  for (let i = 0; i < 10; i++) {
415
392
  const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE / 3 + 100);
416
393
 
417
- content.edit((editable) => {
418
- editable.pushBinaryStreamChunk(chunk, "trusting");
419
- });
394
+ content.pushBinaryStreamChunk(chunk, "trusting");
420
395
  }
421
396
 
422
- content.edit((editable) => {
423
- editable.endBinaryStream("trusting");
424
- });
397
+ content.endBinaryStream("trusting");
425
398
 
426
399
  const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
427
400
  expect(sessionEntry.transactions.length).toEqual(12);
@@ -475,29 +448,23 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
475
448
  if (
476
449
  content.type !== "costream" ||
477
450
  content.headerMeta?.type !== "binary" ||
478
- !(content instanceof BinaryCoStream)
451
+ !(content instanceof RawBinaryCoStream)
479
452
  ) {
480
453
  throw new Error("Expected binary stream");
481
454
  }
482
455
 
483
- content.edit((editable) => {
484
- editable.startBinaryStream(
485
- { mimeType: "text/plain", fileName: "test.txt" },
486
- "trusting"
487
- );
488
- });
456
+ content.startBinaryStream(
457
+ { mimeType: "text/plain", fileName: "test.txt" },
458
+ "trusting"
459
+ );
489
460
 
490
461
  const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE + 100);
491
462
 
492
463
  for (let i = 0; i < 3; i++) {
493
- content.edit((editable) => {
494
- editable.pushBinaryStreamChunk(chunk, "trusting");
495
- });
464
+ content.pushBinaryStreamChunk(chunk, "trusting");
496
465
  }
497
466
 
498
- content.edit((editable) => {
499
- editable.endBinaryStream("trusting");
500
- });
467
+ content.endBinaryStream("trusting");
501
468
 
502
469
  const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
503
470
  expect(sessionEntry.transactions.length).toEqual(5);
@@ -1,3 +1,4 @@
1
+ import { expect, test, beforeEach } from "vitest";
1
2
  import { Transaction } from "../coValueCore.js";
2
3
  import { LocalNode } from "../localNode.js";
3
4
  import { createdNowUnique, getAgentSignerSecret, newRandomAgentSecret, sign } from "../crypto.js";
@@ -7,6 +8,12 @@ import { Role } from "../permissions.js";
7
8
  import { cojsonReady } from "../index.js";
8
9
  import { stableStringify } from "../jsonStringify.js";
9
10
 
11
+ import { webcrypto } from "node:crypto";
12
+ if (!("crypto" in globalThis)) {
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ (globalThis as any).crypto = webcrypto;
15
+ }
16
+
10
17
  beforeEach(async () => {
11
18
  await cojsonReady;
12
19
  });
@@ -142,9 +149,7 @@ test("New transactions in a group correctly update owned values, including subsc
142
149
 
143
150
  let map = group.createMap();
144
151
 
145
- let mapAfterEdit = map.edit((map) => {
146
- map.set("hello", "world");
147
- });
152
+ map.set("hello", "world");
148
153
 
149
154
  const listener = jest.fn().mockImplementation();
150
155
 
@@ -1,3 +1,4 @@
1
+ import { expect, test, beforeEach } from "vitest";
1
2
  import {
2
3
  getSealerID,
3
4
  getSignerID,
@@ -23,6 +24,12 @@ import stableStringify from "fast-json-stable-stringify";
23
24
  import { SessionID } from "../ids.js";
24
25
  import { cojsonReady } from "../index.js";
25
26
 
27
+ import { webcrypto } from "node:crypto";
28
+ if (!("crypto" in globalThis)) {
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ (globalThis as any).crypto = webcrypto;
31
+ }
32
+
26
33
  beforeEach(async () => {
27
34
  await cojsonReady;
28
35
  });
@@ -1,11 +1,18 @@
1
- import { LocalNode, CoMap, CoList, CoStream, BinaryCoStream, cojsonReady } from "../index";
1
+ import { expect, test, beforeEach } from "vitest";
2
+ import { LocalNode, RawCoMap, RawCoList, RawCoStream, RawBinaryCoStream, cojsonReady } from "../index";
2
3
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
3
4
 
5
+ import { webcrypto } from "node:crypto";
6
+ if (!("crypto" in globalThis)) {
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
+ (globalThis as any).crypto = webcrypto;
9
+ }
10
+
4
11
  beforeEach(async () => {
5
12
  await cojsonReady;
6
13
  });
7
14
 
8
- test("Can create a CoMap in a group", () => {
15
+ test("Can create a RawCoMap in a group", () => {
9
16
  const node = new LocalNode(...randomAnonymousAccountAndSessionID());
10
17
 
11
18
  const group = node.createGroup();
@@ -13,7 +20,7 @@ test("Can create a CoMap in a group", () => {
13
20
  const map = group.createMap();
14
21
 
15
22
  expect(map.core.getCurrentContent().type).toEqual("comap");
16
- expect(map instanceof CoMap).toEqual(true);
23
+ expect(map instanceof RawCoMap).toEqual(true);
17
24
  });
18
25
 
19
26
  test("Can create a CoList in a group", () => {
@@ -24,7 +31,7 @@ test("Can create a CoList in a group", () => {
24
31
  const list = group.createList();
25
32
 
26
33
  expect(list.core.getCurrentContent().type).toEqual("colist");
27
- expect(list instanceof CoList).toEqual(true);
34
+ expect(list instanceof RawCoList).toEqual(true);
28
35
  })
29
36
 
30
37
  test("Can create a CoStream in a group", () => {
@@ -35,7 +42,7 @@ test("Can create a CoStream in a group", () => {
35
42
  const stream = group.createStream();
36
43
 
37
44
  expect(stream.core.getCurrentContent().type).toEqual("costream");
38
- expect(stream instanceof CoStream).toEqual(true);
45
+ expect(stream instanceof RawCoStream).toEqual(true);
39
46
  });
40
47
 
41
48
  test("Can create a BinaryCoStream in a group", () => {
@@ -47,5 +54,5 @@ test("Can create a BinaryCoStream in a group", () => {
47
54
 
48
55
  expect(stream.core.getCurrentContent().type).toEqual("costream");
49
56
  expect(stream.headerMeta.type).toEqual("binary");
50
- expect(stream instanceof BinaryCoStream).toEqual(true);
57
+ expect(stream instanceof RawBinaryCoStream).toEqual(true);
51
58
  })