jazz-tools 0.7.0-alpha.6 → 0.7.0-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/coValues/account.js +62 -29
  3. package/dist/coValues/account.js.map +1 -1
  4. package/dist/coValues/coList.js +139 -89
  5. package/dist/coValues/coList.js.map +1 -1
  6. package/dist/coValues/coMap.js +135 -151
  7. package/dist/coValues/coMap.js.map +1 -1
  8. package/dist/coValues/coStream.js +131 -57
  9. package/dist/coValues/coStream.js.map +1 -1
  10. package/dist/coValues/extensions/imageDef.js +10 -7
  11. package/dist/coValues/extensions/imageDef.js.map +1 -1
  12. package/dist/coValues/group.js +8 -30
  13. package/dist/coValues/group.js.map +1 -1
  14. package/dist/coValues/interfaces.js +6 -2
  15. package/dist/coValues/interfaces.js.map +1 -1
  16. package/dist/implementation/encoding.js +21 -0
  17. package/dist/implementation/encoding.js.map +1 -1
  18. package/dist/implementation/refs.js +10 -9
  19. package/dist/implementation/refs.js.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/tests/coList.test.js +5 -9
  23. package/dist/tests/coList.test.js.map +1 -1
  24. package/dist/tests/coMap.test.js +99 -36
  25. package/dist/tests/coMap.test.js.map +1 -1
  26. package/dist/tests/coStream.test.js +46 -51
  27. package/dist/tests/coStream.test.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/coValues/account.ts +82 -52
  30. package/src/coValues/coList.ts +170 -107
  31. package/src/coValues/coMap.ts +196 -230
  32. package/src/coValues/coStream.ts +169 -91
  33. package/src/coValues/extensions/imageDef.ts +7 -11
  34. package/src/coValues/group.ts +16 -63
  35. package/src/coValues/interfaces.ts +9 -8
  36. package/src/implementation/encoding.ts +55 -16
  37. package/src/implementation/refs.ts +12 -10
  38. package/src/index.ts +1 -1
  39. package/src/tests/coList.test.ts +5 -9
  40. package/src/tests/coMap.test.ts +77 -51
  41. package/src/tests/coStream.test.ts +61 -66
@@ -5,7 +5,7 @@ import type {
5
5
  CoValue,
6
6
  ID,
7
7
  Me,
8
- SubclassedConstructor,
8
+ RefEncoded,
9
9
  UnavailableError,
10
10
  } from "../internal.js";
11
11
  import { subscriptionsScopes } from "../internal.js";
@@ -16,8 +16,12 @@ export class Ref<V extends CoValue> {
16
16
  constructor(
17
17
  readonly id: ID<V>,
18
18
  readonly controlledAccount: Account & Me,
19
- readonly valueConstructor: SubclassedConstructor<V>
20
- ) {}
19
+ readonly encoding: RefEncoded<V>
20
+ ) {
21
+ if (!("ref" in encoding)) {
22
+ throw new Error("Ref must be constructed with a ref encoding");
23
+ }
24
+ }
21
25
 
