jazz-tools 0.7.0-alpha.0 → 0.7.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/.eslintrc.cjs +8 -1
  2. package/CHANGELOG.md +14 -0
  3. package/dist/coValues/account.js +138 -0
  4. package/dist/coValues/account.js.map +1 -0
  5. package/dist/coValues/coList.js +196 -0
  6. package/dist/coValues/coList.js.map +1 -0
  7. package/dist/coValues/coMap.js +249 -0
  8. package/dist/coValues/coMap.js.map +1 -0
  9. package/dist/coValues/coStream.js +189 -0
  10. package/dist/coValues/coStream.js.map +1 -0
  11. package/dist/coValues/extensions/imageDef.js +12 -12
  12. package/dist/coValues/extensions/imageDef.js.map +1 -1
  13. package/dist/coValues/group.js +93 -0
  14. package/dist/coValues/group.js.map +1 -0
  15. package/dist/coValues/interfaces.js +58 -0
  16. package/dist/coValues/interfaces.js.map +1 -0
  17. package/dist/implementation/errors.js.map +1 -0
  18. package/dist/implementation/inspect.js +2 -0
  19. package/dist/implementation/inspect.js.map +1 -0
  20. package/dist/{refs.js → implementation/refs.js} +11 -13
  21. package/dist/implementation/refs.js.map +1 -0
  22. package/dist/implementation/schema.js +6 -0
  23. package/dist/implementation/schema.js.map +1 -0
  24. package/dist/{subscriptionScope.js → implementation/subscriptionScope.js} +1 -1
  25. package/dist/implementation/subscriptionScope.js.map +1 -0
  26. package/dist/index.js +8 -28
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal.js +13 -0
  29. package/dist/internal.js.map +1 -0
  30. package/dist/tests/coList.test.js +26 -22
  31. package/dist/tests/coList.test.js.map +1 -1
  32. package/dist/tests/coMap.test.js +74 -43
  33. package/dist/tests/coMap.test.js.map +1 -1
  34. package/dist/tests/coStream.test.js +35 -24
  35. package/dist/tests/coStream.test.js.map +1 -1
  36. package/package.json +11 -4
  37. package/src/coValues/account.ts +297 -0
  38. package/src/coValues/coList.ts +320 -0
  39. package/src/coValues/coMap.ts +447 -0
  40. package/src/coValues/coStream.ts +325 -0
  41. package/src/coValues/extensions/imageDef.ts +25 -16
  42. package/src/coValues/group.ts +186 -0
  43. package/src/coValues/interfaces.ts +216 -0
  44. package/src/implementation/inspect.ts +2 -0
  45. package/src/{refs.ts → implementation/refs.ts} +21 -32
  46. package/src/implementation/schema.ts +69 -0
  47. package/src/{subscriptionScope.ts → implementation/subscriptionScope.ts} +11 -13
  48. package/src/index.ts +9 -54
  49. package/src/internal.ts +15 -0
  50. package/src/tests/coList.test.ts +27 -25
  51. package/src/tests/coMap.test.ts +111 -50
  52. package/src/tests/coStream.test.ts +51 -38
  53. package/dist/coValueInterfaces.js +0 -8
  54. package/dist/coValueInterfaces.js.map +0 -1
  55. package/dist/coValues/account/account.js +0 -11
  56. package/dist/coValues/account/account.js.map +0 -1
  57. package/dist/coValues/account/accountOf.js +0 -150
  58. package/dist/coValues/account/accountOf.js.map +0 -1
  59. package/dist/coValues/account/migration.js +0 -4
  60. package/dist/coValues/account/migration.js.map +0 -1
  61. package/dist/coValues/coList/coList.js +0 -2
  62. package/dist/coValues/coList/coList.js.map +0 -1
  63. package/dist/coValues/coList/coListOf.js +0 -235
  64. package/dist/coValues/coList/coListOf.js.map +0 -1
  65. package/dist/coValues/coList/internalDocs.js +0 -2
  66. package/dist/coValues/coList/internalDocs.js.map +0 -1
  67. package/dist/coValues/coMap/coMap.js +0 -2
  68. package/dist/coValues/coMap/coMap.js.map +0 -1
  69. package/dist/coValues/coMap/coMapOf.js +0 -262
  70. package/dist/coValues/coMap/coMapOf.js.map +0 -1
  71. package/dist/coValues/coMap/internalDocs.js +0 -2
  72. package/dist/coValues/coMap/internalDocs.js.map +0 -1
  73. package/dist/coValues/coStream/coStream.js +0 -2
  74. package/dist/coValues/coStream/coStream.js.map +0 -1
  75. package/dist/coValues/coStream/coStreamOf.js +0 -244
  76. package/dist/coValues/coStream/coStreamOf.js.map +0 -1
  77. package/dist/coValues/construction.js +0 -34
  78. package/dist/coValues/construction.js.map +0 -1
  79. package/dist/coValues/group/group.js +0 -2
  80. package/dist/coValues/group/group.js.map +0 -1
  81. package/dist/coValues/group/groupOf.js +0 -109
  82. package/dist/coValues/group/groupOf.js.map +0 -1
  83. package/dist/coValues/resolution.js +0 -66
  84. package/dist/coValues/resolution.js.map +0 -1
  85. package/dist/errors.js.map +0 -1
  86. package/dist/refs.js.map +0 -1
  87. package/dist/schemaHelpers.js +0 -14
  88. package/dist/schemaHelpers.js.map +0 -1
  89. package/dist/subscriptionScope.js.map +0 -1
  90. package/dist/tests/types.test.js +0 -33
  91. package/dist/tests/types.test.js.map +0 -1
  92. package/src/coValueInterfaces.ts +0 -105
  93. package/src/coValues/account/account.ts +0 -106
  94. package/src/coValues/account/accountOf.ts +0 -284
  95. package/src/coValues/account/migration.ts +0 -12
  96. package/src/coValues/coList/coList.ts +0 -57
  97. package/src/coValues/coList/coListOf.ts +0 -377
  98. package/src/coValues/coList/internalDocs.ts +0 -1
  99. package/src/coValues/coMap/coMap.ts +0 -110
  100. package/src/coValues/coMap/coMapOf.ts +0 -451
  101. package/src/coValues/coMap/internalDocs.ts +0 -1
  102. package/src/coValues/coStream/coStream.ts +0 -63
  103. package/src/coValues/coStream/coStreamOf.ts +0 -404
  104. package/src/coValues/construction.ts +0 -110
  105. package/src/coValues/group/group.ts +0 -27
  106. package/src/coValues/group/groupOf.ts +0 -183
  107. package/src/coValues/resolution.ts +0 -111
  108. package/src/schemaHelpers.ts +0 -72
  109. package/src/tests/types.test.ts +0 -37
  110. /package/dist/{errors.js → implementation/errors.js} +0 -0
  111. /package/src/{errors.ts → implementation/errors.ts} +0 -0
