cojson 0.20.10 → 0.20.12
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -0
- package/dist/OngoingStorageReconciliationTracker.d.ts +16 -0
- package/dist/OngoingStorageReconciliationTracker.d.ts.map +1 -0
- package/dist/OngoingStorageReconciliationTracker.js +75 -0
- package/dist/OngoingStorageReconciliationTracker.js.map +1 -0
- package/dist/StorageReconciliationAckTracker.d.ts +2 -2
- package/dist/StorageReconciliationAckTracker.d.ts.map +1 -1
- package/dist/StorageReconciliationAckTracker.js +2 -2
- package/dist/StorageReconciliationAckTracker.js.map +1 -1
- package/dist/sync.d.ts +11 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +42 -10
- package/dist/sync.js.map +1 -1
- package/dist/tests/OngoingStorageReconciliationTracker.test.d.ts +2 -0
- package/dist/tests/OngoingStorageReconciliationTracker.test.d.ts.map +1 -0
- package/dist/tests/OngoingStorageReconciliationTracker.test.js +60 -0
- package/dist/tests/OngoingStorageReconciliationTracker.test.js.map +1 -0
- package/dist/tests/StorageReconciliationAckTracker.test.js +7 -7
- package/dist/tests/StorageReconciliationAckTracker.test.js.map +1 -1
- package/dist/tests/sync.storageReconciliation.test.js +7 -6
- package/dist/tests/sync.storageReconciliation.test.js.map +1 -1
- package/package.json +4 -4
- package/src/OngoingStorageReconciliationTracker.ts +97 -0
- package/src/StorageReconciliationAckTracker.ts +2 -2
- package/src/sync.ts +61 -13
- package/src/tests/OngoingStorageReconciliationTracker.test.ts +85 -0
- package/src/tests/StorageReconciliationAckTracker.test.ts +7 -7
- package/src/tests/sync.storageReconciliation.test.ts +8 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test, vi } from "vitest";
|
|
2
2
|
import { PeerState } from "../PeerState.js";
|
|
3
|
-
import {
|
|
3
|
+
import { StorageReconciliationServerAckTracker } from "../StorageReconciliationAckTracker.js";
|
|
4
4
|
import { ConnectedPeerChannel } from "../streamUtils.js";
|
|
5
5
|
import { Peer } from "../sync.js";
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ function createPeerState(id = "peer-1"): PeerState {
|
|
|
18
18
|
|
|
19
19
|
describe("StorageReconciliationAckTracker", () => {
|
|
20
20
|
test("tracks pending acks and returns next offset on ack", () => {
|
|
21
|
-
const tracker = new
|
|
21
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
22
22
|
|
|
23
23
|
tracker.trackBatch("batch-1", "peer-1", 100);
|
|
24
24
|
|
|
@@ -31,7 +31,7 @@ describe("StorageReconciliationAckTracker", () => {
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
test("invokes registered callback when ack is received", () => {
|
|
34
|
-
const tracker = new
|
|
34
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
35
35
|
const peer = createPeerState("peer-1");
|
|
36
36
|
const onAck = vi.fn();
|
|
37
37
|
|
|
@@ -46,7 +46,7 @@ describe("StorageReconciliationAckTracker", () => {
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
test("invokes callback only once even if peer closes after ack", () => {
|
|
49
|
-
const tracker = new
|
|
49
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
50
50
|
const peer = createPeerState("peer-1");
|
|
51
51
|
const onAck = vi.fn();
|
|
52
52
|
|
|
@@ -59,7 +59,7 @@ describe("StorageReconciliationAckTracker", () => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test("invokes all listeners registered for a batch", () => {
|
|
62
|
-
const tracker = new
|
|
62
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
63
63
|
const peer = createPeerState("peer-1");
|
|
64
64
|
const first = vi.fn();
|
|
65
65
|
const second = vi.fn();
|
|
@@ -74,7 +74,7 @@ describe("StorageReconciliationAckTracker", () => {
|
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
test("calls callback immediately when batch is not pending", () => {
|
|
77
|
-
const tracker = new
|
|
77
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
78
78
|
const peer = createPeerState("peer-1");
|
|
79
79
|
const onAck = vi.fn();
|
|
80
80
|
|
|
@@ -84,7 +84,7 @@ describe("StorageReconciliationAckTracker", () => {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
test("aborts wait on peer close and clears pending ack", () => {
|
|
87
|
-
const tracker = new
|
|
87
|
+
const tracker = new StorageReconciliationServerAckTracker();
|
|
88
88
|
const peer = createPeerState("peer-1");
|
|
89
89
|
const onAck = vi.fn();
|
|
90
90
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, test
|
|
1
|
+
import { beforeEach, describe, expect, test } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
cojsonInternals,
|
|
4
4
|
LocalNode,
|
|
@@ -13,8 +13,6 @@ import {
|
|
|
13
13
|
waitFor,
|
|
14
14
|
} from "./testUtils";
|
|
15
15
|
import {
|
|
16
|
-
GARBAGE_COLLECTOR_CONFIG,
|
|
17
|
-
setGarbageCollectorMaxAge,
|
|
18
16
|
setStorageReconciliationBatchSize,
|
|
19
17
|
setStorageReconciliationInterval,
|
|
20
18
|
setStorageReconciliationLockTTL,
|
|
@@ -39,7 +37,7 @@ beforeEach(async () => {
|
|
|
39
37
|
});
|
|
40
38
|
|
|
41
39
|
describe("full storage reconciliation", () => {
|
|
42
|
-
test("startStorageReconciliation sends 'reconcile' message, server responds with '
|
|
40
|
+
test("startStorageReconciliation sends 'reconcile' message, server responds with 'load' messages for missing CoValues", async () => {
|
|
43
41
|
const client = setupTestNode();
|
|
44
42
|
const { storage } = client.addStorage();
|
|
45
43
|
|
|
@@ -78,7 +76,6 @@ describe("full storage reconciliation", () => {
|
|
|
78
76
|
"client -> server | RECONCILE",
|
|
79
77
|
"server -> client | LOAD Group sessions: empty",
|
|
80
78
|
"server -> client | LOAD Map sessions: empty",
|
|
81
|
-
"server -> client | RECONCILE_ACK",
|
|
82
79
|
"client -> storage | LOAD Group sessions: empty",
|
|
83
80
|
"storage -> client | CONTENT Group header: true new: After: 0 New: 4",
|
|
84
81
|
"client -> server | CONTENT Group header: true new: After: 0 New: 4",
|
|
@@ -89,11 +86,12 @@ describe("full storage reconciliation", () => {
|
|
|
89
86
|
"client -> server | KNOWN Map sessions: header/1",
|
|
90
87
|
"server -> client | KNOWN Group sessions: header/4",
|
|
91
88
|
"server -> client | KNOWN Map sessions: header/1",
|
|
89
|
+
"server -> client | RECONCILE_ACK",
|
|
92
90
|
]
|
|
93
91
|
`);
|
|
94
92
|
});
|
|
95
93
|
|
|
96
|
-
test("startStorageReconciliation sends 'reconcile' message, server responds with '
|
|
94
|
+
test("startStorageReconciliation sends 'reconcile' message, server responds with 'load' messages for outdated CoValues", async () => {
|
|
97
95
|
const client = setupTestNode();
|
|
98
96
|
const { storage } = client.addStorage();
|
|
99
97
|
client.connectToSyncServer({ persistent: true });
|
|
@@ -124,6 +122,7 @@ describe("full storage reconciliation", () => {
|
|
|
124
122
|
Group: group.core,
|
|
125
123
|
Map: map.core,
|
|
126
124
|
});
|
|
125
|
+
// Note: reconcile-ack is sent after all the unsynced coValues in the batch are synced
|
|
127
126
|
expect(messages).toMatchInlineSnapshot(`
|
|
128
127
|
[
|
|
129
128
|
"client -> storage | GET_KNOWN_STATE Group",
|
|
@@ -132,7 +131,6 @@ describe("full storage reconciliation", () => {
|
|
|
132
131
|
"storage -> client | GET_KNOWN_STATE_RESULT Map sessions: header/2",
|
|
133
132
|
"client -> server | RECONCILE",
|
|
134
133
|
"server -> client | LOAD Map sessions: header/1",
|
|
135
|
-
"server -> client | RECONCILE_ACK",
|
|
136
134
|
"client -> storage | GET_KNOWN_STATE Map",
|
|
137
135
|
"storage -> client | GET_KNOWN_STATE_RESULT Map sessions: header/2",
|
|
138
136
|
"client -> storage | LOAD Map sessions: empty",
|
|
@@ -143,6 +141,7 @@ describe("full storage reconciliation", () => {
|
|
|
143
141
|
"client -> server | KNOWN Map sessions: header/2",
|
|
144
142
|
"server -> client | KNOWN Group sessions: header/4",
|
|
145
143
|
"server -> client | KNOWN Map sessions: header/2",
|
|
144
|
+
"server -> client | RECONCILE_ACK",
|
|
146
145
|
]
|
|
147
146
|
`);
|
|
148
147
|
});
|
|
@@ -224,7 +223,6 @@ describe("full storage reconciliation", () => {
|
|
|
224
223
|
"client -> server | RECONCILE",
|
|
225
224
|
"server -> client | LOAD Group sessions: empty",
|
|
226
225
|
"server -> client | LOAD Map sessions: empty",
|
|
227
|
-
"server -> client | RECONCILE_ACK",
|
|
228
226
|
"client -> storage | LOAD Group sessions: empty",
|
|
229
227
|
"storage -> client | CONTENT Group header: true new: After: 0 New: 4",
|
|
230
228
|
"client -> server | CONTENT Group header: true new: After: 0 New: 4",
|
|
@@ -235,6 +233,7 @@ describe("full storage reconciliation", () => {
|
|
|
235
233
|
"client -> server | KNOWN Map sessions: header/1",
|
|
236
234
|
"server -> client | KNOWN Group sessions: header/4",
|
|
237
235
|
"server -> client | KNOWN Map sessions: header/1",
|
|
236
|
+
"server -> client | RECONCILE_ACK",
|
|
238
237
|
]
|
|
239
238
|
`);
|
|
240
239
|
});
|
|
@@ -441,7 +440,6 @@ describe("full storage reconciliation", () => {
|
|
|
441
440
|
"client -> server | RECONCILE",
|
|
442
441
|
"server -> client | LOAD Group sessions: empty",
|
|
443
442
|
"server -> client | LOAD Map sessions: empty",
|
|
444
|
-
"server -> client | RECONCILE_ACK",
|
|
445
443
|
"client -> storage | LOAD Group sessions: empty",
|
|
446
444
|
"storage -> client | CONTENT Group header: true new: After: 0 New: 4",
|
|
447
445
|
"client -> server | CONTENT Group header: true new: After: 0 New: 4",
|
|
@@ -452,6 +450,7 @@ describe("full storage reconciliation", () => {
|
|
|
452
450
|
"client -> server | KNOWN Map sessions: header/1",
|
|
453
451
|
"server -> client | KNOWN Group sessions: header/4",
|
|
454
452
|
"server -> client | KNOWN Map sessions: header/1",
|
|
453
|
+
"server -> client | RECONCILE_ACK",
|
|
455
454
|
]
|
|
456
455
|
`);
|
|
457
456
|
});
|