cojson 0.1.8 → 0.1.10

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 (76) hide show
  1. package/dist/account.d.ts +6 -3
  2. package/dist/account.js +4 -2
  3. package/dist/account.js.map +1 -1
  4. package/dist/coValue.d.ts +44 -80
  5. package/dist/coValue.js +4 -348
  6. package/dist/coValue.js.map +1 -1
  7. package/dist/coValueCore.d.ts +84 -0
  8. package/dist/coValueCore.js +356 -0
  9. package/dist/coValueCore.js.map +1 -0
  10. package/dist/coValues/coList.d.ts +114 -0
  11. package/dist/{contentTypes → coValues}/coList.js +59 -19
  12. package/dist/coValues/coList.js.map +1 -0
  13. package/dist/{contentTypes → coValues}/coMap.d.ts +25 -7
  14. package/dist/{contentTypes → coValues}/coMap.js +34 -15
  15. package/dist/coValues/coMap.js.map +1 -0
  16. package/dist/coValues/coStream.d.ts +69 -0
  17. package/dist/coValues/coStream.js +131 -0
  18. package/dist/coValues/coStream.js.map +1 -0
  19. package/dist/coValues/static.d.ts +14 -0
  20. package/dist/coValues/static.js +20 -0
  21. package/dist/coValues/static.js.map +1 -0
  22. package/dist/group.d.ts +57 -9
  23. package/dist/group.js +94 -28
  24. package/dist/group.js.map +1 -1
  25. package/dist/index.d.ts +19 -10
  26. package/dist/index.js +7 -5
  27. package/dist/index.js.map +1 -1
  28. package/dist/node.d.ts +59 -5
  29. package/dist/node.js +36 -15
  30. package/dist/node.js.map +1 -1
  31. package/dist/permissions.d.ts +2 -2
  32. package/dist/permissions.js +1 -1
  33. package/dist/permissions.js.map +1 -1
  34. package/dist/sync.d.ts +3 -3
  35. package/dist/sync.js +2 -2
  36. package/dist/sync.js.map +1 -1
  37. package/dist/testUtils.d.ts +2 -2
  38. package/dist/testUtils.js +1 -1
  39. package/dist/testUtils.js.map +1 -1
  40. package/package.json +2 -2
  41. package/src/account.test.ts +1 -1
  42. package/src/account.ts +8 -5
  43. package/src/coValue.test.ts +335 -129
  44. package/src/coValue.ts +52 -576
  45. package/src/coValueCore.test.ts +180 -0
  46. package/src/coValueCore.ts +592 -0
  47. package/src/{contentTypes → coValues}/coList.ts +91 -42
  48. package/src/{contentTypes → coValues}/coMap.ts +40 -20
  49. package/src/coValues/coStream.ts +249 -0
  50. package/src/coValues/static.ts +31 -0
  51. package/src/group.test.ts +47 -0
  52. package/src/group.ts +120 -50
  53. package/src/index.ts +43 -28
  54. package/src/node.ts +48 -27
  55. package/src/permissions.test.ts +32 -32
  56. package/src/permissions.ts +5 -5
  57. package/src/sync.test.ts +77 -77
  58. package/src/sync.ts +5 -5
  59. package/src/testUtils.ts +1 -1
  60. package/tsconfig.json +1 -2
  61. package/dist/contentType.d.ts +0 -15
  62. package/dist/contentType.js +0 -7
  63. package/dist/contentType.js.map +0 -1
  64. package/dist/contentTypes/coList.d.ts +0 -77
  65. package/dist/contentTypes/coList.js.map +0 -1
  66. package/dist/contentTypes/coMap.js.map +0 -1
  67. package/dist/contentTypes/coStream.d.ts +0 -11
  68. package/dist/contentTypes/coStream.js +0 -16
  69. package/dist/contentTypes/coStream.js.map +0 -1
  70. package/dist/contentTypes/static.d.ts +0 -11
  71. package/dist/contentTypes/static.js +0 -14
  72. package/dist/contentTypes/static.js.map +0 -1
  73. package/src/contentType.test.ts +0 -284
  74. package/src/contentType.ts +0 -26
  75. package/src/contentTypes/coStream.ts +0 -24
  76. package/src/contentTypes/static.ts +0 -22
