jazz-tools 0.7.0-alpha.3 → 0.7.0-alpha.30
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +80 -8
- package/CHANGELOG.md +175 -0
- package/dist/coValues/account.js +78 -38
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coList.js +150 -99
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/coMap.js +178 -162
- package/dist/coValues/coMap.js.map +1 -1
- package/dist/coValues/coStream.js +195 -70
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/extensions/imageDef.js +13 -8
- package/dist/coValues/extensions/imageDef.js.map +1 -1
- package/dist/coValues/group.js +40 -36
- package/dist/coValues/group.js.map +1 -1
- package/dist/coValues/interfaces.js +22 -4
- package/dist/coValues/interfaces.js.map +1 -1
- package/dist/implementation/refs.js +26 -12
- package/dist/implementation/refs.js.map +1 -1
- package/dist/implementation/schema.js +38 -1
- package/dist/implementation/schema.js.map +1 -1
- package/dist/implementation/symbols.js +5 -0
- package/dist/implementation/symbols.js.map +1 -0
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/tests/coList.test.js +20 -24
- package/dist/tests/coList.test.js.map +1 -1
- package/dist/tests/coMap.test.js +154 -43
- package/dist/tests/coMap.test.js.map +1 -1
- package/dist/tests/coStream.test.js +50 -55
- package/dist/tests/coStream.test.js.map +1 -1
- package/dist/tests/groupsAndAccounts.test.js +86 -0
- package/dist/tests/groupsAndAccounts.test.js.map +1 -0
- package/package.json +5 -4
- package/src/coValues/account.ts +116 -75
- package/src/coValues/coList.ts +189 -125
- package/src/coValues/coMap.ts +238 -295
- package/src/coValues/coStream.ts +282 -124
- package/src/coValues/extensions/imageDef.ts +13 -15
- package/src/coValues/group.ts +85 -85
- package/src/coValues/interfaces.ts +32 -11
- package/src/implementation/refs.ts +42 -25
- package/src/implementation/schema.ts +68 -46
- package/src/implementation/symbols.ts +12 -0
- package/src/index.ts +10 -8
- package/src/internal.ts +1 -0
- package/src/tests/coList.test.ts +20 -24
- package/src/tests/coMap.test.ts +153 -58
- package/src/tests/coStream.test.ts +65 -70
- package/src/tests/groupsAndAccounts.test.ts +96 -0
package/src/tests/coList.test.ts
CHANGED
@@ -4,7 +4,7 @@ import { webcrypto } from "node:crypto";
|
|
4
4
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
5
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
6
|
import { Effect, Queue } from "effect";
|
7
|
-
import { Account, CoList, jazzReady } from "..";
|
7
|
+
import { Account, CoList, co, jazzReady } from "..";
|
8
8
|
|
9
9
|
if (!("crypto" in globalThis)) {
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -17,11 +17,10 @@ beforeEach(async () => {
|
|
17
17
|
|
18
18
|
describe("Simple CoList operations", async () => {
|
19
19
|
const me = await Account.create({
|
20
|
-
name: "Hermes Puggington",
|
20
|
+
creationProps: { name: "Hermes Puggington" },
|
21
21
|
});
|
22
22
|
|
23
|
-
class TestList extends CoList
|
24
|
-
TestList.encoding({ _item: "json" });
|
23
|
+
class TestList extends CoList.Of(co.string) {}
|
25
24
|
|
26
25
|
const list = new TestList(["bread", "butter", "onion"], { owner: me });
|
27
26
|
|
@@ -98,39 +97,36 @@ describe("Simple CoList operations", async () => {
|
|
98
97
|
expect(list._raw.asArray()).toEqual(["butter", "onion"]);
|
99
98
|
});
|
100
99
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
100
|
+
test("splice", () => {
|
101
|
+
const list = new TestList(["bread", "butter", "onion"], {
|
102
|
+
owner: me,
|
103
|
+
});
|
104
|
+
list.splice(1, 1, "salt", "pepper");
|
105
|
+
expect(list.length).toBe(4);
|
106
|
+
expect(list._raw.asArray()).toEqual([
|
107
|
+
"bread",
|
108
|
+
"salt",
|
109
|
+
"pepper",
|
110
|
+
"onion",
|
111
|
+
]);
|
112
|
+
});
|
114
113
|
});
|
115
114
|
});
|
116
115
|
|
117
116
|
describe("CoList resolution", async () => {
|
118
|
-
class TwiceNestedList extends CoList
|
117
|
+
class TwiceNestedList extends CoList.Of(co.string) {
|
119
118
|
joined() {
|
120
119
|
return this.join(",");
|
121
120
|
}
|
122
121
|
}
|
123
|
-
TwiceNestedList.encoding({ _item: "json" });
|
124
122
|
|
125
|
-
class NestedList extends CoList
|
126
|
-
NestedList.encoding({ _item: { ref: () => TwiceNestedList } });
|
123
|
+
class NestedList extends CoList.Of(co.ref(TwiceNestedList)) {}
|
127
124
|
|
128
|
-
class TestList extends CoList
|
129
|
-
TestList.encoding({ _item: { ref: () => NestedList } });
|
125
|
+
class TestList extends CoList.Of(co.ref(NestedList)) {}
|
130
126
|
|
131
127
|
const initNodeAndList = async () => {
|
132
128
|
const me = await Account.create({
|
133
|
-
name: "Hermes Puggington",
|
129
|
+
creationProps: { name: "Hermes Puggington" },
|
134
130
|
});
|
135
131
|
|
136
132
|
const list = new TestList(
|
package/src/tests/coMap.test.ts
CHANGED
@@ -4,7 +4,7 @@ import { webcrypto } from "node:crypto";
|
|
4
4
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
5
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
6
|
import { Effect, Queue } from "effect";
|
7
|
-
import { Account, jazzReady, Encoders,
|
7
|
+
import { Account, jazzReady, Encoders, CoMap, co } from "..";
|
8
8
|
|
9
9
|
if (!("crypto" in globalThis)) {
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
@@ -17,34 +17,28 @@ beforeEach(async () => {
|
|
17
17
|
|
18
18
|
describe("Simple CoMap operations", async () => {
|
19
19
|
const me = await Account.create({
|
20
|
-
name: "Hermes Puggington",
|
20
|
+
creationProps: { name: "Hermes Puggington" },
|
21
21
|
});
|
22
22
|
|
23
23
|
class TestMap extends CoMap<TestMap> {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
color = co.string;
|
25
|
+
_height = co.number;
|
26
|
+
birthday = co.encoded(Encoders.Date);
|
27
|
+
name? = co.string;
|
28
28
|
|
29
|
-
get
|
29
|
+
get roughColor() {
|
30
30
|
return this.color + "ish";
|
31
31
|
}
|
32
32
|
}
|
33
|
-
TestMap.encoding({
|
34
|
-
color: "json",
|
35
|
-
height: "json",
|
36
|
-
birthday: { encoded: Encoders.Date },
|
37
|
-
name: "json",
|
38
|
-
});
|
39
33
|
|
40
|
-
console.log("TestMap schema", TestMap.prototype.
|
34
|
+
console.log("TestMap schema", TestMap.prototype._schema);
|
41
35
|
|
42
36
|
const birthday = new Date();
|
43
37
|
|
44
38
|
const map = new TestMap(
|
45
39
|
{
|
46
40
|
color: "red",
|
47
|
-
|
41
|
+
_height: 10,
|
48
42
|
birthday: birthday,
|
49
43
|
},
|
50
44
|
{ owner: me }
|
@@ -52,14 +46,15 @@ describe("Simple CoMap operations", async () => {
|
|
52
46
|
|
53
47
|
test("Construction", () => {
|
54
48
|
expect(map.color).toEqual("red");
|
55
|
-
expect(map.
|
56
|
-
expect(map.
|
49
|
+
expect(map.roughColor).toEqual("redish");
|
50
|
+
expect(map._height).toEqual(10);
|
57
51
|
expect(map.birthday).toEqual(birthday);
|
58
52
|
expect(map._raw.get("birthday")).toEqual(birthday.toISOString());
|
53
|
+
expect(Object.keys(map)).toEqual(["color", "_height", "birthday"]);
|
59
54
|
});
|
60
55
|
|
61
56
|
describe("Mutation", () => {
|
62
|
-
test("assignment", () => {
|
57
|
+
test("assignment & deletion", () => {
|
63
58
|
map.color = "blue";
|
64
59
|
expect(map.color).toEqual("blue");
|
65
60
|
expect(map._raw.get("color")).toEqual("blue");
|
@@ -68,27 +63,27 @@ describe("Simple CoMap operations", async () => {
|
|
68
63
|
expect(map.birthday).toEqual(newBirthday);
|
69
64
|
expect(map._raw.get("birthday")).toEqual(newBirthday.toISOString());
|
70
65
|
|
71
|
-
Object.assign(map, { color: "green",
|
66
|
+
Object.assign(map, { color: "green", _height: 20 });
|
72
67
|
expect(map.color).toEqual("green");
|
73
68
|
expect(map._raw.get("color")).toEqual("green");
|
74
|
-
expect(map.
|
75
|
-
expect(map._raw.get("
|
69
|
+
expect(map._height).toEqual(20);
|
70
|
+
expect(map._raw.get("_height")).toEqual(20);
|
76
71
|
|
77
72
|
map.name = "Secret name";
|
78
73
|
expect(map.name).toEqual("Secret name");
|
79
74
|
map.name = undefined;
|
80
75
|
expect(map.name).toEqual(undefined);
|
76
|
+
expect(Object.keys(map)).toContain("name");
|
77
|
+
delete map.name;
|
78
|
+
expect(map.name).toEqual(undefined);
|
79
|
+
expect(Object.keys(map)).not.toContain("name");
|
81
80
|
});
|
82
81
|
});
|
83
82
|
|
84
83
|
class RecursiveMap extends CoMap<RecursiveMap> {
|
85
|
-
|
86
|
-
|
84
|
+
name = co.string;
|
85
|
+
next: co<RecursiveMap | null> = co.ref(RecursiveMap);
|
87
86
|
}
|
88
|
-
RecursiveMap.encoding({
|
89
|
-
name: "json",
|
90
|
-
next: { ref: () => RecursiveMap },
|
91
|
-
});
|
92
87
|
|
93
88
|
const recursiveMap = new RecursiveMap(
|
94
89
|
{
|
@@ -116,47 +111,94 @@ describe("Simple CoMap operations", async () => {
|
|
116
111
|
expect(recursiveMap.next?.next?.name).toEqual("third");
|
117
112
|
});
|
118
113
|
});
|
114
|
+
|
115
|
+
class MapWithEnumOfMaps extends CoMap<MapWithEnumOfMaps> {
|
116
|
+
name = co.string;
|
117
|
+
child = co.ref<typeof ChildA | typeof ChildB>((raw) =>
|
118
|
+
raw.get("type") === "a" ? ChildA : ChildB
|
119
|
+
);
|
120
|
+
}
|
121
|
+
|
122
|
+
class ChildA extends CoMap<ChildA> {
|
123
|
+
type = co.literal("a");
|
124
|
+
value = co.number;
|
125
|
+
}
|
126
|
+
|
127
|
+
class ChildB extends CoMap<ChildB> {
|
128
|
+
type = co.literal("b");
|
129
|
+
value = co.string;
|
130
|
+
}
|
131
|
+
|
132
|
+
const mapWithEnum = new MapWithEnumOfMaps(
|
133
|
+
{
|
134
|
+
name: "enum",
|
135
|
+
child: new ChildA(
|
136
|
+
{
|
137
|
+
type: "a",
|
138
|
+
value: 5,
|
139
|
+
},
|
140
|
+
{ owner: me }
|
141
|
+
),
|
142
|
+
},
|
143
|
+
{ owner: me }
|
144
|
+
);
|
145
|
+
|
146
|
+
test("Enum of maps", () => {
|
147
|
+
expect(mapWithEnum.name).toEqual("enum");
|
148
|
+
expect(mapWithEnum.child?.type).toEqual("a");
|
149
|
+
expect(mapWithEnum.child?.value).toEqual(5);
|
150
|
+
expect(mapWithEnum.child?.id).toBeDefined();
|
151
|
+
});
|
152
|
+
|
153
|
+
class SuperClassMap extends CoMap<SuperClassMap> {
|
154
|
+
name = co.string;
|
155
|
+
}
|
156
|
+
|
157
|
+
class SubClassMap extends SuperClassMap {
|
158
|
+
name = co.literal("specificString");
|
159
|
+
value = co.number;
|
160
|
+
extra = co.ref(TestMap);
|
161
|
+
}
|
162
|
+
interface SubClassMap extends CoMap<SubClassMap> {}
|
163
|
+
|
164
|
+
class GenericMapWithLoose<
|
165
|
+
out T extends string = string,
|
166
|
+
> extends CoMap<GenericMapWithLoose> {
|
167
|
+
name = co.json<T>();
|
168
|
+
}
|
169
|
+
|
170
|
+
const loose: GenericMapWithLoose<string> = {} as GenericMapWithLoose<
|
171
|
+
"a" | "b"
|
172
|
+
>;
|
119
173
|
});
|
120
174
|
|
121
175
|
describe("CoMap resolution", async () => {
|
122
176
|
class TwiceNestedMap extends CoMap<TwiceNestedMap> {
|
123
|
-
taste
|
177
|
+
taste = co.string;
|
124
178
|
}
|
125
|
-
TwiceNestedMap.encoding({
|
126
|
-
taste: "json",
|
127
|
-
});
|
128
179
|
|
129
180
|
class NestedMap extends CoMap<NestedMap> {
|
130
|
-
name
|
131
|
-
twiceNested
|
181
|
+
name = co.string;
|
182
|
+
twiceNested = co.ref(TwiceNestedMap);
|
132
183
|
|
133
184
|
get _fancyName() {
|
134
185
|
return "Sir " + this.name;
|
135
186
|
}
|
136
187
|
}
|
137
|
-
NestedMap.encoding({
|
138
|
-
name: "json",
|
139
|
-
twiceNested: { ref: () => TwiceNestedMap },
|
140
|
-
});
|
141
188
|
|
142
189
|
class TestMap extends CoMap<TestMap> {
|
143
|
-
|
144
|
-
|
145
|
-
|
190
|
+
color = co.string;
|
191
|
+
height = co.number;
|
192
|
+
nested = co.ref(NestedMap);
|
146
193
|
|
147
194
|
get _roughColor() {
|
148
195
|
return this.color + "ish";
|
149
196
|
}
|
150
197
|
}
|
151
|
-
TestMap.encoding({
|
152
|
-
color: "json",
|
153
|
-
height: "json",
|
154
|
-
nested: { ref: () => NestedMap },
|
155
|
-
});
|
156
198
|
|
157
199
|
const initNodeAndMap = async () => {
|
158
200
|
const me = await Account.create({
|
159
|
-
name: "Hermes Puggington",
|
201
|
+
creationProps: { name: "Hermes Puggington" },
|
160
202
|
});
|
161
203
|
|
162
204
|
const map = new TestMap(
|
@@ -342,17 +384,13 @@ describe("CoMap resolution", async () => {
|
|
342
384
|
});
|
343
385
|
|
344
386
|
class TestMapWithOptionalRef extends CoMap<TestMapWithOptionalRef> {
|
345
|
-
|
346
|
-
|
387
|
+
color = co.string;
|
388
|
+
nested? = co.ref(NestedMap);
|
347
389
|
}
|
348
|
-
TestMapWithOptionalRef.encoding({
|
349
|
-
color: "json",
|
350
|
-
nested: { ref: () => NestedMap },
|
351
|
-
});
|
352
390
|
|
353
391
|
test("Construction with optional", async () => {
|
354
392
|
const me = await Account.create({
|
355
|
-
name: "Hermes Puggington",
|
393
|
+
creationProps: { name: "Hermes Puggington" },
|
356
394
|
});
|
357
395
|
|
358
396
|
const mapWithout = new TestMapWithOptionalRef(
|
@@ -389,16 +427,13 @@ describe("CoMap resolution", async () => {
|
|
389
427
|
});
|
390
428
|
|
391
429
|
class TestRecord extends CoMap<TestRecord> {
|
392
|
-
|
430
|
+
[co.items] = co.number;
|
393
431
|
}
|
394
432
|
interface TestRecord extends Record<string, number> {}
|
395
|
-
TestRecord.encoding({
|
396
|
-
[indexSignature]: "json",
|
397
|
-
});
|
398
433
|
|
399
434
|
test("Construction with index signature", async () => {
|
400
435
|
const me = await Account.create({
|
401
|
-
name: "Hermes Puggington",
|
436
|
+
creationProps: { name: "Hermes Puggington" },
|
402
437
|
});
|
403
438
|
|
404
439
|
const record = new TestRecord(
|
@@ -414,5 +449,65 @@ describe("CoMap resolution", async () => {
|
|
414
449
|
expect(record.other).toEqual(3);
|
415
450
|
expect(record._raw.get("other")).toEqual(3);
|
416
451
|
expect(Object.keys(record)).toEqual(["height", "other"]);
|
452
|
+
expect(record.toJSON()).toMatchObject({
|
453
|
+
_type: "CoMap",
|
454
|
+
height: 5,
|
455
|
+
id: expect.any(String),
|
456
|
+
other: 3,
|
457
|
+
});
|
458
|
+
});
|
459
|
+
|
460
|
+
class TestRecord2 extends CoMap.Record(co.number) {}
|
461
|
+
|
462
|
+
test("Construction with index signature (shorthand)", async () => {
|
463
|
+
const me = await Account.create({
|
464
|
+
creationProps: { name: "Hermes Puggington" },
|
465
|
+
});
|
466
|
+
|
467
|
+
const record = new TestRecord2(
|
468
|
+
{
|
469
|
+
height: 5,
|
470
|
+
other: 3,
|
471
|
+
},
|
472
|
+
{ owner: me }
|
473
|
+
);
|
474
|
+
|
475
|
+
expect(record.height).toEqual(5);
|
476
|
+
expect(record._raw.get("height")).toEqual(5);
|
477
|
+
expect(record.other).toEqual(3);
|
478
|
+
expect(record._raw.get("other")).toEqual(3);
|
479
|
+
expect(Object.keys(record)).toEqual(["height", "other"]);
|
480
|
+
});
|
481
|
+
|
482
|
+
class TestRecordRef extends CoMap.Record(co.ref(TwiceNestedMap)) {}
|
483
|
+
|
484
|
+
test("Construction with index signature ref", async () => {
|
485
|
+
const me = await Account.create({
|
486
|
+
creationProps: { name: "Hermes Puggington" },
|
487
|
+
});
|
488
|
+
|
489
|
+
const record = new TestRecordRef(
|
490
|
+
{
|
491
|
+
firstNested: new TwiceNestedMap(
|
492
|
+
{ taste: "sour" },
|
493
|
+
{ owner: me }
|
494
|
+
),
|
495
|
+
secondNested: new TwiceNestedMap(
|
496
|
+
{ taste: "sweet" },
|
497
|
+
{ owner: me }
|
498
|
+
),
|
499
|
+
},
|
500
|
+
{ owner: me }
|
501
|
+
);
|
502
|
+
|
503
|
+
expect(record.firstNested?.taste).toEqual("sour");
|
504
|
+
expect(record.firstNested?.id).toBeDefined();
|
505
|
+
expect(record.secondNested?.taste).toEqual("sweet");
|
506
|
+
expect(record.secondNested?.id).toBeDefined();
|
507
|
+
expect(Object.keys(record)).toEqual(["firstNested", "secondNested"]);
|
508
|
+
expect(Object.keys(record._refs)).toEqual([
|
509
|
+
"firstNested",
|
510
|
+
"secondNested",
|
511
|
+
]);
|
417
512
|
});
|
418
513
|
});
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import { expect, describe, test, beforeEach
|
1
|
+
import { expect, describe, test, beforeEach } from "vitest";
|
2
2
|
|
3
3
|
import { webcrypto } from "node:crypto";
|
4
4
|
import { connectedPeers } from "cojson/src/streamUtils.js";
|
5
5
|
import { newRandomSessionID } from "cojson/src/coValueCore.js";
|
6
6
|
import { Effect, Queue } from "effect";
|
7
|
-
import { BinaryCoStream, ID, Account, jazzReady, CoStream } from "..";
|
7
|
+
import { BinaryCoStream, ID, Account, jazzReady, CoStream, co } from "..";
|
8
8
|
import { Simplify } from "effect/Types";
|
9
9
|
|
10
10
|
if (!("crypto" in globalThis)) {
|
@@ -18,49 +18,45 @@ beforeEach(async () => {
|
|
18
18
|
|
19
19
|
describe("Simple CoStream operations", async () => {
|
20
20
|
const me = await Account.create({
|
21
|
-
name: "Hermes Puggington",
|
21
|
+
creationProps: { name: "Hermes Puggington" },
|
22
22
|
});
|
23
23
|
|
24
|
-
class TestStream extends CoStream
|
25
|
-
TestStream.encoding({ _item: "json" });
|
24
|
+
class TestStream extends CoStream.Of(co.string) {}
|
26
25
|
|
27
26
|
const stream = new TestStream(["milk"], { owner: me });
|
28
27
|
|
29
28
|
test("Construction", () => {
|
30
|
-
expect(stream
|
31
|
-
expect(stream.
|
29
|
+
expect(stream[me.id]?.value).toEqual("milk");
|
30
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("milk");
|
32
31
|
});
|
33
32
|
|
34
33
|
describe("Mutation", () => {
|
35
34
|
test("pushing", () => {
|
36
35
|
stream.push("bread");
|
37
|
-
expect(stream
|
38
|
-
expect(stream.
|
36
|
+
expect(stream[me.id]?.value).toEqual("bread");
|
37
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("bread");
|
39
38
|
|
40
39
|
stream.push("butter");
|
41
|
-
expect(stream
|
42
|
-
expect(stream.
|
40
|
+
expect(stream[me.id]?.value).toEqual("butter");
|
41
|
+
expect(stream.perSession[me.sessionID]?.value).toEqual("butter");
|
43
42
|
});
|
44
43
|
});
|
45
44
|
});
|
46
45
|
|
47
46
|
describe("CoStream resolution", async () => {
|
48
|
-
class TwiceNestedStream extends CoStream
|
47
|
+
class TwiceNestedStream extends CoStream.Of(co.string) {
|
49
48
|
fancyValueOf(account: ID<Account>) {
|
50
|
-
return "Sir " + this
|
49
|
+
return "Sir " + this[account]?.value;
|
51
50
|
}
|
52
51
|
}
|
53
|
-
TwiceNestedStream.encoding({ _item: "json" });
|
54
52
|
|
55
|
-
class NestedStream extends CoStream
|
56
|
-
NestedStream.encoding({ _item: {ref: () => TwiceNestedStream} });
|
53
|
+
class NestedStream extends CoStream.Of(co.ref(TwiceNestedStream)) {}
|
57
54
|
|
58
|
-
class TestStream extends CoStream
|
59
|
-
TestStream.encoding({ _item: {ref: () => NestedStream} });
|
55
|
+
class TestStream extends CoStream.Of(co.ref(NestedStream)) {}
|
60
56
|
|
61
57
|
const initNodeAndStream = async () => {
|
62
58
|
const me = await Account.create({
|
63
|
-
name: "Hermes Puggington",
|
59
|
+
creationProps: { name: "Hermes Puggington" },
|
64
60
|
});
|
65
61
|
|
66
62
|
const stream = new TestStream(
|
@@ -78,9 +74,9 @@ describe("CoStream resolution", async () => {
|
|
78
74
|
|
79
75
|
test("Construction", async () => {
|
80
76
|
const { me, stream } = await initNodeAndStream();
|
81
|
-
expect(
|
82
|
-
|
83
|
-
)
|
77
|
+
expect(stream[me.id]?.value?.[me.id]?.value?.[me.id]?.value).toEqual(
|
78
|
+
"milk"
|
79
|
+
);
|
84
80
|
});
|
85
81
|
|
86
82
|
test("Loading and availability", async () => {
|
@@ -102,48 +98,48 @@ describe("CoStream resolution", async () => {
|
|
102
98
|
as: meOnSecondPeer,
|
103
99
|
});
|
104
100
|
|
105
|
-
expect(loadedStream?.
|
106
|
-
expect(loadedStream?.
|
107
|
-
stream
|
101
|
+
expect(loadedStream?.[me.id]?.value).toEqual(null);
|
102
|
+
expect(loadedStream?.[me.id]?.ref?.id).toEqual(
|
103
|
+
stream[me.id]?.value?.id
|
108
104
|
);
|
109
105
|
|
110
106
|
const loadedNestedStream = await NestedStream.load(
|
111
|
-
stream
|
107
|
+
stream[me.id]!.value!.id,
|
112
108
|
{ as: meOnSecondPeer }
|
113
109
|
);
|
114
110
|
|
115
|
-
// expect(loadedStream?.
|
116
|
-
expect(loadedStream?.
|
111
|
+
// expect(loadedStream?.[me.id]?.value).toEqual(loadedNestedStream);
|
112
|
+
expect(loadedStream?.[me.id]?.value?.id).toEqual(
|
117
113
|
loadedNestedStream?.id
|
118
114
|
);
|
119
|
-
expect(loadedStream?.
|
120
|
-
// expect(loadedStream?.
|
121
|
-
expect(loadedStream?.
|
115
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(null);
|
116
|
+
// expect(loadedStream?.[me.id]?.ref?.value).toEqual(loadedNestedStream);
|
117
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
122
118
|
loadedNestedStream?.id
|
123
119
|
);
|
124
|
-
expect(loadedStream?.
|
125
|
-
stream
|
120
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.ref?.id).toEqual(
|
121
|
+
stream[me.id]?.value?.[me.id]?.value?.id
|
126
122
|
);
|
127
123
|
|
128
124
|
const loadedTwiceNestedStream = await TwiceNestedStream.load(
|
129
|
-
stream
|
125
|
+
stream[me.id]!.value![me.id]!.value!.id,
|
130
126
|
{ as: meOnSecondPeer }
|
131
127
|
);
|
132
128
|
|
133
|
-
// expect(loadedStream?.
|
129
|
+
// expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(
|
134
130
|
// loadedTwiceNestedStream
|
135
131
|
// );
|
136
|
-
expect(loadedStream?.
|
132
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
|
137
133
|
loadedTwiceNestedStream?.id
|
138
134
|
);
|
139
135
|
expect(
|
140
|
-
loadedStream?.
|
141
|
-
me.id
|
142
|
-
)
|
136
|
+
loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id)
|
143
137
|
).toEqual("Sir milk");
|
144
|
-
// expect(loadedStream?.
|
145
|
-
expect(loadedStream?.
|
146
|
-
|
138
|
+
// expect(loadedStream?.[me.id]?.ref?.value).toEqual(loadedNestedStream);
|
139
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
140
|
+
loadedNestedStream?.id
|
141
|
+
);
|
142
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.ref?.value?.id).toEqual(
|
147
143
|
loadedTwiceNestedStream?.id
|
148
144
|
);
|
149
145
|
|
@@ -152,16 +148,16 @@ describe("CoStream resolution", async () => {
|
|
152
148
|
{ owner: meOnSecondPeer }
|
153
149
|
);
|
154
150
|
loadedStream?.push(otherNestedStream);
|
155
|
-
// expect(loadedStream?.
|
156
|
-
expect(loadedStream?.
|
157
|
-
expect(loadedStream?.
|
158
|
-
|
159
|
-
|
151
|
+
// expect(loadedStream?.[me.id]?.value).toEqual(otherNestedStream);
|
152
|
+
expect(loadedStream?.[me.id]?.value?.id).toEqual(otherNestedStream?.id);
|
153
|
+
expect(loadedStream?.[me.id]?.ref?.value?.id).toEqual(
|
154
|
+
otherNestedStream?.id
|
155
|
+
);
|
156
|
+
expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
|
157
|
+
otherNestedStream[me.id]?.value?.id
|
160
158
|
);
|
161
159
|
expect(
|
162
|
-
loadedStream?.
|
163
|
-
me.id
|
164
|
-
)
|
160
|
+
loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id)
|
165
161
|
).toEqual("Sir butter");
|
166
162
|
});
|
167
163
|
|
@@ -192,17 +188,18 @@ describe("CoStream resolution", async () => {
|
|
192
188
|
{ as: meOnSecondPeer },
|
193
189
|
(subscribedStream) => {
|
194
190
|
console.log(
|
195
|
-
"subscribedStream
|
196
|
-
subscribedStream
|
191
|
+
"subscribedStream[me.id]",
|
192
|
+
subscribedStream[me.id]
|
197
193
|
);
|
198
194
|
console.log(
|
199
|
-
"subscribedStream
|
200
|
-
subscribedStream
|
195
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value",
|
196
|
+
subscribedStream[me.id]?.value?.[me.id]?.value
|
201
197
|
);
|
202
198
|
console.log(
|
203
|
-
"subscribedStream
|
204
|
-
subscribedStream
|
205
|
-
|
199
|
+
"subscribedStream[me.id]?.value?.[me.id]?.value?.[me.id]?.value",
|
200
|
+
subscribedStream[me.id]?.value?.[me.id]?.value?.[
|
201
|
+
me.id
|
202
|
+
]?.value
|
206
203
|
);
|
207
204
|
Effect.runPromise(Queue.offer(queue, subscribedStream));
|
208
205
|
}
|
@@ -212,25 +209,23 @@ describe("CoStream resolution", async () => {
|
|
212
209
|
const te: T = stream;
|
213
210
|
|
214
211
|
const update1 = yield* $(Queue.take(queue));
|
215
|
-
expect(update1
|
212
|
+
expect(update1[me.id]?.value).toEqual(null);
|
216
213
|
|
217
214
|
const update2 = yield* $(Queue.take(queue));
|
218
|
-
expect(update2
|
219
|
-
expect(update2
|
215
|
+
expect(update2[me.id]?.value).toBeDefined();
|
216
|
+
expect(update2[me.id]?.value?.[me.id]?.value).toBe(null);
|
220
217
|
|
221
218
|
const update3 = yield* $(Queue.take(queue));
|
219
|
+
expect(update3[me.id]?.value?.[me.id]?.value).toBeDefined();
|
222
220
|
expect(
|
223
|
-
update3.
|
224
|
-
).toBeDefined();
|
225
|
-
expect(
|
226
|
-
update3.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
|
221
|
+
update3[me.id]?.value?.[me.id]?.value?.[me.id]?.value
|
227
222
|
).toBe("milk");
|
228
223
|
|
229
|
-
update3
|
224
|
+
update3[me.id]!.value![me.id]!.value!.push("bread");
|
230
225
|
|
231
226
|
const update4 = yield* $(Queue.take(queue));
|
232
227
|
expect(
|
233
|
-
update4
|
228
|
+
update4[me.id]?.value?.[me.id]?.value?.[me.id]?.value
|
234
229
|
).toBe("bread");
|
235
230
|
|
236
231
|
// When assigning a new nested stream, we get an update
|
@@ -246,14 +241,14 @@ describe("CoStream resolution", async () => {
|
|
246
241
|
|
247
242
|
const update5 = yield* $(Queue.take(queue));
|
248
243
|
expect(
|
249
|
-
update5
|
244
|
+
update5[me.id]?.value?.[me.id]?.value?.[me.id]?.value
|
250
245
|
).toBe("butter");
|
251
246
|
|
252
247
|
// we get updates when the new nested stream changes
|
253
248
|
newTwiceNested.push("jam");
|
254
249
|
const update6 = yield* $(Queue.take(queue));
|
255
250
|
expect(
|
256
|
-
update6
|
251
|
+
update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value
|
257
252
|
).toBe("jam");
|
258
253
|
})
|
259
254
|
);
|
@@ -262,7 +257,7 @@ describe("CoStream resolution", async () => {
|
|
262
257
|
|
263
258
|
describe("Simple BinaryCoStream operations", async () => {
|
264
259
|
const me = await Account.create({
|
265
|
-
name: "Hermes Puggington",
|
260
|
+
creationProps: { name: "Hermes Puggington" },
|
266
261
|
});
|
267
262
|
|
268
263
|
const stream = new BinaryCoStream(undefined, { owner: me });
|
@@ -290,7 +285,7 @@ describe("Simple BinaryCoStream operations", async () => {
|
|
290
285
|
describe("BinaryCoStream loading & Subscription", async () => {
|
291
286
|
const initNodeAndStream = async () => {
|
292
287
|
const me = await Account.create({
|
293
|
-
name: "Hermes Puggington",
|
288
|
+
creationProps: { name: "Hermes Puggington" },
|
294
289
|
});
|
295
290
|
|
296
291
|
const stream = new BinaryCoStream(undefined, { owner: me });
|