cojson 0.13.17 → 0.13.20
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/PeerState.d.ts +4 -1
- package/dist/PeerState.d.ts.map +1 -1
- package/dist/PeerState.js +16 -36
- package/dist/PeerState.js.map +1 -1
- package/dist/SyncStateManager.d.ts.map +1 -1
- package/dist/SyncStateManager.js +2 -3
- package/dist/SyncStateManager.js.map +1 -1
- package/dist/coValue.d.ts +4 -4
- package/dist/coValue.d.ts.map +1 -1
- package/dist/coValue.js +4 -4
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +143 -0
- package/dist/coValueCore/coValueCore.d.ts.map +1 -0
- package/dist/{coValueCore.js → coValueCore/coValueCore.js} +325 -253
- package/dist/coValueCore/coValueCore.js.map +1 -0
- package/dist/coValueCore/verifiedState.d.ts +65 -0
- package/dist/coValueCore/verifiedState.d.ts.map +1 -0
- package/dist/coValueCore/verifiedState.js +210 -0
- package/dist/coValueCore/verifiedState.js.map +1 -0
- package/dist/coValues/account.d.ts +8 -10
- package/dist/coValues/account.d.ts.map +1 -1
- package/dist/coValues/account.js +12 -13
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.d.ts +3 -3
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coList.js +6 -3
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.d.ts +3 -3
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coMap.js +3 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coPlainText.d.ts +2 -2
- package/dist/coValues/coPlainText.d.ts.map +1 -1
- package/dist/coValues/coPlainText.js +4 -4
- package/dist/coValues/coPlainText.js.map +1 -1
- package/dist/coValues/coStream.d.ts +3 -3
- package/dist/coValues/coStream.d.ts.map +1 -1
- package/dist/coValues/coStream.js +3 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.d.ts +7 -2
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +29 -26
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.d.ts +2 -2
- package/dist/coreToCoValue.d.ts.map +1 -1
- package/dist/coreToCoValue.js +10 -14
- package/dist/coreToCoValue.js.map +1 -1
- package/dist/exports.d.ts +6 -5
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +3 -4
- package/dist/exports.js.map +1 -1
- package/dist/localNode.d.ts +30 -24
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +147 -173
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.d.ts +2 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +15 -11
- package/dist/permissions.js.map +1 -1
- package/dist/priority.d.ts +1 -1
- package/dist/priority.d.ts.map +1 -1
- package/dist/streamUtils.d.ts +5 -5
- package/dist/streamUtils.d.ts.map +1 -1
- package/dist/streamUtils.js +5 -20
- package/dist/streamUtils.js.map +1 -1
- package/dist/sync.d.ts +8 -6
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +121 -74
- package/dist/sync.js.map +1 -1
- package/dist/tests/PeerState.test.js +0 -31
- package/dist/tests/PeerState.test.js.map +1 -1
- package/dist/tests/SyncStateManager.test.js +41 -6
- package/dist/tests/SyncStateManager.test.js.map +1 -1
- package/dist/tests/account.test.js +16 -0
- package/dist/tests/account.test.js.map +1 -1
- package/dist/tests/coList.test.js +19 -16
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +12 -13
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coPlainText.test.js +9 -10
- package/dist/tests/coPlainText.test.js.map +1 -1
- package/dist/tests/coStream.test.js +22 -17
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/coValueCore.test.js +22 -28
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/coValueCoreLoadingState.test.d.ts +2 -0
- package/dist/tests/coValueCoreLoadingState.test.d.ts.map +1 -0
- package/dist/tests/{coValueState.test.js → coValueCoreLoadingState.test.js} +62 -46
- package/dist/tests/coValueCoreLoadingState.test.js.map +1 -0
- package/dist/tests/group.test.js +42 -43
- package/dist/tests/group.test.js.map +1 -1
- package/dist/tests/messagesTestUtils.d.ts +2 -2
- package/dist/tests/messagesTestUtils.d.ts.map +1 -1
- package/dist/tests/messagesTestUtils.js +1 -1
- package/dist/tests/messagesTestUtils.js.map +1 -1
- package/dist/tests/permissions.test.js +224 -292
- package/dist/tests/permissions.test.js.map +1 -1
- package/dist/tests/priority.test.js +13 -14
- package/dist/tests/priority.test.js.map +1 -1
- package/dist/tests/sync.auth.test.d.ts +2 -0
- package/dist/tests/sync.auth.test.d.ts.map +1 -0
- package/dist/tests/sync.auth.test.js +190 -0
- package/dist/tests/sync.auth.test.js.map +1 -0
- package/dist/tests/sync.load.test.js +6 -6
- package/dist/tests/sync.load.test.js.map +1 -1
- package/dist/tests/sync.mesh.test.js +25 -12
- package/dist/tests/sync.mesh.test.js.map +1 -1
- package/dist/tests/sync.peerReconciliation.test.js +19 -19
- package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
- package/dist/tests/sync.storage.test.js +20 -13
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.test.js +32 -39
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js +126 -37
- package/dist/tests/sync.upload.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +35 -17
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +103 -79
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/expectGroup.js +1 -1
- package/dist/typeUtils/expectGroup.js.map +1 -1
- package/package.json +1 -1
- package/src/PeerState.ts +19 -40
- package/src/SyncStateManager.ts +2 -3
- package/src/coValue.ts +11 -8
- package/src/{coValueCore.ts → coValueCore/coValueCore.ts} +478 -422
- package/src/coValueCore/verifiedState.ts +376 -0
- package/src/coValues/account.ts +20 -25
- package/src/coValues/coList.ts +12 -6
- package/src/coValues/coMap.ts +9 -6
- package/src/coValues/coPlainText.ts +9 -6
- package/src/coValues/coStream.ts +9 -6
- package/src/coValues/group.ts +50 -28
- package/src/coreToCoValue.ts +14 -15
- package/src/exports.ts +9 -7
- package/src/localNode.ts +236 -275
- package/src/permissions.ts +18 -12
- package/src/priority.ts +1 -1
- package/src/streamUtils.ts +7 -34
- package/src/sync.ts +146 -84
- package/src/tests/PeerState.test.ts +0 -37
- package/src/tests/SyncStateManager.test.ts +56 -6
- package/src/tests/account.test.ts +24 -0
- package/src/tests/coList.test.ts +21 -15
- package/src/tests/coMap.test.ts +12 -13
- package/src/tests/coPlainText.test.ts +12 -9
- package/src/tests/coStream.test.ts +25 -16
- package/src/tests/coValueCore.test.ts +30 -27
- package/src/tests/{coValueState.test.ts → coValueCoreLoadingState.test.ts} +67 -57
- package/src/tests/group.test.ts +44 -69
- package/src/tests/messagesTestUtils.ts +3 -8
- package/src/tests/permissions.test.ts +283 -449
- package/src/tests/priority.test.ts +17 -13
- package/src/tests/sync.auth.test.ts +246 -0
- package/src/tests/sync.load.test.ts +7 -6
- package/src/tests/sync.mesh.test.ts +25 -12
- package/src/tests/sync.peerReconciliation.test.ts +25 -25
- package/src/tests/sync.storage.test.ts +20 -13
- package/src/tests/sync.test.ts +43 -43
- package/src/tests/sync.upload.test.ts +157 -37
- package/src/tests/testUtils.ts +143 -96
- package/src/typeUtils/expectGroup.ts +1 -1
- package/dist/CoValuesStore.d.ts +0 -14
- package/dist/CoValuesStore.d.ts.map +0 -1
- package/dist/CoValuesStore.js +0 -32
- package/dist/CoValuesStore.js.map +0 -1
- package/dist/coValueCore.d.ts +0 -142
- package/dist/coValueCore.d.ts.map +0 -1
- package/dist/coValueCore.js.map +0 -1
- package/dist/coValueState.d.ts +0 -34
- package/dist/coValueState.d.ts.map +0 -1
- package/dist/coValueState.js +0 -190
- package/dist/coValueState.js.map +0 -1
- package/dist/tests/coValueState.test.d.ts +0 -2
- package/dist/tests/coValueState.test.d.ts.map +0 -1
- package/dist/tests/coValueState.test.js.map +0 -1
- package/src/CoValuesStore.ts +0 -41
- package/src/coValueState.ts +0 -245
|
@@ -70,12 +70,12 @@ describe("SyncStateManager", () => {
|
|
|
70
70
|
const map = group.createMap();
|
|
71
71
|
map.set("key1", "value1", "trusting");
|
|
72
72
|
|
|
73
|
-
const [
|
|
74
|
-
peer1role: "
|
|
75
|
-
peer2role: "
|
|
73
|
+
const [serverPeer] = connectedPeers("serverPeer", "unusedPeer", {
|
|
74
|
+
peer1role: "server",
|
|
75
|
+
peer2role: "client",
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
client.node.syncManager.addPeer(
|
|
78
|
+
client.node.syncManager.addPeer(serverPeer);
|
|
79
79
|
|
|
80
80
|
const subscriptionManager = client.node.syncManager.syncState;
|
|
81
81
|
|
|
@@ -86,7 +86,7 @@ describe("SyncStateManager", () => {
|
|
|
86
86
|
updateToJazzCloudSpy,
|
|
87
87
|
);
|
|
88
88
|
const unsubscribe2 = subscriptionManager.subscribeToPeerUpdates(
|
|
89
|
-
|
|
89
|
+
serverPeer.id,
|
|
90
90
|
updateToStorageSpy,
|
|
91
91
|
);
|
|
92
92
|
|
|
@@ -115,7 +115,7 @@ describe("SyncStateManager", () => {
|
|
|
115
115
|
);
|
|
116
116
|
|
|
117
117
|
expect(updateToStorageSpy).toHaveBeenLastCalledWith(
|
|
118
|
-
emptyKnownState(
|
|
118
|
+
emptyKnownState(group.core.id),
|
|
119
119
|
{ uploaded: false },
|
|
120
120
|
);
|
|
121
121
|
});
|
|
@@ -247,4 +247,54 @@ describe("SyncStateManager", () => {
|
|
|
247
247
|
),
|
|
248
248
|
).toEqual({ uploaded: true });
|
|
249
249
|
});
|
|
250
|
+
|
|
251
|
+
test("should skip closed peers", async () => {
|
|
252
|
+
const client = setupTestNode();
|
|
253
|
+
const { peerState } = client.connectToSyncServer();
|
|
254
|
+
|
|
255
|
+
peerState.gracefulShutdown();
|
|
256
|
+
|
|
257
|
+
const group = client.node.createGroup();
|
|
258
|
+
const map = group.createMap();
|
|
259
|
+
|
|
260
|
+
await expect(map.core.waitForSync()).resolves.toBeUndefined();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("should skip client peers that are not subscribed to the coValue", async () => {
|
|
264
|
+
const server = setupTestNode({ isSyncServer: true });
|
|
265
|
+
const client = setupTestNode();
|
|
266
|
+
|
|
267
|
+
client.connectToSyncServer({
|
|
268
|
+
syncServer: server.node,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
const group = server.node.createGroup();
|
|
272
|
+
const map = group.createMap();
|
|
273
|
+
|
|
274
|
+
await map.core.waitForSync();
|
|
275
|
+
|
|
276
|
+
expect(client.node.getCoValue(map.id).isAvailable()).toBe(false);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("should wait for client peers that are subscribed to the coValue", async () => {
|
|
280
|
+
const server = setupTestNode({ isSyncServer: true });
|
|
281
|
+
const client = setupTestNode();
|
|
282
|
+
|
|
283
|
+
const { peerStateOnServer } = client.connectToSyncServer();
|
|
284
|
+
|
|
285
|
+
const group = server.node.createGroup();
|
|
286
|
+
const map = group.createMap();
|
|
287
|
+
map.set("key1", "value1", "trusting");
|
|
288
|
+
|
|
289
|
+
// Simulate the subscription to the coValue
|
|
290
|
+
peerStateOnServer.setKnownState(map.core.id, {
|
|
291
|
+
id: map.core.id,
|
|
292
|
+
header: true,
|
|
293
|
+
sessions: {},
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await map.core.waitForSync();
|
|
297
|
+
|
|
298
|
+
expect(client.node.getCoValue(map.id).isAvailable()).toBe(true);
|
|
299
|
+
});
|
|
250
300
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
+
import { expectAccount } from "../coValues/account.js";
|
|
2
3
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
3
4
|
import { LocalNode } from "../localNode.js";
|
|
4
5
|
import { connectedPeers } from "../streamUtils.js";
|
|
6
|
+
import { createMockStoragePeer } from "./testUtils.js";
|
|
5
7
|
|
|
6
8
|
const Crypto = await WasmCrypto.create();
|
|
7
9
|
|
|
@@ -85,3 +87,25 @@ test("throws an error if the user tried to create an invite from an account", as
|
|
|
85
87
|
"Cannot create invite from an account",
|
|
86
88
|
);
|
|
87
89
|
});
|
|
90
|
+
|
|
91
|
+
test("wait for storage sync before resolving withNewlyCreatedAccount", async () => {
|
|
92
|
+
const { storage, peer } = createMockStoragePeer({
|
|
93
|
+
peerId: "account-node",
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const { node, accountID } = await LocalNode.withNewlyCreatedAccount({
|
|
97
|
+
creationProps: { name: "Hermes Puggington" },
|
|
98
|
+
crypto: Crypto,
|
|
99
|
+
peersToLoadFrom: [peer],
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const account = storage.getCoValue(accountID);
|
|
103
|
+
|
|
104
|
+
expect(account.isAvailable()).toBe(true);
|
|
105
|
+
|
|
106
|
+
const profile = storage.getCoValue(
|
|
107
|
+
expectAccount(account.getCurrentContent()).get("profile")!,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(profile.isAvailable()).toBe(true);
|
|
111
|
+
});
|
package/src/tests/coList.test.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { beforeEach, expect, test } from "vitest";
|
|
|
2
2
|
import { expectList } from "../coValue.js";
|
|
3
3
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
4
4
|
import { LocalNode } from "../localNode.js";
|
|
5
|
+
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
5
6
|
import {
|
|
6
7
|
loadCoValueOrFail,
|
|
7
|
-
|
|
8
|
+
nodeWithRandomAgentAndSessionID,
|
|
9
|
+
randomAgentAndSessionID,
|
|
8
10
|
setupTestNode,
|
|
9
11
|
waitFor,
|
|
10
12
|
} from "./testUtils.js";
|
|
@@ -16,7 +18,7 @@ beforeEach(async () => {
|
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
test("Empty CoList works", () => {
|
|
19
|
-
const node =
|
|
21
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
20
22
|
|
|
21
23
|
const coValue = node.createCoValue({
|
|
22
24
|
type: "colist",
|
|
@@ -32,7 +34,7 @@ test("Empty CoList works", () => {
|
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
test("Can append, prepend, delete and replace items in CoList", () => {
|
|
35
|
-
const node =
|
|
37
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
36
38
|
|
|
37
39
|
const coValue = node.createCoValue({
|
|
38
40
|
type: "colist",
|
|
@@ -63,7 +65,7 @@ test("Can append, prepend, delete and replace items in CoList", () => {
|
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
test("Push is equivalent to append after last item", () => {
|
|
66
|
-
const node =
|
|
68
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
67
69
|
|
|
68
70
|
const coValue = node.createCoValue({
|
|
69
71
|
type: "colist",
|
|
@@ -85,7 +87,7 @@ test("Push is equivalent to append after last item", () => {
|
|
|
85
87
|
});
|
|
86
88
|
|
|
87
89
|
test("appendItems add an array of items at the end of the list", () => {
|
|
88
|
-
const node =
|
|
90
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
89
91
|
|
|
90
92
|
const coValue = node.createCoValue({
|
|
91
93
|
type: "colist",
|
|
@@ -105,7 +107,7 @@ test("appendItems add an array of items at the end of the list", () => {
|
|
|
105
107
|
});
|
|
106
108
|
|
|
107
109
|
test("appendItems at index", () => {
|
|
108
|
-
const node =
|
|
110
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
109
111
|
|
|
110
112
|
const coValue = node.createCoValue({
|
|
111
113
|
type: "colist",
|
|
@@ -135,7 +137,7 @@ test("appendItems at index", () => {
|
|
|
135
137
|
});
|
|
136
138
|
|
|
137
139
|
test("appendItems at index", () => {
|
|
138
|
-
const node =
|
|
140
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
139
141
|
|
|
140
142
|
const coValue = node.createCoValue({
|
|
141
143
|
type: "colist",
|
|
@@ -157,7 +159,7 @@ test("appendItems at index", () => {
|
|
|
157
159
|
});
|
|
158
160
|
|
|
159
161
|
test("appendItems with negative index", () => {
|
|
160
|
-
const node =
|
|
162
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
161
163
|
|
|
162
164
|
const coValue = node.createCoValue({
|
|
163
165
|
type: "colist",
|
|
@@ -175,7 +177,7 @@ test("appendItems with negative index", () => {
|
|
|
175
177
|
});
|
|
176
178
|
|
|
177
179
|
test("Can push into empty list", () => {
|
|
178
|
-
const node =
|
|
180
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
179
181
|
|
|
180
182
|
const coValue = node.createCoValue({
|
|
181
183
|
type: "colist",
|
|
@@ -193,7 +195,7 @@ test("Can push into empty list", () => {
|
|
|
193
195
|
});
|
|
194
196
|
|
|
195
197
|
test("init the list correctly", () => {
|
|
196
|
-
const node =
|
|
198
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
197
199
|
|
|
198
200
|
const group = node.createGroup();
|
|
199
201
|
|
|
@@ -213,7 +215,7 @@ test("init the list correctly", () => {
|
|
|
213
215
|
});
|
|
214
216
|
|
|
215
217
|
test("Items prepended to start appear with latest first", () => {
|
|
216
|
-
const node =
|
|
218
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
217
219
|
|
|
218
220
|
const coValue = node.createCoValue({
|
|
219
221
|
type: "colist",
|
|
@@ -232,7 +234,7 @@ test("Items prepended to start appear with latest first", () => {
|
|
|
232
234
|
});
|
|
233
235
|
|
|
234
236
|
test("mixing prepend and append", () => {
|
|
235
|
-
const node =
|
|
237
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
236
238
|
|
|
237
239
|
const coValue = node.createCoValue({
|
|
238
240
|
type: "colist",
|
|
@@ -251,7 +253,7 @@ test("mixing prepend and append", () => {
|
|
|
251
253
|
});
|
|
252
254
|
|
|
253
255
|
test("Items appended to start", () => {
|
|
254
|
-
const node =
|
|
256
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
255
257
|
|
|
256
258
|
const coValue = node.createCoValue({
|
|
257
259
|
type: "colist",
|
|
@@ -277,7 +279,9 @@ test("syncing appends with an older timestamp", async () => {
|
|
|
277
279
|
});
|
|
278
280
|
const otherClient = setupTestNode({});
|
|
279
281
|
|
|
280
|
-
const otherClientConnection = otherClient.connectToSyncServer(
|
|
282
|
+
const otherClientConnection = otherClient.connectToSyncServer({
|
|
283
|
+
ourName: "otherClient",
|
|
284
|
+
});
|
|
281
285
|
|
|
282
286
|
const coValue = client.node.createCoValue({
|
|
283
287
|
type: "colist",
|
|
@@ -309,7 +313,9 @@ test("syncing appends with an older timestamp", async () => {
|
|
|
309
313
|
|
|
310
314
|
list.append(6, undefined, "trusting");
|
|
311
315
|
|
|
312
|
-
otherClient.connectToSyncServer(
|
|
316
|
+
otherClient.connectToSyncServer({
|
|
317
|
+
ourName: "otherClient",
|
|
318
|
+
});
|
|
313
319
|
|
|
314
320
|
await waitFor(() => {
|
|
315
321
|
expect(list.toJSON()).toEqual([1, 2, 4, 6, 3, 5]);
|
package/src/tests/coMap.test.ts
CHANGED
|
@@ -2,12 +2,11 @@ import { beforeEach, expect, test } from "vitest";
|
|
|
2
2
|
import { expectMap } from "../coValue.js";
|
|
3
3
|
import { operationToEditEntry } from "../coValues/coMap.js";
|
|
4
4
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
5
|
-
import { LocalNode } from "../localNode.js";
|
|
6
5
|
import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
|
|
7
6
|
import {
|
|
8
7
|
hotSleep,
|
|
9
8
|
loadCoValueOrFail,
|
|
10
|
-
|
|
9
|
+
nodeWithRandomAgentAndSessionID,
|
|
11
10
|
setupTestNode,
|
|
12
11
|
waitFor,
|
|
13
12
|
} from "./testUtils.js";
|
|
@@ -19,7 +18,7 @@ beforeEach(async () => {
|
|
|
19
18
|
});
|
|
20
19
|
|
|
21
20
|
test("Empty CoMap works", () => {
|
|
22
|
-
const node =
|
|
21
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
23
22
|
|
|
24
23
|
const coValue = node.createCoValue({
|
|
25
24
|
type: "comap",
|
|
@@ -36,7 +35,7 @@ test("Empty CoMap works", () => {
|
|
|
36
35
|
});
|
|
37
36
|
|
|
38
37
|
test("Can insert and delete CoMap entries in edit()", () => {
|
|
39
|
-
const node =
|
|
38
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
40
39
|
|
|
41
40
|
const coValue = node.createCoValue({
|
|
42
41
|
type: "comap",
|
|
@@ -60,7 +59,7 @@ test("Can insert and delete CoMap entries in edit()", () => {
|
|
|
60
59
|
});
|
|
61
60
|
|
|
62
61
|
test("Can get CoMap entry values at different points in time", () => {
|
|
63
|
-
const node =
|
|
62
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
64
63
|
|
|
65
64
|
const coValue = node.createCoValue({
|
|
66
65
|
type: "comap",
|
|
@@ -110,7 +109,7 @@ test("Can get CoMap entry values at different points in time", () => {
|
|
|
110
109
|
});
|
|
111
110
|
|
|
112
111
|
test("Can get all historic values of key in CoMap", () => {
|
|
113
|
-
const node =
|
|
112
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
114
113
|
|
|
115
114
|
const coValue = node.createCoValue({
|
|
116
115
|
type: "comap",
|
|
@@ -134,25 +133,25 @@ test("Can get all historic values of key in CoMap", () => {
|
|
|
134
133
|
expect([...content.editsAt("hello")]).toEqual([
|
|
135
134
|
{
|
|
136
135
|
tx: editA!.tx,
|
|
137
|
-
by: node.
|
|
136
|
+
by: node.getCurrentAgent().id,
|
|
138
137
|
value: "A",
|
|
139
138
|
at: editA?.at,
|
|
140
139
|
},
|
|
141
140
|
{
|
|
142
141
|
tx: editB!.tx,
|
|
143
|
-
by: node.
|
|
142
|
+
by: node.getCurrentAgent().id,
|
|
144
143
|
value: "B",
|
|
145
144
|
at: editB?.at,
|
|
146
145
|
},
|
|
147
146
|
{
|
|
148
147
|
tx: editDel!.tx,
|
|
149
|
-
by: node.
|
|
148
|
+
by: node.getCurrentAgent().id,
|
|
150
149
|
value: undefined,
|
|
151
150
|
at: editDel?.at,
|
|
152
151
|
},
|
|
153
152
|
{
|
|
154
153
|
tx: editC!.tx,
|
|
155
|
-
by: node.
|
|
154
|
+
by: node.getCurrentAgent().id,
|
|
156
155
|
value: "C",
|
|
157
156
|
at: editC?.at,
|
|
158
157
|
},
|
|
@@ -160,7 +159,7 @@ test("Can get all historic values of key in CoMap", () => {
|
|
|
160
159
|
});
|
|
161
160
|
|
|
162
161
|
test("Can get last tx ID for a key in CoMap", () => {
|
|
163
|
-
const node =
|
|
162
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
164
163
|
|
|
165
164
|
const coValue = node.createCoValue({
|
|
166
165
|
type: "comap",
|
|
@@ -177,7 +176,7 @@ test("Can get last tx ID for a key in CoMap", () => {
|
|
|
177
176
|
content.set("hello", "A", "trusting");
|
|
178
177
|
const sessionID = content.lastEditAt("hello")?.tx.sessionID;
|
|
179
178
|
expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
|
|
180
|
-
node.
|
|
179
|
+
node.getCurrentAgent().id,
|
|
181
180
|
);
|
|
182
181
|
expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(0);
|
|
183
182
|
content.set("hello", "B", "trusting");
|
|
@@ -187,7 +186,7 @@ test("Can get last tx ID for a key in CoMap", () => {
|
|
|
187
186
|
});
|
|
188
187
|
|
|
189
188
|
test("Can set items in bulk with assign", () => {
|
|
190
|
-
const node =
|
|
189
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
191
190
|
|
|
192
191
|
const coValue = node.createCoValue({
|
|
193
192
|
type: "comap",
|
|
@@ -2,7 +2,10 @@ import { afterEach, expect, test, vi } from "vitest";
|
|
|
2
2
|
import { expectPlainText } from "../coValue.js";
|
|
3
3
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
4
4
|
import { LocalNode } from "../localNode.js";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
nodeWithRandomAgentAndSessionID,
|
|
7
|
+
randomAgentAndSessionID,
|
|
8
|
+
} from "./testUtils.js";
|
|
6
9
|
|
|
7
10
|
const Crypto = await WasmCrypto.create();
|
|
8
11
|
|
|
@@ -13,7 +16,7 @@ test("should throw on creation if Intl.Segmenter is not available", () => {
|
|
|
13
16
|
Segmenter: undefined,
|
|
14
17
|
});
|
|
15
18
|
|
|
16
|
-
const node =
|
|
19
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
17
20
|
const group = node.createGroup();
|
|
18
21
|
expect(() => group.createPlainText()).toThrow(
|
|
19
22
|
"Intl.Segmenter is not supported. Use a polyfill to get coPlainText support in Jazz. (eg. https://formatjs.github.io/docs/polyfills/intl-segmenter/)",
|
|
@@ -21,7 +24,7 @@ test("should throw on creation if Intl.Segmenter is not available", () => {
|
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
test("Empty CoPlainText works", () => {
|
|
24
|
-
const node =
|
|
27
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
25
28
|
|
|
26
29
|
const coValue = node.createCoValue({
|
|
27
30
|
type: "coplaintext",
|
|
@@ -37,7 +40,7 @@ test("Empty CoPlainText works", () => {
|
|
|
37
40
|
});
|
|
38
41
|
|
|
39
42
|
test("Can insert into empty CoPlainText", () => {
|
|
40
|
-
const node =
|
|
43
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
41
44
|
|
|
42
45
|
const coValue = node.createCoValue({
|
|
43
46
|
type: "coplaintext",
|
|
@@ -55,7 +58,7 @@ test("Can insert into empty CoPlainText", () => {
|
|
|
55
58
|
});
|
|
56
59
|
|
|
57
60
|
test("Can insert and delete in CoPlainText", () => {
|
|
58
|
-
const node =
|
|
61
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
59
62
|
|
|
60
63
|
const coValue = node.createCoValue({
|
|
61
64
|
type: "coplaintext",
|
|
@@ -88,7 +91,7 @@ test("Can insert and delete in CoPlainText", () => {
|
|
|
88
91
|
});
|
|
89
92
|
|
|
90
93
|
test("Multiple items inserted appear in correct order", () => {
|
|
91
|
-
const node =
|
|
94
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
92
95
|
|
|
93
96
|
const coValue = node.createCoValue({
|
|
94
97
|
type: "coplaintext",
|
|
@@ -109,7 +112,7 @@ test("Multiple items inserted appear in correct order", () => {
|
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
test("Items inserted at start appear with latest first", () => {
|
|
112
|
-
const node =
|
|
115
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
113
116
|
|
|
114
117
|
const coValue = node.createCoValue({
|
|
115
118
|
type: "coplaintext",
|
|
@@ -131,7 +134,7 @@ test("Items inserted at start appear with latest first", () => {
|
|
|
131
134
|
});
|
|
132
135
|
|
|
133
136
|
test("Handles different locales correctly", () => {
|
|
134
|
-
const node =
|
|
137
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
135
138
|
|
|
136
139
|
// Test with explicit locale in meta
|
|
137
140
|
const coValueJa = node.createCoValue({
|
|
@@ -175,7 +178,7 @@ test("Handles different locales correctly", () => {
|
|
|
175
178
|
});
|
|
176
179
|
|
|
177
180
|
test("insertBefore and insertAfter work as expected", () => {
|
|
178
|
-
const node =
|
|
181
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
179
182
|
const coValue = node.createCoValue({
|
|
180
183
|
type: "coplaintext",
|
|
181
184
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, test } from "vitest";
|
|
2
2
|
import { expectStream } from "../coValue.js";
|
|
3
|
-
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
|
|
3
|
+
import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore/coValueCore.js";
|
|
4
4
|
import {
|
|
5
5
|
BinaryStreamItem,
|
|
6
6
|
CoStreamItem,
|
|
@@ -12,7 +12,8 @@ import { SessionID } from "../ids.js";
|
|
|
12
12
|
import { LocalNode } from "../localNode.js";
|
|
13
13
|
import {
|
|
14
14
|
loadCoValueOrFail,
|
|
15
|
-
|
|
15
|
+
nodeWithRandomAgentAndSessionID,
|
|
16
|
+
randomAgentAndSessionID,
|
|
16
17
|
setupTestNode,
|
|
17
18
|
waitFor,
|
|
18
19
|
} from "./testUtils.js";
|
|
@@ -24,7 +25,7 @@ beforeEach(async () => {
|
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
test("Empty CoStream works", () => {
|
|
27
|
-
const node =
|
|
28
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
28
29
|
|
|
29
30
|
const coValue = node.createCoValue({
|
|
30
31
|
type: "costream",
|
|
@@ -41,7 +42,7 @@ test("Empty CoStream works", () => {
|
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
test("Can push into CoStream", () => {
|
|
44
|
-
const node =
|
|
45
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
45
46
|
|
|
46
47
|
const coValue = node.createCoValue({
|
|
47
48
|
type: "costream",
|
|
@@ -67,7 +68,7 @@ test("Can push into CoStream", () => {
|
|
|
67
68
|
});
|
|
68
69
|
|
|
69
70
|
test("Empty RawBinaryCoStream works", () => {
|
|
70
|
-
const node =
|
|
71
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
71
72
|
|
|
72
73
|
const coValue = node.createCoValue({
|
|
73
74
|
type: "costream",
|
|
@@ -93,7 +94,7 @@ test("Empty RawBinaryCoStream works", () => {
|
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
test("Can push into RawBinaryCoStream", () => {
|
|
96
|
-
const node =
|
|
97
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
97
98
|
|
|
98
99
|
const coValue = node.createCoValue({
|
|
99
100
|
type: "costream",
|
|
@@ -129,7 +130,7 @@ test("Can push into RawBinaryCoStream", () => {
|
|
|
129
130
|
});
|
|
130
131
|
|
|
131
132
|
test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature every time we reach MAX_RECOMMENDED_TX_SIZE and split up newContentSince accordingly", () => {
|
|
132
|
-
const node =
|
|
133
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
133
134
|
|
|
134
135
|
const coValue = node.createCoValue({
|
|
135
136
|
type: "costream",
|
|
@@ -161,7 +162,11 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
161
162
|
|
|
162
163
|
content.endBinaryStream("trusting");
|
|
163
164
|
|
|
164
|
-
|
|
165
|
+
if (!coValue.isAvailable()) {
|
|
166
|
+
throw new Error("CoValue is not available");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
|
|
165
170
|
expect(sessionEntry.transactions.length).toEqual(12);
|
|
166
171
|
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
167
172
|
expect(sessionEntry.signatureAfter[1]).not.toBeDefined();
|
|
@@ -176,7 +181,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
176
181
|
expect(sessionEntry.signatureAfter[10]).not.toBeDefined();
|
|
177
182
|
expect(sessionEntry.signatureAfter[11]).not.toBeDefined();
|
|
178
183
|
|
|
179
|
-
const newContent = coValue.newContentSince({
|
|
184
|
+
const newContent = coValue.verified.newContentSince({
|
|
180
185
|
id: coValue.id,
|
|
181
186
|
header: false,
|
|
182
187
|
sessions: {},
|
|
@@ -199,7 +204,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
|
|
|
199
204
|
});
|
|
200
205
|
|
|
201
206
|
test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature after every large transaction and split up newContentSince accordingly", () => {
|
|
202
|
-
const node =
|
|
207
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
203
208
|
|
|
204
209
|
const coValue = node.createCoValue({
|
|
205
210
|
type: "costream",
|
|
@@ -231,7 +236,11 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
231
236
|
|
|
232
237
|
content.endBinaryStream("trusting");
|
|
233
238
|
|
|
234
|
-
|
|
239
|
+
if (!coValue.isAvailable()) {
|
|
240
|
+
throw new Error("CoValue is not available");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
|
|
235
244
|
expect(sessionEntry.transactions.length).toEqual(5);
|
|
236
245
|
expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
|
|
237
246
|
expect(sessionEntry.signatureAfter[1]).toBeDefined();
|
|
@@ -239,7 +248,7 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
|
|
|
239
248
|
expect(sessionEntry.signatureAfter[3]).toBeDefined();
|
|
240
249
|
expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
|
|
241
250
|
|
|
242
|
-
const newContent = coValue.newContentSince({
|
|
251
|
+
const newContent = coValue.verified.newContentSince({
|
|
243
252
|
id: coValue.id,
|
|
244
253
|
header: false,
|
|
245
254
|
sessions: {},
|
|
@@ -308,7 +317,7 @@ test("totalValidTransactions should return the number of valid transactions proc
|
|
|
308
317
|
|
|
309
318
|
describe("isBinaryStreamEnded", () => {
|
|
310
319
|
function setup() {
|
|
311
|
-
const node =
|
|
320
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
312
321
|
|
|
313
322
|
const coValue = node.createCoValue({
|
|
314
323
|
type: "costream",
|
|
@@ -371,7 +380,7 @@ describe("Binary stream order", () => {
|
|
|
371
380
|
}
|
|
372
381
|
|
|
373
382
|
test("sorts by madeAt timestamp first", () => {
|
|
374
|
-
const node =
|
|
383
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
375
384
|
const coValue = node.createCoValue({
|
|
376
385
|
type: "costream",
|
|
377
386
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -403,7 +412,7 @@ describe("Binary stream order", () => {
|
|
|
403
412
|
});
|
|
404
413
|
|
|
405
414
|
test("sorts by sessionID when timestamps are equal", () => {
|
|
406
|
-
const node =
|
|
415
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
407
416
|
const coValue = node.createCoValue({
|
|
408
417
|
type: "costream",
|
|
409
418
|
ruleset: { type: "unsafeAllowAll" },
|
|
@@ -436,7 +445,7 @@ describe("Binary stream order", () => {
|
|
|
436
445
|
});
|
|
437
446
|
|
|
438
447
|
test("sorts by txIndex when timestamps and sessionIDs are equal", () => {
|
|
439
|
-
const node =
|
|
448
|
+
const node = nodeWithRandomAgentAndSessionID();
|
|
440
449
|
const coValue = node.createCoValue({
|
|
441
450
|
type: "costream",
|
|
442
451
|
ruleset: { type: "unsafeAllowAll" },
|