jazz-tools 0.7.0-alpha.3 → 0.7.0-alpha.30
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +80 -8
- package/CHANGELOG.md +175 -0
- package/dist/coValues/account.js +78 -38
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +150 -99
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +178 -162
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +195 -70
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +13 -8
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +40 -36
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +22 -4
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/refs.js +26 -12
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +38 -1
- 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/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +20 -24
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +154 -43
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +50 -55
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +86 -0
- package/dist/tests/groupsAndAccounts.test.js.map +1 -0
- package/package.json +5 -4
- package/src/coValues/account.ts +116 -75
- package/src/coValues/coList.ts +189 -125
- package/src/coValues/coMap.ts +238 -295
- package/src/coValues/coStream.ts +282 -124
- package/src/coValues/extensions/imageDef.ts +13 -15
- package/src/coValues/group.ts +85 -85
- package/src/coValues/interfaces.ts +32 -11
- package/src/implementation/refs.ts +42 -25
- package/src/implementation/schema.ts +68 -46
- package/src/implementation/symbols.ts +12 -0
- package/src/index.ts +10 -8
- package/src/internal.ts +1 -0
- package/src/tests/coList.test.ts +20 -24
- package/src/tests/coMap.test.ts +153 -58
- package/src/tests/coStream.test.ts +65 -70
- package/src/tests/groupsAndAccounts.test.ts +96 -0
@@ -1,105 +1,79 @@
|
|
1
1
|
var _a;
|
2
2
|
import { cojsonInternals } from "cojson";
|
3
|
-
import { Account, CoValueBase,
|
4
|
-
import {
|
3
|
+
import { ItemsSym, Account, CoValueBase, Ref, inspect, co, InitValues, SchemaInit, isRefEncoded, } from "../internal.js";
|
4
|
+
import { encodeSync, decodeSync } from "@effect/schema/Schema";
|
5
5
|
export class CoStream extends CoValueBase {
|
6
|
-
|
7
|
-
|
6
|
+
static Of(item) {
|
7
|
+
var _b, _c;
|
8
|
+
return _c = class CoStreamOf extends _a {
|
9
|
+
constructor() {
|
10
|
+
super(...arguments);
|
11
|
+
this[_b] = item;
|
12
|
+
}
|
13
|
+
},
|
14
|
+
_b = co.items,
|
15
|
+
_c;
|
16
|
+
}
|
17
|
+
get _schema() {
|
18
|
+
return this.constructor._schema;
|
8
19
|
}
|
9
20
|
get byMe() {
|
10
|
-
return this
|
21
|
+
return this[this._loadedAs.id];
|
11
22
|
}
|
12
23
|
get inCurrentSession() {
|
13
|
-
return this.
|
24
|
+
return this.perSession[this._loadedAs.sessionID];
|
14
25
|
}
|
15
26
|
constructor(init, options) {
|
16
27
|
super();
|
17
|
-
this.by = {};
|
18
|
-
this.in = {};
|
19
|
-
let raw;
|
20
28
|
if ("fromRaw" in options) {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
raw = rawOwner.createStream();
|
26
|
-
}
|
27
|
-
Object.defineProperties(this, {
|
28
|
-
id: {
|
29
|
-
value: raw.id,
|
30
|
-
enumerable: false,
|
31
|
-
},
|
32
|
-
_raw: { value: raw, enumerable: false },
|
33
|
-
});
|
34
|
-
if (init !== undefined) {
|
35
|
-
for (const item of init) {
|
36
|
-
this.pushItem(item);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
this.updateEntries();
|
40
|
-
}
|
41
|
-
updateEntries() {
|
42
|
-
for (const accountID of this._raw.accounts()) {
|
43
|
-
Object.defineProperty(this.by, accountID, {
|
44
|
-
get: () => {
|
45
|
-
const rawEntry = this._raw.lastItemBy(accountID);
|
46
|
-
if (!rawEntry)
|
47
|
-
return;
|
48
|
-
return entryFromRawEntry(this, rawEntry, this._loadedAs, accountID, this._encoding._item);
|
29
|
+
Object.defineProperties(this, {
|
30
|
+
id: {
|
31
|
+
value: options.fromRaw.id,
|
32
|
+
enumerable: false,
|
49
33
|
},
|
50
|
-
|
51
|
-
enumerable: true,
|
34
|
+
_raw: { value: options.fromRaw, enumerable: false },
|
52
35
|
});
|
53
36
|
}
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
return;
|
60
|
-
const by = cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
|
61
|
-
return entryFromRawEntry(this, rawEntry, this._loadedAs, cojsonInternals.isAccountID(by)
|
62
|
-
? by
|
63
|
-
: undefined, this._encoding._item);
|
64
|
-
},
|
65
|
-
configurable: true,
|
66
|
-
enumerable: true,
|
67
|
-
});
|
37
|
+
else {
|
38
|
+
this[InitValues] = {
|
39
|
+
init,
|
40
|
+
owner: options.owner,
|
41
|
+
};
|
68
42
|
}
|
43
|
+
return new Proxy(this, CoStreamProxyHandler);
|
69
44
|
}
|
70
45
|
push(...items) {
|
71
46
|
for (const item of items) {
|
72
47
|
this.pushItem(item);
|
73
48
|
}
|
74
|
-
this.updateEntries();
|
75
49
|
}
|
76
50
|
pushItem(item) {
|
77
|
-
const itemDescriptor = this.
|
51
|
+
const itemDescriptor = this._schema[ItemsSym];
|
78
52
|
if (itemDescriptor === "json") {
|
79
53
|
this._raw.push(item);
|
80
54
|
}
|
81
55
|
else if ("encoded" in itemDescriptor) {
|
82
|
-
this._raw.push(
|
56
|
+
this._raw.push(encodeSync(itemDescriptor.encoded)(item));
|
83
57
|
}
|
84
|
-
else if (
|
58
|
+
else if (isRefEncoded(itemDescriptor)) {
|
85
59
|
this._raw.push(item.id);
|
86
60
|
}
|
87
61
|
}
|
88
62
|
toJSON() {
|
89
|
-
const itemDescriptor = this.
|
63
|
+
const itemDescriptor = this._schema[ItemsSym];
|
90
64
|
const mapper = itemDescriptor === "json"
|
91
65
|
? (v) => v
|
92
66
|
: "encoded" in itemDescriptor
|
93
|
-
?
|
67
|
+
? encodeSync(itemDescriptor.encoded)
|
94
68
|
: (v) => v && v.id;
|
95
69
|
return {
|
96
70
|
id: this.id,
|
97
71
|
_type: this._type,
|
98
|
-
|
72
|
+
...Object.fromEntries(Object.entries(this).map(([account, entry]) => [
|
99
73
|
account,
|
100
74
|
mapper(entry.value),
|
101
75
|
])),
|
102
|
-
in: Object.fromEntries(Object.entries(this.
|
76
|
+
in: Object.fromEntries(Object.entries(this.perSession).map(([session, entry]) => [
|
103
77
|
session,
|
104
78
|
mapper(entry.value),
|
105
79
|
])),
|
@@ -108,9 +82,9 @@ export class CoStream extends CoValueBase {
|
|
108
82
|
[inspect]() {
|
109
83
|
return this.toJSON();
|
110
84
|
}
|
111
|
-
static
|
112
|
-
this.
|
113
|
-
Object.assign(this.
|
85
|
+
static schema(def) {
|
86
|
+
this._schema || (this._schema = {});
|
87
|
+
Object.assign(this._schema, def);
|
114
88
|
}
|
115
89
|
}
|
116
90
|
_a = CoStream;
|
@@ -124,28 +98,179 @@ function entryFromRawEntry(accessFrom, rawEntry, loadedAs, accountID, itemField)
|
|
124
98
|
return rawEntry.value;
|
125
99
|
}
|
126
100
|
else if ("encoded" in itemField) {
|
127
|
-
return
|
101
|
+
return decodeSync(itemField.encoded)(rawEntry.value);
|
128
102
|
}
|
129
|
-
else if (
|
103
|
+
else if (isRefEncoded(itemField)) {
|
130
104
|
return this.ref?.accessFrom(accessFrom);
|
131
105
|
}
|
106
|
+
else {
|
107
|
+
throw new Error("Invalid item field schema");
|
108
|
+
}
|
132
109
|
},
|
133
110
|
get ref() {
|
134
|
-
if (itemField !== "json" &&
|
111
|
+
if (itemField !== "json" && isRefEncoded(itemField)) {
|
135
112
|
const rawId = rawEntry.value;
|
136
|
-
return new
|
113
|
+
return new Ref(rawId, loadedAs, itemField);
|
114
|
+
}
|
115
|
+
else {
|
116
|
+
return undefined;
|
137
117
|
}
|
138
118
|
},
|
139
119
|
get by() {
|
140
120
|
return (accountID &&
|
141
|
-
new
|
121
|
+
new Ref(accountID, loadedAs, Account)?.accessFrom(accessFrom));
|
142
122
|
},
|
143
123
|
madeAt: rawEntry.at,
|
144
124
|
tx: rawEntry.tx,
|
145
125
|
};
|
146
126
|
}
|
127
|
+
function init(stream) {
|
128
|
+
const init = stream[InitValues];
|
129
|
+
if (!init)
|
130
|
+
return;
|
131
|
+
const raw = init.owner._raw.createStream();
|
132
|
+
Object.defineProperties(stream, {
|
133
|
+
id: {
|
134
|
+
value: raw.id,
|
135
|
+
enumerable: false,
|
136
|
+
},
|
137
|
+
_raw: { value: raw, enumerable: false },
|
138
|
+
});
|
139
|
+
if (init.init) {
|
140
|
+
stream.push(...init.init);
|
141
|
+
}
|
142
|
+
delete stream[InitValues];
|
143
|
+
}
|
144
|
+
export const CoStreamProxyHandler = {
|
145
|
+
get(target, key, receiver) {
|
146
|
+
if (typeof key === "string" && key.startsWith("co_")) {
|
147
|
+
const rawEntry = target._raw.lastItemBy(key);
|
148
|
+
if (!rawEntry)
|
149
|
+
return;
|
150
|
+
const entry = entryFromRawEntry(receiver, rawEntry, target._loadedAs, key, target._schema[ItemsSym]);
|
151
|
+
Object.defineProperty(entry, "all", {
|
152
|
+
get: () => {
|
153
|
+
const allRawEntries = target._raw.itemsBy(key);
|
154
|
+
return (function* () {
|
155
|
+
while (true) {
|
156
|
+
const rawEntry = allRawEntries.next();
|
157
|
+
if (rawEntry.done)
|
158
|
+
return;
|
159
|
+
yield entryFromRawEntry(receiver, rawEntry.value, target._loadedAs, key, target._schema[ItemsSym]);
|
160
|
+
}
|
161
|
+
})();
|
162
|
+
},
|
163
|
+
});
|
164
|
+
return entry;
|
165
|
+
}
|
166
|
+
else if (key === "perSession") {
|
167
|
+
return new Proxy({}, CoStreamPerSessionProxyHandler(target, receiver));
|
168
|
+
}
|
169
|
+
else {
|
170
|
+
return Reflect.get(target, key, receiver);
|
171
|
+
}
|
172
|
+
},
|
173
|
+
set(target, key, value, receiver) {
|
174
|
+
var _b;
|
175
|
+
if (key === ItemsSym &&
|
176
|
+
typeof value === "object" &&
|
177
|
+
SchemaInit in value) {
|
178
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
179
|
+
target.constructor._schema[ItemsSym] =
|
180
|
+
value[SchemaInit];
|
181
|
+
init(target);
|
182
|
+
return true;
|
183
|
+
}
|
184
|
+
else {
|
185
|
+
return Reflect.set(target, key, value, receiver);
|
186
|
+
}
|
187
|
+
},
|
188
|
+
defineProperty(target, key, descriptor) {
|
189
|
+
var _b;
|
190
|
+
if (descriptor.value &&
|
191
|
+
key === ItemsSym &&
|
192
|
+
typeof descriptor.value === "object" &&
|
193
|
+
SchemaInit in descriptor.value) {
|
194
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
195
|
+
target.constructor._schema[ItemsSym] =
|
196
|
+
descriptor.value[SchemaInit];
|
197
|
+
init(target);
|
198
|
+
return true;
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
return Reflect.defineProperty(target, key, descriptor);
|
202
|
+
}
|
203
|
+
},
|
204
|
+
ownKeys(target) {
|
205
|
+
const keys = Reflect.ownKeys(target);
|
206
|
+
for (const accountID of target._raw.accounts()) {
|
207
|
+
keys.push(accountID);
|
208
|
+
}
|
209
|
+
return keys;
|
210
|
+
},
|
211
|
+
getOwnPropertyDescriptor(target, key) {
|
212
|
+
if (typeof key === "string" && key.startsWith("co_")) {
|
213
|
+
return {
|
214
|
+
configurable: true,
|
215
|
+
enumerable: true,
|
216
|
+
writable: false,
|
217
|
+
};
|
218
|
+
}
|
219
|
+
else {
|
220
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
221
|
+
}
|
222
|
+
},
|
223
|
+
};
|
224
|
+
const CoStreamPerSessionProxyHandler = (innerTarget, accessFrom) => ({
|
225
|
+
get(_target, key, receiver) {
|
226
|
+
if (typeof key === "string" && key.includes("session")) {
|
227
|
+
const sessionID = key;
|
228
|
+
const rawEntry = innerTarget._raw.lastItemIn(sessionID);
|
229
|
+
if (!rawEntry)
|
230
|
+
return;
|
231
|
+
const by = cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
|
232
|
+
const entry = entryFromRawEntry(accessFrom, rawEntry, innerTarget._loadedAs, cojsonInternals.isAccountID(by)
|
233
|
+
? by
|
234
|
+
: undefined, innerTarget._schema[ItemsSym]);
|
235
|
+
Object.defineProperty(entry, "all", {
|
236
|
+
get: () => {
|
237
|
+
const allRawEntries = innerTarget._raw.itemsIn(sessionID);
|
238
|
+
return (function* () {
|
239
|
+
while (true) {
|
240
|
+
const rawEntry = allRawEntries.next();
|
241
|
+
if (rawEntry.done)
|
242
|
+
return;
|
243
|
+
yield entryFromRawEntry(accessFrom, rawEntry.value, innerTarget._loadedAs, cojsonInternals.isAccountID(by)
|
244
|
+
? by
|
245
|
+
: undefined, innerTarget._schema[ItemsSym]);
|
246
|
+
}
|
247
|
+
})();
|
248
|
+
},
|
249
|
+
});
|
250
|
+
return entry;
|
251
|
+
}
|
252
|
+
else {
|
253
|
+
return Reflect.get(innerTarget, key, receiver);
|
254
|
+
}
|
255
|
+
},
|
256
|
+
ownKeys() {
|
257
|
+
return innerTarget._raw.sessions();
|
258
|
+
},
|
259
|
+
getOwnPropertyDescriptor(target, key) {
|
260
|
+
if (typeof key === "string" && key.startsWith("co_")) {
|
261
|
+
return {
|
262
|
+
configurable: true,
|
263
|
+
enumerable: true,
|
264
|
+
writable: false,
|
265
|
+
};
|
266
|
+
}
|
267
|
+
else {
|
268
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
269
|
+
}
|
270
|
+
},
|
271
|
+
});
|
147
272
|
export class BinaryCoStream extends CoValueBase {
|
148
|
-
constructor(
|
273
|
+
constructor(_init, options) {
|
149
274
|
super();
|
150
275
|
let raw;
|
151
276
|
if ("fromRaw" in options) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"coStream.js","sourceRoot":"","sources":["../../src/coValues/coStream.ts"],"names":[],"mappings":";AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAUzC,OAAO,
|
1
|
+
{"version":3,"file":"coStream.js","sourceRoot":"","sources":["../../src/coValues/coStream.ts"],"names":[],"mappings":";AAUA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAUzC,OAAO,EACH,QAAQ,EACR,OAAO,EACP,WAAW,EACX,GAAG,EACH,OAAO,EACP,EAAE,EACF,UAAU,EACV,UAAU,EACV,YAAY,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAc/D,MAAM,OAAO,QACT,SAAQ,WAAW;IAGnB,MAAM,CAAC,EAAE,CACL,IAAsB;;QAEtB,YAAO,MAAM,UAAW,SAAQ,EAAc;gBAAvC;;oBACH,QAAU,GAAG,IAAI,CAAC;gBACtB,CAAC;aAAA;iBADI,EAAE,CAAC,KAAK;eACX;IACN,CAAC;IAYD,IAAI,OAAO;QAGP,OAAQ,IAAI,CAAC,WAA+B,CAAC,OAAO,CAAC;IACzD,CAAC;IAID,IAAI,IAAI;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAID,IAAI,gBAAgB;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAMD,YACI,IAAwB,EACxB,OAA8D;QAE9D,KAAK,EAAE,CAAC;QAER,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;YACvB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;gBAC1B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I,CAAC,eAAe,EAAE,CAAC;IAChC,CAAC;IAED,MAAM;QACF,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,GAAG,IAAI,CAAC,SAAS,EAAE;SACtB,CAAC;IACN,CAAC;IAED,CAAC,OAAO,CAAC;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;CACJ"}
|
@@ -1,10 +1,19 @@
|
|
1
|
-
|
1
|
+
var _a;
|
2
|
+
import { BinaryCoStream, CoMap, co, subscriptionsScopes, } from "../../internal.js";
|
2
3
|
export class ImageDefinition extends CoMap {
|
3
|
-
|
4
|
+
constructor() {
|
5
|
+
super(...arguments);
|
6
|
+
this.originalSize = co.json();
|
7
|
+
this.placeholderDataURL = co.string;
|
8
|
+
this[_a] = co.ref(BinaryCoStream);
|
9
|
+
}
|
10
|
+
highestResAvailable(options) {
|
4
11
|
if (!subscriptionsScopes.get(this)) {
|
5
12
|
console.warn("highestResAvailable() only makes sense when used within a subscription.");
|
6
13
|
}
|
7
|
-
const resolutions = Object.keys(this).filter((key) => key.match(/^\d+x\d+$/)
|
14
|
+
const resolutions = Object.keys(this).filter((key) => key.match(/^\d+x\d+$/) &&
|
15
|
+
(!options?.maxWidth ||
|
16
|
+
Number(key.split("x")[0]) <= options.maxWidth));
|
8
17
|
resolutions.sort((a, b) => {
|
9
18
|
const aWidth = Number(a.split("x")[0]);
|
10
19
|
const bWidth = Number(b.split("x")[0]);
|
@@ -28,9 +37,5 @@ export class ImageDefinition extends CoMap {
|
|
28
37
|
});
|
29
38
|
}
|
30
39
|
}
|
31
|
-
|
32
|
-
originalSize: "json",
|
33
|
-
placeholderDataURL: "json",
|
34
|
-
[indexSignature]: { ref: () => BinaryCoStream },
|
35
|
-
});
|
40
|
+
_a = co.items;
|
36
41
|
//# sourceMappingURL=imageDef.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"imageDef.js","sourceRoot":"","sources":["../../../src/coValues/extensions/imageDef.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,KAAK,EACL,
|
1
|
+
{"version":3,"file":"imageDef.js","sourceRoot":"","sources":["../../../src/coValues/extensions/imageDef.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,cAAc,EACd,KAAK,EACL,EAAE,EACF,mBAAmB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,OAAO,eAAgB,SAAQ,KAAsB;IAA3D;;QACI,iBAAY,GAAG,EAAE,CAAC,IAAI,EAAoB,CAAC;QAC3C,uBAAkB,GAAI,EAAE,CAAC,MAAM,CAAC;QAEhC,QAAU,GAAG,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IA8CxC,CAAC;IA3CG,mBAAmB,CAAC,OAEnB;QACG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CACR,yEAAyE,CAC5E,CAAC;QACN,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CACxC,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC;YACtB,CAAC,CAAC,OAAO,EAAE,QAAQ;gBACf,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAC9B,CAAC;QAE7B,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACtB,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACvC,OAAO,MAAM,GAAG,MAAM,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,IAAI,0BAA6D,CAAC;QAElE,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,EAAE,CAAC;gBACpD,0BAA0B,GAAG,UAAU,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACJ,OAAO,CACH,0BAA0B,IAAI;oBAC1B,GAAG,EAAE,0BAA0B;oBAC/B,MAAM,EAAE,IAAI,CAAC,0BAA0B,CAAE;iBAC5C,CACJ,CAAC;YACN,CAAC;QACL,CAAC;QACD,OAAO,CACH,0BAA0B,IAAI;YAC1B,GAAG,EAAE,0BAA0B;YAC/B,MAAM,EAAE,IAAI,CAAC,0BAA0B,CAAE;SAC5C,CACJ,CAAC;IACN,CAAC;CACJ;KA9CI,EAAE,CAAC,KAAK"}
|
package/dist/coValues/group.js
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
var _a;
|
2
|
-
import { Account, CoMap, CoValueBase,
|
2
|
+
import { Account, CoMap, CoValueBase, Ref, co, isControlledAccount, AccountAndGroupProxyHandler, MembersSym, } from "../internal.js";
|
3
3
|
export class Profile extends CoMap {
|
4
|
+
constructor() {
|
5
|
+
super(...arguments);
|
6
|
+
this.name = co.string;
|
7
|
+
}
|
4
8
|
}
|
5
|
-
Profile.encoding({ name: "json" });
|
6
9
|
export class Group extends CoValueBase {
|
7
|
-
get
|
8
|
-
return this.constructor.
|
10
|
+
get _schema() {
|
11
|
+
return this.constructor._schema;
|
9
12
|
}
|
10
13
|
get _refs() {
|
11
14
|
const profileID = this._raw.get("profile");
|
12
15
|
const rootID = this._raw.get("root");
|
13
16
|
return {
|
14
17
|
profile: profileID &&
|
15
|
-
new
|
18
|
+
new Ref(profileID, this._loadedAs, this._schema.profile),
|
16
19
|
root: rootID &&
|
17
|
-
new
|
20
|
+
new Ref(rootID, this._loadedAs, this._schema.root),
|
18
21
|
};
|
19
22
|
}
|
20
23
|
constructor(init, options) {
|
@@ -42,39 +45,39 @@ export class Group extends CoValueBase {
|
|
42
45
|
enumerable: false,
|
43
46
|
},
|
44
47
|
_raw: { value: raw, enumerable: false },
|
45
|
-
profile: {
|
46
|
-
get: () => {
|
47
|
-
const ref = this._refs.profile;
|
48
|
-
return ref ? ref.accessFrom(this) : undefined;
|
49
|
-
},
|
50
|
-
set: (value) => {
|
51
|
-
if (value) {
|
52
|
-
this._raw.set("profile", value.id);
|
53
|
-
}
|
54
|
-
},
|
55
|
-
},
|
56
|
-
root: {
|
57
|
-
get: () => {
|
58
|
-
const ref = this._refs.root;
|
59
|
-
return ref ? ref.accessFrom(this) : undefined;
|
60
|
-
},
|
61
|
-
set: (value) => {
|
62
|
-
if (value) {
|
63
|
-
this._raw.set("root", value.id);
|
64
|
-
}
|
65
|
-
},
|
66
|
-
},
|
67
48
|
});
|
49
|
+
return new Proxy(this, AccountAndGroupProxyHandler);
|
68
50
|
}
|
69
51
|
myRole() {
|
70
52
|
return this._raw.myRole();
|
71
53
|
}
|
72
54
|
addMember(member, role) {
|
73
55
|
this._raw.addMember(member === "everyone" ? member : member._raw, role);
|
56
|
+
return this;
|
74
57
|
}
|
75
|
-
|
76
|
-
|
77
|
-
|
58
|
+
get members() {
|
59
|
+
return this._raw
|
60
|
+
.keys()
|
61
|
+
.filter((key) => {
|
62
|
+
return key === "everyone" || key.startsWith("co_");
|
63
|
+
})
|
64
|
+
.map((id) => {
|
65
|
+
const role = this._raw.get(id);
|
66
|
+
const accountID = id === "everyone"
|
67
|
+
? undefined
|
68
|
+
: id;
|
69
|
+
const ref = accountID &&
|
70
|
+
new Ref(accountID, this._loadedAs, this._schema[MembersSym]);
|
71
|
+
const accessRef = () => ref?.accessFrom(this);
|
72
|
+
return {
|
73
|
+
id: id,
|
74
|
+
role,
|
75
|
+
ref,
|
76
|
+
get account() {
|
77
|
+
return accessRef();
|
78
|
+
},
|
79
|
+
};
|
80
|
+
});
|
78
81
|
}
|
79
82
|
}
|
80
83
|
_a = Group;
|
@@ -82,12 +85,13 @@ _a = Group;
|
|
82
85
|
_a.prototype._type = "Group";
|
83
86
|
})();
|
84
87
|
(() => {
|
85
|
-
_a.
|
86
|
-
profile:
|
87
|
-
root:
|
88
|
+
_a._schema = {
|
89
|
+
profile: "json",
|
90
|
+
root: "json",
|
91
|
+
[MembersSym]: () => Account,
|
88
92
|
};
|
89
|
-
Object.defineProperty(_a.prototype, "
|
90
|
-
get: () => _a.
|
93
|
+
Object.defineProperty(_a.prototype, "_schema", {
|
94
|
+
get: () => _a._schema,
|
91
95
|
});
|
92
96
|
})();
|
93
97
|
//# sourceMappingURL=group.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/coValues/group.ts"],"names":[],"mappings":";AAQA,OAAO,EACH,OAAO,EACP,KAAK,EACL,WAAW,EACX,
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/coValues/group.ts"],"names":[],"mappings":";AAQA,OAAO,EACH,OAAO,EACP,KAAK,EACL,WAAW,EACX,GAAG,EACH,EAAE,EACF,mBAAmB,EACnB,2BAA2B,EAC3B,UAAU,GACb,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,OAAQ,SAAQ,KAA2B;IAAxD;;QACI,SAAI,GAAG,EAAE,CAAC,MAAM,CAAC;IACrB,CAAC;CAAA;AAYD,MAAM,OAAO,KAWT,SAAQ,WAAW;IAWnB,IAAI,OAAO;QACP,OAAQ,IAAI,CAAC,WAA4B,CAAC,OAAO,CAAC;IACtD,CAAC;IAgBD,IAAI,KAAK;QAIL,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAE1B,CAAC;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAEpB,CAAC;QAChB,OAAO;YACH,OAAO,EACH,SAAS;g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wB;KACxC,CAAC;IACT,MAAM,CAAC,cAAc,CAAC,GAAK,SAAS,EAAE,SAAS,EAAE;QAC7C,GAAG,EAAE,GAAG,EAAE,CAAC,GAAK,OAAO;KAC1B,CAAC,CAAC;AACP,CAAC,GAAA,CAAA"}
|
@@ -1,15 +1,25 @@
|
|
1
1
|
import { Effect, Sink, Stream } from "effect";
|
2
2
|
import { RawAccount } from "cojson";
|
3
|
-
import { Account, AccountCtx, Group, SubscriptionScope,
|
3
|
+
import { Account, AccountCtx, Group, SubscriptionScope, Ref, inspect, subscriptionsScopes, } from "../internal.js";
|
4
4
|
export function isCoValue(value) {
|
5
5
|
return value && value._type !== undefined;
|
6
6
|
}
|
7
|
+
export function isCoValueClass(value) {
|
8
|
+
return typeof value === "function" && value.fromRaw !== undefined;
|
9
|
+
}
|
7
10
|
export class CoValueBase {
|
8
11
|
get _owner() {
|
9
|
-
|
12
|
+
const owner = this._raw.group instanceof RawAccount
|
10
13
|
? Account.fromRaw(this._raw.group)
|
11
14
|
: Group.fromRaw(this._raw.group);
|
15
|
+
const subScope = subscriptionsScopes.get(this);
|
16
|
+
if (subScope) {
|
17
|
+
subScope.onRefAccessedOrSet(owner.id);
|
18
|
+
subscriptionsScopes.set(owner, subScope);
|
19
|
+
}
|
20
|
+
return owner;
|
12
21
|
}
|
22
|
+
/** @private */
|
13
23
|
get _loadedAs() {
|
14
24
|
return Account.fromNode(this._raw.core.node);
|
15
25
|
}
|
@@ -20,11 +30,11 @@ export class CoValueBase {
|
|
20
30
|
static loadEf(id) {
|
21
31
|
return Effect.gen(this, function* (_) {
|
22
32
|
const account = yield* _(AccountCtx);
|
23
|
-
return yield* _(new
|
33
|
+
return yield* _(new Ref(id, account, this).loadEf());
|
24
34
|
});
|
25
35
|
}
|
26
36
|
static load(id, options) {
|
27
|
-
return new
|
37
|
+
return new Ref(id, options.as, this).load(options?.onProgress && { onProgress: options.onProgress });
|
28
38
|
}
|
29
39
|
static subscribe(id, options, onUpdate) {
|
30
40
|
void Effect.runPromise(Effect.provideService(this.subscribeEf(id).pipe(Stream.run(Sink.forEach((update) => Effect.sync(() => onUpdate(update))))), AccountCtx, options.as));
|
@@ -54,5 +64,13 @@ export class CoValueBase {
|
|
54
64
|
[inspect]() {
|
55
65
|
return this.toJSON();
|
56
66
|
}
|
67
|
+
as(otherSchema) {
|
68
|
+
const cast = otherSchema.fromRaw(this._raw);
|
69
|
+
const subScope = subscriptionsScopes.get(this);
|
70
|
+
if (subScope) {
|
71
|
+
subscriptionsScopes.set(cast, subScope);
|
72
|
+
}
|
73
|
+
return cast;
|
74
|
+
}
|
57
75
|
}
|
58
76
|
//# sourceMappingURL=interfaces.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/coValues/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACH,OAAO,EACP,UAAU,EACV,KAAK,EACL,iBAAiB,EACjB,
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/coValues/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EACH,OAAO,EACP,UAAU,EACV,KAAK,EACL,iBAAiB,EACjB,GAAG,EACH,OAAO,EACP,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAkExB,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AAC9C,CAAC;AACD,MAAM,UAAU,cAAc,CAAC,KAAU;IACrC,OAAO,OAAO,KAAK,KAAK,UAAU,IAAI,KAAK,CAAC,O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