jazz-tools 0.7.0-alpha.30 → 0.7.0-alpha.32
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +55 -57
- package/CHANGELOG.md +13 -0
- package/dist/cli/index.js +46 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/coValues/account.js +9 -6
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +10 -7
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +57 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +55 -4
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +1 -0
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +8 -2
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +10 -1
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/schema.js +3 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/subscriptionScope.js.map +1 -1
- package/dist/tests/coList.test.js +13 -13
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +22 -22
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +9 -9
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +6 -4
- package/dist/tests/groupsAndAccounts.test.js.map +1 -1
- package/package.json +14 -8
- package/src/cli/index.ts +69 -0
- package/src/coValues/account.ts +29 -42
- package/src/coValues/coList.ts +24 -17
- package/src/coValues/coMap.ts +73 -20
- package/src/coValues/coStream.ts +110 -18
- package/src/coValues/extensions/imageDef.ts +2 -1
- package/src/coValues/group.ts +34 -48
- package/src/coValues/interfaces.ts +30 -20
- package/src/implementation/schema.ts +5 -1
- package/src/implementation/subscriptionScope.ts +2 -2
- package/src/tests/coList.test.ts +16 -16
- package/src/tests/coMap.test.ts +35 -35
- package/src/tests/coStream.test.ts +11 -11
- package/src/tests/groupsAndAccounts.test.ts +13 -9
@@ -12,10 +12,11 @@ import {
|
|
12
12
|
subscriptionsScopes,
|
13
13
|
} from "../internal.js";
|
14
14
|
|
15
|
-
export type
|
15
|
+
export type ClassOf<T> = {
|
16
16
|
new (...args: any[]): T;
|
17
17
|
};
|
18
18
|
|
19
|
+
/** @category Abstract interfaces */
|
19
20
|
export interface CoValueClass<Value extends CoValue = CoValue, Init = any> {
|
20
21
|
/** @category Construction and loading */
|
21
22
|
new (init: Init, options: { owner: Account | Group }): Value;
|
@@ -25,7 +26,7 @@ export interface CoValueClass<Value extends CoValue = CoValue, Init = any> {
|
|
25
26
|
|
26
27
|
/** @category Construction and loading */
|
27
28
|
load<V extends Value>(
|
28
|
-
this:
|
29
|
+
this: ClassOf<V>,
|
29
30
|
id: ID<V>,
|
30
31
|
options: {
|
31
32
|
as: Account & Me;
|
@@ -35,13 +36,13 @@ export interface CoValueClass<Value extends CoValue = CoValue, Init = any> {
|
|
35
36
|
|
36
37
|
/** @category Construction and loading */
|
37
38
|
loadEf<V extends Value>(
|
38
|
-
this:
|
39
|
+
this: ClassOf<V>,
|
39
40
|
id: ID<V>
|
40
41
|
): Effect.Effect<V, UnavailableError, AccountCtx>;
|
41
42
|
|
42
43
|
/** @category Subscription */
|
43
44
|
subscribe<V extends Value, Acc extends Account>(
|
44
|
-
this:
|
45
|
+
this: ClassOf<V>,
|
45
46
|
id: ID<V>,
|
46
47
|
options: { as: Acc & Me },
|
47
48
|
onUpdate: (value: V) => void
|
@@ -49,30 +50,30 @@ export interface CoValueClass<Value extends CoValue = CoValue, Init = any> {
|
|
49
50
|
|
50
51
|
/** @category Subscription */
|
51
52
|
subscribeEf<V extends Value>(
|
52
|
-
this:
|
53
|
+
this: ClassOf<V>,
|
53
54
|
id: ID<V>
|
54
55
|
): Stream.Stream<V, UnavailableError, AccountCtx>;
|
55
56
|
}
|
56
57
|
|
57
|
-
/** @category
|
58
|
+
/** @category Abstract interfaces */
|
58
59
|
export interface CoValue<Type extends string = string, Raw = any> {
|
59
|
-
/** @category
|
60
|
+
/** @category Content */
|
60
61
|
readonly id: ID<this>;
|
61
|
-
/** @category
|
62
|
+
/** @category Type Helpers */
|
62
63
|
_type: Type;
|
63
64
|
/** @category Collaboration */
|
64
65
|
_owner: Account | Group;
|
65
|
-
/** @category Subscription */
|
66
|
+
/** @category Subscription & Loading */
|
66
67
|
subscribe(listener: (update: this) => void): () => void;
|
67
|
-
/** @category Subscription */
|
68
|
+
/** @category Subscription & Loading */
|
68
69
|
subscribeEf(): Stream.Stream<this, UnavailableError, never>;
|
69
70
|
/** @category Internals */
|
70
71
|
_raw: Raw;
|
71
|
-
/** @
|
72
|
+
/** @internal */
|
72
73
|
readonly _loadedAs: Account & Me;
|
73
|
-
/** @category Stringifying &
|
74
|
+
/** @category Stringifying & Inspection */
|
74
75
|
toJSON(): any[] | object;
|
75
|
-
/** @category Stringifying &
|
76
|
+
/** @category Stringifying & Inspection */
|
76
77
|
[inspect](): any;
|
77
78
|
}
|
78
79
|
|
@@ -83,11 +84,12 @@ export function isCoValueClass(value: any): value is CoValueClass {
|
|
83
84
|
return typeof value === "function" && value.fromRaw !== undefined;
|
84
85
|
}
|
85
86
|
|
86
|
-
/** @category
|
87
|
+
/** @category CoValues */
|
87
88
|
export type ID<T> = CojsonInternalTypes.RawCoID & IDMarker<T>;
|
88
89
|
|
89
90
|
type IDMarker<out T> = { __type(_: never): T };
|
90
91
|
|
92
|
+
/** @internal */
|
91
93
|
export class CoValueBase implements CoValue {
|
92
94
|
id!: ID<this>;
|
93
95
|
_type!: string;
|
@@ -114,15 +116,17 @@ export class CoValueBase implements CoValue {
|
|
114
116
|
|
115
117
|
constructor(..._args: any) {}
|
116
118
|
|
119
|
+
/** @category Internals */
|
117
120
|
static fromRaw<V extends CoValue>(
|
118
|
-
this:
|
121
|
+
this: ClassOf<V>,
|
119
122
|
raw: RawCoValue
|
120
123
|
): V {
|
121
|
-
return new this(
|
124
|
+
return new this({ fromRaw: raw });
|
122
125
|
}
|
123
126
|
|
127
|
+
/** @category Subscription & Loading */
|
124
128
|
static loadEf<V extends CoValue>(
|
125
|
-
this:
|
129
|
+
this: ClassOf<V> & typeof CoValueBase,
|
126
130
|
id: ID<V>
|
127
131
|
): Effect.Effect<V, UnavailableError, AccountCtx> {
|
128
132
|
return Effect.gen(this, function* (_) {
|
@@ -133,8 +137,9 @@ export class CoValueBase implements CoValue {
|
|
133
137
|
});
|
134
138
|
}
|
135
139
|
|
140
|
+
/** @category Subscription & Loading */
|
136
141
|
static load<V extends CoValue>(
|
137
|
-
this:
|
142
|
+
this: ClassOf<V> & typeof CoValueBase,
|
138
143
|
id: ID<V>,
|
139
144
|
options: {
|
140
145
|
as: Account & Me;
|
@@ -146,8 +151,9 @@ export class CoValueBase implements CoValue {
|
|
146
151
|
);
|
147
152
|
}
|
148
153
|
|
154
|
+
/** @category Subscription & Loading */
|
149
155
|
static subscribe<V extends CoValue, Acc extends Account>(
|
150
|
-
this:
|
156
|
+
this: ClassOf<V> & typeof CoValueBase,
|
151
157
|
id: ID<V>,
|
152
158
|
options: { as: Acc & Me },
|
153
159
|
onUpdate: (value: V) => void
|
@@ -169,8 +175,9 @@ export class CoValueBase implements CoValue {
|
|
169
175
|
return function unsubscribe() {};
|
170
176
|
}
|
171
177
|
|
178
|
+
/** @category Subscription & Loading */
|
172
179
|
static subscribeEf<V extends CoValue>(
|
173
|
-
this:
|
180
|
+
this: ClassOf<V> & typeof CoValueBase,
|
174
181
|
id: ID<V>
|
175
182
|
): Stream.Stream<V, UnavailableError, AccountCtx> {
|
176
183
|
return Stream.fromEffect(this.loadEf(id)).pipe(
|
@@ -196,6 +203,7 @@ export class CoValueBase implements CoValue {
|
|
196
203
|
);
|
197
204
|
}
|
198
205
|
|
206
|
+
/** @category Subscription & Loading */
|
199
207
|
subscribe(listener: (update: this) => void): () => void {
|
200
208
|
return (this.constructor as unknown as typeof CoValueBase).subscribe(
|
201
209
|
this.id as unknown as ID<CoValue>,
|
@@ -204,6 +212,7 @@ export class CoValueBase implements CoValue {
|
|
204
212
|
);
|
205
213
|
}
|
206
214
|
|
215
|
+
/** @category Subscription & Loading */
|
207
216
|
subscribeEf(): Stream.Stream<this, UnavailableError, never> {
|
208
217
|
return Stream.provideService(
|
209
218
|
(this.constructor as unknown as typeof CoValueBase).subscribeEf(
|
@@ -226,6 +235,7 @@ export class CoValueBase implements CoValue {
|
|
226
235
|
return this.toJSON();
|
227
236
|
}
|
228
237
|
|
238
|
+
/** @category Type Helpers*/
|
229
239
|
as<C extends CoValueClass>(otherSchema: C): InstanceType<C> {
|
230
240
|
const cast = otherSchema.fromRaw(this._raw) as InstanceType<C>;
|
231
241
|
const subScope = subscriptionsScopes.get(this);
|
@@ -3,13 +3,16 @@ import { type CoValue, type CoValueClass, isCoValueClass } from "../internal.js"
|
|
3
3
|
import type { Schema as EffectSchema, TypeId } from "@effect/schema/Schema";
|
4
4
|
|
5
5
|
export type CoMarker = { readonly __co: unique symbol };
|
6
|
+
/** @category Schema definition */
|
6
7
|
export type co<T> = T | (T & CoMarker);
|
7
8
|
export type IfCo<C, R> = C extends infer _A | infer B
|
8
9
|
? B extends CoMarker
|
9
10
|
? R
|
10
11
|
: never
|
11
12
|
: never;
|
13
|
+
export type UnCo<T> = T extends co<infer A> ? A : T;
|
12
14
|
|
15
|
+
/** @category Schema definition */
|
13
16
|
export const co = {
|
14
17
|
string: {
|
15
18
|
[SchemaInit]: "json" satisfies Schema,
|
@@ -23,7 +26,7 @@ export const co = {
|
|
23
26
|
null: {
|
24
27
|
[SchemaInit]: "json" satisfies Schema,
|
25
28
|
} as unknown as co<null>,
|
26
|
-
literal: <T extends string | number | boolean>(_lit: T): co<T> => {
|
29
|
+
literal: <T extends (string | number | boolean)[]>(..._lit: T): co<T[number]> => {
|
27
30
|
return { [SchemaInit]: "json" satisfies Schema } as any;
|
28
31
|
},
|
29
32
|
json: <T extends JsonValue>(): co<T> => {
|
@@ -86,6 +89,7 @@ export type Encoder<V> = EffectSchemaWithInputAndOutput<V, JsonValue>;
|
|
86
89
|
import { Date } from "@effect/schema/Schema";
|
87
90
|
import { SchemaInit, ItemsSym, MembersSym } from "./symbols.js";
|
88
91
|
|
92
|
+
/** @category Schema definition */
|
89
93
|
export const Encoders = {
|
90
94
|
Date,
|
91
95
|
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { RawCoValue } from "cojson";
|
2
|
-
import type { Account, CoValue, CoValueBase, ID, Me,
|
2
|
+
import type { Account, CoValue, CoValueBase, ID, Me, ClassOf } from "../internal.js";
|
3
3
|
|
4
4
|
export const subscriptionsScopes = new WeakMap<
|
5
5
|
CoValue,
|
@@ -26,7 +26,7 @@ export class SubscriptionScope<
|
|
26
26
|
|
27
27
|
constructor(
|
28
28
|
root: Root,
|
29
|
-
rootSchema:
|
29
|
+
rootSchema: ClassOf<Root> & typeof CoValueBase,
|
30
30
|
onUpdate: (newRoot: Root) => void
|
31
31
|
) {
|
32
32
|
this.rootEntry = {
|
package/src/tests/coList.test.ts
CHANGED
@@ -22,7 +22,7 @@ describe("Simple CoList operations", async () => {
|
|
22
22
|
|
23
23
|
class TestList extends CoList.Of(co.string) {}
|
24
24
|
|
25
|
-
const list =
|
25
|
+
const list = TestList.create(["bread", "butter", "onion"], { owner: me });
|
26
26
|
|
27
27
|
test("Construction", () => {
|
28
28
|
expect(list[0]).toBe("bread");
|
@@ -39,7 +39,7 @@ describe("Simple CoList operations", async () => {
|
|
39
39
|
|
40
40
|
describe("Mutation", () => {
|
41
41
|
test("assignment", () => {
|
42
|
-
const list =
|
42
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
43
43
|
owner: me,
|
44
44
|
});
|
45
45
|
list[1] = "margarine";
|
@@ -52,7 +52,7 @@ describe("Simple CoList operations", async () => {
|
|
52
52
|
});
|
53
53
|
|
54
54
|
test("push", () => {
|
55
|
-
const list =
|
55
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
56
56
|
owner: me,
|
57
57
|
});
|
58
58
|
list.push("cheese");
|
@@ -66,7 +66,7 @@ describe("Simple CoList operations", async () => {
|
|
66
66
|
});
|
67
67
|
|
68
68
|
test("unshift", () => {
|
69
|
-
const list =
|
69
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
70
70
|
owner: me,
|
71
71
|
});
|
72
72
|
list.unshift("lettuce");
|
@@ -80,7 +80,7 @@ describe("Simple CoList operations", async () => {
|
|
80
80
|
});
|
81
81
|
|
82
82
|
test("pop", () => {
|
83
|
-
const list =
|
83
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
84
84
|
owner: me,
|
85
85
|
});
|
86
86
|
expect(list.pop()).toBe("onion");
|
@@ -89,7 +89,7 @@ describe("Simple CoList operations", async () => {
|
|
89
89
|
});
|
90
90
|
|
91
91
|
test("shift", () => {
|
92
|
-
const list =
|
92
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
93
93
|
owner: me,
|
94
94
|
});
|
95
95
|
expect(list.shift()).toBe("bread");
|
@@ -98,7 +98,7 @@ describe("Simple CoList operations", async () => {
|
|
98
98
|
});
|
99
99
|
|
100
100
|
test("splice", () => {
|
101
|
-
const list =
|
101
|
+
const list = TestList.create(["bread", "butter", "onion"], {
|
102
102
|
owner: me,
|
103
103
|
});
|
104
104
|
list.splice(1, 1, "salt", "pepper");
|
@@ -129,14 +129,14 @@ describe("CoList resolution", async () => {
|
|
129
129
|
creationProps: { name: "Hermes Puggington" },
|
130
130
|
});
|
131
131
|
|
132
|
-
const list =
|
132
|
+
const list = TestList.create(
|
133
133
|
[
|
134
|
-
|
135
|
-
[
|
134
|
+
NestedList.create(
|
135
|
+
[TwiceNestedList.create(["a", "b"], { owner: me })],
|
136
136
|
{ owner: me }
|
137
137
|
),
|
138
|
-
|
139
|
-
[
|
138
|
+
NestedList.create(
|
139
|
+
[TwiceNestedList.create(["c", "d"], { owner: me })],
|
140
140
|
{ owner: me }
|
141
141
|
),
|
142
142
|
],
|
@@ -196,8 +196,8 @@ describe("CoList resolution", async () => {
|
|
196
196
|
expect(loadedList?.[0]?._refs[0]?.id).toEqual(list[0]?.[0]?.id);
|
197
197
|
expect(loadedList?.[0]?._refs[0]?.value).toEqual(loadedTwiceNestedList);
|
198
198
|
|
199
|
-
const otherNestedList =
|
200
|
-
[
|
199
|
+
const otherNestedList = NestedList.create(
|
200
|
+
[TwiceNestedList.create(["e", "f"], { owner: meOnSecondPeer })],
|
201
201
|
{ owner: meOnSecondPeer }
|
202
202
|
);
|
203
203
|
|
@@ -257,11 +257,11 @@ describe("CoList resolution", async () => {
|
|
257
257
|
|
258
258
|
// When assigning a new nested value, we get an update
|
259
259
|
|
260
|
-
const newTwiceNestedList =
|
260
|
+
const newTwiceNestedList = TwiceNestedList.create(["y", "z"], {
|
261
261
|
owner: meOnSecondPeer,
|
262
262
|
});
|
263
263
|
|
264
|
-
const newNestedList =
|
264
|
+
const newNestedList = NestedList.create([newTwiceNestedList], {
|
265
265
|
owner: meOnSecondPeer,
|
266
266
|
});
|
267
267
|
|
package/src/tests/coMap.test.ts
CHANGED
@@ -20,7 +20,7 @@ describe("Simple CoMap operations", async () => {
|
|
20
20
|
creationProps: { name: "Hermes Puggington" },
|
21
21
|
});
|
22
22
|
|
23
|
-
class TestMap extends CoMap
|
23
|
+
class TestMap extends CoMap {
|
24
24
|
color = co.string;
|
25
25
|
_height = co.number;
|
26
26
|
birthday = co.encoded(Encoders.Date);
|
@@ -35,7 +35,7 @@ describe("Simple CoMap operations", async () => {
|
|
35
35
|
|
36
36
|
const birthday = new Date();
|
37
37
|
|
38
|
-
const map =
|
38
|
+
const map = TestMap.create(
|
39
39
|
{
|
40
40
|
color: "red",
|
41
41
|
_height: 10,
|
@@ -80,18 +80,18 @@ describe("Simple CoMap operations", async () => {
|
|
80
80
|
});
|
81
81
|
});
|
82
82
|
|
83
|
-
class RecursiveMap extends CoMap
|
83
|
+
class RecursiveMap extends CoMap {
|
84
84
|
name = co.string;
|
85
85
|
next: co<RecursiveMap | null> = co.ref(RecursiveMap);
|
86
86
|
}
|
87
87
|
|
88
|
-
const recursiveMap =
|
88
|
+
const recursiveMap = RecursiveMap.create(
|
89
89
|
{
|
90
90
|
name: "first",
|
91
|
-
next:
|
91
|
+
next: RecursiveMap.create(
|
92
92
|
{
|
93
93
|
name: "second",
|
94
|
-
next:
|
94
|
+
next: RecursiveMap.create(
|
95
95
|
{
|
96
96
|
name: "third",
|
97
97
|
},
|
@@ -112,27 +112,27 @@ describe("Simple CoMap operations", async () => {
|
|
112
112
|
});
|
113
113
|
});
|
114
114
|
|
115
|
-
class MapWithEnumOfMaps extends CoMap
|
115
|
+
class MapWithEnumOfMaps extends CoMap {
|
116
116
|
name = co.string;
|
117
117
|
child = co.ref<typeof ChildA | typeof ChildB>((raw) =>
|
118
118
|
raw.get("type") === "a" ? ChildA : ChildB
|
119
119
|
);
|
120
120
|
}
|
121
121
|
|
122
|
-
class ChildA extends CoMap
|
122
|
+
class ChildA extends CoMap {
|
123
123
|
type = co.literal("a");
|
124
124
|
value = co.number;
|
125
125
|
}
|
126
126
|
|
127
|
-
class ChildB extends CoMap
|
127
|
+
class ChildB extends CoMap {
|
128
128
|
type = co.literal("b");
|
129
129
|
value = co.string;
|
130
130
|
}
|
131
131
|
|
132
|
-
const mapWithEnum =
|
132
|
+
const mapWithEnum = MapWithEnumOfMaps.create(
|
133
133
|
{
|
134
134
|
name: "enum",
|
135
|
-
child:
|
135
|
+
child: ChildA.create(
|
136
136
|
{
|
137
137
|
type: "a",
|
138
138
|
value: 5,
|
@@ -150,7 +150,7 @@ describe("Simple CoMap operations", async () => {
|
|
150
150
|
expect(mapWithEnum.child?.id).toBeDefined();
|
151
151
|
});
|
152
152
|
|
153
|
-
class SuperClassMap extends CoMap
|
153
|
+
class SuperClassMap extends CoMap {
|
154
154
|
name = co.string;
|
155
155
|
}
|
156
156
|
|
@@ -159,11 +159,11 @@ describe("Simple CoMap operations", async () => {
|
|
159
159
|
value = co.number;
|
160
160
|
extra = co.ref(TestMap);
|
161
161
|
}
|
162
|
-
interface SubClassMap extends CoMap
|
162
|
+
interface SubClassMap extends CoMap {}
|
163
163
|
|
164
164
|
class GenericMapWithLoose<
|
165
165
|
out T extends string = string,
|
166
|
-
> extends CoMap
|
166
|
+
> extends CoMap {
|
167
167
|
name = co.json<T>();
|
168
168
|
}
|
169
169
|
|
@@ -173,11 +173,11 @@ describe("Simple CoMap operations", async () => {
|
|
173
173
|
});
|
174
174
|
|
175
175
|
describe("CoMap resolution", async () => {
|
176
|
-
class TwiceNestedMap extends CoMap
|
176
|
+
class TwiceNestedMap extends CoMap {
|
177
177
|
taste = co.string;
|
178
178
|
}
|
179
179
|
|
180
|
-
class NestedMap extends CoMap
|
180
|
+
class NestedMap extends CoMap {
|
181
181
|
name = co.string;
|
182
182
|
twiceNested = co.ref(TwiceNestedMap);
|
183
183
|
|
@@ -186,7 +186,7 @@ describe("CoMap resolution", async () => {
|
|
186
186
|
}
|
187
187
|
}
|
188
188
|
|
189
|
-
class TestMap extends CoMap
|
189
|
+
class TestMap extends CoMap {
|
190
190
|
color = co.string;
|
191
191
|
height = co.number;
|
192
192
|
nested = co.ref(NestedMap);
|
@@ -201,14 +201,14 @@ describe("CoMap resolution", async () => {
|
|
201
201
|
creationProps: { name: "Hermes Puggington" },
|
202
202
|
});
|
203
203
|
|
204
|
-
const map =
|
204
|
+
const map = TestMap.create(
|
205
205
|
{
|
206
206
|
color: "red",
|
207
207
|
height: 10,
|
208
|
-
nested:
|
208
|
+
nested: NestedMap.create(
|
209
209
|
{
|
210
210
|
name: "nested",
|
211
|
-
twiceNested:
|
211
|
+
twiceNested: TwiceNestedMap.create(
|
212
212
|
{ taste: "sour" },
|
213
213
|
{ owner: me }
|
214
214
|
),
|
@@ -278,10 +278,10 @@ describe("CoMap resolution", async () => {
|
|
278
278
|
loadedTwiceNestedMap
|
279
279
|
);
|
280
280
|
|
281
|
-
const otherNestedMap =
|
281
|
+
const otherNestedMap = NestedMap.create(
|
282
282
|
{
|
283
283
|
name: "otherNested",
|
284
|
-
twiceNested:
|
284
|
+
twiceNested: TwiceNestedMap.create(
|
285
285
|
{ taste: "sweet" },
|
286
286
|
{ owner: meOnSecondPeer }
|
287
287
|
),
|
@@ -347,14 +347,14 @@ describe("CoMap resolution", async () => {
|
|
347
347
|
expect(oldTwiceNested?.taste).toEqual("sour");
|
348
348
|
|
349
349
|
// When assigning a new nested value, we get an update
|
350
|
-
const newTwiceNested =
|
350
|
+
const newTwiceNested = TwiceNestedMap.create(
|
351
351
|
{
|
352
352
|
taste: "sweet",
|
353
353
|
},
|
354
354
|
{ owner: meOnSecondPeer }
|
355
355
|
);
|
356
356
|
|
357
|
-
const newNested =
|
357
|
+
const newNested = NestedMap.create(
|
358
358
|
{
|
359
359
|
name: "newNested",
|
360
360
|
twiceNested: newTwiceNested,
|
@@ -383,7 +383,7 @@ describe("CoMap resolution", async () => {
|
|
383
383
|
);
|
384
384
|
});
|
385
385
|
|
386
|
-
class TestMapWithOptionalRef extends CoMap
|
386
|
+
class TestMapWithOptionalRef extends CoMap {
|
387
387
|
color = co.string;
|
388
388
|
nested? = co.ref(NestedMap);
|
389
389
|
}
|
@@ -393,7 +393,7 @@ describe("CoMap resolution", async () => {
|
|
393
393
|
creationProps: { name: "Hermes Puggington" },
|
394
394
|
});
|
395
395
|
|
396
|
-
const mapWithout =
|
396
|
+
const mapWithout = TestMapWithOptionalRef.create(
|
397
397
|
{
|
398
398
|
color: "red",
|
399
399
|
},
|
@@ -403,13 +403,13 @@ describe("CoMap resolution", async () => {
|
|
403
403
|
expect(mapWithout.color).toEqual("red");
|
404
404
|
expect(mapWithout.nested).toEqual(undefined);
|
405
405
|
|
406
|
-
const mapWith =
|
406
|
+
const mapWith = TestMapWithOptionalRef.create(
|
407
407
|
{
|
408
408
|
color: "red",
|
409
|
-
nested:
|
409
|
+
nested: NestedMap.create(
|
410
410
|
{
|
411
411
|
name: "wow!",
|
412
|
-
twiceNested:
|
412
|
+
twiceNested: TwiceNestedMap.create(
|
413
413
|
{ taste: "sour" },
|
414
414
|
{ owner: me }
|
415
415
|
),
|
@@ -426,7 +426,7 @@ describe("CoMap resolution", async () => {
|
|
426
426
|
expect(mapWith.nested?._raw).toBeDefined();
|
427
427
|
});
|
428
428
|
|
429
|
-
class TestRecord extends CoMap
|
429
|
+
class TestRecord extends CoMap {
|
430
430
|
[co.items] = co.number;
|
431
431
|
}
|
432
432
|
interface TestRecord extends Record<string, number> {}
|
@@ -436,7 +436,7 @@ describe("CoMap resolution", async () => {
|
|
436
436
|
creationProps: { name: "Hermes Puggington" },
|
437
437
|
});
|
438
438
|
|
439
|
-
const record =
|
439
|
+
const record = TestRecord.create(
|
440
440
|
{
|
441
441
|
height: 5,
|
442
442
|
other: 3,
|
@@ -464,7 +464,7 @@ describe("CoMap resolution", async () => {
|
|
464
464
|
creationProps: { name: "Hermes Puggington" },
|
465
465
|
});
|
466
466
|
|
467
|
-
const record =
|
467
|
+
const record = TestRecord2.create(
|
468
468
|
{
|
469
469
|
height: 5,
|
470
470
|
other: 3,
|
@@ -486,13 +486,13 @@ describe("CoMap resolution", async () => {
|
|
486
486
|
creationProps: { name: "Hermes Puggington" },
|
487
487
|
});
|
488
488
|
|
489
|
-
const record =
|
489
|
+
const record = TestRecordRef.create(
|
490
490
|
{
|
491
|
-
firstNested:
|
491
|
+
firstNested: TwiceNestedMap.create(
|
492
492
|
{ taste: "sour" },
|
493
493
|
{ owner: me }
|
494
494
|
),
|
495
|
-
secondNested:
|
495
|
+
secondNested: TwiceNestedMap.create(
|
496
496
|
{ taste: "sweet" },
|
497
497
|
{ owner: me }
|
498
498
|
),
|
@@ -23,7 +23,7 @@ describe("Simple CoStream operations", async () => {
|
|
23
23
|
|
24
24
|
class TestStream extends CoStream.Of(co.string) {}
|
25
25
|
|
26
|
-
const stream =
|
26
|
+
const stream = TestStream.create(["milk"], { owner: me });
|
27
27
|
|
28
28
|
test("Construction", () => {
|
29
29
|
expect(stream[me.id]?.value).toEqual("milk");
|
@@ -59,10 +59,10 @@ describe("CoStream resolution", async () => {
|
|
59
59
|
creationProps: { name: "Hermes Puggington" },
|
60
60
|
});
|
61
61
|
|
62
|
-
const stream =
|
62
|
+
const stream = TestStream.create(
|
63
63
|
[
|
64
|
-
|
65
|
-
[
|
64
|
+
NestedStream.create(
|
65
|
+
[TwiceNestedStream.create(["milk"], { owner: me })],
|
66
66
|
{ owner: me }
|
67
67
|
),
|
68
68
|
],
|
@@ -143,8 +143,8 @@ describe("CoStream resolution", async () => {
|
|
143
143
|
loadedTwiceNestedStream?.id
|
144
144
|
);
|
145
145
|
|
146
|
-
const otherNestedStream =
|
147
|
-
[
|
146
|
+
const otherNestedStream = NestedStream.create(
|
147
|
+
[TwiceNestedStream.create(["butter"], { owner: meOnSecondPeer })],
|
148
148
|
{ owner: meOnSecondPeer }
|
149
149
|
);
|
150
150
|
loadedStream?.push(otherNestedStream);
|
@@ -229,11 +229,11 @@ describe("CoStream resolution", async () => {
|
|
229
229
|
).toBe("bread");
|
230
230
|
|
231
231
|
// When assigning a new nested stream, we get an update
|
232
|
-
const newTwiceNested =
|
232
|
+
const newTwiceNested = TwiceNestedStream.create(["butter"], {
|
233
233
|
owner: meOnSecondPeer,
|
234
234
|
});
|
235
235
|
|
236
|
-
const newNested =
|
236
|
+
const newNested = NestedStream.create([newTwiceNested], {
|
237
237
|
owner: meOnSecondPeer,
|
238
238
|
});
|
239
239
|
|
@@ -260,7 +260,7 @@ describe("Simple BinaryCoStream operations", async () => {
|
|
260
260
|
creationProps: { name: "Hermes Puggington" },
|
261
261
|
});
|
262
262
|
|
263
|
-
const stream =
|
263
|
+
const stream = BinaryCoStream.create({ owner: me });
|
264
264
|
|
265
265
|
test("Construction", () => {
|
266
266
|
expect(stream.getChunks()).toBe(undefined);
|
@@ -288,7 +288,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
288
288
|
creationProps: { name: "Hermes Puggington" },
|
289
289
|
});
|
290
290
|
|
291
|
-
const stream =
|
291
|
+
const stream = BinaryCoStream.create({ owner: me });
|
292
292
|
|
293
293
|
stream.start({ mimeType: "text/plain" });
|
294
294
|
stream.push(new Uint8Array([1, 2, 3]));
|
@@ -336,7 +336,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
|
|
336
336
|
test("Subscription", async () => {
|
337
337
|
const { me } = await initNodeAndStream();
|
338
338
|
|
339
|
-
const stream =
|
339
|
+
const stream = BinaryCoStream.create({ owner: me });
|
340
340
|
|
341
341
|
const [initialAsPeer, secondAsPeer] = connectedPeers(
|
342
342
|
"initial",
|