@tursodatabase/sync 0.1.4-pre.10
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 +60 -0
- package/browser.js +1 -0
- package/dist/sync_engine.d.ts +15 -0
- package/dist/sync_engine.js +135 -0
- package/index.js +519 -0
- package/package.json +68 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">Turso Sync for JavaScript</h1>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a title="JavaScript" target="_blank" href="https://www.npmjs.com/package/@tursodatabase/sync"><img alt="npm" src="https://img.shields.io/npm/v/@tursodatabase/sync"></a>
|
|
7
|
+
<a title="MIT" target="_blank" href="https://github.com/tursodatabase/turso/blob/main/LICENSE.md"><img src="http://img.shields.io/badge/license-MIT-orange.svg?style=flat-square"></a>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a title="Users Discord" target="_blank" href="https://tur.so/discord"><img alt="Chat with other users of Turso on Discord" src="https://img.shields.io/discord/933071162680958986?label=Discord&logo=Discord&style=social"></a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## About
|
|
16
|
+
|
|
17
|
+
This package is for syncing local Turso databases to the Turso Cloud and back.
|
|
18
|
+
|
|
19
|
+
> **⚠️ Warning:** This software is ALPHA, only use for development, testing, and experimentation. We are working to make it production ready, but do not use it for critical data right now.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @tursodatabase/sync
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Getting Started
|
|
28
|
+
|
|
29
|
+
To sync a database hosted at [Turso Cloud](https://turso.tech):
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import { connect } from '@tursodatabase/sync';
|
|
33
|
+
|
|
34
|
+
const db = await connect({
|
|
35
|
+
path: 'local.db', // path used as a prefix for local files created by sync-engine
|
|
36
|
+
url: 'https://<db>.turso.io', // URL of the remote database: turso db show <db>
|
|
37
|
+
authToken: '...', // auth token issued from the Turso Cloud: turso db tokens create <db>
|
|
38
|
+
clientName: 'turso-sync-example' // arbitrary client name
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// db has same functions as Database class from @tursodatabase/database package but adds few more methods for sync:
|
|
42
|
+
await db.pull(); // pull changes from the remote
|
|
43
|
+
await db.push(); // push changes to the remote
|
|
44
|
+
await db.sync(); // pull & push changes
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Related Packages
|
|
48
|
+
|
|
49
|
+
* The [@tursodatabase/database](https://www.npmjs.com/package/@tursodatabase/database) package provides the Turso in-memory database, compatible with SQLite.
|
|
50
|
+
* The [@tursodatabase/serverless](https://www.npmjs.com/package/@tursodatabase/serverless) package provides a serverless driver with the same API.
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
This project is licensed under the [MIT license](../../LICENSE.md).
|
|
55
|
+
|
|
56
|
+
## Support
|
|
57
|
+
|
|
58
|
+
- [GitHub Issues](https://github.com/tursodatabase/turso/issues)
|
|
59
|
+
- [Documentation](https://docs.turso.tech)
|
|
60
|
+
- [Discord Community](https://tur.so/discord)
|
package/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@tursodatabase/sync-wasm32-wasi'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Database } from '@tursodatabase/database';
|
|
2
|
+
interface ConnectOpts {
|
|
3
|
+
path: string;
|
|
4
|
+
clientName?: string;
|
|
5
|
+
url: string;
|
|
6
|
+
authToken?: string;
|
|
7
|
+
encryptionKey?: string;
|
|
8
|
+
}
|
|
9
|
+
interface Sync {
|
|
10
|
+
sync(): Promise<void>;
|
|
11
|
+
push(): Promise<void>;
|
|
12
|
+
pull(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare function connect(opts: ConnectOpts): Database & Sync;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { SyncEngine } from '#entry-point';
|
|
3
|
+
import { Database } from '@tursodatabase/database';
|
|
4
|
+
const GENERATOR_RESUME_IO = 0;
|
|
5
|
+
const GENERATOR_RESUME_DONE = 1;
|
|
6
|
+
function trackPromise(p) {
|
|
7
|
+
let status = { promise: null, finished: false };
|
|
8
|
+
status.promise = p.finally(() => status.finished = true);
|
|
9
|
+
return status;
|
|
10
|
+
}
|
|
11
|
+
function timeoutMs(ms) {
|
|
12
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
13
|
+
}
|
|
14
|
+
async function read(opts, path) {
|
|
15
|
+
if (opts.isMemory) {
|
|
16
|
+
return opts.value;
|
|
17
|
+
}
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
const { promises } = await import('node:fs');
|
|
20
|
+
try {
|
|
21
|
+
return await promises.readFile(path);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code === 'ENOENT') {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const data = localStorage.getItem(path);
|
|
32
|
+
if (data != null) {
|
|
33
|
+
return new TextEncoder().encode(data);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function write(opts, path, content) {
|
|
41
|
+
if (opts.isMemory) {
|
|
42
|
+
opts.value = content;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const data = new Uint8Array(content);
|
|
46
|
+
if (typeof window === 'undefined') {
|
|
47
|
+
const { promises } = await import('node:fs');
|
|
48
|
+
const unix = Math.floor(Date.now() / 1000);
|
|
49
|
+
const nonce = Math.floor(Math.random() * 1000000000);
|
|
50
|
+
const tmp = `${path}.tmp.${unix}.${nonce}`;
|
|
51
|
+
await promises.writeFile(tmp, data);
|
|
52
|
+
await promises.rename(tmp, path);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
localStorage.setItem(path, new TextDecoder().decode(data));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function process(opts, request) {
|
|
59
|
+
const requestType = request.request();
|
|
60
|
+
const completion = request.completion();
|
|
61
|
+
if (requestType.type == 'Http') {
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch(`${opts.url}${requestType.path}`, {
|
|
64
|
+
method: requestType.method,
|
|
65
|
+
headers: opts.headers,
|
|
66
|
+
body: requestType.body != null ? new Uint8Array(requestType.body) : null,
|
|
67
|
+
});
|
|
68
|
+
completion.status(response.status);
|
|
69
|
+
const reader = response.body.getReader();
|
|
70
|
+
while (true) {
|
|
71
|
+
const { done, value } = await reader.read();
|
|
72
|
+
if (done) {
|
|
73
|
+
completion.done();
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
completion.push(value);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
completion.poison(`fetch error: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (requestType.type == 'FullRead') {
|
|
84
|
+
try {
|
|
85
|
+
const metadata = await read(opts.metadata, requestType.path);
|
|
86
|
+
if (metadata != null) {
|
|
87
|
+
completion.push(metadata);
|
|
88
|
+
}
|
|
89
|
+
completion.done();
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
completion.poison(`metadata read error: ${error}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (requestType.type == 'FullWrite') {
|
|
96
|
+
try {
|
|
97
|
+
await write(opts.metadata, requestType.path, requestType.content);
|
|
98
|
+
completion.done();
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
completion.poison(`metadata write error: ${error}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function run(opts, engine, generator) {
|
|
106
|
+
let tasks = [];
|
|
107
|
+
while (generator.resume(null) !== GENERATOR_RESUME_DONE) {
|
|
108
|
+
for (let request = engine.protocolIo(); request != null; request = engine.protocolIo()) {
|
|
109
|
+
tasks.push(trackPromise(process(opts, request)));
|
|
110
|
+
}
|
|
111
|
+
const tasksRace = tasks.length == 0 ? Promise.resolve() : Promise.race([timeoutMs(opts.preemptionMs), ...tasks.map(t => t.promise)]);
|
|
112
|
+
await Promise.all([engine.ioLoopAsync(), tasksRace]);
|
|
113
|
+
tasks = tasks.filter(t => !t.finished);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function connect(opts) {
|
|
117
|
+
const engine = new SyncEngine({ path: opts.path, clientName: opts.clientName });
|
|
118
|
+
const httpOpts = {
|
|
119
|
+
url: opts.url,
|
|
120
|
+
headers: {
|
|
121
|
+
...(opts.authToken != null && { "Authorization": `Bearer ${opts.authToken}` }),
|
|
122
|
+
...(opts.encryptionKey != null && { "x-turso-encryption-key": opts.encryptionKey })
|
|
123
|
+
},
|
|
124
|
+
metadata: opts.path == ':memory:' ? { isMemory: true, value: null } : { isMemory: false },
|
|
125
|
+
preemptionMs: 1,
|
|
126
|
+
};
|
|
127
|
+
await run(httpOpts, engine, engine.init());
|
|
128
|
+
const nativeDb = engine.open();
|
|
129
|
+
const db = Database.create();
|
|
130
|
+
db.initialize(nativeDb, opts.path, false);
|
|
131
|
+
db.sync = async function () { await run(httpOpts, engine, engine.sync()); };
|
|
132
|
+
db.pull = async function () { await run(httpOpts, engine, engine.pull()); };
|
|
133
|
+
db.push = async function () { await run(httpOpts, engine, engine.push()); };
|
|
134
|
+
return db;
|
|
135
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
const __dirname = new URL('.', import.meta.url).pathname
|
|
9
|
+
|
|
10
|
+
const { readFileSync } = require('node:fs')
|
|
11
|
+
let nativeBinding = null
|
|
12
|
+
const loadErrors = []
|
|
13
|
+
|
|
14
|
+
const isMusl = () => {
|
|
15
|
+
let musl = false
|
|
16
|
+
if (process.platform === 'linux') {
|
|
17
|
+
musl = isMuslFromFilesystem()
|
|
18
|
+
if (musl === null) {
|
|
19
|
+
musl = isMuslFromReport()
|
|
20
|
+
}
|
|
21
|
+
if (musl === null) {
|
|
22
|
+
musl = isMuslFromChildProcess()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return musl
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
29
|
+
|
|
30
|
+
const isMuslFromFilesystem = () => {
|
|
31
|
+
try {
|
|
32
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
33
|
+
} catch {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isMuslFromReport = () => {
|
|
39
|
+
let report = null
|
|
40
|
+
if (typeof process.report?.getReport === 'function') {
|
|
41
|
+
process.report.excludeNetwork = true
|
|
42
|
+
report = process.report.getReport()
|
|
43
|
+
}
|
|
44
|
+
if (!report) {
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
51
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const isMuslFromChildProcess = () => {
|
|
59
|
+
try {
|
|
60
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function requireNative() {
|
|
68
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
69
|
+
try {
|
|
70
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
loadErrors.push(err)
|
|
73
|
+
}
|
|
74
|
+
} else if (process.platform === 'android') {
|
|
75
|
+
if (process.arch === 'arm64') {
|
|
76
|
+
try {
|
|
77
|
+
return require('./turso-sync-js.android-arm64.node')
|
|
78
|
+
} catch (e) {
|
|
79
|
+
loadErrors.push(e)
|
|
80
|
+
}
|
|
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
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadErrors.push(e)
|
|
90
|
+
}
|
|
91
|
+
} else if (process.arch === 'arm') {
|
|
92
|
+
try {
|
|
93
|
+
return require('./turso-sync-js.android-arm-eabi.node')
|
|
94
|
+
} catch (e) {
|
|
95
|
+
loadErrors.push(e)
|
|
96
|
+
}
|
|
97
|
+
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
|
|
104
|
+
} catch (e) {
|
|
105
|
+
loadErrors.push(e)
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
109
|
+
}
|
|
110
|
+
} else if (process.platform === 'win32') {
|
|
111
|
+
if (process.arch === 'x64') {
|
|
112
|
+
try {
|
|
113
|
+
return require('./turso-sync-js.win32-x64-msvc.node')
|
|
114
|
+
} catch (e) {
|
|
115
|
+
loadErrors.push(e)
|
|
116
|
+
}
|
|
117
|
+
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
|
|
124
|
+
} catch (e) {
|
|
125
|
+
loadErrors.push(e)
|
|
126
|
+
}
|
|
127
|
+
} else if (process.arch === 'ia32') {
|
|
128
|
+
try {
|
|
129
|
+
return require('./turso-sync-js.win32-ia32-msvc.node')
|
|
130
|
+
} catch (e) {
|
|
131
|
+
loadErrors.push(e)
|
|
132
|
+
}
|
|
133
|
+
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
|
|
140
|
+
} catch (e) {
|
|
141
|
+
loadErrors.push(e)
|
|
142
|
+
}
|
|
143
|
+
} else if (process.arch === 'arm64') {
|
|
144
|
+
try {
|
|
145
|
+
return require('./turso-sync-js.win32-arm64-msvc.node')
|
|
146
|
+
} catch (e) {
|
|
147
|
+
loadErrors.push(e)
|
|
148
|
+
}
|
|
149
|
+
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
|
|
156
|
+
} catch (e) {
|
|
157
|
+
loadErrors.push(e)
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
161
|
+
}
|
|
162
|
+
} else if (process.platform === 'darwin') {
|
|
163
|
+
try {
|
|
164
|
+
return require('./turso-sync-js.darwin-universal.node')
|
|
165
|
+
} catch (e) {
|
|
166
|
+
loadErrors.push(e)
|
|
167
|
+
}
|
|
168
|
+
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
|
|
175
|
+
} catch (e) {
|
|
176
|
+
loadErrors.push(e)
|
|
177
|
+
}
|
|
178
|
+
if (process.arch === 'x64') {
|
|
179
|
+
try {
|
|
180
|
+
return require('./turso-sync-js.darwin-x64.node')
|
|
181
|
+
} catch (e) {
|
|
182
|
+
loadErrors.push(e)
|
|
183
|
+
}
|
|
184
|
+
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
|
|
191
|
+
} catch (e) {
|
|
192
|
+
loadErrors.push(e)
|
|
193
|
+
}
|
|
194
|
+
} else if (process.arch === 'arm64') {
|
|
195
|
+
try {
|
|
196
|
+
return require('./turso-sync-js.darwin-arm64.node')
|
|
197
|
+
} catch (e) {
|
|
198
|
+
loadErrors.push(e)
|
|
199
|
+
}
|
|
200
|
+
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
|
|
207
|
+
} catch (e) {
|
|
208
|
+
loadErrors.push(e)
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
212
|
+
}
|
|
213
|
+
} else if (process.platform === 'freebsd') {
|
|
214
|
+
if (process.arch === 'x64') {
|
|
215
|
+
try {
|
|
216
|
+
return require('./turso-sync-js.freebsd-x64.node')
|
|
217
|
+
} catch (e) {
|
|
218
|
+
loadErrors.push(e)
|
|
219
|
+
}
|
|
220
|
+
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
|
|
227
|
+
} catch (e) {
|
|
228
|
+
loadErrors.push(e)
|
|
229
|
+
}
|
|
230
|
+
} else if (process.arch === 'arm64') {
|
|
231
|
+
try {
|
|
232
|
+
return require('./turso-sync-js.freebsd-arm64.node')
|
|
233
|
+
} catch (e) {
|
|
234
|
+
loadErrors.push(e)
|
|
235
|
+
}
|
|
236
|
+
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
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadErrors.push(e)
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
248
|
+
}
|
|
249
|
+
} else if (process.platform === 'linux') {
|
|
250
|
+
if (process.arch === 'x64') {
|
|
251
|
+
if (isMusl()) {
|
|
252
|
+
try {
|
|
253
|
+
return require('./turso-sync-js.linux-x64-musl.node')
|
|
254
|
+
} catch (e) {
|
|
255
|
+
loadErrors.push(e)
|
|
256
|
+
}
|
|
257
|
+
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
|
|
264
|
+
} catch (e) {
|
|
265
|
+
loadErrors.push(e)
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
try {
|
|
269
|
+
return require('./turso-sync-js.linux-x64-gnu.node')
|
|
270
|
+
} catch (e) {
|
|
271
|
+
loadErrors.push(e)
|
|
272
|
+
}
|
|
273
|
+
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
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} else if (process.arch === 'arm64') {
|
|
285
|
+
if (isMusl()) {
|
|
286
|
+
try {
|
|
287
|
+
return require('./turso-sync-js.linux-arm64-musl.node')
|
|
288
|
+
} catch (e) {
|
|
289
|
+
loadErrors.push(e)
|
|
290
|
+
}
|
|
291
|
+
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
|
|
298
|
+
} catch (e) {
|
|
299
|
+
loadErrors.push(e)
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
try {
|
|
303
|
+
return require('./turso-sync-js.linux-arm64-gnu.node')
|
|
304
|
+
} catch (e) {
|
|
305
|
+
loadErrors.push(e)
|
|
306
|
+
}
|
|
307
|
+
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
|
|
314
|
+
} catch (e) {
|
|
315
|
+
loadErrors.push(e)
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
} else if (process.arch === 'arm') {
|
|
319
|
+
if (isMusl()) {
|
|
320
|
+
try {
|
|
321
|
+
return require('./turso-sync-js.linux-arm-musleabihf.node')
|
|
322
|
+
} catch (e) {
|
|
323
|
+
loadErrors.push(e)
|
|
324
|
+
}
|
|
325
|
+
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
|
|
332
|
+
} catch (e) {
|
|
333
|
+
loadErrors.push(e)
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
try {
|
|
337
|
+
return require('./turso-sync-js.linux-arm-gnueabihf.node')
|
|
338
|
+
} catch (e) {
|
|
339
|
+
loadErrors.push(e)
|
|
340
|
+
}
|
|
341
|
+
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
|
|
348
|
+
} catch (e) {
|
|
349
|
+
loadErrors.push(e)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
} else if (process.arch === 'riscv64') {
|
|
353
|
+
if (isMusl()) {
|
|
354
|
+
try {
|
|
355
|
+
return require('./turso-sync-js.linux-riscv64-musl.node')
|
|
356
|
+
} catch (e) {
|
|
357
|
+
loadErrors.push(e)
|
|
358
|
+
}
|
|
359
|
+
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
|
|
366
|
+
} catch (e) {
|
|
367
|
+
loadErrors.push(e)
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
try {
|
|
371
|
+
return require('./turso-sync-js.linux-riscv64-gnu.node')
|
|
372
|
+
} catch (e) {
|
|
373
|
+
loadErrors.push(e)
|
|
374
|
+
}
|
|
375
|
+
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
|
|
382
|
+
} catch (e) {
|
|
383
|
+
loadErrors.push(e)
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
} else if (process.arch === 'ppc64') {
|
|
387
|
+
try {
|
|
388
|
+
return require('./turso-sync-js.linux-ppc64-gnu.node')
|
|
389
|
+
} catch (e) {
|
|
390
|
+
loadErrors.push(e)
|
|
391
|
+
}
|
|
392
|
+
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
|
|
399
|
+
} catch (e) {
|
|
400
|
+
loadErrors.push(e)
|
|
401
|
+
}
|
|
402
|
+
} else if (process.arch === 's390x') {
|
|
403
|
+
try {
|
|
404
|
+
return require('./turso-sync-js.linux-s390x-gnu.node')
|
|
405
|
+
} catch (e) {
|
|
406
|
+
loadErrors.push(e)
|
|
407
|
+
}
|
|
408
|
+
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
|
|
415
|
+
} catch (e) {
|
|
416
|
+
loadErrors.push(e)
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
420
|
+
}
|
|
421
|
+
} else if (process.platform === 'openharmony') {
|
|
422
|
+
if (process.arch === 'arm64') {
|
|
423
|
+
try {
|
|
424
|
+
return require('./turso-sync-js.openharmony-arm64.node')
|
|
425
|
+
} catch (e) {
|
|
426
|
+
loadErrors.push(e)
|
|
427
|
+
}
|
|
428
|
+
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
|
|
435
|
+
} catch (e) {
|
|
436
|
+
loadErrors.push(e)
|
|
437
|
+
}
|
|
438
|
+
} else if (process.arch === 'x64') {
|
|
439
|
+
try {
|
|
440
|
+
return require('./turso-sync-js.openharmony-x64.node')
|
|
441
|
+
} catch (e) {
|
|
442
|
+
loadErrors.push(e)
|
|
443
|
+
}
|
|
444
|
+
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
|
|
451
|
+
} catch (e) {
|
|
452
|
+
loadErrors.push(e)
|
|
453
|
+
}
|
|
454
|
+
} else if (process.arch === 'arm') {
|
|
455
|
+
try {
|
|
456
|
+
return require('./turso-sync-js.openharmony-arm.node')
|
|
457
|
+
} catch (e) {
|
|
458
|
+
loadErrors.push(e)
|
|
459
|
+
}
|
|
460
|
+
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
|
|
467
|
+
} catch (e) {
|
|
468
|
+
loadErrors.push(e)
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
472
|
+
}
|
|
473
|
+
} else {
|
|
474
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
nativeBinding = requireNative()
|
|
479
|
+
|
|
480
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
481
|
+
try {
|
|
482
|
+
nativeBinding = require('./turso-sync-js.wasi.cjs')
|
|
483
|
+
} catch (err) {
|
|
484
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
485
|
+
loadErrors.push(err)
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (!nativeBinding) {
|
|
489
|
+
try {
|
|
490
|
+
nativeBinding = require('@tursodatabase/sync-wasm32-wasi')
|
|
491
|
+
} catch (err) {
|
|
492
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
493
|
+
loadErrors.push(err)
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (!nativeBinding) {
|
|
500
|
+
if (loadErrors.length > 0) {
|
|
501
|
+
throw new Error(
|
|
502
|
+
`Cannot find native binding. ` +
|
|
503
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
504
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
505
|
+
{ cause: loadErrors }
|
|
506
|
+
)
|
|
507
|
+
}
|
|
508
|
+
throw new Error(`Failed to load native binding`)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const { Database, Statement, GeneratorHolder, JsDataCompletion, JsDataPollResult, JsProtocolIo, JsProtocolRequestData, SyncEngine } = nativeBinding
|
|
512
|
+
export { Database }
|
|
513
|
+
export { Statement }
|
|
514
|
+
export { GeneratorHolder }
|
|
515
|
+
export { JsDataCompletion }
|
|
516
|
+
export { JsDataPollResult }
|
|
517
|
+
export { JsProtocolIo }
|
|
518
|
+
export { JsProtocolRequestData }
|
|
519
|
+
export { SyncEngine }
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tursodatabase/sync",
|
|
3
|
+
"version": "0.1.4-pre.10",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/tursodatabase/turso"
|
|
7
|
+
},
|
|
8
|
+
"description": "Sync engine for the Turso database library",
|
|
9
|
+
"module": "./dist/sync_engine.js",
|
|
10
|
+
"main": "./dist/sync_engine.js",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": "./dist/sync_engine.js",
|
|
13
|
+
"files": [
|
|
14
|
+
"browser.js",
|
|
15
|
+
"index.js",
|
|
16
|
+
"dist/**"
|
|
17
|
+
],
|
|
18
|
+
"types": "./dist/sync_engine.d.ts",
|
|
19
|
+
"napi": {
|
|
20
|
+
"binaryName": "turso-sync-js",
|
|
21
|
+
"targets": [
|
|
22
|
+
"x86_64-unknown-linux-gnu",
|
|
23
|
+
"x86_64-pc-windows-msvc",
|
|
24
|
+
"universal-apple-darwin",
|
|
25
|
+
"wasm32-wasip1-threads"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@napi-rs/cli": "^3.0.4",
|
|
31
|
+
"@napi-rs/wasm-runtime": "^1.0.1",
|
|
32
|
+
"@types/node": "^24.2.0",
|
|
33
|
+
"ava": "^6.0.1",
|
|
34
|
+
"typescript": "^5.9.2"
|
|
35
|
+
},
|
|
36
|
+
"ava": {
|
|
37
|
+
"timeout": "3m"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">= 10"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"artifacts": "napi artifacts",
|
|
44
|
+
"build": "npm exec tsc && napi build --platform --release --esm",
|
|
45
|
+
"build:debug": "npm exec tsc && napi build --platform",
|
|
46
|
+
"prepublishOnly": "npm exec tsc && napi prepublish -t npm",
|
|
47
|
+
"test": "true",
|
|
48
|
+
"universal": "napi universalize",
|
|
49
|
+
"version": "napi version"
|
|
50
|
+
},
|
|
51
|
+
"packageManager": "yarn@4.9.2",
|
|
52
|
+
"imports": {
|
|
53
|
+
"#entry-point": {
|
|
54
|
+
"types": "./index.d.ts",
|
|
55
|
+
"browser": "./browser.js",
|
|
56
|
+
"node": "./index.js"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@tursodatabase/database": "~0.1.4-pre.5"
|
|
61
|
+
},
|
|
62
|
+
"optionalDependencies": {
|
|
63
|
+
"@tursodatabase/sync-linux-x64-gnu": "0.1.4-pre.10",
|
|
64
|
+
"@tursodatabase/sync-win32-x64-msvc": "0.1.4-pre.10",
|
|
65
|
+
"@tursodatabase/sync-darwin-universal": "0.1.4-pre.10",
|
|
66
|
+
"@tursodatabase/sync-wasm32-wasi": "0.1.4-pre.10"
|
|
67
|
+
}
|
|
68
|
+
}
|