@tursodatabase/sync 0.2.0-pre.1 → 0.2.0-pre.11
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/README.md +1 -1
- package/dist/promise.d.ts +31 -18
- package/dist/promise.d.ts.map +1 -1
- package/dist/promise.js +73 -38
- package/dist/promise.test.js +205 -10
- package/index.js +103 -52
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ This package is the Turso embedded database library for JavaScript in Node.
|
|
|
23
23
|
- **SQLite compatible:** SQLite query language and file format support ([status](https://github.com/tursodatabase/turso/blob/main/COMPAT.md)).
|
|
24
24
|
- **In-process**: No network overhead, runs directly in your Node.js process
|
|
25
25
|
- **TypeScript support**: Full TypeScript definitions included
|
|
26
|
-
- **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows (browser is supported in the separate package `@tursodatabase/database-
|
|
26
|
+
- **Cross-platform**: Supports Linux (x86 and arm64), macOS, Windows (browser is supported in the separate package `@tursodatabase/database-wasm` package)
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
package/dist/promise.d.ts
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
|
-
import { DatabasePromise
|
|
2
|
-
import {
|
|
1
|
+
import { DatabasePromise } from "@tursodatabase/database-common";
|
|
2
|
+
import { DatabaseOpts, EncryptionOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, DatabaseStats } from "@tursodatabase/sync-common";
|
|
3
3
|
declare class Database extends DatabasePromise {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
#private;
|
|
5
|
+
constructor(opts: DatabaseOpts);
|
|
6
|
+
/**
|
|
7
|
+
* connect database and initialize it in case of clean start
|
|
8
|
+
*/
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* pull new changes from the remote database
|
|
12
|
+
* if {@link DatabaseOpts.longPollTimeoutMs} is set - then server will hold the connection open until either new changes will appear in the database or timeout occurs.
|
|
13
|
+
* @returns true if new changes were pulled from the remote
|
|
14
|
+
*/
|
|
15
|
+
pull(): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* push new local changes to the remote database
|
|
18
|
+
* if {@link DatabaseOpts.transform} is set - then provided callback will be called for every mutation before sending it to the remote
|
|
19
|
+
*/
|
|
10
20
|
push(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* checkpoint WAL for local database
|
|
23
|
+
*/
|
|
11
24
|
checkpoint(): Promise<void>;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @returns statistic of current local database
|
|
27
|
+
*/
|
|
28
|
+
stats(): Promise<DatabaseStats>;
|
|
29
|
+
/**
|
|
30
|
+
* close the database
|
|
31
|
+
*/
|
|
19
32
|
close(): Promise<void>;
|
|
20
33
|
}
|
|
21
34
|
/**
|
|
22
35
|
* Creates a new database connection asynchronously.
|
|
23
36
|
*
|
|
24
|
-
* @param {string} path - Path to the database file.
|
|
25
37
|
* @param {Object} opts - Options for database behavior.
|
|
26
38
|
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
|
27
39
|
*/
|
|
28
|
-
declare function connect(opts:
|
|
29
|
-
export { connect, Database
|
|
40
|
+
declare function connect(opts: DatabaseOpts): Promise<Database>;
|
|
41
|
+
export { connect, Database };
|
|
42
|
+
export type { DatabaseOpts, EncryptionOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult };
|
|
30
43
|
//# sourceMappingURL=promise.d.ts.map
|
package/dist/promise.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAmB,YAAY,EAAE,cAAc,EAAW,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,aAAa,EAAoB,MAAM,4BAA4B,CAAC;AAwC5M,cAAM,QAAS,SAAQ,eAAe;;gBAKtB,IAAI,EAAE,YAAY;IAmC9B;;OAEG;IACY,OAAO;IAGtB;;;;OAIG;IACG,IAAI;IAQV;;;OAGG;IACG,IAAI;IAGV;;OAEG;IACG,UAAU;IAGhB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,aAAa,CAAC;IAGrC;;OAEG;IACY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGxC;AAED;;;;;GAKG;AACH,iBAAe,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAI5D;AAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAA;AAC5B,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,CAAA"}
|
package/dist/promise.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DatabasePromise } from "@tursodatabase/database-common";
|
|
2
|
-
import { run } from "@tursodatabase/sync-common";
|
|
2
|
+
import { run, SyncEngineGuards } from "@tursodatabase/sync-common";
|
|
3
3
|
import { SyncEngine } from "#index";
|
|
4
4
|
import { promises } from "node:fs";
|
|
5
5
|
let NodeIO = {
|
|
@@ -41,62 +41,97 @@ function memoryIO() {
|
|
|
41
41
|
}
|
|
42
42
|
;
|
|
43
43
|
class Database extends DatabasePromise {
|
|
44
|
-
runOpts;
|
|
45
|
-
engine;
|
|
46
|
-
io;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
#runOpts;
|
|
45
|
+
#engine;
|
|
46
|
+
#io;
|
|
47
|
+
#guards;
|
|
48
|
+
constructor(opts) {
|
|
49
|
+
const engine = new SyncEngine({
|
|
50
|
+
path: opts.path,
|
|
51
|
+
clientName: opts.clientName,
|
|
52
|
+
useTransform: opts.transform != null,
|
|
53
|
+
protocolVersion: "v1" /* SyncEngineProtocolVersion.V1 */,
|
|
54
|
+
longPollTimeoutMs: opts.longPollTimeoutMs,
|
|
55
|
+
tracing: opts.tracing,
|
|
56
|
+
});
|
|
57
|
+
super(engine.db());
|
|
58
|
+
let headers = typeof opts.authToken === "function" ? () => ({
|
|
59
|
+
...(opts.authToken != null && { "Authorization": `Bearer ${opts.authToken()}` }),
|
|
60
|
+
...(opts.encryption != null && {
|
|
61
|
+
"x-turso-encryption-key": opts.encryption.key,
|
|
62
|
+
"x-turso-encryption-cipher": opts.encryption.cipher,
|
|
63
|
+
})
|
|
64
|
+
}) : {
|
|
65
|
+
...(opts.authToken != null && { "Authorization": `Bearer ${opts.authToken}` }),
|
|
66
|
+
...(opts.encryption != null && {
|
|
67
|
+
"x-turso-encryption-key": opts.encryption.key,
|
|
68
|
+
"x-turso-encryption-cipher": opts.encryption.cipher,
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
this.#runOpts = {
|
|
72
|
+
url: opts.url,
|
|
73
|
+
headers: headers,
|
|
74
|
+
preemptionMs: 1,
|
|
75
|
+
transform: opts.transform,
|
|
76
|
+
};
|
|
77
|
+
this.#engine = engine;
|
|
78
|
+
this.#io = this.memory ? memoryIO() : NodeIO;
|
|
79
|
+
this.#guards = new SyncEngineGuards();
|
|
52
80
|
}
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
/**
|
|
82
|
+
* connect database and initialize it in case of clean start
|
|
83
|
+
*/
|
|
84
|
+
async connect() {
|
|
85
|
+
await run(this.#runOpts, this.#io, this.#engine, this.#engine.connect());
|
|
55
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* pull new changes from the remote database
|
|
89
|
+
* if {@link DatabaseOpts.longPollTimeoutMs} is set - then server will hold the connection open until either new changes will appear in the database or timeout occurs.
|
|
90
|
+
* @returns true if new changes were pulled from the remote
|
|
91
|
+
*/
|
|
56
92
|
async pull() {
|
|
57
|
-
await run(this
|
|
93
|
+
const changes = await this.#guards.wait(async () => await run(this.#runOpts, this.#io, this.#engine, this.#engine.wait()));
|
|
94
|
+
if (changes.empty()) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
await this.#guards.apply(async () => await run(this.#runOpts, this.#io, this.#engine, this.#engine.apply(changes)));
|
|
98
|
+
return true;
|
|
58
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* push new local changes to the remote database
|
|
102
|
+
* if {@link DatabaseOpts.transform} is set - then provided callback will be called for every mutation before sending it to the remote
|
|
103
|
+
*/
|
|
59
104
|
async push() {
|
|
60
|
-
await run(this
|
|
105
|
+
await this.#guards.push(async () => await run(this.#runOpts, this.#io, this.#engine, this.#engine.push()));
|
|
61
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* checkpoint WAL for local database
|
|
109
|
+
*/
|
|
62
110
|
async checkpoint() {
|
|
63
|
-
await run(this
|
|
111
|
+
await this.#guards.checkpoint(async () => await run(this.#runOpts, this.#io, this.#engine, this.#engine.checkpoint()));
|
|
64
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* @returns statistic of current local database
|
|
115
|
+
*/
|
|
65
116
|
async stats() {
|
|
66
|
-
return (await run(this
|
|
117
|
+
return (await run(this.#runOpts, this.#io, this.#engine, this.#engine.stats()));
|
|
67
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* close the database
|
|
121
|
+
*/
|
|
68
122
|
async close() {
|
|
69
|
-
this
|
|
123
|
+
this.#engine.close();
|
|
70
124
|
}
|
|
71
125
|
}
|
|
72
126
|
/**
|
|
73
127
|
* Creates a new database connection asynchronously.
|
|
74
128
|
*
|
|
75
|
-
* @param {string} path - Path to the database file.
|
|
76
129
|
* @param {Object} opts - Options for database behavior.
|
|
77
130
|
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
|
78
131
|
*/
|
|
79
132
|
async function connect(opts) {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
tablesIgnore: opts.tablesIgnore,
|
|
84
|
-
useTransform: opts.transform != null,
|
|
85
|
-
tracing: opts.tracing,
|
|
86
|
-
protocolVersion: 1
|
|
87
|
-
});
|
|
88
|
-
const runOpts = {
|
|
89
|
-
url: opts.url,
|
|
90
|
-
headers: {
|
|
91
|
-
...(opts.authToken != null && { "Authorization": `Bearer ${opts.authToken}` }),
|
|
92
|
-
...(opts.encryptionKey != null && { "x-turso-encryption-key": opts.encryptionKey })
|
|
93
|
-
},
|
|
94
|
-
preemptionMs: 1,
|
|
95
|
-
transform: opts.transform,
|
|
96
|
-
};
|
|
97
|
-
let io = opts.path == ':memory:' ? memoryIO() : NodeIO;
|
|
98
|
-
await run(runOpts, io, engine, engine.init());
|
|
99
|
-
const nativeDb = engine.open();
|
|
100
|
-
return new Database(nativeDb, io, runOpts, engine, {});
|
|
133
|
+
const db = new Database(opts);
|
|
134
|
+
await db.connect();
|
|
135
|
+
return db;
|
|
101
136
|
}
|
|
102
137
|
export { connect, Database };
|
package/dist/promise.test.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { unlinkSync } from "node:fs";
|
|
2
2
|
import { expect, test } from 'vitest';
|
|
3
|
-
import { connect } from './promise.js';
|
|
3
|
+
import { connect, Database } from './promise.js';
|
|
4
4
|
const localeCompare = (a, b) => a.x.localeCompare(b.x);
|
|
5
|
+
function cleanup(path) {
|
|
6
|
+
unlinkSync(path);
|
|
7
|
+
unlinkSync(`${path}-wal`);
|
|
8
|
+
unlinkSync(`${path}-info`);
|
|
9
|
+
unlinkSync(`${path}-changes`);
|
|
10
|
+
try {
|
|
11
|
+
unlinkSync(`${path}-wal-revert`);
|
|
12
|
+
}
|
|
13
|
+
catch (e) { }
|
|
14
|
+
}
|
|
15
|
+
test('explicit connect', async () => {
|
|
16
|
+
const db = new Database({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
17
|
+
expect(() => db.prepare("SELECT 1")).toThrowError(/database must be connected/g);
|
|
18
|
+
await db.connect();
|
|
19
|
+
expect(await db.prepare("SELECT 1 as x").all()).toEqual([{ x: 1 }]);
|
|
20
|
+
});
|
|
5
21
|
test('select-after-push', async () => {
|
|
6
22
|
{
|
|
7
23
|
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
@@ -133,14 +149,14 @@ test('checkpoint', async () => {
|
|
|
133
149
|
await db1.checkpoint();
|
|
134
150
|
expect((await db1.stats()).mainWal).toBe(0);
|
|
135
151
|
let revertWal = (await db1.stats()).revertWal;
|
|
136
|
-
expect(revertWal).toBeLessThan(4096 * 1000 /
|
|
152
|
+
expect(revertWal).toBeLessThan(4096 * 1000 / 50);
|
|
137
153
|
for (let i = 0; i < 1000; i++) {
|
|
138
154
|
await db1.exec(`UPDATE q SET y = 'u${i}' WHERE x = 'k${i}'`);
|
|
139
155
|
}
|
|
140
156
|
await db1.checkpoint();
|
|
141
157
|
expect((await db1.stats()).revertWal).toBe(revertWal);
|
|
142
158
|
});
|
|
143
|
-
test('persistence', async () => {
|
|
159
|
+
test('persistence-push', async () => {
|
|
144
160
|
{
|
|
145
161
|
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
146
162
|
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
@@ -160,9 +176,11 @@ test('persistence', async () => {
|
|
|
160
176
|
const db2 = await connect({ path: path, url: process.env.VITE_TURSO_DB_URL });
|
|
161
177
|
await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
|
|
162
178
|
await db2.exec(`INSERT INTO q VALUES ('k4', 'v4')`);
|
|
163
|
-
const
|
|
179
|
+
const stmt = db2.prepare('SELECT * FROM q');
|
|
180
|
+
const rows = await stmt.all();
|
|
164
181
|
const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }, { x: 'k3', y: 'v3' }, { x: 'k4', y: 'v4' }];
|
|
165
182
|
expect(rows).toEqual(expected);
|
|
183
|
+
stmt.close();
|
|
166
184
|
await db2.close();
|
|
167
185
|
}
|
|
168
186
|
{
|
|
@@ -179,15 +197,192 @@ test('persistence', async () => {
|
|
|
179
197
|
}
|
|
180
198
|
}
|
|
181
199
|
finally {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
200
|
+
cleanup(path);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
test('persistence-offline', async () => {
|
|
204
|
+
{
|
|
205
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
206
|
+
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
207
|
+
await db.exec("DELETE FROM q");
|
|
208
|
+
await db.push();
|
|
209
|
+
await db.close();
|
|
210
|
+
}
|
|
211
|
+
const path = `test-${(Math.random() * 10000) | 0}.db`;
|
|
212
|
+
try {
|
|
213
|
+
{
|
|
214
|
+
const db = await connect({ path: path, url: process.env.VITE_TURSO_DB_URL });
|
|
215
|
+
await db.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
|
|
216
|
+
await db.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
|
|
217
|
+
await db.push();
|
|
218
|
+
await db.close();
|
|
219
|
+
}
|
|
220
|
+
{
|
|
221
|
+
const db = await connect({ path: path, url: "https://not-valid-url.localhost" });
|
|
222
|
+
const rows = await db.prepare("SELECT * FROM q").all();
|
|
223
|
+
const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }];
|
|
224
|
+
expect(rows.sort(localeCompare)).toEqual(expected.sort(localeCompare));
|
|
225
|
+
await db.close();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
cleanup(path);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
test('persistence-pull-push', async () => {
|
|
233
|
+
{
|
|
234
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
235
|
+
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
236
|
+
await db.exec("DELETE FROM q");
|
|
237
|
+
await db.push();
|
|
238
|
+
await db.close();
|
|
239
|
+
}
|
|
240
|
+
const path1 = `test-${(Math.random() * 10000) | 0}.db`;
|
|
241
|
+
const path2 = `test-${(Math.random() * 10000) | 0}.db`;
|
|
242
|
+
try {
|
|
243
|
+
const db1 = await connect({ path: path1, url: process.env.VITE_TURSO_DB_URL });
|
|
244
|
+
await db1.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
|
|
245
|
+
await db1.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
|
|
246
|
+
const stats1 = await db1.stats();
|
|
247
|
+
const db2 = await connect({ path: path2, url: process.env.VITE_TURSO_DB_URL });
|
|
248
|
+
await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
|
|
249
|
+
await db2.exec(`INSERT INTO q VALUES ('k4', 'v4')`);
|
|
250
|
+
await Promise.all([db1.push(), db2.push()]);
|
|
251
|
+
await Promise.all([db1.pull(), db2.pull()]);
|
|
252
|
+
const stats2 = await db1.stats();
|
|
253
|
+
console.info(stats1, stats2);
|
|
254
|
+
expect(stats1.revision).not.toBe(stats2.revision);
|
|
255
|
+
const rows1 = await db1.prepare('SELECT * FROM q').all();
|
|
256
|
+
const rows2 = await db2.prepare('SELECT * FROM q').all();
|
|
257
|
+
const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }, { x: 'k3', y: 'v3' }, { x: 'k4', y: 'v4' }];
|
|
258
|
+
expect(rows1.sort(localeCompare)).toEqual(expected.sort(localeCompare));
|
|
259
|
+
expect(rows2.sort(localeCompare)).toEqual(expected.sort(localeCompare));
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
cleanup(path1);
|
|
263
|
+
cleanup(path2);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
test('update', async () => {
|
|
267
|
+
{
|
|
268
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
|
|
269
|
+
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
270
|
+
await db.exec("DELETE FROM q");
|
|
271
|
+
await db.push();
|
|
272
|
+
await db.close();
|
|
273
|
+
}
|
|
274
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
275
|
+
await db.exec("INSERT INTO q VALUES ('1', '2')");
|
|
276
|
+
await db.push();
|
|
277
|
+
await db.exec("INSERT INTO q VALUES ('1', '2') ON CONFLICT DO UPDATE SET y = '3'");
|
|
278
|
+
await db.push();
|
|
279
|
+
});
|
|
280
|
+
test('concurrent-updates', async () => {
|
|
281
|
+
{
|
|
282
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
|
|
283
|
+
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
284
|
+
await db.exec("DELETE FROM q");
|
|
285
|
+
await db.push();
|
|
286
|
+
await db.close();
|
|
287
|
+
}
|
|
288
|
+
const db1 = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
289
|
+
async function pull(db) {
|
|
290
|
+
try {
|
|
291
|
+
await db.pull();
|
|
292
|
+
}
|
|
293
|
+
catch (e) {
|
|
294
|
+
// ignore
|
|
295
|
+
}
|
|
296
|
+
finally {
|
|
297
|
+
setTimeout(async () => await pull(db), 0);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function push(db) {
|
|
301
|
+
try {
|
|
302
|
+
await db.push();
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
// ignore
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
setTimeout(async () => await push(db), 0);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
setTimeout(async () => await pull(db1), 0);
|
|
312
|
+
setTimeout(async () => await push(db1), 0);
|
|
313
|
+
for (let i = 0; i < 1000; i++) {
|
|
186
314
|
try {
|
|
187
|
-
|
|
315
|
+
await Promise.all([
|
|
316
|
+
db1.exec(`INSERT INTO q VALUES ('1', 0) ON CONFLICT DO UPDATE SET y = ${i + 1}`),
|
|
317
|
+
db1.exec(`INSERT INTO q VALUES ('2', 0) ON CONFLICT DO UPDATE SET y = ${i + 1}`)
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
// ignore
|
|
188
322
|
}
|
|
189
|
-
|
|
323
|
+
await new Promise(resolve => setTimeout(resolve, 1));
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
test('pull-push-concurrent', async () => {
|
|
327
|
+
{
|
|
328
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
|
|
329
|
+
await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
|
|
330
|
+
await db.exec("DELETE FROM q");
|
|
331
|
+
await db.push();
|
|
332
|
+
await db.close();
|
|
333
|
+
}
|
|
334
|
+
let pullResolve = null;
|
|
335
|
+
const pullFinish = new Promise(resolve => pullResolve = resolve);
|
|
336
|
+
let pushResolve = null;
|
|
337
|
+
const pushFinish = new Promise(resolve => pushResolve = resolve);
|
|
338
|
+
let stopPull = false;
|
|
339
|
+
let stopPush = false;
|
|
340
|
+
const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
|
|
341
|
+
let pull = async () => {
|
|
342
|
+
try {
|
|
343
|
+
await db.pull();
|
|
344
|
+
}
|
|
345
|
+
catch (e) {
|
|
346
|
+
console.error('pull', e);
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
if (!stopPull) {
|
|
350
|
+
setTimeout(pull, 0);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
pullResolve();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
let push = async () => {
|
|
358
|
+
try {
|
|
359
|
+
if ((await db.stats()).operations > 0) {
|
|
360
|
+
await db.push();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
console.error('push', e);
|
|
365
|
+
}
|
|
366
|
+
finally {
|
|
367
|
+
if (!stopPush) {
|
|
368
|
+
setTimeout(push, 0);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
pushResolve();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
setTimeout(pull, 0);
|
|
376
|
+
setTimeout(push, 0);
|
|
377
|
+
for (let i = 0; i < 1000; i++) {
|
|
378
|
+
await db.exec(`INSERT INTO q VALUES ('k${i}', 'v${i}')`);
|
|
190
379
|
}
|
|
380
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
381
|
+
stopPush = true;
|
|
382
|
+
await pushFinish;
|
|
383
|
+
stopPull = true;
|
|
384
|
+
await pullFinish;
|
|
385
|
+
console.info(await db.stats());
|
|
191
386
|
});
|
|
192
387
|
test('transform', async () => {
|
|
193
388
|
{
|
package/index.js
CHANGED
|
@@ -67,7 +67,7 @@ const isMuslFromChildProcess = () => {
|
|
|
67
67
|
function requireNative() {
|
|
68
68
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
69
69
|
try {
|
|
70
|
-
|
|
70
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
71
71
|
} catch (err) {
|
|
72
72
|
loadErrors.push(err)
|
|
73
73
|
}
|
|
@@ -81,8 +81,8 @@ function requireNative() {
|
|
|
81
81
|
try {
|
|
82
82
|
const binding = require('@tursodatabase/sync-android-arm64')
|
|
83
83
|
const bindingPackageVersion = require('@tursodatabase/sync-android-arm64/package.json').version
|
|
84
|
-
if (bindingPackageVersion !== '0.
|
|
85
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
84
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
85
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
86
86
|
}
|
|
87
87
|
return binding
|
|
88
88
|
} catch (e) {
|
|
@@ -97,8 +97,8 @@ function requireNative() {
|
|
|
97
97
|
try {
|
|
98
98
|
const binding = require('@tursodatabase/sync-android-arm-eabi')
|
|
99
99
|
const bindingPackageVersion = require('@tursodatabase/sync-android-arm-eabi/package.json').version
|
|
100
|
-
if (bindingPackageVersion !== '0.
|
|
101
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
100
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
101
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
102
102
|
}
|
|
103
103
|
return binding
|
|
104
104
|
} catch (e) {
|
|
@@ -117,8 +117,8 @@ function requireNative() {
|
|
|
117
117
|
try {
|
|
118
118
|
const binding = require('@tursodatabase/sync-win32-x64-msvc')
|
|
119
119
|
const bindingPackageVersion = require('@tursodatabase/sync-win32-x64-msvc/package.json').version
|
|
120
|
-
if (bindingPackageVersion !== '0.
|
|
121
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
120
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
121
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
122
122
|
}
|
|
123
123
|
return binding
|
|
124
124
|
} catch (e) {
|
|
@@ -133,8 +133,8 @@ function requireNative() {
|
|
|
133
133
|
try {
|
|
134
134
|
const binding = require('@tursodatabase/sync-win32-ia32-msvc')
|
|
135
135
|
const bindingPackageVersion = require('@tursodatabase/sync-win32-ia32-msvc/package.json').version
|
|
136
|
-
if (bindingPackageVersion !== '0.
|
|
137
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
136
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
137
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
138
138
|
}
|
|
139
139
|
return binding
|
|
140
140
|
} catch (e) {
|
|
@@ -149,8 +149,8 @@ function requireNative() {
|
|
|
149
149
|
try {
|
|
150
150
|
const binding = require('@tursodatabase/sync-win32-arm64-msvc')
|
|
151
151
|
const bindingPackageVersion = require('@tursodatabase/sync-win32-arm64-msvc/package.json').version
|
|
152
|
-
if (bindingPackageVersion !== '0.
|
|
153
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
152
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
153
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
154
154
|
}
|
|
155
155
|
return binding
|
|
156
156
|
} catch (e) {
|
|
@@ -168,8 +168,8 @@ function requireNative() {
|
|
|
168
168
|
try {
|
|
169
169
|
const binding = require('@tursodatabase/sync-darwin-universal')
|
|
170
170
|
const bindingPackageVersion = require('@tursodatabase/sync-darwin-universal/package.json').version
|
|
171
|
-
if (bindingPackageVersion !== '0.
|
|
172
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
171
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
172
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
173
173
|
}
|
|
174
174
|
return binding
|
|
175
175
|
} catch (e) {
|
|
@@ -184,8 +184,8 @@ function requireNative() {
|
|
|
184
184
|
try {
|
|
185
185
|
const binding = require('@tursodatabase/sync-darwin-x64')
|
|
186
186
|
const bindingPackageVersion = require('@tursodatabase/sync-darwin-x64/package.json').version
|
|
187
|
-
if (bindingPackageVersion !== '0.
|
|
188
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
187
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
188
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
189
189
|
}
|
|
190
190
|
return binding
|
|
191
191
|
} catch (e) {
|
|
@@ -200,8 +200,8 @@ function requireNative() {
|
|
|
200
200
|
try {
|
|
201
201
|
const binding = require('@tursodatabase/sync-darwin-arm64')
|
|
202
202
|
const bindingPackageVersion = require('@tursodatabase/sync-darwin-arm64/package.json').version
|
|
203
|
-
if (bindingPackageVersion !== '0.
|
|
204
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
203
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
204
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
205
205
|
}
|
|
206
206
|
return binding
|
|
207
207
|
} catch (e) {
|
|
@@ -220,8 +220,8 @@ function requireNative() {
|
|
|
220
220
|
try {
|
|
221
221
|
const binding = require('@tursodatabase/sync-freebsd-x64')
|
|
222
222
|
const bindingPackageVersion = require('@tursodatabase/sync-freebsd-x64/package.json').version
|
|
223
|
-
if (bindingPackageVersion !== '0.
|
|
224
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
223
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
224
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
225
225
|
}
|
|
226
226
|
return binding
|
|
227
227
|
} catch (e) {
|
|
@@ -236,8 +236,8 @@ function requireNative() {
|
|
|
236
236
|
try {
|
|
237
237
|
const binding = require('@tursodatabase/sync-freebsd-arm64')
|
|
238
238
|
const bindingPackageVersion = require('@tursodatabase/sync-freebsd-arm64/package.json').version
|
|
239
|
-
if (bindingPackageVersion !== '0.
|
|
240
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
239
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
240
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
241
241
|
}
|
|
242
242
|
return binding
|
|
243
243
|
} catch (e) {
|
|
@@ -257,8 +257,8 @@ function requireNative() {
|
|
|
257
257
|
try {
|
|
258
258
|
const binding = require('@tursodatabase/sync-linux-x64-musl')
|
|
259
259
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-x64-musl/package.json').version
|
|
260
|
-
if (bindingPackageVersion !== '0.
|
|
261
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
260
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
261
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
262
262
|
}
|
|
263
263
|
return binding
|
|
264
264
|
} catch (e) {
|
|
@@ -273,8 +273,8 @@ function requireNative() {
|
|
|
273
273
|
try {
|
|
274
274
|
const binding = require('@tursodatabase/sync-linux-x64-gnu')
|
|
275
275
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-x64-gnu/package.json').version
|
|
276
|
-
if (bindingPackageVersion !== '0.
|
|
277
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
276
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
277
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
278
278
|
}
|
|
279
279
|
return binding
|
|
280
280
|
} catch (e) {
|
|
@@ -291,8 +291,8 @@ function requireNative() {
|
|
|
291
291
|
try {
|
|
292
292
|
const binding = require('@tursodatabase/sync-linux-arm64-musl')
|
|
293
293
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-arm64-musl/package.json').version
|
|
294
|
-
if (bindingPackageVersion !== '0.
|
|
295
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
294
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
295
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
296
296
|
}
|
|
297
297
|
return binding
|
|
298
298
|
} catch (e) {
|
|
@@ -307,8 +307,8 @@ function requireNative() {
|
|
|
307
307
|
try {
|
|
308
308
|
const binding = require('@tursodatabase/sync-linux-arm64-gnu')
|
|
309
309
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-arm64-gnu/package.json').version
|
|
310
|
-
if (bindingPackageVersion !== '0.
|
|
311
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
310
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
311
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
312
312
|
}
|
|
313
313
|
return binding
|
|
314
314
|
} catch (e) {
|
|
@@ -325,8 +325,8 @@ function requireNative() {
|
|
|
325
325
|
try {
|
|
326
326
|
const binding = require('@tursodatabase/sync-linux-arm-musleabihf')
|
|
327
327
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-arm-musleabihf/package.json').version
|
|
328
|
-
if (bindingPackageVersion !== '0.
|
|
329
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
328
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
329
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
330
330
|
}
|
|
331
331
|
return binding
|
|
332
332
|
} catch (e) {
|
|
@@ -341,8 +341,42 @@ function requireNative() {
|
|
|
341
341
|
try {
|
|
342
342
|
const binding = require('@tursodatabase/sync-linux-arm-gnueabihf')
|
|
343
343
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-arm-gnueabihf/package.json').version
|
|
344
|
-
if (bindingPackageVersion !== '0.
|
|
345
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
344
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
345
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
|
+
}
|
|
347
|
+
return binding
|
|
348
|
+
} catch (e) {
|
|
349
|
+
loadErrors.push(e)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} else if (process.arch === 'loong64') {
|
|
353
|
+
if (isMusl()) {
|
|
354
|
+
try {
|
|
355
|
+
return require('./sync.linux-loong64-musl.node')
|
|
356
|
+
} catch (e) {
|
|
357
|
+
loadErrors.push(e)
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const binding = require('@tursodatabase/sync-linux-loong64-musl')
|
|
361
|
+
const bindingPackageVersion = require('@tursodatabase/sync-linux-loong64-musl/package.json').version
|
|
362
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
363
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
364
|
+
}
|
|
365
|
+
return binding
|
|
366
|
+
} catch (e) {
|
|
367
|
+
loadErrors.push(e)
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
try {
|
|
371
|
+
return require('./sync.linux-loong64-gnu.node')
|
|
372
|
+
} catch (e) {
|
|
373
|
+
loadErrors.push(e)
|
|
374
|
+
}
|
|
375
|
+
try {
|
|
376
|
+
const binding = require('@tursodatabase/sync-linux-loong64-gnu')
|
|
377
|
+
const bindingPackageVersion = require('@tursodatabase/sync-linux-loong64-gnu/package.json').version
|
|
378
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
379
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
346
380
|
}
|
|
347
381
|
return binding
|
|
348
382
|
} catch (e) {
|
|
@@ -359,8 +393,8 @@ function requireNative() {
|
|
|
359
393
|
try {
|
|
360
394
|
const binding = require('@tursodatabase/sync-linux-riscv64-musl')
|
|
361
395
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-musl/package.json').version
|
|
362
|
-
if (bindingPackageVersion !== '0.
|
|
363
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
396
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
397
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
364
398
|
}
|
|
365
399
|
return binding
|
|
366
400
|
} catch (e) {
|
|
@@ -375,8 +409,8 @@ function requireNative() {
|
|
|
375
409
|
try {
|
|
376
410
|
const binding = require('@tursodatabase/sync-linux-riscv64-gnu')
|
|
377
411
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-gnu/package.json').version
|
|
378
|
-
if (bindingPackageVersion !== '0.
|
|
379
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
412
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
413
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
380
414
|
}
|
|
381
415
|
return binding
|
|
382
416
|
} catch (e) {
|
|
@@ -392,8 +426,8 @@ function requireNative() {
|
|
|
392
426
|
try {
|
|
393
427
|
const binding = require('@tursodatabase/sync-linux-ppc64-gnu')
|
|
394
428
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-ppc64-gnu/package.json').version
|
|
395
|
-
if (bindingPackageVersion !== '0.
|
|
396
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
429
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
430
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
397
431
|
}
|
|
398
432
|
return binding
|
|
399
433
|
} catch (e) {
|
|
@@ -408,8 +442,8 @@ function requireNative() {
|
|
|
408
442
|
try {
|
|
409
443
|
const binding = require('@tursodatabase/sync-linux-s390x-gnu')
|
|
410
444
|
const bindingPackageVersion = require('@tursodatabase/sync-linux-s390x-gnu/package.json').version
|
|
411
|
-
if (bindingPackageVersion !== '0.
|
|
412
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
445
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
446
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
413
447
|
}
|
|
414
448
|
return binding
|
|
415
449
|
} catch (e) {
|
|
@@ -428,8 +462,8 @@ function requireNative() {
|
|
|
428
462
|
try {
|
|
429
463
|
const binding = require('@tursodatabase/sync-openharmony-arm64')
|
|
430
464
|
const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm64/package.json').version
|
|
431
|
-
if (bindingPackageVersion !== '0.
|
|
432
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
465
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
466
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
433
467
|
}
|
|
434
468
|
return binding
|
|
435
469
|
} catch (e) {
|
|
@@ -444,8 +478,8 @@ function requireNative() {
|
|
|
444
478
|
try {
|
|
445
479
|
const binding = require('@tursodatabase/sync-openharmony-x64')
|
|
446
480
|
const bindingPackageVersion = require('@tursodatabase/sync-openharmony-x64/package.json').version
|
|
447
|
-
if (bindingPackageVersion !== '0.
|
|
448
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
481
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
482
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
449
483
|
}
|
|
450
484
|
return binding
|
|
451
485
|
} catch (e) {
|
|
@@ -460,8 +494,8 @@ function requireNative() {
|
|
|
460
494
|
try {
|
|
461
495
|
const binding = require('@tursodatabase/sync-openharmony-arm')
|
|
462
496
|
const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm/package.json').version
|
|
463
|
-
if (bindingPackageVersion !== '0.
|
|
464
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
497
|
+
if (bindingPackageVersion !== '0.2.0-pre.10' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
498
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.10 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
465
499
|
}
|
|
466
500
|
return binding
|
|
467
501
|
} catch (e) {
|
|
@@ -478,22 +512,32 @@ function requireNative() {
|
|
|
478
512
|
nativeBinding = requireNative()
|
|
479
513
|
|
|
480
514
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
515
|
+
let wasiBinding = null
|
|
516
|
+
let wasiBindingError = null
|
|
481
517
|
try {
|
|
482
|
-
|
|
518
|
+
wasiBinding = require('./sync.wasi.cjs')
|
|
519
|
+
nativeBinding = wasiBinding
|
|
483
520
|
} catch (err) {
|
|
484
521
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
485
|
-
|
|
522
|
+
wasiBindingError = err
|
|
486
523
|
}
|
|
487
524
|
}
|
|
488
525
|
if (!nativeBinding) {
|
|
489
526
|
try {
|
|
490
|
-
|
|
527
|
+
wasiBinding = require('@tursodatabase/sync-wasm32-wasi')
|
|
528
|
+
nativeBinding = wasiBinding
|
|
491
529
|
} catch (err) {
|
|
492
530
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
531
|
+
wasiBindingError.cause = err
|
|
493
532
|
loadErrors.push(err)
|
|
494
533
|
}
|
|
495
534
|
}
|
|
496
535
|
}
|
|
536
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
537
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
538
|
+
error.cause = wasiBindingError
|
|
539
|
+
throw error
|
|
540
|
+
}
|
|
497
541
|
}
|
|
498
542
|
|
|
499
543
|
if (!nativeBinding) {
|
|
@@ -502,13 +546,19 @@ if (!nativeBinding) {
|
|
|
502
546
|
`Cannot find native binding. ` +
|
|
503
547
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
504
548
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
505
|
-
{
|
|
549
|
+
{
|
|
550
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
551
|
+
cur.cause = err
|
|
552
|
+
return cur
|
|
553
|
+
}),
|
|
554
|
+
},
|
|
506
555
|
)
|
|
507
556
|
}
|
|
508
557
|
throw new Error(`Failed to load native binding`)
|
|
509
558
|
}
|
|
510
559
|
|
|
511
|
-
const { Database, Statement, GeneratorHolder, JsDataCompletion, JsProtocolIo, JsProtocolRequestBytes, SyncEngine, DatabaseChangeTypeJs, SyncEngineProtocolVersion } = nativeBinding
|
|
560
|
+
const { BatchExecutor, Database, Statement, GeneratorHolder, JsDataCompletion, JsProtocolIo, JsProtocolRequestBytes, SyncEngine, SyncEngineChanges, DatabaseChangeTypeJs, SyncEngineProtocolVersion } = nativeBinding
|
|
561
|
+
export { BatchExecutor }
|
|
512
562
|
export { Database }
|
|
513
563
|
export { Statement }
|
|
514
564
|
export { GeneratorHolder }
|
|
@@ -516,5 +566,6 @@ export { JsDataCompletion }
|
|
|
516
566
|
export { JsProtocolIo }
|
|
517
567
|
export { JsProtocolRequestBytes }
|
|
518
568
|
export { SyncEngine }
|
|
569
|
+
export { SyncEngineChanges }
|
|
519
570
|
export { DatabaseChangeTypeJs }
|
|
520
571
|
export { SyncEngineProtocolVersion }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tursodatabase/sync",
|
|
3
|
-
"version": "0.2.0-pre.
|
|
3
|
+
"version": "0.2.0-pre.11",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/tursodatabase/turso"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"napi-artifacts": "napi artifacts --output-dir .",
|
|
32
32
|
"tsc-build": "npm exec tsc",
|
|
33
33
|
"build": "npm run napi-build && npm run tsc-build",
|
|
34
|
-
"test": "VITE_TURSO_DB_URL=http://
|
|
34
|
+
"test": "VITE_TURSO_DB_URL=http://d--a--a.localhost:10000 vitest --run",
|
|
35
35
|
"prepublishOnly": "npm run napi-dirs && npm run napi-artifacts && napi prepublish -t npm"
|
|
36
36
|
},
|
|
37
37
|
"napi": {
|
|
@@ -39,21 +39,21 @@
|
|
|
39
39
|
"targets": [
|
|
40
40
|
"x86_64-unknown-linux-gnu",
|
|
41
41
|
"x86_64-pc-windows-msvc",
|
|
42
|
-
"
|
|
42
|
+
"aarch64-apple-darwin",
|
|
43
43
|
"aarch64-unknown-linux-gnu"
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tursodatabase/database-common": "^0.2.0-pre.
|
|
48
|
-
"@tursodatabase/sync-common": "^0.2.0-pre.
|
|
47
|
+
"@tursodatabase/database-common": "^0.2.0-pre.11",
|
|
48
|
+
"@tursodatabase/sync-common": "^0.2.0-pre.11"
|
|
49
49
|
},
|
|
50
50
|
"imports": {
|
|
51
51
|
"#index": "./index.js"
|
|
52
52
|
},
|
|
53
53
|
"optionalDependencies": {
|
|
54
|
-
"@tursodatabase/sync-linux-x64-gnu": "0.2.0-pre.
|
|
55
|
-
"@tursodatabase/sync-win32-x64-msvc": "0.2.0-pre.
|
|
56
|
-
"@tursodatabase/sync-darwin-
|
|
57
|
-
"@tursodatabase/sync-linux-arm64-gnu": "0.2.0-pre.
|
|
54
|
+
"@tursodatabase/sync-linux-x64-gnu": "0.2.0-pre.11",
|
|
55
|
+
"@tursodatabase/sync-win32-x64-msvc": "0.2.0-pre.11",
|
|
56
|
+
"@tursodatabase/sync-darwin-arm64": "0.2.0-pre.11",
|
|
57
|
+
"@tursodatabase/sync-linux-arm64-gnu": "0.2.0-pre.11"
|
|
58
58
|
}
|
|
59
59
|
}
|