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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. package/.eslintrc.cjs +8 -1
  2. package/.turbo/turbo-build.log +79 -9
  3. package/CHANGELOG.md +76 -0
  4. package/dist/coValues/account.js +171 -0
  5. package/dist/coValues/account.js.map +1 -0
  6. package/dist/coValues/coList.js +246 -0
  7. package/dist/coValues/coList.js.map +1 -0
  8. package/dist/coValues/coMap.js +235 -0
  9. package/dist/coValues/coMap.js.map +1 -0
  10. package/dist/coValues/coStream.js +263 -0
  11. package/dist/coValues/coStream.js.map +1 -0
  12. package/dist/coValues/extensions/imageDef.js +14 -11
  13. package/dist/coValues/extensions/imageDef.js.map +1 -1
  14. package/dist/coValues/group.js +71 -0
  15. package/dist/coValues/group.js.map +1 -0
  16. package/dist/coValues/interfaces.js +61 -0
  17. package/dist/coValues/interfaces.js.map +1 -0
  18. package/dist/implementation/errors.js.map +1 -0
  19. package/dist/implementation/inspect.js +2 -0
  20. package/dist/implementation/inspect.js.map +1 -0
  21. package/dist/{refs.js → implementation/refs.js} +16 -15
  22. package/dist/implementation/refs.js.map +1 -0
  23. package/dist/implementation/schema.js +41 -0
  24. package/dist/implementation/schema.js.map +1 -0
  25. package/dist/{subscriptionScope.js → implementation/subscriptionScope.js} +1 -1
  26. package/dist/implementation/subscriptionScope.js.map +1 -0
  27. package/dist/index.js +10 -29
  28. package/dist/index.js.map +1 -1
  29. package/dist/internal.js +13 -0
  30. package/dist/internal.js.map +1 -0
  31. package/dist/tests/coList.test.js +22 -22
  32. package/dist/tests/coList.test.js.map +1 -1
  33. package/dist/tests/coMap.test.js +140 -46
  34. package/dist/tests/coMap.test.js.map +1 -1
  35. package/dist/tests/coStream.test.js +55 -49
  36. package/dist/tests/coStream.test.js.map +1 -1
  37. package/package.json +11 -4
  38. package/src/coValues/account.ts +327 -0
  39. package/src/coValues/coList.ts +391 -0
  40. package/src/coValues/coMap.ts +413 -0
  41. package/src/coValues/coStream.ts +404 -0
  42. package/src/coValues/extensions/imageDef.ts +20 -16
  43. package/src/coValues/group.ts +139 -0
  44. package/src/coValues/interfaces.ts +218 -0
  45. package/src/implementation/inspect.ts +2 -0
  46. package/src/{refs.ts → implementation/refs.ts} +53 -39
  47. package/src/implementation/schema.ts +124 -0
  48. package/src/{subscriptionScope.ts → implementation/subscriptionScope.ts} +11 -13
  49. package/src/index.ts +14 -57
  50. package/src/internal.ts +15 -0
  51. package/src/tests/coList.test.ts +23 -25
  52. package/src/tests/coMap.test.ts +140 -53
  53. package/src/tests/coStream.test.ts +76 -68
  54. package/dist/coValueInterfaces.js +0 -8
  55. package/dist/coValueInterfaces.js.map +0 -1
  56. package/dist/coValues/account/account.js +0 -11
  57. package/dist/coValues/account/account.js.map +0 -1
  58. package/dist/coValues/account/accountOf.js +0 -150
  59. package/dist/coValues/account/accountOf.js.map +0 -1
  60. package/dist/coValues/account/migration.js +0 -4
  61. package/dist/coValues/account/migration.js.map +0 -1
  62. package/dist/coValues/coList/coList.js +0 -2
  63. package/dist/coValues/coList/coList.js.map +0 -1
  64. package/dist/coValues/coList/coListOf.js +0 -235
  65. package/dist/coValues/coList/coListOf.js.map +0 -1
  66. package/dist/coValues/coList/internalDocs.js +0 -2
  67. package/dist/coValues/coList/internalDocs.js.map +0 -1
  68. package/dist/coValues/coMap/coMap.js +0 -2
  69. package/dist/coValues/coMap/coMap.js.map +0 -1
  70. package/dist/coValues/coMap/coMapOf.js +0 -262
  71. package/dist/coValues/coMap/coMapOf.js.map +0 -1
  72. package/dist/coValues/coMap/internalDocs.js +0 -2
  73. package/dist/coValues/coMap/internalDocs.js.map +0 -1
  74. package/dist/coValues/coStream/coStream.js +0 -2
  75. package/dist/coValues/coStream/coStream.js.map +0 -1
  76. package/dist/coValues/coStream/coStreamOf.js +0 -244
  77. package/dist/coValues/coStream/coStreamOf.js.map +0 -1
  78. package/dist/coValues/construction.js +0 -34
  79. package/dist/coValues/construction.js.map +0 -1
  80. package/dist/coValues/group/group.js +0 -2
  81. package/dist/coValues/group/group.js.map +0 -1
  82. package/dist/coValues/group/groupOf.js +0 -109
  83. package/dist/coValues/group/groupOf.js.map +0 -1
  84. package/dist/coValues/resolution.js +0 -66
  85. package/dist/coValues/resolution.js.map +0 -1
  86. package/dist/errors.js.map +0 -1
  87. package/dist/refs.js.map +0 -1
  88. package/dist/schemaHelpers.js +0 -14
  89. package/dist/schemaHelpers.js.map +0 -1
  90. package/dist/subscriptionScope.js.map +0 -1
  91. package/dist/tests/types.test.js +0 -33
  92. package/dist/tests/types.test.js.map +0 -1
  93. package/src/coValueInterfaces.ts +0 -105
  94. package/src/coValues/account/account.ts +0 -106
  95. package/src/coValues/account/accountOf.ts +0 -284
  96. package/src/coValues/account/migration.ts +0 -12
  97. package/src/coValues/coList/coList.ts +0 -57
  98. package/src/coValues/coList/coListOf.ts +0 -377
  99. package/src/coValues/coList/internalDocs.ts +0 -1
  100. package/src/coValues/coMap/coMap.ts +0 -110
  101. package/src/coValues/coMap/coMapOf.ts +0 -451
  102. package/src/coValues/coMap/internalDocs.ts +0 -1
  103. package/src/coValues/coStream/coStream.ts +0 -63
  104. package/src/coValues/coStream/coStreamOf.ts +0 -404
  105. package/src/coValues/construction.ts +0 -110
  106. package/src/coValues/group/group.ts +0 -27
  107. package/src/coValues/group/groupOf.ts +0 -183
  108. package/src/coValues/resolution.ts +0 -111
  109. package/src/schemaHelpers.ts +0 -72
  110. package/src/tests/types.test.ts +0 -37
  111. /package/dist/{errors.js → implementation/errors.js} +0 -0
  112. /package/src/{errors.ts → implementation/errors.ts} +0 -0
