cojson 0.18.28 → 0.18.30
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 +16 -0
- package/dist/PeerState.d.ts +23 -14
- package/dist/PeerState.d.ts.map +1 -1
- package/dist/PeerState.js +74 -23
- package/dist/PeerState.js.map +1 -1
- package/dist/SyncStateManager.d.ts +3 -3
- package/dist/SyncStateManager.d.ts.map +1 -1
- package/dist/SyncStateManager.js +18 -44
- package/dist/SyncStateManager.js.map +1 -1
- package/dist/coValueContentMessage.d.ts.map +1 -1
- package/dist/coValueContentMessage.js +2 -1
- package/dist/coValueContentMessage.js.map +1 -1
- package/dist/coValueCore/PeerKnownState.d.ts +21 -0
- package/dist/coValueCore/PeerKnownState.d.ts.map +1 -0
- package/dist/coValueCore/PeerKnownState.js +52 -0
- package/dist/coValueCore/PeerKnownState.js.map +1 -0
- package/dist/coValueCore/coValueCore.d.ts +39 -8
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +139 -40
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/decryptTransactionChangesAndMeta.d.ts.map +1 -1
- package/dist/coValueCore/decryptTransactionChangesAndMeta.js +0 -5
- package/dist/coValueCore/decryptTransactionChangesAndMeta.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts +0 -14
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValueCore/verifiedState.js +2 -32
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/coValues/coList.d.ts +3 -4
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coList.js +4 -4
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.d.ts +3 -4
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coMap.js +5 -4
- package/dist/coValues/coMap.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 -4
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.d.ts +3 -3
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +74 -52
- package/dist/coValues/group.js.map +1 -1
- package/dist/exports.d.ts +2 -2
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +2 -2
- package/dist/exports.js.map +1 -1
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +7 -5
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.d.ts +5 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +173 -109
- package/dist/permissions.js.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +33 -44
- package/dist/sync.js.map +1 -1
- package/dist/tests/PeerKnownState.test.d.ts +2 -0
- package/dist/tests/PeerKnownState.test.d.ts.map +1 -0
- package/dist/tests/PeerKnownState.test.js +342 -0
- package/dist/tests/PeerKnownState.test.js.map +1 -0
- package/dist/tests/PeerState.test.js +17 -16
- package/dist/tests/PeerState.test.js.map +1 -1
- package/dist/tests/StorageApiAsync.test.js +12 -12
- package/dist/tests/StorageApiAsync.test.js.map +1 -1
- package/dist/tests/StorageApiSync.test.js +11 -11
- package/dist/tests/StorageApiSync.test.js.map +1 -1
- package/dist/tests/SyncStateManager.test.js +16 -21
- package/dist/tests/SyncStateManager.test.js.map +1 -1
- package/dist/tests/coValueCore.dependencies.test.js +59 -0
- package/dist/tests/coValueCore.dependencies.test.js.map +1 -1
- package/dist/tests/coValueCore.test.js +41 -21
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/group.addMember.test.js +266 -219
- package/dist/tests/group.addMember.test.js.map +1 -1
- package/dist/tests/group.inheritance.test.js +12 -0
- package/dist/tests/group.inheritance.test.js.map +1 -1
- package/dist/tests/group.invite.test.js +77 -0
- package/dist/tests/group.invite.test.js.map +1 -1
- package/dist/tests/group.removeMember.test.js +64 -7
- package/dist/tests/group.removeMember.test.js.map +1 -1
- package/dist/tests/group.roleOf.test.js +14 -4
- package/dist/tests/group.roleOf.test.js.map +1 -1
- package/dist/tests/permissions.test.js +51 -202
- package/dist/tests/permissions.test.js.map +1 -1
- package/dist/tests/sync.content.test.js +2 -2
- package/dist/tests/sync.content.test.js.map +1 -1
- package/dist/tests/sync.invite.test.js +6 -6
- package/dist/tests/sync.load.test.js +22 -22
- package/dist/tests/sync.mesh.test.js +9 -9
- package/dist/tests/sync.storage.test.js +13 -7
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.storageAsync.test.js +3 -3
- package/dist/tests/sync.test.js +13 -33
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js +2 -2
- package/package.json +3 -3
- package/src/PeerState.ts +86 -34
- package/src/SyncStateManager.ts +25 -60
- package/src/coValueContentMessage.ts +3 -1
- package/src/coValueCore/PeerKnownState.ts +74 -0
- package/src/coValueCore/coValueCore.ts +180 -49
- package/src/coValueCore/decryptTransactionChangesAndMeta.ts +0 -6
- package/src/coValueCore/verifiedState.ts +2 -37
- package/src/coValues/coList.ts +7 -7
- package/src/coValues/coMap.ts +9 -7
- package/src/coValues/coStream.ts +6 -5
- package/src/coValues/group.ts +99 -60
- package/src/exports.ts +2 -1
- package/src/localNode.ts +7 -5
- package/src/permissions.ts +204 -123
- package/src/sync.ts +37 -53
- package/src/tests/PeerKnownState.test.ts +426 -0
- package/src/tests/PeerState.test.ts +24 -24
- package/src/tests/StorageApiAsync.test.ts +12 -12
- package/src/tests/StorageApiSync.test.ts +11 -11
- package/src/tests/SyncStateManager.test.ts +23 -53
- package/src/tests/coValueCore.dependencies.test.ts +87 -0
- package/src/tests/coValueCore.test.ts +64 -22
- package/src/tests/group.addMember.test.ts +384 -345
- package/src/tests/group.inheritance.test.ts +33 -0
- package/src/tests/group.invite.test.ts +117 -0
- package/src/tests/group.removeMember.test.ts +95 -9
- package/src/tests/group.roleOf.test.ts +16 -4
- package/src/tests/permissions.test.ts +56 -295
- package/src/tests/sync.content.test.ts +2 -2
- package/src/tests/sync.invite.test.ts +6 -6
- package/src/tests/sync.load.test.ts +22 -22
- package/src/tests/sync.mesh.test.ts +9 -9
- package/src/tests/sync.storage.test.ts +13 -8
- package/src/tests/sync.storageAsync.test.ts +3 -3
- package/src/tests/sync.test.ts +21 -50
- package/src/tests/sync.upload.test.ts +2 -2
- package/dist/PeerKnownStates.d.ts +0 -19
- package/dist/PeerKnownStates.d.ts.map +0 -1
- package/dist/PeerKnownStates.js +0 -64
- package/dist/PeerKnownStates.js.map +0 -1
- package/dist/tests/PeerKnownStates.test.d.ts +0 -2
- package/dist/tests/PeerKnownStates.test.d.ts.map +0 -1
- package/dist/tests/PeerKnownStates.test.js +0 -77
- package/dist/tests/PeerKnownStates.test.js.map +0 -1
- package/src/PeerKnownStates.ts +0 -93
- package/src/tests/PeerKnownStates.test.ts +0 -99
|
@@ -170,7 +170,7 @@ describe("StorageApiAsync", () => {
|
|
|
170
170
|
|
|
171
171
|
// Verify that storage known state is updated after load
|
|
172
172
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
173
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
173
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
174
174
|
|
|
175
175
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
176
176
|
|
|
@@ -211,7 +211,7 @@ describe("StorageApiAsync", () => {
|
|
|
211
211
|
|
|
212
212
|
// Verify that storage known state is updated after load
|
|
213
213
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
214
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
214
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
215
215
|
|
|
216
216
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
217
217
|
expect(groupOnNode.get("everyone")).toEqual("reader");
|
|
@@ -239,7 +239,7 @@ describe("StorageApiAsync", () => {
|
|
|
239
239
|
|
|
240
240
|
// Verify that storage known state is updated after store
|
|
241
241
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
242
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
242
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
243
243
|
|
|
244
244
|
node.setStorage(storage);
|
|
245
245
|
|
|
@@ -256,7 +256,7 @@ describe("StorageApiAsync", () => {
|
|
|
256
256
|
|
|
257
257
|
// Create a real group and add a member to create transactions
|
|
258
258
|
const group = fixturesNode.createGroup();
|
|
259
|
-
const knownState = group.core.
|
|
259
|
+
const knownState = group.core.knownState();
|
|
260
260
|
|
|
261
261
|
group.addMember("everyone", "reader");
|
|
262
262
|
|
|
@@ -275,7 +275,7 @@ describe("StorageApiAsync", () => {
|
|
|
275
275
|
|
|
276
276
|
// Verify that storage known state is updated after store
|
|
277
277
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
278
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
278
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
279
279
|
|
|
280
280
|
node.setStorage(storage);
|
|
281
281
|
|
|
@@ -288,7 +288,7 @@ describe("StorageApiAsync", () => {
|
|
|
288
288
|
const { node, storage } = await createTestNode();
|
|
289
289
|
|
|
290
290
|
const group = fixturesNode.createGroup();
|
|
291
|
-
const knownState = group.core.
|
|
291
|
+
const knownState = group.core.knownState();
|
|
292
292
|
|
|
293
293
|
group.addMember("everyone", "reader");
|
|
294
294
|
|
|
@@ -309,7 +309,7 @@ describe("StorageApiAsync", () => {
|
|
|
309
309
|
|
|
310
310
|
// Verify that storage known state is updated after store with correction
|
|
311
311
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
312
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
312
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
313
313
|
|
|
314
314
|
node.setStorage(storage);
|
|
315
315
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
@@ -355,7 +355,7 @@ describe("StorageApiAsync", () => {
|
|
|
355
355
|
|
|
356
356
|
// Verify that storage known state is updated after store with correction
|
|
357
357
|
const finalKnownState = storage.getKnownState(group.id);
|
|
358
|
-
expect(finalKnownState).toEqual(group.core.
|
|
358
|
+
expect(finalKnownState).toEqual(group.core.knownState());
|
|
359
359
|
|
|
360
360
|
node.setStorage(storage);
|
|
361
361
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
@@ -722,8 +722,8 @@ describe("StorageApiAsync", () => {
|
|
|
722
722
|
// Verify that storage known states are updated after load
|
|
723
723
|
const updatedGroupKnownState = storage.getKnownState(group.id);
|
|
724
724
|
const updatedMapKnownState = storage.getKnownState(map.id);
|
|
725
|
-
expect(updatedGroupKnownState).toEqual(group.core.
|
|
726
|
-
expect(updatedMapKnownState).toEqual(map.core.
|
|
725
|
+
expect(updatedGroupKnownState).toEqual(group.core.knownState());
|
|
726
|
+
expect(updatedMapKnownState).toEqual(map.core.knownState());
|
|
727
727
|
|
|
728
728
|
node.setStorage(storage);
|
|
729
729
|
const mapOnNode = await loadCoValueOrFail(node, map.id);
|
|
@@ -759,7 +759,7 @@ describe("StorageApiAsync", () => {
|
|
|
759
759
|
|
|
760
760
|
// Verify group known state is updated after first load
|
|
761
761
|
const afterGroupLoad = storage.getKnownState(group.id);
|
|
762
|
-
expect(afterGroupLoad).toEqual(group.core.
|
|
762
|
+
expect(afterGroupLoad).toEqual(group.core.knownState());
|
|
763
763
|
|
|
764
764
|
// Then load the map - the group dependency should already be loaded
|
|
765
765
|
await storage.load(map.id, callback, done);
|
|
@@ -776,7 +776,7 @@ describe("StorageApiAsync", () => {
|
|
|
776
776
|
|
|
777
777
|
// Verify map known state is updated after second load
|
|
778
778
|
const finalMapKnownState = storage.getKnownState(map.id);
|
|
779
|
-
expect(finalMapKnownState).toEqual(map.core.
|
|
779
|
+
expect(finalMapKnownState).toEqual(map.core.knownState());
|
|
780
780
|
|
|
781
781
|
node.setStorage(storage);
|
|
782
782
|
const mapOnNode = await loadCoValueOrFail(node, map.id);
|
|
@@ -152,7 +152,7 @@ describe("StorageApiSync", () => {
|
|
|
152
152
|
|
|
153
153
|
// Verify that storage known state is updated after load
|
|
154
154
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
155
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
155
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
156
156
|
|
|
157
157
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
158
158
|
|
|
@@ -193,7 +193,7 @@ describe("StorageApiSync", () => {
|
|
|
193
193
|
|
|
194
194
|
// Verify that storage known state is updated after load
|
|
195
195
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
196
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
196
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
197
197
|
|
|
198
198
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
199
199
|
expect(groupOnNode.get("everyone")).toEqual("reader");
|
|
@@ -220,7 +220,7 @@ describe("StorageApiSync", () => {
|
|
|
220
220
|
|
|
221
221
|
// Verify that storage known state is updated after store
|
|
222
222
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
223
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
223
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
224
224
|
|
|
225
225
|
node.setStorage(storage);
|
|
226
226
|
|
|
@@ -254,7 +254,7 @@ describe("StorageApiSync", () => {
|
|
|
254
254
|
|
|
255
255
|
// Verify that storage known state is updated after store
|
|
256
256
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
257
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
257
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
258
258
|
|
|
259
259
|
node.setStorage(storage);
|
|
260
260
|
|
|
@@ -267,7 +267,7 @@ describe("StorageApiSync", () => {
|
|
|
267
267
|
const { node, storage } = await createTestNode();
|
|
268
268
|
|
|
269
269
|
const group = fixturesNode.createGroup();
|
|
270
|
-
const knownState = group.core.
|
|
270
|
+
const knownState = group.core.knownState();
|
|
271
271
|
|
|
272
272
|
group.addMember("everyone", "reader");
|
|
273
273
|
|
|
@@ -288,7 +288,7 @@ describe("StorageApiSync", () => {
|
|
|
288
288
|
|
|
289
289
|
// Verify that storage known state is updated after store with correction
|
|
290
290
|
const updatedKnownState = storage.getKnownState(group.id);
|
|
291
|
-
expect(updatedKnownState).toEqual(group.core.
|
|
291
|
+
expect(updatedKnownState).toEqual(group.core.knownState());
|
|
292
292
|
|
|
293
293
|
node.setStorage(storage);
|
|
294
294
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
@@ -338,7 +338,7 @@ describe("StorageApiSync", () => {
|
|
|
338
338
|
|
|
339
339
|
// Verify that storage known state is updated after store with correction
|
|
340
340
|
const finalKnownState = storage.getKnownState(group.id);
|
|
341
|
-
expect(finalKnownState).toEqual(group.core.
|
|
341
|
+
expect(finalKnownState).toEqual(group.core.knownState());
|
|
342
342
|
|
|
343
343
|
node.setStorage(storage);
|
|
344
344
|
const groupOnNode = await loadCoValueOrFail(node, group.id);
|
|
@@ -518,8 +518,8 @@ describe("StorageApiSync", () => {
|
|
|
518
518
|
// Verify that storage known states are updated after load
|
|
519
519
|
const updatedGroupKnownState = storage.getKnownState(group.id);
|
|
520
520
|
const updatedMapKnownState = storage.getKnownState(map.id);
|
|
521
|
-
expect(updatedGroupKnownState).toEqual(group.core.
|
|
522
|
-
expect(updatedMapKnownState).toEqual(map.core.
|
|
521
|
+
expect(updatedGroupKnownState).toEqual(group.core.knownState());
|
|
522
|
+
expect(updatedMapKnownState).toEqual(map.core.knownState());
|
|
523
523
|
|
|
524
524
|
node.setStorage(storage);
|
|
525
525
|
const mapOnNode = await loadCoValueOrFail(node, map.id);
|
|
@@ -555,7 +555,7 @@ describe("StorageApiSync", () => {
|
|
|
555
555
|
|
|
556
556
|
// Verify group known state is updated after first load
|
|
557
557
|
const afterGroupLoad = storage.getKnownState(group.id);
|
|
558
|
-
expect(afterGroupLoad).toEqual(group.core.
|
|
558
|
+
expect(afterGroupLoad).toEqual(group.core.knownState());
|
|
559
559
|
|
|
560
560
|
// Then load the map - the group dependency should already be loaded
|
|
561
561
|
await storage.load(map.id, callback, done);
|
|
@@ -572,7 +572,7 @@ describe("StorageApiSync", () => {
|
|
|
572
572
|
|
|
573
573
|
// Verify map known state is updated after second load
|
|
574
574
|
const finalMapKnownState = storage.getKnownState(map.id);
|
|
575
|
-
expect(finalMapKnownState).toEqual(map.core.
|
|
575
|
+
expect(finalMapKnownState).toEqual(map.core.knownState());
|
|
576
576
|
|
|
577
577
|
node.setStorage(storage);
|
|
578
578
|
const mapOnNode = await loadCoValueOrFail(node, map.id);
|
|
@@ -39,15 +39,14 @@ describe("SyncStateManager", () => {
|
|
|
39
39
|
const unsubscribe = subscriptionManager.subscribeToUpdates(updateSpy);
|
|
40
40
|
|
|
41
41
|
await waitFor(() => {
|
|
42
|
-
return subscriptionManager.
|
|
43
|
-
.uploaded;
|
|
42
|
+
return subscriptionManager.isSynced(peerState, map.core.id);
|
|
44
43
|
});
|
|
45
44
|
|
|
45
|
+
const newPeerState = client.node.syncManager.peers[peerState.id]!;
|
|
46
|
+
|
|
46
47
|
expect(updateSpy).toHaveBeenCalledWith(
|
|
47
48
|
peerState.id,
|
|
48
|
-
|
|
49
|
-
map.core.id,
|
|
50
|
-
)!,
|
|
49
|
+
newPeerState.getKnownState(map.core.id)!,
|
|
51
50
|
{ uploaded: true },
|
|
52
51
|
);
|
|
53
52
|
|
|
@@ -91,14 +90,11 @@ describe("SyncStateManager", () => {
|
|
|
91
90
|
});
|
|
92
91
|
|
|
93
92
|
await waitFor(() => {
|
|
94
|
-
return subscriptionManager.
|
|
95
|
-
.uploaded;
|
|
93
|
+
return subscriptionManager.isSynced(peerState, map.core.id);
|
|
96
94
|
});
|
|
97
95
|
|
|
98
96
|
expect(updateToJazzCloudSpy).toHaveBeenLastCalledWith(
|
|
99
|
-
|
|
100
|
-
map.core.id,
|
|
101
|
-
)!,
|
|
97
|
+
peerState.getKnownState(map.core.id)!,
|
|
102
98
|
{ uploaded: true },
|
|
103
99
|
);
|
|
104
100
|
|
|
@@ -120,20 +116,13 @@ describe("SyncStateManager", () => {
|
|
|
120
116
|
|
|
121
117
|
const subscriptionManager = client.node.syncManager.syncState;
|
|
122
118
|
|
|
123
|
-
expect(
|
|
124
|
-
subscriptionManager.getCurrentSyncState(peerState.id, map.core.id)
|
|
125
|
-
.uploaded,
|
|
126
|
-
).toBe(false);
|
|
119
|
+
expect(subscriptionManager.isSynced(peerState, map.core.id)).toBe(false);
|
|
127
120
|
|
|
128
121
|
await waitFor(() => {
|
|
129
|
-
return subscriptionManager.
|
|
130
|
-
.uploaded;
|
|
122
|
+
return subscriptionManager.isSynced(peerState, map.core.id);
|
|
131
123
|
});
|
|
132
124
|
|
|
133
|
-
expect(
|
|
134
|
-
subscriptionManager.getCurrentSyncState(peerState.id, map.core.id)
|
|
135
|
-
.uploaded,
|
|
136
|
-
).toBe(true);
|
|
125
|
+
expect(subscriptionManager.isSynced(peerState, map.core.id)).toBe(true);
|
|
137
126
|
});
|
|
138
127
|
|
|
139
128
|
test("unsubscribe stops receiving updates", async () => {
|
|
@@ -160,8 +149,7 @@ describe("SyncStateManager", () => {
|
|
|
160
149
|
anyUpdateSpy.mockClear();
|
|
161
150
|
|
|
162
151
|
await waitFor(() => {
|
|
163
|
-
return subscriptionManager.
|
|
164
|
-
.uploaded;
|
|
152
|
+
return subscriptionManager.isSynced(peerState, map.core.id);
|
|
165
153
|
});
|
|
166
154
|
|
|
167
155
|
expect(anyUpdateSpy).not.toHaveBeenCalled();
|
|
@@ -171,7 +159,7 @@ describe("SyncStateManager", () => {
|
|
|
171
159
|
// Setup nodes
|
|
172
160
|
const client = setupTestNode({ connected: true });
|
|
173
161
|
const serverNode = jazzCloud.node;
|
|
174
|
-
const {
|
|
162
|
+
const { peerState, peerStateOnServer } = client.connectToSyncServer();
|
|
175
163
|
|
|
176
164
|
// Create test data
|
|
177
165
|
const group = client.node.createGroup();
|
|
@@ -181,55 +169,37 @@ describe("SyncStateManager", () => {
|
|
|
181
169
|
|
|
182
170
|
// Initially should not be synced
|
|
183
171
|
expect(
|
|
184
|
-
client.node.syncManager.syncState.
|
|
185
|
-
|
|
186
|
-
map.core.id,
|
|
187
|
-
),
|
|
188
|
-
).toEqual({ uploaded: false });
|
|
172
|
+
client.node.syncManager.syncState.isSynced(peerState, map.core.id),
|
|
173
|
+
).toEqual(false);
|
|
189
174
|
|
|
190
175
|
// Wait for full sync
|
|
191
176
|
await map.core.waitForSync();
|
|
192
177
|
|
|
193
178
|
expect(
|
|
194
|
-
client.node.syncManager.syncState.
|
|
195
|
-
|
|
196
|
-
map.core.id,
|
|
197
|
-
),
|
|
198
|
-
).toEqual({ uploaded: true });
|
|
179
|
+
client.node.syncManager.syncState.isSynced(peerState, map.core.id),
|
|
180
|
+
).toEqual(true);
|
|
199
181
|
|
|
200
182
|
const mapOnServer = await loadCoValueOrFail(serverNode, map.id);
|
|
201
183
|
|
|
202
184
|
mapOnServer.set("key2", "value2", "trusting");
|
|
203
185
|
|
|
204
186
|
expect(
|
|
205
|
-
client.node.syncManager.syncState.
|
|
206
|
-
|
|
207
|
-
map.core.id,
|
|
208
|
-
),
|
|
209
|
-
).toEqual({ uploaded: true });
|
|
187
|
+
client.node.syncManager.syncState.isSynced(peerState, map.core.id),
|
|
188
|
+
).toEqual(true);
|
|
210
189
|
|
|
211
190
|
expect(
|
|
212
|
-
serverNode.syncManager.syncState.
|
|
213
|
-
|
|
214
|
-
map.core.id,
|
|
215
|
-
),
|
|
216
|
-
).toEqual({ uploaded: false });
|
|
191
|
+
serverNode.syncManager.syncState.isSynced(peerStateOnServer, map.core.id),
|
|
192
|
+
).toEqual(false);
|
|
217
193
|
|
|
218
194
|
await mapOnServer.core.waitForSync();
|
|
219
195
|
|
|
220
196
|
expect(
|
|
221
|
-
client.node.syncManager.syncState.
|
|
222
|
-
|
|
223
|
-
map.core.id,
|
|
224
|
-
),
|
|
225
|
-
).toEqual({ uploaded: true });
|
|
197
|
+
client.node.syncManager.syncState.isSynced(peerState, map.core.id),
|
|
198
|
+
).toEqual(true);
|
|
226
199
|
|
|
227
200
|
expect(
|
|
228
|
-
serverNode.syncManager.syncState.
|
|
229
|
-
|
|
230
|
-
map.core.id,
|
|
231
|
-
),
|
|
232
|
-
).toEqual({ uploaded: true });
|
|
201
|
+
serverNode.syncManager.syncState.isSynced(peerStateOnServer, map.core.id),
|
|
202
|
+
).toEqual(true);
|
|
233
203
|
});
|
|
234
204
|
|
|
235
205
|
test("should skip non-persistent closed peers", async () => {
|
|
@@ -88,3 +88,90 @@ test("should track the account dependency when syncing a group extension", async
|
|
|
88
88
|
new Set([parentGroup.core.id, sourceClient.accountID]),
|
|
89
89
|
);
|
|
90
90
|
});
|
|
91
|
+
|
|
92
|
+
test("should track group as dependant when creating a coValue owned by it", () => {
|
|
93
|
+
const client = setupTestNode();
|
|
94
|
+
|
|
95
|
+
const group = client.node.createGroup();
|
|
96
|
+
const map = group.createMap();
|
|
97
|
+
|
|
98
|
+
expect(group.core.dependant).toEqual(new Set([map.core.id]));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("should track source as dependant when creating a branch", () => {
|
|
102
|
+
const client = setupTestNode();
|
|
103
|
+
|
|
104
|
+
const group = client.node.createGroup();
|
|
105
|
+
const map = group.createMap();
|
|
106
|
+
|
|
107
|
+
const branch = map.core.createBranch("feature-branch", group.id);
|
|
108
|
+
|
|
109
|
+
expect(map.core.dependant).toEqual(new Set([branch.id]));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("should track parent group as dependant when extending a group", () => {
|
|
113
|
+
const client = setupTestNode();
|
|
114
|
+
|
|
115
|
+
const group = client.node.createGroup();
|
|
116
|
+
const parentGroup = client.node.createGroup();
|
|
117
|
+
|
|
118
|
+
group.extend(parentGroup);
|
|
119
|
+
|
|
120
|
+
expect(parentGroup.core.dependant).toEqual(new Set([group.core.id]));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("should track multiple dependants when multiple coValues depend on the same group", () => {
|
|
124
|
+
const client = setupTestNode();
|
|
125
|
+
|
|
126
|
+
const group = client.node.createGroup();
|
|
127
|
+
const map1 = group.createMap();
|
|
128
|
+
const map2 = group.createMap();
|
|
129
|
+
const list = group.createList();
|
|
130
|
+
|
|
131
|
+
expect(group.core.dependant).toEqual(
|
|
132
|
+
new Set([map1.core.id, map2.core.id, list.core.id]),
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("should track account as dependant when syncing a coValue", async () => {
|
|
137
|
+
const sourceClient = await setupTestAccount({
|
|
138
|
+
connected: true,
|
|
139
|
+
});
|
|
140
|
+
const targetClient = await setupTestAccount({
|
|
141
|
+
connected: true,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const group = sourceClient.node.createGroup();
|
|
145
|
+
group.addMember("everyone", "reader");
|
|
146
|
+
const map = group.createMap();
|
|
147
|
+
|
|
148
|
+
map.set("hello", "world");
|
|
149
|
+
|
|
150
|
+
await map.core.waitForSync();
|
|
151
|
+
|
|
152
|
+
const loadedMap = await loadCoValueOrFail(targetClient.node, map.id);
|
|
153
|
+
const sourceAccount = targetClient.node.getCoValue(sourceClient.accountID);
|
|
154
|
+
|
|
155
|
+
expect(sourceAccount.dependant.has(loadedMap.core.id)).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("should track account as dependant when syncing a group extension", async () => {
|
|
159
|
+
const sourceClient = await setupTestAccount({
|
|
160
|
+
connected: true,
|
|
161
|
+
});
|
|
162
|
+
const targetClient = await setupTestAccount({
|
|
163
|
+
connected: true,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const group = sourceClient.node.createGroup();
|
|
167
|
+
const parentGroup = sourceClient.node.createGroup();
|
|
168
|
+
|
|
169
|
+
group.extend(parentGroup);
|
|
170
|
+
|
|
171
|
+
await group.core.waitForSync();
|
|
172
|
+
|
|
173
|
+
const loadedGroup = await loadCoValueOrFail(targetClient.node, group.id);
|
|
174
|
+
const sourceAccount = targetClient.node.getCoValue(sourceClient.accountID);
|
|
175
|
+
|
|
176
|
+
expect(sourceAccount.dependant.has(loadedGroup.core.id)).toBe(true);
|
|
177
|
+
});
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
loadCoValueOrFail,
|
|
20
20
|
nodeWithRandomAgentAndSessionID,
|
|
21
21
|
randomAgentAndSessionID,
|
|
22
|
+
setupTestAccount,
|
|
22
23
|
setupTestNode,
|
|
23
24
|
tearDownTestMetricReader,
|
|
24
25
|
waitFor,
|
|
@@ -148,32 +149,24 @@ describe("transactions that exceed the byte size limit are rejected", () => {
|
|
|
148
149
|
});
|
|
149
150
|
});
|
|
150
151
|
|
|
151
|
-
test("
|
|
152
|
-
const
|
|
153
|
-
const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
|
|
154
|
-
|
|
155
|
-
const timeBeforeEdit = Date.now() - 1000;
|
|
156
|
-
const dateNowMock = vi
|
|
157
|
-
.spyOn(Date, "now")
|
|
158
|
-
.mockImplementation(() => timeBeforeEdit);
|
|
152
|
+
test("new transactions in a group correctly update owned values, including subscriptions", async () => {
|
|
153
|
+
const client = await setupTestAccount();
|
|
159
154
|
|
|
160
|
-
const
|
|
155
|
+
const agent = client.node.getCurrentAgent();
|
|
161
156
|
|
|
162
|
-
|
|
157
|
+
const group = client.node.createGroup();
|
|
163
158
|
|
|
164
159
|
const map = group.createMap();
|
|
165
160
|
|
|
166
|
-
|
|
161
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
167
162
|
|
|
168
|
-
|
|
163
|
+
map.set("hello", "world");
|
|
169
164
|
|
|
170
|
-
map.
|
|
171
|
-
listener(map.get("hello"));
|
|
172
|
-
});
|
|
165
|
+
const transaction = map.core.getValidSortedTransactions().at(-1);
|
|
173
166
|
|
|
174
|
-
|
|
167
|
+
assert(transaction);
|
|
175
168
|
|
|
176
|
-
expect(
|
|
169
|
+
expect(transaction.isValid).toBe(true);
|
|
177
170
|
expect(group.get(agent.id)).toBe("admin");
|
|
178
171
|
|
|
179
172
|
group.core.makeTransaction(
|
|
@@ -185,16 +178,65 @@ test("New transactions in a group correctly update owned values, including subsc
|
|
|
185
178
|
},
|
|
186
179
|
],
|
|
187
180
|
"trusting",
|
|
181
|
+
undefined,
|
|
182
|
+
transaction.madeAt - 1, // Make the revocation to be before the map update
|
|
188
183
|
);
|
|
189
184
|
|
|
190
185
|
expect(group.get(agent.id)).toBe("revoked");
|
|
191
|
-
|
|
186
|
+
expect(map.core.getValidSortedTransactions().length).toBe(0);
|
|
187
|
+
});
|
|
192
188
|
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
// TODO: The test is skipped because we don't support this invalidation yet
|
|
190
|
+
test.skip("new transactions in a parent group correctly update owned values, including subscriptions", async () => {
|
|
191
|
+
const client = await setupTestAccount();
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
const agent = client.node.getCurrentAgent();
|
|
194
|
+
|
|
195
|
+
const group = client.node.createGroup();
|
|
196
|
+
const parentGroup = client.node.createGroup();
|
|
197
|
+
group.extend(parentGroup);
|
|
198
|
+
group.core.makeTransaction(
|
|
199
|
+
[
|
|
200
|
+
{
|
|
201
|
+
op: "set",
|
|
202
|
+
key: agent.id,
|
|
203
|
+
value: "revoked",
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
"trusting",
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const map = group.createMap();
|
|
210
|
+
|
|
211
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
212
|
+
|
|
213
|
+
map.set("hello", "world");
|
|
214
|
+
|
|
215
|
+
const transaction = map.core.getValidSortedTransactions().at(-1);
|
|
216
|
+
|
|
217
|
+
assert(transaction);
|
|
218
|
+
|
|
219
|
+
expect(transaction.isValid).toBe(true);
|
|
220
|
+
expect(group.roleOfInternal(agent.id)).toBe("admin");
|
|
221
|
+
|
|
222
|
+
parentGroup.core.makeTransaction(
|
|
223
|
+
[
|
|
224
|
+
{
|
|
225
|
+
op: "set",
|
|
226
|
+
key: agent.id,
|
|
227
|
+
value: "revoked",
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
"trusting",
|
|
231
|
+
undefined,
|
|
232
|
+
transaction.madeAt - 1, // Make the revocation to be before the map update
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
expect(group.roleOfInternal(agent.id)).toBe(undefined);
|
|
236
|
+
|
|
237
|
+
await waitFor(() =>
|
|
238
|
+
expect(map.core.getValidSortedTransactions().length).toBe(0),
|
|
239
|
+
);
|
|
198
240
|
});
|
|
199
241
|
|
|
200
242
|
test("correctly records transactions", async () => {
|