cojson 0.6.7 → 0.7.0-alpha.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.
- package/.eslintrc.cjs +1 -0
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +8 -2
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/account.js +5 -5
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +39 -58
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +20 -61
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +14 -64
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +57 -59
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.js +17 -12
- package/dist/coreToCoValue.js.map +1 -1
- package/dist/ids.js +3 -0
- package/dist/ids.js.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/localNode.js +54 -38
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js +2 -2
- package/dist/permissions.js.map +1 -1
- package/dist/tests/testUtils.js +6 -11
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/expectGroup.js +2 -2
- package/dist/typeUtils/expectGroup.js.map +1 -1
- package/dist/typeUtils/isCoValue.js +8 -8
- package/dist/typeUtils/isCoValue.js.map +1 -1
- package/package.json +3 -4
- package/src/coValue.ts +21 -21
- package/src/coValueCore.ts +8 -8
- package/src/coValues/account.ts +15 -27
- package/src/coValues/coList.ts +58 -97
- package/src/coValues/coMap.ts +27 -129
- package/src/coValues/coStream.ts +31 -137
- package/src/coValues/group.ts +52 -46
- package/src/coreToCoValue.ts +16 -12
- package/src/ids.ts +4 -0
- package/src/index.ts +30 -38
- package/src/jsonValue.ts +1 -1
- package/src/localNode.ts +92 -79
- package/src/media.ts +4 -4
- package/src/permissions.ts +3 -3
- package/src/tests/account.test.ts +12 -12
- package/src/tests/coValue.test.ts +149 -182
- package/src/tests/coValueCore.test.ts +8 -3
- package/src/tests/crypto.test.ts +7 -0
- package/src/tests/group.test.ts +13 -6
- package/src/tests/permissions.test.ts +648 -840
- package/src/tests/sync.test.ts +44 -68
- package/src/tests/testUtils.ts +6 -11
- package/src/typeUtils/expectGroup.ts +4 -4
- 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 {
|
|
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.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
|
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.
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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.
|
|
254
|
-
|
|
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.
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
333
|
+
!(content instanceof RawBinaryCoStream)
|
|
346
334
|
) {
|
|
347
335
|
throw new Error("Expected binary stream");
|
|
348
336
|
}
|
|
349
337
|
|
|
350
|
-
content.
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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
|
|
381
|
+
!(content instanceof RawBinaryCoStream)
|
|
403
382
|
) {
|
|
404
383
|
throw new Error("Expected binary stream");
|
|
405
384
|
}
|
|
406
385
|
|
|
407
|
-
content.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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.
|
|
418
|
-
editable.pushBinaryStreamChunk(chunk, "trusting");
|
|
419
|
-
});
|
|
394
|
+
content.pushBinaryStreamChunk(chunk, "trusting");
|
|
420
395
|
}
|
|
421
396
|
|
|
422
|
-
content.
|
|
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
|
|
451
|
+
!(content instanceof RawBinaryCoStream)
|
|
479
452
|
) {
|
|
480
453
|
throw new Error("Expected binary stream");
|
|
481
454
|
}
|
|
482
455
|
|
|
483
|
-
content.
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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.
|
|
494
|
-
editable.pushBinaryStreamChunk(chunk, "trusting");
|
|
495
|
-
});
|
|
464
|
+
content.pushBinaryStreamChunk(chunk, "trusting");
|
|
496
465
|
}
|
|
497
466
|
|
|
498
|
-
content.
|
|
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
|
-
|
|
146
|
-
map.set("hello", "world");
|
|
147
|
-
});
|
|
152
|
+
map.set("hello", "world");
|
|
148
153
|
|
|
149
154
|
const listener = jest.fn().mockImplementation();
|
|
150
155
|
|
package/src/tests/crypto.test.ts
CHANGED
|
@@ -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
|
});
|
package/src/tests/group.test.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
57
|
+
expect(stream instanceof RawBinaryCoStream).toEqual(true);
|
|
51
58
|
})
|