@powersync/common 0.0.0-dev-20240723112746 → 0.0.0-dev-20240726145618
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/lib/client/AbstractPowerSyncDatabase.d.ts +8 -3
- package/lib/client/AbstractPowerSyncDatabase.js +11 -5
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -1
- package/lib/client/SQLOpenFactory.d.ts +10 -0
- package/lib/client/SQLOpenFactory.js +0 -1
- package/lib/client/connection/PowerSyncBackendConnector.js +0 -1
- package/lib/client/connection/PowerSyncCredentials.js +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -1
- package/lib/client/sync/bucket/CrudBatch.js +0 -1
- package/lib/client/sync/bucket/CrudEntry.js +0 -1
- package/lib/client/sync/bucket/CrudTransaction.js +0 -1
- package/lib/client/sync/bucket/OpType.js +0 -1
- package/lib/client/sync/bucket/OplogEntry.js +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -1
- package/lib/client/sync/bucket/SyncDataBatch.js +0 -1
- package/lib/client/sync/bucket/SyncDataBucket.js +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +1 -1
- package/lib/client/sync/stream/AbstractRemote.js +15 -9
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -1
- package/lib/client/sync/stream/streaming-sync-types.js +0 -1
- package/lib/db/Column.js +0 -1
- package/lib/db/DBAdapter.js +0 -1
- package/lib/db/crud/SyncStatus.js +0 -1
- package/lib/db/crud/UploadQueueStatus.js +0 -1
- package/lib/db/schema/Index.js +0 -1
- package/lib/db/schema/IndexedColumn.js +0 -1
- package/lib/db/schema/Schema.js +0 -1
- package/lib/db/schema/Table.js +0 -1
- package/lib/db/schema/TableV2.js +0 -1
- package/lib/index.js +0 -1
- package/lib/types/types.js +0 -1
- package/lib/utils/AbortOperation.js +0 -1
- package/lib/utils/BaseObserver.js +0 -1
- package/lib/utils/ControlledExecutor.js +0 -1
- package/lib/utils/DataStream.js +0 -1
- package/lib/utils/mutex.js +0 -1
- package/lib/utils/parseQuery.js +0 -1
- package/lib/utils/strings.js +0 -1
- package/package.json +13 -22
- package/dist/index.js +0 -16
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/SQLOpenFactory.js.map +0 -1
- package/lib/client/connection/PowerSyncBackendConnector.js.map +0 -1
- package/lib/client/connection/PowerSyncCredentials.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/CrudBatch.js.map +0 -1
- package/lib/client/sync/bucket/CrudEntry.js.map +0 -1
- package/lib/client/sync/bucket/CrudTransaction.js.map +0 -1
- package/lib/client/sync/bucket/OpType.js.map +0 -1
- package/lib/client/sync/bucket/OplogEntry.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBatch.js.map +0 -1
- package/lib/client/sync/bucket/SyncDataBucket.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/streaming-sync-types.js.map +0 -1
- package/lib/db/Column.js.map +0 -1
- package/lib/db/DBAdapter.js.map +0 -1
- package/lib/db/crud/SyncStatus.js.map +0 -1
- package/lib/db/crud/UploadQueueStatus.js.map +0 -1
- package/lib/db/schema/Index.js.map +0 -1
- package/lib/db/schema/IndexedColumn.js.map +0 -1
- package/lib/db/schema/Schema.js.map +0 -1
- package/lib/db/schema/Table.js.map +0 -1
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/types.js.map +0 -1
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/BaseObserver.js.map +0 -1
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/DataStream.js.map +0 -1
- package/lib/utils/mutex.js.map +0 -1
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/strings.js.map +0 -1
|
@@ -5,12 +5,12 @@ import { SyncStatus } from '../db/crud/SyncStatus';
|
|
|
5
5
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus';
|
|
6
6
|
import { Schema } from '../db/schema/Schema';
|
|
7
7
|
import { BaseObserver } from '../utils/BaseObserver';
|
|
8
|
+
import { SQLOpenFactory, SQLOpenOptions } from './SQLOpenFactory';
|
|
8
9
|
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector';
|
|
9
10
|
import { BucketStorageAdapter } from './sync/bucket/BucketStorageAdapter';
|
|
10
11
|
import { CrudBatch } from './sync/bucket/CrudBatch';
|
|
11
12
|
import { CrudTransaction } from './sync/bucket/CrudTransaction';
|
|
12
|
-
import { AbstractStreamingSyncImplementation,
|
|
13
|
-
import { SQLOpenFactory, SQLOpenOptions } from './SQLOpenFactory';
|
|
13
|
+
import { AbstractStreamingSyncImplementation, PowerSyncConnectionOptions, StreamingSyncImplementation, StreamingSyncImplementationListener } from './sync/stream/AbstractStreamingSyncImplementation';
|
|
14
14
|
export interface DisconnectAndClearOptions {
|
|
15
15
|
/** When set to false, data in local-only tables is preserved. */
|
|
16
16
|
clearLocal?: boolean;
|
|
@@ -96,6 +96,11 @@ export declare const DEFAULT_POWERSYNC_DB_OPTIONS: {
|
|
|
96
96
|
* be obtained.
|
|
97
97
|
*/
|
|
98
98
|
export declare const DEFAULT_LOCK_TIMEOUT_MS = 120000;
|
|
99
|
+
/**
|
|
100
|
+
* Tests if the input is a {@link PowerSyncDatabaseOptionsWithSettings}
|
|
101
|
+
* @internal
|
|
102
|
+
*/
|
|
103
|
+
export declare const isPowerSyncDatabaseOptionsWithSettings: (test: any) => test is PowerSyncDatabaseOptionsWithSettings;
|
|
99
104
|
export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDBListener> {
|
|
100
105
|
protected options: PowerSyncDatabaseOptions;
|
|
101
106
|
/**
|
|
@@ -143,7 +148,7 @@ export declare abstract class AbstractPowerSyncDatabase extends BaseObserver<Pow
|
|
|
143
148
|
/**
|
|
144
149
|
* Opens the DBAdapter given open options using a default open factory
|
|
145
150
|
*/
|
|
146
|
-
protected abstract openDBAdapter(options:
|
|
151
|
+
protected abstract openDBAdapter(options: PowerSyncDatabaseOptionsWithSettings): DBAdapter;
|
|
147
152
|
protected abstract generateSyncStreamImplementation(connector: PowerSyncBackendConnector): AbstractStreamingSyncImplementation;
|
|
148
153
|
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
|
|
149
154
|
/**
|
|
@@ -6,15 +6,15 @@ import { isBatchedUpdateNotification } from '../db/DBAdapter';
|
|
|
6
6
|
import { SyncStatus } from '../db/crud/SyncStatus';
|
|
7
7
|
import { UploadQueueStats } from '../db/crud/UploadQueueStatus';
|
|
8
8
|
import { BaseObserver } from '../utils/BaseObserver';
|
|
9
|
+
import { ControlledExecutor } from '../utils/ControlledExecutor';
|
|
9
10
|
import { mutexRunExclusive } from '../utils/mutex';
|
|
10
11
|
import { quoteIdentifier } from '../utils/strings';
|
|
12
|
+
import { isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory';
|
|
11
13
|
import { PSInternalTable } from './sync/bucket/BucketStorageAdapter';
|
|
12
14
|
import { CrudBatch } from './sync/bucket/CrudBatch';
|
|
13
15
|
import { CrudEntry } from './sync/bucket/CrudEntry';
|
|
14
16
|
import { CrudTransaction } from './sync/bucket/CrudTransaction';
|
|
15
17
|
import { DEFAULT_CRUD_UPLOAD_THROTTLE_MS } from './sync/stream/AbstractStreamingSyncImplementation';
|
|
16
|
-
import { ControlledExecutor } from '../utils/ControlledExecutor';
|
|
17
|
-
import { isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory';
|
|
18
18
|
const POWERSYNC_TABLE_MATCH = /(^ps_data__|^ps_data_local__)/;
|
|
19
19
|
const DEFAULT_DISCONNECT_CLEAR_OPTIONS = {
|
|
20
20
|
clearLocal: true
|
|
@@ -34,6 +34,13 @@ export const DEFAULT_POWERSYNC_DB_OPTIONS = {
|
|
|
34
34
|
* be obtained.
|
|
35
35
|
*/
|
|
36
36
|
export const DEFAULT_LOCK_TIMEOUT_MS = 120_000; // 2 mins
|
|
37
|
+
/**
|
|
38
|
+
* Tests if the input is a {@link PowerSyncDatabaseOptionsWithSettings}
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export const isPowerSyncDatabaseOptionsWithSettings = (test) => {
|
|
42
|
+
return typeof test == 'object' && isSQLOpenOptions(test.database);
|
|
43
|
+
};
|
|
37
44
|
export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
38
45
|
options;
|
|
39
46
|
/**
|
|
@@ -68,8 +75,8 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
68
75
|
else if (isSQLOpenFactory(database)) {
|
|
69
76
|
this._database = database.openDB();
|
|
70
77
|
}
|
|
71
|
-
else if (
|
|
72
|
-
this._database = this.openDBAdapter(
|
|
78
|
+
else if (isPowerSyncDatabaseOptionsWithSettings(options)) {
|
|
79
|
+
this._database = this.openDBAdapter(options);
|
|
73
80
|
}
|
|
74
81
|
this.bucketStorageAdapter = this.generateBucketStorageAdapter();
|
|
75
82
|
this.closed = false;
|
|
@@ -663,4 +670,3 @@ export class AbstractPowerSyncDatabase extends BaseObserver {
|
|
|
663
670
|
return this.database.readLock((tx) => tx.execute(sql, params));
|
|
664
671
|
}
|
|
665
672
|
}
|
|
666
|
-
//# sourceMappingURL=AbstractPowerSyncDatabase.js.map
|
|
@@ -8,6 +8,16 @@ export interface SQLOpenOptions {
|
|
|
8
8
|
* Directory where the database file is located.
|
|
9
9
|
*/
|
|
10
10
|
dbLocation?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Enable debugMode to log queries to the performance timeline.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to false.
|
|
15
|
+
*
|
|
16
|
+
* To enable in development builds, use:
|
|
17
|
+
*
|
|
18
|
+
* debugMode: process.env.NODE_ENV !== 'production'
|
|
19
|
+
*/
|
|
20
|
+
debugMode?: boolean;
|
|
11
21
|
}
|
|
12
22
|
export interface SQLOpenFactory {
|
|
13
23
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILogger } from 'js-logger';
|
|
2
|
-
import {
|
|
2
|
+
import { fetch } from 'cross-fetch';
|
|
3
3
|
import { PowerSyncCredentials } from '../../connection/PowerSyncCredentials';
|
|
4
4
|
import { StreamingSyncLine, StreamingSyncRequest } from './streaming-sync-types';
|
|
5
5
|
import { DataStream } from '../../../utils/DataStream';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Logger from 'js-logger';
|
|
2
|
+
import { fetch } from 'cross-fetch';
|
|
2
3
|
import { DataStream } from '../../../utils/DataStream';
|
|
3
4
|
import ndjsonStream from 'can-ndjson-stream';
|
|
4
5
|
import { RSocketConnector } from 'rsocket-core';
|
|
@@ -22,7 +23,7 @@ export const DEFAULT_REMOTE_LOGGER = Logger.get('PowerSyncRemote');
|
|
|
22
23
|
*/
|
|
23
24
|
export class FetchImplementationProvider {
|
|
24
25
|
getFetch() {
|
|
25
|
-
|
|
26
|
+
return fetch.bind(globalThis);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
export const DEFAULT_REMOTE_OPTIONS = {
|
|
@@ -82,7 +83,7 @@ export class AbstractRemote {
|
|
|
82
83
|
}
|
|
83
84
|
async post(path, data, headers = {}) {
|
|
84
85
|
const request = await this.buildRequest(path);
|
|
85
|
-
const res = await
|
|
86
|
+
const res = await fetch(request.url, {
|
|
86
87
|
method: 'POST',
|
|
87
88
|
headers: {
|
|
88
89
|
...headers,
|
|
@@ -179,8 +180,16 @@ export class AbstractRemote {
|
|
|
179
180
|
socketIsClosed = true;
|
|
180
181
|
rsocket.close();
|
|
181
182
|
};
|
|
183
|
+
// Helps to prevent double close scenarios
|
|
184
|
+
rsocket.onClose(() => (socketIsClosed = true));
|
|
182
185
|
// We initially request this amount and expect these to arrive eventually
|
|
183
186
|
let pendingEventsCount = SYNC_QUEUE_REQUEST_N;
|
|
187
|
+
const disposeClosedListener = stream.registerListener({
|
|
188
|
+
closed: () => {
|
|
189
|
+
closeSocket();
|
|
190
|
+
disposeClosedListener();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
184
193
|
const socket = await new Promise((resolve, reject) => {
|
|
185
194
|
let connectionEstablished = false;
|
|
186
195
|
const res = rsocket.requestStream({
|
|
@@ -195,9 +204,8 @@ export class AbstractRemote {
|
|
|
195
204
|
if (e.message !== 'Closed. ') {
|
|
196
205
|
this.logger.error(e);
|
|
197
206
|
}
|
|
198
|
-
// RSocket will close
|
|
199
|
-
//
|
|
200
|
-
socketIsClosed = true;
|
|
207
|
+
// RSocket will close the RSocket stream automatically
|
|
208
|
+
// Close the downstream stream as well - this will close the RSocket connection and WebSocket
|
|
201
209
|
stream.close();
|
|
202
210
|
// Handles cases where the connection failed e.g. auth error or connection error
|
|
203
211
|
if (!connectionEstablished) {
|
|
@@ -235,8 +243,7 @@ export class AbstractRemote {
|
|
|
235
243
|
}
|
|
236
244
|
},
|
|
237
245
|
closed: () => {
|
|
238
|
-
|
|
239
|
-
l?.();
|
|
246
|
+
l();
|
|
240
247
|
}
|
|
241
248
|
});
|
|
242
249
|
/**
|
|
@@ -347,7 +354,7 @@ export class AbstractRemote {
|
|
|
347
354
|
processStream();
|
|
348
355
|
}
|
|
349
356
|
});
|
|
350
|
-
const jsonS = ndjsonStream(outputStream);
|
|
357
|
+
const jsonS = ndjsonStream(new Response(outputStream).body);
|
|
351
358
|
const stream = new DataStream({
|
|
352
359
|
logger: this.logger
|
|
353
360
|
});
|
|
@@ -377,4 +384,3 @@ export class AbstractRemote {
|
|
|
377
384
|
return stream;
|
|
378
385
|
}
|
|
379
386
|
}
|
|
380
|
-
//# sourceMappingURL=AbstractRemote.js.map
|
package/lib/db/Column.js
CHANGED
package/lib/db/DBAdapter.js
CHANGED
package/lib/db/schema/Index.js
CHANGED
package/lib/db/schema/Schema.js
CHANGED
package/lib/db/schema/Table.js
CHANGED
package/lib/db/schema/TableV2.js
CHANGED
package/lib/index.js
CHANGED
package/lib/types/types.js
CHANGED
package/lib/utils/DataStream.js
CHANGED
package/lib/utils/mutex.js
CHANGED
package/lib/utils/parseQuery.js
CHANGED
package/lib/utils/strings.js
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/common",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20240726145618",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"description": "API definitions for JourneyApps PowerSync",
|
|
9
|
-
"main": "
|
|
9
|
+
"main": "lib/index.js",
|
|
10
10
|
"types": "lib/index.d.ts",
|
|
11
11
|
"author": "JOURNEYAPPS",
|
|
12
12
|
"license": "Apache-2.0",
|
|
13
13
|
"files": [
|
|
14
|
-
"lib"
|
|
15
|
-
"dist"
|
|
14
|
+
"lib"
|
|
16
15
|
],
|
|
17
16
|
"repository": {
|
|
18
17
|
"type": "git",
|
|
@@ -23,35 +22,27 @@
|
|
|
23
22
|
},
|
|
24
23
|
"homepage": "https://docs.powersync.com",
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"js-logger": "^1.6.1"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
|
30
|
-
"@rollup/plugin-inject": "^5.0.5",
|
|
31
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
32
|
-
"@rollup/plugin-node-resolve": "15.2.3",
|
|
33
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
34
|
-
"@types/lodash": "^4.14.197",
|
|
35
|
-
"@types/node": "^20.5.9",
|
|
36
|
-
"@types/uuid": "^9.0.1",
|
|
37
25
|
"async-mutex": "^0.4.0",
|
|
38
|
-
"bson": "^6.6.0",
|
|
39
26
|
"buffer": "^6.0.3",
|
|
40
27
|
"can-ndjson-stream": "^1.0.2",
|
|
41
28
|
"cross-fetch": "^4.0.0",
|
|
42
29
|
"event-iterator": "^2.0.0",
|
|
30
|
+
"js-logger": "^1.6.1",
|
|
43
31
|
"lodash": "^4.17.21",
|
|
44
|
-
"rollup": "4.14.3",
|
|
45
32
|
"rsocket-core": "1.0.0-alpha.3",
|
|
46
|
-
"rsocket-websocket-client": "1.0.0-alpha.3"
|
|
47
|
-
|
|
33
|
+
"rsocket-websocket-client": "1.0.0-alpha.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/lodash": "^4.14.197",
|
|
37
|
+
"@types/node": "^20.5.9",
|
|
38
|
+
"@types/uuid": "^9.0.1",
|
|
48
39
|
"typescript": "^5.5.3",
|
|
49
40
|
"vitest": "^1.5.2",
|
|
50
|
-
"
|
|
41
|
+
"bson": "^6.6.0"
|
|
51
42
|
},
|
|
52
43
|
"scripts": {
|
|
53
|
-
"build": "tsc -b
|
|
54
|
-
"clean": "rm -rf lib tsconfig.tsbuildinfo
|
|
44
|
+
"build": "tsc -b",
|
|
45
|
+
"clean": "rm -rf lib tsconfig.tsbuildinfo",
|
|
55
46
|
"test": "vitest"
|
|
56
47
|
}
|
|
57
48
|
}
|