jazz-tools 0.7.21 → 0.7.24
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +33 -33
- package/CHANGELOG.md +14 -0
- package/dist/coValues/account.js +1 -9
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +1 -21
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +1 -21
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +1 -17
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +1 -9
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +36 -20
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/refs.js +0 -17
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +31 -0
- package/dist/implementation/schema.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tests/coList.test.js +8 -2
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +5 -2
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/deepLoading.test.js.map +1 -1
- package/package.json +2 -2
- package/src/coValues/account.ts +8 -27
- package/src/coValues/coList.ts +0 -35
- package/src/coValues/coMap.ts +0 -35
- package/src/coValues/coStream.ts +0 -41
- package/src/coValues/group.ts +0 -23
- package/src/coValues/interfaces.ts +49 -77
- package/src/implementation/refs.ts +0 -18
- package/src/implementation/schema.ts +41 -0
- package/src/index.ts +1 -6
- package/src/tests/coList.test.ts +12 -10
- package/src/tests/coMap.test.ts +5 -2
- package/src/tests/deepLoading.test.ts +12 -8
package/src/coValues/coMap.ts
CHANGED
@@ -11,8 +11,6 @@ import type {
|
|
11
11
|
RefIfCoValue,
|
12
12
|
DepthsIn,
|
13
13
|
DeeplyLoaded,
|
14
|
-
UnavailableError,
|
15
|
-
AccountCtx,
|
16
14
|
CoValueClass,
|
17
15
|
} from "../internal.js";
|
18
16
|
import {
|
@@ -26,13 +24,10 @@ import {
|
|
26
24
|
ItemsSym,
|
27
25
|
isRefEncoded,
|
28
26
|
loadCoValue,
|
29
|
-
loadCoValueEf,
|
30
27
|
subscribeToCoValue,
|
31
|
-
subscribeToCoValueEf,
|
32
28
|
ensureCoValueLoaded,
|
33
29
|
subscribeToExistingCoValue,
|
34
30
|
} from "../internal.js";
|
35
|
-
import { Effect, Stream } from "effect";
|
36
31
|
|
37
32
|
type CoMapEdit<V> = {
|
38
33
|
value?: V;
|
@@ -391,21 +386,6 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
391
386
|
return loadCoValue(this, id, as, depth);
|
392
387
|
}
|
393
388
|
|
394
|
-
/**
|
395
|
-
* Effectful version of `CoMap.load()`.
|
396
|
-
*
|
397
|
-
* Needs to be run inside an `AccountCtx` context.
|
398
|
-
*
|
399
|
-
* @category Subscription & Loading
|
400
|
-
*/
|
401
|
-
static loadEf<M extends CoMap, Depth>(
|
402
|
-
this: CoValueClass<M>,
|
403
|
-
id: ID<M>,
|
404
|
-
depth: Depth & DepthsIn<M>,
|
405
|
-
): Effect.Effect<DeeplyLoaded<M, Depth>, UnavailableError, AccountCtx> {
|
406
|
-
return loadCoValueEf<M, Depth>(this, id, depth);
|
407
|
-
}
|
408
|
-
|
409
389
|
/**
|
410
390
|
* Load and subscribe to a `CoMap` with a given ID, as a given account.
|
411
391
|
*
|
@@ -444,21 +424,6 @@ export class CoMap extends CoValueBase implements CoValue {
|
|
444
424
|
return subscribeToCoValue<M, Depth>(this, id, as, depth, listener);
|
445
425
|
}
|
446
426
|
|
447
|
-
/**
|
448
|
-
* Effectful version of `CoMap.subscribe()` that returns a stream of updates.
|
449
|
-
*
|
450
|
-
* Needs to be run inside an `AccountCtx` context.
|
451
|
-
*
|
452
|
-
* @category Subscription & Loading
|
453
|
-
*/
|
454
|
-
static subscribeEf<M extends CoMap, Depth>(
|
455
|
-
this: CoValueClass<M>,
|
456
|
-
id: ID<M>,
|
457
|
-
depth: Depth & DepthsIn<M>,
|
458
|
-
): Stream.Stream<DeeplyLoaded<M, Depth>, UnavailableError, AccountCtx> {
|
459
|
-
return subscribeToCoValueEf<M, Depth>(this, id, depth);
|
460
|
-
}
|
461
|
-
|
462
427
|
/**
|
463
428
|
* Given an already loaded `CoMap`, ensure that the specified fields are loaded to the specified depth.
|
464
429
|
*
|
package/src/coValues/coStream.ts
CHANGED
@@ -17,11 +17,9 @@ import type {
|
|
17
17
|
ID,
|
18
18
|
IfCo,
|
19
19
|
UnCo,
|
20
|
-
AccountCtx,
|
21
20
|
CoValueClass,
|
22
21
|
DeeplyLoaded,
|
23
22
|
DepthsIn,
|
24
|
-
UnavailableError,
|
25
23
|
} from "../internal.js";
|
26
24
|
import {
|
27
25
|
ItemsSym,
|
@@ -33,14 +31,11 @@ import {
|
|
33
31
|
SchemaInit,
|
34
32
|
isRefEncoded,
|
35
33
|
loadCoValue,
|
36
|
-
loadCoValueEf,
|
37
34
|
subscribeToCoValue,
|
38
|
-
subscribeToCoValueEf,
|
39
35
|
ensureCoValueLoaded,
|
40
36
|
subscribeToExistingCoValue,
|
41
37
|
} from "../internal.js";
|
42
38
|
import { encodeSync, decodeSync } from "@effect/schema/Schema";
|
43
|
-
import { Effect, Stream } from "effect";
|
44
39
|
|
45
40
|
export type CoStreamEntry<Item> = SingleCoStreamEntry<Item> & {
|
46
41
|
all: IterableIterator<SingleCoStreamEntry<Item>>;
|
@@ -202,15 +197,6 @@ export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
|
202
197
|
return loadCoValue(this, id, as, depth);
|
203
198
|
}
|
204
199
|
|
205
|
-
/** @category Subscription & Loading */
|
206
|
-
static loadEf<S extends CoStream, Depth>(
|
207
|
-
this: CoValueClass<S>,
|
208
|
-
id: ID<S>,
|
209
|
-
depth: Depth & DepthsIn<S>,
|
210
|
-
): Effect.Effect<DeeplyLoaded<S, Depth>, UnavailableError, AccountCtx> {
|
211
|
-
return loadCoValueEf<S, Depth>(this, id, depth);
|
212
|
-
}
|
213
|
-
|
214
200
|
/** @category Subscription & Loading */
|
215
201
|
static subscribe<S extends CoStream, Depth>(
|
216
202
|
this: CoValueClass<S>,
|
@@ -222,15 +208,6 @@ export class CoStream<Item = any> extends CoValueBase implements CoValue {
|
|
222
208
|
return subscribeToCoValue<S, Depth>(this, id, as, depth, listener);
|
223
209
|
}
|
224
210
|
|
225
|
-
/** @category Subscription & Loading */
|
226
|
-
static subscribeEf<S extends CoStream, Depth>(
|
227
|
-
this: CoValueClass<S>,
|
228
|
-
id: ID<S>,
|
229
|
-
depth: Depth & DepthsIn<S>,
|
230
|
-
): Stream.Stream<DeeplyLoaded<S, Depth>, UnavailableError, AccountCtx> {
|
231
|
-
return subscribeToCoValueEf<S, Depth>(this, id, depth);
|
232
|
-
}
|
233
|
-
|
234
211
|
/** @category Subscription & Loading */
|
235
212
|
ensureLoaded<S extends CoStream, Depth>(
|
236
213
|
this: S,
|
@@ -638,15 +615,6 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
638
615
|
return loadCoValue(this, id, as, depth);
|
639
616
|
}
|
640
617
|
|
641
|
-
/** @category Subscription & Loading */
|
642
|
-
static loadEf<B extends BinaryCoStream, Depth>(
|
643
|
-
this: CoValueClass<B>,
|
644
|
-
id: ID<B>,
|
645
|
-
depth: Depth & DepthsIn<B>,
|
646
|
-
): Effect.Effect<DeeplyLoaded<B, Depth>, UnavailableError, AccountCtx> {
|
647
|
-
return loadCoValueEf<B, Depth>(this, id, depth);
|
648
|
-
}
|
649
|
-
|
650
618
|
/** @category Subscription & Loading */
|
651
619
|
static subscribe<B extends BinaryCoStream, Depth>(
|
652
620
|
this: CoValueClass<B>,
|
@@ -658,15 +626,6 @@ export class BinaryCoStream extends CoValueBase implements CoValue {
|
|
658
626
|
return subscribeToCoValue<B, Depth>(this, id, as, depth, listener);
|
659
627
|
}
|
660
628
|
|
661
|
-
/** @category Subscription & Loading */
|
662
|
-
static subscribeEf<B extends BinaryCoStream, Depth>(
|
663
|
-
this: CoValueClass<B>,
|
664
|
-
id: ID<B>,
|
665
|
-
depth: Depth & DepthsIn<B>,
|
666
|
-
): Stream.Stream<DeeplyLoaded<B, Depth>, UnavailableError, AccountCtx> {
|
667
|
-
return subscribeToCoValueEf<B, Depth>(this, id, depth);
|
668
|
-
}
|
669
|
-
|
670
629
|
/** @category Subscription & Loading */
|
671
630
|
ensureLoaded<B extends BinaryCoStream, Depth>(
|
672
631
|
this: B,
|
package/src/coValues/group.ts
CHANGED
@@ -4,11 +4,9 @@ import type {
|
|
4
4
|
ID,
|
5
5
|
RefEncoded,
|
6
6
|
Schema,
|
7
|
-
AccountCtx,
|
8
7
|
CoValueClass,
|
9
8
|
DeeplyLoaded,
|
10
9
|
DepthsIn,
|
11
|
-
UnavailableError,
|
12
10
|
} from "../internal.js";
|
13
11
|
import {
|
14
12
|
Account,
|
@@ -20,13 +18,10 @@ import {
|
|
20
18
|
AccountAndGroupProxyHandler,
|
21
19
|
MembersSym,
|
22
20
|
loadCoValue,
|
23
|
-
loadCoValueEf,
|
24
21
|
subscribeToCoValue,
|
25
|
-
subscribeToCoValueEf,
|
26
22
|
ensureCoValueLoaded,
|
27
23
|
subscribeToExistingCoValue,
|
28
24
|
} from "../internal.js";
|
29
|
-
import { Effect, Stream } from "effect";
|
30
25
|
|
31
26
|
/** @category Identity & Permissions */
|
32
27
|
export class Profile extends CoMap {
|
@@ -198,15 +193,6 @@ export class Group extends CoValueBase implements CoValue {
|
|
198
193
|
return loadCoValue(this, id, as, depth);
|
199
194
|
}
|
200
195
|
|
201
|
-
/** @category Subscription & Loading */
|
202
|
-
static loadEf<G extends Group, Depth>(
|
203
|
-
this: CoValueClass<G>,
|
204
|
-
id: ID<G>,
|
205
|
-
depth: Depth & DepthsIn<G>,
|
206
|
-
): Effect.Effect<DeeplyLoaded<G, Depth>, UnavailableError, AccountCtx> {
|
207
|
-
return loadCoValueEf<G, Depth>(this, id, depth);
|
208
|
-
}
|
209
|
-
|
210
196
|
/** @category Subscription & Loading */
|
211
197
|
static subscribe<G extends Group, Depth>(
|
212
198
|
this: CoValueClass<G>,
|
@@ -218,15 +204,6 @@ export class Group extends CoValueBase implements CoValue {
|
|
218
204
|
return subscribeToCoValue<G, Depth>(this, id, as, depth, listener);
|
219
205
|
}
|
220
206
|
|
221
|
-
/** @category Subscription & Loading */
|
222
|
-
static subscribeEf<G extends Group, Depth>(
|
223
|
-
this: CoValueClass<G>,
|
224
|
-
id: ID<G>,
|
225
|
-
depth: Depth & DepthsIn<G>,
|
226
|
-
): Stream.Stream<DeeplyLoaded<G, Depth>, UnavailableError, AccountCtx> {
|
227
|
-
return subscribeToCoValueEf<G, Depth>(this, id, depth);
|
228
|
-
}
|
229
|
-
|
230
207
|
/** @category Subscription & Loading */
|
231
208
|
ensureLoaded<G extends Group, Depth>(
|
232
209
|
this: G,
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import { Effect, Option, Sink, Stream } from "effect";
|
2
1
|
import type { CojsonInternalTypes, RawCoValue } from "cojson";
|
3
2
|
import { RawAccount } from "cojson";
|
4
|
-
import type { DeeplyLoaded, DepthsIn
|
3
|
+
import type { DeeplyLoaded, DepthsIn } from "../internal.js";
|
5
4
|
import {
|
6
5
|
Account,
|
7
|
-
AccountCtx,
|
8
6
|
Group,
|
9
7
|
SubscriptionScope,
|
10
8
|
Ref,
|
@@ -134,13 +132,22 @@ export function loadCoValue<V extends CoValue, Depth>(
|
|
134
132
|
as: Account,
|
135
133
|
depth: Depth & DepthsIn<V>,
|
136
134
|
): Promise<DeeplyLoaded<V, Depth> | undefined> {
|
137
|
-
return
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
return new Promise((resolve) => {
|
136
|
+
const unsubscribe = subscribeToCoValue(
|
137
|
+
cls,
|
138
|
+
id,
|
139
|
+
as,
|
140
|
+
depth,
|
141
|
+
(value) => {
|
142
|
+
resolve(value);
|
143
|
+
unsubscribe();
|
144
|
+
},
|
145
|
+
() => {
|
146
|
+
resolve(undefined);
|
147
|
+
unsubscribe();
|
148
|
+
},
|
149
|
+
);
|
150
|
+
});
|
144
151
|
}
|
145
152
|
|
146
153
|
export function ensureCoValueLoaded<V extends CoValue, Depth>(
|
@@ -155,41 +162,46 @@ export function ensureCoValueLoaded<V extends CoValue, Depth>(
|
|
155
162
|
);
|
156
163
|
}
|
157
164
|
|
158
|
-
export function loadCoValueEf<V extends CoValue, Depth>(
|
159
|
-
cls: CoValueClass<V>,
|
160
|
-
id: ID<V>,
|
161
|
-
depth: Depth & DepthsIn<V>,
|
162
|
-
): Effect.Effect<DeeplyLoaded<V, Depth>, UnavailableError, AccountCtx> {
|
163
|
-
return subscribeToCoValueEf(cls, id, depth).pipe(
|
164
|
-
Stream.runHead,
|
165
|
-
Effect.andThen(
|
166
|
-
Effect.mapError((_noSuchElem) => "unavailable" as const),
|
167
|
-
),
|
168
|
-
);
|
169
|
-
}
|
170
|
-
|
171
165
|
export function subscribeToCoValue<V extends CoValue, Depth>(
|
172
166
|
cls: CoValueClass<V>,
|
173
167
|
id: ID<V>,
|
174
168
|
as: Account,
|
175
169
|
depth: Depth & DepthsIn<V>,
|
176
170
|
listener: (value: DeeplyLoaded<V, Depth>) => void,
|
171
|
+
onUnavailable?: () => void,
|
177
172
|
): () => void {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
173
|
+
const ref = new Ref(id, as, { ref: cls, optional: false });
|
174
|
+
|
175
|
+
let unsubscribed = false;
|
176
|
+
let unsubscribe: (() => void) | undefined;
|
177
|
+
|
178
|
+
ref.load()
|
179
|
+
.then((value) => {
|
180
|
+
if (!value) {
|
181
|
+
onUnavailable && onUnavailable();
|
182
|
+
return;
|
183
|
+
}
|
184
|
+
if (unsubscribed) return;
|
185
|
+
const subscription = new SubscriptionScope(
|
186
|
+
value,
|
187
|
+
cls as CoValueClass<V> & CoValueFromRaw<V>,
|
188
|
+
(update) => {
|
189
|
+
if (fulfillsDepth(depth, update)) {
|
190
|
+
listener(update as DeeplyLoaded<V, Depth>);
|
191
|
+
}
|
192
|
+
},
|
193
|
+
);
|
194
|
+
|
195
|
+
unsubscribe = () => subscription.unsubscribeAll();
|
196
|
+
})
|
197
|
+
.catch((e) => {
|
198
|
+
console.error("Failed to load / subscribe to CoValue", e);
|
199
|
+
});
|
191
200
|
|
192
|
-
return function
|
201
|
+
return function unsubscribeAtAnyPoint() {
|
202
|
+
unsubscribed = true;
|
203
|
+
unsubscribe && unsubscribe();
|
204
|
+
};
|
193
205
|
}
|
194
206
|
|
195
207
|
export function subscribeToExistingCoValue<V extends CoValue, Depth>(
|
@@ -205,43 +217,3 @@ export function subscribeToExistingCoValue<V extends CoValue, Depth>(
|
|
205
217
|
listener,
|
206
218
|
);
|
207
219
|
}
|
208
|
-
|
209
|
-
export function subscribeToCoValueEf<V extends CoValue, Depth>(
|
210
|
-
cls: CoValueClass<V>,
|
211
|
-
id: ID<V>,
|
212
|
-
depth: Depth & DepthsIn<V>,
|
213
|
-
): Stream.Stream<DeeplyLoaded<V, Depth>, UnavailableError, AccountCtx> {
|
214
|
-
return AccountCtx.pipe(
|
215
|
-
Effect.andThen((account) =>
|
216
|
-
new Ref(id, account, {
|
217
|
-
ref: cls,
|
218
|
-
optional: false,
|
219
|
-
}).loadEf(),
|
220
|
-
),
|
221
|
-
Stream.fromEffect,
|
222
|
-
Stream.flatMap((value: V) =>
|
223
|
-
Stream.asyncScoped<V, UnavailableError>((emit) =>
|
224
|
-
Effect.gen(function* (_) {
|
225
|
-
const subscription = new SubscriptionScope(
|
226
|
-
value,
|
227
|
-
cls as CoValueClass<V> & CoValueFromRaw<V>,
|
228
|
-
(update) => void emit.single(update as V),
|
229
|
-
);
|
230
|
-
|
231
|
-
yield* _(
|
232
|
-
Effect.addFinalizer(() =>
|
233
|
-
Effect.sync(() => subscription.unsubscribeAll()),
|
234
|
-
),
|
235
|
-
);
|
236
|
-
}),
|
237
|
-
),
|
238
|
-
),
|
239
|
-
Stream.filterMap((update: V) =>
|
240
|
-
Option.fromNullable(
|
241
|
-
fulfillsDepth(depth, update)
|
242
|
-
? (update as DeeplyLoaded<V, Depth>)
|
243
|
-
: undefined,
|
244
|
-
),
|
245
|
-
),
|
246
|
-
);
|
247
|
-
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { Effect } from "effect";
|
2
1
|
import type { CoID, RawCoValue } from "cojson";
|
3
2
|
import type {
|
4
3
|
Account,
|
@@ -6,7 +5,6 @@ import type {
|
|
6
5
|
ID,
|
7
6
|
RefEncoded,
|
8
7
|
UnCo,
|
9
|
-
UnavailableError,
|
10
8
|
} from "../internal.js";
|
11
9
|
import {
|
12
10
|
instantiateRefEncoded,
|
@@ -47,22 +45,6 @@ export class Ref<out V extends CoValue> {
|
|
47
45
|
}
|
48
46
|
}
|
49
47
|
|
50
|
-
loadEf() {
|
51
|
-
return Effect.async<V, UnavailableError>((fulfill) => {
|
52
|
-
this.loadHelper()
|
53
|
-
.then((value) => {
|
54
|
-
if (value === "unavailable") {
|
55
|
-
fulfill(Effect.fail<UnavailableError>("unavailable"));
|
56
|
-
} else {
|
57
|
-
fulfill(Effect.succeed(value));
|
58
|
-
}
|
59
|
-
})
|
60
|
-
.catch((e) => {
|
61
|
-
fulfill(Effect.die(e));
|
62
|
-
});
|
63
|
-
});
|
64
|
-
}
|
65
|
-
|
66
48
|
private async loadHelper(options?: {
|
67
49
|
onProgress: (p: number) => void;
|
68
50
|
}): Promise<V | "unavailable"> {
|
@@ -17,6 +17,36 @@ export type IfCo<C, R> = C extends infer _A | infer B
|
|
17
17
|
: never;
|
18
18
|
export type UnCo<T> = T extends co<infer A> ? A : T;
|
19
19
|
|
20
|
+
const optional = {
|
21
|
+
ref: optionalRef,
|
22
|
+
json<T extends JsonValue>(): co<T | undefined> {
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
24
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
25
|
+
},
|
26
|
+
encoded<T>(arg: OptionalEncoder<T>): co<T | undefined> {
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
28
|
+
return { [SchemaInit]: { encoded: arg } satisfies Schema } as any;
|
29
|
+
},
|
30
|
+
string: {
|
31
|
+
[SchemaInit]: "json" satisfies Schema,
|
32
|
+
} as unknown as co<string | undefined>,
|
33
|
+
number: {
|
34
|
+
[SchemaInit]: "json" satisfies Schema,
|
35
|
+
} as unknown as co<number | undefined>,
|
36
|
+
boolean: {
|
37
|
+
[SchemaInit]: "json" satisfies Schema,
|
38
|
+
} as unknown as co<boolean | undefined>,
|
39
|
+
null: {
|
40
|
+
[SchemaInit]: "json" satisfies Schema,
|
41
|
+
} as unknown as co<null | undefined>,
|
42
|
+
literal<T extends (string | number | boolean)[]>(
|
43
|
+
..._lit: T
|
44
|
+
): co<T[number] | undefined> {
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
46
|
+
return { [SchemaInit]: "json" satisfies Schema } as any;
|
47
|
+
},
|
48
|
+
};
|
49
|
+
|
20
50
|
/** @category Schema definition */
|
21
51
|
export const co = {
|
22
52
|
string: {
|
@@ -48,8 +78,15 @@ export const co = {
|
|
48
78
|
ref,
|
49
79
|
items: ItemsSym as ItemsSym,
|
50
80
|
members: MembersSym as MembersSym,
|
81
|
+
optional,
|
51
82
|
};
|
52
83
|
|
84
|
+
function optionalRef<C extends CoValueClass>(
|
85
|
+
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
86
|
+
): co<InstanceType<C> | null | undefined> {
|
87
|
+
return ref(arg, { optional: true });
|
88
|
+
}
|
89
|
+
|
53
90
|
function ref<C extends CoValueClass>(
|
54
91
|
arg: C | ((_raw: InstanceType<C>["_raw"]) => C),
|
55
92
|
): co<InstanceType<C> | null>;
|
@@ -131,6 +168,10 @@ export type EffectSchemaWithInputAndOutput<A, I = A> = EffectSchema<
|
|
131
168
|
};
|
132
169
|
|
133
170
|
export type Encoder<V> = EffectSchemaWithInputAndOutput<V, JsonValue>;
|
171
|
+
export type OptionalEncoder<V> = EffectSchemaWithInputAndOutput<
|
172
|
+
V,
|
173
|
+
JsonValue | undefined
|
174
|
+
>;
|
134
175
|
|
135
176
|
import { Date } from "@effect/schema/Schema";
|
136
177
|
import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
|
package/src/index.ts
CHANGED
@@ -26,9 +26,4 @@ export { ImageDefinition } from "./internal.js";
|
|
26
26
|
export { CoValueBase, type CoValueClass } from "./internal.js";
|
27
27
|
export type { DepthsIn, DeeplyLoaded } from "./internal.js";
|
28
28
|
|
29
|
-
export {
|
30
|
-
loadCoValue,
|
31
|
-
loadCoValueEf,
|
32
|
-
subscribeToCoValue,
|
33
|
-
subscribeToCoValueEf,
|
34
|
-
} from "./internal.js";
|
29
|
+
export { loadCoValue, subscribeToCoValue } from "./internal.js";
|
package/src/tests/coList.test.ts
CHANGED
@@ -157,11 +157,12 @@ describe("CoList resolution", async () => {
|
|
157
157
|
test("Loading and availability", async () => {
|
158
158
|
const { me, list } = await initNodeAndList();
|
159
159
|
|
160
|
-
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
161
|
-
"initial",
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
161
|
+
connectedPeers("initial", "second", {
|
162
|
+
peer1role: "server",
|
163
|
+
peer2role: "client",
|
164
|
+
}),
|
165
|
+
);
|
165
166
|
if (!isControlledAccount(me)) {
|
166
167
|
throw "me is not a controlled account";
|
167
168
|
}
|
@@ -216,11 +217,12 @@ describe("CoList resolution", async () => {
|
|
216
217
|
test("Subscription & auto-resolution", async () => {
|
217
218
|
const { me, list } = await initNodeAndList();
|
218
219
|
|
219
|
-
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
220
|
-
"initial",
|
221
|
-
|
222
|
-
|
223
|
-
|
220
|
+
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
221
|
+
connectedPeers("initial", "second", {
|
222
|
+
peer1role: "server",
|
223
|
+
peer2role: "client",
|
224
|
+
}),
|
225
|
+
);
|
224
226
|
if (!isControlledAccount(me)) {
|
225
227
|
throw "me is not a controlled account";
|
226
228
|
}
|
package/src/tests/coMap.test.ts
CHANGED
@@ -25,7 +25,8 @@ describe("Simple CoMap operations", async () => {
|
|
25
25
|
_height = co.number;
|
26
26
|
birthday = co.encoded(Encoders.Date);
|
27
27
|
name? = co.string;
|
28
|
-
nullable = co.encoded(Schema.
|
28
|
+
nullable = co.optional.encoded(Schema.NullishOr(Schema.String));
|
29
|
+
optionalDate = co.optional.encoded(Encoders.Date);
|
29
30
|
|
30
31
|
get roughColor() {
|
31
32
|
return this.color + "ish";
|
@@ -94,6 +95,8 @@ describe("Simple CoMap operations", async () => {
|
|
94
95
|
|
95
96
|
map.nullable = "not null";
|
96
97
|
map.nullable = null;
|
98
|
+
delete map.nullable;
|
99
|
+
map.nullable = undefined;
|
97
100
|
|
98
101
|
map.name = "Secret name";
|
99
102
|
expect(map.name).toEqual("Secret name");
|
@@ -442,7 +445,7 @@ describe("CoMap resolution", async () => {
|
|
442
445
|
|
443
446
|
class TestMapWithOptionalRef extends CoMap {
|
444
447
|
color = co.string;
|
445
|
-
nested = co.ref(NestedMap
|
448
|
+
nested = co.optional.ref(NestedMap);
|
446
449
|
}
|
447
450
|
|
448
451
|
test("Construction with optional", async () => {
|
@@ -39,10 +39,12 @@ describe("Deep loading with depth arg", async () => {
|
|
39
39
|
crypto: Crypto,
|
40
40
|
});
|
41
41
|
|
42
|
-
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
43
|
+
connectedPeers("initial", "second", {
|
44
|
+
peer1role: "server",
|
45
|
+
peer2role: "client",
|
46
|
+
}),
|
47
|
+
);
|
46
48
|
if (!isControlledAccount(me)) {
|
47
49
|
throw "me is not a controlled account";
|
48
50
|
}
|
@@ -252,10 +254,12 @@ test("Deep loading a record-like coMap", async () => {
|
|
252
254
|
crypto: Crypto,
|
253
255
|
});
|
254
256
|
|
255
|
-
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
256
|
-
|
257
|
-
|
258
|
-
|
257
|
+
const [initialAsPeer, secondPeer] = await Effect.runPromise(
|
258
|
+
connectedPeers("initial", "second", {
|
259
|
+
peer1role: "server",
|
260
|
+
peer2role: "client",
|
261
|
+
}),
|
262
|
+
);
|
259
263
|
if (!isControlledAccount(me)) {
|
260
264
|
throw "me is not a controlled account";
|
261
265
|
}
|