cojson 0.3.7 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/coValue.d.ts +7 -12
  2. package/dist/coValue.js.map +1 -1
  3. package/dist/coValueCore.d.ts +9 -4
  4. package/dist/coValueCore.js +69 -33
  5. package/dist/coValueCore.js.map +1 -1
  6. package/dist/coValues/account.d.ts +62 -0
  7. package/dist/{account.js → coValues/account.js} +19 -11
  8. package/dist/coValues/account.js.map +1 -0
  9. package/dist/coValues/coList.d.ts +19 -19
  10. package/dist/coValues/coList.js.map +1 -1
  11. package/dist/coValues/coMap.d.ts +31 -23
  12. package/dist/coValues/coMap.js +4 -6
  13. package/dist/coValues/coMap.js.map +1 -1
  14. package/dist/coValues/coStream.d.ts +20 -20
  15. package/dist/coValues/coStream.js +2 -1
  16. package/dist/coValues/coStream.js.map +1 -1
  17. package/dist/{group.d.ts → coValues/group.d.ts} +27 -38
  18. package/dist/{group.js → coValues/group.js} +69 -73
  19. package/dist/coValues/group.js.map +1 -0
  20. package/dist/ids.d.ts +1 -1
  21. package/dist/index.d.ts +15 -11
  22. package/dist/index.js +10 -5
  23. package/dist/index.js.map +1 -1
  24. package/dist/localNode.d.ts +20 -7
  25. package/dist/localNode.js +74 -39
  26. package/dist/localNode.js.map +1 -1
  27. package/dist/media.d.ts +1 -1
  28. package/dist/permissions.d.ts +1 -1
  29. package/dist/permissions.js +43 -22
  30. package/dist/permissions.js.map +1 -1
  31. package/dist/queriedCoValues/queriedAccount.d.ts +13 -0
  32. package/dist/queriedCoValues/queriedAccount.js +24 -0
  33. package/dist/queriedCoValues/queriedAccount.js.map +1 -0
  34. package/dist/queriedCoValues/queriedCoList.d.ts +10 -10
  35. package/dist/queriedCoValues/queriedCoList.js +11 -15
  36. package/dist/queriedCoValues/queriedCoList.js.map +1 -1
  37. package/dist/queriedCoValues/queriedCoMap.d.ts +14 -21
  38. package/dist/queriedCoValues/queriedCoMap.js +27 -28
  39. package/dist/queriedCoValues/queriedCoMap.js.map +1 -1
  40. package/dist/queriedCoValues/queriedCoStream.d.ts +13 -17
  41. package/dist/queriedCoValues/queriedCoStream.js +57 -32
  42. package/dist/queriedCoValues/queriedCoStream.js.map +1 -1
  43. package/dist/queriedCoValues/queriedGroup.d.ts +29 -0
  44. package/dist/queriedCoValues/queriedGroup.js +54 -0
  45. package/dist/queriedCoValues/queriedGroup.js.map +1 -0
  46. package/dist/queries.d.ts +40 -9
  47. package/dist/queries.js +104 -39
  48. package/dist/queries.js.map +1 -1
  49. package/dist/tests/testUtils.d.ts +15 -7
  50. package/dist/tests/testUtils.js +16 -17
  51. package/dist/tests/testUtils.js.map +1 -1
  52. package/package.json +2 -2
  53. package/src/coValue.ts +12 -31
  54. package/src/coValueCore.ts +100 -40
  55. package/src/{account.ts → coValues/account.ts} +46 -27
  56. package/src/coValues/coList.ts +24 -28
  57. package/src/coValues/coMap.ts +42 -68
  58. package/src/coValues/coStream.ts +22 -28
  59. package/src/{group.ts → coValues/group.ts} +121 -141
  60. package/src/ids.ts +1 -1
  61. package/src/index.ts +25 -10
  62. package/src/localNode.ts +180 -77
  63. package/src/media.ts +1 -1
  64. package/src/permissions.ts +67 -36
  65. package/src/queriedCoValues/queriedAccount.ts +40 -0
  66. package/src/queriedCoValues/queriedCoList.ts +22 -30
  67. package/src/queriedCoValues/queriedCoMap.ts +60 -72
  68. package/src/queriedCoValues/queriedCoStream.ts +105 -79
  69. package/src/queriedCoValues/queriedGroup.ts +90 -0
  70. package/src/queries.ts +181 -60
  71. package/src/tests/account.test.ts +14 -9
  72. package/src/tests/coValueCore.test.ts +2 -2
  73. package/src/tests/permissions.test.ts +351 -242
  74. package/src/tests/queries.test.ts +162 -82
  75. package/src/tests/sync.test.ts +11 -11
  76. package/src/tests/testUtils.ts +16 -18
  77. package/dist/account.d.ts +0 -58
  78. package/dist/account.js.map +0 -1
  79. package/dist/group.js.map +0 -1
