jazz-tools 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +15 -0
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +33 -33
- package/CHANGELOG.md +171 -165
- package/LICENSE.txt +1 -1
- package/dist/coValues/account.js +30 -3
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +29 -5
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +25 -1
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +49 -1
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +25 -1
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +32 -48
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/tests/deepLoading.test.js +2 -2
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +3 -3
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +1 -1
- package/src/coValues/account.ts +82 -12
- package/src/coValues/coList.ts +78 -13
- package/src/coValues/coMap.ts +78 -7
- package/src/coValues/coStream.ts +128 -11
- package/src/coValues/group.ts +77 -4
- package/src/coValues/interfaces.ts +140 -211
- package/src/implementation/schema.ts +7 -4
- package/src/implementation/subscriptionScope.ts +3 -3
- package/src/index.ts +7 -0
- package/src/tests/deepLoading.test.ts +6 -3
- package/src/tests/groupsAndAccounts.test.ts +4 -4
@@ -52,7 +52,7 @@ describe("Custom accounts and groups", async () => {
|
|
52
52
|
]);
|
53
53
|
expect(group.nMembers).toBe(2);
|
54
54
|
await new Promise((resolve) => {
|
55
|
-
|
55
|
+
group.subscribe({}, (update) => {
|
56
56
|
const meAsMember = update.members.find((member) => {
|
57
57
|
return member.id === me.id && member.account?.profile;
|
58
58
|
});
|
@@ -71,13 +71,13 @@ describe("Custom accounts and groups", async () => {
|
|
71
71
|
}
|
72
72
|
const map = MyMap.create({ name: "test" }, { owner: group });
|
73
73
|
const meAsCastMember = map._owner
|
74
|
-
.
|
74
|
+
.castAs(CustomGroup)
|
75
75
|
.members.find((member) => member.id === me.id);
|
76
76
|
expect(meAsCastMember?.account?.profile?.name).toBe("Hermes Puggington");
|
77
77
|
expect(meAsCastMember?.account?.profile?.color).toBe("blue");
|
78
78
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
79
79
|
expect(map._owner.nMembers).toBeUndefined();
|
80
|
-
expect(map._owner.
|
80
|
+
expect(map._owner.castAs(CustomGroup).nMembers).toBe(2);
|
81
81
|
});
|
82
82
|
});
|
83
83
|
//# sourceMappingURL=groupsAndAccounts.test.js.map
|
@@ -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,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,CAAC;QAVG,OAAO,
|
1
|
+
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AAC,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
package/src/coValues/account.ts
CHANGED
@@ -11,7 +11,7 @@ import type {
|
|
11
11
|
RawControlledAccount,
|
12
12
|
SessionID,
|
13
13
|
} from "cojson";
|
14
|
-
import { Context } from "effect";
|
14
|
+
import { Context, Effect, Stream } from "effect";
|
15
15
|
import type {
|
16
16
|
CoMap,
|
17
17
|
CoValue,
|
@@ -19,8 +19,10 @@ import type {
|
|
19
19
|
Schema,
|
20
20
|
ID,
|
21
21
|
RefEncoded,
|
22
|
-
ClassOf,
|
23
22
|
RefIfCoValue,
|
23
|
+
DeeplyLoaded,
|
24
|
+
DepthsIn,
|
25
|
+
UnavailableError,
|
24
26
|
} from "../internal.js";
|
25
27
|
import {
|
26
28
|
Group,
|
@@ -31,13 +33,16 @@ import {
|
|
31
33
|
SchemaInit,
|
32
34
|
inspect,
|
33
35
|
subscriptionsScopes,
|
36
|
+
loadCoValue,
|
37
|
+
loadCoValueEf,
|
38
|
+
subscribeToCoValue,
|
39
|
+
subscribeToCoValueEf,
|
40
|
+
ensureCoValueLoaded,
|
41
|
+
subscribeToExistingCoValue,
|
34
42
|
} from "../internal.js";
|
35
43
|
|
36
44
|
/** @category Identity & Permissions */
|
37
|
-
export class Account
|
38
|
-
extends CoValueBase
|
39
|
-
implements CoValue<"Account", RawAccount | RawControlledAccount>
|
40
|
-
{
|
45
|
+
export class Account extends CoValueBase implements CoValue {
|
41
46
|
declare id: ID<this>;
|
42
47
|
declare _type: "Account";
|
43
48
|
declare _raw: RawAccount | RawControlledAccount;
|
@@ -52,7 +57,10 @@ export class Account
|
|
52
57
|
}
|
53
58
|
static {
|
54
59
|
this._schema = {
|
55
|
-
profile: {
|
60
|
+
profile: {
|
61
|
+
ref: () => Profile,
|
62
|
+
optional: false,
|
63
|
+
} satisfies RefEncoded<Profile>,
|
56
64
|
root: "json" satisfies Schema,
|
57
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
58
66
|
} as any;
|
@@ -151,12 +159,12 @@ export class Account
|
|
151
159
|
inviteSecret,
|
152
160
|
);
|
153
161
|
|
154
|
-
return coValueClass
|
162
|
+
return loadCoValue(coValueClass, valueID, this as Account, []);
|
155
163
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
156
164
|
}
|
157
165
|
|
158
166
|
static async create<A extends Account>(
|
159
|
-
this:
|
167
|
+
this: CoValueClass<A> & typeof Account,
|
160
168
|
options: {
|
161
169
|
creationProps: { name: string };
|
162
170
|
initialAgentSecret?: AgentSecret;
|
@@ -179,7 +187,7 @@ export class Account
|
|
179
187
|
}
|
180
188
|
|
181
189
|
static async become<A extends Account>(
|
182
|
-
this:
|
190
|
+
this: CoValueClass<A> & typeof Account,
|
183
191
|
options: {
|
184
192
|
accountID: ID<Account>;
|
185
193
|
accountSecret: AgentSecret;
|
@@ -206,7 +214,10 @@ export class Account
|
|
206
214
|
return this.fromNode(node) as A;
|
207
215
|
}
|
208
216
|
|
209
|
-
static fromNode<A extends Account>(
|
217
|
+
static fromNode<A extends Account>(
|
218
|
+
this: CoValueClass<A>,
|
219
|
+
node: LocalNode,
|
220
|
+
): A {
|
210
221
|
return new this({
|
211
222
|
fromRaw: node.account as RawControlledAccount,
|
212
223
|
}) as A;
|
@@ -224,7 +235,10 @@ export class Account
|
|
224
235
|
return this.toJSON();
|
225
236
|
}
|
226
237
|
|
227
|
-
migrate(
|
238
|
+
migrate(
|
239
|
+
this: Account,
|
240
|
+
creationProps?: { name: string },
|
241
|
+
): void | Promise<void> {
|
228
242
|
if (creationProps) {
|
229
243
|
const profileGroup = Group.create({ owner: this });
|
230
244
|
profileGroup.addMember("everyone", "reader");
|
@@ -234,6 +248,62 @@ export class Account
|
|
234
248
|
);
|
235
249
|
}
|
236
250
|
}
|
251
|
+
|
252
|
+
/** @category Subscription & Loading */
|
253
|
+
static load<A extends Account, Depth>(
|
254
|
+
this: CoValueClass<A>,
|
255
|
+
id: ID<A>,
|
256
|
+
as: Account,
|
257
|
+
depth: Depth & DepthsIn<A>,
|
258
|
+
): Promise<DeeplyLoaded<A, Depth> | undefined> {
|
259
|
+
return loadCoValue(this, id, as, depth);
|
260
|
+
}
|
261
|
+
|
262
|
+
/** @category Subscription & Loading */
|
263
|
+
static loadEf<A extends Account, Depth>(
|
264
|
+
this: CoValueClass<A>,
|
265
|
+
id: ID<A>,
|
266
|
+
depth: Depth & DepthsIn<A>,
|
267
|
+
): Effect.Effect<DeeplyLoaded<A, Depth>, UnavailableError, AccountCtx> {
|
268
|
+
return loadCoValueEf<A, Depth>(this, id, depth);
|
269
|
+
}
|
270
|
+
|
271
|
+
/** @category Subscription & Loading */
|
272
|
+
static subscribe<A extends Account, Depth>(
|
273
|
+
this: CoValueClass<A>,
|
274
|
+
id: ID<A>,
|
275
|
+
as: Account,
|
276
|
+
depth: Depth & DepthsIn<A>,
|
277
|
+
listener: (value: DeeplyLoaded<A, Depth>) => void,
|
278
|
+
): () => void {
|
279
|
+
return subscribeToCoValue<A, Depth>(this, id, as, depth, listener);
|
280
|
+
}
|
281
|
+
|
282
|
+
/** @category Subscription & Loading */
|
283
|
+
static subscribeEf<A extends Account, Depth>(
|
284
|
+
this: CoValueClass<A>,
|
285
|
+
id: ID<A>,
|
286
|
+
depth: Depth & DepthsIn<A>,
|
287
|
+
): Stream.Stream<DeeplyLoaded<A, Depth>, UnavailableError, AccountCtx> {
|
288
|
+
return subscribeToCoValueEf<A, Depth>(this, id, depth);
|
289
|
+
}
|
290
|
+
|
291
|
+
/** @category Subscription & Loading */
|
292
|
+
ensureLoaded<A extends Account, Depth>(
|
293
|
+
this: A,
|
294
|
+
depth: Depth & DepthsIn<A>,
|
295
|
+
): Promise<DeeplyLoaded<A, Depth> | undefined> {
|
296
|
+
return ensureCoValueLoaded(this, depth);
|
297
|
+
}
|
298
|
+
|
299
|
+
/** @category Subscription & Loading */
|
300
|
+
subscribe<A extends Account, Depth>(
|
301
|
+
this: A,
|
302
|
+
depth: Depth & DepthsIn<A>,
|
303
|
+
listener: (value: DeeplyLoaded<A, Depth>) => void,
|
304
|
+
): () => void {
|
305
|
+
return subscribeToExistingCoValue(this, depth, listener);
|
306
|
+
}
|
237
307
|
}
|
238
308
|
|
239
309
|
export const AccountAndGroupProxyHandler: ProxyHandler<Account | Group> = {
|
package/src/coValues/coList.ts
CHANGED
@@ -6,31 +6,38 @@ import type {
|
|
6
6
|
SchemaFor,
|
7
7
|
ID,
|
8
8
|
RefEncoded,
|
9
|
-
ClassOf,
|
10
9
|
UnCo,
|
11
10
|
CoValueClass,
|
11
|
+
DepthsIn,
|
12
|
+
DeeplyLoaded,
|
13
|
+
UnavailableError,
|
14
|
+
AccountCtx,
|
15
|
+
CoValueFromRaw,
|
12
16
|
} from "../internal.js";
|
13
17
|
import {
|
14
18
|
Account,
|
15
|
-
CoValueBase,
|
16
19
|
Group,
|
17
20
|
InitValues,
|
18
21
|
ItemsSym,
|
19
22
|
Ref,
|
20
23
|
SchemaInit,
|
21
24
|
co,
|
25
|
+
ensureCoValueLoaded,
|
22
26
|
inspect,
|
23
27
|
isRefEncoded,
|
28
|
+
loadCoValue,
|
29
|
+
loadCoValueEf,
|
24
30
|
makeRefs,
|
31
|
+
subscribeToCoValue,
|
32
|
+
subscribeToCoValueEf,
|
33
|
+
subscribeToExistingCoValue,
|
25
34
|
} from "../internal.js";
|
26
35
|
import { encodeSync, decodeSync } from "@effect/schema/Schema";
|
36
|
+
import { Effect, Stream } from "effect";
|
27
37
|
|
28
38
|
/** @category CoValues */
|
29
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
30
|
-
export class CoList<Item = any>
|
31
|
-
extends Array<Item>
|
32
|
-
implements CoValue<"CoList", RawCoList>
|
33
|
-
{
|
40
|
+
export class CoList<Item = any> extends Array<Item> implements CoValue {
|
34
41
|
static Of<Item>(item: Item): typeof CoList<Item> {
|
35
42
|
// TODO: cache superclass for item class
|
36
43
|
return class CoListOf extends CoList<Item> {
|
@@ -146,7 +153,7 @@ export class CoList<Item = any>
|
|
146
153
|
}
|
147
154
|
|
148
155
|
static create<L extends CoList>(
|
149
|
-
this:
|
156
|
+
this: CoValueClass<L>,
|
150
157
|
items: UnCo<L[number]>[],
|
151
158
|
options: { owner: Account | Group },
|
152
159
|
) {
|
@@ -241,17 +248,12 @@ export class CoList<Item = any>
|
|
241
248
|
}
|
242
249
|
|
243
250
|
static fromRaw<V extends CoList>(
|
244
|
-
this:
|
251
|
+
this: CoValueClass<V> & typeof CoList,
|
245
252
|
raw: RawCoList,
|
246
253
|
) {
|
247
254
|
return new this({ fromRaw: raw });
|
248
255
|
}
|
249
256
|
|
250
|
-
static load = CoValueBase.load as CoValueClass["load"];
|
251
|
-
static loadEf = CoValueBase.loadEf as CoValueClass["loadEf"];
|
252
|
-
static subscribe = CoValueBase.subscribe as CoValueClass["subscribe"];
|
253
|
-
static subscribeEf = CoValueBase.subscribeEf as CoValueClass["subscribeEf"];
|
254
|
-
|
255
257
|
static schema<V extends CoList>(
|
256
258
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
257
259
|
this: { new (...args: any): V } & typeof CoList,
|
@@ -260,6 +262,69 @@ export class CoList<Item = any>
|
|
260
262
|
this._schema ||= {};
|
261
263
|
Object.assign(this._schema, def);
|
262
264
|
}
|
265
|
+
|
266
|
+
/** @category Subscription & Loading */
|
267
|
+
static load<L extends CoList, Depth>(
|
268
|
+
this: CoValueClass<L>,
|
269
|
+
id: ID<L>,
|
270
|
+
as: Account,
|
271
|
+
depth: Depth & DepthsIn<L>,
|
272
|
+
): Promise<DeeplyLoaded<L, Depth> | undefined> {
|
273
|
+
return loadCoValue(this, id, as, depth);
|
274
|
+
}
|
275
|
+
|
276
|
+
/** @category Subscription & Loading */
|
277
|
+
static loadEf<L extends CoList, Depth>(
|
278
|
+
this: CoValueClass<L>,
|
279
|
+
id: ID<L>,
|
280
|
+
depth: Depth & DepthsIn<L>,
|
281
|
+
): Effect.Effect<DeeplyLoaded<L, Depth>, UnavailableError, AccountCtx> {
|
282
|
+
return loadCoValueEf<L, Depth>(this, id, depth);
|
283
|
+
}
|
284
|
+
|
285
|
+
/** @category Subscription & Loading */
|
286
|
+
static subscribe<L extends CoList, Depth>(
|
287
|
+
this: CoValueClass<L>,
|
288
|
+
id: ID<L>,
|
289
|
+
as: Account,
|
290
|
+
depth: Depth & DepthsIn<L>,
|
291
|
+
listener: (value: DeeplyLoaded<L, Depth>) => void,
|
292
|
+
): () => void {
|
293
|
+
return subscribeToCoValue<L, Depth>(this, id, as, depth, listener);
|
294
|
+
}
|
295
|
+
|
296
|
+
/** @category Subscription & Loading */
|
297
|
+
static subscribeEf<L extends CoList, Depth>(
|
298
|
+
this: CoValueClass<L>,
|
299
|
+
id: ID<L>,
|
300
|
+
depth: Depth & DepthsIn<L>,
|
301
|
+
): Stream.Stream<DeeplyLoaded<L, Depth>, UnavailableError, AccountCtx> {
|
302
|
+
return subscribeToCoValueEf<L, Depth>(this, id, depth);
|
303
|
+
}
|
304
|
+
|
305
|
+
/** @category Subscription & Loading */
|
306
|
+
ensureLoaded<L extends CoList, Depth>(
|
307
|
+
this: L,
|
308
|
+
depth: Depth & DepthsIn<L>,
|
309
|
+
): Promise<DeeplyLoaded<L, Depth> | undefined> {
|
310
|
+
return ensureCoValueLoaded(this, depth);
|
311
|
+
}
|
312
|
+
|
313
|
+
/** @category Subscription & Loading */
|
314
|
+
subscribe<L extends CoList, Depth>(
|
315
|
+
this: L,
|
316
|
+
depth: Depth & DepthsIn<L>,
|
317
|
+
listener: (value: DeeplyLoaded<L, Depth>) => void,
|
318
|
+
): () => void {
|
319
|
+
return subscribeToExistingCoValue(this, depth, listener);
|
320
|
+
}
|
321
|
+
|
322
|
+
/** @category Type Helpers */
|
323
|
+
castAs<Cl extends CoValueClass & CoValueFromRaw<CoValue>>(
|
324
|
+
cl: Cl,
|
325
|
+
): InstanceType<Cl> {
|
326
|
+
return cl.fromRaw(this._raw) as InstanceType<Cl>;
|
327
|
+
}
|
263
328
|
}
|
264
329
|
|
265
330
|
function toRawItems<Item>(items: Item[], itemDescriptor: Schema) {
|
package/src/coValues/coMap.ts
CHANGED
@@ -9,7 +9,11 @@ import type {
|
|
9
9
|
RefEncoded,
|
10
10
|
IfCo,
|
11
11
|
RefIfCoValue,
|
12
|
-
|
12
|
+
DepthsIn,
|
13
|
+
DeeplyLoaded,
|
14
|
+
UnavailableError,
|
15
|
+
AccountCtx,
|
16
|
+
CoValueClass,
|
13
17
|
} from "../internal.js";
|
14
18
|
import {
|
15
19
|
Account,
|
@@ -22,7 +26,14 @@ import {
|
|
22
26
|
ItemsSym,
|
23
27
|
InitValues,
|
24
28
|
isRefEncoded,
|
29
|
+
loadCoValue,
|
30
|
+
loadCoValueEf,
|
31
|
+
subscribeToCoValue,
|
32
|
+
subscribeToCoValueEf,
|
33
|
+
ensureCoValueLoaded,
|
34
|
+
subscribeToExistingCoValue,
|
25
35
|
} from "../internal.js";
|
36
|
+
import { Effect, Stream } from "effect";
|
26
37
|
|
27
38
|
type CoMapEdit<V> = {
|
28
39
|
value?: V;
|
@@ -66,7 +77,7 @@ type InitValuesFor<C extends CoMap> = {
|
|
66
77
|
*
|
67
78
|
* @category CoValues
|
68
79
|
* */
|
69
|
-
export class CoMap extends CoValueBase implements CoValue
|
80
|
+
export class CoMap extends CoValueBase implements CoValue {
|
70
81
|
/**
|
71
82
|
* The ID of this `CoMap`
|
72
83
|
* @category Content */
|
@@ -161,10 +172,14 @@ export class CoMap extends CoValueBase implements CoValue<"CoMap", RawCoMap> {
|
|
161
172
|
: undefined,
|
162
173
|
by:
|
163
174
|
rawEdit.by &&
|
164
|
-
new Ref
|
165
|
-
|
166
|
-
|
167
|
-
|
175
|
+
new Ref<Account>(
|
176
|
+
rawEdit.by as ID<Account>,
|
177
|
+
target._loadedAs,
|
178
|
+
{
|
179
|
+
ref: Account,
|
180
|
+
optional: false,
|
181
|
+
},
|
182
|
+
).accessFrom(
|
168
183
|
target,
|
169
184
|
"_edits." + key.toString() + ".by",
|
170
185
|
),
|
@@ -214,7 +229,7 @@ export class CoMap extends CoValueBase implements CoValue<"CoMap", RawCoMap> {
|
|
214
229
|
|
215
230
|
/** @category Creation */
|
216
231
|
static create<M extends CoMap>(
|
217
|
-
this:
|
232
|
+
this: CoValueClass<M>,
|
218
233
|
init: Simplify<CoMapInit<M>>,
|
219
234
|
options: { owner: Account | Group },
|
220
235
|
) {
|
@@ -297,6 +312,62 @@ export class CoMap extends CoValueBase implements CoValue<"CoMap", RawCoMap> {
|
|
297
312
|
|
298
313
|
return RecordLikeCoMap;
|
299
314
|
}
|
315
|
+
|
316
|
+
/** @category Subscription & Loading */
|
317
|
+
static load<M extends CoMap, Depth>(
|
318
|
+
this: CoValueClass<M>,
|
319
|
+
id: ID<M>,
|
320
|
+
as: Account,
|
321
|
+
depth: Depth & DepthsIn<M>,
|
322
|
+
): Promise<DeeplyLoaded<M, Depth> | undefined> {
|
323
|
+
return loadCoValue(this, id, as, depth);
|
324
|
+
}
|
325
|
+
|
326
|
+
/** @category Subscription & Loading */
|
327
|
+
static loadEf<M extends CoMap, Depth>(
|
328
|
+
this: CoValueClass<M>,
|
329
|
+
id: ID<M>,
|
330
|
+
depth: Depth & DepthsIn<M>,
|
331
|
+
): Effect.Effect<DeeplyLoaded<M, Depth>, UnavailableError, AccountCtx> {
|
332
|
+
return loadCoValueEf<M, Depth>(this, id, depth);
|
333
|
+
}
|
334
|
+
|
335
|
+
/** @category Subscription & Loading */
|
336
|
+
static subscribe<M extends CoMap, Depth>(
|
337
|
+
this: CoValueClass<M>,
|
338
|
+
id: ID<M>,
|
339
|
+
as: Account,
|
340
|
+
depth: Depth & DepthsIn<M>,
|
341
|
+
listener: (value: DeeplyLoaded<M, Depth>) => void,
|
342
|
+
): () => void {
|
343
|
+
return subscribeToCoValue<M, Depth>(this, id, as, depth, listener);
|
344
|
+
}
|
345
|
+
|
346
|
+
/** @category Subscription & Loading */
|
347
|
+
static subscribeEf<M extends CoMap, Depth>(
|
348
|
+
this: CoValueClass<M>,
|
349
|
+
id: ID<M>,
|
350
|
+
depth: Depth & DepthsIn<M>,
|
351
|
+
): Stream.Stream<DeeplyLoaded<M, Depth>, UnavailableError, AccountCtx> {
|
352
|
+
return subscribeToCoValueEf<M, Depth>(this, id, depth);
|
353
|
+
}
|
354
|
+
|
355
|
+
/** @category Subscription & Loading */
|
356
|
+
ensureLoaded<M extends CoMap, Depth>(
|
357
|
+
this: M,
|
358
|
+
depth: Depth & DepthsIn<M>,
|
359
|
+
): Promise<DeeplyLoaded<M, Depth> | undefined> {
|
360
|
+
return ensureCoValueLoaded(this, depth);
|
361
|
+
}
|
362
|
+
|
363
|
+
/** @category Subscription & Loading */
|
364
|
+
subscribe<M extends CoMap, Depth>(
|
365
|
+
this: M,
|
366
|
+
depth: Depth & DepthsIn<M>,
|
367
|
+
listener: (value: DeeplyLoaded<M, Depth>) => void,
|
368
|
+
): () => void {
|
369
|
+
return subscribeToExistingCoValue(this, depth, listener);
|
370
|
+
}
|
300
371
|
}
|
301
372
|
|
302
373
|
export type CoKeys<Map extends object> = Exclude<
|
package/src/coValues/coStream.ts
CHANGED
@@ -16,8 +16,12 @@ import type {
|
|
16
16
|
Group,
|
17
17
|
ID,
|
18
18
|
IfCo,
|
19
|
-
ClassOf,
|
20
19
|
UnCo,
|
20
|
+
AccountCtx,
|
21
|
+
CoValueClass,
|
22
|
+
DeeplyLoaded,
|
23
|
+
DepthsIn,
|
24
|
+
UnavailableError,
|
21
25
|
} from "../internal.js";
|
22
26
|
import {
|
23
27
|
ItemsSym,
|
@@ -29,8 +33,15 @@ import {
|
|
29
33
|
InitValues,
|
30
34
|
SchemaInit,
|
31
35
|
isRefEncoded,
|
36
|
+
loadCoValue,
|
37
|
+
loadCoValueEf,
|
38
|
+
subscribeToCoValue,
|
39
|
+
subscribeToCoValueEf,
|
40
|
+
ensureCoValueLoaded,
|
41
|
+
subscribeToExistingCoValue,
|
32
42
|
} from "../internal.js";
|
33
43
|
import { encodeSync, decodeSync } from "@effect/schema/Schema";
|
44
|
+
import { Effect, Stream } from "effect";
|
34
45
|
|
35
46
|
export type CoStreamEntry<Item> = SingleCoStreamEntry<Item> & {
|
36
47
|
all: IterableIterator<SingleCoStreamEntry<Item>>;
|
@@ -46,10 +57,7 @@ export type SingleCoStreamEntry<Item> = {
|
|
46
57
|
|
47
58
|
/** @category CoValues */
|
48
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
49
|
-
export class CoStream<Item = any>
|
50
|
-
extends CoValueBase
|
51
|
-
implements CoValue<"CoStream", RawCoStream>
|
52
|
-
{
|
60
|
+
export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
53
61
|
static Of<Item>(item: IfCo<Item, Item>): typeof CoStream<Item> {
|
54
62
|
return class CoStreamOf extends CoStream<Item> {
|
55
63
|
[co.items] = item;
|
@@ -114,7 +122,7 @@ export class CoStream<Item = any>
|
|
114
122
|
}
|
115
123
|
|
116
124
|
static create<S extends CoStream>(
|
117
|
-
this:
|
125
|
+
this: CoValueClass<S>,
|
118
126
|
init: S extends CoStream<infer Item> ? UnCo<Item>[] : never,
|
119
127
|
options: { owner: Account | Group },
|
120
128
|
) {
|
@@ -178,6 +186,62 @@ export class CoStream<Item = any>
|
|
178
186
|
this._schema ||= {};
|
179
187
|
Object.assign(this._schema, def);
|
180
188
|
}
|
189
|
+
|
190
|
+
/** @category Subscription & Loading */
|
191
|
+
static load<S extends CoStream, Depth>(
|
192
|
+
this: CoValueClass<S>,
|
193
|
+
id: ID<S>,
|
194
|
+
as: Account,
|
195
|
+
depth: Depth & DepthsIn<S>,
|
196
|
+
): Promise<DeeplyLoaded<S, Depth> | undefined> {
|
197
|
+
return loadCoValue(this, id, as, depth);
|
198
|
+
}
|
199
|
+
|
200
|
+
/** @category Subscription & Loading */
|
201
|
+
static loadEf<S extends CoStream, Depth>(
|
202
|
+
this: CoValueClass<S>,
|
203
|
+
id: ID<S>,
|
204
|
+
depth: Depth & DepthsIn<S>,
|
205
|
+
): Effect.Effect<DeeplyLoaded<S, Depth>, UnavailableError, AccountCtx> {
|
206
|
+
return loadCoValueEf<S, Depth>(this, id, depth);
|
207
|
+
}
|
208
|
+
|
209
|
+
/** @category Subscription & Loading */
|
210
|
+
static subscribe<S extends CoStream, Depth>(
|
211
|
+
this: CoValueClass<S>,
|
212
|
+
id: ID<S>,
|
213
|
+
as: Account,
|
214
|
+
depth: Depth & DepthsIn<S>,
|
215
|
+
listener: (value: DeeplyLoaded<S, Depth>) => void,
|
216
|
+
): () => void {
|
217
|
+
return subscribeToCoValue<S, Depth>(this, id, as, depth, listener);
|
218
|
+
}
|
219
|
+
|
220
|
+
/** @category Subscription & Loading */
|
221
|
+
static subscribeEf<S extends CoStream, Depth>(
|
222
|
+
this: CoValueClass<S>,
|
223
|
+
id: ID<S>,
|
224
|
+
depth: Depth & DepthsIn<S>,
|
225
|
+
): Stream.Stream<DeeplyLoaded<S, Depth>, UnavailableError, AccountCtx> {
|
226
|
+
return subscribeToCoValueEf<S, Depth>(this, id, depth);
|
227
|
+
}
|
228
|
+
|
229
|
+
/** @category Subscription & Loading */
|
230
|
+
ensureLoaded<S extends CoStream, Depth>(
|
231
|
+
this: S,
|
232
|
+
depth: Depth & DepthsIn<S>,
|
233
|
+
): Promise<DeeplyLoaded<S, Depth> | undefined> {
|
234
|
+
return ensureCoValueLoaded(this, depth);
|
235
|
+
}
|
236
|
+
|
237
|
+
/** @category Subscription & Loading */
|
238
|
+
subscribe<S extends CoStream, Depth>(
|
239
|
+
this: S,
|
240
|
+
depth: Depth & DepthsIn<S>,
|
241
|
+
listener: (value: DeeplyLoaded<S, Depth>) => void,
|
242
|
+
): () => void {
|
243
|
+
return subscribeToExistingCoValue(this, depth, listener);
|
244
|
+
}
|
181
245
|
}
|
182
246
|
|
183
247
|
function entryFromRawEntry<Item>(
|
@@ -437,10 +501,7 @@ const CoStreamPerSessionProxyHandler = (
|
|
437
501
|
});
|
438
502
|
|
439
503
|
/** @category CoValues */
|
440
|
-
export class BinaryCoStream
|
441
|
-
extends CoValueBase
|
442
|
-
implements CoValue<"BinaryCoStream", RawBinaryCoStream>
|
443
|
-
{
|
504
|
+
export class BinaryCoStream extends CoValueBase implements CoValue {
|
444
505
|
declare id: ID<this>;
|
445
506
|
declare _type: "BinaryCoStream";
|
446
507
|
declare _raw: RawBinaryCoStream;
|
@@ -476,7 +537,7 @@ export class BinaryCoStream
|
|
476
537
|
}
|
477
538
|
|
478
539
|
static create<S extends BinaryCoStream>(
|
479
|
-
this:
|
540
|
+
this: CoValueClass<S>,
|
480
541
|
options: { owner: Account | Group },
|
481
542
|
) {
|
482
543
|
return new this(options);
|
@@ -584,4 +645,60 @@ export class BinaryCoStream
|
|
584
645
|
[inspect]() {
|
585
646
|
return this.toJSON();
|
586
647
|
}
|
648
|
+
|
649
|
+
/** @category Subscription & Loading */
|
650
|
+
static load<B extends BinaryCoStream, Depth>(
|
651
|
+
this: CoValueClass<B>,
|
652
|
+
id: ID<B>,
|
653
|
+
as: Account,
|
654
|
+
depth: Depth & DepthsIn<B>,
|
655
|
+
): Promise<DeeplyLoaded<B, Depth> | undefined> {
|
656
|
+
return loadCoValue(this, id, as, depth);
|
657
|
+
}
|
658
|
+
|
659
|
+
/** @category Subscription & Loading */
|
660
|
+
static loadEf<B extends BinaryCoStream, Depth>(
|
661
|
+
this: CoValueClass<B>,
|
662
|
+
id: ID<B>,
|
663
|
+
depth: Depth & DepthsIn<B>,
|
664
|
+
): Effect.Effect<DeeplyLoaded<B, Depth>, UnavailableError, AccountCtx> {
|
665
|
+
return loadCoValueEf<B, Depth>(this, id, depth);
|
666
|
+
}
|
667
|
+
|
668
|
+
/** @category Subscription & Loading */
|
669
|
+
static subscribe<B extends BinaryCoStream, Depth>(
|
670
|
+
this: CoValueClass<B>,
|
671
|
+
id: ID<B>,
|
672
|
+
as: Account,
|
673
|
+
depth: Depth & DepthsIn<B>,
|
674
|
+
listener: (value: DeeplyLoaded<B, Depth>) => void,
|
675
|
+
): () => void {
|
676
|
+
return subscribeToCoValue<B, Depth>(this, id, as, depth, listener);
|
677
|
+
}
|
678
|
+
|
679
|
+
/** @category Subscription & Loading */
|
680
|
+
static subscribeEf<B extends BinaryCoStream, Depth>(
|
681
|
+
this: CoValueClass<B>,
|
682
|
+
id: ID<B>,
|
683
|
+
depth: Depth & DepthsIn<B>,
|
684
|
+
): Stream.Stream<DeeplyLoaded<B, Depth>, UnavailableError, AccountCtx> {
|
685
|
+
return subscribeToCoValueEf<B, Depth>(this, id, depth);
|
686
|
+
}
|
687
|
+
|
688
|
+
/** @category Subscription & Loading */
|
689
|
+
ensureLoaded<B extends BinaryCoStream, Depth>(
|
690
|
+
this: B,
|
691
|
+
depth: Depth & DepthsIn<B>,
|
692
|
+
): Promise<DeeplyLoaded<B, Depth> | undefined> {
|
693
|
+
return ensureCoValueLoaded(this, depth);
|
694
|
+
}
|
695
|
+
|
696
|
+
/** @category Subscription & Loading */
|
697
|
+
subscribe<B extends BinaryCoStream, Depth>(
|
698
|
+
this: B,
|
699
|
+
depth: Depth & DepthsIn<B>,
|
700
|
+
listener: (value: DeeplyLoaded<B, Depth>) => void,
|
701
|
+
): () => void {
|
702
|
+
return subscribeToExistingCoValue(this, depth, listener);
|
703
|
+
}
|
587
704
|
}
|