@tursodatabase/sync 0.2.0-pre.3 → 0.2.0-pre.4

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/promise.d.ts CHANGED
@@ -1,21 +1,16 @@
1
1
  import { DatabasePromise, DatabaseOpts, NativeDatabase } from "@tursodatabase/database-common";
2
- import { ProtocolIo, SyncOpts, RunOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult } from "@tursodatabase/sync-common";
2
+ import { ProtocolIo, SyncOpts, RunOpts, DatabaseRowMutation, DatabaseRowStatement, DatabaseRowTransformResult, SyncEngineStats, SyncEngineGuards } from "@tursodatabase/sync-common";
3
3
  declare class Database extends DatabasePromise {
4
4
  runOpts: RunOpts;
5
5
  engine: any;
6
6
  io: ProtocolIo;
7
+ guards: SyncEngineGuards;
7
8
  constructor(db: NativeDatabase, io: ProtocolIo, runOpts: RunOpts, engine: any, opts?: DatabaseOpts);
8
9
  sync(): Promise<void>;
9
10
  pull(): Promise<void>;
10
11
  push(): Promise<void>;
11
12
  checkpoint(): Promise<void>;
12
- stats(): Promise<{
13
- operations: number;
14
- mainWal: number;
15
- revertWal: number;
16
- lastPullUnixTime: number;
17
- lastPushUnixTime: number | null;
18
- }>;
13
+ stats(): Promise<SyncEngineStats>;
19
14
  close(): Promise<void>;
20
15
  }