@@ -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 { AnyAccount, BinaryCoStream, Co, ID, S, Account, jazzReady } 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)) {
@@ -21,42 +21,38 @@ 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.Of(co.string) {}
25
25
 
26
26
  const stream = new TestStream(["milk"], { owner: me });
27
27
 
28
28
  test("Construction", () => {
29
- expect(stream.by[me.id]?.value).toEqual("milk");
30
- 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");
31
31
  });
32
32
 
33
33
  describe("Mutation", () => {
34
34
  test("pushing", () => {
35
35
  stream.push("bread");
36
- expect(stream.by[me.id]?.value).toEqual("bread");
37
- 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");
38
38
 
39
39
  stream.push("butter");
40
- expect(stream.by[me.id]?.value).toEqual("butter");
41
- 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");
42
42
  });
43
43
  });
44
44
  });
45
45
 
46
46
  describe("CoStream resolution", async () => {
47
- class TwiceNestedStream extends Co.stream(
48
- S.string
49
- ).as<TwiceNestedStream>() {
50
- fancyValueOf(account: ID<AnyAccount>) {
51
- return "Sir " + this.by[account]?.value;
47
+ class TwiceNestedStream extends CoStream.Of(co.string) {
48
+ fancyValueOf(account: ID<Account>) {
49
+ return "Sir " + this[account]?.value;
52
50
  }
53
51
  }
54
52
 
55
- class NestedStream extends Co.stream(
56
- TwiceNestedStream
57
- ).as<NestedStream>() {}
53
+ class NestedStream extends CoStream.Of(co.ref(TwiceNestedStream)) {}
58
54
 
59
- class TestStream extends Co.stream(NestedStream).as<TestStream>() {}
55
+ class TestStream extends CoStream.Of(co.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,39 +98,49 @@ describe("CoStream resolution", async () => {
102
98
  as: meOnSecondPeer,
103
99
  });
104
100
 
105
- expect(loadedStream?.by[me.id]?.value).toEqual(undefined);
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?.by[me.id]?.value).toEqual(
117
- undefined
111
+ // expect(loadedStream?.[me.id]?.value).toEqual(loadedNestedStream);
112
+ expect(loadedStream?.[me.id]?.value?.id).toEqual(
113
+ loadedNestedStream?.id
114
+ );
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(
118
+ loadedNestedStream?.id
118
119
  );
119
- expect(loadedStream?.by[me.id]?.ref?.value).toEqual(loadedNestedStream);
120
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.ref?.id).toEqual(
121
- 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
122
122
  );
123
123
 
124
124
  const loadedTwiceNestedStream = await TwiceNestedStream.load(
125
- stream.by[me.id]!.value!.by[me.id]!.value!.id,
125
+ stream[me.id]!.value![me.id]!.value!.id,
126
126
  { as: meOnSecondPeer }
127
127
  );
128
128
 
129
- expect(loadedStream?.by[me.id]?.value?.by[me.id]?.value).toEqual(
130
- loadedTwiceNestedStream
129
+ // expect(loadedStream?.[me.id]?.value?.[me.id]?.value).toEqual(
130
+ // loadedTwiceNestedStream
131
+ // );
132
+ expect(loadedStream?.[me.id]?.value?.[me.id]?.value?.id).toEqual(
133
+ loadedTwiceNestedStream?.id
131
134
  );
132
135
  expect(
133
- loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(me.id)
136
+ loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id)
134
137
  ).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
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(
143
+ loadedTwiceNestedStream?.id
138
144
  );
139
145
 
140
146
  const otherNestedStream = new NestedStream(
@@ -142,13 +148,16 @@ describe("CoStream resolution", async () => {
142
148
  { owner: meOnSecondPeer }
143
149
  );
144
150
  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
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
149
158
  );
150
159
  expect(
151
- loadedStream?.by[me.id]?.value?.by[me.id]?.value?.fancyValueOf(me.id)
160
+ loadedStream?.[me.id]?.value?.[me.id]?.value?.fancyValueOf(me.id)
152
161
  ).toEqual("Sir butter");
153
162
  });
154
163
 
@@ -179,17 +188,18 @@ describe("CoStream resolution", async () => {
179
188
  { as: meOnSecondPeer },
180
189
  (subscribedStream) => {
181
190
  console.log(
182
- "subscribedStream.by[me.id]",
183
- subscribedStream.by[me.id]
191
+ "subscribedStream[me.id]",
192
+ subscribedStream[me.id]
184
193
  );
185
194
  console.log(
186
- "subscribedStream.by[me.id]?.value?.by[me.id]?.value",
187
- 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
188
197
  );
189
198
  console.log(
190
- "subscribedStream.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value",
191
- subscribedStream.by[me.id]?.value?.by[me.id]?.value
192
- ?.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
193
203
  );
194
204
  Effect.runPromise(Queue.offer(queue, subscribedStream));
195
205
  }
@@ -199,25 +209,23 @@ describe("CoStream resolution", async () => {
199
209
  const te: T = stream;
200
210
 
201
211
  const update1 = yield* $(Queue.take(queue));
202
- expect(update1.by[me.id]?.value).toEqual(undefined);
212
+ expect(update1[me.id]?.value).toEqual(null);
203
213
 
204
214
  const update2 = yield* $(Queue.take(queue));
205
- expect(update2.by[me.id]?.value).toBeDefined();
206
- expect(
207
- update2.by[me.id]?.value?.by[me.id]?.value
208
- ).toBeUndefined();
215
+ expect(update2[me.id]?.value).toBeDefined();
216
+ expect(update2[me.id]?.value?.[me.id]?.value).toBe(null);
209
217
 
210
218
  const update3 = yield* $(Queue.take(queue));
211
- expect(update3.by[me.id]?.value?.by[me.id]?.value).toBeDefined();
219
+ expect(update3[me.id]?.value?.[me.id]?.value).toBeDefined();
212
220
  expect(
213
- update3.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
221
+ update3[me.id]?.value?.[me.id]?.value?.[me.id]?.value
214
222
  ).toBe("milk");
215
223
 
216
- update3.by[me.id]!.value!.by[me.id]!.value!.push("bread");
224
+ update3[me.id]!.value![me.id]!.value!.push("bread");
217
225
 
218
226
  const update4 = yield* $(Queue.take(queue));
219
227
  expect(
220
- update4.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
228
+ update4[me.id]?.value?.[me.id]?.value?.[me.id]?.value
221
229
  ).toBe("bread");
222
230
 
223
231
  // When assigning a new nested stream, we get an update
@@ -233,14 +241,14 @@ describe("CoStream resolution", async () => {
233
241
 
234
242
  const update5 = yield* $(Queue.take(queue));
235
243
  expect(
236
- update5.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
244
+ update5[me.id]?.value?.[me.id]?.value?.[me.id]?.value
237
245
  ).toBe("butter");
238
246
 
239
247
  // we get updates when the new nested stream changes
240
248
  newTwiceNested.push("jam");
241
249
  const update6 = yield* $(Queue.take(queue));
242
250
  expect(
243
- update6.by[me.id]?.value?.by[me.id]?.value?.by[me.id]?.value
251
+ update6[me.id]?.value?.[me.id]?.value?.[me.id]?.value
244
252
  ).toBe("jam");
245
253
  })
246
254
  );
@@ -252,10 +260,10 @@ describe("Simple BinaryCoStream operations", async () => {
252
260
  name: "Hermes Puggington",
253
261
  });
254
262
 
255
- const stream = new Co.binaryStream(undefined, { owner: me });
263
+ const stream = new BinaryCoStream(undefined, { owner: me });
256
264
 
257
265
  test("Construction", () => {
258
- expect(stream.getChunks()).toBeUndefined();
266
+ expect(stream.getChunks()).toBe(undefined);
259
267
  });
260
268
 
261
269
  test("Mutation", () => {
@@ -280,7 +288,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
280
288
  name: "Hermes Puggington",
281
289
  });
282
290
 
283
- const stream = new Co.binaryStream(undefined, { owner: me });
291
+ const stream = new BinaryCoStream(undefined, { owner: me });
284
292
 
285
293
  stream.start({ mimeType: "text/plain" });
286
294
  stream.push(new Uint8Array([1, 2, 3]));
@@ -314,7 +322,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
314
322
  sessionID: newRandomSessionID(me.id as any),
315
323
  });
316
324
 
317
- const loadedStream = await Co.binaryStream.load(stream.id, {
325
+ const loadedStream = await BinaryCoStream.load(stream.id, {
318
326
  as: meOnSecondPeer,
319
327
  });
320
328
 
@@ -328,7 +336,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
328
336
  test("Subscription", async () => {
329
337
  const { me } = await initNodeAndStream();
330
338
 
331
- const stream = new Co.binaryStream(undefined, { owner: me });
339
+ const stream = new BinaryCoStream(undefined, { owner: me });
332
340
 
333
341
  const [initialAsPeer, secondAsPeer] = connectedPeers(
334
342
  "initial",
@@ -349,7 +357,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
349
357
  Effect.gen(function* ($) {
350
358
  const queue = yield* $(Queue.unbounded<BinaryCoStream>());
351
359
 
352
- Co.binaryStream.subscribe(
360
+ BinaryCoStream.subscribe(
353
361
  stream.id,
354
362
  { as: meOnSecondPeer },
355
363
  (subscribedStream) => {
@@ -358,7 +366,7 @@ describe("BinaryCoStream loading & Subscription", async () => {
358
366
  );
359
367
 
360
368
  const update1 = yield* $(Queue.take(queue));
361
- expect(update1.getChunks()).toBeUndefined();
369
+ expect(update1.getChunks()).toBe(undefined);
362
370
 
363
371
  stream.start({ mimeType: "text/plain" });
364
372
 
@@ -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,cAAc,CAAC;AACtB,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,UAAU,SAAS,CAGvB,MAA+B;IAC7B,MAAM,uBACF,SAAQ,wBAAwB;QAGhC,MA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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
@@ -1 +0,0 @@
1
- {"version":3,"file":"coList.js","sourceRoot":"","sources":["../../../src/coValues/coList/coList.ts"],"names":[],"mappings":""}