@tursodatabase/sync 0.1.4 → 0.1.5-pre.2

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.
@@ -1,3 +1,4 @@
1
+ import { DatabaseRowMutationJs, DatabaseRowStatementJs } from '#entry-point';
1
2
  import { Database } from '@tursodatabase/database';
2
3
  interface ConnectOpts {
3
4
  path: string;
@@ -5,11 +6,19 @@ interface ConnectOpts {
5
6
  url: string;
6
7
  authToken?: string;
7
8
  encryptionKey?: string;
9
+ tablesIgnore?: string[];
10
+ transform?: (arg: DatabaseRowMutationJs) => DatabaseRowStatementJs | null;
11
+ enableTracing?: string;
8
12
  }
9
13
  interface Sync {
10
14
  sync(): Promise<void>;
11
15
  push(): Promise<void>;
12
16
  pull(): Promise<void>;
17
+ checkpoint(): Promise<void>;
18
+ stats(): Promise<{
19
+ operations: number;
20
+ wal: number;
21
+ }>;
13
22
  }
14
23
  export declare function connect(opts: ConnectOpts): Database & Sync;
15
- export {};
24
+ export { Database, Sync };
@@ -60,9 +60,16 @@ async function process(opts, request) {
60
60
  const completion = request.completion();
61
61
  if (requestType.type == 'Http') {
62
62
  try {
63
+ let headers = opts.headers;
64
+ if (requestType.headers != null && requestType.headers.length > 0) {
65
+ headers = { ...opts.headers };
66
+ for (let header of requestType.headers) {
67
+ headers[header[0]] = header[1];
68
+ }
69
+ }
63
70
  const response = await fetch(`${opts.url}${requestType.path}`, {
64
71
  method: requestType.method,
65
- headers: opts.headers,
72
+ headers: headers,
66
73
  body: requestType.body != null ? new Uint8Array(requestType.body) : null,
67
74
  });
68
75
  completion.status(response.status);
@@ -112,9 +119,16 @@ async function run(opts, engine, generator) {
112
119
  await Promise.all([engine.ioLoopAsync(), tasksRace]);
113
120
  tasks = tasks.filter(t => !t.finished);
114
121
  }
122
+ return generator.take();
115
123
  }
116
124
  export async function connect(opts) {
117
- const engine = new SyncEngine({ path: opts.path, clientName: opts.clientName });
125
+ const engine = new SyncEngine({
126
+ path: opts.path,
127
+ clientName: opts.clientName,
128
+ tablesIgnore: opts.tablesIgnore,
129
+ transform: opts.transform,
130
+ enableTracing: opts.enableTracing
131
+ });
118
132
  const httpOpts = {
119
133
  url: opts.url,
120
134
  headers: {
@@ -131,5 +145,8 @@ export async function connect(opts) {
131
145
  db.sync = async function () { await run(httpOpts, engine, engine.sync()); };
132
146
  db.pull = async function () { await run(httpOpts, engine, engine.pull()); };
133
147
  db.push = async function () { await run(httpOpts, engine, engine.push()); };
148
+ db.checkpoint = async function () { await run(httpOpts, engine, engine.checkpoint()); };
149
+ db.stats = async function () { return (await run(httpOpts, engine, engine.stats())); };
134
150
  return db;
135
151
  }
152
+ export { Database };
package/index.js CHANGED
@@ -79,12 +79,7 @@ function requireNative() {
79
79
  loadErrors.push(e)
80
80
  }
81
81
  try {
82
- const binding = require('@tursodatabase/sync-android-arm64')
83
- const bindingPackageVersion = require('@tursodatabase/sync-android-arm64/package.json').version
84
- if (bindingPackageVersion !== '0.1.4-pre.5') {
85
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
- }
87
- return binding
82
+ return require('@tursodatabase/sync-android-arm64')
88
83
  } catch (e) {
89
84
  loadErrors.push(e)
90
85
  }
@@ -95,12 +90,7 @@ function requireNative() {
95
90
  loadErrors.push(e)
96
91
  }
97
92
  try {
98
- const binding = require('@tursodatabase/sync-android-arm-eabi')
99
- const bindingPackageVersion = require('@tursodatabase/sync-android-arm-eabi/package.json').version
100
- if (bindingPackageVersion !== '0.1.4-pre.5') {
101
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
- }
103
- return binding
93
+ return require('@tursodatabase/sync-android-arm-eabi')
104
94
  } catch (e) {
105
95
  loadErrors.push(e)
106
96
  }
@@ -115,12 +105,7 @@ function requireNative() {
115
105
  loadErrors.push(e)
116
106
  }
117
107
  try {
118
- const binding = require('@tursodatabase/sync-win32-x64-msvc')
119
- const bindingPackageVersion = require('@tursodatabase/sync-win32-x64-msvc/package.json').version
120
- if (bindingPackageVersion !== '0.1.4-pre.5') {
121
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
122
- }
123
- return binding
108
+ return require('@tursodatabase/sync-win32-x64-msvc')
124
109
  } catch (e) {
125
110
  loadErrors.push(e)
126
111
  }
@@ -131,12 +116,7 @@ function requireNative() {
131
116
  loadErrors.push(e)
132
117
  }
133
118
  try {
134
- const binding = require('@tursodatabase/sync-win32-ia32-msvc')
135
- const bindingPackageVersion = require('@tursodatabase/sync-win32-ia32-msvc/package.json').version
136
- if (bindingPackageVersion !== '0.1.4-pre.5') {
137
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
138
- }
139
- return binding
119
+ return require('@tursodatabase/sync-win32-ia32-msvc')
140
120
  } catch (e) {
141
121
  loadErrors.push(e)
142
122
  }
@@ -147,12 +127,7 @@ function requireNative() {
147
127
  loadErrors.push(e)
148
128
  }
149
129
  try {
150
- const binding = require('@tursodatabase/sync-win32-arm64-msvc')
151
- const bindingPackageVersion = require('@tursodatabase/sync-win32-arm64-msvc/package.json').version
152
- if (bindingPackageVersion !== '0.1.4-pre.5') {
153
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
154
- }
155
- return binding
130
+ return require('@tursodatabase/sync-win32-arm64-msvc')
156
131
  } catch (e) {
157
132
  loadErrors.push(e)
158
133
  }
@@ -166,12 +141,7 @@ function requireNative() {
166
141
  loadErrors.push(e)
167
142
  }
168
143
  try {
169
- const binding = require('@tursodatabase/sync-darwin-universal')
170
- const bindingPackageVersion = require('@tursodatabase/sync-darwin-universal/package.json').version
171
- if (bindingPackageVersion !== '0.1.4-pre.5') {
172
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
173
- }
174
- return binding
144
+ return require('@tursodatabase/sync-darwin-universal')
175
145
  } catch (e) {
176
146
  loadErrors.push(e)
177
147
  }
@@ -182,12 +152,7 @@ function requireNative() {
182
152
  loadErrors.push(e)
183
153
  }
184
154
  try {
185
- const binding = require('@tursodatabase/sync-darwin-x64')
186
- const bindingPackageVersion = require('@tursodatabase/sync-darwin-x64/package.json').version
187
- if (bindingPackageVersion !== '0.1.4-pre.5') {
188
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
189
- }
190
- return binding
155
+ return require('@tursodatabase/sync-darwin-x64')
191
156
  } catch (e) {
192
157
  loadErrors.push(e)
193
158
  }
@@ -198,12 +163,7 @@ function requireNative() {
198
163
  loadErrors.push(e)
199
164
  }
200
165
  try {
201
- const binding = require('@tursodatabase/sync-darwin-arm64')
202
- const bindingPackageVersion = require('@tursodatabase/sync-darwin-arm64/package.json').version
203
- if (bindingPackageVersion !== '0.1.4-pre.5') {
204
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
- }
206
- return binding
166
+ return require('@tursodatabase/sync-darwin-arm64')
207
167
  } catch (e) {
208
168
  loadErrors.push(e)
209
169
  }
@@ -218,12 +178,7 @@ function requireNative() {
218
178
  loadErrors.push(e)
219
179
  }
220
180
  try {
221
- const binding = require('@tursodatabase/sync-freebsd-x64')
222
- const bindingPackageVersion = require('@tursodatabase/sync-freebsd-x64/package.json').version
223
- if (bindingPackageVersion !== '0.1.4-pre.5') {
224
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
225
- }
226
- return binding
181
+ return require('@tursodatabase/sync-freebsd-x64')
227
182
  } catch (e) {
228
183
  loadErrors.push(e)
229
184
  }
@@ -234,12 +189,7 @@ function requireNative() {
234
189
  loadErrors.push(e)
235
190
  }
236
191
  try {
237
- const binding = require('@tursodatabase/sync-freebsd-arm64')
238
- const bindingPackageVersion = require('@tursodatabase/sync-freebsd-arm64/package.json').version
239
- if (bindingPackageVersion !== '0.1.4-pre.5') {
240
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
241
- }
242
- return binding
192
+ return require('@tursodatabase/sync-freebsd-arm64')
243
193
  } catch (e) {
244
194
  loadErrors.push(e)
245
195
  }
@@ -255,12 +205,7 @@ function requireNative() {
255
205
  loadErrors.push(e)
256
206
  }
257
207
  try {
258
- const binding = require('@tursodatabase/sync-linux-x64-musl')
259
- const bindingPackageVersion = require('@tursodatabase/sync-linux-x64-musl/package.json').version
260
- if (bindingPackageVersion !== '0.1.4-pre.5') {
261
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
262
- }
263
- return binding
208
+ return require('@tursodatabase/sync-linux-x64-musl')
264
209
  } catch (e) {
265
210
  loadErrors.push(e)
266
211
  }
@@ -271,12 +216,7 @@ function requireNative() {
271
216
  loadErrors.push(e)
272
217
  }
273
218
  try {
274
- const binding = require('@tursodatabase/sync-linux-x64-gnu')
275
- const bindingPackageVersion = require('@tursodatabase/sync-linux-x64-gnu/package.json').version
276
- if (bindingPackageVersion !== '0.1.4-pre.5') {
277
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
278
- }
279
- return binding
219
+ return require('@tursodatabase/sync-linux-x64-gnu')
280
220
  } catch (e) {
281
221
  loadErrors.push(e)
282
222
  }
@@ -289,12 +229,7 @@ function requireNative() {
289
229
  loadErrors.push(e)
290
230
  }
291
231
  try {
292
- const binding = require('@tursodatabase/sync-linux-arm64-musl')
293
- const bindingPackageVersion = require('@tursodatabase/sync-linux-arm64-musl/package.json').version
294
- if (bindingPackageVersion !== '0.1.4-pre.5') {
295
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
- }
297
- return binding
232
+ return require('@tursodatabase/sync-linux-arm64-musl')
298
233
  } catch (e) {
299
234
  loadErrors.push(e)
300
235
  }
@@ -305,12 +240,7 @@ function requireNative() {
305
240
  loadErrors.push(e)
306
241
  }
307
242
  try {
308
- const binding = require('@tursodatabase/sync-linux-arm64-gnu')
309
- const bindingPackageVersion = require('@tursodatabase/sync-linux-arm64-gnu/package.json').version
310
- if (bindingPackageVersion !== '0.1.4-pre.5') {
311
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
312
- }
313
- return binding
243
+ return require('@tursodatabase/sync-linux-arm64-gnu')
314
244
  } catch (e) {
315
245
  loadErrors.push(e)
316
246
  }
@@ -323,12 +253,7 @@ function requireNative() {
323
253
  loadErrors.push(e)
324
254
  }
325
255
  try {
326
- const binding = require('@tursodatabase/sync-linux-arm-musleabihf')
327
- const bindingPackageVersion = require('@tursodatabase/sync-linux-arm-musleabihf/package.json').version
328
- if (bindingPackageVersion !== '0.1.4-pre.5') {
329
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
- }
331
- return binding
256
+ return require('@tursodatabase/sync-linux-arm-musleabihf')
332
257
  } catch (e) {
333
258
  loadErrors.push(e)
334
259
  }
@@ -339,12 +264,7 @@ function requireNative() {
339
264
  loadErrors.push(e)
340
265
  }
341
266
  try {
342
- const binding = require('@tursodatabase/sync-linux-arm-gnueabihf')
343
- const bindingPackageVersion = require('@tursodatabase/sync-linux-arm-gnueabihf/package.json').version
344
- if (bindingPackageVersion !== '0.1.4-pre.5') {
345
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
- }
347
- return binding
267
+ return require('@tursodatabase/sync-linux-arm-gnueabihf')
348
268
  } catch (e) {
349
269
  loadErrors.push(e)
350
270
  }
@@ -357,12 +277,7 @@ function requireNative() {
357
277
  loadErrors.push(e)
358
278
  }
359
279
  try {
360
- const binding = require('@tursodatabase/sync-linux-riscv64-musl')
361
- const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-musl/package.json').version
362
- if (bindingPackageVersion !== '0.1.4-pre.5') {
363
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
- }
365
- return binding
280
+ return require('@tursodatabase/sync-linux-riscv64-musl')
366
281
  } catch (e) {
367
282
  loadErrors.push(e)
368
283
  }
@@ -373,12 +288,7 @@ function requireNative() {
373
288
  loadErrors.push(e)
374
289
  }
375
290
  try {
376
- const binding = require('@tursodatabase/sync-linux-riscv64-gnu')
377
- const bindingPackageVersion = require('@tursodatabase/sync-linux-riscv64-gnu/package.json').version
378
- if (bindingPackageVersion !== '0.1.4-pre.5') {
379
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
- }
381
- return binding
291
+ return require('@tursodatabase/sync-linux-riscv64-gnu')
382
292
  } catch (e) {
383
293
  loadErrors.push(e)
384
294
  }
@@ -390,12 +300,7 @@ function requireNative() {
390
300
  loadErrors.push(e)
391
301
  }
392
302
  try {
393
- const binding = require('@tursodatabase/sync-linux-ppc64-gnu')
394
- const bindingPackageVersion = require('@tursodatabase/sync-linux-ppc64-gnu/package.json').version
395
- if (bindingPackageVersion !== '0.1.4-pre.5') {
396
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
397
- }
398
- return binding
303
+ return require('@tursodatabase/sync-linux-ppc64-gnu')
399
304
  } catch (e) {
400
305
  loadErrors.push(e)
401
306
  }
@@ -406,12 +311,7 @@ function requireNative() {
406
311
  loadErrors.push(e)
407
312
  }
408
313
  try {
409
- const binding = require('@tursodatabase/sync-linux-s390x-gnu')
410
- const bindingPackageVersion = require('@tursodatabase/sync-linux-s390x-gnu/package.json').version
411
- if (bindingPackageVersion !== '0.1.4-pre.5') {
412
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
413
- }
414
- return binding
314
+ return require('@tursodatabase/sync-linux-s390x-gnu')
415
315
  } catch (e) {
416
316
  loadErrors.push(e)
417
317
  }
@@ -421,49 +321,34 @@ function requireNative() {
421
321
  } else if (process.platform === 'openharmony') {
422
322
  if (process.arch === 'arm64') {
423
323
  try {
424
- return require('./turso-sync-js.openharmony-arm64.node')
324
+ return require('./turso-sync-js.linux-arm64-ohos.node')
425
325
  } catch (e) {
426
326
  loadErrors.push(e)
427
327
  }
428
328
  try {
429
- const binding = require('@tursodatabase/sync-openharmony-arm64')
430
- const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm64/package.json').version
431
- if (bindingPackageVersion !== '0.1.4-pre.5') {
432
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
433
- }
434
- return binding
329
+ return require('@tursodatabase/sync-linux-arm64-ohos')
435
330
  } catch (e) {
436
331
  loadErrors.push(e)
437
332
  }
438
333
  } else if (process.arch === 'x64') {
439
334
  try {
440
- return require('./turso-sync-js.openharmony-x64.node')
335
+ return require('./turso-sync-js.linux-x64-ohos.node')
441
336
  } catch (e) {
442
337
  loadErrors.push(e)
443
338
  }
444
339
  try {
445
- const binding = require('@tursodatabase/sync-openharmony-x64')
446
- const bindingPackageVersion = require('@tursodatabase/sync-openharmony-x64/package.json').version
447
- if (bindingPackageVersion !== '0.1.4-pre.5') {
448
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
- }
450
- return binding
340
+ return require('@tursodatabase/sync-linux-x64-ohos')
451
341
  } catch (e) {
452
342
  loadErrors.push(e)
453
343
  }
454
344
  } else if (process.arch === 'arm') {
455
345
  try {
456
- return require('./turso-sync-js.openharmony-arm.node')
346
+ return require('./turso-sync-js.linux-arm-ohos.node')
457
347
  } catch (e) {
458
348
  loadErrors.push(e)
459
349
  }
460
350
  try {
461
- const binding = require('@tursodatabase/sync-openharmony-arm')
462
- const bindingPackageVersion = require('@tursodatabase/sync-openharmony-arm/package.json').version
463
- if (bindingPackageVersion !== '0.1.4-pre.5') {
464
- throw new Error(`Native binding package version mismatch, expected 0.1.4-pre.5 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
- }
466
- return binding
351
+ return require('@tursodatabase/sync-linux-arm-ohos')
467
352
  } catch (e) {
468
353
  loadErrors.push(e)
469
354
  }
@@ -508,7 +393,7 @@ if (!nativeBinding) {
508
393
  throw new Error(`Failed to load native binding`)
509
394
  }
510
395
 
511
- const { Database, Statement, GeneratorHolder, JsDataCompletion, JsDataPollResult, JsProtocolIo, JsProtocolRequestData, SyncEngine } = nativeBinding
396
+ const { Database, Statement, GeneratorHolder, JsDataCompletion, JsDataPollResult, JsProtocolIo, JsProtocolRequestData, SyncEngine, DatabaseChangeTypeJs, SyncEngineProtocolVersion } = nativeBinding
512
397
  export { Database }
513
398
  export { Statement }
514
399
  export { GeneratorHolder }
@@ -517,3 +402,5 @@ export { JsDataPollResult }
517
402
  export { JsProtocolIo }
518
403
  export { JsProtocolRequestData }
519
404
  export { SyncEngine }
405
+ export { DatabaseChangeTypeJs }
406
+ export { SyncEngineProtocolVersion }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tursodatabase/sync",
3
- "version": "0.1.4",
3
+ "version": "0.1.5-pre.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/tursodatabase/turso"
@@ -60,9 +60,9 @@
60
60
  "@tursodatabase/database": "~0.1.4-pre.5"
61
61
  },
62
62
  "optionalDependencies": {
63
- "@tursodatabase/sync-linux-x64-gnu": "0.1.4",
64
- "@tursodatabase/sync-win32-x64-msvc": "0.1.4",
65
- "@tursodatabase/sync-darwin-universal": "0.1.4",
66
- "@tursodatabase/sync-wasm32-wasi": "0.1.4"
63
+ "@tursodatabase/sync-linux-x64-gnu": "0.1.5-pre.2",
64
+ "@tursodatabase/sync-win32-x64-msvc": "0.1.5-pre.2",
65
+ "@tursodatabase/sync-darwin-universal": "0.1.5-pre.2",
66
+ "@tursodatabase/sync-wasm32-wasi": "0.1.5-pre.2"
67
67
  }
68
68
  }