jazz-tools 0.7.0-alpha.3 → 0.7.0-alpha.6
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/coValues/account.js +3 -3
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +2 -2
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +11 -11
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +3 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +2 -2
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +3 -3
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +3 -3
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/encoding.js +5 -0
- package/dist/implementation/encoding.js.map +1 -0
- package/dist/implementation/refs.js +4 -4
- package/dist/implementation/refs.js.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/tests/coMap.test.js +2 -2
- package/dist/tests/coMap.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +11 -11
- package/src/coValues/coList.ts +22 -15
- package/src/coValues/coMap.ts +30 -40
- package/src/coValues/coStream.ts +12 -12
- package/src/coValues/extensions/imageDef.ts +2 -3
- package/src/coValues/group.ts +13 -13
- package/src/coValues/interfaces.ts +3 -3
- package/src/implementation/{schema.ts → encoding.ts} +14 -17
- package/src/implementation/refs.ts +9 -10
- package/src/index.ts +2 -2
- package/src/internal.ts +1 -1
- package/src/tests/coMap.test.ts +3 -3
- package/dist/implementation/schema.js +0 -6
- package/dist/implementation/schema.js.map +0 -1
package/src/coValues/account.ts
CHANGED
@@ -15,14 +15,14 @@ import type {
|
|
15
15
|
CoMap,
|
16
16
|
CoValue,
|
17
17
|
CoValueClass,
|
18
|
-
|
18
|
+
Encoding,
|
19
19
|
Group,
|
20
20
|
ID,
|
21
|
-
|
21
|
+
RefEncoded,
|
22
22
|
SubclassedConstructor,
|
23
23
|
UnavailableError,
|
24
24
|
} from "../internal.js";
|
25
|
-
import { CoValueBase, Profile,
|
25
|
+
import { CoValueBase, Profile, Ref, inspect } from "../internal.js";
|
26
26
|
import type { Stream } from "effect/Stream";
|
27
27
|
|
28
28
|
export class Account<
|
@@ -40,8 +40,8 @@ export class Account<
|
|
40
40
|
|
41
41
|
static _encoding: any;
|
42
42
|
get _encoding(): {
|
43
|
-
profile:
|
44
|
-
root:
|
43
|
+
profile: Encoding;
|
44
|
+
root: Encoding;
|
45
45
|
} {
|
46
46
|
return (this.constructor as typeof Account)._encoding;
|
47
47
|
}
|
@@ -66,10 +66,10 @@ export class Account<
|
|
66
66
|
|
67
67
|
get _refs(): {
|
68
68
|
profile: NonNullable<Def["profile"]> extends Profile
|
69
|
-
?
|
69
|
+
? Ref<NonNullable<Def["profile"]>> | null
|
70
70
|
: null;
|
71
71
|
root: NonNullable<Def["root"]> extends CoMap
|
72
|
-
?
|
72
|
+
? Ref<NonNullable<Def["root"]>> | null
|
73
73
|
: null;
|
74
74
|
} {
|
75
75
|
const profileID = this._raw.get("profile") as unknown as ID<
|
@@ -79,22 +79,22 @@ export class Account<
|
|
79
79
|
| ID<NonNullable<Def["root"]>>
|
80
80
|
| undefined;
|
81
81
|
return {
|
82
|
-
profile: profileID && (new
|
82
|
+
profile: profileID && (new Ref(
|
83
83
|
profileID,
|
84
84
|
this._loadedAs,
|
85
85
|
(
|
86
|
-
this._encoding.profile as
|
86
|
+
this._encoding.profile as RefEncoded<
|
87
87
|
NonNullable<Def["profile"]> & CoValue
|
88
88
|
>
|
89
89
|
).ref()
|
90
90
|
)) as any,
|
91
91
|
root:
|
92
92
|
rootID &&
|
93
|
-
(new
|
93
|
+
(new Ref(
|
94
94
|
rootID,
|
95
95
|
this._loadedAs,
|
96
96
|
(
|
97
|
-
this._encoding.root as
|
97
|
+
this._encoding.root as RefEncoded<NonNullable<Def["root"]> & CoValue>
|
98
98
|
).ref()
|
99
99
|
) as any),
|
100
100
|
};
|
package/src/coValues/coList.ts
CHANGED
@@ -4,11 +4,11 @@ import type { Effect, Stream } from "effect";
|
|
4
4
|
import type {
|
5
5
|
AccountCtx,
|
6
6
|
CoValue,
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
ValidItem,
|
8
|
+
Encoding,
|
9
|
+
EncodingFor,
|
10
10
|
ID,
|
11
|
-
|
11
|
+
RefEncoded,
|
12
12
|
SubclassedConstructor,
|
13
13
|
UnavailableError,
|
14
14
|
} from "../internal.js";
|
@@ -16,13 +16,13 @@ import {
|
|
16
16
|
Account,
|
17
17
|
CoValueBase,
|
18
18
|
Group,
|
19
|
-
|
19
|
+
Ref,
|
20
20
|
inspect,
|
21
21
|
makeRefs,
|
22
22
|
} from "../internal.js";
|
23
23
|
import { Schema } from "@effect/schema";
|
24
24
|
|
25
|
-
export class CoList<Item extends
|
25
|
+
export class CoList<Item extends ValidItem<Item, "Co.List"> = any>
|
26
26
|
extends Array<Item>
|
27
27
|
implements CoValue<"CoList", RawCoList>
|
28
28
|
{
|
@@ -35,7 +35,7 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
35
35
|
|
36
36
|
static _encoding: any;
|
37
37
|
get _encoding(): {
|
38
|
-
_item:
|
38
|
+
_item: EncodingFor<Item>;
|
39
39
|
} {
|
40
40
|
return (this.constructor as typeof CoList)._encoding;
|
41
41
|
}
|
@@ -48,8 +48,15 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
48
48
|
|
49
49
|
get _refs(): {
|
50
50
|
[idx: number]: NonNullable<Item> extends CoValue
|
51
|
-
?
|
51
|
+
? Ref<NonNullable<Item>>
|
52
52
|
: never;
|
53
|
+
} & {
|
54
|
+
length: number;
|
55
|
+
[Symbol.iterator](): IterableIterator<
|
56
|
+
NonNullable<Item> extends CoValue
|
57
|
+
? Ref<NonNullable<Item>>
|
58
|
+
: never
|
59
|
+
>;
|
53
60
|
} {
|
54
61
|
return makeRefs<number>(
|
55
62
|
(idx) => this._raw.get(idx) as unknown as ID<CoValue>,
|
@@ -59,14 +66,14 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
59
66
|
(_, idx) => idx
|
60
67
|
),
|
61
68
|
this._loadedAs,
|
62
|
-
(_idx) => (this._encoding._item as
|
69
|
+
(_idx) => (this._encoding._item as RefEncoded<CoValue>).ref()
|
63
70
|
) as any;
|
64
71
|
}
|
65
72
|
|
66
73
|
get _edits(): {
|
67
74
|
[idx: number]: {
|
68
75
|
value?: Item;
|
69
|
-
ref?: Item extends CoValue ?
|
76
|
+
ref?: Item extends CoValue ? Ref<Item> : never;
|
70
77
|
by?: Account;
|
71
78
|
madeAt: Date;
|
72
79
|
};
|
@@ -122,7 +129,7 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
122
129
|
}
|
123
130
|
|
124
131
|
private toRawItems(items: Item[]) {
|
125
|
-
const itemDescriptor = this._encoding._item as
|
132
|
+
const itemDescriptor = this._encoding._item as Encoding;
|
126
133
|
const rawItems =
|
127
134
|
itemDescriptor === "json"
|
128
135
|
? items
|
@@ -199,7 +206,7 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
199
206
|
}
|
200
207
|
|
201
208
|
toJSON() {
|
202
|
-
const itemDescriptor = this._encoding._item as
|
209
|
+
const itemDescriptor = this._encoding._item as Encoding;
|
203
210
|
if (itemDescriptor === "json") {
|
204
211
|
return this._raw.asArray();
|
205
212
|
} else if ("encoded" in itemDescriptor) {
|
@@ -265,8 +272,8 @@ export class CoList<Item extends EnsureItemNullable<Item, 'Co.List'> = any>
|
|
265
272
|
}
|
266
273
|
}
|
267
274
|
|
268
|
-
function CoListProxyHandler<Item extends
|
269
|
-
itemDescriptor:
|
275
|
+
function CoListProxyHandler<Item extends ValidItem<Item, "Co.List">>(
|
276
|
+
itemDescriptor: Encoding
|
270
277
|
): ProxyHandler<CoList<Item>> {
|
271
278
|
return {
|
272
279
|
get(target, key, receiver) {
|
@@ -281,7 +288,7 @@ function CoListProxyHandler<Item extends EnsureItemNullable<Item, "Co.List">>(
|
|
281
288
|
} else if ("ref" in itemDescriptor) {
|
282
289
|
return rawValue === undefined
|
283
290
|
? undefined
|
284
|
-
: new
|
291
|
+
: new Ref(
|
285
292
|
rawValue as unknown as ID<CoValue>,
|
286
293
|
target._loadedAs,
|
287
294
|
itemDescriptor.ref()
|
package/src/coValues/coMap.ts
CHANGED
@@ -4,27 +4,24 @@ import { Schema } from "@effect/schema";
|
|
4
4
|
import type {
|
5
5
|
CoValue,
|
6
6
|
Encoder,
|
7
|
-
|
8
|
-
|
7
|
+
Encoding,
|
8
|
+
EncodingFor,
|
9
9
|
Group,
|
10
10
|
ID,
|
11
|
-
|
11
|
+
RefEncoded,
|
12
12
|
EnsureCoValueNullable,
|
13
13
|
CoValueClass,
|
14
14
|
} from "../internal.js";
|
15
15
|
import {
|
16
16
|
Account,
|
17
17
|
CoValueBase,
|
18
|
-
|
18
|
+
Ref,
|
19
19
|
inspect,
|
20
20
|
makeRefs,
|
21
21
|
subscriptionsScopes,
|
22
|
-
indexSignature,
|
23
22
|
} from "../internal.js";
|
24
23
|
|
25
|
-
type
|
26
|
-
Fields extends { [key: string]: any; [indexSignature]?: any },
|
27
|
-
> = {
|
24
|
+
type ValidFields<Fields extends { [key: string]: any; _item?: any }> = {
|
28
25
|
[Key in OwnKeys<Fields> as IfOptionalKey<
|
29
26
|
Key,
|
30
27
|
Fields
|
@@ -35,10 +32,7 @@ type EnsureValid<
|
|
35
32
|
Fields
|
36
33
|
>]: EnsureCoValueNullable<Fields[Key], Key>;
|
37
34
|
} & {
|
38
|
-
[Key in
|
39
|
-
Fields[indexSignature],
|
40
|
-
Key
|
41
|
-
>;
|
35
|
+
[Key in "_item"]?: EnsureCoValueNullable<Fields["_item"], Key>;
|
42
36
|
};
|
43
37
|
|
44
38
|
type IfOptionalKey<Key extends keyof Obj, Obj> = Pick<
|
@@ -56,10 +50,10 @@ type IfRequiredKey<Key extends keyof Obj, Obj> = Pick<
|
|
56
50
|
|
57
51
|
type DefaultFields = {
|
58
52
|
[key: string]: any;
|
59
|
-
|
53
|
+
_item?: any;
|
60
54
|
};
|
61
55
|
|
62
|
-
export class CoMap<Fields extends
|
56
|
+
export class CoMap<Fields extends ValidFields<Fields> = DefaultFields>
|
63
57
|
extends CoValueBase
|
64
58
|
implements CoValue<"CoMap", RawCoMap>
|
65
59
|
{
|
@@ -72,10 +66,10 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
72
66
|
|
73
67
|
static _encoding: any;
|
74
68
|
get _encoding(): {
|
75
|
-
[Key in OwnKeys<Fields>]:
|
69
|
+
[Key in OwnKeys<Fields>]: EncodingFor<Fields[Key]>;
|
76
70
|
} & {
|
77
|
-
|
78
|
-
?
|
71
|
+
_item: "_item" extends keyof Fields
|
72
|
+
? EncodingFor<Fields["_item"]>
|
79
73
|
: never;
|
80
74
|
} {
|
81
75
|
return (this.constructor as typeof CoMap)._encoding;
|
@@ -85,7 +79,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
85
79
|
[Key in OwnKeys<Fields> as NonNullable<Fields[Key]> extends CoValue
|
86
80
|
? Key
|
87
81
|
: never]: NonNullable<Fields[Key]> extends CoValue
|
88
|
-
?
|
82
|
+
? Ref<NonNullable<Fields[Key]>>
|
89
83
|
: never;
|
90
84
|
} {
|
91
85
|
return makeRefs<OwnKeys<Fields>>(
|
@@ -94,18 +88,18 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
94
88
|
Object.keys(this._encoding).filter((key) => {
|
95
89
|
const schema = this._encoding[
|
96
90
|
key as keyof typeof this._encoding
|
97
|
-
] as
|
91
|
+
] as Encoding;
|
98
92
|
schema !== "json" && "ref" in schema;
|
99
93
|
}) as OwnKeys<Fields>[],
|
100
94
|
this._loadedAs,
|
101
|
-
(key) => (this._encoding[key] as
|
95
|
+
(key) => (this._encoding[key] as RefEncoded<CoValue>).ref()
|
102
96
|
) as any;
|
103
97
|
}
|
104
98
|
|
105
99
|
get _edits(): {
|
106
100
|
[Key in OwnKeys<Fields>]: {
|
107
101
|
value?: Fields[Key];
|
108
|
-
ref?: Fields[Key] extends CoValue ?
|
102
|
+
ref?: Fields[Key] extends CoValue ? Ref<Fields[Key]> : never;
|
109
103
|
by?: Account;
|
110
104
|
madeAt: Date;
|
111
105
|
};
|
@@ -117,7 +111,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
117
111
|
|
118
112
|
const descriptor = target._encoding[
|
119
113
|
key as keyof typeof target._encoding
|
120
|
-
] as
|
114
|
+
] as Encoding;
|
121
115
|
|
122
116
|
return {
|
123
117
|
value:
|
@@ -127,14 +121,14 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
127
121
|
? Schema.decodeSync(descriptor.encoded)(
|
128
122
|
rawEdit.value
|
129
123
|
)
|
130
|
-
: new
|
124
|
+
: new Ref(
|
131
125
|
rawEdit.value as ID<CoValue>,
|
132
126
|
target._loadedAs,
|
133
127
|
descriptor.ref()
|
134
128
|
).accessFrom(target),
|
135
129
|
ref:
|
136
130
|
descriptor !== "json" && "ref" in descriptor
|
137
|
-
? new
|
131
|
+
? new Ref(
|
138
132
|
rawEdit.value as ID<CoValue>,
|
139
133
|
target._loadedAs,
|
140
134
|
descriptor.ref()
|
@@ -142,7 +136,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
142
136
|
: undefined,
|
143
137
|
by:
|
144
138
|
rawEdit.by &&
|
145
|
-
new
|
139
|
+
new Ref(
|
146
140
|
rawEdit.by as ID<Account>,
|
147
141
|
target._loadedAs,
|
148
142
|
Account
|
@@ -188,7 +182,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
188
182
|
|
189
183
|
this.definePropertiesFromSchema();
|
190
184
|
|
191
|
-
if (this._encoding
|
185
|
+
if (this._encoding._item) {
|
192
186
|
return new Proxy(this, CoMapProxyHandler<Fields>());
|
193
187
|
}
|
194
188
|
}
|
@@ -196,7 +190,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
196
190
|
toJSON() {
|
197
191
|
const jsonedFields = this._raw.keys().map((key) => {
|
198
192
|
const tKey = key as OwnKeys<Fields>;
|
199
|
-
const descriptor = this._encoding[tKey] as
|
193
|
+
const descriptor = this._encoding[tKey] as Encoding;
|
200
194
|
|
201
195
|
if (descriptor == "json" || "encode" in descriptor) {
|
202
196
|
return [key, this._raw.get(key)];
|
@@ -240,7 +234,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
240
234
|
|
241
235
|
const descriptor = (this._encoding[
|
242
236
|
key as keyof typeof this._encoding
|
243
|
-
] || this._encoding
|
237
|
+
] || this._encoding._item) as Encoding;
|
244
238
|
|
245
239
|
if (descriptor === "json") {
|
246
240
|
rawInit[key] = initValue as JsonValue;
|
@@ -275,7 +269,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
275
269
|
private definePropertiesFromSchema() {
|
276
270
|
for (const [key, fieldSchema] of Object.entries(this._encoding)) {
|
277
271
|
if (key === "indexSignature") continue;
|
278
|
-
const descriptor = fieldSchema as
|
272
|
+
const descriptor = fieldSchema as Encoding;
|
279
273
|
if (descriptor === "json") {
|
280
274
|
Object.defineProperty(
|
281
275
|
this,
|
@@ -294,7 +288,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
294
288
|
key,
|
295
289
|
this.refPropDef(
|
296
290
|
key as string,
|
297
|
-
(descriptor as
|
291
|
+
(descriptor as RefEncoded<CoValue>).ref
|
298
292
|
)
|
299
293
|
);
|
300
294
|
}
|
@@ -339,7 +333,7 @@ export class CoMap<Fields extends EnsureValid<Fields> = DefaultFields>
|
|
339
333
|
const rawID = this._raw.get(key);
|
340
334
|
return rawID === undefined
|
341
335
|
? undefined
|
342
|
-
: new
|
336
|
+
: new Ref(
|
343
337
|
rawID as unknown as ID<CoValue>,
|
344
338
|
this._loadedAs,
|
345
339
|
ref()
|
@@ -369,14 +363,12 @@ export type CoMapInit<Fields extends object> = {
|
|
369
363
|
} & { [Key in OwnKeys<Fields>]?: Fields[Key] };
|
370
364
|
|
371
365
|
// TODO: cache handlers per descriptor for performance?
|
372
|
-
function CoMapProxyHandler<Fields extends
|
366
|
+
function CoMapProxyHandler<Fields extends ValidFields<Fields>>(): ProxyHandler<
|
373
367
|
CoMap<Fields>
|
374
368
|
> {
|
375
369
|
return {
|
376
370
|
get(target, key, receiver) {
|
377
|
-
const descriptor = target._encoding
|
378
|
-
indexSignature
|
379
|
-
] as FieldDescriptor;
|
371
|
+
const descriptor = target._encoding._item as Encoding;
|
380
372
|
if (key in target || typeof key === "symbol") {
|
381
373
|
return Reflect.get(target, key, receiver);
|
382
374
|
} else {
|
@@ -391,7 +383,7 @@ function CoMapProxyHandler<Fields extends EnsureValid<Fields>>(): ProxyHandler<
|
|
391
383
|
} else if ("ref" in descriptor) {
|
392
384
|
return raw === undefined
|
393
385
|
? undefined
|
394
|
-
: new
|
386
|
+
: new Ref(
|
395
387
|
raw as unknown as ID<CoValue>,
|
396
388
|
target._loadedAs,
|
397
389
|
descriptor.ref()
|
@@ -400,9 +392,7 @@ function CoMapProxyHandler<Fields extends EnsureValid<Fields>>(): ProxyHandler<
|
|
400
392
|
}
|
401
393
|
},
|
402
394
|
set(target, key, value, receiver) {
|
403
|
-
const descriptor = target._encoding
|
404
|
-
indexSignature
|
405
|
-
] as FieldDescriptor;
|
395
|
+
const descriptor = target._encoding._item as Encoding;
|
406
396
|
if (key in target || typeof key === "symbol") {
|
407
397
|
return Reflect.set(target, key, value, receiver);
|
408
398
|
} else {
|
@@ -423,7 +413,7 @@ function CoMapProxyHandler<Fields extends EnsureValid<Fields>>(): ProxyHandler<
|
|
423
413
|
}
|
424
414
|
},
|
425
415
|
ownKeys(target) {
|
426
|
-
const keys = Reflect.ownKeys(target);
|
416
|
+
const keys = Reflect.ownKeys(target).filter((k) => k !== "_item");
|
427
417
|
for (const key of target._raw.keys()) {
|
428
418
|
if (!keys.includes(key)) {
|
429
419
|
keys.push(key);
|
package/src/coValues/coStream.ts
CHANGED
@@ -11,27 +11,27 @@ import type {
|
|
11
11
|
import { cojsonInternals } from "cojson";
|
12
12
|
import type {
|
13
13
|
CoValue,
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
ValidItem,
|
15
|
+
Encoding,
|
16
|
+
EncodingFor,
|
17
17
|
Group,
|
18
18
|
ID,
|
19
19
|
Me,
|
20
20
|
} from "../internal.js";
|
21
|
-
import { Account, CoValueBase,
|
21
|
+
import { Account, CoValueBase, Ref, inspect } from "../internal.js";
|
22
22
|
import { Schema } from "@effect/schema";
|
23
23
|
|
24
24
|
export type CoStreamEntry<Item> = {
|
25
25
|
value: NonNullable<Item> extends CoValue ? NonNullable<Item> | null : Item;
|
26
26
|
ref?: NonNullable<Item> extends CoValue
|
27
|
-
?
|
27
|
+
? Ref<NonNullable<Item>>
|
28
28
|
: never;
|
29
29
|
by?: Account;
|
30
30
|
madeAt: Date;
|
31
31
|
tx: CojsonInternalTypes.TransactionID;
|
32
32
|
};
|
33
33
|
|
34
|
-
export class CoStream<Item extends
|
34
|
+
export class CoStream<Item extends ValidItem<Item, "Co.Stream"> = any>
|
35
35
|
extends CoValueBase
|
36
36
|
implements CoValue<"CoStream", RawCoStream>
|
37
37
|
{
|
@@ -46,7 +46,7 @@ export class CoStream<Item extends EnsureItemNullable<Item, "Co.Stream"> = any>
|
|
46
46
|
_item!: Item;
|
47
47
|
static _encoding: any;
|
48
48
|
get _encoding(): {
|
49
|
-
_item:
|
49
|
+
_item: EncodingFor<Item>;
|
50
50
|
} {
|
51
51
|
return (this.constructor as typeof CoStream)._encoding;
|
52
52
|
}
|
@@ -155,7 +155,7 @@ export class CoStream<Item extends EnsureItemNullable<Item, "Co.Stream"> = any>
|
|
155
155
|
}
|
156
156
|
|
157
157
|
private pushItem(item: Item) {
|
158
|
-
const itemDescriptor = this._encoding._item as
|
158
|
+
const itemDescriptor = this._encoding._item as Encoding;
|
159
159
|
|
160
160
|
if (itemDescriptor === "json") {
|
161
161
|
this._raw.push(item as JsonValue);
|
@@ -167,7 +167,7 @@ export class CoStream<Item extends EnsureItemNullable<Item, "Co.Stream"> = any>
|
|
167
167
|
}
|
168
168
|
|
169
169
|
toJSON() {
|
170
|
-
const itemDescriptor = this._encoding._item as
|
170
|
+
const itemDescriptor = this._encoding._item as Encoding;
|
171
171
|
const mapper =
|
172
172
|
itemDescriptor === "json"
|
173
173
|
? (v: unknown) => v
|
@@ -216,7 +216,7 @@ function entryFromRawEntry<Item>(
|
|
216
216
|
},
|
217
217
|
loadedAs: Account & Me,
|
218
218
|
accountID: ID<Account> | undefined,
|
219
|
-
itemField:
|
219
|
+
itemField: Encoding
|
220
220
|
) {
|
221
221
|
return {
|
222
222
|
get value(): Item | undefined {
|
@@ -231,7 +231,7 @@ function entryFromRawEntry<Item>(
|
|
231
231
|
get ref() {
|
232
232
|
if (itemField !== "json" && "ref" in itemField) {
|
233
233
|
const rawId = rawEntry.value;
|
234
|
-
return new
|
234
|
+
return new Ref(
|
235
235
|
rawId as unknown as ID<CoValue>,
|
236
236
|
loadedAs,
|
237
237
|
itemField.ref()
|
@@ -241,7 +241,7 @@ function entryFromRawEntry<Item>(
|
|
241
241
|
get by() {
|
242
242
|
return (
|
243
243
|
accountID &&
|
244
|
-
new
|
244
|
+
new Ref(
|
245
245
|
accountID as unknown as ID<Account>,
|
246
246
|
loadedAs,
|
247
247
|
Account
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import {
|
2
2
|
BinaryCoStream,
|
3
3
|
CoMap,
|
4
|
-
indexSignature,
|
5
4
|
subscriptionsScopes,
|
6
5
|
} from "../../internal.js";
|
7
6
|
|
@@ -10,7 +9,7 @@ export class ImageDefinition extends CoMap<ImageDefinition> {
|
|
10
9
|
declare placeholderDataURL?: string;
|
11
10
|
|
12
11
|
[res: `${number}x${number}`]: BinaryCoStream | null;
|
13
|
-
declare
|
12
|
+
declare _item: BinaryCoStream | null;
|
14
13
|
|
15
14
|
get _highestResAvailable():
|
16
15
|
| { res: `${number}x${number}`; stream: BinaryCoStream }
|
@@ -56,5 +55,5 @@ export class ImageDefinition extends CoMap<ImageDefinition> {
|
|
56
55
|
ImageDefinition.encoding({
|
57
56
|
originalSize: "json",
|
58
57
|
placeholderDataURL: "json",
|
59
|
-
|
58
|
+
_item: { ref: () => BinaryCoStream },
|
60
59
|
});
|
package/src/coValues/group.ts
CHANGED
@@ -3,14 +3,14 @@ import type {
|
|
3
3
|
CoValue,
|
4
4
|
CoValueClass,
|
5
5
|
ID,
|
6
|
-
|
7
|
-
|
6
|
+
JsonEncoded,
|
7
|
+
RefEncoded,
|
8
8
|
} from "../internal.js";
|
9
9
|
import {
|
10
10
|
Account,
|
11
11
|
CoMap,
|
12
12
|
CoValueBase,
|
13
|
-
|
13
|
+
Ref,
|
14
14
|
isControlledAccount,
|
15
15
|
} from "../internal.js";
|
16
16
|
|
@@ -38,11 +38,11 @@ export class Group<
|
|
38
38
|
static _encoding: any;
|
39
39
|
get _encoding(): {
|
40
40
|
profile: Def["profile"] extends CoValue
|
41
|
-
?
|
42
|
-
:
|
41
|
+
? RefEncoded<Def["profile"]>
|
42
|
+
: JsonEncoded;
|
43
43
|
root: Def["root"] extends CoValue
|
44
|
-
?
|
45
|
-
:
|
44
|
+
? RefEncoded<Def["root"]>
|
45
|
+
: JsonEncoded;
|
46
46
|
} {
|
47
47
|
return (this.constructor as typeof Group)._encoding;
|
48
48
|
}
|
@@ -64,9 +64,9 @@ export class Group<
|
|
64
64
|
|
65
65
|
get _refs(): {
|
66
66
|
profile: Def["profile"] extends Profile
|
67
|
-
?
|
67
|
+
? Ref<Def["profile"]>
|
68
68
|
: never;
|
69
|
-
root: Def["root"] extends CoMap ?
|
69
|
+
root: Def["root"] extends CoMap ? Ref<Def["root"]> : never;
|
70
70
|
} {
|
71
71
|
const profileID = this._raw.get("profile") as unknown as
|
72
72
|
| ID<NonNullable<Def["profile"]>>
|
@@ -77,22 +77,22 @@ export class Group<
|
|
77
77
|
return {
|
78
78
|
profile:
|
79
79
|
profileID &&
|
80
|
-
(new
|
80
|
+
(new Ref(
|
81
81
|
profileID,
|
82
82
|
this._loadedAs,
|
83
83
|
(
|
84
|
-
this._encoding.profile as
|
84
|
+
this._encoding.profile as RefEncoded<
|
85
85
|
NonNullable<Def["profile"]>
|
86
86
|
>
|
87
87
|
).ref()
|
88
88
|
) as any),
|
89
89
|
root:
|
90
90
|
rootID &&
|
91
|
-
(new
|
91
|
+
(new Ref(
|
92
92
|
rootID,
|
93
93
|
this._loadedAs,
|
94
94
|
(
|
95
|
-
this._encoding.root as
|
95
|
+
this._encoding.root as RefEncoded<
|
96
96
|
NonNullable<Def["root"]>
|
97
97
|
>
|
98
98
|
).ref()
|
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
AccountCtx,
|
8
8
|
Group,
|
9
9
|
SubscriptionScope,
|
10
|
-
|
10
|
+
Ref,
|
11
11
|
inspect,
|
12
12
|
} from "../internal.js";
|
13
13
|
|
@@ -117,7 +117,7 @@ export class CoValueBase implements CoValue {
|
|
117
117
|
): Effect.Effect<V, UnavailableError, AccountCtx> {
|
118
118
|
return Effect.gen(this, function* (_) {
|
119
119
|
const account = yield* _(AccountCtx);
|
120
|
-
return yield* _(new
|
120
|
+
return yield* _(new Ref(id as ID<V>, account, this).loadEf());
|
121
121
|
});
|
122
122
|
}
|
123
123
|
|
@@ -129,7 +129,7 @@ export class CoValueBase implements CoValue {
|
|
129
129
|
onProgress?: (progress: number) => void;
|
130
130
|
}
|
131
131
|
): Promise<V | undefined> {
|
132
|
-
return new
|
132
|
+
return new Ref(id as ID<V>, options.as, this).load(
|
133
133
|
options?.onProgress && { onProgress: options.onProgress }
|
134
134
|
);
|
135
135
|
}
|