cojson-storage-sqlite 0.13.17 → 0.13.18
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 +12 -0
- package/dist/tests/sqlite.test.js +57 -8
- package/dist/tests/sqlite.test.js.map +1 -1
- package/package.json +3 -3
- package/src/tests/sqlite.test.ts +88 -9
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# cojson-storage-sqlite
|
|
2
2
|
|
|
3
|
+
## 0.13.18
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9089252]
|
|
8
|
+
- Updated dependencies [b470f63]
|
|
9
|
+
- Updated dependencies [8b2df0e]
|
|
10
|
+
- Updated dependencies [66373ba]
|
|
11
|
+
- Updated dependencies [f24cad1]
|
|
12
|
+
- cojson@0.13.18
|
|
13
|
+
- cojson-storage@0.13.18
|
|
14
|
+
|
|
3
15
|
## 0.13.17
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { unlinkSync } from "node:fs";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import {
|
|
5
|
+
import { LocalNode } from "cojson";
|
|
6
6
|
import { SyncManager } from "cojson-storage";
|
|
7
7
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
8
8
|
import { expect, onTestFinished, test, vi } from "vitest";
|
|
@@ -26,14 +26,14 @@ async function createSQLiteStorage(defaultDbPath) {
|
|
|
26
26
|
}
|
|
27
27
|
test("Should be able to initialize and load from empty DB", async () => {
|
|
28
28
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
29
|
-
const node = new LocalNode(
|
|
29
|
+
const node = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
30
30
|
node.syncManager.addPeer((await createSQLiteStorage()).peer);
|
|
31
31
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
32
32
|
expect(node.syncManager.peers.storage).toBeDefined();
|
|
33
33
|
});
|
|
34
34
|
test("should sync and load data from storage", async () => {
|
|
35
35
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
36
|
-
const node1 = new LocalNode(
|
|
36
|
+
const node1 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
37
37
|
const node1Sync = trackMessages(node1);
|
|
38
38
|
const { peer, dbPath } = await createSQLiteStorage();
|
|
39
39
|
node1.syncManager.addPeer(peer);
|
|
@@ -51,7 +51,7 @@ test("should sync and load data from storage", async () => {
|
|
|
51
51
|
]
|
|
52
52
|
`);
|
|
53
53
|
node1Sync.restore();
|
|
54
|
-
const node2 = new LocalNode(
|
|
54
|
+
const node2 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
55
55
|
const node2Sync = trackMessages(node2);
|
|
56
56
|
const { peer: peer2 } = await createSQLiteStorage(dbPath);
|
|
57
57
|
node2.syncManager.addPeer(peer2);
|
|
@@ -77,7 +77,7 @@ test("should sync and load data from storage", async () => {
|
|
|
77
77
|
});
|
|
78
78
|
test("should load dependencies correctly (group inheritance)", async () => {
|
|
79
79
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
80
|
-
const node1 = new LocalNode(
|
|
80
|
+
const node1 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
81
81
|
const node1Sync = trackMessages(node1);
|
|
82
82
|
const { peer, dbPath } = await createSQLiteStorage();
|
|
83
83
|
node1.syncManager.addPeer(peer);
|
|
@@ -99,7 +99,7 @@ test("should load dependencies correctly (group inheritance)", async () => {
|
|
|
99
99
|
]
|
|
100
100
|
`);
|
|
101
101
|
node1Sync.restore();
|
|
102
|
-
const node2 = new LocalNode(
|
|
102
|
+
const node2 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
103
103
|
const node2Sync = trackMessages(node2);
|
|
104
104
|
const { peer: peer2 } = await createSQLiteStorage(dbPath);
|
|
105
105
|
node2.syncManager.addPeer(peer2);
|
|
@@ -125,9 +125,58 @@ test("should load dependencies correctly (group inheritance)", async () => {
|
|
|
125
125
|
]
|
|
126
126
|
`);
|
|
127
127
|
});
|
|
128
|
+
test("should not send the same dependency value twice", async () => {
|
|
129
|
+
const agentSecret = Crypto.newRandomAgentSecret();
|
|
130
|
+
const node1 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
131
|
+
const node1Sync = trackMessages(node1);
|
|
132
|
+
const { peer, dbPath } = await createSQLiteStorage();
|
|
133
|
+
node1.syncManager.addPeer(peer);
|
|
134
|
+
const group = node1.createGroup();
|
|
135
|
+
const parentGroup = node1.createGroup();
|
|
136
|
+
group.extend(parentGroup);
|
|
137
|
+
const mapFromParent = parentGroup.createMap();
|
|
138
|
+
const map = group.createMap();
|
|
139
|
+
map.set("hello", "world");
|
|
140
|
+
mapFromParent.set("hello", "world");
|
|
141
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
142
|
+
node1Sync.restore();
|
|
143
|
+
const node2 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
144
|
+
const node2Sync = trackMessages(node2);
|
|
145
|
+
const { peer: peer2 } = await createSQLiteStorage(dbPath);
|
|
146
|
+
node2.syncManager.addPeer(peer2);
|
|
147
|
+
await node2.load(map.id);
|
|
148
|
+
await node2.load(mapFromParent.id);
|
|
149
|
+
expect(node2.expectCoValueLoaded(map.id)).toBeTruthy();
|
|
150
|
+
expect(node2.expectCoValueLoaded(mapFromParent.id)).toBeTruthy();
|
|
151
|
+
expect(node2.expectCoValueLoaded(group.id)).toBeTruthy();
|
|
152
|
+
expect(node2.expectCoValueLoaded(parentGroup.id)).toBeTruthy();
|
|
153
|
+
expect(toSimplifiedMessages({
|
|
154
|
+
Map: map.core,
|
|
155
|
+
Group: group.core,
|
|
156
|
+
ParentGroup: parentGroup.core,
|
|
157
|
+
MapFromParent: mapFromParent.core,
|
|
158
|
+
}, node2Sync.messages)).toMatchInlineSnapshot(`
|
|
159
|
+
[
|
|
160
|
+
"client -> LOAD Map sessions: empty",
|
|
161
|
+
"storage -> KNOWN ParentGroup sessions: header/4",
|
|
162
|
+
"storage -> CONTENT ParentGroup header: true new: After: 0 New: 4",
|
|
163
|
+
"storage -> KNOWN Group sessions: header/5",
|
|
164
|
+
"storage -> CONTENT Group header: true new: After: 0 New: 5",
|
|
165
|
+
"client -> KNOWN ParentGroup sessions: header/4",
|
|
166
|
+
"storage -> KNOWN Map sessions: header/1",
|
|
167
|
+
"storage -> CONTENT Map header: true new: After: 0 New: 1",
|
|
168
|
+
"client -> KNOWN Group sessions: header/5",
|
|
169
|
+
"client -> KNOWN Map sessions: header/1",
|
|
170
|
+
"client -> LOAD MapFromParent sessions: empty",
|
|
171
|
+
"storage -> KNOWN MapFromParent sessions: header/1",
|
|
172
|
+
"storage -> CONTENT MapFromParent header: true new: After: 0 New: 1",
|
|
173
|
+
"client -> KNOWN MapFromParent sessions: header/1",
|
|
174
|
+
]
|
|
175
|
+
`);
|
|
176
|
+
});
|
|
128
177
|
test("should recover from data loss", async () => {
|
|
129
178
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
130
|
-
const node1 = new LocalNode(
|
|
179
|
+
const node1 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
131
180
|
const node1Sync = trackMessages(node1);
|
|
132
181
|
const { peer, dbPath } = await createSQLiteStorage();
|
|
133
182
|
node1.syncManager.addPeer(peer);
|
|
@@ -157,7 +206,7 @@ test("should recover from data loss", async () => {
|
|
|
157
206
|
]
|
|
158
207
|
`);
|
|
159
208
|
node1Sync.restore();
|
|
160
|
-
const node2 = new LocalNode(
|
|
209
|
+
const node2 = new LocalNode(agentSecret, Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)), Crypto);
|
|
161
210
|
const node2Sync = trackMessages(node2);
|
|
162
211
|
const { peer: peer2 } = await createSQLiteStorage(dbPath);
|
|
163
212
|
node2.syncManager.addPeer(peer2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.test.js","sourceRoot":"","sources":["../../src/tests/sqlite.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sqlite.test.js","sourceRoot":"","sources":["../../src/tests/sqlite.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;AAEzC,KAAK,UAAU,mBAAmB,CAAC,aAAsB;IACvD,MAAM,MAAM,GAAG,aAAa,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,QAAQ,UAAU,EAA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,SAAS,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAEvC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE1D,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEjC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEtC,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC;QAC5B,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,CAAC;KACP,CAAC,CAAC;IAEH,MAAM,CACJ,oBAAoB,CAClB;QACE,GAAG,EAAE,GAAG,CAAC,IAAI;QACb,KAAK,EAAE,KAAK,CAAC,IAAI;KAClB,EACD,SAAS,CAAC,QAAQ,CACnB,CACF,CAAC,qBAAqB,CAAC;;;;;;;;;GASvB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cojson-storage-sqlite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.13.
|
|
4
|
+
"version": "0.13.18",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"better-sqlite3": "^11.7.0",
|
|
10
|
-
"cojson": "0.13.
|
|
11
|
-
"cojson-storage": "0.13.
|
|
10
|
+
"cojson": "0.13.18",
|
|
11
|
+
"cojson-storage": "0.13.18"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/better-sqlite3": "^7.6.12",
|
package/src/tests/sqlite.test.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { assert } from "node:console";
|
|
2
1
|
import { randomUUID } from "node:crypto";
|
|
3
2
|
import { unlinkSync } from "node:fs";
|
|
4
3
|
import { tmpdir } from "node:os";
|
|
5
4
|
import { join } from "node:path";
|
|
6
|
-
import {
|
|
5
|
+
import { LocalNode } from "cojson";
|
|
7
6
|
import { SyncManager } from "cojson-storage";
|
|
8
7
|
import { WasmCrypto } from "cojson/crypto/WasmCrypto";
|
|
9
8
|
import { expect, onTestFinished, test, vi } from "vitest";
|
|
@@ -34,7 +33,7 @@ test("Should be able to initialize and load from empty DB", async () => {
|
|
|
34
33
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
35
34
|
|
|
36
35
|
const node = new LocalNode(
|
|
37
|
-
|
|
36
|
+
agentSecret,
|
|
38
37
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
39
38
|
Crypto,
|
|
40
39
|
);
|
|
@@ -50,7 +49,7 @@ test("should sync and load data from storage", async () => {
|
|
|
50
49
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
51
50
|
|
|
52
51
|
const node1 = new LocalNode(
|
|
53
|
-
|
|
52
|
+
agentSecret,
|
|
54
53
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
55
54
|
Crypto,
|
|
56
55
|
);
|
|
@@ -87,7 +86,7 @@ test("should sync and load data from storage", async () => {
|
|
|
87
86
|
node1Sync.restore();
|
|
88
87
|
|
|
89
88
|
const node2 = new LocalNode(
|
|
90
|
-
|
|
89
|
+
agentSecret,
|
|
91
90
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
92
91
|
Crypto,
|
|
93
92
|
);
|
|
@@ -131,7 +130,7 @@ test("should load dependencies correctly (group inheritance)", async () => {
|
|
|
131
130
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
132
131
|
|
|
133
132
|
const node1 = new LocalNode(
|
|
134
|
-
|
|
133
|
+
agentSecret,
|
|
135
134
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
136
135
|
Crypto,
|
|
137
136
|
);
|
|
@@ -173,7 +172,7 @@ test("should load dependencies correctly (group inheritance)", async () => {
|
|
|
173
172
|
node1Sync.restore();
|
|
174
173
|
|
|
175
174
|
const node2 = new LocalNode(
|
|
176
|
-
|
|
175
|
+
agentSecret,
|
|
177
176
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
178
177
|
Crypto,
|
|
179
178
|
);
|
|
@@ -214,11 +213,91 @@ test("should load dependencies correctly (group inheritance)", async () => {
|
|
|
214
213
|
`);
|
|
215
214
|
});
|
|
216
215
|
|
|
216
|
+
test("should not send the same dependency value twice", async () => {
|
|
217
|
+
const agentSecret = Crypto.newRandomAgentSecret();
|
|
218
|
+
|
|
219
|
+
const node1 = new LocalNode(
|
|
220
|
+
agentSecret,
|
|
221
|
+
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
222
|
+
Crypto,
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const node1Sync = trackMessages(node1);
|
|
226
|
+
|
|
227
|
+
const { peer, dbPath } = await createSQLiteStorage();
|
|
228
|
+
|
|
229
|
+
node1.syncManager.addPeer(peer);
|
|
230
|
+
|
|
231
|
+
const group = node1.createGroup();
|
|
232
|
+
const parentGroup = node1.createGroup();
|
|
233
|
+
|
|
234
|
+
group.extend(parentGroup);
|
|
235
|
+
|
|
236
|
+
const mapFromParent = parentGroup.createMap();
|
|
237
|
+
const map = group.createMap();
|
|
238
|
+
|
|
239
|
+
map.set("hello", "world");
|
|
240
|
+
mapFromParent.set("hello", "world");
|
|
241
|
+
|
|
242
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
243
|
+
|
|
244
|
+
node1Sync.restore();
|
|
245
|
+
|
|
246
|
+
const node2 = new LocalNode(
|
|
247
|
+
agentSecret,
|
|
248
|
+
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
249
|
+
Crypto,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const node2Sync = trackMessages(node2);
|
|
253
|
+
|
|
254
|
+
const { peer: peer2 } = await createSQLiteStorage(dbPath);
|
|
255
|
+
|
|
256
|
+
node2.syncManager.addPeer(peer2);
|
|
257
|
+
|
|
258
|
+
await node2.load(map.id);
|
|
259
|
+
await node2.load(mapFromParent.id);
|
|
260
|
+
|
|
261
|
+
expect(node2.expectCoValueLoaded(map.id)).toBeTruthy();
|
|
262
|
+
expect(node2.expectCoValueLoaded(mapFromParent.id)).toBeTruthy();
|
|
263
|
+
expect(node2.expectCoValueLoaded(group.id)).toBeTruthy();
|
|
264
|
+
expect(node2.expectCoValueLoaded(parentGroup.id)).toBeTruthy();
|
|
265
|
+
|
|
266
|
+
expect(
|
|
267
|
+
toSimplifiedMessages(
|
|
268
|
+
{
|
|
269
|
+
Map: map.core,
|
|
270
|
+
Group: group.core,
|
|
271
|
+
ParentGroup: parentGroup.core,
|
|
272
|
+
MapFromParent: mapFromParent.core,
|
|
273
|
+
},
|
|
274
|
+
node2Sync.messages,
|
|
275
|
+
),
|
|
276
|
+
).toMatchInlineSnapshot(`
|
|
277
|
+
[
|
|
278
|
+
"client -> LOAD Map sessions: empty",
|
|
279
|
+
"storage -> KNOWN ParentGroup sessions: header/4",
|
|
280
|
+
"storage -> CONTENT ParentGroup header: true new: After: 0 New: 4",
|
|
281
|
+
"storage -> KNOWN Group sessions: header/5",
|
|
282
|
+
"storage -> CONTENT Group header: true new: After: 0 New: 5",
|
|
283
|
+
"client -> KNOWN ParentGroup sessions: header/4",
|
|
284
|
+
"storage -> KNOWN Map sessions: header/1",
|
|
285
|
+
"storage -> CONTENT Map header: true new: After: 0 New: 1",
|
|
286
|
+
"client -> KNOWN Group sessions: header/5",
|
|
287
|
+
"client -> KNOWN Map sessions: header/1",
|
|
288
|
+
"client -> LOAD MapFromParent sessions: empty",
|
|
289
|
+
"storage -> KNOWN MapFromParent sessions: header/1",
|
|
290
|
+
"storage -> CONTENT MapFromParent header: true new: After: 0 New: 1",
|
|
291
|
+
"client -> KNOWN MapFromParent sessions: header/1",
|
|
292
|
+
]
|
|
293
|
+
`);
|
|
294
|
+
});
|
|
295
|
+
|
|
217
296
|
test("should recover from data loss", async () => {
|
|
218
297
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
219
298
|
|
|
220
299
|
const node1 = new LocalNode(
|
|
221
|
-
|
|
300
|
+
agentSecret,
|
|
222
301
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
223
302
|
Crypto,
|
|
224
303
|
);
|
|
@@ -273,7 +352,7 @@ test("should recover from data loss", async () => {
|
|
|
273
352
|
node1Sync.restore();
|
|
274
353
|
|
|
275
354
|
const node2 = new LocalNode(
|
|
276
|
-
|
|
355
|
+
agentSecret,
|
|
277
356
|
Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret)),
|
|
278
357
|
Crypto,
|
|
279
358
|
);
|