@@ -1,12 +1,21 @@
1
- import { BinaryCoStream, CoList, CoMap, CoStream, Group, LocalNode, cojsonReady } from "..";
1
+ import {
2
+ BinaryCoStream,
3
+ CoList,
4
+ CoMap,
5
+ CoStream,
6
+ Group,
7
+ LocalNode,
8
+ cojsonReady,
9
+ } from "..";
2
10
 
3
11
  beforeEach(async () => {
4
12
  await cojsonReady;
5
13
  });
6
14
 
7
15
  test("Queries with maps work", async () => {
8
- const { node, accountID } =
9
- LocalNode.withNewlyCreatedAccount("Hermes Puggington");
16
+ const { node, accountID } = LocalNode.withNewlyCreatedAccount({
17
+ name: "Hermes Puggington",
18
+ });
10
19
 
11
20
  const group = node.createGroup();
12
21
 
@@ -16,7 +25,7 @@ test("Queries with maps work", async () => {
16
25
  subMap: CoMap<{
17
26
  hello: "world" | "moon" | "sun";
18
27
  id: string;
19
- }>;
28
+ }>["id"];
20
29
  }>
21
30
  >();
22
31
 
@@ -33,18 +42,20 @@ test("Queries with maps work", async () => {
33
42
  expect(queriedMap.hello).toBe("world");
34
43
  expect(Object.keys(queriedMap)).toEqual(["hello", "subMap"]);
35
44
  if (queriedMap.edits.hello?.by?.profile?.name) {
36
- expect(queriedMap.edits.hello).toMatchObject({
37
- by: {
38
- id: accountID,
39
- profile: {
40
- id: node.expectProfileLoaded(accountID).id,
41
- name: "Hermes Puggington",
42
- },
43
- isMe: true,
44
- },
45
- tx: map.lastEditAt("hello")!.tx,
46
- at: new Date(map.lastEditAt("hello")!.at),
47
- });
45
+ expect(queriedMap.edits.hello.by.id).toEqual(accountID);
46
+ expect(queriedMap.edits.hello.by.profile.id).toEqual(
47
+ node.expectProfileLoaded(accountID).id
48
+ );
49
+ expect(queriedMap.edits.hello.by.profile.name).toEqual(
50
+ "Hermes Puggington"
51
+ );
52
+ expect(queriedMap.edits.hello.by.isMe).toBe(true);
53
+ expect(queriedMap.edits.hello.tx).toEqual(
54
+ map.lastEditAt("hello")!.tx
55
+ );
56
+ expect(queriedMap.edits.hello.at).toEqual(
57
+ new Date(map.lastEditAt("hello")!.at)
58
+ );
48
59
  if (queriedMap.subMap) {
49
60
  expect(queriedMap.subMap.type).toBe("comap");
50
61
  expect(queriedMap.subMap.id).toEqual("foreignID");
@@ -79,7 +90,7 @@ test("Queries with maps work", async () => {
79
90
  }>
80
91
  >();
81
92
 
82
- map = map.set("subMap", subMap);
93
+ map = map.set("subMap", subMap.id);
83
94
 
84
95
  subMap = subMap.mutate((subMap) => {
85
96
  subMap.set("hello", "world");
@@ -92,8 +103,9 @@ test("Queries with maps work", async () => {
92
103
  });
93
104
 
94
105
  test("Queries with lists work", () => {
95
- const { node, accountID } =
96
- LocalNode.withNewlyCreatedAccount("Hermes Puggington");
106
+ const { node, accountID } = LocalNode.withNewlyCreatedAccount({
107
+ name: "Hermes Puggington",
108
+ });
97
109
 
98
110
  const group = node.createGroup();
99
111
 
@@ -113,20 +125,17 @@ test("Queries with lists work", () => {
113
125
  expect(queriedList[1]).toBe("world");
114
126
  expect(queriedList[2]).toBe("moon");
115
127
  if (queriedList.edits[2]?.by?.profile?.name) {
116
- expect(queriedList.edits[2]).toMatchObject({
117
- by: {
118
- id: accountID,
119
- profile: {
120
- id: node.expectProfileLoaded(accountID).id,
121
- name: "Hermes Puggington",
122
- },
123
- isMe: true,
124
- },
125
- at: expect.any(Date),
126
- });
128
+ expect(queriedList.edits[2].by.id).toEqual(accountID);
129
+ expect(queriedList.edits[2].by.profile.id).toEqual(
130
+ node.expectProfileLoaded(accountID).id
131
+ );
132
+ expect(queriedList.edits[2].by.profile.name).toEqual(
133
+ "Hermes Puggington"
134
+ );
135
+ expect(queriedList.edits[2].by.isMe).toBe(true);
136
+ expect(queriedList.edits[2].at).toBeInstanceOf(Date);
127
137
  if (queriedList.length === 3) {
128
138
  queriedList.append("sun");
129
-
130
139
  } else if (
131
140
  queriedList.length === 4 &&
132
141
  queriedList.edits[3]?.by?.profile?.name ===
@@ -152,11 +161,13 @@ test("Queries with lists work", () => {
152
161
  });
153
162
 
154
163
  test("List of nested maps works", () => {
155
- const { node } = LocalNode.withNewlyCreatedAccount("Hermes Puggington");
164
+ const { node } = LocalNode.withNewlyCreatedAccount({
165
+ name: "Hermes Puggington",
166
+ });
156
167
 
157
168
  const group = node.createGroup();
158
169
 
159
- let list = group.createList<CoList<CoMap<{ hello: "world" }>>>();
170
+ let list = group.createList<CoList<CoMap<{ hello: "world" }>["id"]>>();
160
171
 
161
172
  const done = new Promise<void>((resolve) => {
162
173
  const unsubQuery = node.query(list.id, (queriedList) => {
@@ -176,23 +187,23 @@ test("List of nested maps works", () => {
176
187
  list = list.append(
177
188
  group.createMap<CoMap<{ hello: "world" }>>({
178
189
  hello: "world",
179
- })
190
+ }).id
180
191
  );
181
192
 
182
193
  return done;
183
194
  });
184
195
 
185
196
  test("Can call .map on a quieried coList", async () => {
186
- const { node } = LocalNode.withNewlyCreatedAccount("Hermes Puggington");
197
+ const { node } = LocalNode.withNewlyCreatedAccount({
198
+ name: "Hermes Puggington",
199
+ });
187
200
 
188
201
  const group = node.createGroup();
189
202
 
190
203
  let list = group.createList<CoList<string>>();
191
204
 
192
205
  const done = new Promise<void>((resolve) => {
193
-
194
206
  const unsubQuery = node.query(list.id, (queriedList) => {
195
-
196
207
  if (queriedList && queriedList[0]) {
197
208
  // console.log("update", queriedList);
198
209
  expect(queriedList.map((item) => item + "!!!")).toEqual([
@@ -215,8 +226,9 @@ test("Can call .map on a quieried coList", async () => {
215
226
  });
216
227
 
217
228
  test("Queries with streams work", () => {
218
- const { node, accountID } =
219
- LocalNode.withNewlyCreatedAccount("Hermes Puggington");
229
+ const { node, accountID } = LocalNode.withNewlyCreatedAccount({
230
+ name: "Hermes Puggington",
231
+ });
220
232
 
221
233
  const group = node.createGroup();
222
234
 
@@ -233,45 +245,110 @@ test("Queries with streams work", () => {
233
245
  expect(queriedStream.group).toBeInstanceOf(Group);
234
246
  expect(queriedStream.group.id).toBe(group.id);
235
247
  expect(queriedStream.meta).toBe(null);
236
- const expectedEntry = {
237
- last: "world",
238
- by: {
239
- id: accountID,
240
- isMe: true,
241
- profile: {
242
- id: node.expectProfileLoaded(accountID).id,
243
- name: "Hermes Puggington",
244
- },
245
- },
246
- at: new Date(
247
- stream.items[node.currentSessionID][1].madeAt
248
- ),
249
- all: [
250
- {
251
- value: "hello",
252
- at: new Date(
253
- stream.items[
254
- node.currentSessionID
255
- ][0].madeAt
256
- ),
257
- },
258
- {
259
- value: "world",
260
- at: new Date(
261
- stream.items[
262
- node.currentSessionID
263
- ][1].madeAt
264
- ),
265
- },
266
- ],
267
- };
268
- expect(queriedStream.perSession).toMatchObject({
269
- [node.currentSessionID]: expectedEntry,
270
- });
271
- expect(queriedStream.perAccount).toMatchObject({
272
- [accountID]: expectedEntry,
273
- });
274
- expect(queriedStream.me).toMatchObject(expectedEntry);
248
+
249
+ expect(
250
+ Object.fromEntries(queriedStream.perSession)[
251
+ node.currentSessionID
252
+ ].last
253
+ ).toEqual("world");
254
+ expect(
255
+ Object.fromEntries(queriedStream.perSession)[
256
+ node.currentSessionID
257
+ ].all[0].value
258
+ ).toEqual("hello");
259
+ expect(
260
+ Object.fromEntries(queriedStream.perSession)[
261
+ node.currentSessionID
262
+ ].all[0].at
263
+ ).toEqual(
264
+ new Date(stream.items[node.currentSessionID][0].madeAt)
265
+ );
266
+ expect(
267
+ Object.fromEntries(queriedStream.perSession)[
268
+ node.currentSessionID
269
+ ].all[1].value
270
+ ).toEqual("world");
271
+ expect(
272
+ Object.fromEntries(queriedStream.perSession)[
273
+ node.currentSessionID
274
+ ].all[1].at
275
+ ).toEqual(
276
+ new Date(stream.items[node.currentSessionID][1].madeAt)
277
+ );
278
+ expect(
279
+ Object.fromEntries(queriedStream.perSession)[
280
+ node.currentSessionID
281
+ ].by?.id
282
+ ).toEqual(accountID);
283
+ expect(
284
+ Object.fromEntries(queriedStream.perSession)[
285
+ node.currentSessionID
286
+ ].by?.profile?.id
287
+ ).toEqual(node.expectProfileLoaded(accountID).id);
288
+ expect(
289
+ Object.fromEntries(queriedStream.perSession)[
290
+ node.currentSessionID
291
+ ].by?.profile?.name
292
+ ).toEqual("Hermes Puggington");
293
+ expect(
294
+ Object.fromEntries(queriedStream.perSession)[
295
+ node.currentSessionID
296
+ ].by?.isMe
297
+ ).toBe(true);
298
+ expect(
299
+ Object.fromEntries(queriedStream.perSession)[
300
+ node.currentSessionID
301
+ ].at
302
+ ).toBeInstanceOf(Date);
303
+
304
+ expect(
305
+ Object.fromEntries(queriedStream.perAccount)[accountID]
306
+ .last
307
+ ).toEqual("world");
308
+ expect(
309
+ Object.fromEntries(queriedStream.perAccount)[accountID]
310
+ .all[0].value
311
+ ).toEqual("hello");
312
+ expect(
313
+ Object.fromEntries(queriedStream.perAccount)[accountID]
314
+ .all[0].at
315
+ ).toEqual(
316
+ new Date(stream.items[node.currentSessionID][0].madeAt)
317
+ );
318
+ expect(
319
+ Object.fromEntries(queriedStream.perAccount)[accountID]
320
+ .all[1].value
321
+ ).toEqual("world");
322
+ expect(
323
+ Object.fromEntries(queriedStream.perAccount)[accountID]
324
+ .all[1].at
325
+ ).toEqual(
326
+ new Date(stream.items[node.currentSessionID][1].madeAt)
327
+ );
328
+ expect(
329
+ Object.fromEntries(queriedStream.perAccount)[accountID]
330
+ .by?.id
331
+ ).toEqual(accountID);
332
+ expect(
333
+ Object.fromEntries(queriedStream.perAccount)[accountID]
334
+ .by?.profile?.id
335
+ ).toEqual(node.expectProfileLoaded(accountID).id);
336
+ expect(
337
+ Object.fromEntries(queriedStream.perAccount)[accountID]
338
+ .by?.profile?.name
339
+ ).toEqual("Hermes Puggington");
340
+ expect(
341
+ Object.fromEntries(queriedStream.perAccount)[accountID]
342
+ .by?.isMe
343
+ ).toBe(true);
344
+ expect(
345
+ Object.fromEntries(queriedStream.perAccount)[accountID]
346
+ .at
347
+ ).toBeInstanceOf(Date);
348
+
349
+ expect(queriedStream.me).toEqual(
350
+ Object.fromEntries(queriedStream.perAccount)[accountID]
351
+ );
275
352
  // console.log("final update", queriedStream);
276
353
  resolve();
277
354
  unsubQuery();
@@ -287,11 +364,14 @@ test("Queries with streams work", () => {
287
364
  });
288
365
 
289
366
  test("Streams of nested maps work", () => {
290
- const { node } = LocalNode.withNewlyCreatedAccount("Hermes Puggington");
367
+ const { node } = LocalNode.withNewlyCreatedAccount({
368
+ name: "Hermes Puggington",
369
+ });
291
370
 
292
371
  const group = node.createGroup();
293
372
 
294
- let stream = group.createStream<CoStream<CoMap<{ hello: "world" }>>>();
373
+ let stream =
374
+ group.createStream<CoStream<CoMap<{ hello: "world" }>["id"]>>();
295
375
 
296
376
  const done = new Promise<void>((resolve) => {
297
377
  const unsubQuery = node.query(stream.id, (queriedStream) => {
@@ -312,7 +392,7 @@ test("Streams of nested maps work", () => {
312
392
  hello: "world",
313
393
  });
314
394
 
315
- stream = stream.push(map);
395
+ stream = stream.push(map.id);
316
396
 
317
397
  return done;
318
- });
398
+ });
@@ -3,13 +3,13 @@ import { LocalNode } from "../localNode.js";
3
3
  import { SyncMessage } from "../sync.js";
4
4
  import { expectMap } from "../coValue.js";
5
5
  import { MapOpPayload } from "../coValues/coMap.js";
6
- import { Group } from "../group.js";
6
+ import { Group } from "../coValues/group.js";
7
7
  import {
8
8
  randomAnonymousAccountAndSessionID,
9
9
  shouldNotResolve,
10
10
  } from "./testUtils.js";
11
11
  import { connectedPeers, newStreamPair } from "../streamUtils.js";
12
- import { AccountID } from "../account.js";
12
+ import { AccountID } from "../coValues/account.js";
13
13
  import { cojsonReady } from "../index.js";
14
14
  import { stableStringify } from "../jsonStringify.js";
15
15
 
@@ -534,7 +534,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
534
534
  // });
535
535
  expect((await reader.read()).value).toMatchObject({
536
536
  action: "load",
537
- id: group.underlyingMap.core.id,
537
+ id: group.core.id,
538
538
  });
539
539
 
540
540
  const mapSubscribeMsg = await reader.read();
@@ -606,7 +606,7 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
606
606
  // });
607
607
  expect((await reader.read()).value).toMatchObject({
608
608
  action: "load",
609
- id: group.underlyingMap.core.id,
609
+ id: group.core.id,
610
610
  });
611
611
 
612
612
  const map = group.createMap();
@@ -660,7 +660,7 @@ test("When we connect a new server peer, we try to sync all existing coValues to
660
660
 
661
661
  expect(groupSubscribeMessage.value).toEqual({
662
662
  action: "load",
663
- ...group.underlyingMap.core.knownState(),
663
+ ...group.core.knownState(),
664
664
  } satisfies SyncMessage);
665
665
 
666
666
  const secondMessage = await reader.read();
@@ -756,7 +756,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
756
756
  const groupSubscribeMsg = await from1.read();
757
757
  expect(groupSubscribeMsg.value).toMatchObject({
758
758
  action: "load",
759
- id: group.underlyingMap.core.id,
759
+ id: group.core.id,
760
760
  });
761
761
 
762
762
  await to2.write(adminSubscribeMessage.value!);
@@ -770,7 +770,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
770
770
 
771
771
  expect(
772
772
  node2.syncManager.peers["test1"]!.optimisticKnownStates[
773
- group.underlyingMap.core.id
773
+ group.core.id
774
774
  ]
775
775
  ).toBeDefined();
776
776
 
@@ -970,7 +970,7 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
970
970
  // });
971
971
  expect((await reader.read()).value).toMatchObject({
972
972
  action: "load",
973
- id: group.underlyingMap.core.id,
973
+ id: group.core.id,
974
974
  });
975
975
 
976
976
  const map = group.createMap();
@@ -1024,7 +1024,7 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
1024
1024
  // });
1025
1025
  expect((await reader.read()).value).toMatchObject({
1026
1026
  action: "load",
1027
- id: group.underlyingMap.core.id,
1027
+ id: group.core.id,
1028
1028
  });
1029
1029
 
1030
1030
  const map = group.createMap();
@@ -1098,7 +1098,7 @@ test("If we start loading a coValue before connecting to a peer that has it, it
1098
1098
  function groupContentEx(group: Group) {
1099
1099
  return {
1100
1100
  action: "content",
1101
- id: group.underlyingMap.core.id,
1101
+ id: group.core.id,
1102
1102
  };
1103
1103
  }
1104
1104
 
@@ -1112,7 +1112,7 @@ function admContEx(adminID: AccountID) {
1112
1112
  function groupStateEx(group: Group) {
1113
1113
  return {
1114
1114
  action: "known",
1115
- id: group.underlyingMap.core.id,
1115
+ id: group.core.id,
1116
1116
  };
1117
1117
  }
1118
1118
 
@@ -1,8 +1,8 @@
1
1
  import { AgentSecret, createdNowUnique, getAgentID, newRandomAgentSecret } from "../crypto.js";
2
2
  import { newRandomSessionID } from "../coValueCore.js";
3
3
  import { LocalNode } from "../localNode.js";
4
- import { expectGroupContent } from "../group.js";
5
- import { AnonymousControlledAccount } from "../account.js";
4
+ import { expectGroup } from "../coValues/group.js";
5
+ import { AnonymousControlledAccount } from "../coValues/account.js";
6
6
  import { SessionID } from "../ids.js";
7
7
  // @ts-ignore
8
8
  import { expect } from "bun:test";
@@ -20,43 +20,41 @@ export function newGroup() {
20
20
 
21
21
  const node = new LocalNode(admin, sessionID);
22
22
 
23
- const group = node.createCoValue({
23
+ const groupCore = node.createCoValue({
24
24
  type: "comap",
25
25
  ruleset: { type: "group", initialAdmin: admin.id },
26
26
  meta: null,
27
27
  ...createdNowUnique(),
28
28
  });
29
29
 
30
- const groupContent = expectGroupContent(group.getCurrentContent());
30
+ const group = expectGroup(groupCore.getCurrentContent());
31
31
 
32
- groupContent.mutate((editable) => {
32
+ group.mutate((editable) => {
33
33
  editable.set(admin.id, "admin", "trusting");
34
34
  expect(editable.get(admin.id)).toEqual("admin");
35
35
  });
36
36
 
37
- return { node, group, admin };
37
+ return { node, groupCore, admin };
38
38
  }
39
39
 
40
40
  export function groupWithTwoAdmins() {
41
- const { group, admin, node } = newGroup();
41
+ const { groupCore, admin, node } = newGroup();
42
42
 
43
43
  const otherAdmin = node.createAccount("otherAdmin");
44
44
 
45
- let content = expectGroupContent(group.getCurrentContent());
45
+ let group = expectGroup(groupCore.getCurrentContent());
46
46
 
47
- content.mutate((editable) => {
48
- editable.set(otherAdmin.id, "admin", "trusting");
49
- expect(editable.get(otherAdmin.id)).toEqual("admin");
47
+ group = group.mutate((mutable) => {
48
+ mutable.set(otherAdmin.id, "admin", "trusting");
49
+ expect(mutable.get(otherAdmin.id)).toEqual("admin");
50
50
  });
51
51
 
52
- content = expectGroupContent(group.getCurrentContent());
53
-
54
- if (content.type !== "comap") {
52
+ if (group.type !== "comap") {
55
53
  throw new Error("Expected map");
56
54
  }
57
55
 
58
- expect(content.get(otherAdmin.id)).toEqual("admin");
59
- return { group, admin, otherAdmin, node };
56
+ expect(group.get(otherAdmin.id)).toEqual("admin");
57
+ return { groupCore, admin, otherAdmin, node };
60
58
  }
61
59
 
62
60
  export function newGroupHighLevel() {
@@ -71,11 +69,11 @@ export function newGroupHighLevel() {
71
69
  }
72
70
 
73
71
  export function groupWithTwoAdminsHighLevel() {
74
- const { admin, node, group } = newGroupHighLevel();
72
+ let { admin, node, group } = newGroupHighLevel();
75
73
 
76
74
  const otherAdmin = node.createAccount("otherAdmin");
77
75
 
78
- group.addMember(otherAdmin.id, "admin");
76
+ group = group.addMember(otherAdmin.id, "admin");
79
77
 
80
78
  return { admin, node, group, otherAdmin };
81
79
  }
package/dist/account.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import { CoValueHeader } from "./coValueCore.js";
2
- import { CoID } from "./coValue.js";
3
- import { AgentSecret, SealerID, SealerSecret, SignerID, SignerSecret } from "./crypto.js";
4
- import { AgentID } from "./ids.js";
5
- import { CoMap } from "./coValues/coMap.js";
6
- import { LocalNode } from "./localNode.js";
7
- import { Group, GroupContent } from "./group.js";
8
- export declare function accountHeaderForInitialAgentSecret(agentSecret: AgentSecret): CoValueHeader;
9
- export declare class AccountGroup extends Group {
10
- get id(): AccountID;
11
- getCurrentAgentID(): AgentID;
12
- }
13
- export interface GeneralizedControlledAccount {
14
- id: AccountID | AgentID;
15
- agentSecret: AgentSecret;
16
- currentAgentID: () => AgentID;
17
- currentSignerID: () => SignerID;
18
- currentSignerSecret: () => SignerSecret;
19
- currentSealerID: () => SealerID;
20
- currentSealerSecret: () => SealerSecret;
21
- }
22
- /** @hidden */
23
- export declare class ControlledAccount extends AccountGroup implements GeneralizedControlledAccount {
24
- agentSecret: AgentSecret;
25
- constructor(agentSecret: AgentSecret, groupMap: CoMap<AccountContent, AccountMeta>, node: LocalNode);
26
- currentAgentID(): AgentID;
27
- currentSignerID(): SignerID;
28
- currentSignerSecret(): SignerSecret;
29
- currentSealerID(): SealerID;
30
- currentSealerSecret(): SealerSecret;
31
- }
32
- /** @hidden */
33
- export declare class AnonymousControlledAccount implements GeneralizedControlledAccount {
34
- agentSecret: AgentSecret;
35
- constructor(agentSecret: AgentSecret);
36
- get id(): AgentID;
37
- currentAgentID(): AgentID;
38
- currentSignerID(): SignerID;
39
- currentSignerSecret(): SignerSecret;
40
- currentSealerID(): SealerID;
41
- currentSealerSecret(): SealerSecret;
42
- }
43
- export type AccountContent = {
44
- profile: Profile;
45
- } & GroupContent;
46
- export type AccountMeta = {
47
- type: "account";
48
- };
49
- export type Account = CoMap<AccountContent, AccountMeta>;
50
- export type AccountID = CoID<Account>;
51
- export declare function isAccountID(id: AccountID | AgentID): id is AccountID;
52
- export type ProfileContent = {
53
- name: string;
54
- };
55
- export type ProfileMeta = {
56
- type: "profile";
57
- };
58
- export type Profile = CoMap<ProfileContent, ProfileMeta>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAEA,OAAO,EAMH,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACvB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,KAAK,EAAgB,MAAM,YAAY,CAAC;AAEjD,MAAM,UAAU,kCAAkC,CAC9C,WAAwB;IAExB,MAAM,KAAK,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACtC,OAAO;QACH,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE;QAC/C,IAAI,EAAE;YACF,IAAI,EAAE,SAAS;SACl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GAAG,WAAW,CAAC;IACnC,CAAC;IAED,IAAI,EAAE;QACF,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED,cAAc;QACV,OAAO,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACxC,CAAC;IAED,eAAe;QACX,OAAO,gBAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,mBAAmB;QACf,OAAO,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED,eAAe;QACX,OAAO,gBAAgB,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,mBAAmB;QACf,OAAO,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;CACJ;AAOD,MAAM,UAAU,WAAW,CAAC,EAAuB;IAC/C,OAAO,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
package/dist/group.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAGA,OAAO,EAIH,gBAAgB,EAChB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAEhB,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAsB,SAAS,EAAE,MAAM,UAAU,CAAC;AAGzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAkBrC,MAAM,UAAU,kBAAkB,CAC9B,OAAgB;IAEhB,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KACnC;IAED,OAAO,OAAiD,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;;KAoBK;AACL,MAAM,OAAO,KAAK;IAMd,gBAAgB;IACh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