@@ -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 { Co, S, Account, jazzReady } from "..";
7
+ import { Account, jazzReady, Encoders, indexSignature, CoMap } from "..";
8
8
 
9
9
  if (!("crypto" in globalThis)) {
10
10
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -20,16 +20,24 @@ describe("Simple CoMap operations", async () => {
20
20
  name: "Hermes Puggington",
21
21
  });
22
22
 
23
- class TestMap extends Co.map({
24
- color: S.string,
25
- height: S.number,
26
- birthday: S.Date,
27
- name: S.optional(S.string),
28
- }).as<TestMap>() {
29
- get roughColor() {
23
+ class TestMap extends CoMap<TestMap> {
24
+ declare color: string;
25
+ declare height: number;
26
+ declare birthday: Date;
27
+ declare name?: string;
28
+
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
+
40
+ console.log("TestMap schema", TestMap.prototype._encoding);
33
41
 
34
42
  const birthday = new Date();
35
43
 
@@ -44,7 +52,7 @@ describe("Simple CoMap operations", async () => {
44
52
 
45
53
  test("Construction", () => {
46
54
  expect(map.color).toEqual("red");
47
- expect(map.roughColor).toEqual("redish");
55
+ expect(map._roughColor).toEqual("redish");
48
56
  expect(map.height).toEqual(10);
49
57
  expect(map.birthday).toEqual(birthday);
50
58
  expect(map._raw.get("birthday")).toEqual(birthday.toISOString());
@@ -58,9 +66,7 @@ describe("Simple CoMap operations", async () => {
58
66
  const newBirthday = new Date();
59
67
  map.birthday = newBirthday;
60
68
  expect(map.birthday).toEqual(newBirthday);
61
- expect(map._raw.get("birthday")).toEqual(
62
- newBirthday.toISOString()
63
- );
69
+ expect(map._raw.get("birthday")).toEqual(newBirthday.toISOString());
64
70
 
65
71
  Object.assign(map, { color: "green", height: 20 });
66
72
  expect(map.color).toEqual("green");
@@ -70,35 +76,83 @@ describe("Simple CoMap operations", async () => {
70
76
 
71
77
  map.name = "Secret name";
72
78
  expect(map.name).toEqual("Secret name");
73
- delete map.name;
79
+ map.name = undefined;
74
80
  expect(map.name).toEqual(undefined);
75
81
  });
76
82
  });
83
+
84
+ class RecursiveMap extends CoMap<RecursiveMap> {
85
+ declare name: string;
86
+ declare next: RecursiveMap | null;
87
+ }
88
+ RecursiveMap.encoding({
89
+ name: "json",
90
+ next: { ref: () => RecursiveMap },
91
+ });
92
+
93
+ const recursiveMap = new RecursiveMap(
94
+ {
95
+ name: "first",
96
+ next: new RecursiveMap(
97
+ {
98
+ name: "second",
99
+ next: new RecursiveMap(
100
+ {
101
+ name: "third",
102
+ },
103
+ { owner: me }
104
+ ),
105
+ },
106
+ { owner: me }
107
+ ),
108
+ },
109
+ { owner: me }
110
+ );
111
+
112
+ describe("Recursive CoMap", () => {
113
+ test("Construction", () => {
114
+ expect(recursiveMap.name).toEqual("first");
115
+ expect(recursiveMap.next?.name).toEqual("second");
116
+ expect(recursiveMap.next?.next?.name).toEqual("third");
117
+ });
118
+ });
77
119
  });
78
120
 
79
121
  describe("CoMap resolution", async () => {
80
- class TwiceNestedMap extends Co.map({
81
- taste: S.string,
82
- }).as<TwiceNestedMap>() {}
83
-
84
- class NestedMap extends Co.map({
85
- name: S.string,
86
- twiceNested: TwiceNestedMap,
87
- }).as<NestedMap>() {
88
- get fancyName() {
122
+ class TwiceNestedMap extends CoMap<TwiceNestedMap> {
123
+ taste!: string;
124
+ }
125
+ TwiceNestedMap.encoding({
126
+ taste: "json",
127
+ });
128
+
129
+ class NestedMap extends CoMap<NestedMap> {
130
+ name!: string;
131
+ twiceNested!: TwiceNestedMap | null;
132
+
133
+ get _fancyName() {
89
134
  return "Sir " + this.name;
90
135
  }
91
136
  }
137
+ NestedMap.encoding({
138
+ name: "json",
139
+ twiceNested: { ref: () => TwiceNestedMap },
140
+ });
141
+
142
+ class TestMap extends CoMap<TestMap> {
143
+ declare color: string;
144
+ declare height: number;
145
+ declare nested: NestedMap | null;
92
146
 
93
- class TestMap extends Co.map({
94
- color: S.string,
95
- height: S.number,
96
- nested: NestedMap,
97
- }).as<TestMap>() {
98
- get roughColor() {
147
+ get _roughColor() {
99
148
  return this.color + "ish";
100
149
  }
101
150
  }
151
+ TestMap.encoding({
152
+ color: "json",
153
+ height: "json",
154
+ nested: { ref: () => NestedMap },
155
+ });
102
156
 
103
157
  const initNodeAndMap = async () => {
104
158
  const me = await Account.create({
@@ -132,10 +186,10 @@ describe("CoMap resolution", async () => {
132
186
  // const test: Schema.Schema.To<typeof NestedMap>
133
187
 
134
188
  expect(map.color).toEqual("red");
135
- expect(map.roughColor).toEqual("redish");
189
+ expect(map._roughColor).toEqual("redish");
136
190
  expect(map.height).toEqual(10);
137
191
  expect(map.nested?.name).toEqual("nested");
138
- expect(map.nested?.fancyName).toEqual("Sir nested");
192
+ expect(map.nested?._fancyName).toEqual("Sir nested");
139
193
  expect(map.nested?.id).toBeDefined();
140
194
  expect(map.nested?.twiceNested?.taste).toEqual("sour");
141
195
  });
@@ -159,16 +213,16 @@ describe("CoMap resolution", async () => {
159
213
 
160
214
  expect(loadedMap?.color).toEqual("red");
161
215
  expect(loadedMap?.height).toEqual(10);
162
- expect(loadedMap?.nested).toEqual(undefined);
216
+ expect(loadedMap?.nested).toEqual(null);
163
217
  expect(loadedMap?._refs.nested?.id).toEqual(map.nested?.id);
164
- expect(loadedMap?._refs.nested?.value).toEqual(undefined);
218
+ expect(loadedMap?._refs.nested?.value).toEqual(null);
165
219
 
166
220
  const loadedNestedMap = await NestedMap.load(map.nested!.id, {
167
221
  as: meOnSecondPeer,
168
222
  });
169
223
 
170
224
  expect(loadedMap?.nested?.name).toEqual("nested");
171
- expect(loadedMap?.nested.fancyName).toEqual("Sir nested");
225
+ expect(loadedMap?.nested?._fancyName).toEqual("Sir nested");
172
226
  expect(loadedMap?._refs.nested?.value).toEqual(loadedNestedMap);
173
227
  expect(loadedMap?.nested?.twiceNested?.taste).toEqual(undefined);
174
228
 
@@ -236,7 +290,7 @@ describe("CoMap resolution", async () => {
236
290
  );
237
291
 
238
292
  const update1 = yield* $(Queue.take(queue));
239
- expect(update1.nested).toEqual(undefined);
293
+ expect(update1.nested).toEqual(null);
240
294
 
241
295
  const update2 = yield* $(Queue.take(queue));
242
296
  expect(update2.nested?.name).toEqual("nested");
@@ -287,10 +341,14 @@ describe("CoMap resolution", async () => {
287
341
  );
288
342
  });
289
343
 
290
- class TestMapWithOptionalRef extends Co.map({
291
- color: S.string,
292
- nested: S.optional(NestedMap),
293
- }).as<TestMapWithOptionalRef>() {}
344
+ class TestMapWithOptionalRef extends CoMap<TestMapWithOptionalRef> {
345
+ declare color: string;
346
+ declare nested?: NestedMap | null;
347
+ }
348
+ TestMapWithOptionalRef.encoding({
349
+ color: "json",
350
+ nested: { ref: () => NestedMap },
351
+ });
294
352
 
295
353
  test("Construction with optional", async () => {
296
354
  const me = await Account.create({
@@ -326,14 +384,17 @@ describe("CoMap resolution", async () => {
326
384
 
327
385
  expect(mapWith.color).toEqual("red");
328
386
  expect(mapWith.nested?.name).toEqual("wow!");
329
- expect(mapWith.nested?.fancyName).toEqual("Sir wow!");
387
+ expect(mapWith.nested?._fancyName).toEqual("Sir wow!");
330
388
  expect(mapWith.nested?._raw).toBeDefined();
331
389
  });
332
390
 
333
- class TestRecord extends Co.map(
334
- { color: S.string },
335
- { key: S.string, value: S.string }
336
- ).as<TestRecord>() {}
391
+ class TestRecord extends CoMap<TestRecord> {
392
+ declare [indexSignature]: number;
393
+ }
394
+ interface TestRecord extends Record<string, number> {}
395
+ TestRecord.encoding({
396
+ [indexSignature]: "json",
397
+ });
337
398
 
338
399
  test("Construction with index signature", async () => {
339
400
  const me = await Account.create({
@@ -342,16 +403,16 @@ describe("CoMap resolution", async () => {
342
403
 
343
404
  const record = new TestRecord(
344
405
  {
345
- color: "red",
346
- other: "wild",
406
+ height: 5,
407
+ other: 3,
347
408
  },
348
409
  { owner: me }
349
410
  );
350
411
 
351
- expect(record.color).toEqual("red");
352
- expect(record._raw.get("color")).toEqual("red");
353
- expect(record.other).toEqual("wild");
354
- expect(record._raw.get("other")).toEqual("wild");
355
- expect(Object.keys(record)).toEqual(["color", "other"]);
412
+ expect(record.height).toEqual(5);
413
+ expect(record._raw.get("height")).toEqual(5);
414
+ expect(record.other).toEqual(3);
415
+ expect(record._raw.get("other")).toEqual(3);
416
+ expect(Object.keys(record)).toEqual(["height", "other"]);
356
417
  });
357
418
  });
@@ -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 { AnyAccount, BinaryCoStream, Co, ID, S, Account, jazzReady } from "..";
7
+ import { BinaryCoStream, ID, Account, jazzReady, CoStream } from "..";
8
8
  import { Simplify } from "effect/Types";
9
9
 
10
10
  if (!("crypto" in globalThis)) {
@@ -21,7 +21,8 @@ describe("Simple CoStream operations", async () => {
21
21
  name: "Hermes Puggington",
22
22
  });
23
23
 
24
- class TestStream extends Co.stream(S.string).as<TestStream>() {}
24
+ class TestStream extends CoStream<string> {}
25
+ TestStream.encoding({ _item: "json" });
25
26
 
26
27
  const stream = new TestStream(["milk"], { owner: me });
27
28
 
@@ -44,19 +45,18 @@ describe("Simple CoStream operations", async () => {
44
45
  });
45
46
 
46
47
  describe("CoStream resolution", async () => {
47
- class TwiceNestedStream extends Co.stream(
48
- S.string
49
- ).as<TwiceNestedStream>() {
50
- fancyValueOf(account: ID<AnyAccount>) {
48
+ class TwiceNestedStream extends CoStream<string> {
49
+ fancyValueOf(account: ID<Account>) {
51
50
  return "Sir " + this.by[account]?.value;
52
51
  }
53
52
  }
53
+ TwiceNestedStream.encoding({ _item: "json" });
54
54
 
55
- class NestedStream extends Co.stream(
56
- TwiceNestedStream
57
- ).as<NestedStream>() {}
55
+ class NestedStream extends CoStream<TwiceNestedStream | null>{}
56
+ NestedStream.encoding({ _item: {ref: () => TwiceNestedStream} });
58
57
 
59
- class TestStream extends Co.stream(NestedStream).as<TestStream>() {}
58
+ class TestStream extends CoStream<NestedStream | null> {}
59
+ TestStream.encoding({ _item: {ref: () => NestedStream} });
60
60
 
61
61
  const initNodeAndStream = async () => {
62
62
  const me = await Account.create({
@@ -102,7 +102,7 @@ describe("CoStream resolution", async () => {
102
102
  as: meOnSecondPeer,
103
103
  });
104
104
 
105
- expect(loadedStream?.by[me.id]?.value).toEqual(undefined);
105
+ expect(loadedStream?.by[me.id]?.value).toEqual(null);
106
106
  expect(loadedStream?.by[me.id]?.ref?.id).toEqual(
107
107
  stream.by[me.id]?.value?.id
108
108
  );
@@ -112,11 +112,15 @@ describe("CoStream resolution", async () => {
112
112
  { as: meOnSecondPeer }
113
113
  );
114
114
 
115
- expect(loadedStream?.by[me.id]?.value).toEqual(loadedNestedStream);
116
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
117
- undefined
115
+ // expect(loadedStream?.by[me.id]?.value).toEqual(loadedNestedStream);
116
+ expect(loadedStream?.by[me.id]?.value?.id).toEqual(
117
+ loadedNestedStream?.id
118
+ );
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(
122
+ loadedNestedStream?.id
118
123
  );
119
- expect(loadedStream?.by[me.id]?.ref?.value).toEqual(loadedNestedStream);
120
124
  expect(loadedStream?.by[me.id]?.value?.by[me.id]?.ref?.id).toEqual(
121
125
  stream.by[me.id]?.value?.by[me.id]?.value?.id
122
126
  );
@@ -126,15 +130,21 @@ describe("CoStream resolution", async () => {
126
130
  { as: meOnSecondPeer }
127
131
  );
128
132
 
129
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
130
- loadedTwiceNestedStream
133
+ // expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
134
+ // loadedTwiceNestedStream
135
+ // );
136
+ expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value?.id).toEqual(
137
+ loadedTwiceNestedStream?.id
131
138
  );
132
139
  expect(
133
- loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(me.id)
140
+ loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(
141
+ me.id
142
+ )
134
143
  ).toEqual("Sir milk");
135
- expect(loadedStream?.by[me.id]?.ref?.value).toEqual(loadedNestedStream);
136
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.ref?.value).toEqual(
137
- loadedTwiceNestedStream
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(
147
+ loadedTwiceNestedStream?.id
138
148
  );
139
149
 
140
150
  const otherNestedStream = new NestedStream(
@@ -142,13 +152,16 @@ describe("CoStream resolution", async () => {
142
152
  { owner: meOnSecondPeer }
143
153
  );
144
154
  loadedStream?.push(otherNestedStream);
145
- expect(loadedStream?.by[me.id]?.value).toEqual(otherNestedStream);
146
- expect(loadedStream?.by[me.id]?.ref?.value).toEqual(otherNestedStream);
147
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
148
- otherNestedStream.by[me.id]?.value
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
149
160
  );
150
161
  expect(
151
- loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(me.id)
162
+ loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(
163
+ me.id
164
+ )
152
165
  ).toEqual("Sir butter");
153
166
  });
154
167
 
@@ -199,16 +212,16 @@ describe("CoStream resolution", async () => {
199
212
  const te: T = stream;
200
213
 
201
214
  const update1 = yield* $(Queue.take(queue));
202
- expect(update1.by[me.id]?.value).toEqual(undefined);
215
+ expect(update1.by[me.id]?.value).toEqual(null);
203
216
 
204
217
  const update2 = yield* $(Queue.take(queue));
205
218
  expect(update2.by[me.id]?.value).toBeDefined();
206
- expect(
207
- update2.by[me.id]?.value?.by[me.id]?.value
208
- ).toBeUndefined();
219
+ expect(update2.by[me.id]?.value?.by[me.id]?.value).toBe(null);
209
220
 
210
221
  const update3 = yield* $(Queue.take(queue));
211
- expect(update3.by[me.id]?.value?.by[me.id]?.value).toBeDefined();
222
+ expect(
223
+ update3.by[me.id]?.value?.by[me.id]?.value
224
+ ).toBeDefined();
212
225
  expect(
213
226
  update3.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
214
227
  ).toBe("milk");
@@ -252,10 +265,10 @@ describe("Simple BinaryCoStream operations", async () => {
252
265
  name: "Hermes Puggington",
253
266
  });
254
267
 
255
- const stream = new Co.binaryStream(undefined, { owner: me });
268
+ const stream = new BinaryCoStream(undefined, { owner: me });
256
269
 
257
270
  test("Construction", () => {
258
- expect(stream.getChunks()).toBeUndefined();
271
+ expect(stream.getChunks()).toBe(undefined);
259
272
  });
260
273
 
261
274
  test("Mutation", () => {
@@ -280,7 +293,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
280
293
  name: "Hermes Puggington",
281
294
  });
282
295
 
283
- const stream = new Co.binaryStream(undefined, { owner: me });
296
+ const stream = new BinaryCoStream(undefined, { owner: me });
284
297
 
285
298
  stream.start({ mimeType: "text/plain" });
286
299
  stream.push(new Uint8Array([1, 2, 3]));
@@ -314,7 +327,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
314
327
  sessionID: newRandomSessionID(me.id as any),
315
328
  });
316
329
 
317
- const loadedStream = await Co.binaryStream.load(stream.id, {
330
+ const loadedStream = await BinaryCoStream.load(stream.id, {
318
331
  as: meOnSecondPeer,
319
332
  });
320
333
 
@@ -328,7 +341,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
328
341
  test("Subscription", async () => {
329
342
  const { me } = await initNodeAndStream();
330
343
 
331
- const stream = new Co.binaryStream(undefined, { owner: me });
344
+ const stream = new BinaryCoStream(undefined, { owner: me });
332
345
 
333
346
  const [initialAsPeer, secondAsPeer] = connectedPeers(
334
347
  "initial",
@@ -349,7 +362,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
349
362
  Effect.gen(function* ($) {
350
363
  const queue = yield* $(Queue.unbounded<BinaryCoStream>());
351
364
 
352
- Co.binaryStream.subscribe(
365
+ BinaryCoStream.subscribe(
353
366
  stream.id,
354
367
  { as: meOnSecondPeer },
355
368
  (subscribedStream) => {
@@ -358,7 +371,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
358
371
  );
359
372
 
360
373
  const update1 = yield* $(Queue.take(queue));
361
- expect(update1.getChunks()).toBeUndefined();
374
+ expect(update1.getChunks()).toBe(undefined);
362
375
 
363
376
  stream.start({ mimeType: "text/plain" });
364
377
 
@@ -1,8 +0,0 @@
1
- export function isCoValueSchema(value) {
2
- return value && value.type !== undefined;
3
- }
4
- export const inspect = Symbol.for("nodejs.util.inspect.custom");
5
- export function isCoValue(value) {
6
- return value && value._type !== undefined;
7
- }
8
- //# sourceMappingURL=coValueInterfaces.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coValueInterfaces.js","sourceRoot":"","sources":["../src/coValueInterfaces.ts"],"names":[],"mappings":"AAoEA,MAAM,UAAU,eAAe,CAAC,KAAU;IACtC,OAAO,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;AA2BhE,MAAM,UAAU,SAAS,CAAC,KAAU;IAChC,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AAC9C,CAAC"}
@@ -1,11 +0,0 @@
1
- import { Context } from "effect";
2
- export function isAccount(value) {
3
- return value._type === "Account";
4
- }
5
- export function isControlledAccount(value) {
6
- return isAccount(value) && value.isMe;
7
- }
8
- export const controlledAccountSym = Symbol("@jazz/controlledAccount");
9
- export class ControlledAccountCtx extends Context.Tag("ControlledAccount")() {
10
- }
11
- //# sourceMappingURL=account.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/coValues/account/account.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AA0BjC,MAAM,UAAU,SAAS,CAAC,KAAc;IACpC,OAAO,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAC/B,KAAc;IAEd,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC;AAC1C,CAAC;AA+CD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAGtE,MAAM,OAAO,oBAAqB,SAAQ,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAGvE;CAAG"}
@@ -1,150 +0,0 @@
1
- import { LocalNode, RawControlledAccount, } from "cojson";
2
- import { inspect, } from "../../coValueInterfaces.js";
3
- import { CoMapOf } from "../coMap/coMapOf.js";
4
- import { controlledAccountSym, } from "./account.js";
5
- import * as S from "@effect/schema/Schema";
6
- import { AST, Schema } from "@effect/schema";
7
- import { SharedCoValueConstructor } from "../construction.js";
8
- import { constructorOfSchemaSym } from "../resolution.js";
9
- import { pipeArguments } from "effect/Pipeable";
10
- import { ValueRef } from "../../refs.js";
11
- export function AccountOf(fields) {
12
- class AccountOfProfileAndRoot extends SharedCoValueConstructor {
13
- static get ast() {
14
- return AST.setAnnotation(Schema.instanceOf(this).ast, constructorOfSchemaSym, this);
15
- }
16
- static pipe() {
17
- // eslint-disable-next-line prefer-rest-params
18
- return pipeArguments(this, arguments);
19
- }
20
- constructor(init, options) {
21
- super();
22
- if (!("fromRaw" in options)) {
23
- throw new Error("Can only construct account from raw or with .create()");
24
- }
25
- this.isMe =
26
- options.fromRaw.id == options.fromRaw.core.node.account.id;
27
- const refs = {
28
- get profile() {
29
- const profileID = options.fromRaw.get("profile");
30
- return profileID && new ValueRef(profileID, controlledAccountFromNode(options.fromRaw.core.node), fields.profile);
31
- },
32
- get root() {
33
- const rootID = options.fromRaw.get("root");
34
- return rootID && new ValueRef(rootID, controlledAccountFromNode(options.fromRaw.core.node), fields.root);
35
- },
36
- };
37
- Object.defineProperties(this, {
38
- id: { value: options.fromRaw.id, enumerable: false },
39
- _type: { value: "Account", enumerable: false },
40
- _owner: { value: this, enumerable: false },
41
- _refs: { value: refs, enumerable: false },
42
- _raw: { value: options.fromRaw, enumerable: false },
43
- _loadedAs: {
44
- get: () => this.isMe
45
- ? this
46
- : controlledAccountFromNode(options.fromRaw.core.node),
47
- enumerable: false,
48
- },
49
- _schema: { value: AccountOfProfileAndRoot, enumerable: false },
50
- });
51
- if (this.isMe) {
52
- this.sessionID =
53
- options.fromRaw.core.node.currentSessionID;
54
- }
55
- }
56
- static fromRaw(raw) {
57
- return new AccountOfProfileAndRoot(undefined, {
58
- fromRaw: raw,
59
- });
60
- }
61
- static async create(options) {
62
- const { node } = await LocalNode.withNewlyCreatedAccount({
63
- ...options,
64
- migration: options.migration &&
65
- (async (rawAccount) => {
66
- const account = new AccountOfProfileAndRoot(undefined, {
67
- fromRaw: rawAccount,
68
- });
69
- await options.migration(account);
70
- }),
71
- });
72
- return new AccountOfProfileAndRoot(undefined, {
73
- fromRaw: node.account,
74
- });
75
- }
76
- static async become(options) {
77
- const node = await LocalNode.withLoadedAccount({
78
- accountID: options.accountID,
79
- accountSecret: options.accountSecret,
80
- sessionID: options.sessionID,
81
- peersToLoadFrom: options.peersToLoadFrom,
82
- migration: options.migration &&
83
- (async (rawAccount) => {
84
- const account = new AccountOfProfileAndRoot(undefined, {
85
- fromRaw: rawAccount,
86
- });
87
- await options.migration(account);
88
- }),
89
- });
90
- return new AccountOfProfileAndRoot(undefined, {
91
- fromRaw: node.account,
92
- });
93
- }
94
- async acceptInvite(valueID, inviteSecret, valueSchema) {
95
- if (!this.isMe) {
96
- throw new Error("Only a controlled account can accept invites");
97
- }
98
- await this._raw.acceptInvite(valueID, inviteSecret);
99
- return valueSchema.load(valueID, { as: this });
100
- }
101
- get profile() {
102
- return this._refs.profile.accessFrom(this);
103
- }
104
- get root() {
105
- return this._refs.root.accessFrom(this);
106
- }
107
- myRole() {
108
- return "admin";
109
- }
110
- toJSON() {
111
- return {
112
- profile: this.profile?.toJSON(),
113
- root: this.root?.toJSON(),
114
- };
115
- }
116
- [(Schema.TypeId, inspect)]() {
117
- return this.toJSON();
118
- }
119
- static as() {
120
- return this;
121
- }
122
- }
123
- AccountOfProfileAndRoot.type = "Account";
124
- return AccountOfProfileAndRoot;
125
- }
126
- export class BaseProfile extends CoMapOf({
127
- name: S.string,
128
- }).as() {
129
- }
130
- export class Account extends AccountOf({
131
- profile: BaseProfile,
132
- root: S.null,
133
- }).as() {
134
- }
135
- const simpleControlledAccounts = new WeakMap();
136
- export function controlledAccountFromNode(node) {
137
- if (!(node.account instanceof RawControlledAccount)) {
138
- throw new Error("Expected a controlled account");
139
- }
140
- let simpleAccount;
141
- if (simpleControlledAccounts.has(node.account)) {
142
- simpleAccount = simpleControlledAccounts.get(node.account);
143
- }
144
- else {
145
- simpleAccount = Account.fromRaw(node.account);
146
- simpleControlledAccounts.set(node.account, simpleAccount);
147
- }
148
- return simpleAccount;
149
- }
150
- //# sourceMappingURL=accountOf.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accountOf.js","sourceRoot":"","sources":["../../../src/coValues/account/accountOf.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,SAAS,EAIT,oBAAoB,GAEvB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAGH,OAAO,GAEV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAKH,oBAAoB,GACvB,MAAM,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Q,SAAS,CAGpC;IACE,OAAO,EAAE,WAAW;IACpB,IAAI,EAAE,CAAC,CAAC,IAAI;CACf,CAAC,CAAC,EAAE,EAAW;CAAG;AAEnB,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAGzC,CAAC;AAEJ,MAAM,UAAU,yBAAyB,CAAC,IAAe;IACrD,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,YAAY,oBAAoB,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,aAAa,CAAC;IAElB,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7C,aAAa,GAAG,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;SAAM,CAAC;QACJ,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CACvB,CAAC;QACtB,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,aAAc,CAAC;AAC1B,CAAC"}
@@ -1,4 +0,0 @@
1
- export function createAccountMigration(accountSchema, migration) {
2
- return migration;
3
- }
4
- //# sourceMappingURL=migration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/coValues/account/migration.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,sBAAsB,CAClC,aAAgB,EAChB,SAA8B;IAE9B,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=coList.js.map