21
16
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC9F,OAAO,EAAE,UAAU,EAAO,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAwCvJ,cAAM,QAAS,SAAQ,eAAe;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,EAAE,EAAE,UAAU,CAAC;gBACH,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,YAAiB;IAMhG,IAAI;IAGJ,IAAI;IAGJ,IAAI;IAGJ,UAAU;IAGV,KAAK,IAAI,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IAG9H,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGxC;AAED;;;;;;GAMG;AACH,iBAAe,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuBxD;AAED,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,CAAA"}
1
+ {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../promise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC9F,OAAO,EAAE,UAAU,EAAO,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAwC1L,cAAM,QAAS,SAAQ,eAAe;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,GAAG,CAAC;IACZ,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE,gBAAgB,CAAA;gBACZ,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,GAAE,YAAiB;IAOhG,IAAI;IAIJ,IAAI;IAIJ,IAAI;IAGJ,UAAU;IAGV,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAGxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGxC;AAED;;;;;;GAMG;AACH,iBAAe,OAAO,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwBxD;AAED,OAAO,EAAE,OAAO,EAAE,QAAQ,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 = {
@@ -44,23 +44,27 @@ class Database extends DatabasePromise {
44
44
  runOpts;
45
45
  engine;
46
46
  io;
47
+ guards;
47
48
  constructor(db, io, runOpts, engine, opts = {}) {
48
49
  super(db, opts);
49
50
  this.runOpts = runOpts;
50
51
  this.engine = engine;
51
52
  this.io = io;
53
+ this.guards = new SyncEngineGuards();
52
54
  }
53
55
  async sync() {
54
- await run(this.runOpts, this.io, this.engine, this.engine.sync());
56
+ await this.push();
57
+ await this.pull();
55
58
  }
56
59
  async pull() {
57
- await run(this.runOpts, this.io, this.engine, this.engine.pull());
60
+ const changes = await this.guards.wait(async () => await run(this.runOpts, this.io, this.engine, this.engine.wait()));
61
+ await this.guards.apply(async () => await run(this.runOpts, this.io, this.engine, this.engine.apply(changes)));
58
62
  }
59
63
  async push() {
60
- await run(this.runOpts, this.io, this.engine, this.engine.push());
64
+ await this.guards.push(async () => await run(this.runOpts, this.io, this.engine, this.engine.push()));
61
65
  }
62
66
  async checkpoint() {
63
- await run(this.runOpts, this.io, this.engine, this.engine.checkpoint());
67
+ await this.guards.checkpoint(async () => await run(this.runOpts, this.io, this.engine, this.engine.checkpoint()));
64
68
  }
65
69
  async stats() {
66
70
  return (await run(this.runOpts, this.io, this.engine, this.engine.stats()));
@@ -83,7 +87,8 @@ async function connect(opts) {
83
87
  tablesIgnore: opts.tablesIgnore,
84
88
  useTransform: opts.transform != null,
85
89
  tracing: opts.tracing,
86
- protocolVersion: 1
90
+ protocolVersion: 1,
91
+ longPollTimeoutMs: opts.longPollTimeoutMs,
87
92
  });
88
93
  const runOpts = {
89
94
  url: opts.url,
@@ -2,6 +2,16 @@ import { unlinkSync } from "node:fs";
2
2
  import { expect, test } from 'vitest';
3
3
  import { connect } 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
+ }
5
15
  test('select-after-push', async () => {
6
16
  {
7
17
  const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
@@ -133,14 +143,14 @@ test('checkpoint', async () => {
133
143
  await db1.checkpoint();
134
144
  expect((await db1.stats()).mainWal).toBe(0);
135
145
  let revertWal = (await db1.stats()).revertWal;
136
- expect(revertWal).toBeLessThan(4096 * 1000 / 100);
146
+ expect(revertWal).toBeLessThan(4096 * 1000 / 50);
137
147
  for (let i = 0; i < 1000; i++) {
138
148
  await db1.exec(`UPDATE q SET y = 'u${i}' WHERE x = 'k${i}'`);
139
149
  }
140
150
  await db1.checkpoint();
141
151
  expect((await db1.stats()).revertWal).toBe(revertWal);
142
152
  });
143
- test('persistence', async () => {
153
+ test('persistence-push', async () => {
144
154
  {
145
155
  const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
146
156
  await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
@@ -160,9 +170,11 @@ test('persistence', async () => {
160
170
  const db2 = await connect({ path: path, url: process.env.VITE_TURSO_DB_URL });
161
171
  await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
162
172
  await db2.exec(`INSERT INTO q VALUES ('k4', 'v4')`);
163
- const rows = await db2.prepare('SELECT * FROM q').all();
173
+ const stmt = db2.prepare('SELECT * FROM q');
174
+ const rows = await stmt.all();
164
175
  const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }, { x: 'k3', y: 'v3' }, { x: 'k4', y: 'v4' }];
165
176
  expect(rows).toEqual(expected);
177
+ stmt.close();
166
178
  await db2.close();
167
179
  }
168
180
  {
@@ -179,15 +191,192 @@ test('persistence', async () => {
179
191
  }
180
192
  }
181
193
  finally {
182
- unlinkSync(path);
183
- unlinkSync(`${path}-wal`);
184
- unlinkSync(`${path}-info`);
185
- unlinkSync(`${path}-changes`);
194
+ cleanup(path);
195
+ }
196
+ });
197
+ test('persistence-offline', async () => {
198
+ {
199
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
200
+ await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
201
+ await db.exec("DELETE FROM q");
202
+ await db.push();
203
+ await db.close();
204
+ }
205
+ const path = `test-${(Math.random() * 10000) | 0}.db`;
206
+ try {
207
+ {
208
+ const db = await connect({ path: path, url: process.env.VITE_TURSO_DB_URL });
209
+ await db.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
210
+ await db.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
211
+ await db.push();
212
+ await db.close();
213
+ }
214
+ {
215
+ const db = await connect({ path: path, url: "https://not-valid-url.localhost" });
216
+ const rows = await db.prepare("SELECT * FROM q").all();
217
+ const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }];
218
+ expect(rows.sort(localeCompare)).toEqual(expected.sort(localeCompare));
219
+ await db.close();
220
+ }
221
+ }
222
+ finally {
223
+ cleanup(path);
224
+ }
225
+ });
226
+ test('persistence-pull-push', async () => {
227
+ {
228
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
229
+ await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
230
+ await db.exec("DELETE FROM q");
231
+ await db.push();
232
+ await db.close();
233
+ }
234
+ const path1 = `test-${(Math.random() * 10000) | 0}.db`;
235
+ const path2 = `test-${(Math.random() * 10000) | 0}.db`;
236
+ try {
237
+ const db1 = await connect({ path: path1, url: process.env.VITE_TURSO_DB_URL });
238
+ await db1.exec(`INSERT INTO q VALUES ('k1', 'v1')`);
239
+ await db1.exec(`INSERT INTO q VALUES ('k2', 'v2')`);
240
+ const stats1 = await db1.stats();
241
+ const db2 = await connect({ path: path2, url: process.env.VITE_TURSO_DB_URL });
242
+ await db2.exec(`INSERT INTO q VALUES ('k3', 'v3')`);
243
+ await db2.exec(`INSERT INTO q VALUES ('k4', 'v4')`);
244
+ await Promise.all([db1.push(), db2.push()]);
245
+ await Promise.all([db1.pull(), db2.pull()]);
246
+ const stats2 = await db1.stats();
247
+ console.info(stats1, stats2);
248
+ expect(stats1.revision).not.toBe(stats2.revision);
249
+ const rows1 = await db1.prepare('SELECT * FROM q').all();
250
+ const rows2 = await db2.prepare('SELECT * FROM q').all();
251
+ const expected = [{ x: 'k1', y: 'v1' }, { x: 'k2', y: 'v2' }, { x: 'k3', y: 'v3' }, { x: 'k4', y: 'v4' }];
252
+ expect(rows1.sort(localeCompare)).toEqual(expected.sort(localeCompare));
253
+ expect(rows2.sort(localeCompare)).toEqual(expected.sort(localeCompare));
254
+ }
255
+ finally {
256
+ cleanup(path1);
257
+ cleanup(path2);
258
+ }
259
+ });
260
+ test('update', async () => {
261
+ {
262
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
263
+ await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
264
+ await db.exec("DELETE FROM q");
265
+ await db.push();
266
+ await db.close();
267
+ }
268
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
269
+ await db.exec("INSERT INTO q VALUES ('1', '2')");
270
+ await db.push();
271
+ await db.exec("INSERT INTO q VALUES ('1', '2') ON CONFLICT DO UPDATE SET y = '3'");
272
+ await db.push();
273
+ });
274
+ test('concurrent-updates', async () => {
275
+ {
276
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
277
+ await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
278
+ await db.exec("DELETE FROM q");
279
+ await db.push();
280
+ await db.close();
281
+ }
282
+ const db1 = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
283
+ async function pull(db) {
284
+ try {
285
+ await db.pull();
286
+ }
287
+ catch (e) {
288
+ // ignore
289
+ }
290
+ finally {
291
+ setTimeout(async () => await pull(db), 0);
292
+ }
293
+ }
294
+ async function push(db) {
295
+ try {
296
+ await db.push();
297
+ }
298
+ catch (e) {
299
+ // ignore
300
+ }
301
+ finally {
302
+ setTimeout(async () => await push(db), 0);
303
+ }
304
+ }
305
+ setTimeout(async () => await pull(db1), 0);
306
+ setTimeout(async () => await push(db1), 0);
307
+ for (let i = 0; i < 1000; i++) {
186
308
  try {
187
- unlinkSync(`${path}-revert`);
309
+ await Promise.all([
310
+ db1.exec(`INSERT INTO q VALUES ('1', 0) ON CONFLICT DO UPDATE SET y = ${i + 1}`),
311
+ db1.exec(`INSERT INTO q VALUES ('2', 0) ON CONFLICT DO UPDATE SET y = ${i + 1}`)
312
+ ]);
313
+ }
314
+ catch (e) {
315
+ // ignore
188
316
  }
189
- catch (e) { }
317
+ await new Promise(resolve => setTimeout(resolve, 1));
318
+ }
319
+ });
320
+ test('pull-push-concurrent', async () => {
321
+ {
322
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL, longPollTimeoutMs: 5000 });
323
+ await db.exec("CREATE TABLE IF NOT EXISTS q(x TEXT PRIMARY KEY, y)");
324
+ await db.exec("DELETE FROM q");
325
+ await db.push();
326
+ await db.close();
327
+ }
328
+ let pullResolve = null;
329
+ const pullFinish = new Promise(resolve => pullResolve = resolve);
330
+ let pushResolve = null;
331
+ const pushFinish = new Promise(resolve => pushResolve = resolve);
332
+ let stopPull = false;
333
+ let stopPush = false;
334
+ const db = await connect({ path: ':memory:', url: process.env.VITE_TURSO_DB_URL });
335
+ let pull = async () => {
336
+ try {
337
+ await db.pull();
338
+ }
339
+ catch (e) {
340
+ console.error('pull', e);
341
+ }
342
+ finally {
343
+ if (!stopPull) {
344
+ setTimeout(pull, 0);
345
+ }
346
+ else {
347
+ pullResolve();
348
+ }
349
+ }
350
+ };
351
+ let push = async () => {
352
+ try {
353
+ if ((await db.stats()).operations > 0) {
354
+ await db.push();
355
+ }
356
+ }
357
+ catch (e) {
358
+ console.error('push', e);
359
+ }
360
+ finally {
361
+ if (!stopPush) {
362
+ setTimeout(push, 0);
363
+ }
364
+ else {
365
+ pushResolve();
366
+ }
367
+ }
368
+ };
369
+ setTimeout(pull, 0);
370
+ setTimeout(push, 0);
371
+ for (let i = 0; i < 1000; i++) {
372
+ await db.exec(`INSERT INTO q VALUES ('k${i}', 'v${i}')`);
190
373
  }
374
+ await new Promise(resolve => setTimeout(resolve, 1000));
375
+ stopPush = true;
376
+ await pushFinish;
377
+ stopPull = true;
378
+ await pullFinish;
379
+ console.info(await db.stats());
191
380
  });
192
381
  test('transform', async () => {
193
382
  {
package/index.js CHANGED
@@ -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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
84
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
120
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
136
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
171
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
260
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
294
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
328
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
330
  }
331
331
  return binding
332
332
  } catch (e) {
@@ -341,8 +341,8 @@ 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.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
346
  }
347
347
  return binding
348
348
  } catch (e) {
@@ -359,8 +359,8 @@ function requireNative() {
359
359
  try {
360
360
  const binding = require('@tursodatabase/sync-linux-riscv64-musl')
361
361
  const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-musl/package.json').version
362
- if (bindingPackageVersion !== '0.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
362
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
364
  }
365
365
  return binding
366
366
  } catch (e) {
@@ -375,8 +375,8 @@ function requireNative() {
375
375
  try {
376
376
  const binding = require('@tursodatabase/sync-linux-riscv64-gnu')
377
377
  const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-gnu/package.json').version
378
- if (bindingPackageVersion !== '0.2.0-pre.1' && 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.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
+ if (bindingPackageVersion !== '0.2.0-pre.3' && 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.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
380
  }
381
381
  return binding
382
382
  } catch (e) {
@@ -392,8 +392,8 @@ function requireNative() {
392
392
  try {
393
393
  const binding = require('@tursodatabase/sync-linux-ppc64-gnu')
394
394
  const bindingPackageVersion = require('@tursodatabase/sync-linux-ppc64-gnu/package.json').version
395
- if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
396
- throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
395
+ if (bindingPackageVersion !== '0.2.0-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
396
+ throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
397
397
  }
398
398
  return binding
399
399
  } catch (e) {
@@ -408,8 +408,8 @@ function requireNative() {
408
408
  try {
409
409
  const binding = require('@tursodatabase/sync-linux-s390x-gnu')
410
410
  const bindingPackageVersion = require('@tursodatabase/sync-linux-s390x-gnu/package.json').version
411
- if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
412
- throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
411
+ if (bindingPackageVersion !== '0.2.0-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
412
+ throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
413
413
  }
414
414
  return binding
415
415
  } catch (e) {
@@ -428,8 +428,8 @@ function requireNative() {
428
428
  try {
429
429
  const binding = require('@tursodatabase/sync-openharmony-arm64')
430
430
  const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm64/package.json').version
431
- if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
432
- throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
431
+ if (bindingPackageVersion !== '0.2.0-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
432
+ throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
433
433
  }
434
434
  return binding
435
435
  } catch (e) {
@@ -444,8 +444,8 @@ function requireNative() {
444
444
  try {
445
445
  const binding = require('@tursodatabase/sync-openharmony-x64')
446
446
  const bindingPackageVersion = require('@tursodatabase/sync-openharmony-x64/package.json').version
447
- if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
- throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
447
+ if (bindingPackageVersion !== '0.2.0-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
+ throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
449
  }
450
450
  return binding
451
451
  } catch (e) {
@@ -460,8 +460,8 @@ function requireNative() {
460
460
  try {
461
461
  const binding = require('@tursodatabase/sync-openharmony-arm')
462
462
  const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm/package.json').version
463
- if (bindingPackageVersion !== '0.2.0-pre.1' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
- throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
463
+ if (bindingPackageVersion !== '0.2.0-pre.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
+ throw new Error(`Native binding package version mismatch, expected 0.2.0-pre.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
465
  }
466
466
  return binding
467
467
  } catch (e) {
@@ -508,7 +508,7 @@ if (!nativeBinding) {
508
508
  throw new Error(`Failed to load native binding`)
509
509
  }
510
510
 
511
- const { Database, Statement, GeneratorHolder, JsDataCompletion, JsProtocolIo, JsProtocolRequestBytes, SyncEngine, DatabaseChangeTypeJs, SyncEngineProtocolVersion } = nativeBinding
511
+ const { Database, Statement, GeneratorHolder, JsDataCompletion, JsProtocolIo, JsProtocolRequestBytes, SyncEngine, SyncEngineChanges, DatabaseChangeTypeJs, SyncEngineProtocolVersion } = nativeBinding
512
512
  export { Database }
513
513
  export { Statement }
514
514
  export { GeneratorHolder }
@@ -516,5 +516,6 @@ export { JsDataCompletion }
516
516
  export { JsProtocolIo }
517
517
  export { JsProtocolRequestBytes }
518
518
  export { SyncEngine }
519
+ export { SyncEngineChanges }
519
520
  export { DatabaseChangeTypeJs }
520
521
  export { SyncEngineProtocolVersion }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/sync",
3
- "version": "0.2.0-pre.3",
3
+ "version": "0.2.0-pre.4",
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://b--a--a.localhost:10000 vitest --run",
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": {
@@ -44,16 +44,16 @@
44
44
  ]
45
45
  },
46
46
  "dependencies": {
47
- "@tursodatabase/database-common": "^0.2.0-pre.3",
48
- "@tursodatabase/sync-common": "^0.2.0-pre.3"
47
+ "@tursodatabase/database-common": "^0.2.0-pre.4",
48
+ "@tursodatabase/sync-common": "^0.2.0-pre.4"
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.3",
55
- "@tursodatabase/sync-win32-x64-msvc": "0.2.0-pre.3",
56
- "@tursodatabase/sync-darwin-arm64": "0.2.0-pre.3",
57
- "@tursodatabase/sync-linux-arm64-gnu": "0.2.0-pre.3"
54
+ "@tursodatabase/sync-linux-x64-gnu": "0.2.0-pre.4",
55
+ "@tursodatabase/sync-win32-x64-msvc": "0.2.0-pre.4",
56
+ "@tursodatabase/sync-darwin-arm64": "0.2.0-pre.4",
57
+ "@tursodatabase/sync-linux-arm64-gnu": "0.2.0-pre.4"
58
58
  }
59
59
  }