@powersync/node 0.3.0 → 0.4.0
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 +1 -1
- 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,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.0",
|
|
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.29.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.29.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/async-lock": "^1.4.0",
|