@powersync/node 0.3.0 → 0.4.1
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/download_core.js +72 -19
- package/lib/db/PowerSyncDatabase.d.ts +7 -1
- package/lib/db/PowerSyncDatabase.js +4 -1
- package/lib/db/RemoteConnection.d.ts +5 -0
- package/lib/db/RemoteConnection.js +31 -8
- package/lib/libpowersync.so +0 -0
- package/lib/sync/stream/NodeRemote.js +2 -2
- package/package.json +3 -3
package/download_core.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// TODO: Make this a pre-publish hook and just bundle everything
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import * as OS from 'node:os';
|
|
3
4
|
import * as fs from 'node:fs/promises';
|
|
4
5
|
import * as path from 'node:path';
|
|
@@ -6,7 +7,15 @@ import { Readable } from 'node:stream';
|
|
|
6
7
|
import { finished } from 'node:stream/promises';
|
|
7
8
|
import { exit } from 'node:process';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
// When changing this version, run node download_core.js update_hashes
|
|
11
|
+
const version = '0.3.14';
|
|
12
|
+
const versionHashes = {
|
|
13
|
+
'powersync_x64.dll': 'ba0fda2496878d195ea5530562509cc585fa4702fd308594d0eef6f37060dafe',
|
|
14
|
+
'libpowersync_x64.so': '4cee8675b78af786f26f1e1666367de3d228f584084cca257e879060302c1371',
|
|
15
|
+
'libpowersync_aarch64.so': 'ed4ec55cb29ac4b295dc076de71e4247b08d46db562a53e2875cc47420a97a55',
|
|
16
|
+
'libpowersync_x64.dylib': 'cec6fb04732dd8c9a8ec6c6028b1b996965a0a359b0461d7dd6aa885d6eccddf',
|
|
17
|
+
'libpowersync_aarch64.dylib': '55b60e156c3ddc9e7d6fae273943b94b83481c861676c9bcd1e2cfcea02b0a18'
|
|
18
|
+
};
|
|
10
19
|
|
|
11
20
|
const platform = OS.platform();
|
|
12
21
|
let destination;
|
|
@@ -23,24 +32,68 @@ if (platform === 'win32') {
|
|
|
23
32
|
destination = 'libpowersync.dylib';
|
|
24
33
|
}
|
|
25
34
|
|
|
35
|
+
const expectedHash = versionHashes[asset];
|
|
26
36
|
const destinationPath = path.resolve('lib', destination);
|
|
27
|
-
try {
|
|
28
|
-
await fs.access(destinationPath);
|
|
29
|
-
exit(0);
|
|
30
|
-
} catch {}
|
|
31
|
-
|
|
32
|
-
const url = `https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${version}/${asset}`;
|
|
33
|
-
const response = await fetch(url);
|
|
34
|
-
if (response.status != 200) {
|
|
35
|
-
throw `Could not download ${url}`;
|
|
36
|
-
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
await
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
38
|
+
const hashStream = async (input) => {
|
|
39
|
+
for await (const chunk of input.pipe(createHash('sha256')).setEncoding('hex')) {
|
|
40
|
+
return chunk;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const hashLocal = async () => {
|
|
45
|
+
try {
|
|
46
|
+
const handle = await fs.open(destinationPath, 'r');
|
|
47
|
+
const input = handle.createReadStream();
|
|
48
|
+
|
|
49
|
+
const result = await hashStream(input);
|
|
50
|
+
await handle.close();
|
|
51
|
+
return result;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const download = async () => {
|
|
58
|
+
if ((await hashLocal()) == expectedHash) {
|
|
59
|
+
console.debug('Local copy is up-to-date, skipping download');
|
|
60
|
+
exit(0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const url = `https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${version}/${asset}`;
|
|
64
|
+
const response = await fetch(url);
|
|
65
|
+
if (response.status != 200) {
|
|
66
|
+
throw `Could not download ${url}`;
|
|
67
|
+
}
|
|
43
68
|
|
|
44
|
-
|
|
45
|
-
await
|
|
46
|
-
|
|
69
|
+
try {
|
|
70
|
+
await fs.access('lib');
|
|
71
|
+
} catch {
|
|
72
|
+
await fs.mkdir('lib');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const file = await fs.open(destinationPath, 'w');
|
|
76
|
+
await finished(Readable.fromWeb(response.body).pipe(file.createWriteStream()));
|
|
77
|
+
await file.close();
|
|
78
|
+
|
|
79
|
+
const hashAfterDownloading = await hashLocal();
|
|
80
|
+
if (hashAfterDownloading != expectedHash) {
|
|
81
|
+
throw `Unexpected hash after downloading (got ${hashAfterDownloading}, expected ${expectedHash})`;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const updateReferenceHashes = async () => {
|
|
86
|
+
for (const asset of Object.keys(versionHashes)) {
|
|
87
|
+
const url = `https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v${version}/${asset}`;
|
|
88
|
+
const response = await fetch(url);
|
|
89
|
+
const hash = await hashStream(Readable.fromWeb(response.body));
|
|
90
|
+
|
|
91
|
+
console.log(` '${asset}': '${hash}',`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
if (process.argv[process.argv.length - 1] == 'update_hashes') {
|
|
96
|
+
await updateReferenceHashes();
|
|
97
|
+
} else {
|
|
98
|
+
await download();
|
|
99
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import { AbstractPowerSyncDatabase, AbstractStreamingSyncImplementation, AdditionalConnectionOptions, BucketStorageAdapter, DBAdapter, PowerSyncBackendConnector, PowerSyncConnectionOptions, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithSettings, SQLOpenFactory } from '@powersync/common';
|
|
1
|
+
import { AbstractPowerSyncDatabase, AbstractRemoteOptions, AbstractStreamingSyncImplementation, AdditionalConnectionOptions, BucketStorageAdapter, DBAdapter, PowerSyncBackendConnector, PowerSyncConnectionOptions, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithSettings, SQLOpenFactory } from '@powersync/common';
|
|
2
2
|
import { NodeSQLOpenOptions } from './options.js';
|
|
3
3
|
import { Dispatcher } from 'undici';
|
|
4
4
|
export type NodePowerSyncDatabaseOptions = PowerSyncDatabaseOptions & {
|
|
5
5
|
database: DBAdapter | SQLOpenFactory | NodeSQLOpenOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Options to override how the SDK will connect to the sync service.
|
|
8
|
+
*
|
|
9
|
+
* This option is intended to be used for internal tests.
|
|
10
|
+
*/
|
|
11
|
+
remoteOptions?: Partial<AbstractRemoteOptions>;
|
|
6
12
|
};
|
|
7
13
|
export type NodeAdditionalConnectionOptions = AdditionalConnectionOptions & {
|
|
8
14
|
/**
|
|
@@ -36,7 +36,10 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
36
36
|
return super.connect(connector, options);
|
|
37
37
|
}
|
|
38
38
|
generateSyncStreamImplementation(connector, options) {
|
|
39
|
-
const remote = new NodeRemote(connector, this.options.logger, {
|
|
39
|
+
const remote = new NodeRemote(connector, this.options.logger, {
|
|
40
|
+
dispatcher: options.dispatcher,
|
|
41
|
+
...this.options.remoteOptions
|
|
42
|
+
});
|
|
40
43
|
return new NodeStreamingSyncImplementation({
|
|
41
44
|
adapter: this.bucketStorageAdapter,
|
|
42
45
|
remote,
|
|
@@ -11,6 +11,11 @@ export declare class RemoteConnection implements LockContext {
|
|
|
11
11
|
private readonly comlink;
|
|
12
12
|
readonly database: Remote<AsyncDatabase>;
|
|
13
13
|
constructor(worker: Worker, comlink: Remote<AsyncDatabaseOpener>, database: Remote<AsyncDatabase>);
|
|
14
|
+
/**
|
|
15
|
+
* Runs the inner function, but appends the stack trace where this function was called. This is useful for workers
|
|
16
|
+
* because stack traces from worker errors are otherwise unrelated to the application issue that has caused them.
|
|
17
|
+
*/
|
|
18
|
+
private recoverTrace;
|
|
14
19
|
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
15
20
|
execute(query: string, params?: any[] | undefined): Promise<QueryResult>;
|
|
16
21
|
executeRaw(query: string, params?: any[] | undefined): Promise<any[][]>;
|
|
@@ -12,16 +12,39 @@ export class RemoteConnection {
|
|
|
12
12
|
this.comlink = comlink;
|
|
13
13
|
this.database = database;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Runs the inner function, but appends the stack trace where this function was called. This is useful for workers
|
|
17
|
+
* because stack traces from worker errors are otherwise unrelated to the application issue that has caused them.
|
|
18
|
+
*/
|
|
19
|
+
async recoverTrace(inner) {
|
|
20
|
+
const trace = {};
|
|
21
|
+
Error.captureStackTrace(trace);
|
|
22
|
+
try {
|
|
23
|
+
return await inner();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
if (e instanceof Error && e.stack) {
|
|
27
|
+
e.stack += trace.stack;
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
executeBatch(query, params = []) {
|
|
33
|
+
return this.recoverTrace(async () => {
|
|
34
|
+
const result = await this.database.executeBatch(query, params ?? []);
|
|
35
|
+
return RemoteConnection.wrapQueryResult(result);
|
|
36
|
+
});
|
|
18
37
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
execute(query, params) {
|
|
39
|
+
return this.recoverTrace(async () => {
|
|
40
|
+
const result = await this.database.execute(query, params ?? []);
|
|
41
|
+
return RemoteConnection.wrapQueryResult(result);
|
|
42
|
+
});
|
|
22
43
|
}
|
|
23
|
-
|
|
24
|
-
return
|
|
44
|
+
executeRaw(query, params) {
|
|
45
|
+
return this.recoverTrace(async () => {
|
|
46
|
+
return await this.database.executeRaw(query, params ?? []);
|
|
47
|
+
});
|
|
25
48
|
}
|
|
26
49
|
async getAll(sql, parameters) {
|
|
27
50
|
const res = await this.execute(sql, parameters);
|
package/lib/libpowersync.so
CHANGED
|
Binary file
|
|
@@ -17,11 +17,11 @@ export class NodeRemote extends AbstractRemote {
|
|
|
17
17
|
// EnvHttpProxyAgent automatically uses relevant env vars for HTTP
|
|
18
18
|
const dispatcher = options?.dispatcher ?? new EnvHttpProxyAgent();
|
|
19
19
|
super(connector, logger, {
|
|
20
|
-
...(options ?? {}),
|
|
21
20
|
fetchImplementation: options?.fetchImplementation ?? new NodeFetchProvider(),
|
|
22
21
|
fetchOptions: {
|
|
23
22
|
dispatcher
|
|
24
|
-
}
|
|
23
|
+
},
|
|
24
|
+
...(options ?? {})
|
|
25
25
|
});
|
|
26
26
|
this.connector = connector;
|
|
27
27
|
this.logger = logger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/node",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://docs.powersync.com/",
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@powersync/common": "^1.
|
|
39
|
+
"@powersync/common": "^1.30.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@powersync/better-sqlite3": "^0.1.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"proxy-agent": "^6.5.0",
|
|
47
47
|
"undici": "^7.8.0",
|
|
48
48
|
"ws": "^8.18.1",
|
|
49
|
-
"@powersync/common": "1.
|
|
49
|
+
"@powersync/common": "1.30.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/async-lock": "^1.4.0",
|