@powersync/web 0.0.0-dev-20260708104358 → 0.0.0-dev-20260917074240
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-BHScYYZw.wasm +0 -0
- package/dist/worker/assets/mc-wa-sqlite-async-DdlQmAUV.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-CIxTmRHQ.wasm +0 -0
- package/dist/worker/assets/wa-sqlite-async-zc68fxQq.wasm +0 -0
- package/dist/worker/mc-wa-sqlite-PubB6u8c.js +2 -0
- package/dist/worker/mc-wa-sqlite-PubB6u8c.js.map +1 -0
- package/dist/worker/mc-wa-sqlite-async-DJG_ANKO.js +2 -0
- package/dist/worker/mc-wa-sqlite-async-DJG_ANKO.js.map +1 -0
- package/dist/worker/wa-sqlite-D1_4mGs8.js +2 -0
- package/dist/worker/wa-sqlite-D1_4mGs8.js.map +1 -0
- package/dist/worker/wa-sqlite-async-BxkwNY-2.js +2 -0
- package/dist/worker/wa-sqlite-async-BxkwNY-2.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 +140 -107
- 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 +197 -138
- 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
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/web",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20260917074240",
|
|
4
4
|
"description": "PowerSync Web SDK",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"module": "lib/
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "lib/index.js",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"types": "lib/
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
9
|
"bin": {
|
|
10
10
|
"powersync-web": "bin/powersync.cjs"
|
|
11
11
|
},
|
|
@@ -18,25 +18,24 @@
|
|
|
18
18
|
],
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"types": "./lib/
|
|
22
|
-
"
|
|
21
|
+
"types": "./lib/index.d.ts",
|
|
22
|
+
"react-native-web": "./dist/index.react_native_web.js",
|
|
23
|
+
"react-native": "./dist/index.react_native_web.js",
|
|
24
|
+
"default": "./lib/index.js"
|
|
23
25
|
},
|
|
24
|
-
"./
|
|
25
|
-
"types": "./lib/
|
|
26
|
-
"default": "./
|
|
26
|
+
"./extra/shared-memory-pool": {
|
|
27
|
+
"types": "./lib/db/adapters/memory-pool/client.d.ts",
|
|
28
|
+
"default": "./lib/db/adapters/memory-pool/client.js"
|
|
27
29
|
},
|
|
28
|
-
"./
|
|
29
|
-
"types": "./lib/
|
|
30
|
-
"
|
|
31
|
-
"require": "./dist/worker/WASQLiteDB.umd.js"
|
|
32
|
-
},
|
|
33
|
-
"./umd/worker/sync": {
|
|
34
|
-
"types": "./lib/src/index.d.ts",
|
|
35
|
-
"import": "./dist/worker/SharedSyncImplementation.umd.js",
|
|
36
|
-
"require": "./dist/worker/SharedSyncImplementation.umd.js"
|
|
30
|
+
"./bundled_worker": {
|
|
31
|
+
"types": "./lib/worker/worker.d.ts",
|
|
32
|
+
"default": "./dist/worker/worker.js"
|
|
37
33
|
}
|
|
38
34
|
},
|
|
39
|
-
"repository":
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "https://github.com/powersync-ja/powersync-js"
|
|
38
|
+
},
|
|
40
39
|
"bugs": {
|
|
41
40
|
"url": "https://github.com/powersync-ja/powersync-js/issues"
|
|
42
41
|
},
|
|
@@ -55,37 +54,37 @@
|
|
|
55
54
|
"author": "PowerSync",
|
|
56
55
|
"license": "Apache-2.0",
|
|
57
56
|
"peerDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@powersync/
|
|
57
|
+
"@powersync/common": "^2.2.1",
|
|
58
|
+
"@powersync/shared-internals": "0.0.0-dev-20260917074240"
|
|
60
59
|
},
|
|
61
60
|
"dependencies": {
|
|
61
|
+
"@journeyapps/wa-sqlite": "2.0.4",
|
|
62
62
|
"comlink": "^4.4.2",
|
|
63
63
|
"commander": "^12.1.0",
|
|
64
|
-
"@powersync/common": "
|
|
64
|
+
"@powersync/common": "2.2.1",
|
|
65
|
+
"@powersync/shared-internals": "0.0.0-dev-20260917074240"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"@journeyapps/wa-sqlite": "^1.7.0",
|
|
68
68
|
"@types/uuid": "^9.0.6",
|
|
69
69
|
"bson": "^6.10.4",
|
|
70
70
|
"glob": "^11.0.0",
|
|
71
71
|
"p-defer": "^4.0.1",
|
|
72
72
|
"source-map-loader": "^5.0.0",
|
|
73
|
-
"terser-webpack-plugin": "^5.3.9",
|
|
74
73
|
"uuid": "^11.1.0",
|
|
75
74
|
"vite": "^7.3.1",
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
75
|
+
"rollup": "^4.52.5",
|
|
76
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
77
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
78
|
+
"estree-walker": "^3.0.3",
|
|
79
|
+
"magic-string": "^0.30.21"
|
|
79
80
|
},
|
|
80
81
|
"scripts": {
|
|
81
82
|
"build:tsc": "tsc --build",
|
|
82
|
-
"build:
|
|
83
|
-
"build:
|
|
84
|
-
"build": "pnpm run build:tsc && pnpm run build:webpack-main && pnpm run build:webpack-workers",
|
|
85
|
-
"build:prod": "pnpm run build:tsc --sourceMap false && pnpm run build:webpack-main && pnpm run build:webpack-workers",
|
|
83
|
+
"build": "pnpm run build:tsc && rollup --config",
|
|
84
|
+
"build:prod": "pnpm run build",
|
|
86
85
|
"clean": "rm -rf lib dist tsconfig.tsbuildinfo",
|
|
87
86
|
"watch": "tsc --build -w",
|
|
88
87
|
"test": "pnpm build && vitest",
|
|
89
|
-
"test:exports": "attw --pack . --entrypoints . --profile=esm-only "
|
|
88
|
+
"test:exports": "attw --pack . --entrypoints . extra/shared-memory-pool --profile=esm-only "
|
|
90
89
|
}
|
|
91
90
|
}
|
|
@@ -1,53 +1,50 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
type PowerSyncBackendConnector,
|
|
3
|
+
type PowerSyncCloseOptions,
|
|
4
|
+
LogLevels,
|
|
5
|
+
BasePowerSyncDatabaseOptions,
|
|
6
|
+
DatabaseSource,
|
|
3
7
|
DBAdapter,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
PowerSyncDatabaseConstructor,
|
|
9
|
+
CommonPowerSyncDatabase
|
|
10
|
+
} from '@powersync/common';
|
|
11
|
+
import {
|
|
12
|
+
BasePowerSyncDatabase,
|
|
13
|
+
BucketStorageAdapter,
|
|
14
|
+
CreateSyncImplementationOptions,
|
|
15
|
+
Mutex,
|
|
8
16
|
SqliteBucketStorage,
|
|
9
17
|
StreamingSyncImplementation,
|
|
10
18
|
TriggerManagerConfig,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Mutex,
|
|
14
|
-
type BucketStorageAdapter,
|
|
15
|
-
type PowerSyncBackendConnector,
|
|
16
|
-
type PowerSyncCloseOptions,
|
|
17
|
-
type RequiredAdditionalConnectionOptions
|
|
18
|
-
} from '@powersync/common';
|
|
19
|
+
openDatabase
|
|
20
|
+
} from '@powersync/shared-internals';
|
|
19
21
|
import { getNavigatorLocks } from '../shared/navigator.js';
|
|
20
22
|
import { NAVIGATOR_TRIGGER_CLAIM_MANAGER } from './NavigatorTriggerClaimManager.js';
|
|
21
23
|
import { WebDBAdapter } from './adapters/WebDBAdapter.js';
|
|
22
24
|
import { WASQLiteOpenFactory } from './adapters/wa-sqlite/WASQLiteOpenFactory.js';
|
|
23
|
-
import {
|
|
24
|
-
DEFAULT_WEB_SQL_FLAGS,
|
|
25
|
-
ResolvedWebSQLOpenOptions,
|
|
26
|
-
WebSQLFlags,
|
|
27
|
-
isServerSide,
|
|
28
|
-
resolveWebSQLFlags
|
|
29
|
-
} from './adapters/web-sql-flags.js';
|
|
25
|
+
import { WebSpecificOpenOptions, WebSQLOpenOptions } from './adapters/options.js';
|
|
30
26
|
import { SSRStreamingSyncImplementation } from './sync/SSRWebStreamingSyncImplementation.js';
|
|
31
27
|
import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation.js';
|
|
32
28
|
import { WebRemote } from './sync/WebRemote.js';
|
|
33
|
-
import {
|
|
34
|
-
WebStreamingSyncImplementation,
|
|
35
|
-
WebStreamingSyncImplementationOptions
|
|
36
|
-
} from './sync/WebStreamingSyncImplementation.js';
|
|
29
|
+
import { WebStreamingSyncImplementationOptions } from './sync/WebStreamingSyncImplementation.js';
|
|
37
30
|
import { AsyncDbAdapter } from './adapters/AsyncWebAdapter.js';
|
|
31
|
+
import { resolveAndValidateOptions } from './adapters/resolveAndValidateOptions.js';
|
|
32
|
+
import { TabLocalStreamingSyncImplementation } from './sync/TabLocalStreamingSyncImplementation.js';
|
|
33
|
+
|
|
34
|
+
export type WebPowerSyncDatabaseOptions = BasePowerSyncDatabaseOptions &
|
|
35
|
+
DatabaseSource<WebSQLOpenOptions> &
|
|
36
|
+
WebSpecificOptions;
|
|
37
|
+
|
|
38
|
+
export interface WebSpecificOptions {
|
|
39
|
+
sync?: WebSyncOptions;
|
|
38
40
|
|
|
39
|
-
export interface WebPowerSyncFlags extends WebSQLFlags {
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* Setting this to `true` requires calling `close` on all open PowerSyncDatabase
|
|
44
|
-
* instances before the window unloads
|
|
42
|
+
* Broadcast logs from shared workers, such as the shared sync worker,
|
|
43
|
+
* to individual tabs. This defaults to true.
|
|
45
44
|
*/
|
|
46
|
-
|
|
45
|
+
broadcastLogs?: boolean;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
type WithWebFlags<Base> = Base & { flags?: WebPowerSyncFlags };
|
|
50
|
-
|
|
51
48
|
export interface WebSyncOptions {
|
|
52
49
|
/**
|
|
53
50
|
* Allows you to override the default sync worker.
|
|
@@ -55,91 +52,31 @@ export interface WebSyncOptions {
|
|
|
55
52
|
* You can either provide a path to the worker script
|
|
56
53
|
* or a factory method that returns a worker.
|
|
57
54
|
*/
|
|
58
|
-
worker?: string | URL | ((
|
|
59
|
-
}
|
|
55
|
+
worker?: string | URL | (() => SharedWorker);
|
|
60
56
|
|
|
61
|
-
type WithWebSyncOptions<Base> = Base & {
|
|
62
|
-
sync?: WebSyncOptions;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export interface WebEncryptionOptions {
|
|
66
57
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
58
|
+
* The log level for logs from the sync worker.
|
|
59
|
+
*
|
|
60
|
+
* Defaults to {@link LogLevels.info}.
|
|
69
61
|
*/
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type WithWebEncryptionOptions<Base> = Base & WebEncryptionOptions;
|
|
74
|
-
|
|
75
|
-
export type WebPowerSyncDatabaseOptionsWithAdapter = WithWebSyncOptions<
|
|
76
|
-
WithWebFlags<PowerSyncDatabaseOptionsWithDBAdapter>
|
|
77
|
-
>;
|
|
78
|
-
export type WebPowerSyncDatabaseOptionsWithOpenFactory = WithWebSyncOptions<
|
|
79
|
-
WithWebFlags<PowerSyncDatabaseOptionsWithOpenFactory>
|
|
80
|
-
>;
|
|
81
|
-
export type WebPowerSyncDatabaseOptionsWithSettings = WithWebSyncOptions<
|
|
82
|
-
WithWebFlags<WithWebEncryptionOptions<PowerSyncDatabaseOptionsWithSettings>>
|
|
83
|
-
>;
|
|
84
|
-
|
|
85
|
-
export type WebPowerSyncDatabaseOptions = WithWebSyncOptions<WithWebFlags<PowerSyncDatabaseOptions>>;
|
|
86
|
-
|
|
87
|
-
export const DEFAULT_POWERSYNC_FLAGS: Required<WebPowerSyncFlags> = {
|
|
88
|
-
...DEFAULT_WEB_SQL_FLAGS,
|
|
89
|
-
externallyUnload: false
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const resolveWebPowerSyncFlags = (flags?: WebPowerSyncFlags): Required<WebPowerSyncFlags> => {
|
|
93
|
-
return {
|
|
94
|
-
...DEFAULT_POWERSYNC_FLAGS,
|
|
95
|
-
...flags,
|
|
96
|
-
...resolveWebSQLFlags(flags)
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Asserts that the database options are valid for custom database constructors.
|
|
102
|
-
*/
|
|
103
|
-
function assertValidDatabaseOptions(options: WebPowerSyncDatabaseOptions): void {
|
|
104
|
-
if ('database' in options && 'encryptionKey' in options) {
|
|
105
|
-
const { database } = options;
|
|
106
|
-
if (isSQLOpenFactory(database) || isDBAdapter(database)) {
|
|
107
|
-
throw new Error(
|
|
108
|
-
`Invalid configuration: 'encryptionKey' should only be included inside the database object when using a custom ${isSQLOpenFactory(database) ? 'WASQLiteOpenFactory' : 'WASQLiteDBAdapter'} constructor.`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
62
|
+
logLevel?: number;
|
|
112
63
|
}
|
|
113
64
|
|
|
114
65
|
/**
|
|
115
|
-
*
|
|
116
|
-
* which is automatically synced.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* export const db = new PowerSyncDatabase({
|
|
121
|
-
* schema: AppSchema,
|
|
122
|
-
* database: {
|
|
123
|
-
* dbFilename: 'example.db'
|
|
124
|
-
* }
|
|
125
|
-
* });
|
|
126
|
-
* ```
|
|
66
|
+
* @internal Use {@link PowerSyncDatabase} instead, this class is only used by other SDKs also needing web support.
|
|
127
67
|
*/
|
|
128
|
-
export class
|
|
68
|
+
export class WebPowerSyncDatabase extends BasePowerSyncDatabase<WebPowerSyncDatabaseOptions> {
|
|
129
69
|
static SHARED_MUTEX = new Mutex();
|
|
130
70
|
|
|
131
|
-
protected
|
|
71
|
+
protected resolvedOpenOptions: WebSpecificOpenOptions;
|
|
72
|
+
protected enableBroadcastLogs: boolean;
|
|
132
73
|
|
|
133
|
-
constructor(options:
|
|
134
|
-
|
|
135
|
-
constructor(options: WebPowerSyncDatabaseOptionsWithSettings);
|
|
136
|
-
constructor(options: WebPowerSyncDatabaseOptions);
|
|
137
|
-
constructor(protected options: WebPowerSyncDatabaseOptions) {
|
|
138
|
-
super(options);
|
|
139
|
-
|
|
140
|
-
assertValidDatabaseOptions(options);
|
|
74
|
+
constructor(options: WebPowerSyncDatabaseOptions) {
|
|
75
|
+
const resolvedOpenOptions = resolveAndValidateOptions('database' in options ? options.database : {});
|
|
141
76
|
|
|
142
|
-
|
|
77
|
+
super(options);
|
|
78
|
+
this.resolvedOpenOptions = resolvedOpenOptions;
|
|
79
|
+
this.enableBroadcastLogs = options.broadcastLogs ?? true;
|
|
143
80
|
}
|
|
144
81
|
|
|
145
82
|
async _initialize(): Promise<void> {
|
|
@@ -170,13 +107,14 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
170
107
|
};
|
|
171
108
|
}
|
|
172
109
|
|
|
173
|
-
protected openDBAdapter(
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
110
|
+
protected override openDBAdapter(): DBAdapter {
|
|
111
|
+
return openDatabase(this.options, (options) => {
|
|
112
|
+
const defaultFactory = new WASQLiteOpenFactory({
|
|
113
|
+
logger: this.logger,
|
|
114
|
+
open: options
|
|
115
|
+
});
|
|
116
|
+
return defaultFactory.openDB();
|
|
178
117
|
});
|
|
179
|
-
return defaultFactory.openDB();
|
|
180
118
|
}
|
|
181
119
|
|
|
182
120
|
/**
|
|
@@ -187,72 +125,86 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
|
|
|
187
125
|
close(options?: PowerSyncCloseOptions): Promise<void> {
|
|
188
126
|
return super.close({
|
|
189
127
|
// Don't disconnect by default if multiple tabs are enabled
|
|
190
|
-
disconnect: options?.disconnect ?? !this.
|
|
128
|
+
disconnect: options?.disconnect ?? !this.resolvedOpenOptions.enableMultiTabs
|
|
191
129
|
});
|
|
192
130
|
}
|
|
193
131
|
|
|
194
132
|
protected async loadVersion(): Promise<void> {
|
|
195
|
-
if (
|
|
133
|
+
if (this.resolvedOpenOptions.ssrMode) {
|
|
196
134
|
return;
|
|
197
135
|
}
|
|
198
136
|
return super.loadVersion();
|
|
199
137
|
}
|
|
200
138
|
|
|
201
139
|
protected async resolveOfflineSyncStatus() {
|
|
202
|
-
if (
|
|
140
|
+
if (this.resolvedOpenOptions.ssrMode) {
|
|
203
141
|
return;
|
|
204
142
|
}
|
|
205
143
|
return super.resolveOfflineSyncStatus();
|
|
206
144
|
}
|
|
207
145
|
|
|
208
|
-
protected generateBucketStorageAdapter(): BucketStorageAdapter {
|
|
209
|
-
return new SqliteBucketStorage(this.database);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
146
|
protected async runExclusive<T>(cb: () => Promise<T>) {
|
|
213
|
-
if (this.
|
|
214
|
-
return
|
|
147
|
+
if (this.resolvedOpenOptions.ssrMode) {
|
|
148
|
+
return WebPowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
|
|
215
149
|
}
|
|
216
150
|
return getNavigatorLocks().request(`lock-${this.database.name}`, cb);
|
|
217
151
|
}
|
|
218
152
|
|
|
219
153
|
protected generateSyncStreamImplementation(
|
|
220
154
|
connector: PowerSyncBackendConnector,
|
|
221
|
-
options:
|
|
155
|
+
options: CreateSyncImplementationOptions
|
|
222
156
|
): StreamingSyncImplementation {
|
|
223
157
|
const remote = new WebRemote(connector, this.logger);
|
|
224
158
|
const syncOptions: WebStreamingSyncImplementationOptions = {
|
|
225
159
|
...(this.options as {}),
|
|
226
|
-
...options,
|
|
227
|
-
|
|
228
|
-
adapter: this.bucketStorageAdapter,
|
|
229
|
-
remote,
|
|
230
|
-
uploadCrud: async () => {
|
|
231
|
-
await this.waitForReady();
|
|
232
|
-
await connector.uploadData(this);
|
|
233
|
-
},
|
|
234
|
-
identifier: this.database.name,
|
|
235
|
-
logger: this.logger
|
|
160
|
+
...this.commonSyncOptions(connector, options),
|
|
161
|
+
remote
|
|
236
162
|
};
|
|
237
163
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const warning = `
|
|
164
|
+
if (this.resolvedOpenOptions.ssrMode) {
|
|
165
|
+
return new SSRStreamingSyncImplementation();
|
|
166
|
+
} else if (this.resolvedOpenOptions.enableMultiTabs) {
|
|
167
|
+
if (!this.enableBroadcastLogs) {
|
|
168
|
+
const warning = `
|
|
244
169
|
Multiple tabs are enabled, but broadcasting of logs is disabled.
|
|
245
170
|
Logs for shared sync worker will only be available in the shared worker context
|
|
246
171
|
`;
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
172
|
+
const logger = this.options.logger;
|
|
173
|
+
logger ? logger.log({ level: LogLevels.warn, message: warning }) : console.warn(warning);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if ('shareConnection' in this.database) {
|
|
250
177
|
return new SharedWebStreamingSyncImplementation({
|
|
251
178
|
...syncOptions,
|
|
252
|
-
db: this.database as WebDBAdapter // This should always be the case
|
|
179
|
+
db: this.database as WebDBAdapter, // This should always be the case
|
|
180
|
+
logLevel: this.options.sync?.logLevel ?? LogLevels.info,
|
|
181
|
+
enableBroadcastLogs: this.enableBroadcastLogs
|
|
253
182
|
});
|
|
254
|
-
|
|
255
|
-
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
this.logger.log({
|
|
186
|
+
level: LogLevels.warn,
|
|
187
|
+
message: "Not using a shared sync worker because the database adapter doesn't support it."
|
|
188
|
+
});
|
|
256
189
|
}
|
|
190
|
+
|
|
191
|
+
return new TabLocalStreamingSyncImplementation(syncOptions);
|
|
257
192
|
}
|
|
258
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* A PowerSync database which provides SQLite functionality
|
|
196
|
+
* which is automatically synced.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* export const db = new PowerSyncDatabase({
|
|
201
|
+
* schema: AppSchema,
|
|
202
|
+
* database: {
|
|
203
|
+
* dbFilename: 'example.db'
|
|
204
|
+
* }
|
|
205
|
+
* });
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
// Typed constructor to avoid leaking AbstractPowerSyncDatabase into the public interface
|
|
209
|
+
export const PowerSyncDatabase: PowerSyncDatabaseConstructor<WebPowerSyncDatabaseOptions> = WebPowerSyncDatabase;
|
|
210
|
+
export interface PowerSyncDatabase extends CommonPowerSyncDatabase {}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
DBAdapterListener,
|
|
5
|
-
DBLockOptions,
|
|
6
|
-
LockContext,
|
|
7
|
-
Mutex,
|
|
8
|
-
Semaphore,
|
|
9
|
-
UnlockFn
|
|
10
|
-
} from '@powersync/common';
|
|
11
|
-
import { SharedConnectionWorker, WebDBAdapter, WebDBAdapterConfiguration } from './WebDBAdapter.js';
|
|
1
|
+
import { DBAdapter, DBAdapterListener, DBLockOptions, LockContext } from '@powersync/common';
|
|
2
|
+
import { Mutex, Semaphore } from '@powersync/shared-internals';
|
|
3
|
+
import { SharedConnectionWorker, WebDBAdapterConfiguration } from './WebDBAdapter.js';
|
|
12
4
|
import { DatabaseClient } from './wa-sqlite/DatabaseClient.js';
|
|
5
|
+
import { acquireFromPool } from './acquireFromPool.js';
|
|
13
6
|
|
|
14
7
|
type PendingListener = { listener: Partial<DBAdapterListener>; closeAfterRegisteredOnResolvedPool?: () => void };
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
10
|
* A connection pool implementation delegating to another pool opened asynchronnously.
|
|
18
11
|
*/
|
|
19
|
-
class
|
|
12
|
+
export class AsyncDbAdapter extends DBAdapter {
|
|
20
13
|
protected readonly state: Promise<PoolState>;
|
|
21
14
|
protected resolvedWriter?: DatabaseClient;
|
|
22
15
|
|
|
@@ -26,6 +19,7 @@ class AsyncConnectionPool implements ConnectionPool {
|
|
|
26
19
|
inner: Promise<PoolConnection>,
|
|
27
20
|
readonly name: string
|
|
28
21
|
) {
|
|
22
|
+
super();
|
|
29
23
|
this.state = inner.then((client) => {
|
|
30
24
|
for (const pending of this.pendingListeners) {
|
|
31
25
|
pending.closeAfterRegisteredOnResolvedPool = client.writer.registerListener(pending.listener);
|
|
@@ -81,6 +75,19 @@ class AsyncConnectionPool implements ConnectionPool {
|
|
|
81
75
|
};
|
|
82
76
|
}
|
|
83
77
|
}
|
|
78
|
+
|
|
79
|
+
async shareConnection(): Promise<SharedConnectionWorker> {
|
|
80
|
+
const state = await this.state;
|
|
81
|
+
return state.writer.shareConnection();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getConfiguration(): WebDBAdapterConfiguration {
|
|
85
|
+
if (this.resolvedWriter) {
|
|
86
|
+
return this.resolvedWriter.getConfiguration();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw new Error('AsyncDbAdapter.getConfiguration() can only be called after initializing it.');
|
|
90
|
+
}
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
export interface PoolConnection {
|
|
@@ -120,65 +127,16 @@ function readWritePoolState(writer: DatabaseClient, readers: DatabaseClient[]):
|
|
|
120
127
|
return {
|
|
121
128
|
writer,
|
|
122
129
|
async withConnection(allowReadOnly, fn, options) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (allowReadOnly) {
|
|
134
|
-
let connection: DatabaseClient;
|
|
135
|
-
|
|
136
|
-
// Even if we have a pool of read connections, it's typically very small and we assume that most queries are
|
|
137
|
-
// reads. So, we want to request any connection from the read pool and the dedicated write connection (which
|
|
138
|
-
// can also serve reads). We race for the first connection we can obtain this way, and then abort the other
|
|
139
|
-
// request.
|
|
140
|
-
[connection, release] = await new Promise<[DatabaseClient, UnlockFn]>((resolve, reject) => {
|
|
141
|
-
let didComplete = false;
|
|
142
|
-
function complete() {
|
|
143
|
-
didComplete = true;
|
|
144
|
-
abortController.abort();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function completeSuccess(connection: DatabaseClient, returnFn: UnlockFn) {
|
|
148
|
-
if (didComplete) {
|
|
149
|
-
// We're not going to use this connection, so return it immediately.
|
|
150
|
-
returnFn();
|
|
151
|
-
} else {
|
|
152
|
-
complete();
|
|
153
|
-
resolve([connection, returnFn]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function completeError(error: unknown) {
|
|
158
|
-
// We either have a working connection already, or we've rejected the promise. Either way, we don't need
|
|
159
|
-
// to do either thing again.
|
|
160
|
-
if (didComplete) return;
|
|
161
|
-
|
|
162
|
-
complete();
|
|
163
|
-
reject(error);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
writerMutex.acquire(abortSignal).then((unlock) => completeSuccess(writer, unlock), completeError);
|
|
167
|
-
readerSemaphore
|
|
168
|
-
.requestOne(abortSignal)
|
|
169
|
-
.then(({ item, release }) => completeSuccess(item, release), completeError);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return await connection.readLock(fn);
|
|
173
|
-
} else {
|
|
174
|
-
return await writerMutex.runExclusive(() => writer.writeLock(fn), abortSignal);
|
|
175
|
-
}
|
|
176
|
-
} finally {
|
|
177
|
-
if (timeout != null) {
|
|
178
|
-
clearTimeout(timeout);
|
|
179
|
-
}
|
|
180
|
-
release?.();
|
|
181
|
-
}
|
|
130
|
+
return acquireFromPool(
|
|
131
|
+
writerMutex,
|
|
132
|
+
writer,
|
|
133
|
+
readerSemaphore,
|
|
134
|
+
(connection) => {
|
|
135
|
+
return allowReadOnly ? connection.readLock(fn) : connection.writeLock(fn);
|
|
136
|
+
},
|
|
137
|
+
options,
|
|
138
|
+
allowReadOnly
|
|
139
|
+
);
|
|
182
140
|
},
|
|
183
141
|
async close() {
|
|
184
142
|
await writer.close();
|
|
@@ -190,18 +148,3 @@ function readWritePoolState(writer: DatabaseClient, readers: DatabaseClient[]):
|
|
|
190
148
|
}
|
|
191
149
|
};
|
|
192
150
|
}
|
|
193
|
-
|
|
194
|
-
export class AsyncDbAdapter extends DBAdapterDefaultMixin(AsyncConnectionPool) implements WebDBAdapter {
|
|
195
|
-
async shareConnection(): Promise<SharedConnectionWorker> {
|
|
196
|
-
const state = await this.state;
|
|
197
|
-
return state.writer.shareConnection();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
getConfiguration(): WebDBAdapterConfiguration {
|
|
201
|
-
if (this.resolvedWriter) {
|
|
202
|
-
return this.resolvedWriter.getConfiguration();
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
throw new Error('AsyncDbAdapter.getConfiguration() can only be called after initializing it.');
|
|
206
|
-
}
|
|
207
|
-
}
|