@powersync/web 0.0.0-dev-20260503073249 → 0.0.0-dev-20260630141119
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 +1879 -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/OPFSCoopSyncVFS-DRKedN0p.js +2 -0
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.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/{src/attachments → attachments}/IndexDBFileSystemAdapter.js +1 -0
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.js +1 -0
- package/lib/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/db/PowerSyncDatabase.d.ts +67 -0
- package/lib/{src/db → db}/PowerSyncDatabase.js +48 -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 +15 -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 +2 -0
- 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 +3 -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 +12 -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 +12 -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 -10
- 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/{src/db → db}/adapters/wa-sqlite/vfs.js +1 -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 +5 -11
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.d.ts +13 -15
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.js +32 -69
- 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 +4 -2
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/userAgent.js +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} +2 -3
- package/lib/index.js.map +1 -0
- package/lib/{src/shared → shared}/navigator.js +1 -0
- package/lib/shared/navigator.js.map +1 -0
- package/lib/{src/shared → shared}/tab_close_signal.js +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 +26 -15
- package/lib/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +13 -0
- package/lib/{src/worker → worker}/sync/AbstractSharedSyncClientProvider.js +1 -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 -17
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +43 -51
- package/lib/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/{src/worker → worker}/sync/WorkerClient.d.ts +3 -4
- package/lib/{src/worker → worker}/sync/WorkerClient.js +3 -5
- 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 -33
- 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 +35 -24
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +63 -126
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +4 -22
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +38 -81
- package/src/db/sync/WebRemote.ts +23 -42
- 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 +40 -22
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +4 -10
- package/src/worker/sync/BroadcastLogger.ts +35 -103
- package/src/worker/sync/SharedSyncImplementation.ts +62 -73
- package/src/worker/sync/WorkerClient.ts +4 -8
- package/src/worker/worker.ts +38 -0
- package/dist/index.umd.js +0 -12277
- package/dist/index.umd.js.map +0 -1
- package/dist/worker/SharedSyncImplementation.umd.js +0 -16655
- package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
- package/dist/worker/WASQLiteDB.umd.js +0 -17810
- package/dist/worker/WASQLiteDB.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js +0 -4646
- package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.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 -94
- package/lib/src/db/PowerSyncDatabase.d.ts +0 -78
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +0 -23
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -26
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +0 -50
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +0 -30
- package/lib/src/db/adapters/SSRDBAdapter.js +0 -68
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -45
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -145
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +0 -15
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -21
- package/lib/src/db/adapters/web-sql-flags.d.ts +0 -92
- package/lib/src/db/adapters/web-sql-flags.js +0 -36
- package/lib/src/db/sync/WebRemote.d.ts +0 -9
- package/lib/src/db/sync/WebRemote.js +0 -44
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +0 -17
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +0 -4
- package/lib/src/worker/db/WASQLiteDB.worker.js +0 -30
- package/lib/src/worker/db/open-worker-database.d.ts +0 -14
- package/lib/src/worker/db/open-worker-database.js +0 -52
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -19
- package/lib/src/worker/sync/BroadcastLogger.d.ts +0 -47
- package/lib/src/worker/sync/BroadcastLogger.js +0 -128
- package/lib/src/worker/sync/SharedSyncImplementation.worker.d.ts +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +0 -11
- 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/db → db}/adapters/wa-sqlite/vfs.d.ts +0 -0
- /package/lib/{src/db → db}/sync/userAgent.d.ts +0 -0
- /package/lib/{src/shared → shared}/navigator.d.ts +0 -0
- /package/lib/{src/shared → shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{src/db/adapters/WebDBAdapter.js → worker/worker.d.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { LogLevels, SQLOpenOptions } from '@powersync/common';
|
|
2
|
+
import { WASQLiteVFS } from './wa-sqlite/vfs.js';
|
|
3
|
+
|
|
4
|
+
export interface WebSpecificOpenOptions {
|
|
5
|
+
/**
|
|
6
|
+
* SQLite operations are currently not supported in SSR mode.
|
|
7
|
+
* A warning will be logged if attempting to use SQLite in SSR.
|
|
8
|
+
* Setting this to `true` will disabled the warning above.
|
|
9
|
+
*/
|
|
10
|
+
disableSSRWarning: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Enables multi tab support.
|
|
14
|
+
*
|
|
15
|
+
* Enabling multi-tab support will transparently make PowerSync manage the sync process in a shared worker collecting
|
|
16
|
+
* Sync Streams across tabs. Additionally, it enables a shared worker for IndexedDB databases.
|
|
17
|
+
*
|
|
18
|
+
* It is still valid to open multiple tabs when this option is disabled, but the experience may be degrated as only
|
|
19
|
+
* one tab can sync at the time.
|
|
20
|
+
*
|
|
21
|
+
* This is enabled by default on Desktop browsers if shared workers are enabled, except for Safari.
|
|
22
|
+
*/
|
|
23
|
+
enableMultiTabs: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The SQLite connection is often executed through a web worker in order to offload computation and because some file
|
|
27
|
+
* system implementations (notably those based on web filesystem APIs like OPFS) are only available in workers.
|
|
28
|
+
*
|
|
29
|
+
* Manually disabling the use of web workers is not recommended, but can be useful for testing or for environments
|
|
30
|
+
* or toolchains where web workers are not supported.
|
|
31
|
+
*/
|
|
32
|
+
useWebWorker: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Open in SSR placeholder mode. DB operations and Sync operations will be a No-op
|
|
36
|
+
*/
|
|
37
|
+
ssrMode: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The log level for database workers.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to {@link LogLevels.info}.
|
|
43
|
+
*/
|
|
44
|
+
databaseWorkerLogLevel: number;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
|
|
48
|
+
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
|
|
49
|
+
*/
|
|
50
|
+
temporaryStorage: TemporaryStorageOption;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Maximum SQLite cache size. Defaults to 50MB.
|
|
54
|
+
*
|
|
55
|
+
* For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
|
|
56
|
+
*/
|
|
57
|
+
cacheSizeKb: number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Encryption key for the database.
|
|
61
|
+
* If set, the database will be encrypted using ChaCha20.
|
|
62
|
+
*/
|
|
63
|
+
encryptionKey: string | undefined;
|
|
64
|
+
|
|
65
|
+
vfs: WASQLiteVFS;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* If the {@link vfs} supports it, an additional amount of read-only connections to open. Using additional read
|
|
69
|
+
* connections can speed up queries by dispatching them to multiple workers running them concurrently.
|
|
70
|
+
*
|
|
71
|
+
* {@link WASQLiteVFS.OPFSWriteAheadVFS} is the only VFS with support for multiple connections, so this option is
|
|
72
|
+
* ignored for other VFS implementations.
|
|
73
|
+
*
|
|
74
|
+
* Defaults to 1.
|
|
75
|
+
*/
|
|
76
|
+
additionalReaders: number;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Allows you to override the default wasqlite db worker.
|
|
80
|
+
*
|
|
81
|
+
* You can either provide a path to the worker script
|
|
82
|
+
* or a factory method that returns a worker.
|
|
83
|
+
*/
|
|
84
|
+
worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => Worker | SharedWorker);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Use an existing port to an initialized worker.
|
|
88
|
+
* A worker will be initialized if none is provided
|
|
89
|
+
*/
|
|
90
|
+
workerPort?: MessagePort | undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export interface ResolvedWebSQLOpenOptions extends SQLOpenOptions, WebSpecificOpenOptions {}
|
|
94
|
+
|
|
95
|
+
export interface WebSQLOpenOptions extends SQLOpenOptions, Partial<WebSpecificOpenOptions> {}
|
|
96
|
+
|
|
97
|
+
export enum TemporaryStorageOption {
|
|
98
|
+
MEMORY = 'memory',
|
|
99
|
+
FILESYSTEM = 'file'
|
|
100
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LogLevels } from '@powersync/common';
|
|
2
|
+
import { TemporaryStorageOption, WebSpecificOpenOptions } from './options.js';
|
|
3
|
+
import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './wa-sqlite/vfs.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export function resolveAndValidateOptions<And = {}>(
|
|
9
|
+
options: Partial<WebSpecificOpenOptions> & And
|
|
10
|
+
): WebSpecificOpenOptions & And {
|
|
11
|
+
const defaults: WebSpecificOpenOptions = {
|
|
12
|
+
disableSSRWarning: false,
|
|
13
|
+
ssrMode: !('window' in globalThis),
|
|
14
|
+
/**
|
|
15
|
+
* Multiple tabs are by default not supported on Android, iOS and Safari.
|
|
16
|
+
* Other platforms will have multiple tabs enabled by default.
|
|
17
|
+
*/
|
|
18
|
+
enableMultiTabs:
|
|
19
|
+
typeof globalThis.navigator !== 'undefined' && // For SSR purposes
|
|
20
|
+
typeof SharedWorker !== 'undefined' &&
|
|
21
|
+
!navigator.userAgent.match(/(Android|iPhone|iPod|iPad)/i) &&
|
|
22
|
+
!(window as any).safari,
|
|
23
|
+
useWebWorker: true,
|
|
24
|
+
databaseWorkerLogLevel: LogLevels.info,
|
|
25
|
+
temporaryStorage: TemporaryStorageOption.MEMORY,
|
|
26
|
+
cacheSizeKb: 50 * 1024,
|
|
27
|
+
encryptionKey: undefined,
|
|
28
|
+
vfs: WASQLiteVFS.IDBBatchAtomicVFS,
|
|
29
|
+
additionalReaders: 1
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const resolved = Object.assign(defaults, options);
|
|
33
|
+
if (vfsRequiresDedicatedWorkers(resolved.vfs) && !resolved.useWebWorker) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Invalid configuration: The 'useWebWorker' flag must be true when using an OPFS-based VFS (${resolved.vfs}).`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return resolved;
|
|
40
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Mutex, UnlockFn } from '@powersync/
|
|
2
|
-
import { RawSqliteConnection } from './RawSqliteConnection.js';
|
|
3
|
-
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
1
|
+
import { Mutex, UnlockFn } from '@powersync/shared-internals';
|
|
2
|
+
import { RawSqliteConnection, RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* A wrapper around a {@link RawSqliteConnection} allowing multiple tabs to access it.
|
|
@@ -33,7 +32,7 @@ export class ConcurrentSqliteConnection {
|
|
|
33
32
|
this.leaseMutex = needsNavigatorLocks ? null : new Mutex();
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
get options():
|
|
35
|
+
get options(): RawWaSqliteDatabaseOptions {
|
|
37
36
|
return this.inner.options;
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -46,7 +45,7 @@ export class ConcurrentSqliteConnection {
|
|
|
46
45
|
const options: LockOptions = { signal: abort };
|
|
47
46
|
|
|
48
47
|
navigator.locks
|
|
49
|
-
.request(`db-lock-${this.options.
|
|
48
|
+
.request(`db-lock-${this.options.filename}`, options, (_) => {
|
|
50
49
|
return new Promise<void>((returnLock) => {
|
|
51
50
|
return resolve(() => {
|
|
52
51
|
returnLock();
|
|
@@ -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,7 @@ export class DatabaseServer {
|
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
async forceClose() {
|
|
172
|
-
this.#logger.debug
|
|
175
|
+
this.#logger.log({ level: LogLevels.debug, message: `Closing connection to ${this.#inner.options}.` });
|
|
173
176
|
const connection = this.#inner;
|
|
174
177
|
this.#options.onClose();
|
|
175
178
|
this.#updateBroadcastChannel.close();
|
|
@@ -190,8 +193,8 @@ export interface ClientConnectionView {
|
|
|
190
193
|
* give other clients access to the database afterwards.
|
|
191
194
|
*/
|
|
192
195
|
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<
|
|
196
|
+
execute(token: string, sql: string, params: any[] | undefined): Promise<RawWebResult>;
|
|
197
|
+
executeBatch(token: string, sql: string, params: any[][]): Promise<RawWebResult[]>;
|
|
195
198
|
completeAccess(token: string): Promise<void>;
|
|
196
199
|
|
|
197
200
|
/**
|
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
import { Factory as WaSqliteFactory, SQLITE_ROW } from '@journeyapps/wa-sqlite';
|
|
2
2
|
|
|
3
|
-
import { DEFAULT_MODULE_FACTORIES, WASQLiteModuleFactory } from './vfs.js';
|
|
4
|
-
import {
|
|
3
|
+
import { DEFAULT_MODULE_FACTORIES, WASQLiteModuleFactory, WASQLiteVFS } from './vfs.js';
|
|
4
|
+
import { TemporaryStorageOption } from '../options.js';
|
|
5
|
+
import { RawQueryResult, SqliteValue } from '@powersync/common';
|
|
6
|
+
|
|
7
|
+
export interface RawWebResult extends Required<RawQueryResult> {
|
|
8
|
+
autocommit: boolean;
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
export interface RawResultSet {
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
columnNames: string[];
|
|
13
|
+
rawRows: SqliteValue[][];
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export interface RawWaSqliteDatabaseOptions {
|
|
20
|
+
filename: string;
|
|
21
|
+
readonly: boolean;
|
|
22
|
+
vfs: WASQLiteVFS;
|
|
23
|
+
encryptionKey: string | undefined;
|
|
24
|
+
temporaryStorage: TemporaryStorageOption;
|
|
25
|
+
cacheSizeKb: number;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
/**
|
|
@@ -29,7 +39,7 @@ export class RawSqliteConnection {
|
|
|
29
39
|
private db: number = 0;
|
|
30
40
|
private _moduleFactory: WASQLiteModuleFactory;
|
|
31
41
|
|
|
32
|
-
constructor(readonly options:
|
|
42
|
+
constructor(readonly options: RawWaSqliteDatabaseOptions) {
|
|
33
43
|
this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
34
44
|
}
|
|
35
45
|
|
|
@@ -40,8 +50,8 @@ export class RawSqliteConnection {
|
|
|
40
50
|
async init() {
|
|
41
51
|
const api = (this._sqliteAPI = await this.openSQLiteAPI());
|
|
42
52
|
this.db = await api.open_v2(
|
|
43
|
-
this.options.
|
|
44
|
-
this.options.
|
|
53
|
+
this.options.filename,
|
|
54
|
+
this.options.readonly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */
|
|
45
55
|
);
|
|
46
56
|
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
|
|
47
57
|
if (this.options.encryptionKey) {
|
|
@@ -55,7 +65,7 @@ export class RawSqliteConnection {
|
|
|
55
65
|
|
|
56
66
|
private async openSQLiteAPI(): Promise<SQLiteAPI> {
|
|
57
67
|
const { module, vfs } = await this._moduleFactory({
|
|
58
|
-
dbFileName: this.options.
|
|
68
|
+
dbFileName: this.options.filename,
|
|
59
69
|
encryptionKey: this.options.encryptionKey
|
|
60
70
|
});
|
|
61
71
|
const sqlite3 = WaSqliteFactory(module);
|
|
@@ -69,7 +79,7 @@ export class RawSqliteConnection {
|
|
|
69
79
|
* Create the multiple cipher vfs if an encryption key is provided
|
|
70
80
|
*/
|
|
71
81
|
if (this.options.encryptionKey) {
|
|
72
|
-
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.
|
|
82
|
+
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.filename, 1]);
|
|
73
83
|
if (createResult !== 0) {
|
|
74
84
|
throw new Error('Failed to create multiple cipher vfs, Database encryption will not work');
|
|
75
85
|
}
|
|
@@ -93,12 +103,12 @@ export class RawSqliteConnection {
|
|
|
93
103
|
return this.requireSqlite().get_autocommit(this.db) != 0;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
|
-
async execute(sql: string, bindings?: any[]): Promise<
|
|
106
|
+
async execute(sql: string, bindings?: any[]): Promise<RawWebResult> {
|
|
97
107
|
const resultSet = await this.executeSingleStatementRaw(sql, bindings);
|
|
98
108
|
return this.wrapQueryResults(this.requireSqlite(), resultSet);
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
async executeBatch(sql: string, bindings: any[][]): Promise<
|
|
111
|
+
async executeBatch(sql: string, bindings: any[][]): Promise<RawWebResult[]> {
|
|
102
112
|
const results = [];
|
|
103
113
|
const api = this.requireSqlite();
|
|
104
114
|
for await (const stmt of api.statements(this.db, sql)) {
|
|
@@ -116,21 +126,22 @@ export class RawSqliteConnection {
|
|
|
116
126
|
return results;
|
|
117
127
|
}
|
|
118
128
|
|
|
119
|
-
private wrapQueryResults(api: SQLiteAPI,
|
|
129
|
+
private wrapQueryResults(api: SQLiteAPI, { rawRows, columnNames }: RawResultSet): RawWebResult {
|
|
120
130
|
return {
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
rowsAffected: api.changes(this.db),
|
|
132
|
+
insertId: api.last_insert_id(this.db),
|
|
123
133
|
autocommit: api.get_autocommit(this.db) != 0,
|
|
124
|
-
|
|
134
|
+
rawRows,
|
|
135
|
+
columnNames
|
|
125
136
|
};
|
|
126
137
|
}
|
|
127
138
|
|
|
128
139
|
/**
|
|
129
140
|
* This executes a single statement using SQLite3 and returns the results as a {@link RawResultSet}.
|
|
130
141
|
*/
|
|
131
|
-
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet
|
|
142
|
+
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet> {
|
|
132
143
|
const results = await this.executeRaw(sql, bindings);
|
|
133
|
-
return results.length ? results[0] :
|
|
144
|
+
return results.length ? results[0] : { columnNames: [], rawRows: [] };
|
|
134
145
|
}
|
|
135
146
|
|
|
136
147
|
async executeRaw(sql: string, bindings?: any[]): Promise<RawResultSet[]> {
|
|
@@ -140,7 +151,7 @@ export class RawSqliteConnection {
|
|
|
140
151
|
let columns;
|
|
141
152
|
|
|
142
153
|
const rs = await this.stepThroughStatement(api, stmt, bindings ?? [], columns);
|
|
143
|
-
columns = rs.
|
|
154
|
+
columns = rs.columnNames;
|
|
144
155
|
if (columns.length) {
|
|
145
156
|
results.push(rs);
|
|
146
157
|
}
|
|
@@ -182,7 +193,7 @@ export class RawSqliteConnection {
|
|
|
182
193
|
}
|
|
183
194
|
|
|
184
195
|
knownColumns ??= api.column_names(stmt);
|
|
185
|
-
return {
|
|
196
|
+
return { columnNames: knownColumns, rawRows: rows };
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
async close() {
|