jazz-tools 0.7.0-alpha.27 → 0.7.0-alpha.29
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +39 -36
- package/CHANGELOG.md +16 -0
- package/dist/coValues/account.js +15 -8
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/group.js +26 -1
- package/dist/coValues/group.js.map +1 -1
- package/dist/implementation/schema.js +5 -3
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/symbols.js +5 -0
- package/dist/implementation/symbols.js.map +1 -0
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +2 -2
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +15 -16
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +4 -4
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +70 -0
- package/dist/tests/groupsAndAccounts.test.js.map +1 -0
- package/package.json +2 -2
- package/src/coValues/account.ts +21 -10
- package/src/coValues/group.ts +62 -16
- package/src/implementation/schema.ts +5 -9
- package/src/implementation/symbols.ts +12 -0
- package/src/internal.ts +1 -0
- package/src/tests/coList.test.ts +2 -2
- package/src/tests/coMap.test.ts +24 -19
- package/src/tests/coStream.test.ts +4 -4
- package/src/tests/groupsAndAccounts.test.ts +77 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
import { expect, describe, test, beforeEach } from "vitest";
|
2
|
+
|
3
|
+
import { webcrypto } from "node:crypto";
|
4
|
+
import { Account, jazzReady, CoMap, co, Group } from "..";
|
5
|
+
|
6
|
+
if (!("crypto" in globalThis)) {
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
|
+
(globalThis as any).crypto = webcrypto;
|
9
|
+
}
|
10
|
+
|
11
|
+
beforeEach(async () => {
|
12
|
+
await jazzReady;
|
13
|
+
});
|
14
|
+
|
15
|
+
describe("Custom accounts and groups", async () => {
|
16
|
+
class CustomProfile extends CoMap<CustomProfile> {
|
17
|
+
name = co.string;
|
18
|
+
color = co.string;
|
19
|
+
}
|
20
|
+
|
21
|
+
class CustomAccount extends Account<CustomAccount> {
|
22
|
+
profile = co.ref(CustomProfile);
|
23
|
+
root = co.ref(CoMap);
|
24
|
+
|
25
|
+
migrate(creationProps?: { name: string }) {
|
26
|
+
if (creationProps) {
|
27
|
+
const profileGroup = new Group({ owner: this });
|
28
|
+
profileGroup.addMember("everyone", "reader");
|
29
|
+
this.profile = new CustomProfile(
|
30
|
+
{ name: creationProps.name, color: "blue" },
|
31
|
+
{ owner: this }
|
32
|
+
);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
class CustomGroup extends Group<CustomGroup> {
|
38
|
+
profile = co.null;
|
39
|
+
root = co.null;
|
40
|
+
[co.members] = co.ref(CustomAccount);
|
41
|
+
}
|
42
|
+
|
43
|
+
type T = CustomGroup[typeof co.members];
|
44
|
+
|
45
|
+
test("Custom account and group", async () => {
|
46
|
+
const me = await CustomAccount.create({
|
47
|
+
creationProps: { name: "Hermes Puggington" },
|
48
|
+
});
|
49
|
+
|
50
|
+
expect(me.profile).toBeDefined();
|
51
|
+
expect(me.profile?.name).toBe("Hermes Puggington");
|
52
|
+
expect(me.profile?.color).toBe("blue");
|
53
|
+
|
54
|
+
const group = new CustomGroup({ owner: me });
|
55
|
+
group.addMember("everyone", "reader");
|
56
|
+
|
57
|
+
expect(group.members).toMatchObject([
|
58
|
+
{ id: me.id, role: "admin" },
|
59
|
+
{ id: "everyone", role: "reader" },
|
60
|
+
]);
|
61
|
+
|
62
|
+
await new Promise<void>((resolve) => {
|
63
|
+
group.subscribe((update) => {
|
64
|
+
const meAsMember = update.members.find((member) => {
|
65
|
+
return member.id === me.id && member.account?.profile;
|
66
|
+
});
|
67
|
+
if (meAsMember) {
|
68
|
+
expect(meAsMember.account?.profile?.name).toBe(
|
69
|
+
"Hermes Puggington"
|
70
|
+
);
|
71
|
+
expect(meAsMember.account?.profile?.color).toBe("blue");
|
72
|
+
resolve();
|
73
|
+
}
|
74
|
+
});
|
75
|
+
});
|
76
|
+
});
|
77
|
+
});
|