@powersync/web 1.38.7 → 2.0.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/bin/powersync.cjs +1 -1
- package/dist/index.react_native_web.js +1893 -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/mc-wa-sqlite-DiBqIVE5.js +2 -0
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +2 -0
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +1 -0
- package/dist/worker/wa-sqlite-BlSx7-_P.js +2 -0
- package/dist/worker/wa-sqlite-BlSx7-_P.js.map +1 -0
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js +2 -0
- package/dist/worker/wa-sqlite-async-BdR24Ucf.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 +47 -61
- 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 +14 -14
- 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 +5 -0
- package/lib/db/adapters/resolveAndValidateOptions.js +33 -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 +11 -7
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +22 -13
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.js +14 -18
- 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 +131 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/db/adapters/wa-sqlite/vfs.d.ts +47 -0
- package/lib/db/adapters/wa-sqlite/vfs.js +95 -0
- 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 +31 -66
- package/lib/db/sync/SharedWebStreamingSyncImplementation.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 +15 -0
- package/lib/worker/client.js +77 -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 +28 -16
- 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 +11 -15
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +42 -43
- 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 +22 -29
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +80 -122
- package/src/db/adapters/AsyncWebAdapter.ts +17 -26
- 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 +40 -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 +15 -12
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +37 -32
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +63 -126
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -49
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +4 -22
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +38 -77
- 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 +100 -0
- package/src/worker/db/MultiDatabaseServer.ts +43 -23
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +4 -10
- package/src/worker/sync/BroadcastLogger.ts +35 -103
- package/src/worker/sync/SharedSyncImplementation.ts +62 -63
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/src/worker/worker.ts +38 -0
- package/dist/index.umd.js +0 -7613
- package/dist/index.umd.js.map +0 -1
- package/dist/worker/SharedSyncImplementation.umd.js +0 -16139
- package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
- package/dist/worker/WASQLiteDB.umd.js +0 -17418
- 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-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.d.ts +0 -50
- package/lib/src/db/adapters/wa-sqlite/vfs.js +0 -77
- 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/dist/{8e97452e297be23b5e50.wasm → worker/assets/mc-wa-sqlite-CnHbhWvs.wasm} +0 -0
- /package/dist/{2075a31bb151adbb9767.wasm → worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm} +0 -0
- /package/dist/{3322bc84de986b63c2cd.wasm → worker/assets/wa-sqlite-XZW__iJk.wasm} +0 -0
- /package/dist/{fbc178b70d530e8ce02b.wasm → worker/assets/wa-sqlite-async-rHzzC98y.wasm} +0 -0
- /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,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PowerSyncConnectionOptions,
|
|
3
|
-
PowerSyncCredentials,
|
|
4
|
-
SubscribedStream,
|
|
5
|
-
SyncStatusOptions
|
|
6
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogRecord, PowerSyncCredentials } from '@powersync/common';
|
|
7
2
|
import * as Comlink from 'comlink';
|
|
8
|
-
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
9
3
|
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider.js';
|
|
10
4
|
import { ManualSharedSyncPayload, SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation.js';
|
|
11
5
|
import { WorkerClient } from '../../worker/sync/WorkerClient.js';
|
|
12
6
|
import { WebDBAdapter } from '../adapters/WebDBAdapter.js';
|
|
13
|
-
import { DEFAULT_CACHE_SIZE_KB, TemporaryStorageOption, resolveWebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
14
7
|
import {
|
|
15
8
|
WebStreamingSyncImplementation,
|
|
16
9
|
WebStreamingSyncImplementationOptions
|
|
17
10
|
} from './WebStreamingSyncImplementation.js';
|
|
18
11
|
import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
12
|
+
import { SubscribedStream, SyncStatusJson, ResolvedSyncOptions } from '@powersync/shared-internals';
|
|
13
|
+
import { connectToExistingWorker, connectToWorker, WorkerConnection } from '../../worker/client.js';
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* The shared worker will trigger methods on this side of the message port
|
|
@@ -24,7 +19,7 @@ import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
|
24
19
|
class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
25
20
|
constructor(
|
|
26
21
|
protected options: WebStreamingSyncImplementationOptions,
|
|
27
|
-
public statusChanged: (status:
|
|
22
|
+
public statusChanged: (status: SyncStatusJson) => void,
|
|
28
23
|
protected webDB: WebDBAdapter
|
|
29
24
|
) {
|
|
30
25
|
super();
|
|
@@ -68,34 +63,15 @@ class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
|
68
63
|
return this.options.logger;
|
|
69
64
|
}
|
|
70
65
|
|
|
71
|
-
|
|
72
|
-
this.logger
|
|
73
|
-
}
|
|
74
|
-
debug(...x: any[]): void {
|
|
75
|
-
this.logger?.debug(...x);
|
|
76
|
-
}
|
|
77
|
-
info(...x: any[]): void {
|
|
78
|
-
this.logger?.info(...x);
|
|
79
|
-
}
|
|
80
|
-
log(...x: any[]): void {
|
|
81
|
-
this.logger?.log(...x);
|
|
82
|
-
}
|
|
83
|
-
warn(...x: any[]): void {
|
|
84
|
-
this.logger?.warn(...x);
|
|
85
|
-
}
|
|
86
|
-
error(...x: any[]): void {
|
|
87
|
-
this.logger?.error(...x);
|
|
88
|
-
}
|
|
89
|
-
time(label: string): void {
|
|
90
|
-
this.logger?.time(label);
|
|
91
|
-
}
|
|
92
|
-
timeEnd(label: string): void {
|
|
93
|
-
this.logger?.timeEnd(label);
|
|
66
|
+
log(record: LogRecord): void {
|
|
67
|
+
this.logger.log(record);
|
|
94
68
|
}
|
|
95
69
|
}
|
|
96
70
|
|
|
97
71
|
export interface SharedWebStreamingSyncImplementationOptions extends WebStreamingSyncImplementationOptions {
|
|
72
|
+
logLevel: number;
|
|
98
73
|
db: WebDBAdapter;
|
|
74
|
+
enableBroadcastLogs: boolean;
|
|
99
75
|
}
|
|
100
76
|
|
|
101
77
|
/**
|
|
@@ -104,46 +80,30 @@ export interface SharedWebStreamingSyncImplementationOptions extends WebStreamin
|
|
|
104
80
|
export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
105
81
|
protected syncManager: Comlink.Remote<WorkerClient>;
|
|
106
82
|
protected clientProvider: SharedSyncClientProvider;
|
|
107
|
-
protected
|
|
83
|
+
protected worker: WorkerConnection;
|
|
108
84
|
|
|
109
85
|
protected isInitialized: Promise<void>;
|
|
110
86
|
protected dbAdapter: WebDBAdapter;
|
|
111
87
|
private abortOnClose = new AbortController();
|
|
88
|
+
private logLevel: number;
|
|
89
|
+
private enableBroadcastLogs: boolean;
|
|
112
90
|
|
|
113
91
|
constructor(options: SharedWebStreamingSyncImplementationOptions) {
|
|
114
92
|
super(options);
|
|
115
93
|
this.dbAdapter = options.db;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* This worker will manage all syncing operations remotely.
|
|
119
|
-
*/
|
|
120
|
-
const resolvedWorkerOptions = {
|
|
121
|
-
dbFilename: this.options.identifier!,
|
|
122
|
-
temporaryStorage: TemporaryStorageOption.MEMORY,
|
|
123
|
-
cacheSizeKb: DEFAULT_CACHE_SIZE_KB,
|
|
124
|
-
...options,
|
|
125
|
-
flags: resolveWebSQLFlags(options.flags)
|
|
126
|
-
};
|
|
94
|
+
this.logLevel = options.logLevel;
|
|
95
|
+
this.enableBroadcastLogs = options.enableBroadcastLogs;
|
|
127
96
|
|
|
128
97
|
const syncWorker = options.sync?.worker;
|
|
129
|
-
if (syncWorker) {
|
|
130
|
-
|
|
131
|
-
this.messagePort = syncWorker(resolvedWorkerOptions).port;
|
|
132
|
-
} else {
|
|
133
|
-
this.messagePort = new SharedWorker(`${syncWorker}`, {
|
|
134
|
-
/* @vite-ignore */
|
|
135
|
-
name: `shared-sync-${this.webOptions.identifier}`
|
|
136
|
-
}).port;
|
|
137
|
-
}
|
|
98
|
+
if (typeof syncWorker === 'function') {
|
|
99
|
+
this.worker = connectToExistingWorker(syncWorker(), 'sync');
|
|
138
100
|
} else {
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
).port;
|
|
101
|
+
this.worker = connectToWorker({
|
|
102
|
+
service: 'sync',
|
|
103
|
+
databaseIdentifier: this.webOptions.identifier!,
|
|
104
|
+
shared: true,
|
|
105
|
+
customWorker: syncWorker
|
|
106
|
+
});
|
|
147
107
|
}
|
|
148
108
|
|
|
149
109
|
/**
|
|
@@ -151,21 +111,21 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
151
111
|
*/
|
|
152
112
|
this.clientProvider = new SharedSyncClientProvider(
|
|
153
113
|
this.webOptions,
|
|
154
|
-
(
|
|
155
|
-
this.updateSyncStatus(
|
|
114
|
+
({ core, dataFlow }) => {
|
|
115
|
+
this.updateSyncStatus(core, dataFlow);
|
|
156
116
|
},
|
|
157
117
|
options.db
|
|
158
118
|
);
|
|
159
119
|
|
|
160
|
-
this.syncManager = Comlink.wrap<WorkerClient>(this.
|
|
120
|
+
this.syncManager = Comlink.wrap<WorkerClient>(this.worker.endpoint);
|
|
161
121
|
/**
|
|
162
122
|
* The sync worker will call this client provider when it needs
|
|
163
123
|
* to fetch credentials or upload data.
|
|
164
124
|
* This performs bi-directional method calling.
|
|
165
125
|
*/
|
|
166
|
-
Comlink.expose(this.clientProvider, this.
|
|
126
|
+
Comlink.expose(this.clientProvider, this.worker.endpoint);
|
|
167
127
|
|
|
168
|
-
this.syncManager.setLogLevel(this.
|
|
128
|
+
this.syncManager.setLogLevel(this.logLevel);
|
|
169
129
|
|
|
170
130
|
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
171
131
|
|
|
@@ -197,18 +157,16 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
197
157
|
// Awaiting here ensures the worker is waiting for the lock
|
|
198
158
|
await this.syncManager.addLockBasedCloseSignal(closeSignal);
|
|
199
159
|
|
|
200
|
-
const {
|
|
201
|
-
const flags = { ...this.webOptions.flags, workers: undefined };
|
|
160
|
+
const { identifier } = this.options;
|
|
202
161
|
|
|
203
162
|
await this.syncManager.setParams(
|
|
204
163
|
{
|
|
205
164
|
dbParams: this.dbAdapter.getConfiguration(),
|
|
206
165
|
streamOptions: {
|
|
207
|
-
crudUploadThrottleMs,
|
|
208
166
|
identifier,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
167
|
+
serializedSchema: this.options.serializedSchema
|
|
168
|
+
},
|
|
169
|
+
enableBroadcastLogs: this.enableBroadcastLogs
|
|
212
170
|
},
|
|
213
171
|
this.options.subscriptions
|
|
214
172
|
);
|
|
@@ -218,9 +176,9 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
218
176
|
* Starts the sync process, this effectively acts as a call to
|
|
219
177
|
* `connect` if not yet connected.
|
|
220
178
|
*/
|
|
221
|
-
async connect(options
|
|
179
|
+
async connect(options: ResolvedSyncOptions): Promise<void> {
|
|
222
180
|
await this.waitForReady();
|
|
223
|
-
return this.syncManager.connect(options);
|
|
181
|
+
return this.syncManager.connect(options, this.options.serializedSchema);
|
|
224
182
|
}
|
|
225
183
|
|
|
226
184
|
async disconnect(): Promise<void> {
|
|
@@ -237,8 +195,11 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
237
195
|
await this.waitForReady();
|
|
238
196
|
|
|
239
197
|
await new Promise<void>((resolve) => {
|
|
198
|
+
// This will always be a message port since we use shared workers.
|
|
199
|
+
const messagePort = this.worker.endpoint as MessagePort;
|
|
200
|
+
|
|
240
201
|
// Listen for the close acknowledgment from the worker
|
|
241
|
-
|
|
202
|
+
messagePort.addEventListener('message', (event) => {
|
|
242
203
|
const payload = event.data as ManualSharedSyncPayload;
|
|
243
204
|
if (payload?.event === SharedSyncClientEvent.CLOSE_ACK) {
|
|
244
205
|
resolve();
|
|
@@ -250,7 +211,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
250
211
|
event: SharedSyncClientEvent.CLOSE_CLIENT,
|
|
251
212
|
data: {}
|
|
252
213
|
};
|
|
253
|
-
|
|
214
|
+
messagePort.postMessage(closeMessagePayload);
|
|
254
215
|
});
|
|
255
216
|
|
|
256
217
|
await super.dispose();
|
|
@@ -259,7 +220,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
259
220
|
|
|
260
221
|
// Release the proxy
|
|
261
222
|
this.syncManager[Comlink.releaseProxy]();
|
|
262
|
-
this.
|
|
223
|
+
this.worker.close();
|
|
263
224
|
}
|
|
264
225
|
|
|
265
226
|
async waitForReady() {
|
package/src/db/sync/WebRemote.ts
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
AbstractRemoteOptions,
|
|
4
|
-
DEFAULT_REMOTE_LOGGER,
|
|
5
|
-
FetchImplementation,
|
|
6
|
-
FetchImplementationProvider,
|
|
7
|
-
ILogger,
|
|
8
|
-
RemoteConnector
|
|
9
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '@powersync/common';
|
|
2
|
+
import { AbstractRemote, FetchOptions, RemoteConnector } from '@powersync/shared-internals';
|
|
10
3
|
|
|
11
4
|
import { getUserAgentInfo } from './userAgent.js';
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* Depends on browser's implementation of global fetch.
|
|
15
|
-
*/
|
|
16
|
-
class WebFetchProvider extends FetchImplementationProvider {
|
|
17
|
-
getFetch(): FetchImplementation {
|
|
18
|
-
return fetch.bind(globalThis);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
5
|
+
import type { WebSocketSyncStreamPlatform, WebSocketSupport } from '@powersync/shared-internals/websockets';
|
|
21
6
|
|
|
22
7
|
export class WebRemote extends AbstractRemote {
|
|
23
8
|
constructor(
|
|
24
9
|
protected connector: RemoteConnector,
|
|
25
|
-
|
|
26
|
-
options?: Partial<AbstractRemoteOptions>
|
|
10
|
+
logger: PowerSyncLogger
|
|
27
11
|
) {
|
|
28
|
-
super(connector, logger
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
super(connector, logger);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected fetch({ resource, request }: FetchOptions): Promise<Response> {
|
|
16
|
+
return fetch(resource, request);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected async loadWebSocketSupport(platform: WebSocketSyncStreamPlatform): Promise<WebSocketSupport> {
|
|
20
|
+
if (!websockets) {
|
|
21
|
+
// loadWebSocketSupport being called concurrently is safe, the import resolves to the same module in that case.
|
|
22
|
+
const module = await import('@powersync/shared-internals/websockets');
|
|
23
|
+
websockets = new module.WebSocketSupport(platform);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return websockets;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
getUserAgent(): string {
|
|
35
30
|
let ua = [super.getUserAgent(), `powersync-web`];
|
|
36
31
|
try {
|
|
37
32
|
ua.push(...getUserAgentInfo());
|
|
38
|
-
} catch (
|
|
39
|
-
this.logger.warn
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.log({ level: LogLevels.warn, message: 'Failed to get user agent info', error });
|
|
40
35
|
}
|
|
41
36
|
return ua.join(' ');
|
|
42
37
|
}
|
|
43
38
|
}
|
|
39
|
+
|
|
40
|
+
let websockets: WebSocketSupport | undefined;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { LogLevels } from '@powersync/common';
|
|
1
2
|
import {
|
|
2
3
|
AbstractStreamingSyncImplementation,
|
|
3
4
|
AbstractStreamingSyncImplementationOptions,
|
|
4
5
|
LockOptions,
|
|
5
6
|
LockType
|
|
6
|
-
} from '@powersync/
|
|
7
|
+
} from '@powersync/shared-internals';
|
|
7
8
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
8
|
-
import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
9
9
|
|
|
10
10
|
export interface WebStreamingSyncImplementationOptions extends AbstractStreamingSyncImplementationOptions {
|
|
11
|
-
flags?: WebSQLFlags;
|
|
12
11
|
sync?: {
|
|
13
|
-
worker?: string | URL | ((
|
|
12
|
+
worker?: string | URL | (() => SharedWorker);
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -27,7 +26,7 @@ export class WebStreamingSyncImplementation extends AbstractStreamingSyncImpleme
|
|
|
27
26
|
async obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
|
|
28
27
|
const identifier = `streaming-sync-${lockOptions.type}-${this.webOptions.identifier}`;
|
|
29
28
|
if (lockOptions.type == LockType.SYNC) {
|
|
30
|
-
this.logger.debug
|
|
29
|
+
this.logger.log({ level: LogLevels.debug, message: `requesting lock for ${identifier}` });
|
|
31
30
|
}
|
|
32
31
|
return getNavigatorLocks().request(identifier, { signal: lockOptions.signal }, lockOptions.callback);
|
|
33
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from '@powersync/common';
|
|
2
2
|
export * from './attachments/IndexDBFileSystemAdapter.js';
|
|
3
|
-
export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
4
3
|
export { WASQLiteVFS } from './db/adapters/wa-sqlite/vfs.js';
|
|
5
4
|
export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
6
|
-
export * from './db/adapters/
|
|
7
|
-
export * from './db/adapters/web-sql-flags.js';
|
|
5
|
+
export * from './db/adapters/options.js';
|
|
8
6
|
export * from './db/PowerSyncDatabase.js';
|
|
9
7
|
export * from './db/sync/SharedWebStreamingSyncImplementation.js';
|
|
10
8
|
export * from './db/sync/WebRemote.js';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { SharedWorkerConnectionRequest, WorkerService } from './SharedWorkerConnectionRequest.js';
|
|
2
|
+
|
|
3
|
+
export interface OpenWorkerOptions {
|
|
4
|
+
service: WorkerService;
|
|
5
|
+
databaseIdentifier: string;
|
|
6
|
+
customWorker?: string | URL;
|
|
7
|
+
shared: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface WorkerConnection {
|
|
11
|
+
endpoint: MessagePort | Worker;
|
|
12
|
+
worker: Worker | SharedWorker;
|
|
13
|
+
close: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function connectToWorker({
|
|
17
|
+
service,
|
|
18
|
+
databaseIdentifier,
|
|
19
|
+
customWorker,
|
|
20
|
+
shared
|
|
21
|
+
}: OpenWorkerOptions): WorkerConnection {
|
|
22
|
+
const name = `${shared ? 'shared-' : ''}powersync-${databaseIdentifier}`;
|
|
23
|
+
let worker: Worker | SharedWorker;
|
|
24
|
+
|
|
25
|
+
if (customWorker) {
|
|
26
|
+
worker = shared
|
|
27
|
+
? new SharedWorker(customWorker, {
|
|
28
|
+
/* @vite-ignore */
|
|
29
|
+
name,
|
|
30
|
+
type: 'module'
|
|
31
|
+
})
|
|
32
|
+
: new Worker(customWorker, {
|
|
33
|
+
/* @vite-ignore */
|
|
34
|
+
name,
|
|
35
|
+
type: 'module'
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
worker = spawnDefaultPowerSyncWorker(shared, name);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return connectToExistingWorker(worker, service);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Opens the default PowerSync worker.
|
|
46
|
+
*
|
|
47
|
+
* When users depend on the web SDK, we assume they use their own bundler (either vite or webpack). Both recognize the
|
|
48
|
+
* syntax of worker constructors with a string literal and will rewrite the URL as part of their bundling processes.
|
|
49
|
+
*
|
|
50
|
+
* React Native / Metro users can't rely on this on the web, as their app is not a JavaScript module and import.meta.url
|
|
51
|
+
* is not rewritten by Metro. For those users, we include a pre-bundled worker they can copy into a static assets
|
|
52
|
+
* directory and load with a custom URI. This also means that defaultWorker cannot work with Metro for React Native Web.
|
|
53
|
+
* We have a custom rollup plugin and conditional exports that replaces this function with a throwing stub for that
|
|
54
|
+
* platform. This allows a helpful error message.
|
|
55
|
+
*/
|
|
56
|
+
// Note: When changing this function, also update disableDefaultWorkers in rollup.config.ts.
|
|
57
|
+
function spawnDefaultPowerSyncWorker(shared: boolean, name: string): Worker | SharedWorker {
|
|
58
|
+
return shared
|
|
59
|
+
? new SharedWorker(new URL('./worker.js', import.meta.url), {
|
|
60
|
+
/* @vite-ignore */
|
|
61
|
+
name,
|
|
62
|
+
type: 'module'
|
|
63
|
+
})
|
|
64
|
+
: new Worker(new URL('./worker.js', import.meta.url), {
|
|
65
|
+
/* @vite-ignore */
|
|
66
|
+
name,
|
|
67
|
+
type: 'module'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function connectToExistingWorker(worker: Worker | SharedWorker, service: WorkerService): WorkerConnection {
|
|
72
|
+
const isShared = isSharedWorker(worker);
|
|
73
|
+
if (isShared) {
|
|
74
|
+
const { port1, port2 } = new MessageChannel();
|
|
75
|
+
const mainPort = (worker as SharedWorker).port;
|
|
76
|
+
mainPort.start();
|
|
77
|
+
mainPort.postMessage({ port: port1, service } satisfies SharedWorkerConnectionRequest, [port1]);
|
|
78
|
+
|
|
79
|
+
port2.start();
|
|
80
|
+
return {
|
|
81
|
+
endpoint: port2,
|
|
82
|
+
worker,
|
|
83
|
+
close() {
|
|
84
|
+
port2.close();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
} else {
|
|
88
|
+
return {
|
|
89
|
+
endpoint: worker as Worker,
|
|
90
|
+
worker,
|
|
91
|
+
close() {
|
|
92
|
+
worker.terminate();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function isSharedWorker(worker: Worker | SharedWorker): worker is SharedWorker {
|
|
99
|
+
return 'port' in worker;
|
|
100
|
+
}
|
|
@@ -1,27 +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';
|
|
7
|
+
import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/vfs.js';
|
|
11
8
|
|
|
12
9
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
13
10
|
|
|
11
|
+
export interface ConnectToMultiDatabaseServerOptions {
|
|
12
|
+
logLevel: number;
|
|
13
|
+
database: RawWaSqliteDatabaseOptions;
|
|
14
|
+
lockName: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Shared state to manage multiple database connections hosted by a worker.
|
|
16
19
|
*/
|
|
17
20
|
export class MultiDatabaseServer {
|
|
18
21
|
private activeDatabases = new Map<string, DatabaseServer>();
|
|
19
22
|
|
|
20
|
-
constructor(readonly logger:
|
|
23
|
+
constructor(readonly logger: PowerSyncLogger) {}
|
|
21
24
|
|
|
22
|
-
async handleConnection(
|
|
23
|
-
|
|
24
|
-
|
|
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));
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
async connectToExisting(name: string, lockName: string): Promise<ClientConnectionView> {
|
|
@@ -35,7 +47,7 @@ export class MultiDatabaseServer {
|
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
async openConnectionLocally(options:
|
|
50
|
+
async openConnectionLocally(logger: PowerSyncLogger, options: RawWaSqliteDatabaseOptions, lockName?: string) {
|
|
39
51
|
// Especially on Firefox, we're sometimes seeing "NoModificationAllowedError"s when opening OPFS databases we can
|
|
40
52
|
// work around by retrying.
|
|
41
53
|
const maxAttempts = 3;
|
|
@@ -43,28 +55,36 @@ export class MultiDatabaseServer {
|
|
|
43
55
|
|
|
44
56
|
for (let count = 0; count < maxAttempts - 1; count++) {
|
|
45
57
|
try {
|
|
46
|
-
server = await this.databaseOpenAttempt(options);
|
|
47
|
-
} catch (
|
|
48
|
-
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
|
+
});
|
|
49
65
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
50
66
|
}
|
|
51
67
|
}
|
|
52
68
|
|
|
53
69
|
// Final attempt if we haven't been able to open the server - rethrow errors if we still can't open.
|
|
54
|
-
server ??= await this.databaseOpenAttempt(options);
|
|
70
|
+
server ??= await this.databaseOpenAttempt(logger, options);
|
|
55
71
|
return server.connect(lockName);
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
private async databaseOpenAttempt(
|
|
74
|
+
private async databaseOpenAttempt(
|
|
75
|
+
logger: PowerSyncLogger,
|
|
76
|
+
options: RawWaSqliteDatabaseOptions
|
|
77
|
+
): Promise<DatabaseServer> {
|
|
59
78
|
return getNavigatorLocks().request(OPEN_DB_LOCK, async () => {
|
|
60
|
-
const {
|
|
79
|
+
const { filename, readonly, vfs } = options;
|
|
61
80
|
|
|
62
|
-
let server: DatabaseServer | undefined = this.activeDatabases.get(
|
|
81
|
+
let server: DatabaseServer | undefined = this.activeDatabases.get(filename);
|
|
63
82
|
if (server == null) {
|
|
64
83
|
// We don't need navigator locks for shared workers because all queries run in this shared worker exclusively.
|
|
65
84
|
// For read-only connections, we use a VFS that supports concurrent reads (so a single lock on the connection is
|
|
66
|
-
// fine).
|
|
67
|
-
|
|
85
|
+
// fine). In-memory databases either run in a shared worker or aren't shared across tabs at all, so the internal
|
|
86
|
+
// lock is enough.
|
|
87
|
+
const needsNavigatorLocks = !(isSharedWorker || readonly || vfs == WASQLiteVFS.InMemoryVfs);
|
|
68
88
|
const connection = new RawSqliteConnection(options);
|
|
69
89
|
const withSafeConcurrency = new ConcurrentSqliteConnection(connection, needsNavigatorLocks);
|
|
70
90
|
|
|
@@ -81,13 +101,13 @@ export class MultiDatabaseServer {
|
|
|
81
101
|
}
|
|
82
102
|
returnLease();
|
|
83
103
|
|
|
84
|
-
const onClose = () => this.activeDatabases.delete(
|
|
104
|
+
const onClose = () => this.activeDatabases.delete(filename);
|
|
85
105
|
server = new DatabaseServer({
|
|
86
106
|
inner: withSafeConcurrency,
|
|
87
|
-
logger
|
|
107
|
+
logger,
|
|
88
108
|
onClose
|
|
89
109
|
});
|
|
90
|
-
this.activeDatabases.set(
|
|
110
|
+
this.activeDatabases.set(filename, server);
|
|
91
111
|
}
|
|
92
112
|
|
|
93
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
|
}
|