@powersync/web 1.39.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/README.md +0 -10
  2. package/bin/powersync.cjs +1 -1
  3. package/dist/index.react_native_web.js +1992 -0
  4. package/dist/index.react_native_web.js.map +1 -0
  5. package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +2 -0
  6. package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +1 -0
  7. package/dist/worker/FacadeVFS-d1ZDvud7.js +2 -0
  8. package/dist/worker/FacadeVFS-d1ZDvud7.js.map +1 -0
  9. package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +2 -0
  10. package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +1 -0
  11. package/dist/worker/MemoryVFS-DVJL5F8j.js +2 -0
  12. package/dist/worker/MemoryVFS-DVJL5F8j.js.map +1 -0
  13. package/dist/worker/OPFSCoopSyncVFS-BgTiWPfa.js +2 -0
  14. package/dist/worker/OPFSCoopSyncVFS-BgTiWPfa.js.map +1 -0
  15. package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +2 -0
  16. package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +1 -0
  17. package/dist/worker/assets/mc-wa-sqlite-DoDpgFfE.wasm +0 -0
  18. package/dist/worker/assets/mc-wa-sqlite-async-DYagSq56.wasm +0 -0
  19. package/dist/worker/assets/wa-sqlite-CagagB9I.wasm +0 -0
  20. package/dist/worker/assets/wa-sqlite-async-DCIP8kAx.wasm +0 -0
  21. package/dist/worker/mc-wa-sqlite-DDFgWP93.js +2 -0
  22. package/dist/worker/mc-wa-sqlite-DDFgWP93.js.map +1 -0
  23. package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js +2 -0
  24. package/dist/worker/mc-wa-sqlite-async-lGclTjKJ.js.map +1 -0
  25. package/dist/worker/wa-sqlite-B0tZMM0j.js +2 -0
  26. package/dist/worker/wa-sqlite-B0tZMM0j.js.map +1 -0
  27. package/dist/worker/wa-sqlite-async-CM6BmfRh.js +2 -0
  28. package/dist/worker/wa-sqlite-async-CM6BmfRh.js.map +1 -0
  29. package/dist/worker/websockets-Q8W_lerF.js +9 -0
  30. package/dist/worker/websockets-Q8W_lerF.js.map +1 -0
  31. package/dist/worker/worker.js +7 -0
  32. package/dist/worker/worker.js.map +1 -0
  33. package/lib/attachments/IndexDBFileSystemAdapter.js.map +1 -0
  34. package/lib/{src/db → db}/NavigatorTriggerClaimManager.d.ts +1 -1
  35. package/lib/db/NavigatorTriggerClaimManager.js.map +1 -0
  36. package/lib/db/PowerSyncDatabase.d.ts +67 -0
  37. package/lib/{src/db → db}/PowerSyncDatabase.js +49 -63
  38. package/lib/db/PowerSyncDatabase.js.map +1 -0
  39. package/lib/db/adapters/AsyncWebAdapter.d.ts +32 -0
  40. package/lib/{src/db → db}/adapters/AsyncWebAdapter.js +15 -15
  41. package/lib/db/adapters/AsyncWebAdapter.js.map +1 -0
  42. package/lib/db/adapters/SSRDBAdapter.d.ts +17 -0
  43. package/lib/db/adapters/SSRDBAdapter.js +37 -0
  44. package/lib/db/adapters/SSRDBAdapter.js.map +1 -0
  45. package/lib/{src/db → db}/adapters/WebDBAdapter.d.ts +1 -1
  46. package/lib/db/adapters/WebDBAdapter.js.map +1 -0
  47. package/lib/db/adapters/options.d.ts +87 -0
  48. package/lib/db/adapters/options.js +6 -0
  49. package/lib/db/adapters/options.js.map +1 -0
  50. package/lib/db/adapters/resolveAndValidateOptions.d.ts +13 -0
  51. package/lib/db/adapters/resolveAndValidateOptions.js +41 -0
  52. package/lib/db/adapters/resolveAndValidateOptions.js.map +1 -0
  53. package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +3 -4
  54. package/lib/{src/db → db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
  55. package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
  56. package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
  57. package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseClient.js +11 -37
  58. package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
  59. package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
  60. package/lib/{src/db → db}/adapters/wa-sqlite/DatabaseServer.js +14 -7
  61. package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
  62. package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +22 -12
  63. package/lib/{src/db → db}/adapters/wa-sqlite/RawSqliteConnection.js +12 -9
  64. package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
  65. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +18 -0
  66. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +137 -0
  67. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
  68. package/lib/{src/db → db}/adapters/wa-sqlite/vfs.d.ts +9 -2
  69. package/lib/{src/db → db}/adapters/wa-sqlite/vfs.js +6 -6
  70. package/lib/db/adapters/wa-sqlite/vfs.js.map +1 -0
  71. package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.d.ts +4 -8
  72. package/lib/{src/db → db}/sync/SSRWebStreamingSyncImplementation.js +4 -11
  73. package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
  74. package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.d.ts +13 -14
  75. package/lib/{src/db → db}/sync/SharedWebStreamingSyncImplementation.js +32 -66
  76. package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
  77. package/lib/db/sync/TabLocalStreamingSyncImplementation.d.ts +19 -0
  78. package/lib/db/sync/TabLocalStreamingSyncImplementation.js +70 -0
  79. package/lib/db/sync/TabLocalStreamingSyncImplementation.js.map +1 -0
  80. package/lib/db/sync/WebRemote.d.ts +10 -0
  81. package/lib/db/sync/WebRemote.js +33 -0
  82. package/lib/db/sync/WebRemote.js.map +1 -0
  83. package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.d.ts +2 -4
  84. package/lib/{src/db → db}/sync/WebStreamingSyncImplementation.js +3 -2
  85. package/lib/db/sync/WebStreamingSyncImplementation.js.map +1 -0
  86. package/lib/db/sync/userAgent.js.map +1 -0
  87. package/lib/{src/index.d.ts → index.d.ts} +1 -3
  88. package/lib/{src/index.js → index.js} +1 -3
  89. package/lib/index.js.map +1 -0
  90. package/lib/shared/navigator.js.map +1 -0
  91. package/lib/shared/tab_close_signal.js.map +1 -0
  92. package/lib/worker/SharedWorkerConnectionRequest.d.ts +5 -0
  93. package/lib/worker/SharedWorkerConnectionRequest.js +2 -0
  94. package/lib/worker/SharedWorkerConnectionRequest.js.map +1 -0
  95. package/lib/worker/client.d.ts +17 -0
  96. package/lib/worker/client.js +90 -0
  97. package/lib/worker/client.js.map +1 -0
  98. package/lib/worker/db/MultiDatabaseServer.d.ts +22 -0
  99. package/lib/{src/worker → worker}/db/MultiDatabaseServer.js +25 -15
  100. package/lib/worker/db/MultiDatabaseServer.js.map +1 -0
  101. package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +13 -0
  102. package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
  103. package/lib/worker/sync/BroadcastLogger.d.ts +27 -0
  104. package/lib/worker/sync/BroadcastLogger.js +65 -0
  105. package/lib/worker/sync/BroadcastLogger.js.map +1 -0
  106. package/lib/{src/worker → worker}/sync/SharedSyncImplementation.d.ts +12 -15
  107. package/lib/{src/worker → worker}/sync/SharedSyncImplementation.js +44 -44
  108. package/lib/worker/sync/SharedSyncImplementation.js.map +1 -0
  109. package/lib/{src/worker → worker}/sync/WorkerClient.d.ts +3 -3
  110. package/lib/{src/worker → worker}/sync/WorkerClient.js +2 -2
  111. package/lib/worker/sync/WorkerClient.js.map +1 -0
  112. package/lib/worker/worker.js +34 -0
  113. package/lib/worker/worker.js.map +1 -0
  114. package/package.json +23 -31
  115. package/src/db/NavigatorTriggerClaimManager.ts +1 -1
  116. package/src/db/PowerSyncDatabase.ts +83 -127
  117. package/src/db/adapters/AsyncWebAdapter.ts +18 -27
  118. package/src/db/adapters/SSRDBAdapter.ts +14 -64
  119. package/src/db/adapters/WebDBAdapter.ts +1 -1
  120. package/src/db/adapters/options.ts +100 -0
  121. package/src/db/adapters/resolveAndValidateOptions.ts +49 -0
  122. package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +4 -5
  123. package/src/db/adapters/wa-sqlite/DatabaseClient.ts +20 -56
  124. package/src/db/adapters/wa-sqlite/DatabaseServer.ts +18 -12
  125. package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +36 -23
  126. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +70 -125
  127. package/src/db/adapters/wa-sqlite/vfs.ts +13 -8
  128. package/src/db/sync/SSRWebStreamingSyncImplementation.ts +4 -22
  129. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +39 -77
  130. package/src/db/sync/TabLocalStreamingSyncImplementation.ts +90 -0
  131. package/src/db/sync/WebRemote.ts +23 -26
  132. package/src/db/sync/WebStreamingSyncImplementation.ts +4 -5
  133. package/src/index.ts +1 -3
  134. package/src/worker/SharedWorkerConnectionRequest.ts +6 -0
  135. package/src/worker/client.ts +121 -0
  136. package/src/worker/db/MultiDatabaseServer.ts +40 -22
  137. package/src/worker/sync/AbstractSharedSyncClientProvider.ts +4 -10
  138. package/src/worker/sync/BroadcastLogger.ts +35 -103
  139. package/src/worker/sync/SharedSyncImplementation.ts +65 -64
  140. package/src/worker/sync/WorkerClient.ts +4 -4
  141. package/src/worker/worker.ts +38 -0
  142. package/dist/2075a31bb151adbb9767.wasm +0 -0
  143. package/dist/3322bc84de986b63c2cd.wasm +0 -0
  144. package/dist/8e97452e297be23b5e50.wasm +0 -0
  145. package/dist/fbc178b70d530e8ce02b.wasm +0 -0
  146. package/dist/index.umd.js +0 -7821
  147. package/dist/index.umd.js.map +0 -1
  148. package/dist/worker/SharedSyncImplementation.umd.js +0 -16142
  149. package/dist/worker/SharedSyncImplementation.umd.js.map +0 -1
  150. package/dist/worker/WASQLiteDB.umd.js +0 -17437
  151. package/dist/worker/WASQLiteDB.umd.js.map +0 -1
  152. 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
  153. 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
  154. 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
  155. 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
  156. 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
  157. 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
  158. 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
  159. 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
  160. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +0 -3562
  161. 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
  162. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +0 -1400
  163. 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
  164. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +0 -2478
  165. 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
  166. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +0 -1681
  167. 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
  168. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +0 -1820
  169. 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
  170. package/lib/package.json +0 -91
  171. package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +0 -1
  172. package/lib/src/db/NavigatorTriggerClaimManager.js.map +0 -1
  173. package/lib/src/db/PowerSyncDatabase.d.ts +0 -78
  174. package/lib/src/db/PowerSyncDatabase.js.map +0 -1
  175. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +0 -23
  176. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +0 -27
  177. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +0 -1
  178. package/lib/src/db/adapters/AsyncWebAdapter.d.ts +0 -50
  179. package/lib/src/db/adapters/AsyncWebAdapter.js.map +0 -1
  180. package/lib/src/db/adapters/SSRDBAdapter.d.ts +0 -30
  181. package/lib/src/db/adapters/SSRDBAdapter.js +0 -69
  182. package/lib/src/db/adapters/SSRDBAdapter.js.map +0 -1
  183. package/lib/src/db/adapters/WebDBAdapter.js.map +0 -1
  184. package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
  185. package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
  186. package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
  187. package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
  188. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -45
  189. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -146
  190. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
  191. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +0 -15
  192. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +0 -22
  193. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +0 -1
  194. package/lib/src/db/adapters/wa-sqlite/vfs.js.map +0 -1
  195. package/lib/src/db/adapters/web-sql-flags.d.ts +0 -92
  196. package/lib/src/db/adapters/web-sql-flags.js +0 -37
  197. package/lib/src/db/adapters/web-sql-flags.js.map +0 -1
  198. package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
  199. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
  200. package/lib/src/db/sync/WebRemote.d.ts +0 -7
  201. package/lib/src/db/sync/WebRemote.js +0 -33
  202. package/lib/src/db/sync/WebRemote.js.map +0 -1
  203. package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +0 -1
  204. package/lib/src/db/sync/userAgent.js.map +0 -1
  205. package/lib/src/index.js.map +0 -1
  206. package/lib/src/shared/navigator.js.map +0 -1
  207. package/lib/src/shared/tab_close_signal.js.map +0 -1
  208. package/lib/src/worker/db/MultiDatabaseServer.d.ts +0 -17
  209. package/lib/src/worker/db/MultiDatabaseServer.js.map +0 -1
  210. package/lib/src/worker/db/WASQLiteDB.worker.d.ts +0 -4
  211. package/lib/src/worker/db/WASQLiteDB.worker.js +0 -31
  212. package/lib/src/worker/db/WASQLiteDB.worker.js.map +0 -1
  213. package/lib/src/worker/db/open-worker-database.d.ts +0 -14
  214. package/lib/src/worker/db/open-worker-database.js +0 -53
  215. package/lib/src/worker/db/open-worker-database.js.map +0 -1
  216. package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -19
  217. package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
  218. package/lib/src/worker/sync/BroadcastLogger.d.ts +0 -47
  219. package/lib/src/worker/sync/BroadcastLogger.js +0 -129
  220. package/lib/src/worker/sync/BroadcastLogger.js.map +0 -1
  221. package/lib/src/worker/sync/SharedSyncImplementation.js.map +0 -1
  222. package/lib/src/worker/sync/SharedSyncImplementation.worker.js +0 -12
  223. package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +0 -1
  224. package/lib/src/worker/sync/WorkerClient.js.map +0 -1
  225. package/lib/tsconfig.tsbuildinfo +0 -1
  226. package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +0 -47
  227. package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +0 -24
  228. package/src/db/adapters/web-sql-flags.ts +0 -141
  229. package/src/worker/db/WASQLiteDB.worker.ts +0 -35
  230. package/src/worker/db/open-worker-database.ts +0 -62
  231. package/src/worker/sync/SharedSyncImplementation.worker.ts +0 -14
  232. /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
  233. /package/lib/{src/attachments → attachments}/IndexDBFileSystemAdapter.js +0 -0
  234. /package/lib/{src/db → db}/NavigatorTriggerClaimManager.js +0 -0
  235. /package/lib/{src/db → db}/adapters/WebDBAdapter.js +0 -0
  236. /package/lib/{src/db → db}/sync/userAgent.d.ts +0 -0
  237. /package/lib/{src/db → db}/sync/userAgent.js +0 -0
  238. /package/lib/{src/shared → shared}/navigator.d.ts +0 -0
  239. /package/lib/{src/shared → shared}/navigator.js +0 -0
  240. /package/lib/{src/shared → shared}/tab_close_signal.d.ts +0 -0
  241. /package/lib/{src/shared → shared}/tab_close_signal.js +0 -0
  242. /package/lib/{src/worker → worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
  243. /package/lib/{src/worker/sync/SharedSyncImplementation.worker.d.ts → worker/worker.d.ts} +0 -0
@@ -1,53 +1,50 @@
1
1
  import {
2
- AbstractPowerSyncDatabase,
2
+ type PowerSyncBackendConnector,
3
+ type PowerSyncCloseOptions,
4
+ LogLevels,
5
+ BasePowerSyncDatabaseOptions,
6
+ DatabaseSource,
3
7
  DBAdapter,
4
- PowerSyncDatabaseOptions,
5
- PowerSyncDatabaseOptionsWithDBAdapter,
6
- PowerSyncDatabaseOptionsWithOpenFactory,
7
- PowerSyncDatabaseOptionsWithSettings,
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
- isDBAdapter,
12
- isSQLOpenFactory,
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
- * @deprecated This flag is no longer used. Navigator locks now handle tab detection automatically.
42
- * Externally unload open PowerSync database instances when the window closes.
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
- externallyUnload?: boolean;
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 | ((options: ResolvedWebSQLOpenOptions) => SharedWorker);
59
- }
60
-
61
- type WithWebSyncOptions<Base> = Base & {
62
- sync?: WebSyncOptions;
63
- };
55
+ worker?: string | URL | (() => SharedWorker);
64
56
 
65
- export interface WebEncryptionOptions {
66
57
  /**
67
- * Encryption key for the database.
68
- * If set, the database will be encrypted using Multiple Ciphers.
58
+ * The log level for logs from the sync worker.
59
+ *
60
+ * Defaults to {@link LogLevels.info}.
69
61
  */
70
- encryptionKey?: string;
62
+ logLevel?: number;
71
63
  }
72
64
 
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
65
  /**
101
- * Asserts that the database options are valid for custom database constructors.
66
+ * @internal Use {@link PowerSyncDatabase} instead, this class is only used by other SDKs also needing web support.
102
67
  */
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
- }
112
- }
113
-
114
- /**
115
- * A PowerSync database which provides SQLite functionality
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
- * ```
127
- */
128
- export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
68
+ export class WebPowerSyncDatabase extends BasePowerSyncDatabase<WebPowerSyncDatabaseOptions> {
129
69
  static SHARED_MUTEX = new Mutex();
130
70
 
131
- protected resolvedFlags: WebPowerSyncFlags;
71
+ protected resolvedOpenOptions: WebSpecificOpenOptions;
72
+ protected enableBroadcastLogs: boolean;
132
73
 
133
- constructor(options: WebPowerSyncDatabaseOptionsWithAdapter);
134
- constructor(options: WebPowerSyncDatabaseOptionsWithOpenFactory);
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
- this.resolvedFlags = resolveWebPowerSyncFlags(options.flags);
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(options: WebPowerSyncDatabaseOptionsWithSettings): DBAdapter {
174
- const defaultFactory = new WASQLiteOpenFactory({
175
- ...options.database,
176
- flags: resolveWebPowerSyncFlags(options.flags),
177
- encryptionKey: options.encryptionKey
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,44 +125,43 @@ 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.resolvedFlags.enableMultiTabs
128
+ disconnect: options?.disconnect ?? !this.resolvedOpenOptions.enableMultiTabs
191
129
  });
192
130
  }
193
131
 
194
132
  protected async loadVersion(): Promise<void> {
195
- if (isServerSide()) {
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 (isServerSide()) {
140
+ if (this.resolvedOpenOptions.ssrMode) {
203
141
  return;
204
142
  }
205
143
  return super.resolveOfflineSyncStatus();
206
144
  }
207
145
 
208
146
  protected generateBucketStorageAdapter(): BucketStorageAdapter {
209
- return new SqliteBucketStorage(this.database);
147
+ return new SqliteBucketStorage(this.database, this.logger);
210
148
  }
211
149
 
212
150
  protected async runExclusive<T>(cb: () => Promise<T>) {
213
- if (this.resolvedFlags.ssrMode) {
214
- return PowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
151
+ if (this.resolvedOpenOptions.ssrMode) {
152
+ return WebPowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
215
153
  }
216
154
  return getNavigatorLocks().request(`lock-${this.database.name}`, cb);
217
155
  }
218
156
 
219
157
  protected generateSyncStreamImplementation(
220
158
  connector: PowerSyncBackendConnector,
221
- options: RequiredAdditionalConnectionOptions
159
+ options: CreateSyncImplementationOptions
222
160
  ): StreamingSyncImplementation {
223
161
  const remote = new WebRemote(connector, this.logger);
224
162
  const syncOptions: WebStreamingSyncImplementationOptions = {
225
163
  ...(this.options as {}),
226
164
  ...options,
227
- flags: this.resolvedFlags,
228
165
  adapter: this.bucketStorageAdapter,
229
166
  remote,
230
167
  uploadCrud: async () => {
@@ -236,23 +173,42 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
236
173
  };
237
174
 
238
175
  switch (true) {
239
- case this.resolvedFlags.ssrMode:
240
- return new SSRStreamingSyncImplementation(syncOptions);
241
- case this.resolvedFlags.enableMultiTabs:
242
- if (!this.resolvedFlags.broadcastLogs) {
176
+ case this.resolvedOpenOptions.ssrMode:
177
+ return new SSRStreamingSyncImplementation();
178
+ case this.resolvedOpenOptions.enableMultiTabs:
179
+ if (!this.enableBroadcastLogs) {
243
180
  const warning = `
244
181
  Multiple tabs are enabled, but broadcasting of logs is disabled.
245
182
  Logs for shared sync worker will only be available in the shared worker context
246
183
  `;
247
184
  const logger = this.options.logger;
248
- logger ? logger.warn(warning) : console.warn(warning);
185
+ logger ? logger.log({ level: LogLevels.warn, message: warning }) : console.warn(warning);
249
186
  }
250
187
  return new SharedWebStreamingSyncImplementation({
251
188
  ...syncOptions,
252
- db: this.database as WebDBAdapter // This should always be the case
189
+ db: this.database as WebDBAdapter, // This should always be the case
190
+ logLevel: this.options.sync?.logLevel ?? LogLevels.info,
191
+ enableBroadcastLogs: this.enableBroadcastLogs
253
192
  });
254
193
  default:
255
- return new WebStreamingSyncImplementation(syncOptions);
194
+ return new TabLocalStreamingSyncImplementation(syncOptions);
256
195
  }
257
196
  }
258
197
  }
198
+ /**
199
+ * A PowerSync database which provides SQLite functionality
200
+ * which is automatically synced.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * export const db = new PowerSyncDatabase({
205
+ * schema: AppSchema,
206
+ * database: {
207
+ * dbFilename: 'example.db'
208
+ * }
209
+ * });
210
+ * ```
211
+ */
212
+ // Typed constructor to avoid leaking AbstractPowerSyncDatabase into the public interface
213
+ export const PowerSyncDatabase: PowerSyncDatabaseConstructor<WebPowerSyncDatabaseOptions> = WebPowerSyncDatabase;
214
+ export interface PowerSyncDatabase extends CommonPowerSyncDatabase {}
@@ -1,13 +1,5 @@
1
- import {
2
- ConnectionPool,
3
- DBAdapterDefaultMixin,
4
- DBAdapterListener,
5
- DBLockOptions,
6
- LockContext,
7
- Mutex,
8
- Semaphore,
9
- UnlockFn
10
- } from '@powersync/common';
1
+ import { DBAdapter, DBAdapterListener, DBLockOptions, LockContext } from '@powersync/common';
2
+ import { Mutex, Semaphore, UnlockFn } from '@powersync/shared-internals';
11
3
  import { SharedConnectionWorker, WebDBAdapter, WebDBAdapterConfiguration } from './WebDBAdapter.js';
12
4
  import { DatabaseClient } from './wa-sqlite/DatabaseClient.js';
13
5
 
@@ -16,7 +8,7 @@ type PendingListener = { listener: Partial<DBAdapterListener>; closeAfterRegiste
16
8
  /**
17
9
  * A connection pool implementation delegating to another pool opened asynchronnously.
18
10
  */
19
- class AsyncConnectionPool implements ConnectionPool {
11
+ export class AsyncDbAdapter extends DBAdapter {
20
12
  protected readonly state: Promise<PoolState>;
21
13
  protected resolvedWriter?: DatabaseClient;
22
14
 
@@ -26,6 +18,7 @@ class AsyncConnectionPool implements ConnectionPool {
26
18
  inner: Promise<PoolConnection>,
27
19
  readonly name: string
28
20
  ) {
21
+ super();
29
22
  this.state = inner.then((client) => {
30
23
  for (const pending of this.pendingListeners) {
31
24
  pending.closeAfterRegisteredOnResolvedPool = client.writer.registerListener(pending.listener);
@@ -81,6 +74,19 @@ class AsyncConnectionPool implements ConnectionPool {
81
74
  };
82
75
  }
83
76
  }
77
+
78
+ async shareConnection(): Promise<SharedConnectionWorker> {
79
+ const state = await this.state;
80
+ return state.writer.shareConnection();
81
+ }
82
+
83
+ getConfiguration(): WebDBAdapterConfiguration {
84
+ if (this.resolvedWriter) {
85
+ return this.resolvedWriter.getConfiguration();
86
+ }
87
+
88
+ throw new Error('AsyncDbAdapter.getConfiguration() can only be called after initializing it.');
89
+ }
84
90
  }
85
91
 
86
92
  export interface PoolConnection {
@@ -126,7 +132,7 @@ function readWritePoolState(writer: DatabaseClient, readers: DatabaseClient[]):
126
132
  let timeout: any = null;
127
133
  let release: UnlockFn | undefined;
128
134
  if (options?.timeoutMs) {
129
- timeout = setTimeout(() => abortController.abort, options.timeoutMs);
135
+ timeout = setTimeout(() => abortController.abort('requesting database timed out'), options.timeoutMs);
130
136
  }
131
137
 
132
138
  try {
@@ -190,18 +196,3 @@ function readWritePoolState(writer: DatabaseClient, readers: DatabaseClient[]):
190
196
  }
191
197
  };
192
198
  }
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
- }
@@ -1,17 +1,10 @@
1
- import {
2
- BaseObserver,
3
- DBAdapterListener,
4
- DBAdapter,
5
- DBLockOptions,
6
- LockContext,
7
- QueryResult,
8
- Transaction,
9
- Mutex,
10
- timeoutSignal
11
- } from '@powersync/common';
1
+ import { DBAdapter, DBLockOptions, LockContext, RawQueryResult } from '@powersync/common';
2
+ import { Mutex } from '@powersync/shared-internals';
12
3
 
13
- const MOCK_QUERY_RESPONSE: QueryResult = {
14
- rowsAffected: 0
4
+ const MOCK_QUERY_RESPONSE: RawQueryResult = {
5
+ rowsAffected: 0,
6
+ columnNames: [],
7
+ rawRows: []
15
8
  };
16
9
 
17
10
  /**
@@ -19,7 +12,7 @@ const MOCK_QUERY_RESPONSE: QueryResult = {
19
12
  * This adapter will return empty results for queries, which will allow
20
13
  * server rendered views to initially generate scaffolding components
21
14
  */
22
- export class SSRDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
15
+ export class SSRDBAdapter extends DBAdapter {
23
16
  name: string;
24
17
  readMutex: Mutex;
25
18
  writeMutex: Mutex;
@@ -34,61 +27,18 @@ export class SSRDBAdapter extends BaseObserver<DBAdapterListener> implements DBA
34
27
  close() {}
35
28
 
36
29
  async readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) {
37
- return this.readMutex.runExclusive(() => fn(this), timeoutSignal(options?.timeoutMs));
38
- }
39
-
40
- async readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) {
41
- return this.readLock(() => fn(this.generateMockTransactionContext()), options);
30
+ return fn(new StubLockContext());
42
31
  }
43
32
 
44
33
  async writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) {
45
- return this.writeMutex.runExclusive(() => fn(this), timeoutSignal(options?.timeoutMs));
46
- }
47
-
48
- async writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) {
49
- return this.writeLock(() => fn(this.generateMockTransactionContext()), options);
50
- }
51
-
52
- async execute(query: string, params?: any[]): Promise<QueryResult> {
53
- return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
54
- }
55
-
56
- async executeRaw(query: string, params?: any[]): Promise<any[][]> {
57
- return this.writeMutex.runExclusive(async () => []);
58
- }
59
-
60
- async executeBatch(query: string, params?: any[][]): Promise<QueryResult> {
61
- return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
34
+ return fn(new StubLockContext());
62
35
  }
63
36
 
64
- async getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
65
- return [];
66
- }
67
-
68
- async getOptional<T>(sql: string, parameters?: any[] | undefined): Promise<T | null> {
69
- return null;
70
- }
71
-
72
- async get<T>(sql: string, parameters?: any[] | undefined): Promise<T> {
73
- throw new Error(`No values are returned in SSR mode`);
74
- }
37
+ async refreshSchema(): Promise<void> {}
38
+ }
75
39
 
76
- /**
77
- * Generates a mock context for use in read/write transactions.
78
- * `this` already mocks most of the API, commit and rollback mocks
79
- * are added here
80
- */
81
- private generateMockTransactionContext(): Transaction {
82
- return {
83
- ...this,
84
- commit: async () => {
85
- return MOCK_QUERY_RESPONSE;
86
- },
87
- rollback: async () => {
88
- return MOCK_QUERY_RESPONSE;
89
- }
90
- };
40
+ class StubLockContext extends LockContext {
41
+ async executeRaw(): Promise<RawQueryResult> {
42
+ return MOCK_QUERY_RESPONSE;
91
43
  }
92
-
93
- async refreshSchema(): Promise<void> {}
94
44
  }
@@ -1,5 +1,5 @@
1
1
  import { DBAdapter } from '@powersync/common';
2
- import { ResolvedWebSQLOpenOptions } from './web-sql-flags.js';
2
+ import { ResolvedWebSQLOpenOptions } from './options.js';
3
3
 
4
4
  export type SharedConnectionWorker = {
5
5
  identifier: string;
@@ -0,0 +1,100 @@
1
+ import { LogLevels, SQLOpenOptions } from '@powersync/common';
2
+ import { WASQLiteVFS } from './wa-sqlite/vfs.js';
3
+
4
+ export interface WebSpecificOpenOptions {
5
+ /**
6
+ * SQLite operations are currently not supported in SSR mode.
7
+ * A warning will be logged if attempting to use SQLite in SSR.
8
+ * Setting this to `true` will disabled the warning above.
9
+ */
10
+ disableSSRWarning: boolean;
11
+
12
+ /**
13
+ * Enables multi tab support.
14
+ *
15
+ * Enabling multi-tab support will transparently make PowerSync manage the sync process in a shared worker collecting
16
+ * Sync Streams across tabs. Additionally, it enables a shared worker for IndexedDB databases.
17
+ *
18
+ * It is still valid to open multiple tabs when this option is disabled, but the experience may be degrated as only
19
+ * one tab can sync at the time.
20
+ *
21
+ * This is enabled by default on Desktop browsers if shared workers are enabled, except for Safari.
22
+ */
23
+ enableMultiTabs: boolean;
24
+
25
+ /**
26
+ * The SQLite connection is often executed through a web worker in order to offload computation and because some file
27
+ * system implementations (notably those based on web filesystem APIs like OPFS) are only available in workers.
28
+ *
29
+ * Manually disabling the use of web workers is not recommended, but can be useful for testing or for environments
30
+ * or toolchains where web workers are not supported.
31
+ */
32
+ useWebWorker: boolean;
33
+
34
+ /**
35
+ * Open in SSR placeholder mode. DB operations and Sync operations will be a No-op
36
+ */
37
+ ssrMode: boolean;
38
+
39
+ /**
40
+ * The log level for database workers.
41
+ *
42
+ * Defaults to {@link LogLevels.info}.
43
+ */
44
+ databaseWorkerLogLevel: number;
45
+
46
+ /**
47
+ * Where to store SQLite temporary files. Defaults to 'MEMORY'.
48
+ * Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
49
+ */
50
+ temporaryStorage: TemporaryStorageOption;
51
+
52
+ /**
53
+ * Maximum SQLite cache size. Defaults to 50MB.
54
+ *
55
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
56
+ */
57
+ cacheSizeKb: number;
58
+
59
+ /**
60
+ * Encryption key for the database.
61
+ * If set, the database will be encrypted using ChaCha20.
62
+ */
63
+ encryptionKey: string | undefined;
64
+
65
+ vfs: WASQLiteVFS;
66
+
67
+ /**
68
+ * If the {@link vfs} supports it, an additional amount of read-only connections to open. Using additional read
69
+ * connections can speed up queries by dispatching them to multiple workers running them concurrently.
70
+ *
71
+ * {@link WASQLiteVFS.OPFSWriteAheadVFS} is the only VFS with support for multiple connections, so this option is
72
+ * ignored for other VFS implementations.
73
+ *
74
+ * Defaults to 1.
75
+ */
76
+ additionalReaders: number;
77
+
78
+ /**
79
+ * Allows you to override the default wasqlite db worker.
80
+ *
81
+ * You can either provide a path to the worker script
82
+ * or a factory method that returns a worker.
83
+ */
84
+ worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => Worker | SharedWorker);
85
+
86
+ /**
87
+ * Use an existing port to an initialized worker.
88
+ * A worker will be initialized if none is provided
89
+ */
90
+ workerPort?: MessagePort | undefined;
91
+ }
92
+
93
+ export interface ResolvedWebSQLOpenOptions extends SQLOpenOptions, WebSpecificOpenOptions {}
94
+
95
+ export interface WebSQLOpenOptions extends SQLOpenOptions, Partial<WebSpecificOpenOptions> {}
96
+
97
+ export enum TemporaryStorageOption {
98
+ MEMORY = 'memory',
99
+ FILESYSTEM = 'file'
100
+ }
@@ -0,0 +1,49 @@
1
+ import { LogLevels } from '@powersync/common';
2
+ import { TemporaryStorageOption, WebSpecificOpenOptions } from './options.js';
3
+ import { vfsRequiresDedicatedWorkers, WASQLiteVFS } from './wa-sqlite/vfs.js';
4
+
5
+ /**
6
+ * The maximum length of a db filename we support.
7
+ *
8
+ * We configure the same on WA-SQLite (which otherwise defaults to a maximum length of 64). We don't want to support
9
+ * very long path names as Safari maps OPFS files directly to OS files, and APFS has a 255-byte filename limit. Since
10
+ * some VFS append additional characters for pooled file access handles, we want to stay well below that.
11
+ */
12
+ export const maxPathNameLength = 128;
13
+
14
+ /**
15
+ * @internal
16
+ */
17
+ export function resolveAndValidateOptions<And = {}>(
18
+ options: Partial<WebSpecificOpenOptions> & And
19
+ ): WebSpecificOpenOptions & And {
20
+ const defaults: WebSpecificOpenOptions = {
21
+ disableSSRWarning: false,
22
+ ssrMode: !('window' in globalThis),
23
+ /**
24
+ * Multiple tabs are by default not supported on Android, iOS and Safari.
25
+ * Other platforms will have multiple tabs enabled by default.
26
+ */
27
+ enableMultiTabs:
28
+ typeof globalThis.navigator !== 'undefined' && // For SSR purposes
29
+ typeof SharedWorker !== 'undefined' &&
30
+ !navigator.userAgent.match(/(Android|iPhone|iPod|iPad)/i) &&
31
+ !(window as any).safari,
32
+ useWebWorker: true,
33
+ databaseWorkerLogLevel: LogLevels.info,
34
+ temporaryStorage: TemporaryStorageOption.MEMORY,
35
+ cacheSizeKb: 50 * 1024,
36
+ encryptionKey: undefined,
37
+ vfs: WASQLiteVFS.IDBBatchAtomicVFS,
38
+ additionalReaders: 1
39
+ };
40
+
41
+ const resolved = Object.assign(defaults, options);
42
+ if (vfsRequiresDedicatedWorkers(resolved.vfs) && !resolved.useWebWorker) {
43
+ throw new Error(
44
+ `Invalid configuration: The 'useWebWorker' flag must be true when using an OPFS-based VFS (${resolved.vfs}).`
45
+ );
46
+ }
47
+
48
+ return resolved;
49
+ }
@@ -1,6 +1,5 @@
1
- import { Mutex, UnlockFn } from '@powersync/common';
2
- import { RawSqliteConnection } from './RawSqliteConnection.js';
3
- import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
1
+ import { Mutex, UnlockFn } from '@powersync/shared-internals';
2
+ import { RawSqliteConnection, RawWaSqliteDatabaseOptions } from './RawSqliteConnection.js';
4
3
 
5
4
  /**
6
5
  * A wrapper around a {@link RawSqliteConnection} allowing multiple tabs to access it.
@@ -33,7 +32,7 @@ export class ConcurrentSqliteConnection {
33
32
  this.leaseMutex = needsNavigatorLocks ? null : new Mutex();
34
33
  }
35
34
 
36
- get options(): ResolvedWASQLiteOpenFactoryOptions {
35
+ get options(): RawWaSqliteDatabaseOptions {
37
36
  return this.inner.options;
38
37
  }
39
38
 
@@ -46,7 +45,7 @@ export class ConcurrentSqliteConnection {
46
45
  const options: LockOptions = { signal: abort };
47
46
 
48
47
  navigator.locks
49
- .request(`db-lock-${this.options.dbFilename}`, options, (_) => {
48
+ .request(`db-lock-${this.options.filename}`, options, (_) => {
50
49
  return new Promise<void>((returnLock) => {
51
50
  return resolve(() => {
52
51
  returnLock();