22
26
  get value() {
23
27
  if (this.cachedValue) return this.cachedValue;
@@ -26,9 +30,7 @@ export class Ref<V extends CoValue> {
26
30
  this.id as unknown as CoID<RawCoValue>
27
31
  );
28
32
  if (raw) {
29
- const value = new this.valueConstructor(undefined, {
30
- fromRaw: raw,
31
- }) as V;
33
+ const value = this.encoding.ref(raw).fromRaw(raw);
32
34
  this.cachedValue = value;
33
35
  return value;
34
36
  } else {
@@ -65,7 +67,7 @@ export class Ref<V extends CoValue> {
65
67
  return new Ref(
66
68
  this.id,
67
69
  this.controlledAccount,
68
- this.valueConstructor
70
+ this.encoding
69
71
  ).value!;
70
72
  }
71
73
  }
@@ -98,7 +100,7 @@ export function makeRefs<Keys extends string | number>(
98
100
  getIdForKey: (key: Keys) => ID<CoValue> | undefined,
99
101
  getKeysWithIds: () => Keys[],
100
102
  controlledAccount: Account & Me,
101
- valueConstructorForKey: (key: Keys) => SubclassedConstructor<CoValue>
103
+ refEncodingForKey: (key: Keys) => RefEncoded<CoValue>
102
104
  ): { [K in Keys]: Ref<CoValue> } & {
103
105
  [Symbol.iterator]: () => IterableIterator<Ref<CoValue>>;
104
106
  length: number;
@@ -115,7 +117,7 @@ export function makeRefs<Keys extends string | number>(
115
117
  yield new Ref(
116
118
  getIdForKey(key)!,
117
119
  controlledAccount,
118
- valueConstructorForKey(key)
120
+ refEncodingForKey(key)
119
121
  );
120
122
  }
121
123
  };
@@ -129,7 +131,7 @@ export function makeRefs<Keys extends string | number>(
129
131
  return new Ref(
130
132
  id as ID<CoValue>,
131
133
  controlledAccount,
132
- valueConstructorForKey(key as Keys)
134
+ refEncodingForKey(key as Keys)
133
135
  );
134
136
  },
135
137
  ownKeys() {
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@ export {
12
12
 
13
13
  export { ID, CoValue } from "./internal.js";
14
14
 
15
- export { Encoders } from "./internal.js";
15
+ export { Encoders, val } from "./internal.js";
16
16
 
17
17
  export { CoMap } from "./internal.js";
18
18
  export { CoList } from "./internal.js";
@@ -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, val, jazzReady } from "..";
8
8
 
9
9
  if (!("crypto" in globalThis)) {
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,8 +20,7 @@ describe("Simple CoList operations", async () => {
20
20
  name: "Hermes Puggington",
21
21
  });
22
22
 
23
- class TestList extends CoList<string> {}
24
- TestList.encoding({ _item: "json" });
23
+ class TestList extends CoList.Of(val.string) {}
25
24
 
26
25
  const list = new TestList(["bread", "butter", "onion"], { owner: me });
27
26
 
@@ -115,18 +114,15 @@ describe("Simple CoList operations", async () => {
115
114
  });
116
115
 
117
116
  describe("CoList resolution", async () => {
118
- class TwiceNestedList extends CoList<string> {
117
+ class TwiceNestedList extends CoList.Of(val.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<TwiceNestedList | null> {}
126
- NestedList.encoding({ _item: { ref: () => TwiceNestedList } });
123
+ class NestedList extends CoList.Of(val.ref(() => TwiceNestedList)) {}
127
124
 
128
- class TestList extends CoList<NestedList | null> {}
129
- TestList.encoding({ _item: { ref: () => NestedList } });
125
+ class TestList extends CoList.Of(val.ref(() => NestedList)) {}
130
126
 
131
127
  const initNodeAndList = async () => {
132
128
  const me = await Account.create({
@@ -5,6 +5,7 @@ import { connectedPeers } from "cojson/src/streamUtils.js";
5
5
  import { newRandomSessionID } from "cojson/src/coValueCore.js";
6
6
  import { Effect, Queue } from "effect";
7
7
  import { Account, jazzReady, Encoders, CoMap } from "..";
8
+ import { val } from "../internal";
8
9
 
9
10
  if (!("crypto" in globalThis)) {
10
11
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -21,21 +22,15 @@ describe("Simple CoMap operations", async () => {
21
22
  });
22
23
 
23
24
  class TestMap extends CoMap<TestMap> {
24
- declare color: string;
25
- declare height: number;
26
- declare birthday: Date;
27
- declare name?: string;
25
+ color = val.string;
26
+ _height = val.number;
27
+ birthday = val.encoded(Encoders.Date);
28
+ name? = val.string;
28
29
 
29
- get _roughColor() {
30
+ get roughColor() {
30
31
  return this.color + "ish";
31
32
  }
32
33
  }
33
- TestMap.encoding({
34
- color: "json",
35
- height: "json",
36
- birthday: { encoded: Encoders.Date },
37
- name: "json",
38
- });
39
34
 
40
35
  console.log("TestMap schema", TestMap.prototype._encoding);
41
36
 
@@ -44,7 +39,7 @@ describe("Simple CoMap operations", async () => {
44
39
  const map = new TestMap(
45
40
  {
46
41
  color: "red",
47
- height: 10,
42
+ _height: 10,
48
43
  birthday: birthday,
49
44
  },
50
45
  { owner: me }
@@ -52,10 +47,16 @@ describe("Simple CoMap operations", async () => {
52
47
 
53
48
  test("Construction", () => {
54
49
  expect(map.color).toEqual("red");
55
- expect(map._roughColor).toEqual("redish");
56
- expect(map.height).toEqual(10);
50
+ expect(map.roughColor).toEqual("redish");
51
+ expect(map._height).toEqual(10);
57
52
  expect(map.birthday).toEqual(birthday);
58
53
  expect(map._raw.get("birthday")).toEqual(birthday.toISOString());
54
+ expect(Object.keys(map)).toEqual([
55
+ "color",
56
+ "_height",
57
+ "birthday",
58
+ "name",
59
+ ]);
59
60
  });
60
61
 
61
62
  describe("Mutation", () => {
@@ -68,11 +69,11 @@ describe("Simple CoMap operations", async () => {
68
69
  expect(map.birthday).toEqual(newBirthday);
69
70
  expect(map._raw.get("birthday")).toEqual(newBirthday.toISOString());
70
71
 
71
- Object.assign(map, { color: "green", height: 20 });
72
+ Object.assign(map, { color: "green", _height: 20 });
72
73
  expect(map.color).toEqual("green");
73
74
  expect(map._raw.get("color")).toEqual("green");
74
- expect(map.height).toEqual(20);
75
- expect(map._raw.get("height")).toEqual(20);
75
+ expect(map._height).toEqual(20);
76
+ expect(map._raw.get("_height")).toEqual(20);
76
77
 
77
78
  map.name = "Secret name";
78
79
  expect(map.name).toEqual("Secret name");
@@ -82,13 +83,9 @@ describe("Simple CoMap operations", async () => {
82
83
  });
83
84
 
84
85
  class RecursiveMap extends CoMap<RecursiveMap> {
85
- declare name: string;
86
- declare next: RecursiveMap | null;
86
+ name = val.string;
87
+ next: val<RecursiveMap | null> = val.ref(() => RecursiveMap);
87
88
  }
88
- RecursiveMap.encoding({
89
- name: "json",
90
- next: { ref: () => RecursiveMap },
91
- });
92
89
 
93
90
  const recursiveMap = new RecursiveMap(
94
91
  {
@@ -116,43 +113,79 @@ describe("Simple CoMap operations", async () => {
116
113
  expect(recursiveMap.next?.next?.name).toEqual("third");
117
114
  });
118
115
  });
116
+
117
+ class MapWithEnumOfMaps extends CoMap<MapWithEnumOfMaps> {
118
+ name = val.string;
119
+ child = val.ref<typeof ChildA | typeof ChildB>((raw) =>
120
+ raw.get("type") === "a" ? ChildA : ChildB
121
+ );
122
+ }
123
+
124
+ class ChildA extends CoMap<ChildA> {
125
+ type = val.literal("a");
126
+ value = val.number;
127
+ }
128
+
129
+ class ChildB extends CoMap<ChildB> {
130
+ type = val.literal("b");
131
+ value = val.string;
132
+ }
133
+
134
+ const mapWithEnum = new MapWithEnumOfMaps(
135
+ {
136
+ name: "enum",
137
+ child: new ChildA(
138
+ {
139
+ type: "a",
140
+ value: 5,
141
+ },
142
+ { owner: me }
143
+ ),
144
+ },
145
+ { owner: me }
146
+ );
147
+
148
+ test("Enum of maps", () => {
149
+ expect(mapWithEnum.name).toEqual("enum");
150
+ expect(mapWithEnum.child?.type).toEqual("a");
151
+ expect(mapWithEnum.child?.value).toEqual(5);
152
+ expect(mapWithEnum.child?.id).toBeDefined();
153
+ });
154
+
155
+ class SuperClassMap extends CoMap<SuperClassMap> {
156
+ name = val.string;
157
+ }
158
+
159
+ class SubClassMap extends SuperClassMap {
160
+ name = val.literal("specificString")
161
+ value = val.number;
162
+ }
163
+ interface SubClassMap extends CoMap<SubClassMap> {}
119
164
  });
120
165
 
121
166
  describe("CoMap resolution", async () => {
122
167
  class TwiceNestedMap extends CoMap<TwiceNestedMap> {
123
- taste!: string;
168
+ taste = val.string;
124
169
  }
125
- TwiceNestedMap.encoding({
126
- taste: "json",
127
- });
128
170
 
129
171
  class NestedMap extends CoMap<NestedMap> {
130
- name!: string;
131
- twiceNested!: TwiceNestedMap | null;
172
+ name = val.string;
173
+ twiceNested = val.ref(() => TwiceNestedMap);
132
174
 
133
175
  get _fancyName() {
134
176
  return "Sir " + this.name;
135
177
  }
136
178
  }
137
- NestedMap.encoding({
138
- name: "json",
139
- twiceNested: { ref: () => TwiceNestedMap },
140
- });
141
179
 
142
180
  class TestMap extends CoMap<TestMap> {
143
- declare color: string;
144
- declare height: number;
145
- declare nested: NestedMap | null;
181
+ color = val.string;
182
+ height = val.number;
183
+ nested = val.ref(() => NestedMap);
146
184
 
147
185
  get _roughColor() {
148
186
  return this.color + "ish";
149
187
  }
150
188
  }
151
- TestMap.encoding({
152
- color: "json",
153
- height: "json",
154
- nested: { ref: () => NestedMap },
155
- });
156
189
 
157
190
  const initNodeAndMap = async () => {
158
191
  const me = await Account.create({
@@ -342,13 +375,9 @@ describe("CoMap resolution", async () => {
342
375
  });
343
376
 
344
377
  class TestMapWithOptionalRef extends CoMap<TestMapWithOptionalRef> {
345
- declare color: string;
346
- declare nested?: NestedMap | null;
378
+ color = val.string;
379
+ nested? = val.ref(() => NestedMap);
347
380
  }
348
- TestMapWithOptionalRef.encoding({
349
- color: "json",
350
- nested: { ref: () => NestedMap },
351
- });
352
381
 
353
382
  test("Construction with optional", async () => {
354
383
  const me = await Account.create({
@@ -389,12 +418,9 @@ describe("CoMap resolution", async () => {
389
418
  });
390
419
 
391
420
  class TestRecord extends CoMap<TestRecord> {
392
- declare _item: number;
421
+ [val.items] = val.number;
393
422
  }
394
423
  interface TestRecord extends Record<string, number> {}
395
- TestRecord.encoding({
396
- _item: "json",
397
- });
398
424
 
399
425
  test("Construction with index signature", async () => {
400
426
  const me = await Account.create({
@@ -1,10 +1,10 @@
1
- import { expect, describe, test, beforeEach, Test } from "vitest";
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, val } from "..";
8
8
  import { Simplify } from "effect/Types";
9
9
 
10
10
  if (!("crypto" in globalThis)) {
@@ -21,42 +21,38 @@ describe("Simple CoStream operations", async () => {
21
21
  name: "Hermes Puggington",
22
22
  });
23
23
 
24
- class TestStream extends CoStream<string> {}
25
- TestStream.encoding({ _item: "json" });
24
+ class TestStream extends CoStream.Of(val.string) {}
26
25
 
27
26
  const stream = new TestStream(["milk"], { owner: me });
28
27
 
29
28
  test("Construction", () => {
30
- expect(stream.by[me.id]?.value).toEqual("milk");
31
- expect(stream.in[me.sessionID]?.value).toEqual("milk");
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.by[me.id]?.value).toEqual("bread");
38
- expect(stream.in[me.sessionID]?.value).toEqual("bread");
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.by[me.id]?.value).toEqual("butter");
42
- expect(stream.in[me.sessionID]?.value).toEqual("butter");
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<string> {
47
+ class TwiceNestedStream extends CoStream.Of(val.string) {
49
48
  fancyValueOf(account: ID<Account>) {
50
- return "Sir " + this.by[account]?.value;
49
+ return "Sir " + this[account]?.value;
51
50
  }
52
51
  }
53
- TwiceNestedStream.encoding({ _item: "json" });
54
52
 
55
- class NestedStream extends CoStream<TwiceNestedStream | null>{}
56
- NestedStream.encoding({ _item: {ref: () => TwiceNestedStream} });
53
+ class NestedStream extends CoStream.Of(val.ref(() => TwiceNestedStream)) {}
57
54
 
58
- class TestStream extends CoStream<NestedStream | null> {}
59
- TestStream.encoding({ _item: {ref: () => NestedStream} });
55
+ class TestStream extends CoStream.Of(val.ref(() => NestedStream)) {}
60
56
 
61
57
  const initNodeAndStream = async () => {
62
58
  const me = await Account.create({
@@ -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
- stream.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
83
- ).toEqual("milk");
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?.by[me.id]?.value).toEqual(null);
106
- expect(loadedStream?.by[me.id]?.ref?.id).toEqual(
107
- stream.by[me.id]?.value?.id
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.by[me.id]!.value!.id,
107
+ stream[me.id]!.value!.id,
112
108
  { as: meOnSecondPeer }
113
109
  );
114
110
 
115
- // expect(loadedStream?.by[me.id]?.value).toEqual(loadedNestedStream);
116
- expect(loadedStream?.by[me.id]?.value?.id).toEqual(
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?.by[me.id]?.value?.by[me.id]?.value).toEqual(null);
120
- // expect(loadedStream?.by[me.id]?.ref?.value).toEqual(loadedNestedStream);
121
- expect(loadedStream?.by[me.id]?.ref?.value?.id).toEqual(
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?.by[me.id]?.value?.by[me.id]?.ref?.id).toEqual(
125
- stream.by[me.id]?.value?.by[me.id]?.value?.id
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.by[me.id]!.value!.by[me.id]!.value!.id,
125
+ stream[me.id]!.value![me.id]!.value!.id,
130
126
  { as: meOnSecondPeer }
131
127
  );
132
128
 
133
- // expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
129
+ // expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(
134
130
  // loadedTwiceNestedStream
135
131
  // );
136
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value?.id).toEqual(
132
+ expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
137
133
  loadedTwiceNestedStream?.id
138
134
  );
139
135
  expect(
140
- loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(
141
- me.id
142
- )
136
+ loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id)
143
137
  ).toEqual("Sir milk");
144
- // expect(loadedStream?.by[me.id]?.ref?.value).toEqual(loadedNestedStream);
145
- expect(loadedStream?.by[me.id]?.ref?.value?.id).toEqual(loadedNestedStream?.id);
146
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.ref?.value?.id).toEqual(
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?.by[me.id]?.value).toEqual(otherNestedStream);
156
- expect(loadedStream?.by[me.id]?.value?.id).toEqual(otherNestedStream?.id);
157
- expect(loadedStream?.by[me.id]?.ref?.value?.id).toEqual(otherNestedStream?.id);
158
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value?.id).toEqual(
159
- otherNestedStream.by[me.id]?.value?.id
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?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(
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.by[me.id]",
196
- subscribedStream.by[me.id]
191
+ "subscribedStream[me.id]",
192
+ subscribedStream[me.id]
197
193
  );
198
194
  console.log(
199
- "subscribedStream.by[me.id]?.value?.by[me.id]?.value",
200
- subscribedStream.by[me.id]?.value?.by[me.id]?.value
195
+ "subscribedStream[me.id]?.value?.[me.id]?.value",
196
+ subscribedStream[me.id]?.value?.[me.id]?.value
201
197
  );
202
198
  console.log(
203
- "subscribedStream.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value",
204
- subscribedStream.by[me.id]?.value?.by[me.id]?.value
205
- ?.by[me.id]?.value
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.by[me.id]?.value).toEqual(null);
212
+ expect(update1[me.id]?.value).toEqual(null);
216
213
 
217
214
  const update2 = yield* $(Queue.take(queue));
218
- expect(update2.by[me.id]?.value).toBeDefined();
219
- expect(update2.by[me.id]?.value?.by[me.id]?.value).toBe(null);
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.by[me.id]?.value?.by[me.id]?.value
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.by[me.id]!.value!.by[me.id]!.value!.push("bread");
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.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
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.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
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.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
251
+ update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value
257
252
  ).toBe("jam");
258
253
  })
259
254
  );