cojson 0.8.12 → 0.8.17
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/CHANGELOG.md +95 -83
- package/dist/native/PeerKnownStates.js +6 -1
- package/dist/native/PeerKnownStates.js.map +1 -1
- package/dist/native/PeerState.js +4 -3
- package/dist/native/PeerState.js.map +1 -1
- package/dist/native/PriorityBasedMessageQueue.js +1 -10
- package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/native/SyncStateSubscriptionManager.js +70 -0
- package/dist/native/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/native/base64url.js.map +1 -1
- package/dist/native/base64url.test.js +1 -1
- package/dist/native/base64url.test.js.map +1 -1
- package/dist/native/coValue.js.map +1 -1
- package/dist/native/coValueCore.js +141 -149
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValueState.js.map +1 -1
- package/dist/native/coValues/account.js +6 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +2 -3
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +1 -1
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +3 -5
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/group.js +11 -11
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coreToCoValue.js +2 -2
- package/dist/native/coreToCoValue.js.map +1 -1
- package/dist/native/crypto/PureJSCrypto.js +4 -4
- package/dist/native/crypto/PureJSCrypto.js.map +1 -1
- package/dist/native/crypto/crypto.js.map +1 -1
- package/dist/native/exports.js +12 -12
- package/dist/native/exports.js.map +1 -1
- package/dist/native/ids.js.map +1 -1
- package/dist/native/jsonStringify.js.map +1 -1
- package/dist/native/localNode.js +5 -7
- package/dist/native/localNode.js.map +1 -1
- package/dist/native/permissions.js +4 -7
- package/dist/native/permissions.js.map +1 -1
- package/dist/native/priority.js.map +1 -1
- package/dist/native/storage/FileSystem.js.map +1 -1
- package/dist/native/storage/chunksAndKnownStates.js +2 -4
- package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/native/storage/index.js +6 -15
- package/dist/native/storage/index.js.map +1 -1
- package/dist/native/streamUtils.js.map +1 -1
- package/dist/native/sync.js +57 -7
- package/dist/native/sync.js.map +1 -1
- package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/native/typeUtils/expectGroup.js.map +1 -1
- package/dist/native/typeUtils/isAccountID.js.map +1 -1
- package/dist/native/typeUtils/isCoValue.js +1 -1
- package/dist/native/typeUtils/isCoValue.js.map +1 -1
- package/dist/web/PeerKnownStates.js +6 -1
- package/dist/web/PeerKnownStates.js.map +1 -1
- package/dist/web/PeerState.js +4 -3
- package/dist/web/PeerState.js.map +1 -1
- package/dist/web/PriorityBasedMessageQueue.js +1 -10
- package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/web/SyncStateSubscriptionManager.js +70 -0
- package/dist/web/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/web/base64url.js.map +1 -1
- package/dist/web/base64url.test.js +1 -1
- package/dist/web/base64url.test.js.map +1 -1
- package/dist/web/coValue.js.map +1 -1
- package/dist/web/coValueCore.js +141 -149
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValueState.js.map +1 -1
- package/dist/web/coValues/account.js +6 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +2 -3
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +1 -1
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +3 -5
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/group.js +11 -11
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coreToCoValue.js +2 -2
- package/dist/web/coreToCoValue.js.map +1 -1
- package/dist/web/crypto/PureJSCrypto.js +4 -4
- package/dist/web/crypto/PureJSCrypto.js.map +1 -1
- package/dist/web/crypto/WasmCrypto.js +5 -5
- package/dist/web/crypto/WasmCrypto.js.map +1 -1
- package/dist/web/crypto/crypto.js.map +1 -1
- package/dist/web/exports.js +12 -12
- package/dist/web/exports.js.map +1 -1
- package/dist/web/ids.js.map +1 -1
- package/dist/web/jsonStringify.js.map +1 -1
- package/dist/web/localNode.js +5 -7
- package/dist/web/localNode.js.map +1 -1
- package/dist/web/permissions.js +4 -7
- package/dist/web/permissions.js.map +1 -1
- package/dist/web/priority.js.map +1 -1
- package/dist/web/storage/FileSystem.js.map +1 -1
- package/dist/web/storage/chunksAndKnownStates.js +2 -4
- package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/web/storage/index.js +6 -15
- package/dist/web/storage/index.js.map +1 -1
- package/dist/web/streamUtils.js.map +1 -1
- package/dist/web/sync.js +57 -7
- package/dist/web/sync.js.map +1 -1
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/web/typeUtils/expectGroup.js.map +1 -1
- package/dist/web/typeUtils/isAccountID.js.map +1 -1
- package/dist/web/typeUtils/isCoValue.js +1 -1
- package/dist/web/typeUtils/isCoValue.js.map +1 -1
- package/package.json +4 -14
- package/src/PeerKnownStates.ts +98 -90
- package/src/PeerState.ts +92 -73
- package/src/PriorityBasedMessageQueue.ts +42 -49
- package/src/SyncStateSubscriptionManager.ts +124 -0
- package/src/base64url.test.ts +24 -24
- package/src/base64url.ts +44 -45
- package/src/coValue.ts +45 -45
- package/src/coValueCore.ts +746 -785
- package/src/coValueState.ts +82 -72
- package/src/coValues/account.ts +143 -150
- package/src/coValues/coList.ts +520 -522
- package/src/coValues/coMap.ts +283 -285
- package/src/coValues/coStream.ts +320 -324
- package/src/coValues/group.ts +306 -305
- package/src/coreToCoValue.ts +28 -31
- package/src/crypto/PureJSCrypto.ts +188 -194
- package/src/crypto/WasmCrypto.ts +236 -254
- package/src/crypto/crypto.ts +302 -309
- package/src/exports.ts +116 -116
- package/src/ids.ts +9 -9
- package/src/jsonStringify.ts +46 -46
- package/src/jsonValue.ts +24 -10
- package/src/localNode.ts +635 -660
- package/src/media.ts +3 -3
- package/src/permissions.ts +272 -278
- package/src/priority.ts +21 -19
- package/src/storage/FileSystem.ts +91 -99
- package/src/storage/chunksAndKnownStates.ts +110 -115
- package/src/storage/index.ts +466 -497
- package/src/streamUtils.ts +60 -60
- package/src/sync.ts +656 -608
- package/src/tests/PeerKnownStates.test.ts +38 -34
- package/src/tests/PeerState.test.ts +101 -64
- package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
- package/src/tests/SyncStateSubscriptionManager.test.ts +232 -0
- package/src/tests/account.test.ts +59 -59
- package/src/tests/coList.test.ts +65 -65
- package/src/tests/coMap.test.ts +137 -137
- package/src/tests/coStream.test.ts +254 -257
- package/src/tests/coValueCore.test.ts +153 -156
- package/src/tests/crypto.test.ts +136 -144
- package/src/tests/cryptoImpl.test.ts +205 -197
- package/src/tests/group.test.ts +24 -24
- package/src/tests/permissions.test.ts +1306 -1371
- package/src/tests/priority.test.ts +65 -82
- package/src/tests/sync.test.ts +1573 -1263
- package/src/tests/testUtils.ts +85 -53
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
- package/src/typeUtils/expectGroup.ts +9 -9
- package/src/typeUtils/isAccountID.ts +1 -1
- package/src/typeUtils/isCoValue.ts +9 -9
- package/tsconfig.json +4 -6
- package/tsconfig.native.json +9 -11
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -25
- package/.prettierrc.js +0 -9
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { describe, expect, onTestFinished, test, vi } from "vitest";
|
|
2
|
+
import { connectedPeers } from "../streamUtils.js";
|
|
3
|
+
import { emptyKnownState } from "../sync.js";
|
|
4
|
+
import { createTestNode, waitFor } from "./testUtils.js";
|
|
5
|
+
|
|
6
|
+
describe("SyncStateSubscriptionManager", () => {
|
|
7
|
+
test("subscribeToUpdates receives updates when peer state changes", async () => {
|
|
8
|
+
// Setup nodes
|
|
9
|
+
const client = createTestNode();
|
|
10
|
+
const jazzCloud = createTestNode();
|
|
11
|
+
|
|
12
|
+
// Create test data
|
|
13
|
+
const group = client.createGroup();
|
|
14
|
+
const map = group.createMap();
|
|
15
|
+
map.set("key1", "value1", "trusting");
|
|
16
|
+
|
|
17
|
+
// Connect nodes
|
|
18
|
+
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
|
19
|
+
"clientConnection",
|
|
20
|
+
"jazzCloudConnection",
|
|
21
|
+
{
|
|
22
|
+
peer1role: "client",
|
|
23
|
+
peer2role: "server",
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
client.syncManager.addPeer(jazzCloudAsPeer);
|
|
28
|
+
jazzCloud.syncManager.addPeer(clientAsPeer);
|
|
29
|
+
|
|
30
|
+
const subscriptionManager = client.syncManager.syncStateSubscriptionManager;
|
|
31
|
+
|
|
32
|
+
const updateSpy = vi.fn();
|
|
33
|
+
const unsubscribe = subscriptionManager.subscribeToUpdates(updateSpy);
|
|
34
|
+
|
|
35
|
+
await client.syncManager.actuallySyncCoValue(map.core);
|
|
36
|
+
|
|
37
|
+
expect(updateSpy).toHaveBeenCalledWith(
|
|
38
|
+
"jazzCloudConnection",
|
|
39
|
+
emptyKnownState(map.core.id),
|
|
40
|
+
false,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
await waitFor(() => {
|
|
44
|
+
return subscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
45
|
+
"jazzCloudConnection",
|
|
46
|
+
map.core.id,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(updateSpy).toHaveBeenCalledWith(
|
|
51
|
+
"jazzCloudConnection",
|
|
52
|
+
client.syncManager.peers["jazzCloudConnection"]!.knownStates.get(
|
|
53
|
+
map.core.id,
|
|
54
|
+
)!,
|
|
55
|
+
true,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Cleanup
|
|
59
|
+
unsubscribe();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("subscribeToPeerUpdates receives updates only for specific peer", async () => {
|
|
63
|
+
// Setup nodes
|
|
64
|
+
const client = createTestNode();
|
|
65
|
+
const jazzCloud = createTestNode();
|
|
66
|
+
|
|
67
|
+
// Create test data
|
|
68
|
+
const group = client.createGroup();
|
|
69
|
+
const map = group.createMap();
|
|
70
|
+
map.set("key1", "value1", "trusting");
|
|
71
|
+
|
|
72
|
+
// Connect nodes
|
|
73
|
+
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
|
74
|
+
"clientConnection",
|
|
75
|
+
"jazzCloudConnection",
|
|
76
|
+
{
|
|
77
|
+
peer1role: "client",
|
|
78
|
+
peer2role: "server",
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const [clientStoragePeer] = connectedPeers("clientStorage", "unusedPeer", {
|
|
83
|
+
peer1role: "client",
|
|
84
|
+
peer2role: "server",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
client.syncManager.addPeer(jazzCloudAsPeer);
|
|
88
|
+
client.syncManager.addPeer(clientStoragePeer);
|
|
89
|
+
jazzCloud.syncManager.addPeer(clientAsPeer);
|
|
90
|
+
|
|
91
|
+
const subscriptionManager = client.syncManager.syncStateSubscriptionManager;
|
|
92
|
+
|
|
93
|
+
const updateToJazzCloudSpy = vi.fn();
|
|
94
|
+
const updateToStorageSpy = vi.fn();
|
|
95
|
+
const unsubscribe1 = subscriptionManager.subscribeToPeerUpdates(
|
|
96
|
+
"jazzCloudConnection",
|
|
97
|
+
updateToJazzCloudSpy,
|
|
98
|
+
);
|
|
99
|
+
const unsubscribe2 = subscriptionManager.subscribeToPeerUpdates(
|
|
100
|
+
"clientStorage",
|
|
101
|
+
updateToStorageSpy,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
onTestFinished(() => {
|
|
105
|
+
unsubscribe1();
|
|
106
|
+
unsubscribe2();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await client.syncManager.actuallySyncCoValue(map.core);
|
|
110
|
+
|
|
111
|
+
expect(updateToJazzCloudSpy).toHaveBeenCalledWith(
|
|
112
|
+
emptyKnownState(map.core.id),
|
|
113
|
+
false,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
await waitFor(() => {
|
|
117
|
+
return subscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
118
|
+
"jazzCloudConnection",
|
|
119
|
+
map.core.id,
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(updateToJazzCloudSpy).toHaveBeenLastCalledWith(
|
|
124
|
+
client.syncManager.peers["jazzCloudConnection"]!.knownStates.get(
|
|
125
|
+
map.core.id,
|
|
126
|
+
)!,
|
|
127
|
+
true,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(updateToStorageSpy).toHaveBeenLastCalledWith(
|
|
131
|
+
emptyKnownState(map.core.id),
|
|
132
|
+
false,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("getIsCoValueFullyUploadedIntoPeer returns correct status", async () => {
|
|
137
|
+
// Setup nodes
|
|
138
|
+
const client = createTestNode();
|
|
139
|
+
const jazzCloud = createTestNode();
|
|
140
|
+
|
|
141
|
+
// Create test data
|
|
142
|
+
const group = client.createGroup();
|
|
143
|
+
const map = group.createMap();
|
|
144
|
+
map.set("key1", "value1", "trusting");
|
|
145
|
+
|
|
146
|
+
// Connect nodes
|
|
147
|
+
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
|
148
|
+
"clientConnection",
|
|
149
|
+
"jazzCloudConnection",
|
|
150
|
+
{
|
|
151
|
+
peer1role: "client",
|
|
152
|
+
peer2role: "server",
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
client.syncManager.addPeer(jazzCloudAsPeer);
|
|
157
|
+
jazzCloud.syncManager.addPeer(clientAsPeer);
|
|
158
|
+
|
|
159
|
+
await client.syncManager.actuallySyncCoValue(map.core);
|
|
160
|
+
|
|
161
|
+
const subscriptionManager = client.syncManager.syncStateSubscriptionManager;
|
|
162
|
+
|
|
163
|
+
expect(
|
|
164
|
+
subscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
165
|
+
"jazzCloudConnection",
|
|
166
|
+
map.core.id,
|
|
167
|
+
),
|
|
168
|
+
).toBe(false);
|
|
169
|
+
|
|
170
|
+
await waitFor(() => {
|
|
171
|
+
return subscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
172
|
+
"jazzCloudConnection",
|
|
173
|
+
map.core.id,
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(
|
|
178
|
+
subscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
179
|
+
"jazzCloudConnection",
|
|
180
|
+
map.core.id,
|
|
181
|
+
),
|
|
182
|
+
).toBe(true);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("unsubscribe stops receiving updates", async () => {
|
|
186
|
+
// Setup nodes
|
|
187
|
+
const client = createTestNode();
|
|
188
|
+
const jazzCloud = createTestNode();
|
|
189
|
+
|
|
190
|
+
// Create test data
|
|
191
|
+
const group = client.createGroup();
|
|
192
|
+
const map = group.createMap();
|
|
193
|
+
map.set("key1", "value1", "trusting");
|
|
194
|
+
|
|
195
|
+
// Connect nodes
|
|
196
|
+
const [clientAsPeer, jazzCloudAsPeer] = connectedPeers(
|
|
197
|
+
"clientConnection",
|
|
198
|
+
"jazzCloudConnection",
|
|
199
|
+
{
|
|
200
|
+
peer1role: "client",
|
|
201
|
+
peer2role: "server",
|
|
202
|
+
},
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
client.syncManager.addPeer(jazzCloudAsPeer);
|
|
206
|
+
jazzCloud.syncManager.addPeer(clientAsPeer);
|
|
207
|
+
|
|
208
|
+
const subscriptionManager = client.syncManager.syncStateSubscriptionManager;
|
|
209
|
+
const anyUpdateSpy = vi.fn();
|
|
210
|
+
const unsubscribe1 = subscriptionManager.subscribeToUpdates(anyUpdateSpy);
|
|
211
|
+
const unsubscribe2 = subscriptionManager.subscribeToPeerUpdates(
|
|
212
|
+
"jazzCloudConnection",
|
|
213
|
+
anyUpdateSpy,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
unsubscribe1();
|
|
217
|
+
unsubscribe2();
|
|
218
|
+
|
|
219
|
+
await client.syncManager.actuallySyncCoValue(map.core);
|
|
220
|
+
|
|
221
|
+
anyUpdateSpy.mockClear();
|
|
222
|
+
|
|
223
|
+
await waitFor(() => {
|
|
224
|
+
return client.syncManager.syncStateSubscriptionManager.getIsCoValueFullyUploadedIntoPeer(
|
|
225
|
+
"jazzCloudConnection",
|
|
226
|
+
map.core.id,
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(anyUpdateSpy).not.toHaveBeenCalled();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -1,76 +1,76 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
2
3
|
import { LocalNode } from "../localNode.js";
|
|
3
4
|
import { connectedPeers } from "../streamUtils.js";
|
|
4
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
5
5
|
|
|
6
6
|
const Crypto = await WasmCrypto.create();
|
|
7
7
|
|
|
8
8
|
test("Can create a node while creating a new account with profile", async () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
expect(node).not.toBeNull();
|
|
16
|
-
expect(accountID).not.toBeNull();
|
|
17
|
-
expect(accountSecret).not.toBeNull();
|
|
18
|
-
expect(sessionID).not.toBeNull();
|
|
19
|
-
|
|
20
|
-
expect(node.expectProfileLoaded(accountID).get("name")).toEqual(
|
|
21
|
-
"Hermes Puggington",
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test("A node with an account can create groups and and objects within them", async () => {
|
|
26
|
-
const { node, accountID } = await LocalNode.withNewlyCreatedAccount({
|
|
27
|
-
creationProps: { name: "Hermes Puggington" },
|
|
28
|
-
crypto: Crypto,
|
|
9
|
+
const { node, accountID, accountSecret, sessionID } =
|
|
10
|
+
await LocalNode.withNewlyCreatedAccount({
|
|
11
|
+
creationProps: { name: "Hermes Puggington" },
|
|
12
|
+
crypto: Crypto,
|
|
29
13
|
});
|
|
30
14
|
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
expect(node).not.toBeNull();
|
|
16
|
+
expect(accountID).not.toBeNull();
|
|
17
|
+
expect(accountSecret).not.toBeNull();
|
|
18
|
+
expect(sessionID).not.toBeNull();
|
|
19
|
+
|
|
20
|
+
expect(node.expectProfileLoaded(accountID).get("name")).toEqual(
|
|
21
|
+
"Hermes Puggington",
|
|
22
|
+
);
|
|
23
|
+
});
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
test("A node with an account can create groups and and objects within them", async () => {
|
|
26
|
+
const { node, accountID } = await LocalNode.withNewlyCreatedAccount({
|
|
27
|
+
creationProps: { name: "Hermes Puggington" },
|
|
28
|
+
crypto: Crypto,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const group = await node.createGroup();
|
|
32
|
+
expect(group).not.toBeNull();
|
|
33
|
+
|
|
34
|
+
const map = group.createMap();
|
|
35
|
+
map.set("foo", "bar", "private");
|
|
36
|
+
expect(map.get("foo")).toEqual("bar");
|
|
37
|
+
expect(map.lastEditAt("foo")?.by).toEqual(accountID);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
test("Can create account with one node, and then load it on another", async () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const group = await node.createGroup();
|
|
48
|
-
expect(group).not.toBeNull();
|
|
49
|
-
|
|
50
|
-
const map = group.createMap();
|
|
51
|
-
map.set("foo", "bar", "private");
|
|
52
|
-
expect(map.get("foo")).toEqual("bar");
|
|
53
|
-
|
|
54
|
-
const [node1asPeer, node2asPeer] = connectedPeers("node1", "node2", {
|
|
55
|
-
trace: true,
|
|
56
|
-
peer1role: "server",
|
|
57
|
-
peer2role: "client",
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
console.log("After connected peers");
|
|
61
|
-
|
|
62
|
-
node.syncManager.addPeer(node2asPeer);
|
|
63
|
-
|
|
64
|
-
const node2 = await LocalNode.withLoadedAccount({
|
|
65
|
-
accountID,
|
|
66
|
-
accountSecret,
|
|
67
|
-
sessionID: Crypto.newRandomSessionID(accountID),
|
|
68
|
-
peersToLoadFrom: [node1asPeer],
|
|
69
|
-
crypto: Crypto,
|
|
41
|
+
const { node, accountID, accountSecret } =
|
|
42
|
+
await LocalNode.withNewlyCreatedAccount({
|
|
43
|
+
creationProps: { name: "Hermes Puggington" },
|
|
44
|
+
crypto: Crypto,
|
|
70
45
|
});
|
|
71
46
|
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
const group = await node.createGroup();
|
|
48
|
+
expect(group).not.toBeNull();
|
|
49
|
+
|
|
50
|
+
const map = group.createMap();
|
|
51
|
+
map.set("foo", "bar", "private");
|
|
52
|
+
expect(map.get("foo")).toEqual("bar");
|
|
53
|
+
|
|
54
|
+
const [node1asPeer, node2asPeer] = connectedPeers("node1", "node2", {
|
|
55
|
+
trace: true,
|
|
56
|
+
peer1role: "server",
|
|
57
|
+
peer2role: "client",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
console.log("After connected peers");
|
|
61
|
+
|
|
62
|
+
node.syncManager.addPeer(node2asPeer);
|
|
63
|
+
|
|
64
|
+
const node2 = await LocalNode.withLoadedAccount({
|
|
65
|
+
accountID,
|
|
66
|
+
accountSecret,
|
|
67
|
+
sessionID: Crypto.newRandomSessionID(accountID),
|
|
68
|
+
peersToLoadFrom: [node1asPeer],
|
|
69
|
+
crypto: Crypto,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const map2 = await node2.load(map.id);
|
|
73
|
+
if (map2 === "unavailable") throw new Error("Map unavailable");
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
expect(map2.get("foo")).toEqual("bar");
|
|
76
76
|
});
|
package/src/tests/coList.test.ts
CHANGED
|
@@ -1,94 +1,94 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
2
|
import { expectList } from "../coValue.js";
|
|
3
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
3
4
|
import { LocalNode } from "../localNode.js";
|
|
4
5
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
5
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
6
6
|
|
|
7
7
|
const Crypto = await WasmCrypto.create();
|
|
8
8
|
|
|
9
9
|
test("Empty CoList works", () => {
|
|
10
|
-
|
|
10
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const coValue = node.createCoValue({
|
|
13
|
+
type: "colist",
|
|
14
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
15
|
+
meta: null,
|
|
16
|
+
...Crypto.createdNowUnique(),
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const content = expectList(coValue.getCurrentContent());
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
expect(content.type).toEqual("colist");
|
|
22
|
+
expect(content.toJSON()).toEqual([]);
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
test("Can append, prepend, delete and replace items in CoList", () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
26
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
27
|
+
|
|
28
|
+
const coValue = node.createCoValue({
|
|
29
|
+
type: "colist",
|
|
30
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
31
|
+
meta: null,
|
|
32
|
+
...Crypto.createdNowUnique(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const content = expectList(coValue.getCurrentContent());
|
|
36
|
+
|
|
37
|
+
content.append("hello", 0, "trusting");
|
|
38
|
+
expect(content.toJSON()).toEqual(["hello"]);
|
|
39
|
+
content.append("world", 0, "trusting");
|
|
40
|
+
expect(content.toJSON()).toEqual(["hello", "world"]);
|
|
41
|
+
content.prepend("beautiful", 1, "trusting");
|
|
42
|
+
expect(content.toJSON()).toEqual(["hello", "beautiful", "world"]);
|
|
43
|
+
content.prepend("hooray", 3, "trusting");
|
|
44
|
+
expect(content.toJSON()).toEqual(["hello", "beautiful", "world", "hooray"]);
|
|
45
|
+
content.replace(2, "universe", "trusting");
|
|
46
|
+
expect(content.toJSON()).toEqual([
|
|
47
|
+
"hello",
|
|
48
|
+
"beautiful",
|
|
49
|
+
"universe",
|
|
50
|
+
"hooray",
|
|
51
|
+
]);
|
|
52
|
+
content.delete(2, "trusting");
|
|
53
|
+
expect(content.toJSON()).toEqual(["hello", "beautiful", "hooray"]);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test("Push is equivalent to append after last item", () => {
|
|
57
|
-
|
|
57
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const coValue = node.createCoValue({
|
|
60
|
+
type: "colist",
|
|
61
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
62
|
+
meta: null,
|
|
63
|
+
...Crypto.createdNowUnique(),
|
|
64
|
+
});
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
const content = expectList(coValue.getCurrentContent());
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
expect(content.type).toEqual("colist");
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
content.append("hello", 0, "trusting");
|
|
71
|
+
expect(content.toJSON()).toEqual(["hello"]);
|
|
72
|
+
content.append("world", undefined, "trusting");
|
|
73
|
+
expect(content.toJSON()).toEqual(["hello", "world"]);
|
|
74
|
+
content.append("hooray", undefined, "trusting");
|
|
75
|
+
expect(content.toJSON()).toEqual(["hello", "world", "hooray"]);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
test("Can push into empty list", () => {
|
|
79
|
-
|
|
79
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const coValue = node.createCoValue({
|
|
82
|
+
type: "colist",
|
|
83
|
+
ruleset: { type: "unsafeAllowAll" },
|
|
84
|
+
meta: null,
|
|
85
|
+
...Crypto.createdNowUnique(),
|
|
86
|
+
});
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
const content = expectList(coValue.getCurrentContent());
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
expect(content.type).toEqual("colist");
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
content.append("hello", undefined, "trusting");
|
|
93
|
+
expect(content.toJSON()).toEqual(["hello"]);
|
|
94
94
|
});
|