jazz-tools 0.7.0-alpha.0 → 0.7.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +8 -1
- package/CHANGELOG.md +8 -0
- package/dist/coValues/account.js +138 -0
- package/dist/coValues/account.js.map +1 -0
- package/dist/coValues/coList.js +196 -0
- package/dist/coValues/coList.js.map +1 -0
- package/dist/coValues/coMap.js +249 -0
- package/dist/coValues/coMap.js.map +1 -0
- package/dist/coValues/coStream.js +189 -0
- package/dist/coValues/coStream.js.map +1 -0
- package/dist/coValues/extensions/imageDef.js +17 -12
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +96 -0
- package/dist/coValues/group.js.map +1 -0
- package/dist/coValues/interfaces.js +58 -0
- package/dist/coValues/interfaces.js.map +1 -0
- package/dist/implementation/errors.js.map +1 -0
- package/dist/implementation/inspect.js +2 -0
- package/dist/implementation/inspect.js.map +1 -0
- package/dist/{refs.js → implementation/refs.js} +11 -13
- package/dist/implementation/refs.js.map +1 -0
- package/dist/implementation/schema.js +6 -0
- package/dist/implementation/schema.js.map +1 -0
- package/dist/{subscriptionScope.js → implementation/subscriptionScope.js} +1 -1
- package/dist/implementation/subscriptionScope.js.map +1 -0
- package/dist/index.js +23 -27
- package/dist/index.js.map +1 -1
- package/dist/internal.js +13 -0
- package/dist/internal.js.map +1 -0
- package/dist/tests/coList.test.js +26 -22
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +91 -43
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +35 -24
- package/dist/tests/coStream.test.js.map +1 -1
- package/package.json +11 -4
- package/src/coValues/account.ts +297 -0
- package/src/coValues/coList.ts +320 -0
- package/src/coValues/coMap.ts +447 -0
- package/src/coValues/coStream.ts +325 -0
- package/src/coValues/extensions/imageDef.ts +24 -16
- package/src/coValues/group.ts +187 -0
- package/src/coValues/interfaces.ts +216 -0
- package/src/implementation/inspect.ts +2 -0
- package/src/{refs.ts → implementation/refs.ts} +21 -32
- package/src/implementation/schema.ts +69 -0
- package/src/{subscriptionScope.ts → implementation/subscriptionScope.ts} +11 -13
- package/src/index.ts +22 -50
- package/src/internal.ts +15 -0
- package/src/tests/coList.test.ts +27 -25
- package/src/tests/coMap.test.ts +125 -50
- package/src/tests/coStream.test.ts +51 -38
- package/dist/coValueInterfaces.js +0 -8
- package/dist/coValueInterfaces.js.map +0 -1
- package/dist/coValues/account/account.js +0 -11
- package/dist/coValues/account/account.js.map +0 -1
- package/dist/coValues/account/accountOf.js +0 -150
- package/dist/coValues/account/accountOf.js.map +0 -1
- package/dist/coValues/account/migration.js +0 -4
- package/dist/coValues/account/migration.js.map +0 -1
- package/dist/coValues/coList/coList.js +0 -2
- package/dist/coValues/coList/coList.js.map +0 -1
- package/dist/coValues/coList/coListOf.js +0 -235
- package/dist/coValues/coList/coListOf.js.map +0 -1
- package/dist/coValues/coList/internalDocs.js +0 -2
- package/dist/coValues/coList/internalDocs.js.map +0 -1
- package/dist/coValues/coMap/coMap.js +0 -2
- package/dist/coValues/coMap/coMap.js.map +0 -1
- package/dist/coValues/coMap/coMapOf.js +0 -262
- package/dist/coValues/coMap/coMapOf.js.map +0 -1
- package/dist/coValues/coMap/internalDocs.js +0 -2
- package/dist/coValues/coMap/internalDocs.js.map +0 -1
- package/dist/coValues/coStream/coStream.js +0 -2
- package/dist/coValues/coStream/coStream.js.map +0 -1
- package/dist/coValues/coStream/coStreamOf.js +0 -244
- package/dist/coValues/coStream/coStreamOf.js.map +0 -1
- package/dist/coValues/construction.js +0 -34
- package/dist/coValues/construction.js.map +0 -1
- package/dist/coValues/group/group.js +0 -2
- package/dist/coValues/group/group.js.map +0 -1
- package/dist/coValues/group/groupOf.js +0 -109
- package/dist/coValues/group/groupOf.js.map +0 -1
- package/dist/coValues/resolution.js +0 -66
- package/dist/coValues/resolution.js.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/refs.js.map +0 -1
- package/dist/schemaHelpers.js +0 -14
- package/dist/schemaHelpers.js.map +0 -1
- package/dist/subscriptionScope.js.map +0 -1
- package/dist/tests/types.test.js +0 -33
- package/dist/tests/types.test.js.map +0 -1
- package/src/coValueInterfaces.ts +0 -105
- package/src/coValues/account/account.ts +0 -106
- package/src/coValues/account/accountOf.ts +0 -284
- package/src/coValues/account/migration.ts +0 -12
- package/src/coValues/coList/coList.ts +0 -57
- package/src/coValues/coList/coListOf.ts +0 -377
- package/src/coValues/coList/internalDocs.ts +0 -1
- package/src/coValues/coMap/coMap.ts +0 -110
- package/src/coValues/coMap/coMapOf.ts +0 -451
- package/src/coValues/coMap/internalDocs.ts +0 -1
- package/src/coValues/coStream/coStream.ts +0 -63
- package/src/coValues/coStream/coStreamOf.ts +0 -404
- package/src/coValues/construction.ts +0 -110
- package/src/coValues/group/group.ts +0 -27
- package/src/coValues/group/groupOf.ts +0 -183
- package/src/coValues/resolution.ts +0 -111
- package/src/schemaHelpers.ts +0 -72
- package/src/tests/types.test.ts +0 -37
- /package/dist/{errors.js → implementation/errors.js} +0 -0
- /package/src/{errors.ts → implementation/errors.ts} +0 -0
@@ -1,404 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
AccountID,
|
3
|
-
AgentID,
|
4
|
-
BinaryStreamInfo,
|
5
|
-
CojsonInternalTypes,
|
6
|
-
JsonValue,
|
7
|
-
RawAccount,
|
8
|
-
RawBinaryCoStream,
|
9
|
-
RawCoStream,
|
10
|
-
SessionID,
|
11
|
-
cojsonInternals,
|
12
|
-
} from "cojson";
|
13
|
-
import {
|
14
|
-
CoValue,
|
15
|
-
CoValueSchema,
|
16
|
-
ID,
|
17
|
-
inspect,
|
18
|
-
} from "../../coValueInterfaces.js";
|
19
|
-
import { AnyAccount, ControlledAccount } from "../account/account.js";
|
20
|
-
import { AnyGroup } from "../group/group.js";
|
21
|
-
import {
|
22
|
-
BinaryCoStream,
|
23
|
-
BinaryCoStreamSchema,
|
24
|
-
CoStream,
|
25
|
-
CoStreamSchema,
|
26
|
-
} from "./coStream.js";
|
27
|
-
import { SharedCoValueConstructor } from "../construction.js";
|
28
|
-
import { AST, Schema } from "@effect/schema";
|
29
|
-
import {
|
30
|
-
constructorOfSchemaSym,
|
31
|
-
propertyIsCoValueSchema,
|
32
|
-
} from "../resolution.js";
|
33
|
-
import { pipeArguments } from "effect/Pipeable";
|
34
|
-
import { ValueRef } from "../../refs.js";
|
35
|
-
import { SchemaWithOutput } from "../../schemaHelpers.js";
|
36
|
-
import { Account, controlledAccountFromNode } from "../account/accountOf.js";
|
37
|
-
import { Group } from "../group/groupOf.js";
|
38
|
-
|
39
|
-
export function CoStreamOf<
|
40
|
-
Item extends SchemaWithOutput<CoValue> | SchemaWithOutput<JsonValue>,
|
41
|
-
>(itemSchema: Item) {
|
42
|
-
const decodeItem = Schema.decodeSync(itemSchema);
|
43
|
-
const encodeItem = Schema.encodeSync(itemSchema);
|
44
|
-
const itemIsCoValue = propertyIsCoValueSchema(itemSchema);
|
45
|
-
|
46
|
-
class CoStreamOfItem extends SharedCoValueConstructor {
|
47
|
-
static get ast() {
|
48
|
-
return AST.setAnnotation(
|
49
|
-
Schema.instanceOf(this).ast,
|
50
|
-
constructorOfSchemaSym,
|
51
|
-
this
|
52
|
-
);
|
53
|
-
}
|
54
|
-
static [Schema.TypeId]: Schema.Schema.Variance<
|
55
|
-
CoStreamOfItem,
|
56
|
-
CoStreamOfItem,
|
57
|
-
never
|
58
|
-
>[Schema.TypeId];
|
59
|
-
static pipe() {
|
60
|
-
// eslint-disable-next-line prefer-rest-params
|
61
|
-
return pipeArguments(this, arguments);
|
62
|
-
}
|
63
|
-
static type = "CoStream" as const;
|
64
|
-
|
65
|
-
id!: ID<this>;
|
66
|
-
_type!: "CoStream";
|
67
|
-
_owner!: AnyAccount | AnyGroup;
|
68
|
-
_raw!: RawCoStream;
|
69
|
-
_loadedAs!: ControlledAccount;
|
70
|
-
_schema!: typeof CoStreamOfItem;
|
71
|
-
|
72
|
-
by: CoStream<Item>["by"];
|
73
|
-
in: CoStream<Item>["in"];
|
74
|
-
|
75
|
-
constructor(
|
76
|
-
init: Schema.Schema.To<Item>[] | undefined,
|
77
|
-
options: { owner: AnyAccount | AnyGroup } | { fromRaw: RawCoStream }
|
78
|
-
) {
|
79
|
-
super();
|
80
|
-
|
81
|
-
let raw: RawCoStream;
|
82
|
-
|
83
|
-
if ("fromRaw" in options) {
|
84
|
-
raw = options.fromRaw;
|
85
|
-
} else {
|
86
|
-
const rawOwner = options.owner._raw;
|
87
|
-
|
88
|
-
raw = rawOwner.createStream();
|
89
|
-
}
|
90
|
-
|
91
|
-
this.by = {} as CoStream<Item>["by"];
|
92
|
-
this.in = {} as CoStream<Item>["in"];
|
93
|
-
|
94
|
-
Object.defineProperties(this, {
|
95
|
-
id: { value: raw.id, enumerable: false },
|
96
|
-
_type: { value: "CoStream", enumerable: false },
|
97
|
-
_owner: {
|
98
|
-
get: () =>
|
99
|
-
raw.group instanceof RawAccount
|
100
|
-
? Account.fromRaw(raw.group)
|
101
|
-
: Group.fromRaw(raw.group),
|
102
|
-
enumerable: false,
|
103
|
-
},
|
104
|
-
_raw: { value: raw, enumerable: false },
|
105
|
-
_loadedAs: {
|
106
|
-
get: () => controlledAccountFromNode(raw.core.node),
|
107
|
-
enumerable: false,
|
108
|
-
},
|
109
|
-
_schema: { value: this.constructor, enumerable: false },
|
110
|
-
});
|
111
|
-
|
112
|
-
if (init !== undefined) {
|
113
|
-
for (const item of init) {
|
114
|
-
this.pushItem(item);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
|
118
|
-
this.updateEntries();
|
119
|
-
}
|
120
|
-
|
121
|
-
private updateEntries() {
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
123
|
-
const self = this;
|
124
|
-
const raw = this._raw;
|
125
|
-
const loadedAs = this._loadedAs;
|
126
|
-
|
127
|
-
for (const accountID of this._raw.accounts() as unknown as Set<
|
128
|
-
ID<AnyAccount>
|
129
|
-
>) {
|
130
|
-
Object.defineProperty(this.by, accountID, {
|
131
|
-
get() {
|
132
|
-
const rawEntry = raw.lastItemBy(
|
133
|
-
accountID as unknown as AccountID
|
134
|
-
);
|
135
|
-
|
136
|
-
if (!rawEntry) return;
|
137
|
-
return entryFromRawEntry(
|
138
|
-
self,
|
139
|
-
rawEntry,
|
140
|
-
loadedAs,
|
141
|
-
accountID
|
142
|
-
);
|
143
|
-
},
|
144
|
-
configurable: true,
|
145
|
-
});
|
146
|
-
}
|
147
|
-
Object.defineProperty(this.by, "me", {
|
148
|
-
get() {
|
149
|
-
return self.by[loadedAs.id];
|
150
|
-
},
|
151
|
-
enumerable: false,
|
152
|
-
configurable: true,
|
153
|
-
});
|
154
|
-
|
155
|
-
for (const sessionID of raw.sessions() as unknown as Set<SessionID>) {
|
156
|
-
Object.defineProperty(this.in, sessionID, {
|
157
|
-
get() {
|
158
|
-
const rawEntry = raw.lastItemIn(
|
159
|
-
sessionID as unknown as SessionID
|
160
|
-
);
|
161
|
-
|
162
|
-
if (!rawEntry) return;
|
163
|
-
const by =
|
164
|
-
cojsonInternals.accountOrAgentIDfromSessionID(
|
165
|
-
sessionID
|
166
|
-
);
|
167
|
-
return entryFromRawEntry(
|
168
|
-
self,
|
169
|
-
rawEntry,
|
170
|
-
loadedAs,
|
171
|
-
cojsonInternals.isAccountID(by)
|
172
|
-
? (by as unknown as ID<AnyAccount>)
|
173
|
-
: undefined
|
174
|
-
);
|
175
|
-
},
|
176
|
-
configurable: true,
|
177
|
-
});
|
178
|
-
}
|
179
|
-
Object.defineProperty(this.in, "currentSession", {
|
180
|
-
get() {
|
181
|
-
return self.in[loadedAs.sessionID];
|
182
|
-
},
|
183
|
-
enumerable: false,
|
184
|
-
configurable: true,
|
185
|
-
});
|
186
|
-
}
|
187
|
-
|
188
|
-
static fromRaw(raw: RawCoStream) {
|
189
|
-
return new CoStreamOfItem(undefined, { fromRaw: raw });
|
190
|
-
}
|
191
|
-
|
192
|
-
push(...items: Schema.Schema.To<Item>[]) {
|
193
|
-
for (const item of items) {
|
194
|
-
this.pushItem(item);
|
195
|
-
}
|
196
|
-
this.updateEntries();
|
197
|
-
}
|
198
|
-
|
199
|
-
private pushItem(item: Schema.Schema.To<Item>) {
|
200
|
-
if (itemIsCoValue) {
|
201
|
-
this._raw.push(item.id);
|
202
|
-
} else {
|
203
|
-
this._raw.push(encodeItem(item));
|
204
|
-
}
|
205
|
-
}
|
206
|
-
|
207
|
-
toJSON() {
|
208
|
-
return {
|
209
|
-
by: Object.fromEntries(
|
210
|
-
Object.entries(this.by).map(([key, value]) => [
|
211
|
-
key,
|
212
|
-
value &&
|
213
|
-
typeof value === "object" &&
|
214
|
-
"toJSON" in value &&
|
215
|
-
typeof value.toJSON === "function"
|
216
|
-
? value.toJSON()
|
217
|
-
: value,
|
218
|
-
])
|
219
|
-
),
|
220
|
-
in: Object.fromEntries(
|
221
|
-
Object.entries(this.in).map(([key, value]) => [
|
222
|
-
key,
|
223
|
-
value &&
|
224
|
-
typeof value === "object" &&
|
225
|
-
"toJSON" in value &&
|
226
|
-
typeof value.toJSON === "function"
|
227
|
-
? value.toJSON()
|
228
|
-
: value,
|
229
|
-
])
|
230
|
-
),
|
231
|
-
co: {
|
232
|
-
id: this.id,
|
233
|
-
type: "CoStream",
|
234
|
-
},
|
235
|
-
};
|
236
|
-
}
|
237
|
-
|
238
|
-
[inspect]() {
|
239
|
-
return this.toJSON();
|
240
|
-
}
|
241
|
-
|
242
|
-
static as<SubClass>() {
|
243
|
-
return CoStreamOfItem as unknown as CoStreamSchema<SubClass, Item>;
|
244
|
-
}
|
245
|
-
}
|
246
|
-
|
247
|
-
return CoStreamOfItem as CoStreamSchema<CoStreamOfItem, Item> & {
|
248
|
-
as<SubClass>(): CoStreamSchema<SubClass, Item>;
|
249
|
-
};
|
250
|
-
|
251
|
-
function entryFromRawEntry(
|
252
|
-
accessFrom: CoValue,
|
253
|
-
rawEntry: {
|
254
|
-
by: AccountID | AgentID;
|
255
|
-
tx: CojsonInternalTypes.TransactionID;
|
256
|
-
at: Date;
|
257
|
-
value: JsonValue;
|
258
|
-
},
|
259
|
-
loadedAs: ControlledAccount,
|
260
|
-
accountID: ID<AnyAccount> | undefined
|
261
|
-
) {
|
262
|
-
return {
|
263
|
-
get value(): Schema.Schema.To<Item> | undefined {
|
264
|
-
if (itemIsCoValue) {
|
265
|
-
return this.ref?.accessFrom(accessFrom);
|
266
|
-
} else {
|
267
|
-
return decodeItem(rawEntry.value);
|
268
|
-
}
|
269
|
-
},
|
270
|
-
get ref() {
|
271
|
-
if (itemIsCoValue) {
|
272
|
-
const rawId = rawEntry.value;
|
273
|
-
return new ValueRef(
|
274
|
-
rawId as unknown as ID<Schema.Schema.To<Item>>,
|
275
|
-
loadedAs,
|
276
|
-
itemSchema
|
277
|
-
);
|
278
|
-
}
|
279
|
-
},
|
280
|
-
get by() {
|
281
|
-
return (
|
282
|
-
accountID &&
|
283
|
-
new ValueRef(
|
284
|
-
accountID as unknown as ID<AnyAccount>,
|
285
|
-
loadedAs,
|
286
|
-
Account
|
287
|
-
)?.accessFrom(accessFrom)
|
288
|
-
);
|
289
|
-
},
|
290
|
-
madeAt: rawEntry.at,
|
291
|
-
tx: rawEntry.tx,
|
292
|
-
};
|
293
|
-
}
|
294
|
-
}
|
295
|
-
|
296
|
-
class BinaryCoStreamImplClass
|
297
|
-
extends SharedCoValueConstructor
|
298
|
-
implements BinaryCoStream
|
299
|
-
{
|
300
|
-
static ast = AST.setAnnotation(
|
301
|
-
Schema.instanceOf(this).ast,
|
302
|
-
constructorOfSchemaSym,
|
303
|
-
this
|
304
|
-
);
|
305
|
-
static [Schema.TypeId]: Schema.Schema.Variance<
|
306
|
-
BinaryCoStream,
|
307
|
-
BinaryCoStream,
|
308
|
-
never
|
309
|
-
>[Schema.TypeId];
|
310
|
-
static pipe() {
|
311
|
-
// eslint-disable-next-line prefer-rest-params
|
312
|
-
return pipeArguments(this, arguments);
|
313
|
-
}
|
314
|
-
static type = "BinaryCoStream" as const;
|
315
|
-
|
316
|
-
id!: ID<this>;
|
317
|
-
_type!: "BinaryCoStream";
|
318
|
-
_owner!: AnyAccount | AnyGroup;
|
319
|
-
_raw!: RawBinaryCoStream;
|
320
|
-
_loadedAs!: ControlledAccount;
|
321
|
-
_schema!: typeof BinaryCoStreamImplClass;
|
322
|
-
|
323
|
-
constructor(
|
324
|
-
init: [] | undefined,
|
325
|
-
options:
|
326
|
-
| {
|
327
|
-
owner: AnyAccount | AnyGroup;
|
328
|
-
}
|
329
|
-
| {
|
330
|
-
fromRaw: RawBinaryCoStream;
|
331
|
-
}
|
332
|
-
) {
|
333
|
-
super();
|
334
|
-
|
335
|
-
let raw: RawBinaryCoStream;
|
336
|
-
|
337
|
-
if ("fromRaw" in options) {
|
338
|
-
raw = options.fromRaw;
|
339
|
-
} else {
|
340
|
-
const rawOwner = options.owner._raw;
|
341
|
-
|
342
|
-
raw = rawOwner.createBinaryStream();
|
343
|
-
}
|
344
|
-
|
345
|
-
Object.defineProperties(this, {
|
346
|
-
id: { value: raw.id, enumerable: false },
|
347
|
-
_type: { value: "BinaryCoStream", enumerable: false },
|
348
|
-
_owner: {
|
349
|
-
get: () =>
|
350
|
-
raw.group instanceof RawAccount
|
351
|
-
? Account.fromRaw(raw.group)
|
352
|
-
: Group.fromRaw(raw.group),
|
353
|
-
enumerable: false,
|
354
|
-
},
|
355
|
-
_raw: { value: raw, enumerable: false },
|
356
|
-
_loadedAs: {
|
357
|
-
get: () => controlledAccountFromNode(raw.core.node),
|
358
|
-
enumerable: false,
|
359
|
-
},
|
360
|
-
_schema: { value: this.constructor, enumerable: false },
|
361
|
-
});
|
362
|
-
}
|
363
|
-
|
364
|
-
static fromRaw(raw: RawBinaryCoStream) {
|
365
|
-
return new BinaryCoStreamImplClass(undefined, { fromRaw: raw });
|
366
|
-
}
|
367
|
-
|
368
|
-
getChunks(options?: {
|
369
|
-
allowUnfinished?: boolean;
|
370
|
-
}):
|
371
|
-
| (BinaryStreamInfo & { chunks: Uint8Array[]; finished: boolean })
|
372
|
-
| undefined {
|
373
|
-
return this._raw.getBinaryChunks(options?.allowUnfinished);
|
374
|
-
}
|
375
|
-
|
376
|
-
start(options: BinaryStreamInfo): void {
|
377
|
-
this._raw.startBinaryStream(options);
|
378
|
-
}
|
379
|
-
|
380
|
-
push(data: Uint8Array): void {
|
381
|
-
this._raw.pushBinaryStreamChunk(data);
|
382
|
-
}
|
383
|
-
|
384
|
-
end(): void {
|
385
|
-
this._raw.endBinaryStream();
|
386
|
-
}
|
387
|
-
|
388
|
-
toJSON(): object | any[] {
|
389
|
-
return {
|
390
|
-
...this.getChunks(),
|
391
|
-
co: {
|
392
|
-
id: this.id,
|
393
|
-
type: "BinaryCoStream",
|
394
|
-
},
|
395
|
-
};
|
396
|
-
}
|
397
|
-
|
398
|
-
[inspect]() {
|
399
|
-
return this.toJSON();
|
400
|
-
}
|
401
|
-
}
|
402
|
-
|
403
|
-
export const BinaryCoStreamImpl =
|
404
|
-
BinaryCoStreamImplClass as BinaryCoStreamSchema;
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import { Effect, Sink, Stream } from "effect";
|
2
|
-
import {
|
3
|
-
CoValueSchema,
|
4
|
-
CoValue,
|
5
|
-
ID,
|
6
|
-
SubclassedConstructor,
|
7
|
-
} from "../coValueInterfaces.js";
|
8
|
-
import { UnavailableError } from "../errors.js";
|
9
|
-
import { ControlledAccount, ControlledAccountCtx } from "./account/account.js";
|
10
|
-
import { ValueRef } from "../refs.js";
|
11
|
-
import { SubscriptionScope } from "../subscriptionScope.js";
|
12
|
-
|
13
|
-
export abstract class SharedCoValueConstructor {
|
14
|
-
id!: ID<this>;
|
15
|
-
_schema!: CoValueSchema;
|
16
|
-
_loadedAs!: ControlledAccount;
|
17
|
-
|
18
|
-
static loadEf<V extends CoValue>(
|
19
|
-
this: CoValueSchema & SubclassedConstructor<V>,
|
20
|
-
id: ID<V>
|
21
|
-
): Effect.Effect<V, UnavailableError, ControlledAccountCtx> {
|
22
|
-
return Effect.gen(this, function* (_) {
|
23
|
-
const controlledAccount = yield* _(ControlledAccountCtx);
|
24
|
-
return yield* _(
|
25
|
-
new ValueRef(id as ID<V>, controlledAccount, this).loadEf()
|
26
|
-
);
|
27
|
-
});
|
28
|
-
}
|
29
|
-
|
30
|
-
static load<V extends CoValue>(
|
31
|
-
this: CoValueSchema & SubclassedConstructor<V>,
|
32
|
-
id: ID<V>,
|
33
|
-
options: {
|
34
|
-
as: ControlledAccount;
|
35
|
-
onProgress?: (progress: number) => void;
|
36
|
-
}
|
37
|
-
): Promise<V | undefined> {
|
38
|
-
return new ValueRef(id as ID<V>, options.as, this).load(
|
39
|
-
options?.onProgress && { onProgress: options.onProgress }
|
40
|
-
);
|
41
|
-
}
|
42
|
-
|
43
|
-
static subscribe<V extends CoValue>(
|
44
|
-
this: CoValueSchema & SubclassedConstructor<V>,
|
45
|
-
id: ID<V>,
|
46
|
-
options: { as: ControlledAccount },
|
47
|
-
onUpdate: (value: V) => void
|
48
|
-
): () => void {
|
49
|
-
void Effect.runPromise(
|
50
|
-
Effect.provideService(
|
51
|
-
this.subscribeEf(id).pipe(
|
52
|
-
Stream.run(
|
53
|
-
Sink.forEach((update) =>
|
54
|
-
Effect.sync(() => onUpdate(update))
|
55
|
-
)
|
56
|
-
)
|
57
|
-
),
|
58
|
-
ControlledAccountCtx,
|
59
|
-
options.as
|
60
|
-
)
|
61
|
-
);
|
62
|
-
|
63
|
-
return function unsubscribe() {};
|
64
|
-
}
|
65
|
-
|
66
|
-
static subscribeEf<V extends CoValue>(
|
67
|
-
this: CoValueSchema & SubclassedConstructor<V>,
|
68
|
-
id: ID<V>
|
69
|
-
): Stream.Stream<V, UnavailableError, ControlledAccountCtx> {
|
70
|
-
return Stream.fromEffect(this.loadEf(id)).pipe(
|
71
|
-
Stream.flatMap((value) =>
|
72
|
-
Stream.asyncScoped<V, UnavailableError>((emit) =>
|
73
|
-
Effect.gen(this, function* (_) {
|
74
|
-
const subscription = new SubscriptionScope(
|
75
|
-
value,
|
76
|
-
this,
|
77
|
-
(update) => {
|
78
|
-
void emit.single(update as V);
|
79
|
-
}
|
80
|
-
);
|
81
|
-
|
82
|
-
yield* _(
|
83
|
-
Effect.addFinalizer(() =>
|
84
|
-
Effect.sync(() => subscription.unsubscribeAll())
|
85
|
-
)
|
86
|
-
);
|
87
|
-
})
|
88
|
-
)
|
89
|
-
)
|
90
|
-
);
|
91
|
-
}
|
92
|
-
|
93
|
-
subscribe(listener: (update: this) => void): () => void {
|
94
|
-
return (this._schema as unknown as CoValueSchema).subscribe(
|
95
|
-
this.id as unknown as ID<CoValue>,
|
96
|
-
{ as: this._loadedAs },
|
97
|
-
listener as unknown as (update: CoValue) => void
|
98
|
-
);
|
99
|
-
}
|
100
|
-
|
101
|
-
subscribeEf(): Stream.Stream<this, UnavailableError, never> {
|
102
|
-
return Stream.provideService(
|
103
|
-
(this._schema as unknown as CoValueSchema).subscribeEf(
|
104
|
-
this.id as unknown as ID<CoValue>
|
105
|
-
),
|
106
|
-
ControlledAccountCtx,
|
107
|
-
this._loadedAs
|
108
|
-
) as unknown as Stream.Stream<this, UnavailableError, never>;
|
109
|
-
}
|
110
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import * as S from "@effect/schema/Schema";
|
2
|
-
import { Everyone, RawGroup, Role } from "cojson";
|
3
|
-
import { CoValue, CoValueSchema } from "../../coValueInterfaces.js";
|
4
|
-
import { ValueRef } from "../../refs.js";
|
5
|
-
import { AnyAccount } from "../account/account.js";
|
6
|
-
|
7
|
-
export interface AnyGroup<
|
8
|
-
P extends CoValueSchema | S.Schema<null> = CoValueSchema | S.Schema<null>,
|
9
|
-
R extends CoValueSchema | S.Schema<null> = CoValueSchema | S.Schema<null>,
|
10
|
-
> extends CoValue<"Group", RawGroup> {
|
11
|
-
profile?: S.Schema.To<P>;
|
12
|
-
root?: S.Schema.To<R>;
|
13
|
-
_refs: {
|
14
|
-
profile: ValueRef<S.Schema.To<P>>;
|
15
|
-
root: ValueRef<S.Schema.To<R>>;
|
16
|
-
};
|
17
|
-
addMember(member: Everyone | AnyAccount, role: Role): this;
|
18
|
-
myRole(): Role | undefined;
|
19
|
-
}
|
20
|
-
|
21
|
-
export interface GroupSchema<
|
22
|
-
Self,
|
23
|
-
P extends CoValueSchema | S.Schema<null>,
|
24
|
-
R extends CoValueSchema | S.Schema<null>,
|
25
|
-
> extends CoValueSchema<Self, AnyGroup<P, R>, "Group", undefined> {
|
26
|
-
new (options: { owner: AnyAccount | AnyGroup }): AnyGroup<P, R>;
|
27
|
-
}
|