@powersync/web 0.0.0-dev-20260708104358 → 0.0.0-dev-20260827080125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -11
- package/bin/powersync.cjs +1 -1
- package/dist/index.react_native_web.js +2095 -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-Rt5CGCZP.js +2 -0
- package/dist/worker/OPFSWriteAheadVFS-Rt5CGCZP.js.map +1 -0
- package/dist/worker/assets/mc-wa-sqlite-DoDpgFfE.wasm +0 -0
- package/dist/worker/assets/mc-wa-sqlite-async-DYagSq56.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-CagagB9I.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-async-DCIP8kAx.wasm +0 -0
- package/dist/worker/mc-wa-sqlite-DDFgWP93.js +2 -0
- package/dist/worker/mc-wa-sqlite-DDFgWP93.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js +2 -0
- package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js.map +1 -0
- package/dist/worker/wa-sqlite-B0tZMM0j.js +2 -0
- package/dist/worker/wa-sqlite-B0tZMM0j.js.map +1 -0
- package/dist/worker/wa-sqlite-async-CM6BmfRh.js +2 -0
- package/dist/worker/wa-sqlite-async-CM6BmfRh.js.map +1 -0
- package/dist/worker/websockets-Q8W_lerF.js +9 -0
- package/dist/worker/websockets-Q8W_lerF.js.map +1 -0
- package/dist/worker/worker.js +7 -0
- package/dist/worker/worker.js.map +1 -0
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{src/db → db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/db/PowerSyncDatabase.d.ts +66 -0
- package/lib/{src/db → db}/PowerSyncDatabase.js +60 -79
- 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 +18 -69
- 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/acquireFromPool.d.ts +7 -0
- package/lib/db/adapters/acquireFromPool.js +60 -0
- package/lib/db/adapters/acquireFromPool.js.map +1 -0
- package/lib/db/adapters/memory-pool/client.d.ts +70 -0
- package/lib/db/adapters/memory-pool/client.js +269 -0
- package/lib/db/adapters/memory-pool/client.js.map +1 -0
- package/lib/db/adapters/memory-pool/shared.d.ts +51 -0
- package/lib/db/adapters/memory-pool/shared.js +16 -0
- package/lib/db/adapters/memory-pool/shared.js.map +1 -0
- package/lib/db/adapters/memory-pool/vfs.d.ts +19 -0
- package/lib/db/adapters/memory-pool/vfs.js +247 -0
- package/lib/db/adapters/memory-pool/vfs.js.map +1 -0
- package/lib/db/adapters/memory-pool/worker.js +45 -0
- package/lib/db/adapters/memory-pool/worker.js.map +1 -0
- package/lib/db/adapters/options.d.ts +94 -0
- package/lib/db/adapters/options.js +6 -0
- package/lib/db/adapters/options.js.map +1 -0
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +13 -0
- package/lib/db/adapters/resolveAndValidateOptions.js +41 -0
- package/lib/db/adapters/resolveAndValidateOptions.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +3 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.js +11 -37
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.js +14 -7
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +30 -12
- package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.js +70 -16
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/db/adapters/wa-sqlite/StatementCache.d.ts +16 -0
- package/lib/db/adapters/wa-sqlite/StatementCache.js +44 -0
- package/lib/db/adapters/wa-sqlite/StatementCache.js.map +1 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +18 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +140 -0
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/{src/db → db}/adapters/wa-sqlite/vfs.d.ts +9 -2
- package/lib/{src/db → db}/adapters/wa-sqlite/vfs.js +6 -6
- package/lib/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.d.ts +5 -16
- package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.js +7 -23
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.d.ts +15 -15
- package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.js +38 -70
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.d.ts +19 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.js +70 -0
- package/lib/db/sync/TabLocalStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/WebRemote.d.ts +10 -0
- package/lib/db/sync/WebRemote.js +33 -0
- package/lib/db/sync/WebRemote.js.map +1 -0
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.d.ts +2 -4
- package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.js +3 -2
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/db/sync/userAgent.js.map +1 -0
- package/lib/{src/index.d.ts → index.d.ts} +1 -3
- package/lib/{src/index.js → index.js} +1 -3
- package/lib/index.js.map +1 -0
- package/lib/shared/navigator.js.map +1 -0
- package/lib/shared/tab_close_signal.js.map +1 -0
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +5 -0
- package/lib/worker/SharedWorkerConnectionRequest.js +2 -0
- package/lib/worker/SharedWorkerConnectionRequest.js.map +1 -0
- package/lib/worker/client.d.ts +17 -0
- package/lib/worker/client.js +90 -0
- package/lib/worker/client.js.map +1 -0
- package/lib/worker/db/MultiDatabaseServer.d.ts +21 -0
- package/lib/{src/worker → worker}/db/MultiDatabaseServer.js +45 -24
- package/lib/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +14 -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 +14 -25
- package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +72 -104
- package/lib/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/{src/worker → worker}/sync/WorkerClient.d.ts +4 -4
- package/lib/{src/worker → worker}/sync/WorkerClient.js +5 -5
- package/lib/worker/sync/WorkerClient.js.map +1 -0
- package/lib/worker/worker.d.ts +1 -0
- package/lib/worker/worker.js +34 -0
- package/lib/worker/worker.js.map +1 -0
- package/package.json +31 -32
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +96 -144
- package/src/db/adapters/AsyncWebAdapter.ts +29 -86
- package/src/db/adapters/SSRDBAdapter.ts +14 -64
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/acquireFromPool.ts +73 -0
- package/src/db/adapters/memory-pool/client.ts +367 -0
- package/src/db/adapters/memory-pool/shared.ts +79 -0
- package/src/db/adapters/memory-pool/vfs.ts +293 -0
- package/src/db/adapters/memory-pool/worker.ts +53 -0
- package/src/db/adapters/options.ts +108 -0
- package/src/db/adapters/resolveAndValidateOptions.ts +49 -0
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +4 -5
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +20 -56
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +18 -12
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +108 -30
- package/src/db/adapters/wa-sqlite/StatementCache.ts +50 -0
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +82 -125
- package/src/db/adapters/wa-sqlite/vfs.ts +13 -8
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +8 -36
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +47 -82
- package/src/db/sync/TabLocalStreamingSyncImplementation.ts +90 -0
- package/src/db/sync/WebRemote.ts +23 -26
- package/src/db/sync/WebStreamingSyncImplementation.ts +4 -5
- package/src/index.ts +1 -3
- package/src/worker/SharedWorkerConnectionRequest.ts +6 -0
- package/src/worker/client.ts +121 -0
- package/src/worker/db/MultiDatabaseServer.ts +59 -33
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +5 -10
- package/src/worker/sync/BroadcastLogger.ts +35 -103
- package/src/worker/sync/SharedSyncImplementation.ts +101 -135
- package/src/worker/sync/WorkerClient.ts +8 -8
- package/src/worker/worker.ts +38 -0
- package/dist/2075a31bb151adbb9767.wasm +0 -0
- package/dist/3322bc84de986b63c2cd.wasm +0 -0
- package/dist/8e97452e297be23b5e50.wasm +0 -0
- package/dist/fbc178b70d530e8ce02b.wasm +0 -0
- package/dist/index.umd.js +0 -7821
- package/dist/index.umd.js.map +0 -1
- package/dist/worker/SharedSyncImplementation.umd.js +0 -16139
- package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
- package/dist/worker/WASQLiteDB.umd.js +0 -17434
- package/dist/worker/WASQLiteDB.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -31
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +0 -3562
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +0 -1400
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +0 -2478
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +0 -1681
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +0 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +0 -1820
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +0 -1
- package/lib/package.json +0 -91
- package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +0 -1
- package/lib/src/db/NavigatorTriggerClaimManager.js.map +0 -1
- package/lib/src/db/PowerSyncDatabase.d.ts +0 -78
- package/lib/src/db/PowerSyncDatabase.js.map +0 -1
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +0 -23
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -27
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +0 -50
- package/lib/src/db/adapters/AsyncWebAdapter.js.map +0 -1
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +0 -30
- package/lib/src/db/adapters/SSRDBAdapter.js +0 -69
- package/lib/src/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/WebDBAdapter.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -45
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -146
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +0 -15
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -22
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +0 -1
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +0 -1
- package/lib/src/db/adapters/web-sql-flags.d.ts +0 -92
- package/lib/src/db/adapters/web-sql-flags.js +0 -37
- package/lib/src/db/adapters/web-sql-flags.js.map +0 -1
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/WebRemote.d.ts +0 -7
- package/lib/src/db/sync/WebRemote.js +0 -33
- package/lib/src/db/sync/WebRemote.js.map +0 -1
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/src/db/sync/userAgent.js.map +0 -1
- package/lib/src/index.js.map +0 -1
- package/lib/src/shared/navigator.js.map +0 -1
- package/lib/src/shared/tab_close_signal.js.map +0 -1
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +0 -17
- package/lib/src/worker/db/MultiDatabaseServer.js.map +0 -1
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +0 -4
- package/lib/src/worker/db/WASQLiteDB.worker.js +0 -31
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +0 -1
- package/lib/src/worker/db/open-worker-database.d.ts +0 -14
- package/lib/src/worker/db/open-worker-database.js +0 -53
- package/lib/src/worker/db/open-worker-database.js.map +0 -1
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -19
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/src/worker/sync/BroadcastLogger.d.ts +0 -47
- package/lib/src/worker/sync/BroadcastLogger.js +0 -129
- package/lib/src/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +0 -12
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +0 -1
- package/lib/src/worker/sync/WorkerClient.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +0 -47
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +0 -24
- package/src/db/adapters/web-sql-flags.ts +0 -141
- package/src/worker/db/WASQLiteDB.worker.ts +0 -35
- package/src/worker/db/open-worker-database.ts +0 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +0 -14
- /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.js +0 -0
- /package/lib/{src/db → db}/NavigatorTriggerClaimManager.js +0 -0
- /package/lib/{src/db → db}/adapters/WebDBAdapter.js +0 -0
- /package/lib/{src/worker/sync/SharedSyncImplementation.worker.d.ts → db/adapters/memory-pool/worker.d.ts} +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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as SQLite from '@journeyapps/wa-sqlite';
|
|
2
|
-
import {
|
|
2
|
+
import { RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* List of currently tested virtual filesystems
|
|
@@ -32,6 +32,11 @@ export function vfsRequiresDedicatedWorkers(vfs: WASQLiteVFS) {
|
|
|
32
32
|
return vfs != WASQLiteVFS.IDBBatchAtomicVFS && vfs != WASQLiteVFS.InMemoryVfs;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export type WASQLiteModuleFactoryOptions = { dbFileName: string; encryptionKey?: string };
|
|
39
|
+
|
|
35
40
|
/**
|
|
36
41
|
* @internal
|
|
37
42
|
*/
|
|
@@ -62,9 +67,9 @@ async function syncModuleFactory(encryptionKey: string | undefined): Promise<SQL
|
|
|
62
67
|
*/
|
|
63
68
|
export async function loadModuleAndVfs({
|
|
64
69
|
vfs,
|
|
65
|
-
|
|
70
|
+
filename,
|
|
66
71
|
encryptionKey
|
|
67
|
-
}:
|
|
72
|
+
}: RawWaSqliteDatabaseOptions): Promise<{ module: SQLiteModule; vfs: SQLiteVFS }> {
|
|
68
73
|
let moduleFactory = syncModuleFactory;
|
|
69
74
|
let resolveVfs: (module: any) => Promise<SQLiteVFS>;
|
|
70
75
|
|
|
@@ -74,32 +79,32 @@ export async function loadModuleAndVfs({
|
|
|
74
79
|
const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
|
|
75
80
|
resolveVfs = (module) => {
|
|
76
81
|
// @ts-expect-error The types for this static method are missing upstream
|
|
77
|
-
return IDBBatchAtomicVFS.create(
|
|
82
|
+
return IDBBatchAtomicVFS.create(filename, module, { lockPolicy: 'exclusive' });
|
|
78
83
|
};
|
|
79
84
|
break;
|
|
80
85
|
}
|
|
81
86
|
case WASQLiteVFS.AccessHandlePoolVFS: {
|
|
82
87
|
// @ts-expect-error The types for this import are missing upstream
|
|
83
88
|
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
84
|
-
resolveVfs = (module) => AccessHandlePoolVFS.create(
|
|
89
|
+
resolveVfs = (module) => AccessHandlePoolVFS.create(filename, module);
|
|
85
90
|
break;
|
|
86
91
|
}
|
|
87
92
|
case WASQLiteVFS.OPFSCoopSyncVFS: {
|
|
88
93
|
// @ts-expect-error The types for this import are missing upstream
|
|
89
94
|
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
90
|
-
resolveVfs = (module) => OPFSCoopSyncVFS.create(
|
|
95
|
+
resolveVfs = (module) => OPFSCoopSyncVFS.create(filename, module);
|
|
91
96
|
break;
|
|
92
97
|
}
|
|
93
98
|
case WASQLiteVFS.OPFSWriteAheadVFS: {
|
|
94
99
|
// @ts-expect-error The types for this import are missing upstream
|
|
95
100
|
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
96
|
-
resolveVfs = (module) => OPFSWriteAheadVFS.create(
|
|
101
|
+
resolveVfs = (module) => OPFSWriteAheadVFS.create(filename, module, {});
|
|
97
102
|
break;
|
|
98
103
|
}
|
|
99
104
|
case WASQLiteVFS.InMemoryVfs: {
|
|
100
105
|
const { MemoryVFS } = await import('@journeyapps/wa-sqlite/src/examples/MemoryVFS.js');
|
|
101
106
|
// @ts-expect-error The types for this static method are missing upstream
|
|
102
|
-
resolveVfs = (module) => MemoryVFS.create(
|
|
107
|
+
resolveVfs = (module) => MemoryVFS.create(filename, module);
|
|
103
108
|
break;
|
|
104
109
|
}
|
|
105
110
|
}
|
|
@@ -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
|
*/
|
|
@@ -62,20 +44,6 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
62
44
|
return new Promise<void>(() => {});
|
|
63
45
|
}
|
|
64
46
|
|
|
65
|
-
/**
|
|
66
|
-
* Returns a placeholder checkpoint. This should not be used.
|
|
67
|
-
*/
|
|
68
|
-
async getWriteCheckpoint() {
|
|
69
|
-
return '1';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The SSR mode adapter will never complete syncing.
|
|
74
|
-
*/
|
|
75
|
-
async hasCompletedSync() {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
47
|
/**
|
|
80
48
|
* This is a no-op in SSR mode.
|
|
81
49
|
*/
|
|
@@ -90,4 +58,8 @@ export class SSRStreamingSyncImplementation extends BaseObserver implements Stre
|
|
|
90
58
|
* No-op in SSR mode.
|
|
91
59
|
*/
|
|
92
60
|
markConnectionMayHaveChanged(): void {}
|
|
61
|
+
|
|
62
|
+
requestCheckpoint(): Promise<bigint> {
|
|
63
|
+
throw new Error('Sub sync implementation does not support request checkpoints');
|
|
64
|
+
}
|
|
93
65
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PowerSyncConnectionOptions,
|
|
3
|
-
PowerSyncCredentials,
|
|
4
|
-
SubscribedStream,
|
|
5
|
-
SyncStatusOptions
|
|
6
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogRecord, PowerSyncCredentials } from '@powersync/common';
|
|
7
2
|
import * as Comlink from 'comlink';
|
|
8
|
-
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
9
3
|
import { AbstractSharedSyncClientProvider } from '../../worker/sync/AbstractSharedSyncClientProvider.js';
|
|
10
4
|
import { ManualSharedSyncPayload, SharedSyncClientEvent } from '../../worker/sync/SharedSyncImplementation.js';
|
|
11
5
|
import { WorkerClient } from '../../worker/sync/WorkerClient.js';
|
|
12
6
|
import { WebDBAdapter } from '../adapters/WebDBAdapter.js';
|
|
13
|
-
import { DEFAULT_CACHE_SIZE_KB, TemporaryStorageOption, resolveWebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
14
7
|
import {
|
|
15
8
|
WebStreamingSyncImplementation,
|
|
16
9
|
WebStreamingSyncImplementationOptions
|
|
17
10
|
} from './WebStreamingSyncImplementation.js';
|
|
18
11
|
import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
12
|
+
import { SubscribedStream, SyncStatusJson, ResolvedSyncOptions } from '@powersync/shared-internals';
|
|
13
|
+
import { connectToExistingWorker, connectToWorker, WorkerConnection } from '../../worker/client.js';
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
16
|
* The shared worker will trigger methods on this side of the message port
|
|
@@ -24,7 +19,7 @@ import { generateTabCloseSignal } from '../../shared/tab_close_signal.js';
|
|
|
24
19
|
class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
25
20
|
constructor(
|
|
26
21
|
protected options: WebStreamingSyncImplementationOptions,
|
|
27
|
-
public statusChanged: (status:
|
|
22
|
+
public statusChanged: (status: SyncStatusJson) => void,
|
|
28
23
|
protected webDB: WebDBAdapter
|
|
29
24
|
) {
|
|
30
25
|
super();
|
|
@@ -64,38 +59,23 @@ class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
|
|
|
64
59
|
await this.options.uploadCrud();
|
|
65
60
|
}
|
|
66
61
|
|
|
62
|
+
override async postCheckpointRequest(clientId: string, requestId: string): Promise<string | null> {
|
|
63
|
+
return await this.options.postCheckpointRequest(clientId, requestId);
|
|
64
|
+
}
|
|
65
|
+
|
|
67
66
|
get logger() {
|
|
68
67
|
return this.options.logger;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
this.logger
|
|
73
|
-
}
|
|
74
|
-
debug(...x: any[]): void {
|
|
75
|
-
this.logger?.debug(...x);
|
|
76
|
-
}
|
|
77
|
-
info(...x: any[]): void {
|
|
78
|
-
this.logger?.info(...x);
|
|
79
|
-
}
|
|
80
|
-
log(...x: any[]): void {
|
|
81
|
-
this.logger?.log(...x);
|
|
82
|
-
}
|
|
83
|
-
warn(...x: any[]): void {
|
|
84
|
-
this.logger?.warn(...x);
|
|
85
|
-
}
|
|
86
|
-
error(...x: any[]): void {
|
|
87
|
-
this.logger?.error(...x);
|
|
88
|
-
}
|
|
89
|
-
time(label: string): void {
|
|
90
|
-
this.logger?.time(label);
|
|
91
|
-
}
|
|
92
|
-
timeEnd(label: string): void {
|
|
93
|
-
this.logger?.timeEnd(label);
|
|
70
|
+
log(record: LogRecord): void {
|
|
71
|
+
this.logger.log(record);
|
|
94
72
|
}
|
|
95
73
|
}
|
|
96
74
|
|
|
97
75
|
export interface SharedWebStreamingSyncImplementationOptions extends WebStreamingSyncImplementationOptions {
|
|
76
|
+
logLevel: number;
|
|
98
77
|
db: WebDBAdapter;
|
|
78
|
+
enableBroadcastLogs: boolean;
|
|
99
79
|
}
|
|
100
80
|
|
|
101
81
|
/**
|
|
@@ -104,46 +84,31 @@ export interface SharedWebStreamingSyncImplementationOptions extends WebStreamin
|
|
|
104
84
|
export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
105
85
|
protected syncManager: Comlink.Remote<WorkerClient>;
|
|
106
86
|
protected clientProvider: SharedSyncClientProvider;
|
|
107
|
-
protected
|
|
87
|
+
protected worker: WorkerConnection;
|
|
108
88
|
|
|
109
89
|
protected isInitialized: Promise<void>;
|
|
110
90
|
protected dbAdapter: WebDBAdapter;
|
|
111
91
|
private abortOnClose = new AbortController();
|
|
92
|
+
private logLevel: number;
|
|
93
|
+
private enableBroadcastLogs: boolean;
|
|
112
94
|
|
|
113
95
|
constructor(options: SharedWebStreamingSyncImplementationOptions) {
|
|
114
96
|
super(options);
|
|
115
97
|
this.dbAdapter = options.db;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
* This worker will manage all syncing operations remotely.
|
|
119
|
-
*/
|
|
120
|
-
const resolvedWorkerOptions = {
|
|
121
|
-
dbFilename: this.options.identifier!,
|
|
122
|
-
temporaryStorage: TemporaryStorageOption.MEMORY,
|
|
123
|
-
cacheSizeKb: DEFAULT_CACHE_SIZE_KB,
|
|
124
|
-
...options,
|
|
125
|
-
flags: resolveWebSQLFlags(options.flags)
|
|
126
|
-
};
|
|
98
|
+
this.logLevel = options.logLevel;
|
|
99
|
+
this.enableBroadcastLogs = options.enableBroadcastLogs;
|
|
127
100
|
|
|
128
101
|
const syncWorker = options.sync?.worker;
|
|
129
|
-
if (syncWorker) {
|
|
130
|
-
|
|
131
|
-
this.messagePort = syncWorker(resolvedWorkerOptions).port;
|
|
132
|
-
} else {
|
|
133
|
-
this.messagePort = new SharedWorker(`${syncWorker}`, {
|
|
134
|
-
/* @vite-ignore */
|
|
135
|
-
name: `shared-sync-${this.webOptions.identifier}`
|
|
136
|
-
}).port;
|
|
137
|
-
}
|
|
102
|
+
if (typeof syncWorker === 'function') {
|
|
103
|
+
this.worker = connectToExistingWorker(syncWorker(), options.logger, 'sync');
|
|
138
104
|
} else {
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
).port;
|
|
105
|
+
this.worker = connectToWorker({
|
|
106
|
+
service: 'sync',
|
|
107
|
+
databaseIdentifier: this.webOptions.identifier!,
|
|
108
|
+
shared: true,
|
|
109
|
+
customWorker: syncWorker,
|
|
110
|
+
loggerForErrors: options.logger
|
|
111
|
+
});
|
|
147
112
|
}
|
|
148
113
|
|
|
149
114
|
/**
|
|
@@ -151,21 +116,21 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
151
116
|
*/
|
|
152
117
|
this.clientProvider = new SharedSyncClientProvider(
|
|
153
118
|
this.webOptions,
|
|
154
|
-
(
|
|
155
|
-
this.updateSyncStatus(
|
|
119
|
+
({ core, dataFlow }) => {
|
|
120
|
+
this.updateSyncStatus(core, dataFlow);
|
|
156
121
|
},
|
|
157
122
|
options.db
|
|
158
123
|
);
|
|
159
124
|
|
|
160
|
-
this.syncManager = Comlink.wrap<WorkerClient>(this.
|
|
125
|
+
this.syncManager = Comlink.wrap<WorkerClient>(this.worker.endpoint);
|
|
161
126
|
/**
|
|
162
127
|
* The sync worker will call this client provider when it needs
|
|
163
128
|
* to fetch credentials or upload data.
|
|
164
129
|
* This performs bi-directional method calling.
|
|
165
130
|
*/
|
|
166
|
-
Comlink.expose(this.clientProvider, this.
|
|
131
|
+
Comlink.expose(this.clientProvider, this.worker.endpoint);
|
|
167
132
|
|
|
168
|
-
this.syncManager.setLogLevel(this.
|
|
133
|
+
this.syncManager.setLogLevel(this.logLevel);
|
|
169
134
|
|
|
170
135
|
this.triggerCrudUpload = this.syncManager.triggerCrudUpload;
|
|
171
136
|
|
|
@@ -197,18 +162,16 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
197
162
|
// Awaiting here ensures the worker is waiting for the lock
|
|
198
163
|
await this.syncManager.addLockBasedCloseSignal(closeSignal);
|
|
199
164
|
|
|
200
|
-
const {
|
|
201
|
-
const flags = { ...this.webOptions.flags, workers: undefined };
|
|
165
|
+
const { identifier } = this.options;
|
|
202
166
|
|
|
203
167
|
await this.syncManager.setParams(
|
|
204
168
|
{
|
|
205
169
|
dbParams: this.dbAdapter.getConfiguration(),
|
|
206
170
|
streamOptions: {
|
|
207
|
-
crudUploadThrottleMs,
|
|
208
171
|
identifier,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
172
|
+
serializedSchema: this.options.serializedSchema
|
|
173
|
+
},
|
|
174
|
+
enableBroadcastLogs: this.enableBroadcastLogs
|
|
212
175
|
},
|
|
213
176
|
this.options.subscriptions
|
|
214
177
|
);
|
|
@@ -218,9 +181,9 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
218
181
|
* Starts the sync process, this effectively acts as a call to
|
|
219
182
|
* `connect` if not yet connected.
|
|
220
183
|
*/
|
|
221
|
-
async connect(options
|
|
184
|
+
async connect(options: ResolvedSyncOptions): Promise<void> {
|
|
222
185
|
await this.waitForReady();
|
|
223
|
-
return this.syncManager.connect(options);
|
|
186
|
+
return this.syncManager.connect(options, this.options.serializedSchema);
|
|
224
187
|
}
|
|
225
188
|
|
|
226
189
|
async disconnect(): Promise<void> {
|
|
@@ -228,17 +191,15 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
228
191
|
return this.syncManager.disconnect();
|
|
229
192
|
}
|
|
230
193
|
|
|
231
|
-
async getWriteCheckpoint(): Promise<string> {
|
|
232
|
-
await this.waitForReady();
|
|
233
|
-
return this.syncManager.getWriteCheckpoint();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
194
|
async dispose(): Promise<void> {
|
|
237
195
|
await this.waitForReady();
|
|
238
196
|
|
|
239
197
|
await new Promise<void>((resolve) => {
|
|
198
|
+
// This will always be a message port since we use shared workers.
|
|
199
|
+
const messagePort = this.worker.endpoint as MessagePort;
|
|
200
|
+
|
|
240
201
|
// Listen for the close acknowledgment from the worker
|
|
241
|
-
|
|
202
|
+
messagePort.addEventListener('message', (event) => {
|
|
242
203
|
const payload = event.data as ManualSharedSyncPayload;
|
|
243
204
|
if (payload?.event === SharedSyncClientEvent.CLOSE_ACK) {
|
|
244
205
|
resolve();
|
|
@@ -250,7 +211,7 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
250
211
|
event: SharedSyncClientEvent.CLOSE_CLIENT,
|
|
251
212
|
data: {}
|
|
252
213
|
};
|
|
253
|
-
|
|
214
|
+
messagePort.postMessage(closeMessagePayload);
|
|
254
215
|
});
|
|
255
216
|
|
|
256
217
|
await super.dispose();
|
|
@@ -259,13 +220,17 @@ export class SharedWebStreamingSyncImplementation extends WebStreamingSyncImplem
|
|
|
259
220
|
|
|
260
221
|
// Release the proxy
|
|
261
222
|
this.syncManager[Comlink.releaseProxy]();
|
|
262
|
-
this.
|
|
223
|
+
this.worker.close();
|
|
263
224
|
}
|
|
264
225
|
|
|
265
226
|
async waitForReady() {
|
|
266
227
|
return this.isInitialized;
|
|
267
228
|
}
|
|
268
229
|
|
|
230
|
+
requestCheckpoint(): Promise<bigint> {
|
|
231
|
+
return this.syncManager.requestCheckpoint();
|
|
232
|
+
}
|
|
233
|
+
|
|
269
234
|
updateSubscriptions(subscriptions: SubscribedStream[]): void {
|
|
270
235
|
this.syncManager.updateSubscriptions(subscriptions);
|
|
271
236
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LockOptions,
|
|
3
|
+
LockType,
|
|
4
|
+
SubscribedStream,
|
|
5
|
+
SyncStatusJson,
|
|
6
|
+
SyncStatusSnapshot
|
|
7
|
+
} from '@powersync/shared-internals';
|
|
8
|
+
import {
|
|
9
|
+
WebStreamingSyncImplementation,
|
|
10
|
+
WebStreamingSyncImplementationOptions
|
|
11
|
+
} from './WebStreamingSyncImplementation.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* When multi-tab support is disabled and we don't use a shared worker for sync, only a single tab will be able to
|
|
15
|
+
* acquire the sync navigator lock and start a sync iteration.
|
|
16
|
+
*
|
|
17
|
+
* To be able to provide _some_ multi-tab support in that configuration, this utility:
|
|
18
|
+
*
|
|
19
|
+
* 1. Sends sync status updates from the syncing tab to others.
|
|
20
|
+
* 2. Allows other tabs to send notifications when their active sync stream subscriptions update, allowing the active
|
|
21
|
+
* tab to take those subscriptions into account.
|
|
22
|
+
*/
|
|
23
|
+
export class TabLocalStreamingSyncImplementation extends WebStreamingSyncImplementation {
|
|
24
|
+
#statusUpdated: BroadcastChannel;
|
|
25
|
+
#subscriptionsChanged: BroadcastChannel;
|
|
26
|
+
#hasSyncLock = false;
|
|
27
|
+
|
|
28
|
+
constructor(options: WebStreamingSyncImplementationOptions) {
|
|
29
|
+
super(options);
|
|
30
|
+
|
|
31
|
+
const identifier = options.identifier;
|
|
32
|
+
this.#statusUpdated = new BroadcastChannel(`sync-status-${identifier}`);
|
|
33
|
+
this.#subscriptionsChanged = new BroadcastChannel(`subscription-change-${identifier}`);
|
|
34
|
+
|
|
35
|
+
this.#statusUpdated.onmessage = (event) => {
|
|
36
|
+
if (event.data == 'ping') {
|
|
37
|
+
this.#sendStatus(this.syncStatus);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { core, dataFlow } = event.data as SyncStatusJson;
|
|
42
|
+
this.updateSyncStatus(core, dataFlow);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Request other tabs to share their sync status.
|
|
46
|
+
this.#statusUpdated.postMessage('ping');
|
|
47
|
+
this.#subscriptionsChanged.onmessage = () => {
|
|
48
|
+
// We can't update activeStreams since we don't know when another tab referencing them is closed. However,
|
|
49
|
+
// clients will update an internal table listing streams after subscribing, and updateSubscriptions() will
|
|
50
|
+
// scan that table.
|
|
51
|
+
super.updateSubscriptions(this.activeStreams);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
this.registerListener({
|
|
55
|
+
statusChanged: (status) => this.#sendStatus(status)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#sendStatus(status: SyncStatusSnapshot) {
|
|
60
|
+
// Don't share sync status if this is not the tab currently syncing.
|
|
61
|
+
if (this.#hasSyncLock) {
|
|
62
|
+
this.#statusUpdated.postMessage(status.toJSON());
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override updateSubscriptions(subscriptions: SubscribedStream[]): void {
|
|
67
|
+
super.updateSubscriptions(subscriptions);
|
|
68
|
+
this.#subscriptionsChanged.postMessage('');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
override obtainLock<T>({ callback, type, signal }: LockOptions<T>): Promise<T> {
|
|
72
|
+
const wrappedCallback = async (): Promise<T> => {
|
|
73
|
+
this.#hasSyncLock = true;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
return await callback();
|
|
77
|
+
} finally {
|
|
78
|
+
this.#hasSyncLock = false;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
return super.obtainLock({ callback: type == LockType.SYNC ? wrappedCallback : callback, type, signal });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override async dispose(): Promise<void> {
|
|
86
|
+
this.#statusUpdated.close();
|
|
87
|
+
this.#subscriptionsChanged.close();
|
|
88
|
+
await super.dispose();
|
|
89
|
+
}
|
|
90
|
+
}
|
package/src/db/sync/WebRemote.ts
CHANGED
|
@@ -1,43 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
AbstractRemoteOptions,
|
|
4
|
-
DEFAULT_REMOTE_LOGGER,
|
|
5
|
-
FetchImplementation,
|
|
6
|
-
FetchImplementationProvider,
|
|
7
|
-
ILogger,
|
|
8
|
-
RemoteConnector
|
|
9
|
-
} from '@powersync/common';
|
|
1
|
+
import { LogLevels, PowerSyncLogger } from '@powersync/common';
|
|
2
|
+
import { AbstractRemote, FetchOptions, RemoteConnector } from '@powersync/shared-internals';
|
|
10
3
|
|
|
11
4
|
import { getUserAgentInfo } from './userAgent.js';
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* Depends on browser's implementation of global fetch.
|
|
15
|
-
*/
|
|
16
|
-
class WebFetchProvider extends FetchImplementationProvider {
|
|
17
|
-
getFetch(): FetchImplementation {
|
|
18
|
-
return fetch.bind(globalThis);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
5
|
+
import type { WebSocketSyncStreamPlatform, WebSocketSupport } from '@powersync/shared-internals/websockets';
|
|
21
6
|
|
|
22
7
|
export class WebRemote extends AbstractRemote {
|
|
23
8
|
constructor(
|
|
24
9
|
protected connector: RemoteConnector,
|
|
25
|
-
|
|
26
|
-
options?: Partial<AbstractRemoteOptions>
|
|
10
|
+
logger: PowerSyncLogger
|
|
27
11
|
) {
|
|
28
|
-
super(connector, logger
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
super(connector, logger);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
protected fetch({ resource, request }: FetchOptions): Promise<Response> {
|
|
16
|
+
return fetch(resource, request);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected async loadWebSocketSupport(platform: WebSocketSyncStreamPlatform): Promise<WebSocketSupport> {
|
|
20
|
+
if (!websockets) {
|
|
21
|
+
// loadWebSocketSupport being called concurrently is safe, the import resolves to the same module in that case.
|
|
22
|
+
const module = await import('@powersync/shared-internals/websockets');
|
|
23
|
+
websockets = new module.WebSocketSupport(platform);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return websockets;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
29
|
getUserAgent(): string {
|
|
35
30
|
let ua = [super.getUserAgent(), `powersync-web`];
|
|
36
31
|
try {
|
|
37
32
|
ua.push(...getUserAgentInfo());
|
|
38
|
-
} catch (
|
|
39
|
-
this.logger.warn
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.log({ level: LogLevels.warn, message: 'Failed to get user agent info', error });
|
|
40
35
|
}
|
|
41
36
|
return ua.join(' ');
|
|
42
37
|
}
|
|
43
38
|
}
|
|
39
|
+
|
|
40
|
+
let websockets: WebSocketSupport | undefined;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { LogLevels } from '@powersync/common';
|
|
1
2
|
import {
|
|
2
3
|
AbstractStreamingSyncImplementation,
|
|
3
4
|
AbstractStreamingSyncImplementationOptions,
|
|
4
5
|
LockOptions,
|
|
5
6
|
LockType
|
|
6
|
-
} from '@powersync/
|
|
7
|
+
} from '@powersync/shared-internals';
|
|
7
8
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
8
|
-
import { ResolvedWebSQLOpenOptions, WebSQLFlags } from '../adapters/web-sql-flags.js';
|
|
9
9
|
|
|
10
10
|
export interface WebStreamingSyncImplementationOptions extends AbstractStreamingSyncImplementationOptions {
|
|
11
|
-
flags?: WebSQLFlags;
|
|
12
11
|
sync?: {
|
|
13
|
-
worker?: string | URL | ((
|
|
12
|
+
worker?: string | URL | (() => SharedWorker);
|
|
14
13
|
};
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -27,7 +26,7 @@ export class WebStreamingSyncImplementation extends AbstractStreamingSyncImpleme
|
|
|
27
26
|
async obtainLock<T>(lockOptions: LockOptions<T>): Promise<T> {
|
|
28
27
|
const identifier = `streaming-sync-${lockOptions.type}-${this.webOptions.identifier}`;
|
|
29
28
|
if (lockOptions.type == LockType.SYNC) {
|
|
30
|
-
this.logger.debug
|
|
29
|
+
this.logger.log({ level: LogLevels.debug, message: `requesting lock for ${identifier}` });
|
|
31
30
|
}
|
|
32
31
|
return getNavigatorLocks().request(identifier, { signal: lockOptions.signal }, lockOptions.callback);
|
|
33
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
export * from '@powersync/common';
|
|
2
2
|
export * from './attachments/IndexDBFileSystemAdapter.js';
|
|
3
|
-
export * from './db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js';
|
|
4
3
|
export { WASQLiteVFS } from './db/adapters/wa-sqlite/vfs.js';
|
|
5
4
|
export * from './db/adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
6
|
-
export * from './db/adapters/
|
|
7
|
-
export * from './db/adapters/web-sql-flags.js';
|
|
5
|
+
export * from './db/adapters/options.js';
|
|
8
6
|
export * from './db/PowerSyncDatabase.js';
|
|
9
7
|
export * from './db/sync/SharedWebStreamingSyncImplementation.js';
|
|
10
8
|
export * from './db/sync/WebRemote.js';
|