@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
|
@@ -2,23 +2,22 @@ import {
|
|
|
2
2
|
QueryResult,
|
|
3
3
|
LockContext,
|
|
4
4
|
DBLockOptions,
|
|
5
|
-
DBAdapterListener,
|
|
6
|
-
ConnectionPool,
|
|
7
5
|
SqlExecutor,
|
|
8
|
-
DBGetUtilsDefaultMixin,
|
|
9
6
|
BatchedUpdateNotification,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
SQLOpenOptions,
|
|
8
|
+
DBAdapter,
|
|
9
|
+
RawQueryResult,
|
|
10
|
+
queryResultWithoutRows,
|
|
11
|
+
BaseQueryResult
|
|
13
12
|
} from '@powersync/common';
|
|
14
13
|
import { SharedConnectionWorker, WebDBAdapterConfiguration } from '../WebDBAdapter.js';
|
|
15
14
|
import { ClientConnectionView } from './DatabaseServer.js';
|
|
16
|
-
import { RawQueryResult } from './RawSqliteConnection.js';
|
|
17
15
|
import * as Comlink from 'comlink';
|
|
18
|
-
import {
|
|
16
|
+
import type { ConnectToMultiDatabaseServerOptions } from '../../../worker/db/MultiDatabaseServer.js';
|
|
17
|
+
import { ConnectionClosedError } from '@powersync/shared-internals';
|
|
19
18
|
|
|
20
19
|
export interface OpenWorkerConnection {
|
|
21
|
-
connect(config:
|
|
20
|
+
connect(config: ConnectToMultiDatabaseServerOptions): Promise<ClientConnectionView>;
|
|
22
21
|
connectToExisting(options: { identifier: string; lockName: string }): Promise<ClientConnectionView>;
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -44,10 +43,7 @@ export interface ClientOptions {
|
|
|
44
43
|
/**
|
|
45
44
|
* A single-connection {@link ConnectionPool} implementation based on a worker connection.
|
|
46
45
|
*/
|
|
47
|
-
export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfiguration>
|
|
48
|
-
extends BaseObserver<DBAdapterListener>
|
|
49
|
-
implements ConnectionPool
|
|
50
|
-
{
|
|
46
|
+
export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfiguration> extends DBAdapter {
|
|
51
47
|
#connection: ConnectionState;
|
|
52
48
|
#shareConnectionAbortController = new AbortController();
|
|
53
49
|
#receiveTableUpdates: MessagePort;
|
|
@@ -70,9 +66,7 @@ export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfigur
|
|
|
70
66
|
port2.onmessage = (event) => {
|
|
71
67
|
const tables = event.data as string[];
|
|
72
68
|
const notification: BatchedUpdateNotification = {
|
|
73
|
-
tables
|
|
74
|
-
groupedUpdates: {},
|
|
75
|
-
rawUpdates: []
|
|
69
|
+
tables
|
|
76
70
|
};
|
|
77
71
|
this.iterateListeners((l) => {
|
|
78
72
|
l.tablesUpdated && l.tablesUpdated(notification);
|
|
@@ -185,16 +179,17 @@ export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfigur
|
|
|
185
179
|
}
|
|
186
180
|
|
|
187
181
|
/**
|
|
188
|
-
* A {@link
|
|
182
|
+
* A {@link LockContext} implemented by sending commands to a worker.
|
|
189
183
|
*
|
|
190
184
|
* While an instance is active, it has exclusive access to the underlying database connection (as represented by its
|
|
191
185
|
* token).
|
|
192
186
|
*/
|
|
193
|
-
class
|
|
187
|
+
class ClientLockContext extends LockContext {
|
|
194
188
|
readonly #connection: ConnectionState;
|
|
195
189
|
readonly #token: string;
|
|
196
190
|
|
|
197
191
|
constructor(connection: ConnectionState, token: string) {
|
|
192
|
+
super();
|
|
198
193
|
this.#connection = connection;
|
|
199
194
|
this.#token = token;
|
|
200
195
|
}
|
|
@@ -223,37 +218,8 @@ class ClientSqlExecutor implements SqlExecutor {
|
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
|
|
226
|
-
async
|
|
227
|
-
|
|
228
|
-
let rows: QueryResult['rows'] | undefined;
|
|
229
|
-
if (rs.resultSet) {
|
|
230
|
-
const resultSet = rs.resultSet;
|
|
231
|
-
|
|
232
|
-
function rowToJavaScriptObject(row: any[]): Record<string, any> {
|
|
233
|
-
const obj: Record<string, any> = {};
|
|
234
|
-
resultSet.columns.forEach((key, idx) => (obj[key] = row[idx]));
|
|
235
|
-
return obj;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const mapped = resultSet.rows.map(rowToJavaScriptObject);
|
|
239
|
-
|
|
240
|
-
rows = {
|
|
241
|
-
_array: mapped,
|
|
242
|
-
length: mapped.length,
|
|
243
|
-
item: (idx: number) => mapped[idx]
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
rowsAffected: rs.changes,
|
|
249
|
-
insertId: rs.lastInsertRowId,
|
|
250
|
-
rows
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
async executeRaw(query: string, params?: any[] | undefined): Promise<any[][]> {
|
|
255
|
-
const rs = await this.#executeOnWorker(query, params);
|
|
256
|
-
return rs.resultSet?.rows ?? [];
|
|
221
|
+
async executeRaw(query: string, params?: any[] | undefined): Promise<RawQueryResult> {
|
|
222
|
+
return await this.#executeOnWorker(query, params);
|
|
257
223
|
}
|
|
258
224
|
|
|
259
225
|
async #executeOnWorker(query: string, params: any[] | undefined): Promise<RawQueryResult> {
|
|
@@ -263,23 +229,21 @@ class ClientSqlExecutor implements SqlExecutor {
|
|
|
263
229
|
);
|
|
264
230
|
}
|
|
265
231
|
|
|
266
|
-
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult
|
|
232
|
+
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult<never>> {
|
|
267
233
|
const results = await this.maybeTrace(
|
|
268
234
|
(c) => c.executeBatch(this.#token, query, params),
|
|
269
235
|
() => `${query} (batch of ${params.length})`
|
|
270
236
|
);
|
|
271
|
-
const result:
|
|
237
|
+
const result: BaseQueryResult = { insertId: undefined, rowsAffected: 0 };
|
|
272
238
|
for (const source of results) {
|
|
273
|
-
result.insertId = source.
|
|
274
|
-
result.rowsAffected
|
|
239
|
+
result.insertId = source.insertId;
|
|
240
|
+
result.rowsAffected = (result.rowsAffected ?? 0) + source.rowsAffected;
|
|
275
241
|
}
|
|
276
242
|
|
|
277
|
-
return result;
|
|
243
|
+
return queryResultWithoutRows(result);
|
|
278
244
|
}
|
|
279
245
|
}
|
|
280
246
|
|
|
281
|
-
class ClientLockContext extends DBGetUtilsDefaultMixin(ClientSqlExecutor) implements LockContext {}
|
|
282
|
-
|
|
283
247
|
interface ConnectionState {
|
|
284
248
|
connection: ClientConnectionView;
|
|
285
249
|
notifyRemoteClosed: AbortController | undefined;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '@powersync/common';
|
|
2
2
|
import { ConcurrentSqliteConnection, ConnectionLeaseToken } from './ConcurrentConnection.js';
|
|
3
|
-
import {
|
|
3
|
+
import { RawWebResult } from './RawSqliteConnection.js';
|
|
4
4
|
|
|
5
5
|
export interface DatabaseServerOptions {
|
|
6
6
|
inner: ConcurrentSqliteConnection;
|
|
7
7
|
onClose: () => void;
|
|
8
|
-
logger:
|
|
8
|
+
logger: PowerSyncLogger;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -24,7 +24,7 @@ export class DatabaseServer {
|
|
|
24
24
|
constructor(options: DatabaseServerOptions) {
|
|
25
25
|
this.#options = options;
|
|
26
26
|
const inner = options.inner;
|
|
27
|
-
this.#updateBroadcastChannel = new BroadcastChannel(`${inner.options.
|
|
27
|
+
this.#updateBroadcastChannel = new BroadcastChannel(`${inner.options.filename}-table-updates`);
|
|
28
28
|
|
|
29
29
|
this.#updateBroadcastChannel.onmessage = ({ data }) => {
|
|
30
30
|
this.#pushTableUpdateToClients(data as string[]);
|
|
@@ -85,7 +85,7 @@ export class DatabaseServer {
|
|
|
85
85
|
|
|
86
86
|
// If the client holds a connection lease it hasn't returned, return that now.
|
|
87
87
|
for (const { lease } of connectionLeases.values()) {
|
|
88
|
-
this.#logger.debug
|
|
88
|
+
this.#logger.log({ level: LogLevels.debug, message: `Closing connection lease that hasn't been returned.` });
|
|
89
89
|
await lease.returnLease();
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -94,7 +94,10 @@ export class DatabaseServer {
|
|
|
94
94
|
if (this.#activeClients.size == 0) {
|
|
95
95
|
await this.forceClose();
|
|
96
96
|
} else {
|
|
97
|
-
this.#logger.
|
|
97
|
+
this.#logger.log({
|
|
98
|
+
level: LogLevels.debug,
|
|
99
|
+
message: 'Keeping underlying connection active since its used by other clients.'
|
|
100
|
+
});
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
};
|
|
@@ -133,9 +136,9 @@ export class DatabaseServer {
|
|
|
133
136
|
try {
|
|
134
137
|
if (lease.write) {
|
|
135
138
|
// Collect update hooks invoked while the client had the write connection.
|
|
136
|
-
const {
|
|
137
|
-
if (
|
|
138
|
-
const updatedTables: string[] = JSON.parse(
|
|
139
|
+
const { rawRows } = await lease.lease.use((conn) => conn.execute(`SELECT powersync_update_hooks('get')`));
|
|
140
|
+
if (rawRows.length) {
|
|
141
|
+
const updatedTables: string[] = JSON.parse(rawRows[0][0] as string);
|
|
139
142
|
if (updatedTables.length) {
|
|
140
143
|
this.#updateBroadcastChannel.postMessage(updatedTables);
|
|
141
144
|
this.#pushTableUpdateToClients(updatedTables);
|
|
@@ -169,7 +172,10 @@ export class DatabaseServer {
|
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
async forceClose() {
|
|
172
|
-
this.#logger.
|
|
175
|
+
this.#logger.log({
|
|
176
|
+
level: LogLevels.debug,
|
|
177
|
+
message: `Closing connection to ${JSON.stringify(this.#inner.options)}.`
|
|
178
|
+
});
|
|
173
179
|
const connection = this.#inner;
|
|
174
180
|
this.#options.onClose();
|
|
175
181
|
this.#updateBroadcastChannel.close();
|
|
@@ -190,8 +196,8 @@ export interface ClientConnectionView {
|
|
|
190
196
|
* give other clients access to the database afterwards.
|
|
191
197
|
*/
|
|
192
198
|
requestAccess(write: boolean, timeoutMs?: number): Promise<string>;
|
|
193
|
-
execute(token: string, sql: string, params: any[] | undefined): Promise<
|
|
194
|
-
executeBatch(token: string, sql: string, params: any[][]): Promise<
|
|
199
|
+
execute(token: string, sql: string, params: any[] | undefined): Promise<RawWebResult>;
|
|
200
|
+
executeBatch(token: string, sql: string, params: any[][]): Promise<RawWebResult[]>;
|
|
195
201
|
completeAccess(token: string): Promise<void>;
|
|
196
202
|
|
|
197
203
|
/**
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
import { Factory as WaSqliteFactory, SQLITE_ROW } from '@journeyapps/wa-sqlite';
|
|
2
2
|
|
|
3
|
-
import { loadModuleAndVfs } from './vfs.js';
|
|
4
|
-
import {
|
|
3
|
+
import { loadModuleAndVfs, WASQLiteVFS } from './vfs.js';
|
|
4
|
+
import { TemporaryStorageOption } from '../options.js';
|
|
5
|
+
import { RawQueryResult, SqliteValue } from '@powersync/common';
|
|
6
|
+
import { maxPathNameLength } from '../resolveAndValidateOptions.js';
|
|
7
|
+
|
|
8
|
+
export interface RawWebResult extends Required<RawQueryResult> {
|
|
9
|
+
autocommit: boolean;
|
|
10
|
+
}
|
|
5
11
|
|
|
6
12
|
export interface RawResultSet {
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
columnNames: string[];
|
|
14
|
+
rawRows: SqliteValue[][];
|
|
9
15
|
}
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export interface RawWaSqliteDatabaseOptions {
|
|
21
|
+
filename: string;
|
|
22
|
+
readonly: boolean;
|
|
23
|
+
vfs: WASQLiteVFS;
|
|
24
|
+
encryptionKey: string | undefined;
|
|
25
|
+
temporaryStorage: TemporaryStorageOption;
|
|
26
|
+
cacheSizeKb: number;
|
|
16
27
|
}
|
|
17
28
|
|
|
18
29
|
/**
|
|
@@ -28,7 +39,7 @@ export class RawSqliteConnection {
|
|
|
28
39
|
*/
|
|
29
40
|
private db: number = 0;
|
|
30
41
|
|
|
31
|
-
constructor(readonly options:
|
|
42
|
+
constructor(readonly options: RawWaSqliteDatabaseOptions) {}
|
|
32
43
|
|
|
33
44
|
get isOpen(): boolean {
|
|
34
45
|
return this.db != 0;
|
|
@@ -37,8 +48,8 @@ export class RawSqliteConnection {
|
|
|
37
48
|
async init() {
|
|
38
49
|
const api = (this._sqliteAPI = await this.openSQLiteAPI());
|
|
39
50
|
this.db = await api.open_v2(
|
|
40
|
-
this.options.
|
|
41
|
-
this.options.
|
|
51
|
+
this.options.filename,
|
|
52
|
+
this.options.readonly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */
|
|
42
53
|
);
|
|
43
54
|
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
|
|
44
55
|
if (this.options.encryptionKey) {
|
|
@@ -52,6 +63,7 @@ export class RawSqliteConnection {
|
|
|
52
63
|
|
|
53
64
|
private async openSQLiteAPI(): Promise<SQLiteAPI> {
|
|
54
65
|
const { module, vfs } = await loadModuleAndVfs(this.options);
|
|
66
|
+
vfs.mxPathname = maxPathNameLength;
|
|
55
67
|
const sqlite3 = WaSqliteFactory(module);
|
|
56
68
|
sqlite3.vfs_register(vfs, true);
|
|
57
69
|
/**
|
|
@@ -63,7 +75,7 @@ export class RawSqliteConnection {
|
|
|
63
75
|
* Create the multiple cipher vfs if an encryption key is provided
|
|
64
76
|
*/
|
|
65
77
|
if (this.options.encryptionKey) {
|
|
66
|
-
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.
|
|
78
|
+
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.filename, 1]);
|
|
67
79
|
if (createResult !== 0) {
|
|
68
80
|
throw new Error('Failed to create multiple cipher vfs, Database encryption will not work');
|
|
69
81
|
}
|
|
@@ -87,12 +99,12 @@ export class RawSqliteConnection {
|
|
|
87
99
|
return this.requireSqlite().get_autocommit(this.db) != 0;
|
|
88
100
|
}
|
|
89
101
|
|
|
90
|
-
async execute(sql: string, bindings?: any[]): Promise<
|
|
102
|
+
async execute(sql: string, bindings?: any[]): Promise<RawWebResult> {
|
|
91
103
|
const resultSet = await this.executeSingleStatementRaw(sql, bindings);
|
|
92
104
|
return this.wrapQueryResults(this.requireSqlite(), resultSet);
|
|
93
105
|
}
|
|
94
106
|
|
|
95
|
-
async executeBatch(sql: string, bindings: any[][]): Promise<
|
|
107
|
+
async executeBatch(sql: string, bindings: any[][]): Promise<RawWebResult[]> {
|
|
96
108
|
const results = [];
|
|
97
109
|
const api = this.requireSqlite();
|
|
98
110
|
for await (const stmt of api.statements(this.db, sql)) {
|
|
@@ -110,21 +122,22 @@ export class RawSqliteConnection {
|
|
|
110
122
|
return results;
|
|
111
123
|
}
|
|
112
124
|
|
|
113
|
-
private wrapQueryResults(api: SQLiteAPI,
|
|
125
|
+
private wrapQueryResults(api: SQLiteAPI, { rawRows, columnNames }: RawResultSet): RawWebResult {
|
|
114
126
|
return {
|
|
115
|
-
|
|
116
|
-
|
|
127
|
+
rowsAffected: api.changes(this.db),
|
|
128
|
+
insertId: api.last_insert_id(this.db),
|
|
117
129
|
autocommit: api.get_autocommit(this.db) != 0,
|
|
118
|
-
|
|
130
|
+
rawRows,
|
|
131
|
+
columnNames
|
|
119
132
|
};
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
/**
|
|
123
136
|
* This executes a single statement using SQLite3 and returns the results as a {@link RawResultSet}.
|
|
124
137
|
*/
|
|
125
|
-
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet
|
|
138
|
+
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet> {
|
|
126
139
|
const results = await this.executeRaw(sql, bindings);
|
|
127
|
-
return results.length ? results[0] :
|
|
140
|
+
return results.length ? results[0] : { columnNames: [], rawRows: [] };
|
|
128
141
|
}
|
|
129
142
|
|
|
130
143
|
async executeRaw(sql: string, bindings?: any[]): Promise<RawResultSet[]> {
|
|
@@ -134,7 +147,7 @@ export class RawSqliteConnection {
|
|
|
134
147
|
let columns;
|
|
135
148
|
|
|
136
149
|
const rs = await this.stepThroughStatement(api, stmt, bindings ?? [], columns);
|
|
137
|
-
columns = rs.
|
|
150
|
+
columns = rs.columnNames;
|
|
138
151
|
if (columns.length) {
|
|
139
152
|
results.push(rs);
|
|
140
153
|
}
|
|
@@ -176,7 +189,7 @@ export class RawSqliteConnection {
|
|
|
176
189
|
}
|
|
177
190
|
|
|
178
191
|
knownColumns ??= api.column_names(stmt);
|
|
179
|
-
return {
|
|
192
|
+
return { columnNames: knownColumns, rawRows: rows };
|
|
180
193
|
}
|
|
181
194
|
|
|
182
195
|
async close() {
|
|
@@ -1,70 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DBAdapter, LogLevels, PowerSyncLogger, SQLOpenFactory } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_CACHE_SIZE_KB,
|
|
6
|
-
isServerSide,
|
|
7
|
-
ResolvedWebSQLFlags,
|
|
8
|
-
ResolvedWebSQLOpenOptions,
|
|
9
|
-
resolveWebSQLFlags,
|
|
10
|
-
TemporaryStorageOption,
|
|
11
|
-
WebSQLOpenFactoryOptions
|
|
12
|
-
} from '../web-sql-flags.js';
|
|
3
|
+
import { ResolvedWebSQLOpenOptions, WebSQLOpenOptions } from '../options.js';
|
|
13
4
|
import { SSRDBAdapter } from '../SSRDBAdapter.js';
|
|
14
5
|
import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './vfs.js';
|
|
15
6
|
import { MultiDatabaseServer } from '../../../worker/db/MultiDatabaseServer.js';
|
|
16
7
|
import { DatabaseClient, OpenWorkerConnection } from './DatabaseClient.js';
|
|
17
8
|
import { generateTabCloseSignal } from '../../../shared/tab_close_signal.js';
|
|
18
9
|
import { AsyncDbAdapter, PoolConnection } from '../AsyncWebAdapter.js';
|
|
10
|
+
import { RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
|
|
11
|
+
import { maxPathNameLength, resolveAndValidateOptions } from '../resolveAndValidateOptions.js';
|
|
12
|
+
import { connectToExistingWorker, connectToWorker, WorkerConnection } from '../../../worker/client.js';
|
|
19
13
|
|
|
20
|
-
export interface WASQLiteOpenFactoryOptions
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* If the {@link vfs} supports it, an additional amount of read-only connections to open. Using additional read
|
|
24
|
-
* connections can speed up queries by dispatching them to multiple workers running them concurrently.
|
|
25
|
-
*
|
|
26
|
-
* {@link WASQLiteVFS.OPFSWriteAheadVFS} is the only VFS with support for multiple connections, so this option is
|
|
27
|
-
* ignored for other VFS implementations.
|
|
28
|
-
*
|
|
29
|
-
* Defaults to 1.
|
|
30
|
-
*/
|
|
31
|
-
additionalReaders?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ResolvedWASQLiteOpenFactoryOptions extends ResolvedWebSQLOpenOptions {
|
|
35
|
-
vfs: WASQLiteVFS;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Whether this is a read-only connection opened for the `OPFSWriteAheadVFS` file system.
|
|
39
|
-
*/
|
|
40
|
-
isReadOnly: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface WorkerDBOpenerOptions extends ResolvedWASQLiteOpenFactoryOptions {
|
|
44
|
-
logLevel: ILogLevel;
|
|
45
|
-
/**
|
|
46
|
-
* A lock that is currently held by the client. When the lock is returned, we know the client is gone and that we need
|
|
47
|
-
* to clean up resources.
|
|
48
|
-
*/
|
|
49
|
-
lockName: string;
|
|
14
|
+
export interface WASQLiteOpenFactoryOptions {
|
|
15
|
+
open: WebSQLOpenOptions;
|
|
16
|
+
logger: PowerSyncLogger;
|
|
50
17
|
}
|
|
51
18
|
|
|
52
19
|
/**
|
|
53
20
|
* Opens a SQLite connection using WA-SQLite.
|
|
54
21
|
*/
|
|
55
22
|
export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
56
|
-
private
|
|
57
|
-
private logger:
|
|
23
|
+
private options: ResolvedWebSQLOpenOptions;
|
|
24
|
+
private logger: PowerSyncLogger;
|
|
58
25
|
|
|
59
|
-
constructor(
|
|
60
|
-
|
|
61
|
-
this.resolvedFlags = resolveWebSQLFlags(options.flags);
|
|
62
|
-
this.logger = options.logger ?? createLogger(`WASQLiteOpenFactory - ${this.options.dbFilename}`);
|
|
63
|
-
}
|
|
26
|
+
constructor(options: WASQLiteOpenFactoryOptions) {
|
|
27
|
+
this.options = resolveAndValidateOptions(options.open);
|
|
64
28
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
29
|
+
// Account for the fact that SQLite might append -journal suffixes
|
|
30
|
+
const maxLength = maxPathNameLength - 16;
|
|
31
|
+
if (this.options.dbFilename.length > maxLength) {
|
|
32
|
+
throw new Error(`dbFilename too long (max length is ${maxLength})`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.logger = options.logger;
|
|
68
36
|
}
|
|
69
37
|
|
|
70
38
|
protected openAdapter(): DBAdapter {
|
|
@@ -72,84 +40,81 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
72
40
|
}
|
|
73
41
|
|
|
74
42
|
openDB(): DBAdapter {
|
|
75
|
-
const {
|
|
76
|
-
|
|
77
|
-
} = this;
|
|
43
|
+
const { disableSSRWarning, enableMultiTabs, ssrMode } = this.options;
|
|
44
|
+
|
|
78
45
|
if (ssrMode) {
|
|
79
46
|
if (!disableSSRWarning) {
|
|
80
|
-
this.logger.
|
|
81
|
-
|
|
47
|
+
this.logger.log({
|
|
48
|
+
level: LogLevels.warn,
|
|
49
|
+
message: `
|
|
82
50
|
Running PowerSync in SSR mode.
|
|
83
51
|
Only empty query results will be returned.
|
|
84
52
|
Disable this warning by setting 'disableSSRWarning: true' in options.`
|
|
85
|
-
);
|
|
53
|
+
});
|
|
86
54
|
}
|
|
87
55
|
|
|
88
56
|
return new SSRDBAdapter();
|
|
89
57
|
}
|
|
90
58
|
|
|
91
59
|
if (!enableMultiTabs) {
|
|
92
|
-
this.logger.
|
|
93
|
-
|
|
94
|
-
|
|
60
|
+
this.logger.log({
|
|
61
|
+
level: LogLevels.warn,
|
|
62
|
+
message: 'Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.'
|
|
63
|
+
});
|
|
95
64
|
}
|
|
96
65
|
|
|
97
66
|
return this.openAdapter();
|
|
98
67
|
}
|
|
99
68
|
|
|
100
69
|
async openConnection(): Promise<PoolConnection> {
|
|
101
|
-
const { enableMultiTabs, useWebWorker } =
|
|
102
|
-
|
|
103
|
-
vfs = WASQLiteVFS.IDBBatchAtomicVFS,
|
|
104
|
-
temporaryStorage = TemporaryStorageOption.MEMORY,
|
|
105
|
-
cacheSizeKb = DEFAULT_CACHE_SIZE_KB,
|
|
106
|
-
encryptionKey
|
|
107
|
-
} = this.waOptions;
|
|
70
|
+
const { enableMultiTabs, useWebWorker, vfs, dbFilename, encryptionKey, temporaryStorage, cacheSizeKb } =
|
|
71
|
+
this.options;
|
|
108
72
|
|
|
109
73
|
if (!enableMultiTabs) {
|
|
110
|
-
this.logger.warn
|
|
74
|
+
this.logger.log({ level: LogLevels.warn, message: 'Multiple tabs are not enabled in this browser' });
|
|
111
75
|
}
|
|
112
76
|
|
|
113
|
-
const resolveOptions = (isReadOnly: boolean): ResolvedWASQLiteOpenFactoryOptions => ({
|
|
114
|
-
dbFilename: this.options.dbFilename,
|
|
115
|
-
dbLocation: this.options.dbLocation,
|
|
116
|
-
debugMode: this.options.debugMode,
|
|
117
|
-
vfs,
|
|
118
|
-
temporaryStorage,
|
|
119
|
-
cacheSizeKb,
|
|
120
|
-
flags: this.resolvedFlags,
|
|
121
|
-
encryptionKey: encryptionKey,
|
|
122
|
-
isReadOnly
|
|
123
|
-
});
|
|
124
|
-
|
|
125
77
|
let client: DatabaseClient;
|
|
126
78
|
let additionalReaders: DatabaseClient[] = [];
|
|
127
79
|
let requiresPersistentTriggers = vfsRequiresDedicatedWorkers(vfs);
|
|
128
80
|
|
|
81
|
+
function resolveRawWaSqliteDatabaseOptions(readonly: boolean): RawWaSqliteDatabaseOptions {
|
|
82
|
+
return {
|
|
83
|
+
filename: dbFilename,
|
|
84
|
+
readonly,
|
|
85
|
+
vfs,
|
|
86
|
+
encryptionKey,
|
|
87
|
+
temporaryStorage,
|
|
88
|
+
cacheSizeKb
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
129
92
|
if (useWebWorker) {
|
|
130
93
|
const optionsDbWorker = this.options.worker;
|
|
131
94
|
|
|
132
|
-
const openDatabaseWorker = async (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
:
|
|
147
|
-
|
|
148
|
-
|
|
95
|
+
const openDatabaseWorker = async (readonly: boolean): Promise<DatabaseClient> => {
|
|
96
|
+
let workerConnection: WorkerConnection;
|
|
97
|
+
if (typeof optionsDbWorker == 'function') {
|
|
98
|
+
const worker = optionsDbWorker(this.options);
|
|
99
|
+
workerConnection = connectToExistingWorker(worker, this.logger, 'database');
|
|
100
|
+
} else {
|
|
101
|
+
const needsDedicated = vfsRequiresDedicatedWorkers(vfs);
|
|
102
|
+
const useShared = !needsDedicated && enableMultiTabs;
|
|
103
|
+
|
|
104
|
+
workerConnection = connectToWorker({
|
|
105
|
+
service: 'database',
|
|
106
|
+
databaseIdentifier: this.options.dbFilename,
|
|
107
|
+
shared: useShared,
|
|
108
|
+
customWorker: optionsDbWorker,
|
|
109
|
+
loggerForErrors: this.logger
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const source = Comlink.wrap<OpenWorkerConnection>(workerConnection.endpoint);
|
|
149
114
|
const closeSignal = new AbortController();
|
|
150
115
|
const connection = await source.connect({
|
|
151
|
-
|
|
152
|
-
logLevel: this.
|
|
116
|
+
database: resolveRawWaSqliteDatabaseOptions(readonly),
|
|
117
|
+
logLevel: this.options.databaseWorkerLogLevel,
|
|
153
118
|
lockName: await generateTabCloseSignal(closeSignal.signal)
|
|
154
119
|
});
|
|
155
120
|
const clientOptions = {
|
|
@@ -159,28 +124,24 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
159
124
|
remoteCanCloseUnexpectedly: false,
|
|
160
125
|
onClose: () => {
|
|
161
126
|
closeSignal.abort();
|
|
162
|
-
|
|
163
|
-
workerPort.terminate();
|
|
164
|
-
} else {
|
|
165
|
-
workerPort.close();
|
|
166
|
-
}
|
|
127
|
+
workerConnection.close();
|
|
167
128
|
}
|
|
168
129
|
};
|
|
169
130
|
|
|
170
131
|
return new DatabaseClient(clientOptions, {
|
|
171
|
-
...
|
|
132
|
+
...this.options,
|
|
172
133
|
requiresPersistentTriggers
|
|
173
134
|
});
|
|
174
135
|
};
|
|
175
136
|
|
|
176
|
-
client = await openDatabaseWorker(
|
|
137
|
+
client = await openDatabaseWorker(false);
|
|
177
138
|
|
|
178
139
|
if (vfs == WASQLiteVFS.OPFSWriteAheadVFS) {
|
|
179
140
|
// This VFS supports concurrent reads, so we can open additional workers to host read-only connections for
|
|
180
141
|
// concurrent reads / writes.
|
|
181
142
|
const additionalReadersCount = this.options.additionalReaders ?? 1;
|
|
182
143
|
for (let i = 0; i < additionalReadersCount; i++) {
|
|
183
|
-
const reader = await openDatabaseWorker(
|
|
144
|
+
const reader = await openDatabaseWorker(true);
|
|
184
145
|
additionalReaders.push(reader);
|
|
185
146
|
}
|
|
186
147
|
}
|
|
@@ -189,12 +150,11 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
189
150
|
const localServer = new MultiDatabaseServer(this.logger);
|
|
190
151
|
requiresPersistentTriggers = true;
|
|
191
152
|
|
|
192
|
-
const
|
|
193
|
-
const connection = await localServer.openConnectionLocally(resolvedOptions);
|
|
153
|
+
const connection = await localServer.openConnectionLocally(this.logger, resolveRawWaSqliteDatabaseOptions(false));
|
|
194
154
|
client = new DatabaseClient(
|
|
195
155
|
{ connection, source: null, remoteCanCloseUnexpectedly: false },
|
|
196
156
|
{
|
|
197
|
-
...
|
|
157
|
+
...this.options,
|
|
198
158
|
requiresPersistentTriggers
|
|
199
159
|
}
|
|
200
160
|
);
|
|
@@ -206,18 +166,3 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
206
166
|
};
|
|
207
167
|
}
|
|
208
168
|
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Asserts that the factory options are valid.
|
|
212
|
-
*/
|
|
213
|
-
function assertValidWASQLiteOpenFactoryOptions(options: WASQLiteOpenFactoryOptions): void {
|
|
214
|
-
// The OPFS VFS only works in dedicated web workers.
|
|
215
|
-
if ('vfs' in options && 'flags' in options) {
|
|
216
|
-
const { vfs, flags = {} } = options;
|
|
217
|
-
if (vfs && vfsRequiresDedicatedWorkers(vfs) && 'useWebWorker' in flags && !flags.useWebWorker) {
|
|
218
|
-
throw new Error(
|
|
219
|
-
`Invalid configuration: The 'useWebWorker' flag must be true when using an OPFS-based VFS (${vfs}).`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|