jazz-tools 0.7.0-alpha.36 → 0.7.0-alpha.38
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +3 -10
- package/.prettierrc.js +9 -0
- package/.turbo/turbo-build.log +3 -91
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +140 -0
- package/CHANGELOG.md +19 -0
- package/README.md +10 -2
- package/dist/coValues/account.js +22 -12
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +7 -9
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +11 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +15 -8
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/deepLoading.js +57 -0
- package/dist/coValues/deepLoading.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +1 -1
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +1 -0
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +34 -28
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/devtoolsFormatters.js +1 -0
- package/dist/implementation/devtoolsFormatters.js.map +1 -1
- package/dist/implementation/refs.js +4 -2
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +5 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js +9 -4
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/implementation/symbols.js.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.js +2 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +20 -17
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +27 -17
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +39 -24
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js +188 -0
- package/dist/tests/deepLoading.test.js.map +1 -0
- package/dist/tests/groupsAndAccounts.test.js +6 -11
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +12 -6
- package/src/coValues/account.ts +60 -58
- package/src/coValues/coList.ts +31 -51
- package/src/coValues/coMap.ts +27 -21
- package/src/coValues/coStream.ts +44 -32
- package/src/coValues/deepLoading.ts +215 -0
- package/src/coValues/extensions/imageDef.ts +3 -3
- package/src/coValues/group.ts +11 -13
- package/src/coValues/interfaces.ts +151 -93
- package/src/implementation/devtoolsFormatters.ts +1 -0
- package/src/implementation/inspect.ts +1 -1
- package/src/implementation/refs.ts +29 -15
- package/src/implementation/schema.ts +21 -6
- package/src/implementation/subscriptionScope.ts +33 -17
- package/src/implementation/symbols.ts +0 -1
- package/src/index.ts +5 -3
- package/src/internal.ts +3 -2
- package/src/tests/coList.test.ts +33 -28
- package/src/tests/coMap.test.ts +63 -55
- package/src/tests/coStream.test.ts +82 -67
- package/src/tests/deepLoading.test.ts +301 -0
- package/src/tests/groupsAndAccounts.test.ts +9 -18
@@ -0,0 +1,188 @@
|
|
1
|
+
const Crypto = await WasmCrypto.create();
|
2
|
+
import { expect, describe, test, expectTypeOf } from "vitest";
|
3
|
+
import { connectedPeers } from "cojson/src/streamUtils.js";
|
4
|
+
import { Account, CoList, CoMap, CoStream, WasmCrypto, co, Profile, isControlledAccount, } from "../index.js";
|
5
|
+
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
|
+
class TestMap extends CoMap {
|
7
|
+
constructor() {
|
8
|
+
super(...arguments);
|
9
|
+
this.list = co.ref(TestList);
|
10
|
+
this.optionalRef = co.ref(InnermostMap);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
class TestList extends CoList.Of(co.ref(() => InnerMap)) {
|
14
|
+
}
|
15
|
+
class InnerMap extends CoMap {
|
16
|
+
constructor() {
|
17
|
+
super(...arguments);
|
18
|
+
this.stream = co.ref(TestStream);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
class TestStream extends CoStream.Of(co.ref(() => InnermostMap)) {
|
22
|
+
}
|
23
|
+
class InnermostMap extends CoMap {
|
24
|
+
constructor() {
|
25
|
+
super(...arguments);
|
26
|
+
this.value = co.string;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
describe("Deep loading with depth arg", async () => {
|
30
|
+
const me = await Account.create({
|
31
|
+
creationProps: { name: "Hermes Puggington" },
|
32
|
+
crypto: Crypto,
|
33
|
+
});
|
34
|
+
const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
|
35
|
+
peer1role: "server",
|
36
|
+
peer2role: "client",
|
37
|
+
});
|
38
|
+
if (!isControlledAccount(me)) {
|
39
|
+
throw "me is not a controlled account";
|
40
|
+
}
|
41
|
+
me._raw.core.node.syncManager.addPeer(secondPeer);
|
42
|
+
const meOnSecondPeer = await Account.become({
|
43
|
+
accountID: me.id,
|
44
|
+
accountSecret: me._raw.agentSecret,
|
45
|
+
peersToLoadFrom: [initialAsPeer],
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
47
|
+
sessionID: newRandomSessionID(me.id),
|
48
|
+
crypto: Crypto,
|
49
|
+
});
|
50
|
+
test("loading a deeply nested object will wait until all required refs are loaded", async () => {
|
51
|
+
const map = TestMap.create({
|
52
|
+
list: TestList.create([
|
53
|
+
InnerMap.create({
|
54
|
+
stream: TestStream.create([
|
55
|
+
InnermostMap.create({ value: "hello" }, { owner: me }),
|
56
|
+
], { owner: me }),
|
57
|
+
}, { owner: me }),
|
58
|
+
], { owner: me }),
|
59
|
+
}, { owner: me });
|
60
|
+
const map1 = await TestMap.load(map.id, meOnSecondPeer, {});
|
61
|
+
expectTypeOf(map1).toEqualTypeOf();
|
62
|
+
if (map1 === undefined) {
|
63
|
+
throw new Error("map1 is undefined");
|
64
|
+
}
|
65
|
+
expect(map1.list).toBe(null);
|
66
|
+
const map2 = await TestMap.load(map.id, meOnSecondPeer, { list: [] });
|
67
|
+
expectTypeOf(map2).toEqualTypeOf();
|
68
|
+
if (map2 === undefined) {
|
69
|
+
throw new Error("map2 is undefined");
|
70
|
+
}
|
71
|
+
expect(map2.list).not.toBe(null);
|
72
|
+
expect(map2.list[0]).toBe(null);
|
73
|
+
const map3 = await TestMap.load(map.id, meOnSecondPeer, { list: [{}] });
|
74
|
+
expectTypeOf(map3).toEqualTypeOf();
|
75
|
+
if (map3 === undefined) {
|
76
|
+
throw new Error("map3 is undefined");
|
77
|
+
}
|
78
|
+
expect(map3.list[0]).not.toBe(null);
|
79
|
+
expect(map3.list[0]?.stream).toBe(null);
|
80
|
+
const map3a = await TestMap.load(map.id, meOnSecondPeer, {
|
81
|
+
optionalRef: {},
|
82
|
+
});
|
83
|
+
expectTypeOf(map3a).toEqualTypeOf();
|
84
|
+
const map4 = await TestMap.load(map.id, meOnSecondPeer, {
|
85
|
+
list: [{ stream: [] }],
|
86
|
+
});
|
87
|
+
expectTypeOf(map4).toEqualTypeOf();
|
88
|
+
if (map4 === undefined) {
|
89
|
+
throw new Error("map4 is undefined");
|
90
|
+
}
|
91
|
+
expect(map4.list[0]?.stream).not.toBe(null);
|
92
|
+
// TODO: we should expect null here, but apparently we don't even have the id/ref?
|
93
|
+
expect(map4.list[0]?.stream?.[me.id]?.value).not.toBeDefined();
|
94
|
+
expect(map4.list[0]?.stream?.byMe?.value).not.toBeDefined();
|
95
|
+
const map5 = await TestMap.load(map.id, meOnSecondPeer, {
|
96
|
+
list: [{ stream: [{}] }],
|
97
|
+
});
|
98
|
+
expectTypeOf(map5).toEqualTypeOf();
|
99
|
+
if (map5 === undefined) {
|
100
|
+
throw new Error("map5 is undefined");
|
101
|
+
}
|
102
|
+
expect(map5.list[0]?.stream?.[me.id]?.value).not.toBe(null);
|
103
|
+
expect(map5.list[0]?.stream?.byMe?.value).not.toBe(null);
|
104
|
+
});
|
105
|
+
});
|
106
|
+
class CustomProfile extends Profile {
|
107
|
+
constructor() {
|
108
|
+
super(...arguments);
|
109
|
+
this.stream = co.ref(TestStream);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
class CustomAccount extends Account {
|
113
|
+
constructor() {
|
114
|
+
super(...arguments);
|
115
|
+
this.profile = co.ref(CustomProfile);
|
116
|
+
this.root = co.ref(TestMap);
|
117
|
+
}
|
118
|
+
async migrate(creationProps) {
|
119
|
+
if (creationProps) {
|
120
|
+
this.profile = CustomProfile.create({
|
121
|
+
name: creationProps.name,
|
122
|
+
stream: TestStream.create([], { owner: this }),
|
123
|
+
}, { owner: this });
|
124
|
+
this.root = TestMap.create({ list: TestList.create([], { owner: this }) }, { owner: this });
|
125
|
+
}
|
126
|
+
const thisLoaded = await CustomAccount.load(this, {
|
127
|
+
profile: { stream: [] },
|
128
|
+
root: { list: [] },
|
129
|
+
});
|
130
|
+
expectTypeOf(thisLoaded).toEqualTypeOf();
|
131
|
+
}
|
132
|
+
}
|
133
|
+
test("Deep loading within account", async () => {
|
134
|
+
const me = await CustomAccount.create({
|
135
|
+
creationProps: { name: "Hermes Puggington" },
|
136
|
+
crypto: Crypto,
|
137
|
+
});
|
138
|
+
const meLoaded = await CustomAccount.load(me, {
|
139
|
+
profile: { stream: [] },
|
140
|
+
root: { list: [] },
|
141
|
+
});
|
142
|
+
expectTypeOf(meLoaded).toEqualTypeOf();
|
143
|
+
if (meLoaded === undefined) {
|
144
|
+
throw new Error("meLoaded is undefined");
|
145
|
+
}
|
146
|
+
expect(meLoaded.profile.stream).not.toBe(null);
|
147
|
+
expect(meLoaded.root.list).not.toBe(null);
|
148
|
+
});
|
149
|
+
class RecordLike extends CoMap.Record(co.ref(TestMap)) {
|
150
|
+
}
|
151
|
+
test("Deep loading a record-like coMap", async () => {
|
152
|
+
const me = await Account.create({
|
153
|
+
creationProps: { name: "Hermes Puggington" },
|
154
|
+
crypto: Crypto,
|
155
|
+
});
|
156
|
+
const [initialAsPeer, secondPeer] = connectedPeers("initial", "second", {
|
157
|
+
peer1role: "server",
|
158
|
+
peer2role: "client",
|
159
|
+
});
|
160
|
+
if (!isControlledAccount(me)) {
|
161
|
+
throw "me is not a controlled account";
|
162
|
+
}
|
163
|
+
me._raw.core.node.syncManager.addPeer(secondPeer);
|
164
|
+
const meOnSecondPeer = await Account.become({
|
165
|
+
accountID: me.id,
|
166
|
+
accountSecret: me._raw.agentSecret,
|
167
|
+
peersToLoadFrom: [initialAsPeer],
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
169
|
+
sessionID: newRandomSessionID(me.id),
|
170
|
+
crypto: Crypto,
|
171
|
+
});
|
172
|
+
const record = RecordLike.create({
|
173
|
+
key1: TestMap.create({ list: TestList.create([], { owner: me }) }, { owner: me }),
|
174
|
+
key2: TestMap.create({ list: TestList.create([], { owner: me }) }, { owner: me }),
|
175
|
+
}, { owner: me });
|
176
|
+
const recordLoaded = await RecordLike.load(record.id, meOnSecondPeer, [
|
177
|
+
{ list: [{}] },
|
178
|
+
]);
|
179
|
+
expectTypeOf(recordLoaded).toEqualTypeOf();
|
180
|
+
if (recordLoaded === undefined) {
|
181
|
+
throw new Error("recordLoaded is undefined");
|
182
|
+
}
|
183
|
+
expect(recordLoaded.key1?.list).not.toBe(null);
|
184
|
+
expect(recordLoaded.key1?.list).not.toBe(undefined);
|
185
|
+
expect(recordLoaded.key2?.list).not.toBe(null);
|
186
|
+
expect(recordLoaded.key2?.list).not.toBe(undefined);
|
187
|
+
});
|
188
|
+
//# sourceMappingURL=deepLoading.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"deepLoading.test.js","sourceRoot":"","sources":["../../src/tests/deepLoading.test.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACH,OAAO,EACP,MAAM,EACN,KAAK,EACL,QAAQ,EAER,UAAU,EACV,EAAE,EACF,OAAO,EACP,mBAAmB,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AAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACxD,CAAC,CAAC,CAAC"}
|
@@ -1,13 +1,6 @@
|
|
1
|
-
import { expect, describe, test
|
2
|
-
import {
|
3
|
-
|
4
|
-
if (!("crypto" in globalThis)) {
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
6
|
-
globalThis.crypto = webcrypto;
|
7
|
-
}
|
8
|
-
beforeEach(async () => {
|
9
|
-
await jazzReady;
|
10
|
-
});
|
1
|
+
import { expect, describe, test } from "vitest";
|
2
|
+
import { Account, CoMap, co, Group, WasmCrypto } from "../index.js";
|
3
|
+
const Crypto = await WasmCrypto.create();
|
11
4
|
describe("Custom accounts and groups", async () => {
|
12
5
|
var _a;
|
13
6
|
class CustomProfile extends CoMap {
|
@@ -46,6 +39,7 @@ describe("Custom accounts and groups", async () => {
|
|
46
39
|
test("Custom account and group", async () => {
|
47
40
|
const me = await CustomAccount.create({
|
48
41
|
creationProps: { name: "Hermes Puggington" },
|
42
|
+
crypto: Crypto,
|
49
43
|
});
|
50
44
|
expect(me.profile).toBeDefined();
|
51
45
|
expect(me.profile?.name).toBe("Hermes Puggington");
|
@@ -58,7 +52,7 @@ describe("Custom accounts and groups", async () => {
|
|
58
52
|
]);
|
59
53
|
expect(group.nMembers).toBe(2);
|
60
54
|
await new Promise((resolve) => {
|
61
|
-
|
55
|
+
CustomGroup.subscribe(group, {}, (update) => {
|
62
56
|
const meAsMember = update.members.find((member) => {
|
63
57
|
return member.id === me.id && member.account?.profile;
|
64
58
|
});
|
@@ -81,6 +75,7 @@ describe("Custom accounts and groups", async () => {
|
|
81
75
|
.members.find((member) => member.id === me.id);
|
82
76
|
expect(meAsCastMember?.account?.profile?.name).toBe("Hermes Puggington");
|
83
77
|
expect(meAsCastMember?.account?.profile?.color).toBe("blue");
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
84
79
|
expect(map._owner.nMembers).toBeUndefined();
|
85
80
|
expect(map._owner.as(CustomGroup).nMembers).toBe(2);
|
86
81
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"groupsAndAccounts.test.js","sourceRoot":"","sources":["../../src/tests/groupsAndAccounts.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,
|
1
|
+
{"version":3,"file":"groupsAndAccounts.test.js","sourceRoot":"","sources":["../../src/tests/groupsAndAccounts.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;AAEzC,QAAQ,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;;IAC9C,MAAM,aAAc,SAAQ,KAAK;QAAjC;;YACI,SAAI,GAAG,EAAE,CAAC,MAAM,CAAC;YACjB,UAAK,GAAG,EAAE,CAAC,MAAM,CAAC;QACtB,CAAC;KAAA;IAED,MAAM,aAAc,SAAQ,OAAO;QAAnC;;YACI,YAAO,GAAG,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAChC,SAAI,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAYzB,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AK,EAAE,KAAK,EAAE,CAAC,CAAC;QAE7D,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM;aAC5B,EAAE,CAAC,WAAW,CAAC;aACf,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QACnD,MAAM,CAAC,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,CAC/C,mBAAmB,CACtB,CAAC;QACF,MAAM,CAAC,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE7D,8DAA8D;QAC9D,MAAM,CAAE,GAAG,CAAC,MAAc,CAAC,QAAQ,CAAC,CAAC,aAAa,EAAE,CAAC;QACrD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
"types": "./src/index.ts",
|
6
6
|
"type": "module",
|
7
7
|
"license": "MIT",
|
8
|
-
"version": "0.7.0-alpha.
|
8
|
+
"version": "0.7.0-alpha.38",
|
9
9
|
"dependencies": {
|
10
10
|
"@effect/schema": "^0.66.16",
|
11
|
-
"effect": "^3.1.
|
11
|
+
"effect": "^3.1.5",
|
12
12
|
"fast-check": "^3.17.2",
|
13
|
-
"cojson
|
14
|
-
"cojson": "0.7.0-alpha.
|
13
|
+
"cojson": "0.7.0-alpha.38",
|
14
|
+
"cojson-transport-nodejs-ws": "0.7.0-alpha.38"
|
15
15
|
},
|
16
16
|
"devDependencies": {
|
17
17
|
"typescript": "^5.3.3",
|
@@ -24,9 +24,15 @@
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
},
|
27
|
+
"lint-staged": {
|
28
|
+
"*.{ts,tsx}": "eslint --fix",
|
29
|
+
"*.{js,jsx,mdx,json}": "prettier --write"
|
30
|
+
},
|
27
31
|
"scripts": {
|
28
|
-
"test": "vitest",
|
29
|
-
"
|
32
|
+
"test": "vitest --run",
|
33
|
+
"test-watch": "vitest",
|
34
|
+
"lint": "eslint . --ext ts,tsx",
|
35
|
+
"format": "prettier --write './src/**/*.{ts,tsx}'",
|
30
36
|
"build": "npm run lint && rm -rf ./dist && tsc --sourceMap --outDir dist"
|
31
37
|
}
|
32
38
|
}
|
package/src/coValues/account.ts
CHANGED
@@ -2,6 +2,7 @@ import { LocalNode } from "cojson";
|
|
2
2
|
import type {
|
3
3
|
AgentSecret,
|
4
4
|
CoID,
|
5
|
+
CryptoProvider,
|
5
6
|
InviteSecret,
|
6
7
|
Peer,
|
7
8
|
RawAccount,
|
@@ -19,7 +20,7 @@ import type {
|
|
19
20
|
ID,
|
20
21
|
RefEncoded,
|
21
22
|
ClassOf,
|
22
|
-
|
23
|
+
RefIfCoValue,
|
23
24
|
} from "../internal.js";
|
24
25
|
import {
|
25
26
|
Group,
|
@@ -31,7 +32,6 @@ import {
|
|
31
32
|
inspect,
|
32
33
|
subscriptionsScopes,
|
33
34
|
} from "../internal.js";
|
34
|
-
import type { Stream } from "effect/Stream";
|
35
35
|
|
36
36
|
/** @category Identity & Permissions */
|
37
37
|
export class Account
|
@@ -42,6 +42,7 @@ export class Account
|
|
42
42
|
declare _type: "Account";
|
43
43
|
declare _raw: RawAccount | RawControlledAccount;
|
44
44
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
45
46
|
static _schema: any;
|
46
47
|
get _schema(): {
|
47
48
|
profile: Schema;
|
@@ -53,15 +54,16 @@ export class Account
|
|
53
54
|
this._schema = {
|
54
55
|
profile: () => Profile satisfies Schema,
|
55
56
|
root: "json" satisfies Schema,
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
56
58
|
} as any;
|
57
59
|
}
|
58
60
|
|
59
61
|
get _owner(): Account {
|
60
62
|
return this as Account;
|
61
63
|
}
|
62
|
-
get _loadedAs(): Account
|
64
|
+
get _loadedAs(): Account {
|
63
65
|
return this.isMe
|
64
|
-
?
|
66
|
+
? this
|
65
67
|
: Account.fromNode(this._raw.core.node);
|
66
68
|
}
|
67
69
|
|
@@ -84,10 +86,9 @@ export class Account
|
|
84
86
|
this._loadedAs,
|
85
87
|
this._schema.profile as RefEncoded<
|
86
88
|
NonNullable<this["profile"]> & CoValue
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
: null),
|
89
|
+
>,
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
91
|
+
) as any as RefIfCoValue<this["profile"]>),
|
91
92
|
root:
|
92
93
|
rootID &&
|
93
94
|
(new Ref(
|
@@ -95,10 +96,9 @@ export class Account
|
|
95
96
|
this._loadedAs,
|
96
97
|
this._schema.root as RefEncoded<
|
97
98
|
NonNullable<this["root"]> & CoValue
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
: null),
|
99
|
+
>,
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
101
|
+
) as any as RefIfCoValue<this["root"]>),
|
102
102
|
};
|
103
103
|
}
|
104
104
|
|
@@ -109,7 +109,7 @@ export class Account
|
|
109
109
|
super();
|
110
110
|
if (!("fromRaw" in options)) {
|
111
111
|
throw new Error(
|
112
|
-
"Can only construct account from raw or with .create()"
|
112
|
+
"Can only construct account from raw or with .create()",
|
113
113
|
);
|
114
114
|
}
|
115
115
|
this.isMe = options.fromRaw.id == options.fromRaw.core.node.account.id;
|
@@ -124,13 +124,13 @@ export class Account
|
|
124
124
|
});
|
125
125
|
|
126
126
|
if (this.isMe) {
|
127
|
-
|
127
|
+
this.sessionID =
|
128
128
|
options.fromRaw.core.node.currentSessionID;
|
129
129
|
}
|
130
130
|
|
131
131
|
return new Proxy(
|
132
132
|
this,
|
133
|
-
AccountAndGroupProxyHandler as ProxyHandler<this
|
133
|
+
AccountAndGroupProxyHandler as ProxyHandler<this>,
|
134
134
|
);
|
135
135
|
}
|
136
136
|
|
@@ -140,30 +140,27 @@ export class Account
|
|
140
140
|
}
|
141
141
|
}
|
142
142
|
|
143
|
-
acceptInvite
|
144
|
-
| (<V extends CoValue>(
|
145
|
-
valueID: ID<V>,
|
146
|
-
inviteSecret: InviteSecret,
|
147
|
-
coValueClass: CoValueClass<V>
|
148
|
-
) => Promise<V | undefined>)
|
149
|
-
| undefined = (async <V extends CoValue>(
|
143
|
+
async acceptInvite <V extends CoValue>(
|
150
144
|
valueID: ID<V>,
|
151
145
|
inviteSecret: InviteSecret,
|
152
|
-
coValueClass: CoValueClass<V
|
153
|
-
)
|
146
|
+
coValueClass: CoValueClass<V>,
|
147
|
+
) {
|
154
148
|
if (!this.isMe) {
|
155
149
|
throw new Error("Only a controlled account can accept invites");
|
156
150
|
}
|
157
151
|
|
158
152
|
await (this._raw as RawControlledAccount).acceptInvite(
|
159
153
|
valueID as unknown as CoID<RawCoValue>,
|
160
|
-
inviteSecret
|
154
|
+
inviteSecret,
|
161
155
|
);
|
162
156
|
|
163
|
-
return coValueClass.load(
|
164
|
-
|
165
|
-
|
166
|
-
|
157
|
+
return coValueClass.load(
|
158
|
+
valueID,
|
159
|
+
this as Account,
|
160
|
+
[],
|
161
|
+
);
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
163
|
+
}
|
167
164
|
|
168
165
|
static async create<A extends Account>(
|
169
166
|
this: ClassOf<A> & typeof Account,
|
@@ -171,20 +168,21 @@ export class Account
|
|
171
168
|
creationProps: { name: string };
|
172
169
|
initialAgentSecret?: AgentSecret;
|
173
170
|
peersToLoadFrom?: Peer[];
|
174
|
-
|
175
|
-
|
171
|
+
crypto: CryptoProvider;
|
172
|
+
},
|
173
|
+
): Promise<A> {
|
176
174
|
const { node } = await LocalNode.withNewlyCreatedAccount({
|
177
175
|
...options,
|
178
176
|
migration: async (rawAccount, _node, creationProps) => {
|
179
177
|
const account = new this({
|
180
178
|
fromRaw: rawAccount,
|
181
|
-
}) as A
|
179
|
+
}) as A;
|
182
180
|
|
183
181
|
await account.migrate?.(creationProps);
|
184
182
|
},
|
185
183
|
});
|
186
184
|
|
187
|
-
return this.fromNode(node) as A
|
185
|
+
return this.fromNode(node) as A;
|
188
186
|
}
|
189
187
|
|
190
188
|
static async become<A extends Account>(
|
@@ -194,34 +192,37 @@ export class Account
|
|
194
192
|
accountSecret: AgentSecret;
|
195
193
|
sessionID: SessionID;
|
196
194
|
peersToLoadFrom: Peer[];
|
197
|
-
|
198
|
-
|
195
|
+
crypto: CryptoProvider;
|
196
|
+
},
|
197
|
+
): Promise<A> {
|
199
198
|
const node = await LocalNode.withLoadedAccount({
|
200
199
|
accountID: options.accountID as unknown as CoID<RawAccount>,
|
201
200
|
accountSecret: options.accountSecret,
|
202
201
|
sessionID: options.sessionID,
|
203
202
|
peersToLoadFrom: options.peersToLoadFrom,
|
203
|
+
crypto: options.crypto,
|
204
204
|
migration: async (rawAccount, _node, creationProps) => {
|
205
205
|
const account = new this({
|
206
206
|
fromRaw: rawAccount,
|
207
|
-
}) as A
|
207
|
+
}) as A;
|
208
208
|
|
209
209
|
await account.migrate?.(creationProps);
|
210
210
|
},
|
211
211
|
});
|
212
212
|
|
213
|
-
return this.fromNode(node) as A
|
213
|
+
return this.fromNode(node) as A;
|
214
214
|
}
|
215
215
|
|
216
216
|
static fromNode<A extends Account>(
|
217
217
|
this: ClassOf<A>,
|
218
|
-
node: LocalNode
|
219
|
-
): A
|
218
|
+
node: LocalNode,
|
219
|
+
): A {
|
220
220
|
return new this({
|
221
221
|
fromRaw: node.account as RawControlledAccount,
|
222
|
-
}) as A
|
222
|
+
}) as A;
|
223
223
|
}
|
224
224
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
225
226
|
toJSON(): object | any[] {
|
226
227
|
return {
|
227
228
|
id: this.id,
|
@@ -239,7 +240,7 @@ export class Account
|
|
239
240
|
profileGroup.addMember("everyone", "reader");
|
240
241
|
this.profile = Profile.create(
|
241
242
|
{ name: creationProps.name },
|
242
|
-
{ owner: profileGroup }
|
243
|
+
{ owner: profileGroup },
|
243
244
|
);
|
244
245
|
}
|
245
246
|
}
|
@@ -249,9 +250,13 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
249
250
|
get(target, key, receiver) {
|
250
251
|
if (key === "profile") {
|
251
252
|
const ref = target._refs.profile;
|
252
|
-
return ref
|
253
|
+
return ref
|
254
|
+
? ref.accessFrom(receiver, "profile")
|
255
|
+
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
256
|
+
(undefined as any);
|
253
257
|
} else if (key === "root") {
|
254
258
|
const ref = target._refs.root;
|
259
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
255
260
|
return ref ? ref.accessFrom(receiver, "root") : (undefined as any);
|
256
261
|
} else {
|
257
262
|
return Reflect.get(target, key, receiver);
|
@@ -272,16 +277,20 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
272
277
|
target._raw.set(
|
273
278
|
"profile",
|
274
279
|
value.id as unknown as CoID<RawCoMap>,
|
275
|
-
"trusting"
|
280
|
+
"trusting",
|
276
281
|
);
|
277
282
|
}
|
278
|
-
subscriptionsScopes
|
283
|
+
subscriptionsScopes
|
284
|
+
.get(receiver)
|
285
|
+
?.onRefAccessedOrSet(target.id, value.id);
|
279
286
|
return true;
|
280
287
|
} else if (key === "root") {
|
281
288
|
if (value) {
|
282
289
|
target._raw.set("root", value.id as unknown as CoID<RawCoMap>);
|
283
290
|
}
|
284
|
-
subscriptionsScopes
|
291
|
+
subscriptionsScopes
|
292
|
+
.get(receiver)
|
293
|
+
?.onRefAccessedOrSet(target.id, value.id);
|
285
294
|
return true;
|
286
295
|
} else {
|
287
296
|
return Reflect.set(target, key, value, receiver);
|
@@ -303,24 +312,17 @@ export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
|
303
312
|
},
|
304
313
|
};
|
305
314
|
|
306
|
-
/** @category Identity & Permissions */
|
307
|
-
export interface Me {
|
308
|
-
id: ID<any>;
|
309
|
-
isMe: true;
|
310
|
-
_raw: RawControlledAccount;
|
311
|
-
sessionID: SessionID;
|
312
|
-
subscribe(listener: (update: this & Me) => void): () => void;
|
313
|
-
subscribeEf(): Stream<this & Me, UnavailableError, never>;
|
314
|
-
acceptInvite: (...args: any[]) => any;
|
315
|
-
}
|
316
|
-
|
317
315
|
/** @category Identity & Permissions */
|
318
316
|
export class AccountCtx extends Context.Tag("Account")<
|
319
317
|
AccountCtx,
|
320
|
-
Account
|
318
|
+
Account
|
321
319
|
>() {}
|
322
320
|
|
323
321
|
/** @category Identity & Permissions */
|
324
|
-
export function isControlledAccount(account: Account): account is Account &
|
322
|
+
export function isControlledAccount(account: Account): account is Account & {
|
323
|
+
isMe: true;
|
324
|
+
sessionID: SessionID;
|
325
|
+
_raw: RawControlledAccount;
|
326
|
+
} {
|
325
327
|
return account.isMe;
|
326
328
|
}
|