cojson 0.16.4 → 0.16.5
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 +13 -0
- package/dist/coValue.d.ts.map +1 -1
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +6 -10
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +15 -122
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValues/group.d.ts +18 -10
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +221 -59
- package/dist/coValues/group.js.map +1 -1
- package/dist/ids.d.ts +3 -3
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js.map +1 -1
- package/dist/localNode.d.ts +5 -5
- package/dist/localNode.d.ts.map +1 -1
- package/dist/tests/group.inheritance.test.js +195 -0
- package/dist/tests/group.inheritance.test.js.map +1 -1
- package/dist/tests/group.removeMember.test.js +152 -1
- package/dist/tests/group.removeMember.test.js.map +1 -1
- package/dist/tests/group.roleOf.test.js +2 -2
- package/dist/tests/group.roleOf.test.js.map +1 -1
- package/dist/tests/group.test.js +81 -3
- package/dist/tests/group.test.js.map +1 -1
- package/dist/tests/sync.load.test.js +6 -3
- package/dist/tests/sync.load.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +1 -0
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +5 -0
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.d.ts +2 -2
- package/dist/typeUtils/accountOrAgentIDfromSessionID.d.ts.map +1 -1
- package/dist/typeUtils/expectGroup.d.ts.map +1 -1
- package/dist/typeUtils/expectGroup.js +6 -5
- package/dist/typeUtils/expectGroup.js.map +1 -1
- package/package.json +1 -1
- package/src/coValue.ts +1 -4
- package/src/coValueCore/coValueCore.ts +23 -188
- package/src/coValues/group.ts +310 -91
- package/src/ids.ts +3 -3
- package/src/localNode.ts +7 -7
- package/src/tests/group.inheritance.test.ts +279 -0
- package/src/tests/group.removeMember.test.ts +244 -1
- package/src/tests/group.roleOf.test.ts +2 -2
- package/src/tests/group.test.ts +105 -5
- package/src/tests/sync.load.test.ts +6 -3
- package/src/tests/testUtils.ts +5 -0
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +2 -2
- package/src/typeUtils/expectGroup.ts +8 -5
package/src/tests/group.test.ts
CHANGED
|
@@ -3,18 +3,27 @@ import { RawCoList } from "../coValues/coList.js";
|
|
|
3
3
|
import { RawCoMap } from "../coValues/coMap.js";
|
|
4
4
|
import { RawCoStream } from "../coValues/coStream.js";
|
|
5
5
|
import { RawBinaryCoStream } from "../coValues/coStream.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import type { RawCoValue, RawGroup } from "../exports.js";
|
|
7
|
+
import type { NewContentMessage } from "../sync.js";
|
|
8
8
|
import {
|
|
9
9
|
createThreeConnectedNodes,
|
|
10
10
|
createTwoConnectedNodes,
|
|
11
11
|
loadCoValueOrFail,
|
|
12
12
|
nodeWithRandomAgentAndSessionID,
|
|
13
|
-
|
|
14
|
-
waitFor,
|
|
13
|
+
setupTestNode,
|
|
15
14
|
} from "./testUtils.js";
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
function expectGroup(content: RawCoValue): RawGroup {
|
|
17
|
+
if (content.type !== "comap") {
|
|
18
|
+
throw new Error("Expected group");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (content.core.verified.header.ruleset.type !== "group") {
|
|
22
|
+
throw new Error("Expected group ruleset in group");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return content as RawGroup;
|
|
26
|
+
}
|
|
18
27
|
|
|
19
28
|
test("Can create a RawCoMap in a group", () => {
|
|
20
29
|
const node = nodeWithRandomAgentAndSessionID();
|
|
@@ -307,6 +316,97 @@ test("Invites should have access to the new keys", async () => {
|
|
|
307
316
|
expect(mapOnNode2.get("test")).toEqual("Written from node1");
|
|
308
317
|
});
|
|
309
318
|
|
|
319
|
+
test("Should heal the missing key_for_everyone", async () => {
|
|
320
|
+
const client = setupTestNode({
|
|
321
|
+
secret:
|
|
322
|
+
"sealerSecret_zBTPp7U58Fzq9o7EvJpu4KEziepi8QVf2Xaxuy5xmmXFx/signerSecret_z62DuviZdXCjz4EZWofvr9vaLYFXDeTaC9KWhoQiQjzKk",
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const brokenGroupContent = {
|
|
326
|
+
action: "content",
|
|
327
|
+
id: "co_zW7F36Nnop9A7Er4gUzBcUXnZCK",
|
|
328
|
+
header: {
|
|
329
|
+
type: "comap",
|
|
330
|
+
ruleset: {
|
|
331
|
+
type: "group",
|
|
332
|
+
initialAdmin:
|
|
333
|
+
"sealer_z12QDazYB3ygPZtBV7sMm7iYKMRnNZ6Aaj1dfLXR7LSBm/signer_z2AskZQbc82qxo7iA3oiXoNExHLsAEXC2pHbwJzRnATWv",
|
|
334
|
+
},
|
|
335
|
+
meta: null,
|
|
336
|
+
createdAt: "2025-08-06T10:14:39.617Z",
|
|
337
|
+
uniqueness: "z3LJjnuPiPJaf5Qb9A",
|
|
338
|
+
},
|
|
339
|
+
priority: 0,
|
|
340
|
+
new: {
|
|
341
|
+
"sealer_z12QDazYB3ygPZtBV7sMm7iYKMRnNZ6Aaj1dfLXR7LSBm/signer_z2AskZQbc82qxo7iA3oiXoNExHLsAEXC2pHbwJzRnATWv_session_zYLsz2CiW9pW":
|
|
342
|
+
{
|
|
343
|
+
after: 0,
|
|
344
|
+
newTransactions: [
|
|
345
|
+
{
|
|
346
|
+
privacy: "trusting",
|
|
347
|
+
madeAt: 1754475279619,
|
|
348
|
+
changes:
|
|
349
|
+
'[{"key":"sealer_z12QDazYB3ygPZtBV7sMm7iYKMRnNZ6Aaj1dfLXR7LSBm/signer_z2AskZQbc82qxo7iA3oiXoNExHLsAEXC2pHbwJzRnATWv","op":"set","value":"admin"}]',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
privacy: "trusting",
|
|
353
|
+
madeAt: 1754475279621,
|
|
354
|
+
changes:
|
|
355
|
+
'[{"key":"key_z5CVahfMkEWPj1B3zH_for_sealer_z12QDazYB3ygPZtBV7sMm7iYKMRnNZ6Aaj1dfLXR7LSBm/signer_z2AskZQbc82qxo7iA3oiXoNExHLsAEXC2pHbwJzRnATWv","op":"set","value":"sealed_UCg4UkytXF-W8PaIvaDffO3pZ3d9hdXUuNkQQEikPTAuOD9us92Pqb5Vgu7lx1Fpb0X8V5BJ2yxz6_D5WOzK3qjWBSsc7J1xDJA=="}]',
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
privacy: "trusting",
|
|
359
|
+
madeAt: 1754475279621,
|
|
360
|
+
changes:
|
|
361
|
+
'[{"key":"readKey","op":"set","value":"key_z5CVahfMkEWPj1B3zH"}]',
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
privacy: "trusting",
|
|
365
|
+
madeAt: 1754475279622,
|
|
366
|
+
changes: '[{"key":"everyone","op":"set","value":"reader"}]',
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
privacy: "trusting",
|
|
370
|
+
madeAt: 1754475279623,
|
|
371
|
+
changes:
|
|
372
|
+
'[{"key":"key_z5CVahfMkEWPj1B3zH_for_everyone","op":"set","value":"keySecret_z9U9gzkahQXCxDoSw7isiUnbobXwuLdcSkL9Ci6ZEEkaL"}]',
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
privacy: "trusting",
|
|
376
|
+
madeAt: 1754475279623,
|
|
377
|
+
changes:
|
|
378
|
+
'[{"key":"key_z4Fi7hZNBx7XoVAKkP_for_sealer_z12QDazYB3ygPZtBV7sMm7iYKMRnNZ6Aaj1dfLXR7LSBm/signer_z2AskZQbc82qxo7iA3oiXoNExHLsAEXC2pHbwJzRnATWv","op":"set","value":"sealed_UuCBBfZkTnRTrGraqWWlzm9JE-VFduhsfu7WaZjpCbJYOTXpPhSNOnzGeS8qVuIsG6dORbME22lc5ltLxPjRqofQdDCNGQehCeQ=="}]',
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
privacy: "trusting",
|
|
382
|
+
madeAt: 1754475279624,
|
|
383
|
+
changes:
|
|
384
|
+
'[{"key":"key_z5CVahfMkEWPj1B3zH_for_key_z4Fi7hZNBx7XoVAKkP","op":"set","value":"encrypted_USTrBuobwTCORwy5yHxy4sFZ7swfrafP6k5ZwcTf76f0MBu9Ie-JmsX3mNXad4mluI47gvGXzi8I_"}]',
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
privacy: "trusting",
|
|
388
|
+
madeAt: 1754475279624,
|
|
389
|
+
changes:
|
|
390
|
+
'[{"key":"readKey","op":"set","value":"key_z4Fi7hZNBx7XoVAKkP"}]',
|
|
391
|
+
},
|
|
392
|
+
],
|
|
393
|
+
lastSignature:
|
|
394
|
+
"signature_z3tsE7U1JaeNeUmZ4EY3Xq5uQ9jq9jDi6Rkhdt7T7b7z4NCnpMgB4bo8TwLXYVCrRdBm6PoyyPdK8fYFzHJUh5EzA",
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
} as unknown as NewContentMessage;
|
|
398
|
+
|
|
399
|
+
client.node.syncManager.handleNewContent(brokenGroupContent, "import");
|
|
400
|
+
|
|
401
|
+
const group = expectGroup(
|
|
402
|
+
client.node.getCoValue(brokenGroupContent.id).getCurrentContent(),
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
expect(group.get(`${group.get("readKey")!}_for_everyone`)).toBe(
|
|
406
|
+
group.core.getCurrentReadKey()?.secret,
|
|
407
|
+
);
|
|
408
|
+
});
|
|
409
|
+
|
|
310
410
|
describe("writeOnly", () => {
|
|
311
411
|
test("Admins can invite writeOnly members", async () => {
|
|
312
412
|
const { node1, node2 } = await createTwoConnectedNodes("server", "server");
|
|
@@ -590,11 +590,14 @@ describe("loading coValues from server", () => {
|
|
|
590
590
|
"client -> server | LOAD Map sessions: empty",
|
|
591
591
|
"server -> client | CONTENT Group header: true new: After: 0 New: 5",
|
|
592
592
|
"client -> server | KNOWN Group sessions: header/5",
|
|
593
|
-
"
|
|
594
|
-
"
|
|
593
|
+
"server -> client | CONTENT Group header: true new: After: 0 New: 5",
|
|
594
|
+
"client -> server | KNOWN Group sessions: header/5",
|
|
595
595
|
"server -> client | CONTENT Map header: true new: After: 0 New: 1",
|
|
596
|
-
"client -> server | LOAD Group sessions: header/5",
|
|
597
596
|
"client -> server | KNOWN Map sessions: header/1",
|
|
597
|
+
"client -> server | LOAD Group sessions: header/5",
|
|
598
|
+
"server -> client | KNOWN Group sessions: header/5",
|
|
599
|
+
"client -> server | LOAD Map sessions: header/1",
|
|
600
|
+
"server -> client | KNOWN Map sessions: header/1",
|
|
598
601
|
]
|
|
599
602
|
`);
|
|
600
603
|
});
|
package/src/tests/testUtils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RawAccountID } from "../coValues/account.js";
|
|
2
|
-
import { AgentID, SessionID } from "../ids.js";
|
|
1
|
+
import type { RawAccountID } from "../coValues/account.js";
|
|
2
|
+
import type { AgentID, SessionID } from "../ids.js";
|
|
3
3
|
|
|
4
4
|
export function accountOrAgentIDfromSessionID(
|
|
5
5
|
sessionID: SessionID,
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { type RawCoValue
|
|
1
|
+
import { type RawCoValue } from "../coValue.js";
|
|
2
2
|
import { RawGroup } from "../coValues/group.js";
|
|
3
3
|
|
|
4
4
|
export function expectGroup(content: RawCoValue): RawGroup {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (content.type !== "comap") {
|
|
6
|
+
throw new Error("Expected group");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (content.core.verified.header.ruleset.type !== "group") {
|
|
7
10
|
throw new Error("Expected group ruleset in group");
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
if (!(
|
|
13
|
+
if (!(content instanceof RawGroup)) {
|
|
11
14
|
throw new Error("Expected group");
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
return
|
|
17
|
+
return content;
|
|
15
18
|
}
|