package/src/sync.test.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { newRandomSessionID } from "./coValue.js";
1
+ import { newRandomSessionID } from "./coValueCore.js";
2
2
  import { LocalNode } from "./node.js";
3
3
  import { Peer, PeerID, SyncMessage } from "./sync.js";
4
- import { expectMap } from "./contentType.js";
5
- import { MapOpPayload } from "./contentTypes/coMap.js";
4
+ import { expectMap } from "./coValue.js";
5
+ import { MapOpPayload } from "./coValues/coMap.js";
6
6
  import { Group } from "./group.js";
7
7
  import {
8
8
  ReadableStream,
@@ -45,7 +45,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
45
45
 
46
46
  await writer.write({
47
47
  action: "load",
48
- id: map.coValue.id,
48
+ id: map.core.id,
49
49
  header: false,
50
50
  sessions: {},
51
51
  });
@@ -58,7 +58,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
58
58
  const mapTellKnownStateMsg = await reader.read();
59
59
  expect(mapTellKnownStateMsg.value).toEqual({
60
60
  action: "known",
61
- ...map.coValue.knownState(),
61
+ ...map.core.knownState(),
62
62
  } satisfies SyncMessage);
63
63
 
64
64
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -68,13 +68,13 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
68
68
 
69
69
  expect(newContentMsg.value).toEqual({
70
70
  action: "content",
71
- id: map.coValue.id,
71
+ id: map.core.id,
72
72
  header: {
73
73
  type: "comap",
74
74
  ruleset: { type: "ownedByGroup", group: group.id },
75
75
  meta: null,
76
- createdAt: map.coValue.header.createdAt,
77
- uniqueness: map.coValue.header.uniqueness,
76
+ createdAt: map.core.header.createdAt,
77
+ uniqueness: map.core.header.uniqueness,
78
78
  },
79
79
  new: {
80
80
  [node.currentSessionID]: {
@@ -82,7 +82,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
82
82
  newTransactions: [
83
83
  {
84
84
  privacy: "trusting" as const,
85
- madeAt: map.coValue.sessions[node.currentSessionID]!
85
+ madeAt: map.core.sessions[node.currentSessionID]!
86
86
  .transactions[0]!.madeAt,
87
87
  changes: [
88
88
  {
@@ -94,7 +94,7 @@ test("Node replies with initial tx and header to empty subscribe", async () => {
94
94
  },
95
95
  ],
96
96
  lastSignature:
97
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
97
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
98
98
  },
99
99
  },
100
100
  } satisfies SyncMessage);
@@ -127,7 +127,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
127
127
 
128
128
  await writer.write({
129
129
  action: "load",
130
- id: map.coValue.id,
130
+ id: map.core.id,
131
131
  header: true,
132
132
  sessions: {
133
133
  [node.currentSessionID]: 1,
@@ -142,7 +142,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
142
142
  const mapTellKnownStateMsg = await reader.read();
143
143
  expect(mapTellKnownStateMsg.value).toEqual({
144
144
  action: "known",
145
- ...map.coValue.knownState(),
145
+ ...map.core.knownState(),
146
146
  } satisfies SyncMessage);
147
147
 
148
148
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -152,7 +152,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
152
152
 
153
153
  expect(mapNewContentMsg.value).toEqual({
154
154
  action: "content",
155
- id: map.coValue.id,
155
+ id: map.core.id,
156
156
  header: undefined,
157
157
  new: {
158
158
  [node.currentSessionID]: {
@@ -160,7 +160,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
160
160
  newTransactions: [
161
161
  {
162
162
  privacy: "trusting" as const,
163
- madeAt: map.coValue.sessions[node.currentSessionID]!
163
+ madeAt: map.core.sessions[node.currentSessionID]!
164
164
  .transactions[1]!.madeAt,
165
165
  changes: [
166
166
  {
@@ -172,7 +172,7 @@ test("Node replies with only new tx to subscribe with some known state", async (
172
172
  },
173
173
  ],
174
174
  lastSignature:
175
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
175
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
176
176
  },
177
177
  },
178
178
  } satisfies SyncMessage);
@@ -204,7 +204,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
204
204
 
205
205
  await writer.write({
206
206
  action: "load",
207
- id: map.coValue.id,
207
+ id: map.core.id,
208
208
  header: false,
209
209
  sessions: {
210
210
  [node.currentSessionID]: 0,
@@ -219,7 +219,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
219
219
  const mapTellKnownStateMsg = await reader.read();
220
220
  expect(mapTellKnownStateMsg.value).toEqual({
221
221
  action: "known",
222
- ...map.coValue.knownState(),
222
+ ...map.core.knownState(),
223
223
  } satisfies SyncMessage);
224
224
 
225
225
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -229,8 +229,8 @@ test("After subscribing, node sends own known state and new txs to peer", async
229
229
 
230
230
  expect(mapNewContentHeaderOnlyMsg.value).toEqual({
231
231
  action: "content",
232
- id: map.coValue.id,
233
- header: map.coValue.header,
232
+ id: map.core.id,
233
+ header: map.core.header,
234
234
  new: {},
235
235
  } satisfies SyncMessage);
236
236
 
@@ -242,14 +242,14 @@ test("After subscribing, node sends own known state and new txs to peer", async
242
242
 
243
243
  expect(mapEditMsg1.value).toEqual({
244
244
  action: "content",
245
- id: map.coValue.id,
245
+ id: map.core.id,
246
246
  new: {
247
247
  [node.currentSessionID]: {
248
248
  after: 0,
249
249
  newTransactions: [
250
250
  {
251
251
  privacy: "trusting" as const,
252
- madeAt: map.coValue.sessions[node.currentSessionID]!
252
+ madeAt: map.core.sessions[node.currentSessionID]!
253
253
  .transactions[0]!.madeAt,
254
254
  changes: [
255
255
  {
@@ -261,7 +261,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
261
261
  },
262
262
  ],
263
263
  lastSignature:
264
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
264
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
265
265
  },
266
266
  },
267
267
  } satisfies SyncMessage);
@@ -274,14 +274,14 @@ test("After subscribing, node sends own known state and new txs to peer", async
274
274
 
275
275
  expect(mapEditMsg2.value).toEqual({
276
276
  action: "content",
277
- id: map.coValue.id,
277
+ id: map.core.id,
278
278
  new: {
279
279
  [node.currentSessionID]: {
280
280
  after: 1,
281
281
  newTransactions: [
282
282
  {
283
283
  privacy: "trusting" as const,
284
- madeAt: map.coValue.sessions[node.currentSessionID]!
284
+ madeAt: map.core.sessions[node.currentSessionID]!
285
285
  .transactions[1]!.madeAt,
286
286
  changes: [
287
287
  {
@@ -293,7 +293,7 @@ test("After subscribing, node sends own known state and new txs to peer", async
293
293
  },
294
294
  ],
295
295
  lastSignature:
296
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
296
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
297
297
  },
298
298
  },
299
299
  } satisfies SyncMessage);
@@ -329,7 +329,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
329
329
 
330
330
  await writer.write({
331
331
  action: "known",
332
- id: map.coValue.id,
332
+ id: map.core.id,
333
333
  header: false,
334
334
  sessions: {
335
335
  [node.currentSessionID]: 0,
@@ -342,7 +342,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
342
342
  const mapTellKnownStateMsg = await reader.read();
343
343
  expect(mapTellKnownStateMsg.value).toEqual({
344
344
  action: "known",
345
- ...map.coValue.knownState(),
345
+ ...map.core.knownState(),
346
346
  } satisfies SyncMessage);
347
347
 
348
348
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -352,15 +352,15 @@ test("Client replies with known new content to tellKnownState from server", asyn
352
352
 
353
353
  expect(mapNewContentMsg.value).toEqual({
354
354
  action: "content",
355
- id: map.coValue.id,
356
- header: map.coValue.header,
355
+ id: map.core.id,
356
+ header: map.core.header,
357
357
  new: {
358
358
  [node.currentSessionID]: {
359
359
  after: 0,
360
360
  newTransactions: [
361
361
  {
362
362
  privacy: "trusting" as const,
363
- madeAt: map.coValue.sessions[node.currentSessionID]!
363
+ madeAt: map.core.sessions[node.currentSessionID]!
364
364
  .transactions[0]!.madeAt,
365
365
  changes: [
366
366
  {
@@ -372,7 +372,7 @@ test("Client replies with known new content to tellKnownState from server", asyn
372
372
  },
373
373
  ],
374
374
  lastSignature:
375
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
375
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
376
376
  },
377
377
  },
378
378
  } satisfies SyncMessage);
@@ -400,7 +400,7 @@ test("No matter the optimistic known state, node respects invalid known state me
400
400
 
401
401
  await writer.write({
402
402
  action: "load",
403
- id: map.coValue.id,
403
+ id: map.core.id,
404
404
  header: false,
405
405
  sessions: {
406
406
  [node.currentSessionID]: 0,
@@ -415,7 +415,7 @@ test("No matter the optimistic known state, node respects invalid known state me
415
415
  const mapTellKnownStateMsg = await reader.read();
416
416
  expect(mapTellKnownStateMsg.value).toEqual({
417
417
  action: "known",
418
- ...map.coValue.knownState(),
418
+ ...map.core.knownState(),
419
419
  } satisfies SyncMessage);
420
420
 
421
421
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -425,8 +425,8 @@ test("No matter the optimistic known state, node respects invalid known state me
425
425
 
426
426
  expect(mapNewContentHeaderOnlyMsg.value).toEqual({
427
427
  action: "content",
428
- id: map.coValue.id,
429
- header: map.coValue.header,
428
+ id: map.core.id,
429
+ header: map.core.header,
430
430
  new: {},
431
431
  } satisfies SyncMessage);
432
432
 
@@ -444,7 +444,7 @@ test("No matter the optimistic known state, node respects invalid known state me
444
444
  await writer.write({
445
445
  action: "known",
446
446
  isCorrection: true,
447
- id: map.coValue.id,
447
+ id: map.core.id,
448
448
  header: true,
449
449
  sessions: {
450
450
  [node.currentSessionID]: 1,
@@ -455,7 +455,7 @@ test("No matter the optimistic known state, node respects invalid known state me
455
455
 
456
456
  expect(newContentAfterWrongAssumedState.value).toEqual({
457
457
  action: "content",
458
- id: map.coValue.id,
458
+ id: map.core.id,
459
459
  header: undefined,
460
460
  new: {
461
461
  [node.currentSessionID]: {
@@ -463,7 +463,7 @@ test("No matter the optimistic known state, node respects invalid known state me
463
463
  newTransactions: [
464
464
  {
465
465
  privacy: "trusting" as const,
466
- madeAt: map.coValue.sessions[node.currentSessionID]!
466
+ madeAt: map.core.sessions[node.currentSessionID]!
467
467
  .transactions[1]!.madeAt,
468
468
  changes: [
469
469
  {
@@ -475,7 +475,7 @@ test("No matter the optimistic known state, node respects invalid known state me
475
475
  },
476
476
  ],
477
477
  lastSignature:
478
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
478
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
479
479
  },
480
480
  },
481
481
  } satisfies SyncMessage);
@@ -535,14 +535,14 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
535
535
  // });
536
536
  expect((await reader.read()).value).toMatchObject({
537
537
  action: "load",
538
- id: group.groupMap.coValue.id,
538
+ id: group.underlyingMap.core.id,
539
539
  });
540
540
 
541
541
  const mapSubscribeMsg = await reader.read();
542
542
 
543
543
  expect(mapSubscribeMsg.value).toEqual({
544
544
  action: "load",
545
- id: map.coValue.id,
545
+ id: map.core.id,
546
546
  header: true,
547
547
  sessions: {},
548
548
  } satisfies SyncMessage);
@@ -558,15 +558,15 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
558
558
 
559
559
  expect(mapNewContentMsg.value).toEqual({
560
560
  action: "content",
561
- id: map.coValue.id,
562
- header: map.coValue.header,
561
+ id: map.core.id,
562
+ header: map.core.header,
563
563
  new: {
564
564
  [node.currentSessionID]: {
565
565
  after: 0,
566
566
  newTransactions: [
567
567
  {
568
568
  privacy: "trusting" as const,
569
- madeAt: map.coValue.sessions[node.currentSessionID]!
569
+ madeAt: map.core.sessions[node.currentSessionID]!
570
570
  .transactions[0]!.madeAt,
571
571
  changes: [
572
572
  {
@@ -578,7 +578,7 @@ test("If we add a server peer, all updates to all coValues are sent to it, even
578
578
  },
579
579
  ],
580
580
  lastSignature:
581
- map.coValue.sessions[node.currentSessionID]!.lastSignature!,
581
+ map.core.sessions[node.currentSessionID]!.lastSignature!,
582
582
  },
583
583
  },
584
584
  } satisfies SyncMessage);
@@ -607,7 +607,7 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
607
607
  // });
608
608
  expect((await reader.read()).value).toMatchObject({
609
609
  action: "load",
610
- id: group.groupMap.coValue.id,
610
+ id: group.underlyingMap.core.id,
611
611
  });
612
612
 
613
613
  const map = group.createMap();
@@ -616,7 +616,7 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
616
616
 
617
617
  expect(mapSubscribeMsg.value).toEqual({
618
618
  action: "load",
619
- ...map.coValue.knownState(),
619
+ ...map.core.knownState(),
620
620
  } satisfies SyncMessage);
621
621
 
622
622
  // expect((await reader.read()).value).toMatchObject(admContEx(adminID));
@@ -626,8 +626,8 @@ test("If we add a server peer, newly created coValues are auto-subscribed to", a
626
626
 
627
627
  expect(mapContentMsg.value).toEqual({
628
628
  action: "content",
629
- id: map.coValue.id,
630
- header: map.coValue.header,
629
+ id: map.core.id,
630
+ header: map.core.header,
631
631
  new: {},
632
632
  } satisfies SyncMessage);
633
633
  });
@@ -661,14 +661,14 @@ test("When we connect a new server peer, we try to sync all existing coValues to
661
661
 
662
662
  expect(groupSubscribeMessage.value).toEqual({
663
663
  action: "load",
664
- ...group.groupMap.coValue.knownState(),
664
+ ...group.underlyingMap.core.knownState(),
665
665
  } satisfies SyncMessage);
666
666
 
667
667
  const secondMessage = await reader.read();
668
668
 
669
669
  expect(secondMessage.value).toEqual({
670
670
  action: "load",
671
- ...map.coValue.knownState(),
671
+ ...map.core.knownState(),
672
672
  } satisfies SyncMessage);
673
673
  });
674
674
 
@@ -694,7 +694,7 @@ test("When receiving a subscribe with a known state that is ahead of our own, pe
694
694
 
695
695
  await writer.write({
696
696
  action: "load",
697
- id: map.coValue.id,
697
+ id: map.core.id,
698
698
  header: true,
699
699
  sessions: {
700
700
  [node.currentSessionID]: 1,
@@ -709,7 +709,7 @@ test("When receiving a subscribe with a known state that is ahead of our own, pe
709
709
 
710
710
  expect(mapTellKnownState.value).toEqual({
711
711
  action: "known",
712
- ...map.coValue.knownState(),
712
+ ...map.core.knownState(),
713
713
  } satisfies SyncMessage);
714
714
  });
715
715
 
@@ -757,7 +757,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
757
757
  const groupSubscribeMsg = await from1.read();
758
758
  expect(groupSubscribeMsg.value).toMatchObject({
759
759
  action: "load",
760
- id: group.groupMap.coValue.id,
760
+ id: group.underlyingMap.core.id,
761
761
  });
762
762
 
763
763
  await to2.write(adminSubscribeMessage.value!);
@@ -771,7 +771,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
771
771
 
772
772
  expect(
773
773
  node2.sync.peers["test1"]!.optimisticKnownStates[
774
- group.groupMap.coValue.id
774
+ group.underlyingMap.core.id
775
775
  ]
776
776
  ).toBeDefined();
777
777
 
@@ -792,14 +792,14 @@ test.skip("When replaying creation and transactions of a coValue as new content,
792
792
  const mapSubscriptionMsg = await from1.read();
793
793
  expect(mapSubscriptionMsg.value).toMatchObject({
794
794
  action: "load",
795
- id: map.coValue.id,
795
+ id: map.core.id,
796
796
  });
797
797
 
798
798
  const mapNewContentMsg = await from1.read();
799
799
  expect(mapNewContentMsg.value).toEqual({
800
800
  action: "content",
801
- id: map.coValue.id,
802
- header: map.coValue.header,
801
+ id: map.core.id,
802
+ header: map.core.header,
803
803
  new: {},
804
804
  } satisfies SyncMessage);
805
805
 
@@ -808,12 +808,12 @@ test.skip("When replaying creation and transactions of a coValue as new content,
808
808
  const mapTellKnownStateMsg = await from2.read();
809
809
  expect(mapTellKnownStateMsg.value).toEqual({
810
810
  action: "known",
811
- id: map.coValue.id,
811
+ id: map.core.id,
812
812
  header: false,
813
813
  sessions: {},
814
814
  } satisfies SyncMessage);
815
815
 
816
- expect(node2.coValues[map.coValue.id]?.state).toEqual("loading");
816
+ expect(node2.coValues[map.core.id]?.state).toEqual("loading");
817
817
 
818
818
  await to2.write(mapNewContentMsg.value!);
819
819
 
@@ -829,7 +829,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
829
829
 
830
830
  expect(
831
831
  expectMap(
832
- node2.expectCoValueLoaded(map.coValue.id).getCurrentContent()
832
+ node2.expectCoValueLoaded(map.core.id).getCurrentContent()
833
833
  ).get("hello")
834
834
  ).toEqual("world");
835
835
  });
@@ -854,11 +854,11 @@ test.skip("When loading a coValue on one node, the server node it is requested f
854
854
  node1.sync.addPeer(node2asPeer);
855
855
  node2.sync.addPeer(node1asPeer);
856
856
 
857
- await node2.loadCoValue(map.coValue.id);
857
+ await node2.loadCoValue(map.core.id);
858
858
 
859
859
  expect(
860
860
  expectMap(
861
- node2.expectCoValueLoaded(map.coValue.id).getCurrentContent()
861
+ node2.expectCoValueLoaded(map.core.id).getCurrentContent()
862
862
  ).get("hello")
863
863
  ).toEqual("world");
864
864
  });
@@ -898,7 +898,7 @@ test("Can sync a coValue through a server to another client", async () => {
898
898
  client2.sync.addPeer(serverAsOtherPeer);
899
899
  server.sync.addPeer(client2AsPeer);
900
900
 
901
- const mapOnClient2 = await client2.loadCoValue(map.coValue.id);
901
+ const mapOnClient2 = await client2.loadCoValue(map.core.id);
902
902
 
903
903
  expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
904
904
  "world"
@@ -941,7 +941,7 @@ test("Can sync a coValue with private transactions through a server to another c
941
941
  client2.sync.addPeer(serverAsOtherPeer);
942
942
  server.sync.addPeer(client2AsPeer);
943
943
 
944
- const mapOnClient2 = await client2.loadCoValue(map.coValue.id);
944
+ const mapOnClient2 = await client2.loadCoValue(map.core.id);
945
945
 
946
946
  expect(expectMap(mapOnClient2.getCurrentContent()).get("hello")).toEqual(
947
947
  "world"
@@ -971,7 +971,7 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
971
971
  // });
972
972
  expect((await reader.read()).value).toMatchObject({
973
973
  action: "load",
974
- id: group.groupMap.coValue.id,
974
+ id: group.underlyingMap.core.id,
975
975
  });
976
976
 
977
977
  const map = group.createMap();
@@ -980,7 +980,7 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
980
980
 
981
981
  expect(mapSubscribeMsg.value).toEqual({
982
982
  action: "load",
983
- ...map.coValue.knownState(),
983
+ ...map.core.knownState(),
984
984
  } satisfies SyncMessage);
985
985
 
986
986
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -990,8 +990,8 @@ test("When a peer's incoming/readable stream closes, we remove the peer", async
990
990
 
991
991
  expect(mapContentMsg.value).toEqual({
992
992
  action: "content",
993
- id: map.coValue.id,
994
- header: map.coValue.header,
993
+ id: map.core.id,
994
+ header: map.core.header,
995
995
  new: {},
996
996
  } satisfies SyncMessage);
997
997
 
@@ -1025,7 +1025,7 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
1025
1025
  // });
1026
1026
  expect((await reader.read()).value).toMatchObject({
1027
1027
  action: "load",
1028
- id: group.groupMap.coValue.id,
1028
+ id: group.underlyingMap.core.id,
1029
1029
  });
1030
1030
 
1031
1031
  const map = group.createMap();
@@ -1034,7 +1034,7 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
1034
1034
 
1035
1035
  expect(mapSubscribeMsg.value).toEqual({
1036
1036
  action: "load",
1037
- ...map.coValue.knownState(),
1037
+ ...map.core.knownState(),
1038
1038
  } satisfies SyncMessage);
1039
1039
 
1040
1040
  // expect((await reader.read()).value).toMatchObject(admContEx(admin.id));
@@ -1044,8 +1044,8 @@ test("When a peer's outgoing/writable stream closes, we remove the peer", async
1044
1044
 
1045
1045
  expect(mapContentMsg.value).toEqual({
1046
1046
  action: "content",
1047
- id: map.coValue.id,
1048
- header: map.coValue.header,
1047
+ id: map.core.id,
1048
+ header: map.core.header,
1049
1049
  new: {},
1050
1050
  } satisfies SyncMessage);
1051
1051
 
@@ -1083,9 +1083,9 @@ test("If we start loading a coValue before connecting to a peer that has it, it
1083
1083
 
1084
1084
  node1.sync.addPeer(node2asPeer);
1085
1085
 
1086
- const mapOnNode2Promise = node2.loadCoValue(map.coValue.id);
1086
+ const mapOnNode2Promise = node2.loadCoValue(map.core.id);
1087
1087
 
1088
- expect(node2.coValues[map.coValue.id]?.state).toEqual("loading");
1088
+ expect(node2.coValues[map.core.id]?.state).toEqual("loading");
1089
1089
 
1090
1090
  node2.sync.addPeer(node1asPeer);
1091
1091
 
@@ -1099,7 +1099,7 @@ test("If we start loading a coValue before connecting to a peer that has it, it
1099
1099
  function groupContentEx(group: Group) {
1100
1100
  return {
1101
1101
  action: "content",
1102
- id: group.groupMap.coValue.id,
1102
+ id: group.underlyingMap.core.id,
1103
1103
  };
1104
1104
  }
1105
1105
 
@@ -1113,7 +1113,7 @@ function admContEx(adminID: AccountID) {
1113
1113
  function groupStateEx(group: Group) {
1114
1114
  return {
1115
1115
  action: "known",
1116
- id: group.groupMap.coValue.id,
1116
+ id: group.underlyingMap.core.id,
1117
1117
  };
1118
1118
  }
1119
1119
 
package/src/sync.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Signature } from "./crypto.js";
2
- import { CoValueHeader, Transaction } from "./coValue.js";
3
- import { CoValue } from "./coValue.js";
2
+ import { CoValueHeader, Transaction } from "./coValueCore.js";
3
+ import { CoValueCore } from "./coValueCore.js";
4
4
  import { LocalNode } from "./node.js";
5
5
  import { newLoadingState } from "./node.js";
6
6
  import {
@@ -393,7 +393,7 @@ export class SyncManager {
393
393
  );
394
394
  }
395
395
 
396
- let resolveAfterDone: ((coValue: CoValue) => void) | undefined;
396
+ let resolveAfterDone: ((coValue: CoValueCore) => void) | undefined;
397
397
 
398
398
  const peerOptimisticKnownState = peer.optimisticKnownStates[msg.id];
399
399
 
@@ -410,7 +410,7 @@ export class SyncManager {
410
410
 
411
411
  peerOptimisticKnownState.header = true;
412
412
 
413
- const coValue = new CoValue(msg.header, this.local);
413
+ const coValue = new CoValueCore(msg.header, this.local);
414
414
 
415
415
  resolveAfterDone = entry.resolve;
416
416
 
@@ -496,7 +496,7 @@ export class SyncManager {
496
496
  throw new Error("Method not implemented.");
497
497
  }
498
498
 
499
- async syncCoValue(coValue: CoValue) {
499
+ async syncCoValue(coValue: CoValueCore) {
500
500
  for (const peer of Object.values(this.peers)) {
501
501
  const optimisticKnownState = peer.optimisticKnownStates[coValue.id];
502
502
 
package/src/testUtils.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AgentSecret, createdNowUnique, getAgentID, newRandomAgentSecret } from "./crypto.js";
2
- import { newRandomSessionID } from "./coValue.js";
2
+ import { newRandomSessionID } from "./coValueCore.js";
3
3
  import { LocalNode } from "./node.js";
4
4
  import { expectGroupContent } from "./group.js";
5
5
  import { AnonymousControlledAccount } from "./account.js";
package/tsconfig.json CHANGED
@@ -9,8 +9,7 @@
9
9
  "skipLibCheck": true,
10
10
  "forceConsistentCasingInFileNames": true,
11
11
  "noUncheckedIndexedAccess": true,
12
- "esModuleInterop": true,
13
- "stripInternal": true
12
+ "esModuleInterop": true
14
13
  },
15
14
  "include": ["./src/**/*"],
16
15
  "exclude": ["./src/**/*.test.*"],
@@ -1,15 +0,0 @@
1
- import { JsonObject, JsonValue } from "./jsonValue.js";
2
- import { RawCoID } from "./ids.js";
3
- import { CoMap } from "./contentTypes/coMap.js";
4
- import { CoStream } from "./contentTypes/coStream.js";
5
- import { Static } from "./contentTypes/static.js";
6
- import { CoList } from "./contentTypes/coList.js";
7
- export type CoID<T extends ContentType> = RawCoID & {
8
- readonly __type: T;
9
- };
10
- export type ContentType = CoMap<{
11
- [key: string]: JsonValue;
12
- }, JsonObject | null> | CoList<JsonValue, JsonObject | null> | CoStream<JsonValue, JsonObject | null> | Static<JsonObject>;
13
- export declare function expectMap(content: ContentType): CoMap<{
14
- [key: string]: string;
15
- }, JsonObject | null>;
@@ -1,7 +0,0 @@
1
- export function expectMap(content) {
2
- if (content.type !== "comap") {
3
- throw new Error("Expected map");
4
- }
5
- return content;
6
- }
7
- //# sourceMappingURL=contentType.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contentType.js","sourceRoot":"","sources":["../src/contentType.ts"],"names":[],"mappings":"AAiBA,MAAM,UAAU,SAAS,CACrB,OAAoB;IAEpB,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KACnC;IAED,OAAO,OAA8D,CAAC;AAC1E,CAAC"}