@powersync/web 1.39.0 → 2.1.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/README.md +0 -10
- package/bin/powersync.cjs +1 -1
- package/dist/index.react_native_web.js +1992 -0
- package/dist/index.react_native_web.js.map +1 -0
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +2 -0
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +1 -0
- package/dist/worker/FacadeVFS-d1ZDvud7.js +2 -0
- package/dist/worker/FacadeVFS-d1ZDvud7.js.map +1 -0
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +2 -0
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +1 -0
- package/dist/worker/MemoryVFS-DVJL5F8j.js +2 -0
- package/dist/worker/MemoryVFS-DVJL5F8j.js.map +1 -0
- package/dist/worker/OPFSCoopSyncVFS-BgTiWPfa.js +2 -0
- package/dist/worker/OPFSCoopSyncVFS-BgTiWPfa.js.map +1 -0
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +2 -0
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +1 -0
- package/dist/worker/assets/mc-wa-sqlite-DoDpgFfE.wasm +0 -0
- package/dist/worker/assets/mc-wa-sqlite-async-DYagSq56.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-CagagB9I.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-async-DCIP8kAx.wasm +0 -0
- package/dist/worker/mc-wa-sqlite-DDFgWP93.js +2 -0
- package/dist/worker/mc-wa-sqlite-DDFgWP93.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js +2 -0
- package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js.map +1 -0
- package/dist/worker/wa-sqlite-B0tZMM0j.js +2 -0
- package/dist/worker/wa-sqlite-B0tZMM0j.js.map +1 -0
- package/dist/worker/wa-sqlite-async-CM6BmfRh.js +2 -0
- package/dist/worker/wa-sqlite-async-CM6BmfRh.js.map +1 -0
- package/dist/worker/websockets-Q8W_lerF.js +9 -0
- package/dist/worker/websockets-Q8W_lerF.js.map +1 -0
- package/dist/worker/worker.js +7 -0
- package/dist/worker/worker.js.map +1 -0
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/db/PowerSyncDatabase.d.ts +67 -0
- package/lib/{src/db → db}/PowerSyncDatabase.js +49 -63
- package/lib/db/PowerSyncDatabase.js.map +1 -0
- package/lib/db/adapters/AsyncWebAdapter.d.ts +32 -0
- package/lib/{src/db → db}/adapters/AsyncWebAdapter.js +15 -15
- package/lib/db/adapters/AsyncWebAdapter.js.map +1 -0
- package/lib/db/adapters/SSRDBAdapter.d.ts +17 -0
- package/lib/db/adapters/SSRDBAdapter.js +37 -0
- package/lib/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/{src/db → db}/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/db/adapters/WebDBAdapter.js.map +1 -0
- package/lib/db/adapters/options.d.ts +87 -0
- package/lib/db/adapters/options.js +6 -0
- package/lib/db/adapters/options.js.map +1 -0
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +13 -0
- package/lib/db/adapters/resolveAndValidateOptions.js +41 -0
- package/lib/db/adapters/resolveAndValidateOptions.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +3 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.js +11 -37
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.js +14 -7
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +22 -12
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.js +12 -9
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +18 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +137 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/vfs.d.ts +9 -2
- package/lib/{src/db → db}/adapters/wa-sqlite/vfs.js +6 -6
- package/lib/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.d.ts +4 -8
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.js +4 -11
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.d.ts +13 -14
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.js +32 -66
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.d.ts +19 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.js +70 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/WebRemote.d.ts +10 -0
- package/lib/db/sync/WebRemote.js +33 -0
- package/lib/db/sync/WebRemote.js.map +1 -0
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.d.ts +2 -4
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.js +3 -2
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/userAgent.js.map +1 -0
- package/lib/{src/index.d.ts → index.d.ts} +1 -3
- package/lib/{src/index.js → index.js} +1 -3
- package/lib/index.js.map +1 -0
- package/lib/shared/navigator.js.map +1 -0
- package/lib/shared/tab_close_signal.js.map +1 -0
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +5 -0
- package/lib/worker/SharedWorkerConnectionRequest.js +2 -0
- package/lib/worker/SharedWorkerConnectionRequest.js.map +1 -0
- package/lib/worker/client.d.ts +17 -0
- package/lib/worker/client.js +90 -0
- package/lib/worker/client.js.map +1 -0
- package/lib/worker/db/MultiDatabaseServer.d.ts +22 -0
- package/lib/{src/worker → worker}/db/MultiDatabaseServer.js +25 -15
- package/lib/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +13 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/worker/sync/BroadcastLogger.d.ts +27 -0
- package/lib/worker/sync/BroadcastLogger.js +65 -0
- package/lib/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.d.ts +12 -15
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +44 -44
- package/lib/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/{src/worker → worker}/sync/WorkerClient.d.ts +3 -3
- package/lib/{src/worker → worker}/sync/WorkerClient.js +2 -2
- package/lib/worker/sync/WorkerClient.js.map +1 -0
- package/lib/worker/worker.js +34 -0
- package/lib/worker/worker.js.map +1 -0
- package/package.json +23 -31
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +83 -127
- package/src/db/adapters/AsyncWebAdapter.ts +18 -27
- package/src/db/adapters/SSRDBAdapter.ts +14 -64
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/options.ts +100 -0
- package/src/db/adapters/resolveAndValidateOptions.ts +49 -0
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +4 -5
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +20 -56
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +18 -12
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +36 -23
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +70 -125
- package/src/db/adapters/wa-sqlite/vfs.ts +13 -8
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +4 -22
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +39 -77
- package/src/db/sync/TabLocalStreamingSyncImplementation.ts +90 -0
- package/src/db/sync/WebRemote.ts +23 -26
- package/src/db/sync/WebStreamingSyncImplementation.ts +4 -5
- package/src/index.ts +1 -3
- package/src/worker/SharedWorkerConnectionRequest.ts +6 -0
- package/src/worker/client.ts +121 -0
- package/src/worker/db/MultiDatabaseServer.ts +40 -22
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +4 -10
- package/src/worker/sync/BroadcastLogger.ts +35 -103
- package/src/worker/sync/SharedSyncImplementation.ts +65 -64
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/src/worker/worker.ts +38 -0
- package/dist/2075a31bb151adbb9767.wasm +0 -0
- package/dist/3322bc84de986b63c2cd.wasm +0 -0
- package/dist/8e97452e297be23b5e50.wasm +0 -0
- package/dist/fbc178b70d530e8ce02b.wasm +0 -0
- package/dist/index.umd.js +0 -7821
- package/dist/index.umd.js.map +0 -1
- package/dist/worker/SharedSyncImplementation.umd.js +0 -16142
- package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
- package/dist/worker/WASQLiteDB.umd.js +0 -17437
- package/dist/worker/WASQLiteDB.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +0 -3562
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +0 -1400
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +0 -2478
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +0 -1681
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +0 -1820
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +0 -1
- package/lib/package.json +0 -91
- package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +0 -1
- package/lib/src/db/NavigatorTriggerClaimManager.js.map +0 -1
- package/lib/src/db/PowerSyncDatabase.d.ts +0 -78
- package/lib/src/db/PowerSyncDatabase.js.map +0 -1
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +0 -23
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -27
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +0 -50
- package/lib/src/db/adapters/AsyncWebAdapter.js.map +0 -1
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +0 -30
- package/lib/src/db/adapters/SSRDBAdapter.js +0 -69
- package/lib/src/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/WebDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -45
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -146
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +0 -15
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -22
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +0 -1
- package/lib/src/db/adapters/web-sql-flags.d.ts +0 -92
- package/lib/src/db/adapters/web-sql-flags.js +0 -37
- package/lib/src/db/adapters/web-sql-flags.js.map +0 -1
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/WebRemote.d.ts +0 -7
- package/lib/src/db/sync/WebRemote.js +0 -33
- package/lib/src/db/sync/WebRemote.js.map +0 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/userAgent.js.map +0 -1
- package/lib/src/index.js.map +0 -1
- package/lib/src/shared/navigator.js.map +0 -1
- package/lib/src/shared/tab_close_signal.js.map +0 -1
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +0 -17
- package/lib/src/worker/db/MultiDatabaseServer.js.map +0 -1
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +0 -4
- package/lib/src/worker/db/WASQLiteDB.worker.js +0 -31
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +0 -1
- package/lib/src/worker/db/open-worker-database.d.ts +0 -14
- package/lib/src/worker/db/open-worker-database.js +0 -53
- package/lib/src/worker/db/open-worker-database.js.map +0 -1
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -19
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/src/worker/sync/BroadcastLogger.d.ts +0 -47
- package/lib/src/worker/sync/BroadcastLogger.js +0 -129
- package/lib/src/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +0 -12
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +0 -1
- package/lib/src/worker/sync/WorkerClient.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +0 -47
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +0 -24
- package/src/db/adapters/web-sql-flags.ts +0 -141
- package/src/worker/db/WASQLiteDB.worker.ts +0 -35
- package/src/worker/db/open-worker-database.ts +0 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +0 -14
- /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.js +0 -0
- /package/lib/{src/db → db}/NavigatorTriggerClaimManager.js +0 -0
- /package/lib/{src/db → db}/adapters/WebDBAdapter.js +0 -0
- /package/lib/{src/db → db}/sync/userAgent.d.ts +0 -0
- /package/lib/{src/db → db}/sync/userAgent.js +0 -0
- /package/lib/{src/shared → shared}/navigator.d.ts +0 -0
- /package/lib/{src/shared → shared}/navigator.js +0 -0
- /package/lib/{src/shared → shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{src/shared → shared}/tab_close_signal.js +0 -0
- /package/lib/{src/worker → worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
- /package/lib/{src/worker/sync/SharedSyncImplementation.worker.d.ts → worker/worker.d.ts} +0 -0
|
@@ -1,28 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
3
|
import { ClientConnectionView, DatabaseServer } from '../../db/adapters/wa-sqlite/DatabaseServer.js';
|
|
4
|
-
import {
|
|
5
|
-
ResolvedWASQLiteOpenFactoryOptions,
|
|
6
|
-
WorkerDBOpenerOptions
|
|
7
|
-
} from '../../db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
8
4
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
9
|
-
import { RawSqliteConnection } from '../../db/adapters/wa-sqlite/RawSqliteConnection.js';
|
|
5
|
+
import { RawSqliteConnection, RawWaSqliteDatabaseOptions } from '../../db/adapters/wa-sqlite/RawSqliteConnection.js';
|
|
10
6
|
import { ConcurrentSqliteConnection } from '../../db/adapters/wa-sqlite/ConcurrentConnection.js';
|
|
11
7
|
import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/vfs.js';
|
|
12
8
|
|
|
13
9
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
14
10
|
|
|
11
|
+
export interface ConnectToMultiDatabaseServerOptions {
|
|
12
|
+
logLevel: number;
|
|
13
|
+
database: RawWaSqliteDatabaseOptions;
|
|
14
|
+
lockName: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Shared state to manage multiple database connections hosted by a worker.
|
|
17
19
|
*/
|
|
18
20
|
export class MultiDatabaseServer {
|
|
19
21
|
private activeDatabases = new Map<string, DatabaseServer>();
|
|
20
22
|
|
|
21
|
-
constructor(readonly logger:
|
|
23
|
+
constructor(readonly logger: PowerSyncLogger) {}
|
|
22
24
|
|
|
23
|
-
async handleConnection(
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
async handleConnection({
|
|
26
|
+
logLevel,
|
|
27
|
+
database,
|
|
28
|
+
lockName
|
|
29
|
+
}: ConnectToMultiDatabaseServerOptions): Promise<ClientConnectionView> {
|
|
30
|
+
const logger: PowerSyncLogger = {
|
|
31
|
+
log: (record) => {
|
|
32
|
+
if (record.level >= logLevel) this.logger.log(record);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return Comlink.proxy(await this.openConnectionLocally(logger, database, lockName));
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
async connectToExisting(name: string, lockName: string): Promise<ClientConnectionView> {
|
|
@@ -36,7 +47,7 @@ export class MultiDatabaseServer {
|
|
|
36
47
|
});
|
|
37
48
|
}
|
|
38
49
|
|
|
39
|
-
async openConnectionLocally(options:
|
|
50
|
+
async openConnectionLocally(logger: PowerSyncLogger, options: RawWaSqliteDatabaseOptions, lockName?: string) {
|
|
40
51
|
// Especially on Firefox, we're sometimes seeing "NoModificationAllowedError"s when opening OPFS databases we can
|
|
41
52
|
// work around by retrying.
|
|
42
53
|
const maxAttempts = 3;
|
|
@@ -44,29 +55,36 @@ export class MultiDatabaseServer {
|
|
|
44
55
|
|
|
45
56
|
for (let count = 0; count < maxAttempts - 1; count++) {
|
|
46
57
|
try {
|
|
47
|
-
server = await this.databaseOpenAttempt(options);
|
|
48
|
-
} catch (
|
|
49
|
-
this.logger.
|
|
58
|
+
server = await this.databaseOpenAttempt(logger, options);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
this.logger.log({
|
|
61
|
+
level: LogLevels.warn,
|
|
62
|
+
message: `Attempt ${count + 1} of ${maxAttempts} to open database failed, retrying in 1 second...`,
|
|
63
|
+
error
|
|
64
|
+
});
|
|
50
65
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
51
66
|
}
|
|
52
67
|
}
|
|
53
68
|
|
|
54
69
|
// Final attempt if we haven't been able to open the server - rethrow errors if we still can't open.
|
|
55
|
-
server ??= await this.databaseOpenAttempt(options);
|
|
70
|
+
server ??= await this.databaseOpenAttempt(logger, options);
|
|
56
71
|
return server.connect(lockName);
|
|
57
72
|
}
|
|
58
73
|
|
|
59
|
-
private async databaseOpenAttempt(
|
|
74
|
+
private async databaseOpenAttempt(
|
|
75
|
+
logger: PowerSyncLogger,
|
|
76
|
+
options: RawWaSqliteDatabaseOptions
|
|
77
|
+
): Promise<DatabaseServer> {
|
|
60
78
|
return getNavigatorLocks().request(OPEN_DB_LOCK, async () => {
|
|
61
|
-
const {
|
|
79
|
+
const { filename, readonly, vfs } = options;
|
|
62
80
|
|
|
63
|
-
let server: DatabaseServer | undefined = this.activeDatabases.get(
|
|
81
|
+
let server: DatabaseServer | undefined = this.activeDatabases.get(filename);
|
|
64
82
|
if (server == null) {
|
|
65
83
|
// We don't need navigator locks for shared workers because all queries run in this shared worker exclusively.
|
|
66
84
|
// For read-only connections, we use a VFS that supports concurrent reads (so a single lock on the connection is
|
|
67
85
|
// fine). In-memory databases either run in a shared worker or aren't shared across tabs at all, so the internal
|
|
68
86
|
// lock is enough.
|
|
69
|
-
const needsNavigatorLocks = !(isSharedWorker ||
|
|
87
|
+
const needsNavigatorLocks = !(isSharedWorker || readonly || vfs == WASQLiteVFS.InMemoryVfs);
|
|
70
88
|
const connection = new RawSqliteConnection(options);
|
|
71
89
|
const withSafeConcurrency = new ConcurrentSqliteConnection(connection, needsNavigatorLocks);
|
|
72
90
|
|
|
@@ -83,13 +101,13 @@ export class MultiDatabaseServer {
|
|
|
83
101
|
}
|
|
84
102
|
returnLease();
|
|
85
103
|
|
|
86
|
-
const onClose = () => this.activeDatabases.delete(
|
|
104
|
+
const onClose = () => this.activeDatabases.delete(filename);
|
|
87
105
|
server = new DatabaseServer({
|
|
88
106
|
inner: withSafeConcurrency,
|
|
89
|
-
logger
|
|
107
|
+
logger,
|
|
90
108
|
onClose
|
|
91
109
|
});
|
|
92
|
-
this.activeDatabases.set(
|
|
110
|
+
this.activeDatabases.set(filename, server);
|
|
93
111
|
}
|
|
94
112
|
|
|
95
113
|
return server;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LogRecord, PowerSyncCredentials } from '@powersync/common';
|
|
2
|
+
import { SyncStatusJson } from '@powersync/shared-internals';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The client side port should provide these methods.
|
|
@@ -7,15 +8,8 @@ export abstract class AbstractSharedSyncClientProvider {
|
|
|
7
8
|
abstract fetchCredentials(): Promise<PowerSyncCredentials | null>;
|
|
8
9
|
abstract invalidateCredentials(): void;
|
|
9
10
|
abstract uploadCrud(): Promise<void>;
|
|
10
|
-
abstract statusChanged(status:
|
|
11
|
+
abstract statusChanged(status: SyncStatusJson): void;
|
|
11
12
|
abstract getDBWorkerPort(): Promise<MessagePort>;
|
|
12
13
|
|
|
13
|
-
abstract
|
|
14
|
-
abstract debug(...x: any[]): void;
|
|
15
|
-
abstract info(...x: any[]): void;
|
|
16
|
-
abstract log(...x: any[]): void;
|
|
17
|
-
abstract warn(...x: any[]): void;
|
|
18
|
-
abstract error(...x: any[]): void;
|
|
19
|
-
abstract time(label: string): void;
|
|
20
|
-
abstract timeEnd(label: string): void;
|
|
14
|
+
abstract log(record: LogRecord): void;
|
|
21
15
|
}
|
|
@@ -1,113 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PowerSyncLogger, LogLevels, CreateLoggerOptions, createConsoleLogger, LogRecord } from '@powersync/common';
|
|
2
2
|
import { type WrappedSyncPort } from './SharedSyncImplementation.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Broadcasts logs to all clients
|
|
6
6
|
*/
|
|
7
|
-
export class BroadcastLogger implements
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
INFO: ILogLevel;
|
|
11
|
-
TIME: ILogLevel;
|
|
12
|
-
WARN: ILogLevel;
|
|
13
|
-
ERROR: ILogLevel;
|
|
14
|
-
OFF: ILogLevel;
|
|
7
|
+
export class BroadcastLogger implements PowerSyncLogger {
|
|
8
|
+
private readonly inner: PowerSyncLogger & CreateLoggerOptions;
|
|
9
|
+
private currentLevel: number = LogLevels.info;
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
sendBroadcasts = true;
|
|
17
12
|
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.
|
|
23
|
-
this.WARN = LogLevel.WARN;
|
|
24
|
-
this.ERROR = LogLevel.ERROR;
|
|
25
|
-
this.OFF = LogLevel.OFF;
|
|
13
|
+
constructor(
|
|
14
|
+
prefix: string,
|
|
15
|
+
private clients: WrappedSyncPort[]
|
|
16
|
+
) {
|
|
17
|
+
this.inner = createConsoleLogger({ prefix: prefix });
|
|
26
18
|
}
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
log(record: LogRecord) {
|
|
21
|
+
this.inner.log(record);
|
|
30
22
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
debug(...x: any[]): void {
|
|
37
|
-
if (!this.enabledFor(this.DEBUG)) return;
|
|
38
|
-
|
|
39
|
-
console.debug(...x);
|
|
40
|
-
const sanitized = this.sanitizeArgs(x);
|
|
41
|
-
this.iterateClients((client) => client.clientProvider.debug(...sanitized));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
info(...x: any[]): void {
|
|
45
|
-
if (!this.enabledFor(this.INFO)) return;
|
|
46
|
-
|
|
47
|
-
console.info(...x);
|
|
48
|
-
const sanitized = this.sanitizeArgs(x);
|
|
49
|
-
this.iterateClients((client) => client.clientProvider.info(...sanitized));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
log(...x: any[]): void {
|
|
53
|
-
if (!this.enabledFor(this.INFO)) return;
|
|
54
|
-
|
|
55
|
-
console.log(...x);
|
|
56
|
-
const sanitized = this.sanitizeArgs(x);
|
|
57
|
-
this.iterateClients((client) => client.clientProvider.log(...sanitized));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
warn(...x: any[]): void {
|
|
61
|
-
if (!this.enabledFor(this.WARN)) return;
|
|
62
|
-
|
|
63
|
-
console.warn(...x);
|
|
64
|
-
const sanitized = this.sanitizeArgs(x);
|
|
65
|
-
this.iterateClients((client) => client.clientProvider.warn(...sanitized));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
error(...x: any[]): void {
|
|
69
|
-
if (!this.enabledFor(this.ERROR)) return;
|
|
70
|
-
|
|
71
|
-
console.error(...x);
|
|
72
|
-
const sanitized = this.sanitizeArgs(x);
|
|
73
|
-
this.iterateClients((client) => client.clientProvider.error(...sanitized));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
time(label: string): void {
|
|
77
|
-
if (!this.enabledFor(this.TIME)) return;
|
|
78
|
-
|
|
79
|
-
console.time(label);
|
|
80
|
-
this.iterateClients((client) => client.clientProvider.time(label));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
timeEnd(label: string): void {
|
|
84
|
-
if (!this.enabledFor(this.TIME)) return;
|
|
85
|
-
|
|
86
|
-
console.timeEnd(label);
|
|
87
|
-
this.iterateClients((client) => client.clientProvider.timeEnd(label));
|
|
23
|
+
if (this.sendBroadcasts && record.level >= this.currentLevel) {
|
|
24
|
+
const sanitized = this.sanitizeRecord(record);
|
|
25
|
+
this.iterateClients((client) => client.clientProvider.log(sanitized));
|
|
26
|
+
}
|
|
88
27
|
}
|
|
89
28
|
|
|
90
29
|
/**
|
|
91
30
|
* Set the global log level.
|
|
92
31
|
*/
|
|
93
|
-
setLevel(level:
|
|
32
|
+
setLevel(level: number): void {
|
|
33
|
+
this.inner.minLevel = level;
|
|
94
34
|
this.currentLevel = level;
|
|
95
35
|
}
|
|
96
36
|
|
|
97
|
-
/**
|
|
98
|
-
* Get the current log level.
|
|
99
|
-
*/
|
|
100
|
-
getLevel(): ILogLevel {
|
|
101
|
-
return this.currentLevel;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Returns true if the given level is enabled.
|
|
106
|
-
*/
|
|
107
|
-
enabledFor(level: ILogLevel): boolean {
|
|
108
|
-
return level.value >= this.currentLevel.value;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
37
|
/**
|
|
112
38
|
* Iterates all clients, catches individual client exceptions
|
|
113
39
|
* and proceeds to execute for all clients.
|
|
@@ -126,17 +52,23 @@ export class BroadcastLogger implements ILogger {
|
|
|
126
52
|
* Guards against any logging errors.
|
|
127
53
|
* We don't want a logging exception to cause further issues upstream
|
|
128
54
|
*/
|
|
129
|
-
protected
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
})
|
|
55
|
+
protected sanitizeRecord(record: LogRecord): LogRecord {
|
|
56
|
+
if (!record.error) {
|
|
57
|
+
return record;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let error;
|
|
61
|
+
try {
|
|
62
|
+
// Try and clone here first. If it fails it won't be passable over a MessagePort
|
|
63
|
+
error = structuredClone(record.error);
|
|
64
|
+
} catch (ex) {
|
|
65
|
+
console.error(ex);
|
|
66
|
+
error = 'Could not serialize log params. Check shared worker logs for more details.';
|
|
67
|
+
}
|
|
139
68
|
|
|
140
|
-
return
|
|
69
|
+
return {
|
|
70
|
+
...record,
|
|
71
|
+
error
|
|
72
|
+
};
|
|
141
73
|
}
|
|
142
74
|
}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AbortOperation,
|
|
3
2
|
BaseObserver,
|
|
4
|
-
ConnectionManager,
|
|
5
|
-
ConnectionPool,
|
|
6
3
|
DBAdapter,
|
|
7
|
-
DBAdapterDefaultMixin,
|
|
8
|
-
DBAdapterListener,
|
|
9
4
|
DBLockOptions,
|
|
10
5
|
LockContext,
|
|
11
6
|
PowerSyncBackendConnector,
|
|
7
|
+
SyncStatus,
|
|
8
|
+
LogLevels,
|
|
9
|
+
SyncStreamConnectionMethod
|
|
10
|
+
} from '@powersync/common';
|
|
11
|
+
import {
|
|
12
|
+
AbortOperation,
|
|
13
|
+
ConnectionManager,
|
|
12
14
|
SqliteBucketStorage,
|
|
13
15
|
SubscribedStream,
|
|
14
|
-
SyncStatus,
|
|
15
|
-
createLogger,
|
|
16
|
-
Mutex,
|
|
17
|
-
type ILogLevel,
|
|
18
|
-
type ILogger,
|
|
19
|
-
type PowerSyncConnectionOptions,
|
|
20
16
|
type StreamingSyncImplementation,
|
|
21
17
|
type StreamingSyncImplementationListener,
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
Mutex,
|
|
19
|
+
ResolvedSyncOptions,
|
|
20
|
+
SyncStatusSnapshot
|
|
21
|
+
} from '@powersync/shared-internals';
|
|
24
22
|
import * as Comlink from 'comlink';
|
|
25
23
|
import { WebRemote } from '../../db/sync/WebRemote.js';
|
|
26
24
|
import {
|
|
@@ -28,11 +26,11 @@ import {
|
|
|
28
26
|
WebStreamingSyncImplementationOptions
|
|
29
27
|
} from '../../db/sync/WebStreamingSyncImplementation.js';
|
|
30
28
|
|
|
31
|
-
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags.js';
|
|
32
29
|
import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider.js';
|
|
33
30
|
import { BroadcastLogger } from './BroadcastLogger.js';
|
|
34
31
|
import { DatabaseClient, OpenWorkerConnection } from '../../db/adapters/wa-sqlite/DatabaseClient.js';
|
|
35
32
|
import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
33
|
+
import { ResolvedWebSQLOpenOptions } from '../../db/adapters/options.js';
|
|
36
34
|
|
|
37
35
|
/**
|
|
38
36
|
* @internal
|
|
@@ -60,8 +58,12 @@ export type ManualSharedSyncPayload = {
|
|
|
60
58
|
* @internal
|
|
61
59
|
*/
|
|
62
60
|
export type SharedSyncInitOptions = {
|
|
63
|
-
streamOptions: Omit<
|
|
61
|
+
streamOptions: Omit<
|
|
62
|
+
WebStreamingSyncImplementationOptions,
|
|
63
|
+
'adapter' | 'uploadCrud' | 'remote' | 'subscriptions' | 'logger'
|
|
64
|
+
>;
|
|
64
65
|
dbParams: ResolvedWebSQLOpenOptions;
|
|
66
|
+
enableBroadcastLogs: boolean;
|
|
65
67
|
};
|
|
66
68
|
|
|
67
69
|
/**
|
|
@@ -112,21 +114,21 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
112
114
|
protected uploadDataController?: RemoteOperationAbortController;
|
|
113
115
|
|
|
114
116
|
protected syncParams: SharedSyncInitOptions | null;
|
|
115
|
-
protected
|
|
116
|
-
protected lastConnectOptions: PowerSyncConnectionOptions | undefined;
|
|
117
|
+
protected lastConnectOptions: ResolvedSyncOptions | undefined;
|
|
117
118
|
protected portMutex: Mutex;
|
|
118
119
|
private subscriptions: SubscribedStream[] = [];
|
|
119
120
|
|
|
120
121
|
protected connectionManager: ConnectionManager;
|
|
121
|
-
syncStatus
|
|
122
|
-
|
|
122
|
+
private syncStatus?: SyncStatusSnapshot;
|
|
123
|
+
logger: BroadcastLogger;
|
|
123
124
|
protected readonly database = this.generateReconnectableDatabase();
|
|
124
125
|
|
|
126
|
+
private sharedCloseSignal = generateTabCloseSignal();
|
|
127
|
+
|
|
125
128
|
constructor() {
|
|
126
129
|
super();
|
|
127
130
|
this.ports = [];
|
|
128
131
|
this.syncParams = null;
|
|
129
|
-
this.logger = createLogger('shared-sync');
|
|
130
132
|
this.lastConnectOptions = undefined;
|
|
131
133
|
this.portMutex = new Mutex();
|
|
132
134
|
|
|
@@ -139,8 +141,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
139
141
|
});
|
|
140
142
|
});
|
|
141
143
|
|
|
142
|
-
this.
|
|
143
|
-
this.broadCastLogger = new BroadcastLogger(this.ports);
|
|
144
|
+
this.logger = new BroadcastLogger('shared-sync', this.ports);
|
|
144
145
|
|
|
145
146
|
this.connectionManager = new ConnectionManager({
|
|
146
147
|
createSyncImplementation: async () => {
|
|
@@ -148,8 +149,10 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
148
149
|
|
|
149
150
|
const sync = this.generateStreamingImplementation();
|
|
150
151
|
const onDispose = sync.registerListener({
|
|
151
|
-
statusChanged: (
|
|
152
|
-
this.
|
|
152
|
+
statusChanged: (snapshot) => {
|
|
153
|
+
this.syncStatus = snapshot;
|
|
154
|
+
const json = snapshot.toJSON();
|
|
155
|
+
this.ports.forEach((p) => p.clientProvider.statusChanged(json));
|
|
153
156
|
}
|
|
154
157
|
});
|
|
155
158
|
|
|
@@ -158,7 +161,8 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
158
161
|
onDispose
|
|
159
162
|
};
|
|
160
163
|
},
|
|
161
|
-
logger: this.logger
|
|
164
|
+
logger: this.logger,
|
|
165
|
+
defaultConnectionMethod: SyncStreamConnectionMethod.HTTP
|
|
162
166
|
});
|
|
163
167
|
}
|
|
164
168
|
|
|
@@ -192,12 +196,6 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
192
196
|
});
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
async waitForStatus(status: SyncStatusOptions): Promise<void> {
|
|
196
|
-
return this.withSyncImplementation(async (sync) => {
|
|
197
|
-
return sync.waitForStatus(status);
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
199
|
async waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void> {
|
|
202
200
|
return this.withSyncImplementation(async (sync) => {
|
|
203
201
|
return sync.waitUntilStatusMatches(predicate);
|
|
@@ -209,7 +207,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
209
207
|
}
|
|
210
208
|
|
|
211
209
|
private collectActiveSubscriptions() {
|
|
212
|
-
this.logger.debug
|
|
210
|
+
this.logger.log({ level: LogLevels.debug, message: 'Collecting active stream subscriptions across tabs' });
|
|
213
211
|
const active = new Map<string, SubscribedStream>();
|
|
214
212
|
for (const port of this.ports) {
|
|
215
213
|
for (const stream of port.currentSubscriptions) {
|
|
@@ -218,7 +216,10 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
218
216
|
}
|
|
219
217
|
}
|
|
220
218
|
this.subscriptions = [...active.values()];
|
|
221
|
-
this.logger.
|
|
219
|
+
this.logger.log({
|
|
220
|
+
level: LogLevels.debug,
|
|
221
|
+
message: `Collected stream subscriptions, ${JSON.stringify(this.subscriptions)}`
|
|
222
|
+
});
|
|
222
223
|
this.connectionManager.syncStreamImplementation?.updateSubscriptions(this.subscriptions);
|
|
223
224
|
}
|
|
224
225
|
|
|
@@ -227,9 +228,8 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
227
228
|
this.collectActiveSubscriptions();
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
setLogLevel(level:
|
|
231
|
+
setLogLevel(level: number) {
|
|
231
232
|
this.logger.setLevel(level);
|
|
232
|
-
this.broadCastLogger.setLevel(level);
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
/**
|
|
@@ -247,16 +247,18 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
247
247
|
|
|
248
248
|
// First time setting params
|
|
249
249
|
this.syncParams = params;
|
|
250
|
-
|
|
251
|
-
this.logger = this.broadCastLogger;
|
|
252
|
-
}
|
|
250
|
+
this.logger.sendBroadcasts = params.enableBroadcastLogs;
|
|
253
251
|
|
|
254
252
|
// Ensure we have a usable database connection, the reconnectable database will connect lazily on first use.
|
|
255
253
|
await this.database.readLock(async () => {});
|
|
256
254
|
|
|
257
255
|
self.onerror = (event) => {
|
|
258
256
|
// Share any uncaught events on the broadcast logger
|
|
259
|
-
this.logger.
|
|
257
|
+
this.logger.log({
|
|
258
|
+
level: LogLevels.error,
|
|
259
|
+
message: 'Uncaught exception in PowerSync shared sync worker',
|
|
260
|
+
error: event
|
|
261
|
+
});
|
|
260
262
|
};
|
|
261
263
|
|
|
262
264
|
this.iterateListeners((l) => l.initialized?.());
|
|
@@ -274,9 +276,9 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
274
276
|
* The connection will simply be reconnected whenever a new tab
|
|
275
277
|
* connects.
|
|
276
278
|
*/
|
|
277
|
-
async connect(options
|
|
279
|
+
async connect(options: ResolvedSyncOptions, serializedSchema: any) {
|
|
278
280
|
this.lastConnectOptions = options;
|
|
279
|
-
return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options ?? {});
|
|
281
|
+
return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options ?? {}, serializedSchema);
|
|
280
282
|
}
|
|
281
283
|
|
|
282
284
|
async disconnect() {
|
|
@@ -298,7 +300,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
298
300
|
this.ports.push(portProvider);
|
|
299
301
|
|
|
300
302
|
// Give the newly connected client the latest status
|
|
301
|
-
const status = this.
|
|
303
|
+
const status = this.syncStatus;
|
|
302
304
|
if (status) {
|
|
303
305
|
portProvider.clientProvider.statusChanged(status.toJSON());
|
|
304
306
|
}
|
|
@@ -321,7 +323,10 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
321
323
|
return await this.portMutex.runExclusive(async () => {
|
|
322
324
|
const index = this.ports.findIndex((p) => p == port);
|
|
323
325
|
if (index < 0) {
|
|
324
|
-
this.logger.
|
|
326
|
+
this.logger.log({
|
|
327
|
+
level: LogLevels.warn,
|
|
328
|
+
message: `Could not remove port ${port} since it is not present in active ports.`
|
|
329
|
+
});
|
|
325
330
|
return () => {};
|
|
326
331
|
}
|
|
327
332
|
|
|
@@ -397,10 +402,13 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
397
402
|
throw new Error('No client port found to invalidate credentials');
|
|
398
403
|
}
|
|
399
404
|
try {
|
|
400
|
-
this.logger.log(
|
|
405
|
+
this.logger.log({
|
|
406
|
+
level: LogLevels.info,
|
|
407
|
+
message: 'calling the last port client provider to invalidate credentials'
|
|
408
|
+
});
|
|
401
409
|
lastPort.clientProvider.invalidateCredentials();
|
|
402
|
-
} catch (
|
|
403
|
-
this.logger.error
|
|
410
|
+
} catch (error) {
|
|
411
|
+
this.logger.log({ level: LogLevels.error, message: 'error invalidating credentials', error });
|
|
404
412
|
}
|
|
405
413
|
},
|
|
406
414
|
fetchCredentials: async () => {
|
|
@@ -417,7 +425,10 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
417
425
|
|
|
418
426
|
abortController.signal.onabort = reject;
|
|
419
427
|
try {
|
|
420
|
-
this.logger.log(
|
|
428
|
+
this.logger.log({
|
|
429
|
+
level: LogLevels.info,
|
|
430
|
+
message: 'calling the last port client provider for credentials'
|
|
431
|
+
});
|
|
421
432
|
resolve(await lastPort.clientProvider.fetchCredentials());
|
|
422
433
|
} catch (ex) {
|
|
423
434
|
reject(ex);
|
|
@@ -508,7 +519,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
508
519
|
const remote = Comlink.wrap<OpenWorkerConnection>(workerPort);
|
|
509
520
|
const identifier = this.syncParams!.dbParams.dbFilename;
|
|
510
521
|
|
|
511
|
-
const clientLockName = await
|
|
522
|
+
const clientLockName = await this.sharedCloseSignal;
|
|
512
523
|
|
|
513
524
|
/**
|
|
514
525
|
* The open could fail if the tab is closed while we're busy opening the database.
|
|
@@ -542,7 +553,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
542
553
|
clearTimeout(timeout);
|
|
543
554
|
|
|
544
555
|
client.closeListeners.push(async () => {
|
|
545
|
-
this.logger.info
|
|
556
|
+
this.logger.log({ level: LogLevels.info, message: 'Aborting open connection because associated tab closed.' });
|
|
546
557
|
handleClosed(db);
|
|
547
558
|
/**
|
|
548
559
|
* Don't await this close operation. It might never resolve if the tab is closed.
|
|
@@ -550,7 +561,9 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
550
561
|
* We then call close. The close operation is configured to fire-and-forget, the main promise will reject immediately.
|
|
551
562
|
*/
|
|
552
563
|
db.markRemoteClosed();
|
|
553
|
-
db.close().catch((
|
|
564
|
+
db.close().catch((error) =>
|
|
565
|
+
this.logger.log({ level: LogLevels.warn, message: 'error closing database connection', error })
|
|
566
|
+
);
|
|
554
567
|
});
|
|
555
568
|
return db;
|
|
556
569
|
}
|
|
@@ -559,7 +572,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
559
572
|
const syncParams = this.syncParams;
|
|
560
573
|
const sharedSync = this;
|
|
561
574
|
|
|
562
|
-
class
|
|
575
|
+
return new (class extends DBAdapter {
|
|
563
576
|
private connectionState:
|
|
564
577
|
| null
|
|
565
578
|
| DatabaseClient<ResolvedWebSQLOpenOptions>
|
|
@@ -628,19 +641,7 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
|
|
|
628
641
|
async refreshSchema(): Promise<void> {
|
|
629
642
|
// Not used by sync client.
|
|
630
643
|
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
const Adapter = DBAdapterDefaultMixin(ReconnectPool);
|
|
634
|
-
return new Adapter();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* A method to update the all shared statuses for each
|
|
639
|
-
* client.
|
|
640
|
-
*/
|
|
641
|
-
private updateAllStatuses(status: SyncStatusOptions) {
|
|
642
|
-
this.syncStatus = new SyncStatus(status);
|
|
643
|
-
this.ports.forEach((p) => p.clientProvider.statusChanged(status));
|
|
644
|
+
})();
|
|
644
645
|
}
|
|
645
646
|
}
|
|
646
647
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ILogLevel, PowerSyncConnectionOptions, SubscribedStream } from '@powersync/common';
|
|
2
1
|
import * as Comlink from 'comlink';
|
|
3
2
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
4
3
|
import {
|
|
@@ -8,6 +7,7 @@ import {
|
|
|
8
7
|
SharedSyncInitOptions,
|
|
9
8
|
WrappedSyncPort
|
|
10
9
|
} from './SharedSyncImplementation.js';
|
|
10
|
+
import { SubscribedStream, ResolvedSyncOptions } from '@powersync/shared-internals';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A client to the shared sync worker.
|
|
@@ -65,7 +65,7 @@ export class WorkerClient {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
setLogLevel(level:
|
|
68
|
+
setLogLevel(level: number) {
|
|
69
69
|
this.sync.setLogLevel(level);
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -82,8 +82,8 @@ export class WorkerClient {
|
|
|
82
82
|
return this.sync.getWriteCheckpoint();
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
connect(options
|
|
86
|
-
return this.sync.connect(options);
|
|
85
|
+
connect(options: ResolvedSyncOptions, schema: any) {
|
|
86
|
+
return this.sync.connect(options, schema);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
updateSubscriptions(subscriptions: SubscribedStream[]) {
|