@powersync/web 0.0.0-dev-20260630141119 → 0.0.0-dev-20260708103617
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.umd.js +7821 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/worker/SharedSyncImplementation.umd.js +16139 -0
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -0
- package/dist/worker/WASQLiteDB.umd.js +17434 -0
- package/dist/worker/WASQLiteDB.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +31 -0
- 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 +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +31 -0
- 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 +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +3562 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +2478 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +1681 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +1820 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +1 -0
- package/lib/package.json +91 -0
- package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{db → src/db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/src/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +78 -0
- package/lib/{db → src/db}/PowerSyncDatabase.js +61 -47
- package/lib/src/db/PowerSyncDatabase.js.map +1 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +23 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +27 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +50 -0
- package/lib/{db → src/db}/adapters/AsyncWebAdapter.js +14 -14
- package/lib/src/db/adapters/AsyncWebAdapter.js.map +1 -0
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +30 -0
- package/lib/src/db/adapters/SSRDBAdapter.js +69 -0
- package/lib/src/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/src/db/adapters/WebDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +4 -3
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
- package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.js +37 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.js +7 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +12 -23
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.js +11 -17
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +45 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +146 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +15 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +22 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +40 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js +95 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/src/db/adapters/web-sql-flags.d.ts +92 -0
- package/lib/src/db/adapters/web-sql-flags.js +37 -0
- package/lib/src/db/adapters/web-sql-flags.js.map +1 -0
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.d.ts +8 -4
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.js +11 -4
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.d.ts +14 -13
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.js +66 -31
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/WebRemote.d.ts +7 -0
- package/lib/src/db/sync/WebRemote.js +33 -0
- package/lib/src/db/sync/WebRemote.js.map +1 -0
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.d.ts +4 -2
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.js +2 -3
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/userAgent.js.map +1 -0
- package/lib/{index.d.ts → src/index.d.ts} +3 -1
- package/lib/{index.js → src/index.js} +3 -1
- package/lib/src/index.js.map +1 -0
- package/lib/src/shared/navigator.js.map +1 -0
- package/lib/src/shared/tab_close_signal.js.map +1 -0
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +17 -0
- package/lib/{worker → src/worker}/db/MultiDatabaseServer.js +18 -26
- package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +4 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +31 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +1 -0
- package/lib/src/worker/db/open-worker-database.d.ts +14 -0
- package/lib/src/worker/db/open-worker-database.js +53 -0
- package/lib/src/worker/db/open-worker-database.js.map +1 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +19 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/src/worker/sync/BroadcastLogger.d.ts +47 -0
- package/lib/src/worker/sync/BroadcastLogger.js +129 -0
- package/lib/src/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.d.ts +15 -11
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.js +43 -42
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +12 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +1 -0
- package/lib/{worker → src/worker}/sync/WorkerClient.d.ts +3 -3
- package/lib/{worker → src/worker}/sync/WorkerClient.js +2 -2
- package/lib/src/worker/sync/WorkerClient.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -22
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +122 -80
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +47 -0
- package/src/db/adapters/AsyncWebAdapter.ts +26 -17
- package/src/db/adapters/SSRDBAdapter.ts +64 -14
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +5 -4
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +56 -20
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +12 -15
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +24 -41
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +126 -63
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +24 -0
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
- package/src/db/adapters/web-sql-flags.ts +141 -0
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +22 -4
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +77 -38
- package/src/db/sync/WebRemote.ts +26 -23
- package/src/db/sync/WebStreamingSyncImplementation.ts +5 -4
- package/src/index.ts +3 -1
- package/src/worker/db/MultiDatabaseServer.ts +25 -41
- package/src/worker/db/WASQLiteDB.worker.ts +35 -0
- package/src/worker/db/open-worker-database.ts +62 -0
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +10 -4
- package/src/worker/sync/BroadcastLogger.ts +103 -35
- package/src/worker/sync/SharedSyncImplementation.ts +63 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +14 -0
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/dist/index.react_native_web.js +0 -1879
- package/dist/index.react_native_web.js.map +0 -1
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +0 -2
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +0 -1
- package/dist/worker/FacadeVFS-d1ZDvud7.js +0 -2
- package/dist/worker/FacadeVFS-d1ZDvud7.js.map +0 -1
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +0 -2
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +0 -1
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js +0 -2
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js.map +0 -1
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +0 -2
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js +0 -2
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +0 -2
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +0 -1
- package/dist/worker/wa-sqlite-BlSx7-_P.js +0 -2
- package/dist/worker/wa-sqlite-BlSx7-_P.js.map +0 -1
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js +0 -2
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js.map +0 -1
- package/dist/worker/websockets-Q8W_lerF.js +0 -9
- package/dist/worker/websockets-Q8W_lerF.js.map +0 -1
- package/dist/worker/worker.js +0 -7
- package/dist/worker/worker.js.map +0 -1
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +0 -1
- package/lib/db/NavigatorTriggerClaimManager.js.map +0 -1
- package/lib/db/PowerSyncDatabase.d.ts +0 -67
- package/lib/db/PowerSyncDatabase.js.map +0 -1
- package/lib/db/adapters/AsyncWebAdapter.d.ts +0 -32
- package/lib/db/adapters/AsyncWebAdapter.js.map +0 -1
- package/lib/db/adapters/SSRDBAdapter.d.ts +0 -17
- package/lib/db/adapters/SSRDBAdapter.js +0 -37
- package/lib/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/db/adapters/WebDBAdapter.js.map +0 -1
- package/lib/db/adapters/options.d.ts +0 -87
- package/lib/db/adapters/options.js +0 -6
- package/lib/db/adapters/options.js.map +0 -1
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +0 -5
- package/lib/db/adapters/resolveAndValidateOptions.js +0 -33
- package/lib/db/adapters/resolveAndValidateOptions.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -18
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -131
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/vfs.d.ts +0 -50
- package/lib/db/adapters/wa-sqlite/vfs.js +0 -77
- package/lib/db/adapters/wa-sqlite/vfs.js.map +0 -1
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/WebRemote.d.ts +0 -10
- package/lib/db/sync/WebRemote.js +0 -33
- package/lib/db/sync/WebRemote.js.map +0 -1
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/userAgent.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/shared/navigator.js.map +0 -1
- package/lib/shared/tab_close_signal.js.map +0 -1
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +0 -5
- package/lib/worker/SharedWorkerConnectionRequest.js +0 -2
- package/lib/worker/SharedWorkerConnectionRequest.js.map +0 -1
- package/lib/worker/client.d.ts +0 -15
- package/lib/worker/client.js +0 -77
- package/lib/worker/client.js.map +0 -1
- package/lib/worker/db/MultiDatabaseServer.d.ts +0 -22
- package/lib/worker/db/MultiDatabaseServer.js.map +0 -1
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -13
- package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/worker/sync/BroadcastLogger.d.ts +0 -27
- package/lib/worker/sync/BroadcastLogger.js +0 -65
- package/lib/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/worker/sync/WorkerClient.js.map +0 -1
- package/lib/worker/worker.js +0 -34
- package/lib/worker/worker.js.map +0 -1
- package/src/db/adapters/options.ts +0 -100
- package/src/db/adapters/resolveAndValidateOptions.ts +0 -40
- package/src/worker/SharedWorkerConnectionRequest.ts +0 -6
- package/src/worker/client.ts +0 -100
- package/src/worker/worker.ts +0 -38
- /package/dist/{worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm → 2075a31bb151adbb9767.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-XZW__iJk.wasm → 3322bc84de986b63c2cd.wasm} +0 -0
- /package/dist/{worker/assets/mc-wa-sqlite-CnHbhWvs.wasm → 8e97452e297be23b5e50.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-async-rHzzC98y.wasm → fbc178b70d530e8ce02b.wasm} +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.js +0 -0
- /package/lib/{db → src/db}/NavigatorTriggerClaimManager.js +0 -0
- /package/lib/{db → src/db}/adapters/WebDBAdapter.js +0 -0
- /package/lib/{db → src/db}/sync/userAgent.d.ts +0 -0
- /package/lib/{db → src/db}/sync/userAgent.js +0 -0
- /package/lib/{shared → src/shared}/navigator.d.ts +0 -0
- /package/lib/{shared → src/shared}/navigator.js +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.js +0 -0
- /package/lib/{worker → src/worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
- /package/lib/{worker/worker.d.ts → src/worker/sync/SharedSyncImplementation.worker.d.ts} +0 -0
|
@@ -1,31 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLogger, DBAdapter, ILogger, SQLOpenFactory, type ILogLevel } from '@powersync/common';
|
|
2
2
|
import * as Comlink from 'comlink';
|
|
3
|
-
import {
|
|
3
|
+
import { openWorkerDatabasePort, resolveWorkerDatabasePortFactory } from '../../../worker/db/open-worker-database.js';
|
|
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';
|
|
4
13
|
import { SSRDBAdapter } from '../SSRDBAdapter.js';
|
|
5
14
|
import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './vfs.js';
|
|
6
15
|
import { MultiDatabaseServer } from '../../../worker/db/MultiDatabaseServer.js';
|
|
7
16
|
import { DatabaseClient, OpenWorkerConnection } from './DatabaseClient.js';
|
|
8
17
|
import { generateTabCloseSignal } from '../../../shared/tab_close_signal.js';
|
|
9
18
|
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';
|
|
13
19
|
|
|
14
|
-
export interface WASQLiteOpenFactoryOptions {
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
export interface WASQLiteOpenFactoryOptions extends WebSQLOpenFactoryOptions {
|
|
21
|
+
vfs?: WASQLiteVFS;
|
|
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;
|
|
17
50
|
}
|
|
18
51
|
|
|
19
52
|
/**
|
|
20
53
|
* Opens a SQLite connection using WA-SQLite.
|
|
21
54
|
*/
|
|
22
55
|
export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
23
|
-
private
|
|
24
|
-
private logger:
|
|
56
|
+
private resolvedFlags: ResolvedWebSQLFlags;
|
|
57
|
+
private logger: ILogger;
|
|
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
|
+
}
|
|
25
64
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.
|
|
65
|
+
get waOptions(): WASQLiteOpenFactoryOptions {
|
|
66
|
+
// Cast to extended type
|
|
67
|
+
return this.options;
|
|
29
68
|
}
|
|
30
69
|
|
|
31
70
|
protected openAdapter(): DBAdapter {
|
|
@@ -33,80 +72,84 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
33
72
|
}
|
|
34
73
|
|
|
35
74
|
openDB(): DBAdapter {
|
|
36
|
-
const {
|
|
37
|
-
|
|
75
|
+
const {
|
|
76
|
+
resolvedFlags: { disableSSRWarning, enableMultiTabs, ssrMode = isServerSide() }
|
|
77
|
+
} = this;
|
|
38
78
|
if (ssrMode) {
|
|
39
79
|
if (!disableSSRWarning) {
|
|
40
|
-
this.logger.
|
|
41
|
-
|
|
42
|
-
message: `
|
|
80
|
+
this.logger.warn(
|
|
81
|
+
`
|
|
43
82
|
Running PowerSync in SSR mode.
|
|
44
83
|
Only empty query results will be returned.
|
|
45
84
|
Disable this warning by setting 'disableSSRWarning: true' in options.`
|
|
46
|
-
|
|
85
|
+
);
|
|
47
86
|
}
|
|
48
87
|
|
|
49
88
|
return new SSRDBAdapter();
|
|
50
89
|
}
|
|
51
90
|
|
|
52
91
|
if (!enableMultiTabs) {
|
|
53
|
-
this.logger.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
92
|
+
this.logger.warn(
|
|
93
|
+
'Multiple tab support is not enabled. Using this site across multiple tabs may not function correctly.'
|
|
94
|
+
);
|
|
57
95
|
}
|
|
58
96
|
|
|
59
97
|
return this.openAdapter();
|
|
60
98
|
}
|
|
61
99
|
|
|
62
100
|
async openConnection(): Promise<PoolConnection> {
|
|
63
|
-
const { enableMultiTabs, useWebWorker
|
|
64
|
-
|
|
101
|
+
const { enableMultiTabs, useWebWorker } = this.resolvedFlags;
|
|
102
|
+
const {
|
|
103
|
+
vfs = WASQLiteVFS.IDBBatchAtomicVFS,
|
|
104
|
+
temporaryStorage = TemporaryStorageOption.MEMORY,
|
|
105
|
+
cacheSizeKb = DEFAULT_CACHE_SIZE_KB,
|
|
106
|
+
encryptionKey
|
|
107
|
+
} = this.waOptions;
|
|
65
108
|
|
|
66
109
|
if (!enableMultiTabs) {
|
|
67
|
-
this.logger.
|
|
110
|
+
this.logger.warn('Multiple tabs are not enabled in this browser');
|
|
68
111
|
}
|
|
69
112
|
|
|
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
|
+
|
|
70
125
|
let client: DatabaseClient;
|
|
71
126
|
let additionalReaders: DatabaseClient[] = [];
|
|
72
127
|
let requiresPersistentTriggers = vfsRequiresDedicatedWorkers(vfs);
|
|
73
128
|
|
|
74
|
-
function resolveRawWaSqliteDatabaseOptions(readonly: boolean): RawWaSqliteDatabaseOptions {
|
|
75
|
-
return {
|
|
76
|
-
filename: dbFilename,
|
|
77
|
-
readonly,
|
|
78
|
-
vfs,
|
|
79
|
-
encryptionKey,
|
|
80
|
-
temporaryStorage,
|
|
81
|
-
cacheSizeKb
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
129
|
if (useWebWorker) {
|
|
86
130
|
const optionsDbWorker = this.options.worker;
|
|
87
131
|
|
|
88
|
-
const openDatabaseWorker = async (
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const source = Comlink.wrap<OpenWorkerConnection>(workerConnection.endpoint);
|
|
132
|
+
const openDatabaseWorker = async (
|
|
133
|
+
resolvedOptions: ResolvedWASQLiteOpenFactoryOptions
|
|
134
|
+
): Promise<DatabaseClient> => {
|
|
135
|
+
const workerPort =
|
|
136
|
+
typeof optionsDbWorker == 'function'
|
|
137
|
+
? resolveWorkerDatabasePortFactory(() =>
|
|
138
|
+
optionsDbWorker({
|
|
139
|
+
...this.options,
|
|
140
|
+
temporaryStorage,
|
|
141
|
+
cacheSizeKb,
|
|
142
|
+
flags: this.resolvedFlags,
|
|
143
|
+
encryptionKey
|
|
144
|
+
})
|
|
145
|
+
)
|
|
146
|
+
: openWorkerDatabasePort(this.options.dbFilename, enableMultiTabs, optionsDbWorker, this.waOptions.vfs);
|
|
147
|
+
|
|
148
|
+
const source = Comlink.wrap<OpenWorkerConnection>(workerPort);
|
|
106
149
|
const closeSignal = new AbortController();
|
|
107
150
|
const connection = await source.connect({
|
|
108
|
-
|
|
109
|
-
logLevel: this.
|
|
151
|
+
...resolvedOptions,
|
|
152
|
+
logLevel: this.logger.getLevel(),
|
|
110
153
|
lockName: await generateTabCloseSignal(closeSignal.signal)
|
|
111
154
|
});
|
|
112
155
|
const clientOptions = {
|
|
@@ -116,24 +159,28 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
116
159
|
remoteCanCloseUnexpectedly: false,
|
|
117
160
|
onClose: () => {
|
|
118
161
|
closeSignal.abort();
|
|
119
|
-
|
|
162
|
+
if (workerPort instanceof Worker) {
|
|
163
|
+
workerPort.terminate();
|
|
164
|
+
} else {
|
|
165
|
+
workerPort.close();
|
|
166
|
+
}
|
|
120
167
|
}
|
|
121
168
|
};
|
|
122
169
|
|
|
123
170
|
return new DatabaseClient(clientOptions, {
|
|
124
|
-
...
|
|
171
|
+
...resolvedOptions,
|
|
125
172
|
requiresPersistentTriggers
|
|
126
173
|
});
|
|
127
174
|
};
|
|
128
175
|
|
|
129
|
-
client = await openDatabaseWorker(false);
|
|
176
|
+
client = await openDatabaseWorker(resolveOptions(false));
|
|
130
177
|
|
|
131
178
|
if (vfs == WASQLiteVFS.OPFSWriteAheadVFS) {
|
|
132
179
|
// This VFS supports concurrent reads, so we can open additional workers to host read-only connections for
|
|
133
180
|
// concurrent reads / writes.
|
|
134
181
|
const additionalReadersCount = this.options.additionalReaders ?? 1;
|
|
135
182
|
for (let i = 0; i < additionalReadersCount; i++) {
|
|
136
|
-
const reader = await openDatabaseWorker(true);
|
|
183
|
+
const reader = await openDatabaseWorker(resolveOptions(true));
|
|
137
184
|
additionalReaders.push(reader);
|
|
138
185
|
}
|
|
139
186
|
}
|
|
@@ -142,11 +189,12 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
142
189
|
const localServer = new MultiDatabaseServer(this.logger);
|
|
143
190
|
requiresPersistentTriggers = true;
|
|
144
191
|
|
|
145
|
-
const
|
|
192
|
+
const resolvedOptions = resolveOptions(false);
|
|
193
|
+
const connection = await localServer.openConnectionLocally(resolvedOptions);
|
|
146
194
|
client = new DatabaseClient(
|
|
147
195
|
{ connection, source: null, remoteCanCloseUnexpectedly: false },
|
|
148
196
|
{
|
|
149
|
-
...
|
|
197
|
+
...resolvedOptions,
|
|
150
198
|
requiresPersistentTriggers
|
|
151
199
|
}
|
|
152
200
|
);
|
|
@@ -158,3 +206,18 @@ export class WASQLiteOpenFactory implements SQLOpenFactory {
|
|
|
158
206
|
};
|
|
159
207
|
}
|
|
160
208
|
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractPowerSyncDatabase, DBAdapter, PowerSyncDatabaseOptions } from '@powersync/common';
|
|
2
|
+
import { PowerSyncDatabase } from '../../../db/PowerSyncDatabase.js';
|
|
3
|
+
import { AbstractWebPowerSyncDatabaseOpenFactory } from '../AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
4
|
+
import { WASQLiteOpenFactory } from './WASQLiteOpenFactory.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated {@link PowerSyncDatabase} can now be constructed directly
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const powersync = new PowerSyncDatabase({database: {
|
|
11
|
+
* dbFileName: 'powersync.db'
|
|
12
|
+
* }});
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export class WASQLitePowerSyncDatabaseOpenFactory extends AbstractWebPowerSyncDatabaseOpenFactory {
|
|
16
|
+
protected openDB(): DBAdapter {
|
|
17
|
+
const factory = new WASQLiteOpenFactory(this.options);
|
|
18
|
+
return factory.openDB();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase {
|
|
22
|
+
return new PowerSyncDatabase(options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as SQLite from '@journeyapps/wa-sqlite';
|
|
2
|
+
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* List of currently tested virtual filesystems
|
|
@@ -7,31 +8,36 @@ 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
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export type WASQLiteModuleFactoryOptions = { dbFileName: string; encryptionKey?: string };
|
|
21
|
-
|
|
22
35
|
/**
|
|
23
36
|
* @internal
|
|
24
37
|
*/
|
|
25
38
|
export type SQLiteModule = Parameters<typeof SQLite.Factory>[0];
|
|
26
39
|
|
|
27
|
-
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
|
-
export type WASQLiteModuleFactory = (
|
|
31
|
-
options: WASQLiteModuleFactoryOptions
|
|
32
|
-
) => Promise<{ module: SQLiteModule; vfs: SQLiteVFS }>;
|
|
33
|
-
|
|
34
|
-
async function asyncModuleFactory(encryptionKey: unknown) {
|
|
40
|
+
async function asyncModuleFactory(encryptionKey: string | undefined): Promise<SQLiteModule> {
|
|
35
41
|
if (encryptionKey) {
|
|
36
42
|
const { default: factory } = await import('@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs');
|
|
37
43
|
return factory();
|
|
@@ -41,7 +47,7 @@ async function asyncModuleFactory(encryptionKey: unknown) {
|
|
|
41
47
|
}
|
|
42
48
|
}
|
|
43
49
|
|
|
44
|
-
async function syncModuleFactory(encryptionKey:
|
|
50
|
+
async function syncModuleFactory(encryptionKey: string | undefined): Promise<SQLiteModule> {
|
|
45
51
|
if (encryptionKey) {
|
|
46
52
|
const { default: factory } = await import('@journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs');
|
|
47
53
|
return factory();
|
|
@@ -54,43 +60,50 @@ async function syncModuleFactory(encryptionKey: unknown) {
|
|
|
54
60
|
/**
|
|
55
61
|
* @internal
|
|
56
62
|
*/
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
export async function loadModuleAndVfs({
|
|
64
|
+
vfs,
|
|
65
|
+
dbFilename,
|
|
66
|
+
encryptionKey
|
|
67
|
+
}: ResolvedWASQLiteOpenFactoryOptions): Promise<{ module: SQLiteModule; vfs: SQLiteVFS }> {
|
|
68
|
+
let moduleFactory = syncModuleFactory;
|
|
69
|
+
let resolveVfs: (module: any) => Promise<SQLiteVFS>;
|
|
70
|
+
|
|
71
|
+
switch (vfs) {
|
|
72
|
+
case WASQLiteVFS.IDBBatchAtomicVFS: {
|
|
73
|
+
moduleFactory = asyncModuleFactory;
|
|
74
|
+
const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
|
|
75
|
+
resolveVfs = (module) => {
|
|
76
|
+
// @ts-expect-error The types for this static method are missing upstream
|
|
77
|
+
return IDBBatchAtomicVFS.create(filename, module, { lockPolicy: 'exclusive' });
|
|
78
|
+
};
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case WASQLiteVFS.AccessHandlePoolVFS: {
|
|
82
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
83
|
+
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
84
|
+
resolveVfs = (module) => AccessHandlePoolVFS.create(dbFilename, module);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case WASQLiteVFS.OPFSCoopSyncVFS: {
|
|
88
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
89
|
+
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
90
|
+
resolveVfs = (module) => OPFSCoopSyncVFS.create(dbFilename, module);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
case WASQLiteVFS.OPFSWriteAheadVFS: {
|
|
94
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
95
|
+
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
96
|
+
resolveVfs = (module) => OPFSWriteAheadVFS.create(dbFilename, module, {});
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
case WASQLiteVFS.InMemoryVfs: {
|
|
100
|
+
const { MemoryVFS } = await import('@journeyapps/wa-sqlite/src/examples/MemoryVFS.js');
|
|
63
101
|
// @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
|
-
};
|
|
102
|
+
resolveVfs = (module) => MemoryVFS.create(dbFilename, module);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
95
105
|
}
|
|
96
|
-
|
|
106
|
+
|
|
107
|
+
const module = await moduleFactory(encryptionKey);
|
|
108
|
+
return { module, vfs: await resolveVfs(module) };
|
|
109
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type ILogger, SQLOpenOptions } from '@powersync/common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common settings used when creating SQL connections on web.
|
|
5
|
+
*/
|
|
6
|
+
export interface WebSQLFlags {
|
|
7
|
+
/**
|
|
8
|
+
* Broadcast logs from shared workers, such as the shared sync worker,
|
|
9
|
+
* to individual tabs. This defaults to true.
|
|
10
|
+
*/
|
|
11
|
+
broadcastLogs?: boolean;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* SQLite operations are currently not supported in SSR mode.
|
|
15
|
+
* A warning will be logged if attempting to use SQLite in SSR.
|
|
16
|
+
* Setting this to `true` will disabled the warning above.
|
|
17
|
+
*/
|
|
18
|
+
disableSSRWarning?: boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Enables multi tab support
|
|
22
|
+
*/
|
|
23
|
+
enableMultiTabs?: boolean;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The SQLite connection is often executed through a web worker
|
|
27
|
+
* in order to offload computation. This can be used to manually
|
|
28
|
+
* disable the use of web workers in environments where web workers
|
|
29
|
+
* might be unstable.
|
|
30
|
+
*/
|
|
31
|
+
useWebWorker?: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Open in SSR placeholder mode. DB operations and Sync operations will be a No-op
|
|
35
|
+
*/
|
|
36
|
+
ssrMode?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type ResolvedWebSQLFlags = Required<WebSQLFlags>;
|
|
40
|
+
|
|
41
|
+
export interface ResolvedWebSQLOpenOptions extends SQLOpenOptions {
|
|
42
|
+
flags: ResolvedWebSQLFlags;
|
|
43
|
+
/**
|
|
44
|
+
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
|
|
45
|
+
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
|
|
46
|
+
*/
|
|
47
|
+
temporaryStorage: TemporaryStorageOption;
|
|
48
|
+
|
|
49
|
+
cacheSizeKb: number;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Encryption key for the database.
|
|
53
|
+
* If set, the database will be encrypted using ChaCha20.
|
|
54
|
+
*/
|
|
55
|
+
encryptionKey?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export enum TemporaryStorageOption {
|
|
59
|
+
MEMORY = 'memory',
|
|
60
|
+
FILESYSTEM = 'file'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const DEFAULT_CACHE_SIZE_KB = 50 * 1024;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Options for opening a Web SQL connection
|
|
67
|
+
*/
|
|
68
|
+
export interface WebSQLOpenFactoryOptions extends SQLOpenOptions {
|
|
69
|
+
flags?: WebSQLFlags;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Allows you to override the default wasqlite db worker.
|
|
73
|
+
*
|
|
74
|
+
* You can either provide a path to the worker script
|
|
75
|
+
* or a factory method that returns a worker.
|
|
76
|
+
*/
|
|
77
|
+
worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => Worker | SharedWorker);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Use an existing port to an initialized worker.
|
|
81
|
+
* A worker will be initialized if none is provided
|
|
82
|
+
*/
|
|
83
|
+
workerPort?: MessagePort;
|
|
84
|
+
|
|
85
|
+
logger?: ILogger;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
|
|
89
|
+
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
|
|
90
|
+
*
|
|
91
|
+
* For details, see: https://www.sqlite.org/pragma.html#pragma_temp_store
|
|
92
|
+
*/
|
|
93
|
+
temporaryStorage?: TemporaryStorageOption;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Maximum SQLite cache size. Defaults to 50MB.
|
|
97
|
+
*
|
|
98
|
+
* For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
|
|
99
|
+
*/
|
|
100
|
+
cacheSizeKb?: number;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Encryption key for the database.
|
|
104
|
+
* If set, the database will be encrypted using ChaCha20.
|
|
105
|
+
*/
|
|
106
|
+
encryptionKey?: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isServerSide() {
|
|
110
|
+
return typeof window == 'undefined';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const DEFAULT_WEB_SQL_FLAGS: ResolvedWebSQLFlags = {
|
|
114
|
+
broadcastLogs: true,
|
|
115
|
+
disableSSRWarning: false,
|
|
116
|
+
ssrMode: isServerSide(),
|
|
117
|
+
/**
|
|
118
|
+
* Multiple tabs are by default not supported on Android, iOS and Safari.
|
|
119
|
+
* Other platforms will have multiple tabs enabled by default.
|
|
120
|
+
*/
|
|
121
|
+
enableMultiTabs:
|
|
122
|
+
typeof globalThis.navigator !== 'undefined' && // For SSR purposes
|
|
123
|
+
typeof SharedWorker !== 'undefined' &&
|
|
124
|
+
!navigator.userAgent.match(/(Android|iPhone|iPod|iPad)/i) &&
|
|
125
|
+
!(window as any).safari,
|
|
126
|
+
useWebWorker: true
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export function resolveWebSQLFlags(flags?: WebSQLFlags): ResolvedWebSQLFlags {
|
|
130
|
+
const resolvedFlags = {
|
|
131
|
+
...DEFAULT_WEB_SQL_FLAGS,
|
|
132
|
+
...(flags ?? {})
|
|
133
|
+
};
|
|
134
|
+
if (typeof flags?.enableMultiTabs != 'undefined') {
|
|
135
|
+
resolvedFlags.enableMultiTabs = flags.enableMultiTabs;
|
|
136
|
+
}
|
|
137
|
+
if (flags?.useWebWorker === false) {
|
|
138
|
+
resolvedFlags.enableMultiTabs = false;
|
|
139
|
+
}
|
|
140
|
+
return resolvedFlags;
|
|
141
|
+
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AbstractStreamingSyncImplementationOptions,
|
|
3
|
+
BaseObserver,
|
|
4
|
+
LockOptions,
|
|
5
|
+
LockType,
|
|
6
|
+
Mutex,
|
|
7
|
+
PowerSyncConnectionOptions,
|
|
8
|
+
StreamingSyncImplementation,
|
|
9
|
+
SyncStatus,
|
|
10
|
+
SyncStatusOptions
|
|
11
|
+
} from '@powersync/common';
|
|
3
12
|
|
|
4
13
|
export class SSRStreamingSyncImplementation extends BaseObserver implements StreamingSyncImplementation {
|
|
5
14
|
syncMutex: Mutex;
|
|
@@ -7,11 +16,13 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
7
16
|
|
|
8
17
|
isConnected: boolean;
|
|
9
18
|
lastSyncedAt?: Date | undefined;
|
|
19
|
+
syncStatus: SyncStatus;
|
|
10
20
|
|
|
11
|
-
constructor() {
|
|
21
|
+
constructor(options: AbstractStreamingSyncImplementationOptions) {
|
|
12
22
|
super();
|
|
13
23
|
this.syncMutex = new Mutex();
|
|
14
24
|
this.crudMutex = new Mutex();
|
|
25
|
+
this.syncStatus = new SyncStatus({});
|
|
15
26
|
this.isConnected = false;
|
|
16
27
|
}
|
|
17
28
|
|
|
@@ -23,7 +34,7 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
23
34
|
/**
|
|
24
35
|
* This is a no-op in SSR mode
|
|
25
36
|
*/
|
|
26
|
-
async connect(): Promise<void> {}
|
|
37
|
+
async connect(options?: PowerSyncConnectionOptions): Promise<void> {}
|
|
27
38
|
|
|
28
39
|
async dispose() {}
|
|
29
40
|
|
|
@@ -37,6 +48,13 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
37
48
|
*/
|
|
38
49
|
async waitForReady() {}
|
|
39
50
|
|
|
51
|
+
/**
|
|
52
|
+
* This will never resolve in SSR Mode.
|
|
53
|
+
*/
|
|
54
|
+
async waitForStatus(status: SyncStatusOptions) {
|
|
55
|
+
return this.waitUntilStatusMatches(() => false);
|
|
56
|
+
}
|
|
57
|
+
|
|
40
58
|
/**
|
|
41
59
|
* This will never resolve in SSR Mode.
|
|
42
60
|
*/
|