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.
- package/dist/account.d.ts +6 -3
- package/dist/account.js +4 -2
- package/dist/account.js.map +1 -1
- package/dist/coValue.d.ts +44 -80
- package/dist/coValue.js +4 -348
- package/dist/coValue.js.map +1 -1
- package/dist/coValueCore.d.ts +84 -0
- package/dist/coValueCore.js +356 -0
- package/dist/coValueCore.js.map +1 -0
- package/dist/coValues/coList.d.ts +114 -0
- package/dist/{contentTypes → coValues}/coList.js +59 -19
- package/dist/coValues/coList.js.map +1 -0
- package/dist/{contentTypes → coValues}/coMap.d.ts +25 -7
- package/dist/{contentTypes → coValues}/coMap.js +34 -15
- package/dist/coValues/coMap.js.map +1 -0
- package/dist/coValues/coStream.d.ts +69 -0
- package/dist/coValues/coStream.js +131 -0
- package/dist/coValues/coStream.js.map +1 -0
- package/dist/coValues/static.d.ts +14 -0
- package/dist/coValues/static.js +20 -0
- package/dist/coValues/static.js.map +1 -0
- package/dist/group.d.ts +57 -9
- package/dist/group.js +94 -28
- package/dist/group.js.map +1 -1
- package/dist/index.d.ts +19 -10
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +59 -5
- package/dist/node.js +36 -15
- package/dist/node.js.map +1 -1
- package/dist/permissions.d.ts +2 -2
- package/dist/permissions.js +1 -1
- package/dist/permissions.js.map +1 -1
- package/dist/sync.d.ts +3 -3
- package/dist/sync.js +2 -2
- package/dist/sync.js.map +1 -1
- package/dist/testUtils.d.ts +2 -2
- package/dist/testUtils.js +1 -1
- package/dist/testUtils.js.map +1 -1
- package/package.json +2 -2
- package/src/account.test.ts +1 -1
- package/src/account.ts +8 -5
- package/src/coValue.test.ts +335 -129
- package/src/coValue.ts +52 -576
- package/src/coValueCore.test.ts +180 -0
- package/src/coValueCore.ts +592 -0
- package/src/{contentTypes → coValues}/coList.ts +91 -42
- package/src/{contentTypes → coValues}/coMap.ts +40 -20
- package/src/coValues/coStream.ts +249 -0
- package/src/coValues/static.ts +31 -0
- package/src/group.test.ts +47 -0
- package/src/group.ts +120 -50
- package/src/index.ts +43 -28
- package/src/node.ts +48 -27
- package/src/permissions.test.ts +32 -32
- package/src/permissions.ts +5 -5
- package/src/sync.test.ts +77 -77
- package/src/sync.ts +5 -5
- package/src/testUtils.ts +1 -1
- package/tsconfig.json +1 -2
- package/dist/contentType.d.ts +0 -15
- package/dist/contentType.js +0 -7
- package/dist/contentType.js.map +0 -1
- package/dist/contentTypes/coList.d.ts +0 -77
- package/dist/contentTypes/coList.js.map +0 -1
- package/dist/contentTypes/coMap.js.map +0 -1
- package/dist/contentTypes/coStream.d.ts +0 -11
- package/dist/contentTypes/coStream.js +0 -16
- package/dist/contentTypes/coStream.js.map +0 -1
- package/dist/contentTypes/static.d.ts +0 -11
- package/dist/contentTypes/static.js +0 -14
- package/dist/contentTypes/static.js.map +0 -1
- package/src/contentType.test.ts +0 -284
- package/src/contentType.ts +0 -26
- package/src/contentTypes/coStream.ts +0 -24
- package/src/contentTypes/static.ts +0 -22
package/src/sync.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { newRandomSessionID } from "./
|
|
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 "./
|
|
5
|
-
import { MapOpPayload } from "./
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
77
|
-
uniqueness: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
233
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
356
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
429
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
562
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
630
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
802
|
-
header: map.
|
|
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.
|
|
811
|
+
id: map.core.id,
|
|
812
812
|
header: false,
|
|
813
813
|
sessions: {},
|
|
814
814
|
} satisfies SyncMessage);
|
|
815
815
|
|
|
816
|
-
expect(node2.coValues[map.
|
|
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.
|
|
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.
|
|
857
|
+
await node2.loadCoValue(map.core.id);
|
|
858
858
|
|
|
859
859
|
expect(
|
|
860
860
|
expectMap(
|
|
861
|
-
node2.expectCoValueLoaded(map.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
994
|
-
header: map.
|
|
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.
|
|
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.
|
|
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.
|
|
1048
|
-
header: map.
|
|
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.
|
|
1086
|
+
const mapOnNode2Promise = node2.loadCoValue(map.core.id);
|
|
1087
1087
|
|
|
1088
|
-
expect(node2.coValues[map.
|
|
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.
|
|
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.
|
|
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 "./
|
|
3
|
-
import {
|
|
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:
|
|
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
|
|
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:
|
|
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 "./
|
|
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
package/dist/contentType.d.ts
DELETED
|
@@ -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>;
|
package/dist/contentType.js
DELETED
package/dist/contentType.js.map
DELETED
|
@@ -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"}
|