cojson 0.18.25 → 0.18.27
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 +15 -0
- package/dist/PeerKnownStates.d.ts +4 -3
- package/dist/PeerKnownStates.d.ts.map +1 -1
- package/dist/PeerKnownStates.js +27 -18
- package/dist/PeerKnownStates.js.map +1 -1
- package/dist/PeerState.d.ts +3 -2
- package/dist/PeerState.d.ts.map +1 -1
- package/dist/PeerState.js.map +1 -1
- package/dist/SyncStateManager.d.ts +2 -2
- package/dist/SyncStateManager.d.ts.map +1 -1
- package/dist/SyncStateManager.js +2 -10
- package/dist/SyncStateManager.js.map +1 -1
- package/dist/coValueContentMessage.d.ts +1 -1
- package/dist/coValueContentMessage.d.ts.map +1 -1
- package/dist/coValueContentMessage.js +1 -1
- package/dist/coValueContentMessage.js.map +1 -1
- package/dist/coValueCore/SessionMap.d.ts +6 -3
- package/dist/coValueCore/SessionMap.d.ts.map +1 -1
- package/dist/coValueCore/SessionMap.js +41 -8
- package/dist/coValueCore/SessionMap.js.map +1 -1
- package/dist/coValueCore/branching.d.ts +3 -3
- package/dist/coValueCore/branching.d.ts.map +1 -1
- package/dist/coValueCore/branching.js +2 -2
- package/dist/coValueCore/branching.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +3 -2
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +2 -3
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts +12 -6
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValueCore/verifiedState.js +28 -56
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/coValues/coMap.d.ts.map +1 -1
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.d.ts.map +1 -1
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/exports.d.ts +3 -2
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +2 -1
- package/dist/exports.js.map +1 -1
- package/dist/knownState.d.ts +58 -2
- package/dist/knownState.d.ts.map +1 -1
- package/dist/knownState.js +79 -5
- package/dist/knownState.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +1 -4
- package/dist/permissions.js.map +1 -1
- package/dist/storage/knownState.d.ts +1 -1
- package/dist/storage/knownState.d.ts.map +1 -1
- package/dist/storage/knownState.js +2 -3
- package/dist/storage/knownState.js.map +1 -1
- package/dist/storage/storageAsync.d.ts +2 -1
- package/dist/storage/storageAsync.d.ts.map +1 -1
- package/dist/storage/storageAsync.js +5 -6
- package/dist/storage/storageAsync.js.map +1 -1
- package/dist/storage/storageSync.d.ts +2 -1
- package/dist/storage/storageSync.d.ts.map +1 -1
- package/dist/storage/storageSync.js +5 -5
- package/dist/storage/storageSync.js.map +1 -1
- package/dist/storage/types.d.ts +2 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/sync.d.ts +2 -12
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +7 -36
- package/dist/sync.js.map +1 -1
- package/dist/tests/PeerKnownStates.test.js +1 -1
- package/dist/tests/PeerKnownStates.test.js.map +1 -1
- package/dist/tests/PeerState.test.js +19 -0
- package/dist/tests/PeerState.test.js.map +1 -1
- package/dist/tests/PureJSCrypto.test.js.map +1 -1
- package/dist/tests/StorageApiAsync.test.js +1 -1
- package/dist/tests/StorageApiAsync.test.js.map +1 -1
- package/dist/tests/StorageApiSync.test.js +1 -2
- package/dist/tests/StorageApiSync.test.js.map +1 -1
- package/dist/tests/StoreQueue.test.js.map +1 -1
- package/dist/tests/SyncStateManager.test.js +1 -1
- package/dist/tests/SyncStateManager.test.js.map +1 -1
- package/dist/tests/coValueContentMessage.test.js +1 -1
- package/dist/tests/coValueContentMessage.test.js.map +1 -1
- package/dist/tests/coValueCore.test.js +28 -0
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/group.removeMember.test.js +6 -2
- package/dist/tests/group.removeMember.test.js.map +1 -1
- package/dist/tests/knownState.test.d.ts +2 -0
- package/dist/tests/knownState.test.d.ts.map +1 -0
- package/dist/tests/knownState.test.js +510 -0
- package/dist/tests/knownState.test.js.map +1 -0
- package/dist/tests/messagesTestUtils.d.ts.map +1 -1
- package/dist/tests/messagesTestUtils.js.map +1 -1
- package/dist/tests/priority.test.js.map +1 -1
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.upload.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/package.json +3 -3
- package/src/PeerKnownStates.ts +36 -22
- package/src/PeerState.ts +2 -1
- package/src/SyncStateManager.ts +4 -17
- package/src/coValueContentMessage.ts +2 -1
- package/src/coValueCore/SessionMap.ts +66 -11
- package/src/coValueCore/branching.ts +9 -10
- package/src/coValueCore/coValueCore.ts +9 -10
- package/src/coValueCore/verifiedState.ts +32 -64
- package/src/coValues/coMap.ts +1 -5
- package/src/coValues/coStream.ts +1 -5
- package/src/exports.ts +2 -2
- package/src/knownState.ts +118 -12
- package/src/permissions.ts +1 -8
- package/src/storage/knownState.ts +9 -3
- package/src/storage/storageAsync.ts +15 -7
- package/src/storage/storageSync.ts +16 -8
- package/src/storage/types.ts +2 -1
- package/src/sync.ts +12 -58
- package/src/tests/PeerKnownStates.test.ts +1 -1
- package/src/tests/PeerState.test.ts +29 -3
- package/src/tests/PureJSCrypto.test.ts +0 -1
- package/src/tests/StorageApiAsync.test.ts +3 -6
- package/src/tests/StorageApiSync.test.ts +2 -6
- package/src/tests/StoreQueue.test.ts +3 -2
- package/src/tests/SyncStateManager.test.ts +1 -1
- package/src/tests/coValueContentMessage.test.ts +2 -2
- package/src/tests/coValueCore.test.ts +38 -0
- package/src/tests/group.removeMember.test.ts +7 -1
- package/src/tests/knownState.test.ts +665 -0
- package/src/tests/messagesTestUtils.ts +2 -1
- package/src/tests/priority.test.ts +0 -2
- package/src/tests/sync.storage.test.ts +0 -1
- package/src/tests/sync.upload.test.ts +0 -1
- package/src/tests/testUtils.ts +1 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { PeerState } from "../PeerState.js";
|
|
3
|
-
import { CO_VALUE_PRIORITY } from "../priority.js";
|
|
4
3
|
import { ConnectedPeerChannel } from "../streamUtils.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { Peer, SyncMessage } from "../sync.js";
|
|
5
|
+
import { CoValueKnownState, KnownStateSessions } from "../knownState.js";
|
|
7
6
|
|
|
8
7
|
function setup() {
|
|
9
8
|
const mockPeer: Peer = {
|
|
@@ -80,6 +79,33 @@ describe("PeerState", () => {
|
|
|
80
79
|
expect(optimisticKnownStatesSpy).toHaveBeenCalledWith("co_z1", state);
|
|
81
80
|
});
|
|
82
81
|
|
|
82
|
+
test("dispatching an optimistic update should not affect the known states", () => {
|
|
83
|
+
const { peerState } = setup();
|
|
84
|
+
|
|
85
|
+
const state: CoValueKnownState = {
|
|
86
|
+
id: "co_z1",
|
|
87
|
+
header: false,
|
|
88
|
+
sessions: {},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
peerState.setKnownState("co_z1", state);
|
|
92
|
+
|
|
93
|
+
const optimisticState: CoValueKnownState = {
|
|
94
|
+
id: "co_z1",
|
|
95
|
+
header: false,
|
|
96
|
+
sessions: {
|
|
97
|
+
"session-1": 1,
|
|
98
|
+
} as KnownStateSessions,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
peerState.combineOptimisticWith("co_z1", optimisticState);
|
|
102
|
+
|
|
103
|
+
expect(peerState.knownStates.get("co_z1")).not.toEqual(optimisticState);
|
|
104
|
+
expect(peerState.optimisticKnownStates.get("co_z1")).toEqual(
|
|
105
|
+
optimisticState,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
83
109
|
test("should use separate references for knownStates and optimisticKnownStates for non-storage peers", () => {
|
|
84
110
|
const { peerState } = setup(); // Uses a regular peer
|
|
85
111
|
|
|
@@ -4,13 +4,9 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { afterEach, describe, expect, onTestFinished, test, vi } from "vitest";
|
|
6
6
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
7
|
-
import { CoID, LocalNode,
|
|
7
|
+
import { CoID, LocalNode, RawCoMap, logger } from "../exports.js";
|
|
8
8
|
import { CoValueCore } from "../exports.js";
|
|
9
|
-
import {
|
|
10
|
-
CoValueKnownState,
|
|
11
|
-
NewContentMessage,
|
|
12
|
-
emptyKnownState,
|
|
13
|
-
} from "../sync.js";
|
|
9
|
+
import { NewContentMessage } from "../sync.js";
|
|
14
10
|
import { createAsyncStorage } from "./testStorage.js";
|
|
15
11
|
import {
|
|
16
12
|
SyncMessagesLog,
|
|
@@ -18,6 +14,7 @@ import {
|
|
|
18
14
|
randomAgentAndSessionID,
|
|
19
15
|
waitFor,
|
|
20
16
|
} from "./testUtils.js";
|
|
17
|
+
import { CoValueKnownState, emptyKnownState } from "../knownState.js";
|
|
21
18
|
|
|
22
19
|
const crypto = await WasmCrypto.create();
|
|
23
20
|
|
|
@@ -6,11 +6,8 @@ import { describe, expect, onTestFinished, test, vi } from "vitest";
|
|
|
6
6
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
7
7
|
import { CoID, LocalNode, RawCoID, RawCoMap, logger } from "../exports.js";
|
|
8
8
|
import { CoValueCore } from "../exports.js";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
NewContentMessage,
|
|
12
|
-
emptyKnownState,
|
|
13
|
-
} from "../sync.js";
|
|
9
|
+
import { NewContentMessage } from "../sync.js";
|
|
10
|
+
import { CoValueKnownState, emptyKnownState } from "../knownState.js";
|
|
14
11
|
import { createSyncStorage } from "./testStorage.js";
|
|
15
12
|
import { loadCoValueOrFail, randomAgentAndSessionID } from "./testUtils.js";
|
|
16
13
|
|
|
@@ -240,7 +237,6 @@ describe("StorageApiSync", () => {
|
|
|
240
237
|
|
|
241
238
|
// Create a real group and add a member to create transactions
|
|
242
239
|
const group = fixturesNode.createGroup();
|
|
243
|
-
const knownState = group.core.verified.knownState();
|
|
244
240
|
|
|
245
241
|
group.addMember("everyone", "reader");
|
|
246
242
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { StoreQueue } from "../queue/StoreQueue.js";
|
|
3
|
-
import
|
|
3
|
+
import { NewContentMessage } from "../sync.js";
|
|
4
|
+
import { CoValueKnownState } from "../knownState.js";
|
|
4
5
|
|
|
5
6
|
function createMockNewContentMessage(id: string): NewContentMessage {
|
|
6
7
|
return {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
PeerSyncStateListenerCallback,
|
|
5
5
|
} from "../SyncStateManager.js";
|
|
6
6
|
import { connectedPeers } from "../streamUtils.js";
|
|
7
|
-
import { emptyKnownState } from "../
|
|
7
|
+
import { emptyKnownState } from "../exports.js";
|
|
8
8
|
import {
|
|
9
9
|
SyncMessagesLog,
|
|
10
10
|
loadCoValueOrFail,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "vitest";
|
|
2
2
|
import { knownStateFromContent } from "../coValueContentMessage.js";
|
|
3
|
-
import { emptyKnownState } from "../
|
|
4
|
-
import
|
|
3
|
+
import { emptyKnownState } from "../knownState.js";
|
|
4
|
+
import { NewContentMessage } from "../sync.js";
|
|
5
5
|
import type { RawCoID, SessionID } from "../ids.js";
|
|
6
6
|
import { stableStringify } from "../jsonStringify.js";
|
|
7
7
|
import { CO_VALUE_PRIORITY } from "../priority.js";
|
|
@@ -716,3 +716,41 @@ describe("markErrored and isErroredInPeer", () => {
|
|
|
716
716
|
expect(notificationCount).toBeGreaterThan(0);
|
|
717
717
|
});
|
|
718
718
|
});
|
|
719
|
+
|
|
720
|
+
test("knownState should return the same object until the CoValue is modified", () => {
|
|
721
|
+
const [agent, sessionID] = randomAgentAndSessionID();
|
|
722
|
+
const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
|
|
723
|
+
|
|
724
|
+
const group = node.createGroup();
|
|
725
|
+
const map = group.createMap();
|
|
726
|
+
|
|
727
|
+
// Get the knownState for the first time
|
|
728
|
+
const knownState1 = map.core.knownState();
|
|
729
|
+
|
|
730
|
+
// Get the knownState again - should be the same object
|
|
731
|
+
const knownState2 = map.core.knownState();
|
|
732
|
+
expect(knownState2).toBe(knownState1);
|
|
733
|
+
|
|
734
|
+
// Call it multiple times to ensure it's always the same object
|
|
735
|
+
const knownState3 = map.core.knownState();
|
|
736
|
+
expect(knownState3).toBe(knownState1);
|
|
737
|
+
|
|
738
|
+
// Now modify the CoValue by making a transaction
|
|
739
|
+
map.set("hello", "world");
|
|
740
|
+
|
|
741
|
+
// Get the knownState after modification - should be a different object
|
|
742
|
+
const knownState4 = map.core.knownState();
|
|
743
|
+
expect(knownState4).not.toBe(knownState1);
|
|
744
|
+
|
|
745
|
+
// Verify that subsequent calls still return the same (new) object
|
|
746
|
+
const knownState5 = map.core.knownState();
|
|
747
|
+
expect(knownState5).toBe(knownState4);
|
|
748
|
+
|
|
749
|
+
// Make another modification
|
|
750
|
+
map.set("foo", "bar");
|
|
751
|
+
|
|
752
|
+
// Get the knownState after second modification - should be yet another different object
|
|
753
|
+
const knownState6 = map.core.knownState();
|
|
754
|
+
expect(knownState6).not.toBe(knownState4);
|
|
755
|
+
expect(knownState6).not.toBe(knownState1);
|
|
756
|
+
});
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
loadCoValueOrFail,
|
|
7
7
|
setupTestAccount,
|
|
8
8
|
setupTestNode,
|
|
9
|
+
waitFor,
|
|
9
10
|
} from "./testUtils.js";
|
|
10
11
|
|
|
11
12
|
setCoValueLoadingRetryDelay(10);
|
|
@@ -98,9 +99,14 @@ describe("Group.removeMember", () => {
|
|
|
98
99
|
const loadedGroup = await loadCoValueOrFail(client.node, group.id);
|
|
99
100
|
expect(loadedGroup.myRole()).toEqual(member);
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
loadedGroup.removeMember(client.node.expectCurrentAccount(member));
|
|
102
103
|
|
|
103
104
|
expect(loadedGroup.myRole()).toEqual(undefined);
|
|
105
|
+
|
|
106
|
+
await loadedGroup.core.waitForSync();
|
|
107
|
+
await waitFor(() => {
|
|
108
|
+
expect(group.roleOf(client.accountID)).toEqual(undefined);
|
|
109
|
+
});
|
|
104
110
|
});
|
|
105
111
|
}
|
|
106
112
|
|