jazz-tools 0.7.0-alpha.30 → 0.7.0-alpha.31
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +43 -45
- package/CHANGELOG.md +6 -0
- package/dist/coValues/account.js +6 -6
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +8 -7
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +6 -3
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +9 -3
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +6 -2
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +1 -1
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/schema.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 +1 -1
- package/src/coValues/account.ts +21 -38
- package/src/coValues/coList.ts +16 -11
- package/src/coValues/coMap.ts +15 -20
- package/src/coValues/coStream.ts +32 -17
- package/src/coValues/extensions/imageDef.ts +1 -1
- package/src/coValues/group.ts +32 -48
- package/src/coValues/interfaces.ts +1 -1
- package/src/implementation/schema.ts +1 -0
- 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
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",
|
@@ -13,20 +13,20 @@ beforeEach(async () => {
|
|
13
13
|
});
|
14
14
|
|
15
15
|
describe("Custom accounts and groups", async () => {
|
16
|
-
class CustomProfile extends CoMap
|
16
|
+
class CustomProfile extends CoMap {
|
17
17
|
name = co.string;
|
18
18
|
color = co.string;
|
19
19
|
}
|
20
20
|
|
21
|
-
class CustomAccount extends Account
|
21
|
+
class CustomAccount extends Account {
|
22
22
|
profile = co.ref(CustomProfile);
|
23
23
|
root = co.ref(CoMap);
|
24
24
|
|
25
25
|
migrate(creationProps?: { name: string }) {
|
26
26
|
if (creationProps) {
|
27
|
-
const profileGroup =
|
27
|
+
const profileGroup = Group.create({ owner: this });
|
28
28
|
profileGroup.addMember("everyone", "reader");
|
29
|
-
this.profile =
|
29
|
+
this.profile = CustomProfile.create(
|
30
30
|
{ name: creationProps.name, color: "blue" },
|
31
31
|
{ owner: this }
|
32
32
|
);
|
@@ -34,7 +34,7 @@ describe("Custom accounts and groups", async () => {
|
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
-
class CustomGroup extends Group
|
37
|
+
class CustomGroup extends Group {
|
38
38
|
profile = co.null;
|
39
39
|
root = co.null;
|
40
40
|
[co.members] = co.ref(CustomAccount);
|
@@ -80,14 +80,18 @@ describe("Custom accounts and groups", async () => {
|
|
80
80
|
});
|
81
81
|
});
|
82
82
|
|
83
|
-
class MyMap extends CoMap
|
83
|
+
class MyMap extends CoMap {
|
84
84
|
name = co.string;
|
85
85
|
}
|
86
86
|
|
87
|
-
const map =
|
87
|
+
const map = MyMap.create({ name: "test" }, { owner: group });
|
88
88
|
|
89
|
-
const meAsCastMember = map._owner
|
90
|
-
|
89
|
+
const meAsCastMember = map._owner
|
90
|
+
.as(CustomGroup)
|
91
|
+
.members.find((member) => member.id === me.id);
|
92
|
+
expect(meAsCastMember?.account?.profile?.name).toBe(
|
93
|
+
"Hermes Puggington"
|
94
|
+
);
|
91
95
|
expect(meAsCastMember?.account?.profile?.color).toBe("blue");
|
92
96
|
|
93
97
|
expect((map._owner as any).nMembers).toBeUndefined();
|