@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,70 +1,31 @@
|
|
|
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 { 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:
|
|
58
|
-
|
|
59
|
-
constructor(private options: WASQLiteOpenFactoryOptions) {
|
|
60
|
-
assertValidWASQLiteOpenFactoryOptions(options);
|
|
61
|
-
this.resolvedFlags = resolveWebSQLFlags(options.flags);
|
|
62
|
-
this.logger = options.logger ?? createLogger(`WASQLiteOpenFactory - ${this.options.dbFilename}`);
|
|
63
|
-
}
|
|
23
|
+
private options: ResolvedWebSQLOpenOptions;
|
|
24
|
+
private logger: PowerSyncLogger;
|
|
64
25
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
26
|
+
constructor(options: WASQLiteOpenFactoryOptions) {
|
|
27
|
+
this.options = resolveAndValidateOptions(options.open);
|
|
28
|
+
this.logger = options.logger;
|
|
68
29
|
}
|
|
69
30
|
|
|
70
31
|
protected openAdapter(): DBAdapter {
|
|
@@ -72,84 +33,80 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
72
33
|
}
|
|
73
34
|
|
|
74
35
|
openDB(): DBAdapter {
|
|
75
|
-
const {
|
|
76
|
-
|
|
77
|
-
} = this;
|
|
36
|
+
const { disableSSRWarning, enableMultiTabs, ssrMode } = this.options;
|
|
37
|
+
|
|
78
38
|
if (ssrMode) {
|
|
79
39
|
if (!disableSSRWarning) {
|
|
80
|
-
this.logger.
|
|
81
|
-
|
|
40
|
+
this.logger.log({
|
|
41
|
+
level: LogLevels.warn,
|
|
42
|
+
message: `
|
|
82
43
|
Running PowerSync in SSR mode.
|
|
83
44
|
Only empty query results will be returned.
|
|
84
45
|
Disable this warning by setting 'disableSSRWarning: true' in options.`
|
|
85
|
-
);
|
|
46
|
+
});
|
|
86
47
|
}
|
|
87
48
|
|
|
88
49
|
return new SSRDBAdapter();
|
|
89
50
|
}
|
|
90
51
|
|
|
91
52
|
if (!enableMultiTabs) {
|
|
92
|
-
this.logger.
|
|
93
|
-
|
|
94
|
-
|
|
53
|
+
this.logger.log({
|
|
54
|
+
level: LogLevels.warn,
|
|
55
|
+
message: 'Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.'
|
|
56
|
+
});
|
|
95
57
|
}
|
|
96
58
|
|
|
97
59
|
return this.openAdapter();
|
|
98
60
|
}
|
|
99
61
|
|
|
100
62
|
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;
|
|
63
|
+
const { enableMultiTabs, useWebWorker, vfs, dbFilename, encryptionKey, temporaryStorage, cacheSizeKb } =
|
|
64
|
+
this.options;
|
|
108
65
|
|
|
109
66
|
if (!enableMultiTabs) {
|
|
110
|
-
this.logger.warn
|
|
67
|
+
this.logger.log({ level: LogLevels.warn, message: 'Multiple tabs are not enabled in this browser' });
|
|
111
68
|
}
|
|
112
69
|
|
|
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
70
|
let client: DatabaseClient;
|
|
126
71
|
let additionalReaders: DatabaseClient[] = [];
|
|
127
72
|
let requiresPersistentTriggers = vfsRequiresDedicatedWorkers(vfs);
|
|
128
73
|
|
|
74
|
+
function resolveRawWaSqliteDatabaseOptions(readonly: boolean): RawWaSqliteDatabaseOptions {
|
|
75
|
+
return {
|
|
76
|
+
filename: dbFilename,
|
|
77
|
+
readonly,
|
|
78
|
+
vfs,
|
|
79
|
+
encryptionKey,
|
|
80
|
+
temporaryStorage,
|
|
81
|
+
cacheSizeKb
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
129
85
|
if (useWebWorker) {
|
|
130
86
|
const optionsDbWorker = this.options.worker;
|
|
131
87
|
|
|
132
|
-
const openDatabaseWorker = async (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
88
|
+
const openDatabaseWorker = async (readonly: boolean): Promise<DatabaseClient> => {
|
|
89
|
+
let workerConnection: WorkerConnection;
|
|
90
|
+
if (typeof optionsDbWorker == 'function') {
|
|
91
|
+
const worker = optionsDbWorker(this.options);
|
|
92
|
+
workerConnection = connectToExistingWorker(worker, 'database');
|
|
93
|
+
} else {
|
|
94
|
+
const needsDedicated = vfsRequiresDedicatedWorkers(vfs);
|
|
95
|
+
const useShared = !needsDedicated && enableMultiTabs;
|
|
96
|
+
|
|
97
|
+
workerConnection = connectToWorker({
|
|
98
|
+
service: 'database',
|
|
99
|
+
databaseIdentifier: this.options.dbFilename,
|
|
100
|
+
shared: useShared,
|
|
101
|
+
customWorker: optionsDbWorker
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const source = Comlink.wrap<OpenWorkerConnection>(workerConnection.endpoint);
|
|
149
106
|
const closeSignal = new AbortController();
|
|
150
107
|
const connection = await source.connect({
|
|
151
|
-
|
|
152
|
-
logLevel: this.
|
|
108
|
+
database: resolveRawWaSqliteDatabaseOptions(readonly),
|
|
109
|
+
logLevel: this.options.databaseWorkerLogLevel,
|
|
153
110
|
lockName: await generateTabCloseSignal(closeSignal.signal)
|
|
154
111
|
});
|
|
155
112
|
const clientOptions = {
|
|
@@ -159,28 +116,24 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
159
116
|
remoteCanCloseUnexpectedly: false,
|
|
160
117
|
onClose: () => {
|
|
161
118
|
closeSignal.abort();
|
|
162
|
-
|
|
163
|
-
workerPort.terminate();
|
|
164
|
-
} else {
|
|
165
|
-
workerPort.close();
|
|
166
|
-
}
|
|
119
|
+
workerConnection.close();
|
|
167
120
|
}
|
|
168
121
|
};
|
|
169
122
|
|
|
170
123
|
return new DatabaseClient(clientOptions, {
|
|
171
|
-
...
|
|
124
|
+
...this.options,
|
|
172
125
|
requiresPersistentTriggers
|
|
173
126
|
});
|
|
174
127
|
};
|
|
175
128
|
|
|
176
|
-
client = await openDatabaseWorker(
|
|
129
|
+
client = await openDatabaseWorker(false);
|
|
177
130
|
|
|
178
131
|
if (vfs == WASQLiteVFS.OPFSWriteAheadVFS) {
|
|
179
132
|
// This VFS supports concurrent reads, so we can open additional workers to host read-only connections for
|
|
180
133
|
// concurrent reads / writes.
|
|
181
134
|
const additionalReadersCount = this.options.additionalReaders ?? 1;
|
|
182
135
|
for (let i = 0; i < additionalReadersCount; i++) {
|
|
183
|
-
const reader = await openDatabaseWorker(
|
|
136
|
+
const reader = await openDatabaseWorker(true);
|
|
184
137
|
additionalReaders.push(reader);
|
|
185
138
|
}
|
|
186
139
|
}
|
|
@@ -189,12 +142,11 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
189
142
|
const localServer = new MultiDatabaseServer(this.logger);
|
|
190
143
|
requiresPersistentTriggers = true;
|
|
191
144
|
|
|
192
|
-
const
|
|
193
|
-
const connection = await localServer.openConnectionLocally(resolvedOptions);
|
|
145
|
+
const connection = await localServer.openConnectionLocally(this.logger, resolveRawWaSqliteDatabaseOptions(false));
|
|
194
146
|
client = new DatabaseClient(
|
|
195
147
|
{ connection, source: null, remoteCanCloseUnexpectedly: false },
|
|
196
148
|
{
|
|
197
|
-
...
|
|
149
|
+
...this.options,
|
|
198
150
|
requiresPersistentTriggers
|
|
199
151
|
}
|
|
200
152
|
);
|
|
@@ -206,18 +158,3 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
206
158
|
};
|
|
207
159
|
}
|
|
208
160
|
}
|
|
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
|
-
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as SQLite from '@journeyapps/wa-sqlite';
|
|
2
|
+
import { RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* List of currently tested virtual filesystems
|
|
@@ -7,11 +8,28 @@ export enum WASQLiteVFS {
|
|
|
7
8
|
IDBBatchAtomicVFS = 'IDBBatchAtomicVFS',
|
|
8
9
|
OPFSCoopSyncVFS = 'OPFSCoopSyncVFS',
|
|
9
10
|
AccessHandlePoolVFS = 'AccessHandlePoolVFS',
|
|
10
|
-
OPFSWriteAheadVFS = 'OPFSWriteAheadVFS'
|
|
11
|
+
OPFSWriteAheadVFS = 'OPFSWriteAheadVFS',
|
|
12
|
+
/**
|
|
13
|
+
* A virtual file system storing data in-memory only, without persistence.
|
|
14
|
+
*
|
|
15
|
+
* This file system can be used in three configurations:
|
|
16
|
+
*
|
|
17
|
+
* 1. In shared workers (the default when available): All tabs share the same in-memory database, which is cleared
|
|
18
|
+
* once the last tab is closed.
|
|
19
|
+
* 2. In dedicated workers (used when `enableMultiTabs` is disabled). Each tab has its own in-memory database cleared
|
|
20
|
+
* when the tab is closed. Queries are offloaded to a dedicated worker.
|
|
21
|
+
* 3. In the context of the tab itself (used when both `enableMultiTabs` and `useWebWorker` are disabled). The per-tab
|
|
22
|
+
* database is hosted in the tab itself, and queries run synchronously. This is _a lot_ faster than any other
|
|
23
|
+
* single-threadedVFS, but can block JavaScript for computationally-intensive queries.
|
|
24
|
+
*
|
|
25
|
+
* This VFS primarily intended for development, but it also useful for online-first deployments not syncing large
|
|
26
|
+
* amounts of data, as it is quicker to start up.
|
|
27
|
+
*/
|
|
28
|
+
InMemoryVfs = 'InMemoryVFS'
|
|
11
29
|
}
|
|
12
30
|
|
|
13
31
|
export function vfsRequiresDedicatedWorkers(vfs: WASQLiteVFS) {
|
|
14
|
-
return vfs != WASQLiteVFS.IDBBatchAtomicVFS;
|
|
32
|
+
return vfs != WASQLiteVFS.IDBBatchAtomicVFS && vfs != WASQLiteVFS.InMemoryVfs;
|
|
15
33
|
}
|
|
16
34
|
|
|
17
35
|
/**
|
|
@@ -24,14 +42,7 @@ export type WASQLiteModuleFactoryOptions = { dbFileName: string; encryptionKey?:
|
|
|
24
42
|
*/
|
|
25
43
|
export type SQLiteModule = Parameters<typeof SQLite.Factory>[0];
|
|
26
44
|
|
|
27
|
-
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export type WASQLiteModuleFactory = (
|
|
31
|
-
options: WASQLiteModuleFactoryOptions
|
|
32
|
-
) => Promise<{ module: SQLiteModule; vfs: SQLiteVFS }>;
|
|
33
|
-
|
|
34
|
-
async function asyncModuleFactory(encryptionKey: unknown) {
|
|
45
|
+
async function asyncModuleFactory(encryptionKey: string | undefined): Promise<SQLiteModule> {
|
|
35
46
|
if (encryptionKey) {
|
|
36
47
|
const { default: factory } = await import('@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs');
|
|
37
48
|
return factory();
|
|
@@ -41,7 +52,7 @@ async function asyncModuleFactory(encryptionKey: unknown) {
|
|
|
41
52
|
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
|
-
async function syncModuleFactory(encryptionKey:
|
|
55
|
+
async function syncModuleFactory(encryptionKey: string | undefined): Promise<SQLiteModule> {
|
|
45
56
|
if (encryptionKey) {
|
|
46
57
|
const { default: factory } = await import('@journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs');
|
|
47
58
|
return factory();
|
|
@@ -54,43 +65,50 @@ async function syncModuleFactory(encryptionKey: unknown) {
|
|
|
54
65
|
/**
|
|
55
66
|
* @internal
|
|
56
67
|
*/
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
export async function loadModuleAndVfs({
|
|
69
|
+
vfs,
|
|
70
|
+
filename,
|
|
71
|
+
encryptionKey
|
|
72
|
+
}: RawWaSqliteDatabaseOptions): Promise<{ module: SQLiteModule; vfs: SQLiteVFS }> {
|
|
73
|
+
let moduleFactory = syncModuleFactory;
|
|
74
|
+
let resolveVfs: (module: any) => Promise<SQLiteVFS>;
|
|
75
|
+
|
|
76
|
+
switch (vfs) {
|
|
77
|
+
case WASQLiteVFS.IDBBatchAtomicVFS: {
|
|
78
|
+
moduleFactory = asyncModuleFactory;
|
|
79
|
+
const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
|
|
80
|
+
resolveVfs = (module) => {
|
|
81
|
+
// @ts-expect-error The types for this static method are missing upstream
|
|
82
|
+
return IDBBatchAtomicVFS.create(filename, module, { lockPolicy: 'exclusive' });
|
|
83
|
+
};
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case WASQLiteVFS.AccessHandlePoolVFS: {
|
|
87
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
88
|
+
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
89
|
+
resolveVfs = (module) => AccessHandlePoolVFS.create(filename, module);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case WASQLiteVFS.OPFSCoopSyncVFS: {
|
|
93
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
94
|
+
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
95
|
+
resolveVfs = (module) => OPFSCoopSyncVFS.create(filename, module);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case WASQLiteVFS.OPFSWriteAheadVFS: {
|
|
99
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
100
|
+
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
101
|
+
resolveVfs = (module) => OPFSWriteAheadVFS.create(filename, module, {});
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case WASQLiteVFS.InMemoryVfs: {
|
|
105
|
+
const { MemoryVFS } = await import('@journeyapps/wa-sqlite/src/examples/MemoryVFS.js');
|
|
63
106
|
// @ts-expect-error The types for this static method are missing upstream
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
[WASQLiteVFS.AccessHandlePoolVFS]: async (options: WASQLiteModuleFactoryOptions) => {
|
|
68
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
69
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
70
|
-
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
71
|
-
return {
|
|
72
|
-
module,
|
|
73
|
-
vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
[WASQLiteVFS.OPFSCoopSyncVFS]: async (options: WASQLiteModuleFactoryOptions) => {
|
|
77
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
78
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
79
|
-
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
80
|
-
const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
|
|
81
|
-
return {
|
|
82
|
-
module,
|
|
83
|
-
vfs
|
|
84
|
-
};
|
|
85
|
-
},
|
|
86
|
-
[WASQLiteVFS.OPFSWriteAheadVFS]: async (options: WASQLiteModuleFactoryOptions) => {
|
|
87
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
88
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
89
|
-
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
90
|
-
const vfs = await OPFSWriteAheadVFS.create(options.dbFileName, module, {});
|
|
91
|
-
return {
|
|
92
|
-
module,
|
|
93
|
-
vfs
|
|
94
|
-
};
|
|
107
|
+
resolveVfs = (module) => MemoryVFS.create(filename, module);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
95
110
|
}
|
|
96
|
-
|
|
111
|
+
|
|
112
|
+
const module = await moduleFactory(encryptionKey);
|
|
113
|
+
return { module, vfs: await resolveVfs(module) };
|
|
114
|
+
}
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
BaseObserver,
|
|
4
|
-
LockOptions,
|
|
5
|
-
LockType,
|
|
6
|
-
Mutex,
|
|
7
|
-
PowerSyncConnectionOptions,
|
|
8
|
-
StreamingSyncImplementation,
|
|
9
|
-
SyncStatus,
|
|
10
|
-
SyncStatusOptions
|
|
11
|
-
} from '@powersync/common';
|
|
1
|
+
import { BaseObserver, SyncStatus } from '@powersync/common';
|
|
2
|
+
import { Mutex, StreamingSyncImplementation, LockOptions, LockType } from '@powersync/shared-internals';
|
|
12
3
|
|
|
13
4
|
export class SSRStreamingSyncImplementation extends BaseObserver implements StreamingSyncImplementation {
|
|
14
5
|
syncMutex: Mutex;
|
|
@@ -16,13 +7,11 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
16
7
|
|
|
17
8
|
isConnected: boolean;
|
|
18
9
|
lastSyncedAt?: Date | undefined;
|
|
19
|
-
syncStatus: SyncStatus;
|
|
20
10
|
|
|
21
|
-
constructor(
|
|
11
|
+
constructor() {
|
|
22
12
|
super();
|
|
23
13
|
this.syncMutex = new Mutex();
|
|
24
14
|
this.crudMutex = new Mutex();
|
|
25
|
-
this.syncStatus = new SyncStatus({});
|
|
26
15
|
this.isConnected = false;
|
|
27
16
|
}
|
|
28
17
|
|
|
@@ -34,7 +23,7 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
34
23
|
/**
|
|
35
24
|
* This is a no-op in SSR mode
|
|
36
25
|
*/
|
|
37
|
-
async connect(
|
|
26
|
+
async connect(): Promise<void> {}
|
|
38
27
|
|
|
39
28
|
async dispose() {}
|
|
40
29
|
|
|
@@ -48,13 +37,6 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
48
37
|
*/
|
|
49
38
|
async waitForReady() {}
|
|
50
39
|
|
|
51
|
-
/**
|
|
52
|
-
* This will never resolve in SSR Mode.
|
|
53
|
-
*/
|
|
54
|
-
async waitForStatus(status: SyncStatusOptions) {
|
|
55
|
-
return this.waitUntilStatusMatches(() => false);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
40
|
/**
|
|
59
41
|
* This will never resolve in SSR Mode.
|
|
60
42
|
*/
|