jazz-tools 0.7.0-alpha.1 → 0.7.0-alpha.12
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +79 -9
- package/CHANGELOG.md +74 -0
- package/dist/coValues/account.js +63 -30
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +143 -93
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +145 -159
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +140 -66
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +9 -11
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +14 -39
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +6 -3
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/refs.js +13 -10
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +36 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/index.js +4 -19
- package/dist/index.js.map +1 -1
- package/dist/tests/coList.test.js +5 -9
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +107 -61
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +51 -56
- package/dist/tests/coStream.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +94 -64
- package/src/coValues/coList.ts +186 -115
- package/src/coValues/coMap.ts +226 -260
- package/src/coValues/coStream.ts +190 -111
- package/src/coValues/extensions/imageDef.ts +12 -16
- package/src/coValues/group.ts +27 -75
- package/src/coValues/interfaces.ts +10 -8
- package/src/implementation/refs.ts +43 -18
- package/src/implementation/schema.ts +86 -31
- package/src/index.ts +10 -25
- package/src/tests/coList.test.ts +5 -9
- package/src/tests/coMap.test.ts +86 -74
- package/src/tests/coStream.test.ts +66 -71
@@ -1,105 +1,79 @@
|
|
1
1
|
var _a;
|
2
2
|
import { cojsonInternals } from "cojson";
|
3
|
-
import { Account, CoValueBase,
|
4
|
-
import { Schema } from "@effect/schema";
|
3
|
+
import { ItemsSym, Account, CoValueBase, Ref, inspect, co, InitValues, SchemaInit, isRefEncoded, } from "../internal.js";
|
4
|
+
import { Schema as EffectSchema } from "@effect/schema";
|
5
5
|
export class CoStream extends CoValueBase {
|
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
|
+
}
|
6
17
|
get _schema() {
|
7
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._schema._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._schema._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._schema
|
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(EffectSchema.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._schema
|
63
|
+
const itemDescriptor = this._schema[ItemsSym];
|
90
64
|
const mapper = itemDescriptor === "json"
|
91
65
|
? (v) => v
|
92
66
|
: "encoded" in itemDescriptor
|
93
|
-
?
|
67
|
+
? EffectSchema.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,7 +82,7 @@ export class CoStream extends CoValueBase {
|
|
108
82
|
[inspect]() {
|
109
83
|
return this.toJSON();
|
110
84
|
}
|
111
|
-
static
|
85
|
+
static schema(def) {
|
112
86
|
this._schema || (this._schema = {});
|
113
87
|
Object.assign(this._schema, def);
|
114
88
|
}
|
@@ -124,28 +98,128 @@ 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 EffectSchema.decodeSync(itemField.encoded)(rawEntry.value);
|
128
102
|
}
|
129
|
-
else if (
|
103
|
+
else if (isRefEncoded(itemField)) {
|
130
104
|
return this.ref?.accessFrom(accessFrom);
|
131
105
|
}
|
132
106
|
},
|
133
107
|
get ref() {
|
134
|
-
if (itemField !== "json" &&
|
108
|
+
if (itemField !== "json" && isRefEncoded(itemField)) {
|
135
109
|
const rawId = rawEntry.value;
|
136
|
-
return new
|
110
|
+
return new Ref(rawId, loadedAs, itemField);
|
137
111
|
}
|
138
112
|
},
|
139
113
|
get by() {
|
140
114
|
return (accountID &&
|
141
|
-
new
|
115
|
+
new Ref(accountID, loadedAs, Account)?.accessFrom(accessFrom));
|
142
116
|
},
|
143
117
|
madeAt: rawEntry.at,
|
144
118
|
tx: rawEntry.tx,
|
145
119
|
};
|
146
120
|
}
|
121
|
+
function init(stream) {
|
122
|
+
const init = stream[InitValues];
|
123
|
+
if (!init)
|
124
|
+
return;
|
125
|
+
const raw = init.owner._raw.createStream();
|
126
|
+
Object.defineProperties(stream, {
|
127
|
+
id: {
|
128
|
+
value: raw.id,
|
129
|
+
enumerable: false,
|
130
|
+
},
|
131
|
+
_raw: { value: raw, enumerable: false },
|
132
|
+
});
|
133
|
+
if (init.init) {
|
134
|
+
stream.push(...init.init);
|
135
|
+
}
|
136
|
+
delete stream[InitValues];
|
137
|
+
}
|
138
|
+
export const CoStreamProxyHandler = {
|
139
|
+
get(target, key, receiver) {
|
140
|
+
if (typeof key === "string" && key.startsWith("co_")) {
|
141
|
+
const rawEntry = target._raw.lastItemBy(key);
|
142
|
+
if (!rawEntry)
|
143
|
+
return;
|
144
|
+
return entryFromRawEntry(receiver, rawEntry, target._loadedAs, key, target._schema[ItemsSym]);
|
145
|
+
}
|
146
|
+
else if (key === "perSession") {
|
147
|
+
return new Proxy(receiver, CoStreamPerSessionProxyHandler);
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
return Reflect.get(target, key, receiver);
|
151
|
+
}
|
152
|
+
},
|
153
|
+
set(target, key, value, receiver) {
|
154
|
+
var _b;
|
155
|
+
if (key === ItemsSym &&
|
156
|
+
typeof value === "object" &&
|
157
|
+
SchemaInit in value) {
|
158
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
159
|
+
target.constructor._schema[ItemsSym] =
|
160
|
+
value[SchemaInit];
|
161
|
+
init(target);
|
162
|
+
return true;
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
return Reflect.set(target, key, value, receiver);
|
166
|
+
}
|
167
|
+
},
|
168
|
+
defineProperty(target, key, descriptor) {
|
169
|
+
var _b;
|
170
|
+
if (descriptor.value &&
|
171
|
+
key === ItemsSym &&
|
172
|
+
typeof descriptor.value === "object" &&
|
173
|
+
SchemaInit in descriptor.value) {
|
174
|
+
(_b = target.constructor)._schema || (_b._schema = {});
|
175
|
+
target.constructor._schema[ItemsSym] =
|
176
|
+
descriptor.value[SchemaInit];
|
177
|
+
init(target);
|
178
|
+
return true;
|
179
|
+
}
|
180
|
+
else {
|
181
|
+
return Reflect.defineProperty(target, key, descriptor);
|
182
|
+
}
|
183
|
+
},
|
184
|
+
ownKeys(target) {
|
185
|
+
const keys = Reflect.ownKeys(target);
|
186
|
+
for (const accountID of target._raw.accounts()) {
|
187
|
+
keys.push(accountID);
|
188
|
+
}
|
189
|
+
return keys;
|
190
|
+
},
|
191
|
+
getOwnPropertyDescriptor(target, key) {
|
192
|
+
if (typeof key === "string" && key.startsWith("co_")) {
|
193
|
+
return {
|
194
|
+
configurable: true,
|
195
|
+
enumerable: true,
|
196
|
+
writable: false,
|
197
|
+
};
|
198
|
+
}
|
199
|
+
else {
|
200
|
+
return Reflect.getOwnPropertyDescriptor(target, key);
|
201
|
+
}
|
202
|
+
},
|
203
|
+
};
|
204
|
+
const CoStreamPerSessionProxyHandler = {
|
205
|
+
get(target, key, receiver) {
|
206
|
+
if (typeof key === "string" && key.includes("session")) {
|
207
|
+
const sessionID = key;
|
208
|
+
const rawEntry = target._raw.lastItemIn(sessionID);
|
209
|
+
if (!rawEntry)
|
210
|
+
return;
|
211
|
+
const by = cojsonInternals.accountOrAgentIDfromSessionID(sessionID);
|
212
|
+
return entryFromRawEntry(target, rawEntry, target._loadedAs, cojsonInternals.isAccountID(by)
|
213
|
+
? by
|
214
|
+
: undefined, target._schema[ItemsSym]);
|
215
|
+
}
|
216
|
+
else {
|
217
|
+
return Reflect.get(target, key, receiver);
|
218
|
+
}
|
219
|
+
},
|
220
|
+
};
|
147
221
|
export class BinaryCoStream extends CoValueBase {
|
148
|
-
constructor(
|
222
|
+
constructor(_init, options) {
|
149
223
|
super();
|
150
224
|
let raw;
|
151
225
|
if ("fromRaw" in options) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"coStream.js","sourceRoot":"","sources":["../../src/coValues/coStream.ts"],"names":[],"mappings":";AAUA,OAAO,EA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C1C,CAAC,CAAC;IACP,CAAC;IAED,SAAS,CAAC,OAET;QAGG,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,OAAyB;QAC3B,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,IAAgB;QACjB,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,GAAG;QACC,IAAI,CAAC,IAAI,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,7 +1,13 @@
|
|
1
1
|
var _a;
|
2
|
-
import { BinaryCoStream, CoMap,
|
2
|
+
import { BinaryCoStream, CoMap, co, subscriptionsScopes, } from "../../internal.js";
|
3
3
|
export class ImageDefinition extends CoMap {
|
4
|
-
|
4
|
+
constructor() {
|
5
|
+
super(...arguments);
|
6
|
+
this.originalSize = co.json();
|
7
|
+
this.placeholderDataURL = co.string;
|
8
|
+
this[_a] = co.ref(BinaryCoStream);
|
9
|
+
}
|
10
|
+
get highestResAvailable() {
|
5
11
|
if (!subscriptionsScopes.get(this)) {
|
6
12
|
console.warn("highestResAvailable() only makes sense when used within a subscription.");
|
7
13
|
}
|
@@ -29,13 +35,5 @@ export class ImageDefinition extends CoMap {
|
|
29
35
|
});
|
30
36
|
}
|
31
37
|
}
|
32
|
-
_a =
|
33
|
-
(() => {
|
34
|
-
_a.prototype._schema;
|
35
|
-
_a.encoding({
|
36
|
-
originalSize: "json",
|
37
|
-
placeholderDataURL: "json",
|
38
|
-
[indexSignature]: { ref: () => BinaryCoStream },
|
39
|
-
});
|
40
|
-
})();
|
38
|
+
_a = co.items;
|
41
39
|
//# sourceMappingURL=imageDef.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"imageDef.js","sourceRoot":"","sources":["../../../src/coValues/extensions/imageDef.ts"],"names":[],"mappings":";AAAA,OAAO,
|
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;IA2CxC,CAAC;IAxCG,IAAI,mBAAmB;QAGnB,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,CAAC,CAAC,GAAG,EAAE,EAAE,CACjD,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CACE,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;KA3CI,EAAE,CAAC,KAAK"}
|
package/dist/coValues/group.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
var _a
|
2
|
-
import { Account, CoMap, CoValueBase,
|
1
|
+
var _a;
|
2
|
+
import { Account, CoMap, CoValueBase, Ref, co, isControlledAccount, AccountAndGroupProxyHandler, } from "../internal.js";
|
3
3
|
export class Profile extends CoMap {
|
4
|
+
constructor() {
|
5
|
+
super(...arguments);
|
6
|
+
this.name = co.string;
|
7
|
+
}
|
4
8
|
}
|
5
|
-
_a = Profile;
|
6
|
-
(() => {
|
7
|
-
_a.encoding({ name: "json" });
|
8
|
-
})();
|
9
9
|
export class Group extends CoValueBase {
|
10
10
|
get _schema() {
|
11
11
|
return this.constructor._schema;
|
@@ -15,9 +15,9 @@ export class Group extends CoValueBase {
|
|
15
15
|
const rootID = this._raw.get("root");
|
16
16
|
return {
|
17
17
|
profile: profileID &&
|
18
|
-
new
|
18
|
+
new Ref(profileID, this._loadedAs, this._schema.profile),
|
19
19
|
root: rootID &&
|
20
|
-
new
|
20
|
+
new Ref(rootID, this._loadedAs, this._schema.root),
|
21
21
|
};
|
22
22
|
}
|
23
23
|
constructor(init, options) {
|
@@ -45,29 +45,8 @@ export class Group extends CoValueBase {
|
|
45
45
|
enumerable: false,
|
46
46
|
},
|
47
47
|
_raw: { value: raw, enumerable: false },
|
48
|
-
profile: {
|
49
|
-
get: () => {
|
50
|
-
const ref = this._refs.profile;
|
51
|
-
return ref ? ref.accessFrom(this) : undefined;
|
52
|
-
},
|
53
|
-
set: (value) => {
|
54
|
-
if (value) {
|
55
|
-
this._raw.set("profile", value.id);
|
56
|
-
}
|
57
|
-
},
|
58
|
-
},
|
59
|
-
root: {
|
60
|
-
get: () => {
|
61
|
-
const ref = this._refs.root;
|
62
|
-
return ref ? ref.accessFrom(this) : undefined;
|
63
|
-
},
|
64
|
-
set: (value) => {
|
65
|
-
if (value) {
|
66
|
-
this._raw.set("root", value.id);
|
67
|
-
}
|
68
|
-
},
|
69
|
-
},
|
70
48
|
});
|
49
|
+
return new Proxy(this, AccountAndGroupProxyHandler);
|
71
50
|
}
|
72
51
|
myRole() {
|
73
52
|
return this._raw.myRole();
|
@@ -75,22 +54,18 @@ export class Group extends CoValueBase {
|
|
75
54
|
addMember(member, role) {
|
76
55
|
this._raw.addMember(member === "everyone" ? member : member._raw, role);
|
77
56
|
}
|
78
|
-
static define(fields) {
|
79
|
-
this._schema || (this._schema = {});
|
80
|
-
Object.assign(this._schema, fields);
|
81
|
-
}
|
82
57
|
}
|
83
|
-
|
58
|
+
_a = Group;
|
84
59
|
(() => {
|
85
|
-
|
60
|
+
_a.prototype._type = "Group";
|
86
61
|
})();
|
87
62
|
(() => {
|
88
|
-
|
63
|
+
_a._schema = {
|
89
64
|
profile: { json: true },
|
90
65
|
root: { json: true },
|
91
66
|
};
|
92
|
-
Object.defineProperty(
|
93
|
-
get: () =>
|
67
|
+
Object.defineProperty(_a.prototype, "_schema", {
|
68
|
+
get: () => _a._schema,
|
94
69
|
});
|
95
70
|
})();
|
96
71
|
//# sourceMappingURL=group.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/coValues/group.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"group.js","sourceRoot":"","sources":["../../src/coValues/group.ts"],"names":[],"mappings":";AAEA,OAAO,EACH,OAAO,EACP,KAAK,EACL,WAAW,EACX,GAAG,EACH,EAAE,EACF,mBAAmB,EACnB,2BAA2B,GAC9B,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,OAAQ,SAAQ,KAA2B;IAAxD;;QACI,SAAI,GAAG,EAAE,CAAC,MAAM,CAAC;IACrB,CAAC;CAAA;AAED,MAAM,OAAO,KAMT,SAAQ,WAAW;IAWnB,IAAI,OAAO;QAQP,OAAQ,IAAI,CAAC,WAA4B,CAAC,OAAO,CAAC;IACtD,CAAC;IAiBD,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;gBACR,IAAI,GAAG,CACJ,SAAS,EACT,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CAAC,OAEZ,CACI;YACb,IAAI,EACA,MAAM;gBACL,IAAI,GAAG,CACJ,MAAM,EACN,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,OAAO,CAAC,IAA4C,CACpD;SAChB,CAAC;IACN,CAAC;IAKD,YACI,IAA4C,EAC5C,OAA4D;QAE5D,KAAK,EAAE,CAAC;QACR,IAAI,GAAa,CAAC;QAElB,IAAI,OAAO,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;YAClC,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;QAC1B,CAAC;aAAM,CAAC;YACJ,MAAM,SAAS,GAAG,OAAO,EAAE,KAAK,IAAI,IAA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,GAAG,EAAE,CAAC,GAAK,OAAO;KAC1B,CAAC,CAAC;AACP,CAAC,GAAA,CAAA"}
|
@@ -1,9 +1,12 @@
|
|
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, } 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
|
return this._raw.group instanceof RawAccount
|
@@ -20,11 +23,11 @@ export class CoValueBase {
|
|
20
23
|
static loadEf(id) {
|
21
24
|
return Effect.gen(this, function* (_) {
|
22
25
|
const account = yield* _(AccountCtx);
|
23
|
-
return yield* _(new
|
26
|
+
return yield* _(new Ref(id, account, this).loadEf());
|
24
27
|
});
|
25
28
|
}
|
26
29
|
static load(id, options) {
|
27
|
-
return new
|
30
|
+
return new Ref(id, options.as, this).load(options?.onProgress && { onProgress: options.onProgress });
|
28
31
|
}
|
29
32
|
static subscribe(id, options, onUpdate) {
|
30
33
|
void Effect.runPromise(Effect.provideService(this.subscribeEf(id).pipe(Stream.run(Sink.forEach((update) => Effect.sync(() => onUpdate(update))))), AccountCtx, options.as));
|
@@ -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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AC,MAAM,EAAE,EAAE;gBACP,KAAK,IAAI,CAAC,MAAM,CAAC,MAAW,CAAC,CAAC;YAClC,CAAC,CACJ,CAAC;YAEF,KAAK,CAAC,CAAC,CAAC,CACJ,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC,CACnD,CACJ,CAAC;QACN,CAAC,CAAC,CACL,CACJ,CACJ,CAAC;IACN,CAAC;IAED,SAAS,CAAC,QAAgC;QACtC,OAAQ,IAAI,CAAC,WAA6C,CAAC,SAAS,CAChE,IAAI,CAAC,EAA4B,EACjC,EAAE,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,EACtB,QAAgD,CACnD,CAAC;IACN,CAAC;IAED,WAAW;QACP,OAAO,MAAM,CAAC,cAAc,CACvB,IAAI,CAAC,WAA6C,CAAC,WAAW,CAC3D,IAAI,CAAC,EAA4B,CACpC,EACD,UAAU,EACV,IAAI,CAAC,SAAS,CAC0C,CAAC;IACjE,CAAC;IAED,MAAM;QACF,OAAO;YACH,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,KAAK,EAAE,uBAAuB;SACjC,CAAC;IACN,CAAC;IAED,CAAC,OAAO,CAAC;QACL,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACzB,CAAC;CACJ"}
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import { Effect } from "effect";
|
2
|
-
import { subscriptionsScopes } from
|
3
|
-
export class
|
4
|
-
constructor(id, controlledAccount,
|
2
|
+
import { instantiateRefEncoded, isRefEncoded, subscriptionsScopes, } from "../internal.js";
|
3
|
+
export class Ref {
|
4
|
+
constructor(id, controlledAccount, schema) {
|
5
5
|
this.id = id;
|
6
6
|
this.controlledAccount = controlledAccount;
|
7
|
-
this.
|
7
|
+
this.schema = schema;
|
8
|
+
if (!isRefEncoded(schema)) {
|
9
|
+
throw new Error("Ref must be constructed with a ref schema");
|
10
|
+
}
|
8
11
|
}
|
9
12
|
get value() {
|
10
13
|
if (this.cachedValue)
|
@@ -12,7 +15,7 @@ export class ValueRef {
|
|
12
15
|
// TODO: cache it for object identity!!!
|
13
16
|
const raw = this.controlledAccount._raw.core.node.getLoaded(this.id);
|
14
17
|
if (raw) {
|
15
|
-
const value =
|
18
|
+
const value = instantiateRefEncoded(this.schema, raw);
|
16
19
|
this.cachedValue = value;
|
17
20
|
return value;
|
18
21
|
}
|
@@ -42,7 +45,7 @@ export class ValueRef {
|
|
42
45
|
return "unavailable";
|
43
46
|
}
|
44
47
|
else {
|
45
|
-
return new
|
48
|
+
return new Ref(this.id, this.controlledAccount, this.schema)
|
46
49
|
.value;
|
47
50
|
}
|
48
51
|
}
|
@@ -64,14 +67,14 @@ export class ValueRef {
|
|
64
67
|
return this.value;
|
65
68
|
}
|
66
69
|
}
|
67
|
-
export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount,
|
70
|
+
export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, refSchemaForKey) {
|
68
71
|
const refs = {};
|
69
72
|
return new Proxy(refs, {
|
70
|
-
get(
|
73
|
+
get(_target, key) {
|
71
74
|
if (key === Symbol.iterator) {
|
72
75
|
return function* () {
|
73
76
|
for (const key of getKeysWithIds()) {
|
74
|
-
yield new
|
77
|
+
yield new Ref(getIdForKey(key), controlledAccount, refSchemaForKey(key));
|
75
78
|
}
|
76
79
|
};
|
77
80
|
}
|
@@ -83,7 +86,7 @@ export function makeRefs(getIdForKey, getKeysWithIds, controlledAccount, valueCo
|
|
83
86
|
const id = getIdForKey(key);
|
84
87
|
if (!id)
|
85
88
|
return undefined;
|
86
|
-
return new
|
89
|
+
return new Ref(id, controlledAccount, refSchemaForKey(key));
|
87
90
|
},
|
88
91
|
ownKeys() {
|
89
92
|
return getKeysWithIds().map((key) => key.toString());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/implementation/refs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAUhC,OAAO,EACH,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,GACtB,MAAM,gBAAgB,CAAC;AAExB,MAAM,OAAO,GAAG;IAGZ,YACa,EAAS,EACT,iBAA+B,EAC/B,MAAqB;QAFrB,OAAE,GAAF,EAAE,CAAO;QACT,sBAAiB,GAAjB,iBAAiB,CAAc;QAC/B,WAAM,GAAN,MAAM,CAAe;QAE9B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;IAED,IAAI,KAAK;QACL,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC;QAC9C,wCAAwC;QACxC,MAAM,GAAG,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CACvD,IAAI,CAAC,EAAiC,CACzC,CAAC;QACF,IAAI,GAAG,EAAE,CAAC;YACN,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YACtD,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;YACzB,OAAO,KAAK,CAAC;QACjB,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED,MAAM;QACF,OAAO,MAAM,CAAC,KAAK,CAAsB,CAAC,OAAO,EAAE,EAAE;YACjD,IAAI,CAAC,UAAU,EAAE;iBACZ,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;gBACZ,IAAI,KAAK,KAAK,a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import { isCoValueClass } from "../internal.js";
|
2
|
+
export const SchemaInit = Symbol.for("SchemaInit");
|
3
|
+
export const InitValues = Symbol.for("InitValues");
|
4
|
+
export const ItemsSym = Symbol.for("items");
|
5
|
+
export const co = {
|
6
|
+
string: {
|
7
|
+
[SchemaInit]: "json",
|
8
|
+
},
|
9
|
+
number: {
|
10
|
+
[SchemaInit]: "json",
|
11
|
+
},
|
12
|
+
boolean: {
|
13
|
+
[SchemaInit]: "json",
|
14
|
+
},
|
15
|
+
literal: (_lit) => {
|
16
|
+
return { [SchemaInit]: "json" };
|
17
|
+
},
|
18
|
+
json: () => {
|
19
|
+
return { [SchemaInit]: "json" };
|
20
|
+
},
|
21
|
+
encoded: (arg) => {
|
22
|
+
return { [SchemaInit]: { encoded: arg } };
|
23
|
+
},
|
24
|
+
ref: (arg) => {
|
25
|
+
return { [SchemaInit]: arg };
|
26
|
+
},
|
27
|
+
items: ItemsSym,
|
28
|
+
};
|
29
|
+
export function isRefEncoded(schema) {
|
30
|
+
return typeof schema === "function";
|
31
|
+
}
|
32
|
+
export function instantiateRefEncoded(schema, raw) {
|
33
|
+
return isCoValueClass(schema)
|
34
|
+
? schema.fromRaw(raw)
|
35
|
+
: schema(raw).fromRaw(raw);
|
36
|
+
}
|
1
37
|
import { Date } from "@effect/schema/Schema";
|
2
38
|
export const Encoders = {
|
3
39
|
Date,
|
4
40
|
};
|
5
|
-
export const indexSignature = Symbol.for("indexSignature");
|
6
41
|
//# sourceMappingURL=schema.js.map
|