cojson 0.4.13 → 0.5.0
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 +7 -0
- package/dist/coValueCore.js +108 -42
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/coList.js +21 -4
- package/dist/coValues/coList.js.map +1 -1
- package/dist/crypto.js +57 -31
- package/dist/crypto.js.map +1 -1
- package/dist/localNode.js +58 -16
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js +5 -3
- package/dist/permissions.js.map +1 -1
- package/dist/streamUtils.js +34 -8
- package/dist/streamUtils.js.map +1 -1
- package/dist/sync.js +162 -40
- package/dist/sync.js.map +1 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js +2 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/package.json +4 -3
- package/src/coValueCore.ts +140 -63
- package/src/coValues/coList.ts +33 -8
- package/src/crypto.ts +83 -41
- package/src/localNode.ts +127 -34
- package/src/permissions.ts +19 -24
- package/src/streamUtils.ts +41 -8
- package/src/sync.ts +206 -59
- package/src/tests/coValue.test.ts +3 -3
- package/src/tests/permissions.test.ts +124 -83
- package/src/tests/sync.test.ts +29 -20
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { newRandomSessionID } from "../coValueCore.js";
|
|
2
2
|
import { expectMap } from "../coValue.js";
|
|
3
|
-
import { Group
|
|
3
|
+
import { Group } from "../coValues/group.js";
|
|
4
4
|
import {
|
|
5
5
|
createdNowUnique,
|
|
6
6
|
newRandomKeySecret,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
groupWithTwoAdminsHighLevel,
|
|
19
19
|
} from "./testUtils.js";
|
|
20
20
|
import { AnonymousControlledAccount, cojsonReady } from "../index.js";
|
|
21
|
+
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
21
22
|
|
|
22
23
|
beforeEach(async () => {
|
|
23
24
|
await cojsonReady;
|
|
@@ -34,10 +35,14 @@ test("Initial admin can add another admin to a group (high level)", () => {
|
|
|
34
35
|
test("Added admin can add a third admin to a group", () => {
|
|
35
36
|
const { groupCore, otherAdmin, node } = groupWithTwoAdmins();
|
|
36
37
|
|
|
37
|
-
let groupAsOtherAdmin = expectGroup(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
let groupAsOtherAdmin = expectGroup(
|
|
39
|
+
groupCore
|
|
40
|
+
.testWithDifferentAccount(
|
|
41
|
+
otherAdmin,
|
|
42
|
+
newRandomSessionID(otherAdmin.id)
|
|
43
|
+
)
|
|
44
|
+
.getCurrentContent()
|
|
45
|
+
);
|
|
41
46
|
|
|
42
47
|
expect(groupAsOtherAdmin.get(otherAdmin.id)).toEqual("admin");
|
|
43
48
|
|
|
@@ -54,10 +59,14 @@ test("Added admin can add a third admin to a group", () => {
|
|
|
54
59
|
test("Added adming can add a third admin to a group (high level)", () => {
|
|
55
60
|
const { group, otherAdmin, node } = groupWithTwoAdminsHighLevel();
|
|
56
61
|
|
|
57
|
-
let groupAsOtherAdmin = expectGroup(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
let groupAsOtherAdmin = expectGroup(
|
|
63
|
+
group.core
|
|
64
|
+
.testWithDifferentAccount(
|
|
65
|
+
otherAdmin,
|
|
66
|
+
newRandomSessionID(otherAdmin.id)
|
|
67
|
+
)
|
|
68
|
+
.getCurrentContent()
|
|
69
|
+
);
|
|
61
70
|
|
|
62
71
|
const thirdAdmin = groupAsOtherAdmin.core.node.createAccount("thirdAdmin");
|
|
63
72
|
|
|
@@ -78,10 +87,14 @@ test("Admins can't demote other admins in a group", () => {
|
|
|
78
87
|
|
|
79
88
|
expect(groupContent.get(otherAdmin.id)).toEqual("admin");
|
|
80
89
|
|
|
81
|
-
let groupAsOtherAdmin = expectGroup(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
let groupAsOtherAdmin = expectGroup(
|
|
91
|
+
groupCore
|
|
92
|
+
.testWithDifferentAccount(
|
|
93
|
+
otherAdmin,
|
|
94
|
+
newRandomSessionID(otherAdmin.id)
|
|
95
|
+
)
|
|
96
|
+
.getCurrentContent()
|
|
97
|
+
);
|
|
85
98
|
|
|
86
99
|
groupAsOtherAdmin = groupAsOtherAdmin.edit((editable) => {
|
|
87
100
|
editable.set(admin.id, "writer", "trusting");
|
|
@@ -94,10 +107,14 @@ test("Admins can't demote other admins in a group", () => {
|
|
|
94
107
|
test("Admins can't demote other admins in a group (high level)", () => {
|
|
95
108
|
const { group, admin, otherAdmin } = groupWithTwoAdminsHighLevel();
|
|
96
109
|
|
|
97
|
-
const groupAsOtherAdmin = expectGroup(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
const groupAsOtherAdmin = expectGroup(
|
|
111
|
+
group.core
|
|
112
|
+
.testWithDifferentAccount(
|
|
113
|
+
otherAdmin,
|
|
114
|
+
newRandomSessionID(otherAdmin.id)
|
|
115
|
+
)
|
|
116
|
+
.getCurrentContent()
|
|
117
|
+
);
|
|
101
118
|
|
|
102
119
|
expect(() =>
|
|
103
120
|
groupAsOtherAdmin.addMemberInternal(admin.id, "writer")
|
|
@@ -120,11 +137,11 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
|
|
|
120
137
|
groupContent = expectGroup(groupCore.getCurrentContent());
|
|
121
138
|
expect(groupContent.get(writer.id)).toEqual("writer");
|
|
122
139
|
|
|
123
|
-
let groupAsWriter = expectGroup(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
let groupAsWriter = expectGroup(
|
|
141
|
+
groupCore
|
|
142
|
+
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
143
|
+
.getCurrentContent()
|
|
144
|
+
);
|
|
128
145
|
|
|
129
146
|
expect(groupAsWriter.get(writer.id)).toEqual("writer");
|
|
130
147
|
|
|
@@ -152,10 +169,11 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
|
|
|
152
169
|
group = group.addMember(writer.id, "writer");
|
|
153
170
|
expect(group.get(writer.id)).toEqual("writer");
|
|
154
171
|
|
|
155
|
-
const groupAsWriter = expectGroup(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
const groupAsWriter = expectGroup(
|
|
173
|
+
group.core
|
|
174
|
+
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
175
|
+
.getCurrentContent()
|
|
176
|
+
);
|
|
159
177
|
|
|
160
178
|
expect(groupAsWriter.get(writer.id)).toEqual("writer");
|
|
161
179
|
|
|
@@ -188,10 +206,11 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
|
|
|
188
206
|
groupContent = expectGroup(groupCore.getCurrentContent());
|
|
189
207
|
expect(groupContent.get(reader.id)).toEqual("reader");
|
|
190
208
|
|
|
191
|
-
let groupAsReader = expectGroup(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
209
|
+
let groupAsReader = expectGroup(
|
|
210
|
+
groupCore
|
|
211
|
+
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
212
|
+
.getCurrentContent()
|
|
213
|
+
);
|
|
195
214
|
|
|
196
215
|
expect(groupAsReader.get(reader.id)).toEqual("reader");
|
|
197
216
|
|
|
@@ -219,10 +238,11 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
|
|
|
219
238
|
group = group.addMember(reader.id, "reader");
|
|
220
239
|
expect(group.get(reader.id)).toEqual("reader");
|
|
221
240
|
|
|
222
|
-
const groupAsReader = expectGroup(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
241
|
+
const groupAsReader = expectGroup(
|
|
242
|
+
group.core
|
|
243
|
+
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
244
|
+
.getCurrentContent()
|
|
245
|
+
);
|
|
226
246
|
|
|
227
247
|
expect(groupAsReader.get(reader.id)).toEqual("reader");
|
|
228
248
|
|
|
@@ -1291,10 +1311,14 @@ test("Admins can create an adminInvite, which can add an admin", () => {
|
|
|
1291
1311
|
);
|
|
1292
1312
|
});
|
|
1293
1313
|
|
|
1294
|
-
const groupAsInvite = expectGroup(
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1314
|
+
const groupAsInvite = expectGroup(
|
|
1315
|
+
groupCore
|
|
1316
|
+
.testWithDifferentAccount(
|
|
1317
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1318
|
+
newRandomSessionID(inviteID)
|
|
1319
|
+
)
|
|
1320
|
+
.getCurrentContent()
|
|
1321
|
+
);
|
|
1298
1322
|
|
|
1299
1323
|
const invitedAdminSecret = newRandomAgentSecret();
|
|
1300
1324
|
const invitedAdminID = getAgentID(invitedAdminSecret);
|
|
@@ -1349,19 +1373,19 @@ test("Admins can create an adminInvite, which can add an admin (high-level)", as
|
|
|
1349
1373
|
const thirdAdminID = getAgentID(thirdAdmin);
|
|
1350
1374
|
|
|
1351
1375
|
let groupAsInvitedAdmin = await nodeAsInvitedAdmin.load(group.id);
|
|
1376
|
+
if (groupAsInvitedAdmin === "unavailable") {
|
|
1377
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1378
|
+
}
|
|
1352
1379
|
|
|
1353
|
-
expect(groupAsInvitedAdmin.get(invitedAdminID)).toEqual(
|
|
1354
|
-
|
|
1355
|
-
);
|
|
1356
|
-
expect(
|
|
1357
|
-
groupAsInvitedAdmin.core.getCurrentReadKey().secret
|
|
1358
|
-
).toBeDefined();
|
|
1359
|
-
|
|
1360
|
-
groupAsInvitedAdmin = groupAsInvitedAdmin.addMemberInternal(thirdAdminID, "admin");
|
|
1380
|
+
expect(groupAsInvitedAdmin.get(invitedAdminID)).toEqual("admin");
|
|
1381
|
+
expect(groupAsInvitedAdmin.core.getCurrentReadKey().secret).toBeDefined();
|
|
1361
1382
|
|
|
1362
|
-
|
|
1383
|
+
groupAsInvitedAdmin = groupAsInvitedAdmin.addMemberInternal(
|
|
1384
|
+
thirdAdminID,
|
|
1363
1385
|
"admin"
|
|
1364
1386
|
);
|
|
1387
|
+
|
|
1388
|
+
expect(groupAsInvitedAdmin.get(thirdAdminID)).toEqual("admin");
|
|
1365
1389
|
});
|
|
1366
1390
|
|
|
1367
1391
|
test("Admins can create a writerInvite, which can add a writer", () => {
|
|
@@ -1406,10 +1430,14 @@ test("Admins can create a writerInvite, which can add a writer", () => {
|
|
|
1406
1430
|
);
|
|
1407
1431
|
});
|
|
1408
1432
|
|
|
1409
|
-
const groupAsInvite = expectGroup(
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1433
|
+
const groupAsInvite = expectGroup(
|
|
1434
|
+
groupCore
|
|
1435
|
+
.testWithDifferentAccount(
|
|
1436
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1437
|
+
newRandomSessionID(inviteID)
|
|
1438
|
+
)
|
|
1439
|
+
.getCurrentContent()
|
|
1440
|
+
);
|
|
1413
1441
|
|
|
1414
1442
|
const invitedWriterSecret = newRandomAgentSecret();
|
|
1415
1443
|
const invitedWriterID = getAgentID(invitedWriterSecret);
|
|
@@ -1461,13 +1489,12 @@ test("Admins can create a writerInvite, which can add a writer (high-level)", as
|
|
|
1461
1489
|
await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
|
|
1462
1490
|
|
|
1463
1491
|
const groupAsInvitedWriter = await nodeAsInvitedWriter.load(group.id);
|
|
1492
|
+
if (groupAsInvitedWriter === "unavailable") {
|
|
1493
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1494
|
+
}
|
|
1464
1495
|
|
|
1465
|
-
expect(groupAsInvitedWriter.get(invitedWriterID)).toEqual(
|
|
1466
|
-
|
|
1467
|
-
);
|
|
1468
|
-
expect(
|
|
1469
|
-
groupAsInvitedWriter.core.getCurrentReadKey().secret
|
|
1470
|
-
).toBeDefined();
|
|
1496
|
+
expect(groupAsInvitedWriter.get(invitedWriterID)).toEqual("writer");
|
|
1497
|
+
expect(groupAsInvitedWriter.core.getCurrentReadKey().secret).toBeDefined();
|
|
1471
1498
|
});
|
|
1472
1499
|
|
|
1473
1500
|
test("Admins can create a readerInvite, which can add a reader", () => {
|
|
@@ -1512,10 +1539,14 @@ test("Admins can create a readerInvite, which can add a reader", () => {
|
|
|
1512
1539
|
);
|
|
1513
1540
|
});
|
|
1514
1541
|
|
|
1515
|
-
const groupAsInvite = expectGroup(
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1542
|
+
const groupAsInvite = expectGroup(
|
|
1543
|
+
groupCore
|
|
1544
|
+
.testWithDifferentAccount(
|
|
1545
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1546
|
+
newRandomSessionID(inviteID)
|
|
1547
|
+
)
|
|
1548
|
+
.getCurrentContent()
|
|
1549
|
+
);
|
|
1519
1550
|
|
|
1520
1551
|
const invitedReaderSecret = newRandomAgentSecret();
|
|
1521
1552
|
const invitedReaderID = getAgentID(invitedReaderSecret);
|
|
@@ -1566,15 +1597,13 @@ test("Admins can create a readerInvite, which can add a reader (high-level)", as
|
|
|
1566
1597
|
|
|
1567
1598
|
await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
|
|
1568
1599
|
|
|
1569
|
-
const groupAsInvitedReader =
|
|
1570
|
-
|
|
1600
|
+
const groupAsInvitedReader = await nodeAsInvitedReader.load(group.id);
|
|
1601
|
+
if (groupAsInvitedReader === "unavailable") {
|
|
1602
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1603
|
+
}
|
|
1571
1604
|
|
|
1572
|
-
expect(groupAsInvitedReader.get(invitedReaderID)).toEqual(
|
|
1573
|
-
|
|
1574
|
-
);
|
|
1575
|
-
expect(
|
|
1576
|
-
groupAsInvitedReader.core.getCurrentReadKey().secret
|
|
1577
|
-
).toBeDefined();
|
|
1605
|
+
expect(groupAsInvitedReader.get(invitedReaderID)).toEqual("reader");
|
|
1606
|
+
expect(groupAsInvitedReader.core.getCurrentReadKey().secret).toBeDefined();
|
|
1578
1607
|
});
|
|
1579
1608
|
|
|
1580
1609
|
test("WriterInvites can not invite admins", () => {
|
|
@@ -1619,10 +1648,14 @@ test("WriterInvites can not invite admins", () => {
|
|
|
1619
1648
|
);
|
|
1620
1649
|
});
|
|
1621
1650
|
|
|
1622
|
-
const groupAsInvite = expectGroup(
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1651
|
+
const groupAsInvite = expectGroup(
|
|
1652
|
+
groupCore
|
|
1653
|
+
.testWithDifferentAccount(
|
|
1654
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1655
|
+
newRandomSessionID(inviteID)
|
|
1656
|
+
)
|
|
1657
|
+
.getCurrentContent()
|
|
1658
|
+
);
|
|
1626
1659
|
|
|
1627
1660
|
const invitedAdminSecret = newRandomAgentSecret();
|
|
1628
1661
|
const invitedAdminID = getAgentID(invitedAdminSecret);
|
|
@@ -1675,10 +1708,14 @@ test("ReaderInvites can not invite admins", () => {
|
|
|
1675
1708
|
);
|
|
1676
1709
|
});
|
|
1677
1710
|
|
|
1678
|
-
const groupAsInvite = expectGroup(
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1711
|
+
const groupAsInvite = expectGroup(
|
|
1712
|
+
groupCore
|
|
1713
|
+
.testWithDifferentAccount(
|
|
1714
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1715
|
+
newRandomSessionID(inviteID)
|
|
1716
|
+
)
|
|
1717
|
+
.getCurrentContent()
|
|
1718
|
+
);
|
|
1682
1719
|
|
|
1683
1720
|
const invitedAdminSecret = newRandomAgentSecret();
|
|
1684
1721
|
const invitedAdminID = getAgentID(invitedAdminSecret);
|
|
@@ -1731,10 +1768,14 @@ test("ReaderInvites can not invite writers", () => {
|
|
|
1731
1768
|
);
|
|
1732
1769
|
});
|
|
1733
1770
|
|
|
1734
|
-
const groupAsInvite = expectGroup(
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1771
|
+
const groupAsInvite = expectGroup(
|
|
1772
|
+
groupCore
|
|
1773
|
+
.testWithDifferentAccount(
|
|
1774
|
+
new AnonymousControlledAccount(inviteSecret),
|
|
1775
|
+
newRandomSessionID(inviteID)
|
|
1776
|
+
)
|
|
1777
|
+
.getCurrentContent()
|
|
1778
|
+
);
|
|
1738
1779
|
|
|
1739
1780
|
const invitedWriterSecret = newRandomAgentSecret();
|
|
1740
1781
|
const invitedWriterID = getAgentID(invitedWriterSecret);
|
|
@@ -1886,8 +1927,8 @@ test("Can give write permissions to 'everyone' (high-level)", async () => {
|
|
|
1886
1927
|
expect(childContent2.get("foo")).toEqual("bar");
|
|
1887
1928
|
|
|
1888
1929
|
childContent2.edit((editable) => {
|
|
1889
|
-
console.log("Before anon set")
|
|
1930
|
+
console.log("Before anon set");
|
|
1890
1931
|
editable.set("foo", "bar2", "private");
|
|
1891
1932
|
expect(editable.get("foo")).toEqual("bar2");
|
|
1892
1933
|
});
|
|
1893
|
-
});
|
|
1934
|
+
});
|
package/src/tests/sync.test.ts
CHANGED
|
@@ -80,7 +80,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
80
80
|
newTransactions: [
|
|
81
81
|
{
|
|
82
82
|
privacy: "trusting" as const,
|
|
83
|
-
madeAt: map.core.
|
|
83
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
84
84
|
.transactions[0]!.madeAt,
|
|
85
85
|
changes: stableStringify([
|
|
86
86
|
{
|
|
@@ -92,7 +92,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
92
92
|
},
|
|
93
93
|
],
|
|
94
94
|
lastSignature:
|
|
95
|
-
map.core.
|
|
95
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
96
96
|
},
|
|
97
97
|
},
|
|
98
98
|
} satisfies SyncMessage);
|
|
@@ -158,7 +158,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
|
|
|
158
158
|
newTransactions: [
|
|
159
159
|
{
|
|
160
160
|
privacy: "trusting" as const,
|
|
161
|
-
madeAt: map.core.
|
|
161
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
162
162
|
.transactions[1]!.madeAt,
|
|
163
163
|
changes: stableStringify([
|
|
164
164
|
{
|
|
@@ -170,7 +170,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
|
|
|
170
170
|
},
|
|
171
171
|
],
|
|
172
172
|
lastSignature:
|
|
173
|
-
map.core.
|
|
173
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
174
174
|
},
|
|
175
175
|
},
|
|
176
176
|
} satisfies SyncMessage);
|
|
@@ -247,7 +247,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
247
247
|
newTransactions: [
|
|
248
248
|
{
|
|
249
249
|
privacy: "trusting" as const,
|
|
250
|
-
madeAt: map.core.
|
|
250
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
251
251
|
.transactions[0]!.madeAt,
|
|
252
252
|
changes: stableStringify([
|
|
253
253
|
{
|
|
@@ -259,7 +259,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
259
259
|
},
|
|
260
260
|
],
|
|
261
261
|
lastSignature:
|
|
262
|
-
map.core.
|
|
262
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
263
263
|
},
|
|
264
264
|
},
|
|
265
265
|
} satisfies SyncMessage);
|
|
@@ -279,7 +279,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
279
279
|
newTransactions: [
|
|
280
280
|
{
|
|
281
281
|
privacy: "trusting" as const,
|
|
282
|
-
madeAt: map.core.
|
|
282
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
283
283
|
.transactions[1]!.madeAt,
|
|
284
284
|
changes: stableStringify([
|
|
285
285
|
{
|
|
@@ -291,7 +291,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
291
291
|
},
|
|
292
292
|
],
|
|
293
293
|
lastSignature:
|
|
294
|
-
map.core.
|
|
294
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
297
|
} satisfies SyncMessage);
|
|
@@ -358,7 +358,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
358
358
|
newTransactions: [
|
|
359
359
|
{
|
|
360
360
|
privacy: "trusting" as const,
|
|
361
|
-
madeAt: map.core.
|
|
361
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
362
362
|
.transactions[0]!.madeAt,
|
|
363
363
|
changes: stableStringify([
|
|
364
364
|
{
|
|
@@ -370,7 +370,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
370
370
|
},
|
|
371
371
|
],
|
|
372
372
|
lastSignature:
|
|
373
|
-
map.core.
|
|
373
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
374
374
|
},
|
|
375
375
|
},
|
|
376
376
|
} satisfies SyncMessage);
|
|
@@ -462,7 +462,7 @@ test("No matter the optimistic known state, node respects invalid known state me
|
|
|
462
462
|
newTransactions: [
|
|
463
463
|
{
|
|
464
464
|
privacy: "trusting" as const,
|
|
465
|
-
madeAt: map.core.
|
|
465
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
466
466
|
.transactions[1]!.madeAt,
|
|
467
467
|
changes: stableStringify([
|
|
468
468
|
{
|
|
@@ -474,7 +474,7 @@ test("No matter the optimistic known state, node respects invalid known state me
|
|
|
474
474
|
},
|
|
475
475
|
],
|
|
476
476
|
lastSignature:
|
|
477
|
-
map.core.
|
|
477
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
478
478
|
},
|
|
479
479
|
},
|
|
480
480
|
} satisfies SyncMessage);
|
|
@@ -565,7 +565,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
|
|
|
565
565
|
newTransactions: [
|
|
566
566
|
{
|
|
567
567
|
privacy: "trusting" as const,
|
|
568
|
-
madeAt: map.core.
|
|
568
|
+
madeAt: map.core.sessionLogs.get(node.currentSessionID)!
|
|
569
569
|
.transactions[0]!.madeAt,
|
|
570
570
|
changes: stableStringify([
|
|
571
571
|
{
|
|
@@ -577,7 +577,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
|
|
|
577
577
|
},
|
|
578
578
|
],
|
|
579
579
|
lastSignature:
|
|
580
|
-
map.core.
|
|
580
|
+
map.core.sessionLogs.get(node.currentSessionID)!.lastSignature!,
|
|
581
581
|
},
|
|
582
582
|
},
|
|
583
583
|
} satisfies SyncMessage);
|
|
@@ -853,7 +853,7 @@ test.skip("When loading a coValue on one node, the server node it is requested f
|
|
|
853
853
|
node1.syncManager.addPeer(node2asPeer);
|
|
854
854
|
node2.syncManager.addPeer(node1asPeer);
|
|
855
855
|
|
|
856
|
-
await node2.
|
|
856
|
+
await node2.loadCoValueCore(map.core.id);
|
|
857
857
|
|
|
858
858
|
expect(
|
|
859
859
|
expectMap(
|
|
@@ -880,7 +880,7 @@ test("Can sync a coValue through a server to another client", async () => {
|
|
|
880
880
|
|
|
881
881
|
const [serverAsPeer, client1AsPeer] = connectedPeers("server", "client1", {
|
|
882
882
|
peer1role: "server",
|
|
883
|
-
peer2role: "client",
|
|
883
|
+
peer2role: "client", trace: true,
|
|
884
884
|
});
|
|
885
885
|
|
|
886
886
|
client1.syncManager.addPeer(serverAsPeer);
|
|
@@ -891,13 +891,16 @@ test("Can sync a coValue through a server to another client", async () => {
|
|
|
891
891
|
const [serverAsOtherPeer, client2AsPeer] = connectedPeers(
|
|
892
892
|
"server",
|
|
893
893
|
"client2",
|
|
894
|
-
{ peer1role: "server", peer2role: "client" }
|
|
894
|
+
{ peer1role: "server", peer2role: "client", trace: true, }
|
|
895
895
|
);
|
|
896
896
|
|
|
897
897
|
client2.syncManager.addPeer(serverAsOtherPeer);
|
|
898
898
|
server.syncManager.addPeer(client2AsPeer);
|
|
899
899
|
|
|
900
|
-
const mapOnClient2 = await client2.
|
|
900
|
+
const mapOnClient2 = await client2.loadCoValueCore(map.core.id);
|
|
901
|
+
if (mapOnClient2 === "unavailable") {
|
|
902
|
+
throw new Error("Map is unavailable");
|
|
903
|
+
}
|
|
901
904
|
|
|
902
905
|
expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
|
|
903
906
|
"world"
|
|
@@ -940,7 +943,10 @@ test("Can sync a coValue with private transactions through a server to another c
|
|
|
940
943
|
client2.syncManager.addPeer(serverAsOtherPeer);
|
|
941
944
|
server.syncManager.addPeer(client2AsPeer);
|
|
942
945
|
|
|
943
|
-
const mapOnClient2 = await client2.
|
|
946
|
+
const mapOnClient2 = await client2.loadCoValueCore(map.core.id);
|
|
947
|
+
if (mapOnClient2 === "unavailable") {
|
|
948
|
+
throw new Error("Map is unavailable");
|
|
949
|
+
}
|
|
944
950
|
|
|
945
951
|
expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
|
|
946
952
|
"world"
|
|
@@ -1082,13 +1088,16 @@ test("If we start loading a coValue before connecting to a peer that has it, it
|
|
|
1082
1088
|
|
|
1083
1089
|
node1.syncManager.addPeer(node2asPeer);
|
|
1084
1090
|
|
|
1085
|
-
const mapOnNode2Promise = node2.
|
|
1091
|
+
const mapOnNode2Promise = node2.loadCoValueCore(map.core.id);
|
|
1086
1092
|
|
|
1087
1093
|
expect(node2.coValues[map.core.id]?.state).toEqual("loading");
|
|
1088
1094
|
|
|
1089
1095
|
node2.syncManager.addPeer(node1asPeer);
|
|
1090
1096
|
|
|
1091
1097
|
const mapOnNode2 = await mapOnNode2Promise;
|
|
1098
|
+
if (mapOnNode2 === "unavailable") {
|
|
1099
|
+
throw new Error("Map is unavailable");
|
|
1100
|
+
}
|
|
1092
1101
|
|
|
1093
1102
|
expect(expectMap(mapOnNode2.getCurrentContent()).get("hello")).toEqual(
|
|
1094
1103
|
"world"
|
|
@@ -5,5 +5,6 @@ import { AccountID } from "../coValues/account.js";
|
|
|
5
5
|
export function accountOrAgentIDfromSessionID(
|
|
6
6
|
sessionID: SessionID
|
|
7
7
|
): AccountID | AgentID {
|
|
8
|
-
|
|
8
|
+
const until = sessionID.indexOf("_session");
|
|
9
|
+
return sessionID.slice(0, until) as AccountID | AgentID;
|
|
9
10
|
}
|