cojson 0.0.24 → 0.1.1
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/README.md +1 -1
- package/dist/account.d.ts +4 -4
- package/dist/account.js +7 -7
- package/dist/account.js.map +1 -1
- package/dist/coValue.d.ts +2 -2
- package/dist/coValue.js +23 -23
- package/dist/coValue.js.map +1 -1
- package/dist/{team.d.ts → group.d.ts} +7 -7
- package/dist/{team.js → group.js} +24 -24
- package/dist/group.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +3 -3
- package/dist/node.js +41 -39
- package/dist/node.js.map +1 -1
- package/dist/permissions.d.ts +3 -3
- package/dist/permissions.js +13 -13
- package/dist/permissions.js.map +1 -1
- package/dist/testUtils.d.ts +8 -8
- package/dist/testUtils.js +19 -19
- package/dist/testUtils.js.map +1 -1
- package/package.json +2 -2
- package/src/account.test.ts +7 -7
- package/src/account.ts +8 -8
- package/src/coValue.test.ts +5 -5
- package/src/coValue.ts +24 -24
- package/src/{team.ts → group.ts} +31 -31
- package/src/index.ts +4 -4
- package/src/node.ts +48 -46
- package/src/permissions.test.ts +303 -303
- package/src/permissions.ts +16 -16
- package/src/sync.test.ts +74 -74
- package/src/testUtils.ts +19 -19
- package/dist/team.js.map +0 -1
package/src/permissions.ts
CHANGED
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
} from "./account.js";
|
|
18
18
|
|
|
19
19
|
export type PermissionsDef =
|
|
20
|
-
| { type: "
|
|
21
|
-
| { type: "
|
|
20
|
+
| { type: "group"; initialAdmin: AccountIDOrAgentID }
|
|
21
|
+
| { type: "ownedByGroup"; group: RawCoID }
|
|
22
22
|
| { type: "unsafeAllowAll" };
|
|
23
23
|
|
|
24
24
|
export type Role =
|
|
@@ -33,7 +33,7 @@ export type Role =
|
|
|
33
33
|
export function determineValidTransactions(
|
|
34
34
|
coValue: CoValue
|
|
35
35
|
): { txID: TransactionID; tx: Transaction }[] {
|
|
36
|
-
if (coValue.header.ruleset.type === "
|
|
36
|
+
if (coValue.header.ruleset.type === "group") {
|
|
37
37
|
const allTrustingTransactionsSorted = Object.entries(
|
|
38
38
|
coValue.sessions
|
|
39
39
|
).flatMap(([sessionID, sessionLog]) => {
|
|
@@ -43,7 +43,7 @@ export function determineValidTransactions(
|
|
|
43
43
|
if (tx.privacy === "trusting") {
|
|
44
44
|
return true;
|
|
45
45
|
} else {
|
|
46
|
-
console.warn("Unexpected private transaction in
|
|
46
|
+
console.warn("Unexpected private transaction in Group");
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
}) as {
|
|
@@ -60,7 +60,7 @@ export function determineValidTransactions(
|
|
|
60
60
|
const initialAdmin = coValue.header.ruleset.initialAdmin;
|
|
61
61
|
|
|
62
62
|
if (!initialAdmin) {
|
|
63
|
-
throw new Error("
|
|
63
|
+
throw new Error("Group must have initialAdmin");
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const memberState: { [agent: AccountIDOrAgentID]: Role } = {};
|
|
@@ -81,12 +81,12 @@ export function determineValidTransactions(
|
|
|
81
81
|
| MapOpPayload<"readKey", JsonValue>
|
|
82
82
|
| MapOpPayload<"profile", CoID<Profile>>;
|
|
83
83
|
if (tx.changes.length !== 1) {
|
|
84
|
-
console.warn("
|
|
84
|
+
console.warn("Group transaction must have exactly one change");
|
|
85
85
|
continue;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
if (change.op !== "set") {
|
|
89
|
-
console.warn("
|
|
89
|
+
console.warn("Group transaction must set a role or readKey");
|
|
90
90
|
continue;
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -138,7 +138,7 @@ export function determineValidTransactions(
|
|
|
138
138
|
change.value !== "writerInvite" &&
|
|
139
139
|
change.value !== "readerInvite"
|
|
140
140
|
) {
|
|
141
|
-
console.warn("
|
|
141
|
+
console.warn("Group transaction must set a valid role");
|
|
142
142
|
continue;
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -176,7 +176,7 @@ export function determineValidTransactions(
|
|
|
176
176
|
}
|
|
177
177
|
} else {
|
|
178
178
|
console.warn(
|
|
179
|
-
"
|
|
179
|
+
"Group transaction must be made by current admin or invite"
|
|
180
180
|
);
|
|
181
181
|
continue;
|
|
182
182
|
}
|
|
@@ -189,16 +189,16 @@ export function determineValidTransactions(
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
return validTransactions;
|
|
192
|
-
} else if (coValue.header.ruleset.type === "
|
|
193
|
-
const
|
|
192
|
+
} else if (coValue.header.ruleset.type === "ownedByGroup") {
|
|
193
|
+
const groupContent = coValue.node
|
|
194
194
|
.expectCoValueLoaded(
|
|
195
|
-
coValue.header.ruleset.
|
|
196
|
-
"Determining valid transaction in owned object but its
|
|
195
|
+
coValue.header.ruleset.group,
|
|
196
|
+
"Determining valid transaction in owned object but its group wasn't loaded"
|
|
197
197
|
)
|
|
198
198
|
.getCurrentContent();
|
|
199
199
|
|
|
200
|
-
if (
|
|
201
|
-
throw new Error("
|
|
200
|
+
if (groupContent.type !== "comap") {
|
|
201
|
+
throw new Error("Group must be a map");
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
return Object.entries(coValue.sessions).flatMap(
|
|
@@ -208,7 +208,7 @@ export function determineValidTransactions(
|
|
|
208
208
|
);
|
|
209
209
|
return sessionLog.transactions
|
|
210
210
|
.filter((tx) => {
|
|
211
|
-
const transactorRoleAtTxTime =
|
|
211
|
+
const transactorRoleAtTxTime = groupContent.getAtTime(
|
|
212
212
|
transactor,
|
|
213
213
|
tx.madeAt
|
|
214
214
|
);
|
package/src/sync.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { LocalNode } from "./node.js";
|
|
|
3
3
|
import { Peer, PeerID, SyncMessage } from "./sync.js";
|
|
4
4
|
import { expectMap } from "./contentType.js";
|
|
5
5
|
import { MapOpPayload } from "./contentTypes/coMap.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Group } from "./group.js";
|
|
7
7
|
import {
|
|
8
8
|
ReadableStream,
|
|
9
9
|
WritableStream,
|
|
@@ -23,9 +23,9 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
23
23
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
24
24
|
const node = new LocalNode(admin, session);
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const group = node.createGroup();
|
|
27
27
|
|
|
28
|
-
const map =
|
|
28
|
+
const map = group.createMap();
|
|
29
29
|
|
|
30
30
|
map.edit((editable) => {
|
|
31
31
|
editable.set("hello", "world", "trusting");
|
|
@@ -53,7 +53,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
53
53
|
const reader = outRx.getReader();
|
|
54
54
|
|
|
55
55
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
56
|
-
expect((await reader.read()).value).toMatchObject(
|
|
56
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
57
57
|
|
|
58
58
|
const mapTellKnownStateMsg = await reader.read();
|
|
59
59
|
expect(mapTellKnownStateMsg.value).toEqual({
|
|
@@ -62,7 +62,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
62
62
|
} satisfies SyncMessage);
|
|
63
63
|
|
|
64
64
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
65
|
-
expect((await reader.read()).value).toMatchObject(
|
|
65
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
66
66
|
|
|
67
67
|
const newContentMsg = await reader.read();
|
|
68
68
|
|
|
@@ -71,7 +71,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
|
|
|
71
71
|
id: map.coValue.id,
|
|
72
72
|
header: {
|
|
73
73
|
type: "comap",
|
|
74
|
-
ruleset: { type: "
|
|
74
|
+
ruleset: { type: "ownedByGroup", group: group.id },
|
|
75
75
|
meta: null,
|
|
76
76
|
createdAt: map.coValue.header.createdAt,
|
|
77
77
|
uniqueness: map.coValue.header.uniqueness,
|
|
@@ -104,9 +104,9 @@ test("Node replies with only new tx to subscribe with some known state", async (
|
|
|
104
104
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
105
105
|
const node = new LocalNode(admin, session);
|
|
106
106
|
|
|
107
|
-
const
|
|
107
|
+
const group = node.createGroup();
|
|
108
108
|
|
|
109
|
-
const map =
|
|
109
|
+
const map = group.createMap();
|
|
110
110
|
|
|
111
111
|
map.edit((editable) => {
|
|
112
112
|
editable.set("hello", "world", "trusting");
|
|
@@ -137,7 +137,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
|
|
|
137
137
|
const reader = outRx.getReader();
|
|
138
138
|
|
|
139
139
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
140
|
-
expect((await reader.read()).value).toMatchObject(
|
|
140
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
141
141
|
|
|
142
142
|
const mapTellKnownStateMsg = await reader.read();
|
|
143
143
|
expect(mapTellKnownStateMsg.value).toEqual({
|
|
@@ -146,7 +146,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
|
|
|
146
146
|
} satisfies SyncMessage);
|
|
147
147
|
|
|
148
148
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
149
|
-
expect((await reader.read()).value).toMatchObject(
|
|
149
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
150
150
|
|
|
151
151
|
const mapNewContentMsg = await reader.read();
|
|
152
152
|
|
|
@@ -186,9 +186,9 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
186
186
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
187
187
|
const node = new LocalNode(admin, session);
|
|
188
188
|
|
|
189
|
-
const
|
|
189
|
+
const group = node.createGroup();
|
|
190
190
|
|
|
191
|
-
const map =
|
|
191
|
+
const map = group.createMap();
|
|
192
192
|
|
|
193
193
|
const [inRx, inTx] = newStreamPair<SyncMessage>();
|
|
194
194
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -214,7 +214,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
214
214
|
const reader = outRx.getReader();
|
|
215
215
|
|
|
216
216
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
217
|
-
expect((await reader.read()).value).toMatchObject(
|
|
217
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
218
218
|
|
|
219
219
|
const mapTellKnownStateMsg = await reader.read();
|
|
220
220
|
expect(mapTellKnownStateMsg.value).toEqual({
|
|
@@ -223,7 +223,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
|
|
|
223
223
|
} satisfies SyncMessage);
|
|
224
224
|
|
|
225
225
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
226
|
-
expect((await reader.read()).value).toMatchObject(
|
|
226
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
227
227
|
|
|
228
228
|
const mapNewContentHeaderOnlyMsg = await reader.read();
|
|
229
229
|
|
|
@@ -303,9 +303,9 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
303
303
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
304
304
|
const node = new LocalNode(admin, session);
|
|
305
305
|
|
|
306
|
-
const
|
|
306
|
+
const group = node.createGroup();
|
|
307
307
|
|
|
308
|
-
const map =
|
|
308
|
+
const map = group.createMap();
|
|
309
309
|
|
|
310
310
|
map.edit((editable) => {
|
|
311
311
|
editable.set("hello", "world", "trusting");
|
|
@@ -323,7 +323,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
323
323
|
|
|
324
324
|
const reader = outRx.getReader();
|
|
325
325
|
|
|
326
|
-
// expect((await reader.read()).value).toMatchObject(
|
|
326
|
+
// expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
327
327
|
|
|
328
328
|
const writer = inTx.getWriter();
|
|
329
329
|
|
|
@@ -337,7 +337,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
337
337
|
});
|
|
338
338
|
|
|
339
339
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
340
|
-
expect((await reader.read()).value).toMatchObject(
|
|
340
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
341
341
|
|
|
342
342
|
const mapTellKnownStateMsg = await reader.read();
|
|
343
343
|
expect(mapTellKnownStateMsg.value).toEqual({
|
|
@@ -346,7 +346,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
|
|
|
346
346
|
} satisfies SyncMessage);
|
|
347
347
|
|
|
348
348
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
349
|
-
expect((await reader.read()).value).toMatchObject(
|
|
349
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
350
350
|
|
|
351
351
|
const mapNewContentMsg = await reader.read();
|
|
352
352
|
|
|
@@ -382,9 +382,9 @@ test("No matter the optimistic known state, node respects invalid known state me
|
|
|
382
382
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
383
383
|
const node = new LocalNode(admin, session);
|
|
384
384
|
|
|
385
|
-
const
|
|
385
|
+
const group = node.createGroup();
|
|
386
386
|
|
|
387
|
-
const map =
|
|
387
|
+
const map = group.createMap();
|
|
388
388
|
|
|
389
389
|
const [inRx, inTx] = newStreamPair<SyncMessage>();
|
|
390
390
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -410,7 +410,7 @@ test("No matter the optimistic known state, node respects invalid known state me
|
|
|
410
410
|
const reader = outRx.getReader();
|
|
411
411
|
|
|
412
412
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
413
|
-
expect((await reader.read()).value).toMatchObject(
|
|
413
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
414
414
|
|
|
415
415
|
const mapTellKnownStateMsg = await reader.read();
|
|
416
416
|
expect(mapTellKnownStateMsg.value).toEqual({
|
|
@@ -419,7 +419,7 @@ test("No matter the optimistic known state, node respects invalid known state me
|
|
|
419
419
|
} satisfies SyncMessage);
|
|
420
420
|
|
|
421
421
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
422
|
-
expect((await reader.read()).value).toMatchObject(
|
|
422
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
423
423
|
|
|
424
424
|
const mapNewContentHeaderOnlyMsg = await reader.read();
|
|
425
425
|
|
|
@@ -485,9 +485,9 @@ test("If we add a peer, but it never subscribes to a coValue, it won't get any m
|
|
|
485
485
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
486
486
|
const node = new LocalNode(admin, session);
|
|
487
487
|
|
|
488
|
-
const
|
|
488
|
+
const group = node.createGroup();
|
|
489
489
|
|
|
490
|
-
const map =
|
|
490
|
+
const map = group.createMap();
|
|
491
491
|
|
|
492
492
|
const [inRx, _inTx] = newStreamPair<SyncMessage>();
|
|
493
493
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -514,9 +514,9 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
|
|
|
514
514
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
515
515
|
const node = new LocalNode(admin, session);
|
|
516
516
|
|
|
517
|
-
const
|
|
517
|
+
const group = node.createGroup();
|
|
518
518
|
|
|
519
|
-
const map =
|
|
519
|
+
const map = group.createMap();
|
|
520
520
|
|
|
521
521
|
const [inRx, _inTx] = newStreamPair<SyncMessage>();
|
|
522
522
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -535,7 +535,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
|
|
|
535
535
|
// });
|
|
536
536
|
expect((await reader.read()).value).toMatchObject({
|
|
537
537
|
action: "load",
|
|
538
|
-
id:
|
|
538
|
+
id: group.groupMap.coValue.id,
|
|
539
539
|
});
|
|
540
540
|
|
|
541
541
|
const mapSubscribeMsg = await reader.read();
|
|
@@ -552,7 +552,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
|
|
|
552
552
|
});
|
|
553
553
|
|
|
554
554
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
555
|
-
expect((await reader.read()).value).toMatchObject(
|
|
555
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
556
556
|
|
|
557
557
|
const mapNewContentMsg = await reader.read();
|
|
558
558
|
|
|
@@ -588,7 +588,7 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
|
|
|
588
588
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
589
589
|
const node = new LocalNode(admin, session);
|
|
590
590
|
|
|
591
|
-
const
|
|
591
|
+
const group = node.createGroup();
|
|
592
592
|
|
|
593
593
|
const [inRx, _inTx] = newStreamPair<SyncMessage>();
|
|
594
594
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -607,10 +607,10 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
|
|
|
607
607
|
// });
|
|
608
608
|
expect((await reader.read()).value).toMatchObject({
|
|
609
609
|
action: "load",
|
|
610
|
-
id:
|
|
610
|
+
id: group.groupMap.coValue.id,
|
|
611
611
|
});
|
|
612
612
|
|
|
613
|
-
const map =
|
|
613
|
+
const map = group.createMap();
|
|
614
614
|
|
|
615
615
|
const mapSubscribeMsg = await reader.read();
|
|
616
616
|
|
|
@@ -620,7 +620,7 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
|
|
|
620
620
|
} satisfies SyncMessage);
|
|
621
621
|
|
|
622
622
|
// expect((await reader.read()).value).toMatchObject(admContEx(adminID));
|
|
623
|
-
expect((await reader.read()).value).toMatchObject(
|
|
623
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
624
624
|
|
|
625
625
|
const mapContentMsg = await reader.read();
|
|
626
626
|
|
|
@@ -640,9 +640,9 @@ test("When we connect a new server peer, we try to sync all existing coValues to
|
|
|
640
640
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
641
641
|
const node = new LocalNode(admin, session);
|
|
642
642
|
|
|
643
|
-
const
|
|
643
|
+
const group = node.createGroup();
|
|
644
644
|
|
|
645
|
-
const map =
|
|
645
|
+
const map = group.createMap();
|
|
646
646
|
|
|
647
647
|
const [inRx, _inTx] = newStreamPair<SyncMessage>();
|
|
648
648
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -657,11 +657,11 @@ test("When we connect a new server peer, we try to sync all existing coValues to
|
|
|
657
657
|
const reader = outRx.getReader();
|
|
658
658
|
|
|
659
659
|
// const _adminSubscribeMessage = await reader.read();
|
|
660
|
-
const
|
|
660
|
+
const groupSubscribeMessage = await reader.read();
|
|
661
661
|
|
|
662
|
-
expect(
|
|
662
|
+
expect(groupSubscribeMessage.value).toEqual({
|
|
663
663
|
action: "load",
|
|
664
|
-
...
|
|
664
|
+
...group.groupMap.coValue.knownState(),
|
|
665
665
|
} satisfies SyncMessage);
|
|
666
666
|
|
|
667
667
|
const secondMessage = await reader.read();
|
|
@@ -676,9 +676,9 @@ test("When receiving a subscribe with a known state that is ahead of our own, pe
|
|
|
676
676
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
677
677
|
const node = new LocalNode(admin, session);
|
|
678
678
|
|
|
679
|
-
const
|
|
679
|
+
const group = node.createGroup();
|
|
680
680
|
|
|
681
|
-
const map =
|
|
681
|
+
const map = group.createMap();
|
|
682
682
|
|
|
683
683
|
const [inRx, inTx] = newStreamPair<SyncMessage>();
|
|
684
684
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -704,7 +704,7 @@ test("When receiving a subscribe with a known state that is ahead of our own, pe
|
|
|
704
704
|
const reader = outRx.getReader();
|
|
705
705
|
|
|
706
706
|
// expect((await reader.read()).value).toMatchObject(admStateEx(admin.id));
|
|
707
|
-
expect((await reader.read()).value).toMatchObject(
|
|
707
|
+
expect((await reader.read()).value).toMatchObject(groupStateEx(group));
|
|
708
708
|
const mapTellKnownState = await reader.read();
|
|
709
709
|
|
|
710
710
|
expect(mapTellKnownState.value).toEqual({
|
|
@@ -719,7 +719,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
|
|
|
719
719
|
|
|
720
720
|
const node1 = new LocalNode(admin, session);
|
|
721
721
|
|
|
722
|
-
const
|
|
722
|
+
const group = node1.createGroup();
|
|
723
723
|
|
|
724
724
|
const [inRx1, inTx1] = newStreamPair<SyncMessage>();
|
|
725
725
|
const [outRx1, outTx1] = newStreamPair<SyncMessage>();
|
|
@@ -754,40 +754,40 @@ test.skip("When replaying creation and transactions of a coValue as new content,
|
|
|
754
754
|
action: "load",
|
|
755
755
|
id: admin.id,
|
|
756
756
|
});
|
|
757
|
-
const
|
|
758
|
-
expect(
|
|
757
|
+
const groupSubscribeMsg = await from1.read();
|
|
758
|
+
expect(groupSubscribeMsg.value).toMatchObject({
|
|
759
759
|
action: "load",
|
|
760
|
-
id:
|
|
760
|
+
id: group.groupMap.coValue.id,
|
|
761
761
|
});
|
|
762
762
|
|
|
763
763
|
await to2.write(adminSubscribeMessage.value!);
|
|
764
|
-
await to2.write(
|
|
764
|
+
await to2.write(groupSubscribeMsg.value!);
|
|
765
765
|
|
|
766
766
|
// const adminTellKnownStateMsg = await from2.read();
|
|
767
767
|
// expect(adminTellKnownStateMsg.value).toMatchObject(admStateEx(admin.id));
|
|
768
768
|
|
|
769
|
-
const
|
|
770
|
-
expect(
|
|
769
|
+
const groupTellKnownStateMsg = await from2.read();
|
|
770
|
+
expect(groupTellKnownStateMsg.value).toMatchObject(groupStateEx(group));
|
|
771
771
|
|
|
772
772
|
expect(
|
|
773
773
|
node2.sync.peers["test1"]!.optimisticKnownStates[
|
|
774
|
-
|
|
774
|
+
group.groupMap.coValue.id
|
|
775
775
|
]
|
|
776
776
|
).toBeDefined();
|
|
777
777
|
|
|
778
778
|
// await to1.write(adminTellKnownStateMsg.value!);
|
|
779
|
-
await to1.write(
|
|
779
|
+
await to1.write(groupTellKnownStateMsg.value!);
|
|
780
780
|
|
|
781
781
|
// const adminContentMsg = await from1.read();
|
|
782
782
|
// expect(adminContentMsg.value).toMatchObject(admContEx(admin.id));
|
|
783
783
|
|
|
784
|
-
const
|
|
785
|
-
expect(
|
|
784
|
+
const groupContentMsg = await from1.read();
|
|
785
|
+
expect(groupContentMsg.value).toMatchObject(groupContentEx(group));
|
|
786
786
|
|
|
787
787
|
// await to2.write(adminContentMsg.value!);
|
|
788
|
-
await to2.write(
|
|
788
|
+
await to2.write(groupContentMsg.value!);
|
|
789
789
|
|
|
790
|
-
const map =
|
|
790
|
+
const map = group.createMap();
|
|
791
791
|
|
|
792
792
|
const mapSubscriptionMsg = await from1.read();
|
|
793
793
|
expect(mapSubscriptionMsg.value).toMatchObject({
|
|
@@ -840,9 +840,9 @@ test.skip("When loading a coValue on one node, the server node it is requested f
|
|
|
840
840
|
|
|
841
841
|
const node1 = new LocalNode(admin, session);
|
|
842
842
|
|
|
843
|
-
const
|
|
843
|
+
const group = node1.createGroup();
|
|
844
844
|
|
|
845
|
-
const map =
|
|
845
|
+
const map = group.createMap();
|
|
846
846
|
map.edit((editable) => {
|
|
847
847
|
editable.set("hello", "world", "trusting");
|
|
848
848
|
});
|
|
@@ -868,9 +868,9 @@ test("Can sync a coValue through a server to another client", async () => {
|
|
|
868
868
|
|
|
869
869
|
const client1 = new LocalNode(admin, session);
|
|
870
870
|
|
|
871
|
-
const
|
|
871
|
+
const group = client1.createGroup();
|
|
872
872
|
|
|
873
|
-
const map =
|
|
873
|
+
const map = group.createMap();
|
|
874
874
|
map.edit((editable) => {
|
|
875
875
|
editable.set("hello", "world", "trusting");
|
|
876
876
|
});
|
|
@@ -910,9 +910,9 @@ test("Can sync a coValue with private transactions through a server to another c
|
|
|
910
910
|
|
|
911
911
|
const client1 = new LocalNode(admin, session);
|
|
912
912
|
|
|
913
|
-
const
|
|
913
|
+
const group = client1.createGroup();
|
|
914
914
|
|
|
915
|
-
const map =
|
|
915
|
+
const map = group.createMap();
|
|
916
916
|
map.edit((editable) => {
|
|
917
917
|
editable.set("hello", "world", "private");
|
|
918
918
|
});
|
|
@@ -952,7 +952,7 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
|
|
|
952
952
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
953
953
|
const node = new LocalNode(admin, session);
|
|
954
954
|
|
|
955
|
-
const
|
|
955
|
+
const group = node.createGroup();
|
|
956
956
|
|
|
957
957
|
const [inRx, inTx] = newStreamPair<SyncMessage>();
|
|
958
958
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -971,10 +971,10 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
|
|
|
971
971
|
// });
|
|
972
972
|
expect((await reader.read()).value).toMatchObject({
|
|
973
973
|
action: "load",
|
|
974
|
-
id:
|
|
974
|
+
id: group.groupMap.coValue.id,
|
|
975
975
|
});
|
|
976
976
|
|
|
977
|
-
const map =
|
|
977
|
+
const map = group.createMap();
|
|
978
978
|
|
|
979
979
|
const mapSubscribeMsg = await reader.read();
|
|
980
980
|
|
|
@@ -984,7 +984,7 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
|
|
|
984
984
|
} satisfies SyncMessage);
|
|
985
985
|
|
|
986
986
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
987
|
-
expect((await reader.read()).value).toMatchObject(
|
|
987
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
988
988
|
|
|
989
989
|
const mapContentMsg = await reader.read();
|
|
990
990
|
|
|
@@ -1006,7 +1006,7 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
|
|
|
1006
1006
|
const [admin, session] = randomAnonymousAccountAndSessionID();
|
|
1007
1007
|
const node = new LocalNode(admin, session);
|
|
1008
1008
|
|
|
1009
|
-
const
|
|
1009
|
+
const group = node.createGroup();
|
|
1010
1010
|
|
|
1011
1011
|
const [inRx, inTx] = newStreamPair<SyncMessage>();
|
|
1012
1012
|
const [outRx, outTx] = newStreamPair<SyncMessage>();
|
|
@@ -1025,10 +1025,10 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
|
|
|
1025
1025
|
// });
|
|
1026
1026
|
expect((await reader.read()).value).toMatchObject({
|
|
1027
1027
|
action: "load",
|
|
1028
|
-
id:
|
|
1028
|
+
id: group.groupMap.coValue.id,
|
|
1029
1029
|
});
|
|
1030
1030
|
|
|
1031
|
-
const map =
|
|
1031
|
+
const map = group.createMap();
|
|
1032
1032
|
|
|
1033
1033
|
const mapSubscribeMsg = await reader.read();
|
|
1034
1034
|
|
|
@@ -1038,7 +1038,7 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
|
|
|
1038
1038
|
} satisfies SyncMessage);
|
|
1039
1039
|
|
|
1040
1040
|
// expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
|
|
1041
|
-
expect((await reader.read()).value).toMatchObject(
|
|
1041
|
+
expect((await reader.read()).value).toMatchObject(groupContentEx(group));
|
|
1042
1042
|
|
|
1043
1043
|
const mapContentMsg = await reader.read();
|
|
1044
1044
|
|
|
@@ -1066,9 +1066,9 @@ test("If we start loading a coValue before connecting to a peer that has it, it
|
|
|
1066
1066
|
|
|
1067
1067
|
const node1 = new LocalNode(admin, session);
|
|
1068
1068
|
|
|
1069
|
-
const
|
|
1069
|
+
const group = node1.createGroup();
|
|
1070
1070
|
|
|
1071
|
-
const map =
|
|
1071
|
+
const map = group.createMap();
|
|
1072
1072
|
map.edit((editable) => {
|
|
1073
1073
|
editable.set("hello", "world", "trusting");
|
|
1074
1074
|
});
|
|
@@ -1096,10 +1096,10 @@ test("If we start loading a coValue before connecting to a peer that has it, it
|
|
|
1096
1096
|
);
|
|
1097
1097
|
});
|
|
1098
1098
|
|
|
1099
|
-
function
|
|
1099
|
+
function groupContentEx(group: Group) {
|
|
1100
1100
|
return {
|
|
1101
1101
|
action: "content",
|
|
1102
|
-
id:
|
|
1102
|
+
id: group.groupMap.coValue.id,
|
|
1103
1103
|
};
|
|
1104
1104
|
}
|
|
1105
1105
|
|
|
@@ -1110,10 +1110,10 @@ function admContEx(adminID: AccountID) {
|
|
|
1110
1110
|
};
|
|
1111
1111
|
}
|
|
1112
1112
|
|
|
1113
|
-
function
|
|
1113
|
+
function groupStateEx(group: Group) {
|
|
1114
1114
|
return {
|
|
1115
1115
|
action: "known",
|
|
1116
|
-
id:
|
|
1116
|
+
id: group.groupMap.coValue.id,
|
|
1117
1117
|
};
|
|
1118
1118
|
}
|
|
1119
1119
|
|