@powersync/web 0.0.0-dev-20260630141119 → 0.0.0-dev-20260708103617

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/bin/powersync.cjs +1 -1
  2. package/dist/index.umd.js +7821 -0
  3. package/dist/index.umd.js.map +1 -0
  4. package/dist/worker/SharedSyncImplementation.umd.js +16139 -0
  5. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -0
  6. package/dist/worker/WASQLiteDB.umd.js +17434 -0
  7. package/dist/worker/WASQLiteDB.umd.js.map +1 -0
  8. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +31 -0
  9. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js.map +1 -0
  10. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +31 -0
  11. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js.map +1 -0
  12. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +31 -0
  13. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +1 -0
  14. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +31 -0
  15. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
  16. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +3562 -0
  17. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +1 -0
  18. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
  19. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
  20. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +2478 -0
  21. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +1 -0
  22. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +1681 -0
  23. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +1 -0
  24. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +1820 -0
  25. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +1 -0
  26. package/lib/package.json +91 -0
  27. package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +1 -0
  28. package/lib/{db → src/db}/NavigatorTriggerClaimManager.d.ts +1 -1
  29. package/lib/src/db/NavigatorTriggerClaimManager.js.map +1 -0
  30. package/lib/src/db/PowerSyncDatabase.d.ts +78 -0
  31. package/lib/{db → src/db}/PowerSyncDatabase.js +61 -47
  32. package/lib/src/db/PowerSyncDatabase.js.map +1 -0
  33. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +23 -0
  34. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +27 -0
  35. package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +1 -0
  36. package/lib/src/db/adapters/AsyncWebAdapter.d.ts +50 -0
  37. package/lib/{db → src/db}/adapters/AsyncWebAdapter.js +14 -14
  38. package/lib/src/db/adapters/AsyncWebAdapter.js.map +1 -0
  39. package/lib/src/db/adapters/SSRDBAdapter.d.ts +30 -0
  40. package/lib/src/db/adapters/SSRDBAdapter.js +69 -0
  41. package/lib/src/db/adapters/SSRDBAdapter.js.map +1 -0
  42. package/lib/{db → src/db}/adapters/WebDBAdapter.d.ts +1 -1
  43. package/lib/src/db/adapters/WebDBAdapter.js.map +1 -0
  44. package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +4 -3
  45. package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
  46. package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
  47. package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
  48. package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.js +37 -11
  49. package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
  50. package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
  51. package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.js +7 -11
  52. package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
  53. package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +12 -23
  54. package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.js +11 -17
  55. package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
  56. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +45 -0
  57. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +146 -0
  58. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
  59. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +15 -0
  60. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +22 -0
  61. package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +1 -0
  62. package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +40 -0
  63. package/lib/src/db/adapters/wa-sqlite/vfs.js +95 -0
  64. package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -0
  65. package/lib/src/db/adapters/web-sql-flags.d.ts +92 -0
  66. package/lib/src/db/adapters/web-sql-flags.js +37 -0
  67. package/lib/src/db/adapters/web-sql-flags.js.map +1 -0
  68. package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.d.ts +8 -4
  69. package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.js +11 -4
  70. package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
  71. package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.d.ts +14 -13
  72. package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.js +66 -31
  73. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
  74. package/lib/src/db/sync/WebRemote.d.ts +7 -0
  75. package/lib/src/db/sync/WebRemote.js +33 -0
  76. package/lib/src/db/sync/WebRemote.js.map +1 -0
  77. package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.d.ts +4 -2
  78. package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.js +2 -3
  79. package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +1 -0
  80. package/lib/src/db/sync/userAgent.js.map +1 -0
  81. package/lib/{index.d.ts → src/index.d.ts} +3 -1
  82. package/lib/{index.js → src/index.js} +3 -1
  83. package/lib/src/index.js.map +1 -0
  84. package/lib/src/shared/navigator.js.map +1 -0
  85. package/lib/src/shared/tab_close_signal.js.map +1 -0
  86. package/lib/src/worker/db/MultiDatabaseServer.d.ts +17 -0
  87. package/lib/{worker → src/worker}/db/MultiDatabaseServer.js +18 -26
  88. package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -0
  89. package/lib/src/worker/db/WASQLiteDB.worker.d.ts +4 -0
  90. package/lib/src/worker/db/WASQLiteDB.worker.js +31 -0
  91. package/lib/src/worker/db/WASQLiteDB.worker.js.map +1 -0
  92. package/lib/src/worker/db/open-worker-database.d.ts +14 -0
  93. package/lib/src/worker/db/open-worker-database.js +53 -0
  94. package/lib/src/worker/db/open-worker-database.js.map +1 -0
  95. package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +19 -0
  96. package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
  97. package/lib/src/worker/sync/BroadcastLogger.d.ts +47 -0
  98. package/lib/src/worker/sync/BroadcastLogger.js +129 -0
  99. package/lib/src/worker/sync/BroadcastLogger.js.map +1 -0
  100. package/lib/{worker → src/worker}/sync/SharedSyncImplementation.d.ts +15 -11
  101. package/lib/{worker → src/worker}/sync/SharedSyncImplementation.js +43 -42
  102. package/lib/src/worker/sync/SharedSyncImplementation.js.map +1 -0
  103. package/lib/src/worker/sync/SharedSyncImplementation.worker.js +12 -0
  104. package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +1 -0
  105. package/lib/{worker → src/worker}/sync/WorkerClient.d.ts +3 -3
  106. package/lib/{worker → src/worker}/sync/WorkerClient.js +2 -2
  107. package/lib/src/worker/sync/WorkerClient.js.map +1 -0
  108. package/lib/tsconfig.tsbuildinfo +1 -0
  109. package/package.json +29 -22
  110. package/src/db/NavigatorTriggerClaimManager.ts +1 -1
  111. package/src/db/PowerSyncDatabase.ts +122 -80
  112. package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +47 -0
  113. package/src/db/adapters/AsyncWebAdapter.ts +26 -17
  114. package/src/db/adapters/SSRDBAdapter.ts +64 -14
  115. package/src/db/adapters/WebDBAdapter.ts +1 -1
  116. package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +5 -4
  117. package/src/db/adapters/wa-sqlite/DatabaseClient.ts +56 -20
  118. package/src/db/adapters/wa-sqlite/DatabaseServer.ts +12 -15
  119. package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +24 -41
  120. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +126 -63
  121. package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +24 -0
  122. package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
  123. package/src/db/adapters/web-sql-flags.ts +141 -0
  124. package/src/db/sync/SSRWebStreamingSyncImplementation.ts +22 -4
  125. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +77 -38
  126. package/src/db/sync/WebRemote.ts +26 -23
  127. package/src/db/sync/WebStreamingSyncImplementation.ts +5 -4
  128. package/src/index.ts +3 -1
  129. package/src/worker/db/MultiDatabaseServer.ts +25 -41
  130. package/src/worker/db/WASQLiteDB.worker.ts +35 -0
  131. package/src/worker/db/open-worker-database.ts +62 -0
  132. package/src/worker/sync/AbstractSharedSyncClientProvider.ts +10 -4
  133. package/src/worker/sync/BroadcastLogger.ts +103 -35
  134. package/src/worker/sync/SharedSyncImplementation.ts +63 -62
  135. package/src/worker/sync/SharedSyncImplementation.worker.ts +14 -0
  136. package/src/worker/sync/WorkerClient.ts +4 -4
  137. package/dist/index.react_native_web.js +0 -1879
  138. package/dist/index.react_native_web.js.map +0 -1
  139. package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +0 -2
  140. package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +0 -1
  141. package/dist/worker/FacadeVFS-d1ZDvud7.js +0 -2
  142. package/dist/worker/FacadeVFS-d1ZDvud7.js.map +0 -1
  143. package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +0 -2
  144. package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +0 -1
  145. package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js +0 -2
  146. package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js.map +0 -1
  147. package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +0 -2
  148. package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +0 -1
  149. package/dist/worker/mc-wa-sqlite-DiBqIVE5.js +0 -2
  150. package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +0 -1
  151. package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +0 -2
  152. package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +0 -1
  153. package/dist/worker/wa-sqlite-BlSx7-_P.js +0 -2
  154. package/dist/worker/wa-sqlite-BlSx7-_P.js.map +0 -1
  155. package/dist/worker/wa-sqlite-async-BdR24Ucf.js +0 -2
  156. package/dist/worker/wa-sqlite-async-BdR24Ucf.js.map +0 -1
  157. package/dist/worker/websockets-Q8W_lerF.js +0 -9
  158. package/dist/worker/websockets-Q8W_lerF.js.map +0 -1
  159. package/dist/worker/worker.js +0 -7
  160. package/dist/worker/worker.js.map +0 -1
  161. package/lib/attachments/IndexDBFileSystemAdapter.js.map +0 -1
  162. package/lib/db/NavigatorTriggerClaimManager.js.map +0 -1
  163. package/lib/db/PowerSyncDatabase.d.ts +0 -67
  164. package/lib/db/PowerSyncDatabase.js.map +0 -1
  165. package/lib/db/adapters/AsyncWebAdapter.d.ts +0 -32
  166. package/lib/db/adapters/AsyncWebAdapter.js.map +0 -1
  167. package/lib/db/adapters/SSRDBAdapter.d.ts +0 -17
  168. package/lib/db/adapters/SSRDBAdapter.js +0 -37
  169. package/lib/db/adapters/SSRDBAdapter.js.map +0 -1
  170. package/lib/db/adapters/WebDBAdapter.js.map +0 -1
  171. package/lib/db/adapters/options.d.ts +0 -87
  172. package/lib/db/adapters/options.js +0 -6
  173. package/lib/db/adapters/options.js.map +0 -1
  174. package/lib/db/adapters/resolveAndValidateOptions.d.ts +0 -5
  175. package/lib/db/adapters/resolveAndValidateOptions.js +0 -33
  176. package/lib/db/adapters/resolveAndValidateOptions.js.map +0 -1
  177. package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
  178. package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
  179. package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
  180. package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
  181. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -18
  182. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -131
  183. package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
  184. package/lib/db/adapters/wa-sqlite/vfs.d.ts +0 -50
  185. package/lib/db/adapters/wa-sqlite/vfs.js +0 -77
  186. package/lib/db/adapters/wa-sqlite/vfs.js.map +0 -1
  187. package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
  188. package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
  189. package/lib/db/sync/WebRemote.d.ts +0 -10
  190. package/lib/db/sync/WebRemote.js +0 -33
  191. package/lib/db/sync/WebRemote.js.map +0 -1
  192. package/lib/db/sync/WebStreamingSyncImplementation.js.map +0 -1
  193. package/lib/db/sync/userAgent.js.map +0 -1
  194. package/lib/index.js.map +0 -1
  195. package/lib/shared/navigator.js.map +0 -1
  196. package/lib/shared/tab_close_signal.js.map +0 -1
  197. package/lib/worker/SharedWorkerConnectionRequest.d.ts +0 -5
  198. package/lib/worker/SharedWorkerConnectionRequest.js +0 -2
  199. package/lib/worker/SharedWorkerConnectionRequest.js.map +0 -1
  200. package/lib/worker/client.d.ts +0 -15
  201. package/lib/worker/client.js +0 -77
  202. package/lib/worker/client.js.map +0 -1
  203. package/lib/worker/db/MultiDatabaseServer.d.ts +0 -22
  204. package/lib/worker/db/MultiDatabaseServer.js.map +0 -1
  205. package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -13
  206. package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
  207. package/lib/worker/sync/BroadcastLogger.d.ts +0 -27
  208. package/lib/worker/sync/BroadcastLogger.js +0 -65
  209. package/lib/worker/sync/BroadcastLogger.js.map +0 -1
  210. package/lib/worker/sync/SharedSyncImplementation.js.map +0 -1
  211. package/lib/worker/sync/WorkerClient.js.map +0 -1
  212. package/lib/worker/worker.js +0 -34
  213. package/lib/worker/worker.js.map +0 -1
  214. package/src/db/adapters/options.ts +0 -100
  215. package/src/db/adapters/resolveAndValidateOptions.ts +0 -40
  216. package/src/worker/SharedWorkerConnectionRequest.ts +0 -6
  217. package/src/worker/client.ts +0 -100
  218. package/src/worker/worker.ts +0 -38
  219. /package/dist/{worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm → 2075a31bb151adbb9767.wasm} +0 -0
  220. /package/dist/{worker/assets/wa-sqlite-XZW__iJk.wasm → 3322bc84de986b63c2cd.wasm} +0 -0
  221. /package/dist/{worker/assets/mc-wa-sqlite-CnHbhWvs.wasm → 8e97452e297be23b5e50.wasm} +0 -0
  222. /package/dist/{worker/assets/wa-sqlite-async-rHzzC98y.wasm → fbc178b70d530e8ce02b.wasm} +0 -0
  223. /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
  224. /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.js +0 -0
  225. /package/lib/{db → src/db}/NavigatorTriggerClaimManager.js +0 -0
  226. /package/lib/{db → src/db}/adapters/WebDBAdapter.js +0 -0
  227. /package/lib/{db → src/db}/sync/userAgent.d.ts +0 -0
  228. /package/lib/{db → src/db}/sync/userAgent.js +0 -0
  229. /package/lib/{shared → src/shared}/navigator.d.ts +0 -0
  230. /package/lib/{shared → src/shared}/navigator.js +0 -0
  231. /package/lib/{shared → src/shared}/tab_close_signal.d.ts +0 -0
  232. /package/lib/{shared → src/shared}/tab_close_signal.js +0 -0
  233. /package/lib/{worker → src/worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
  234. /package/lib/{worker/worker.d.ts → src/worker/sync/SharedSyncImplementation.worker.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js","mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/sBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;AC7NA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":["webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/FacadeVFS.js","webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/VFS.js","webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"],"sourcesContent":["// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport * as VFS from './VFS.js';\n\nconst AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;\n\n// Milliseconds since Julian epoch as a BigInt.\n// https://github.com/sqlite/sqlite/blob/e57527c14f7b7cfa6e32eeab5c549d50c4fa3674/src/os_unix.c#L6872-L6882\nconst UNIX_EPOCH = 24405875n * 8640000n;\n\n// Convenience base class for a JavaScript VFS.\n// The raw xOpen, xRead, etc. function signatures receive only C primitives\n// which aren't easy to work with. This class provides corresponding calls\n// like jOpen, jRead, etc., which receive JavaScript-friendlier arguments\n// such as string, Uint8Array, and DataView.\nexport class FacadeVFS extends VFS.Base {\n /**\n * @param {string} name \n * @param {object} module \n */\n constructor(name, module) {\n super(name, module);\n }\n\n /**\n * Override to indicate which methods are asynchronous.\n * @param {string} methodName \n * @returns {boolean}\n */\n hasAsyncMethod(methodName) {\n // The input argument is a string like \"xOpen\", so convert to \"jOpen\".\n // Then check if the method exists and is async.\n const jMethodName = `j${methodName.slice(1)}`;\n return this[jMethodName] instanceof AsyncFunction;\n }\n \n /**\n * Return the filename for a file id for use by mixins.\n * @param {number} pFile \n * @returns {string}\n */\n getFilename(pFile) {\n throw new Error('unimplemented');\n }\n\n /**\n * @param {string?} filename \n * @param {number} pFile \n * @param {number} flags \n * @param {DataView} pOutFlags \n * @returns {number|Promise<number>}\n */\n jOpen(filename, pFile, flags, pOutFlags) {\n return VFS.SQLITE_CANTOPEN;\n }\n\n /**\n * @param {string} filename \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n jDelete(filename, syncDir) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} filename \n * @param {number} flags \n * @param {DataView} pResOut \n * @returns {number|Promise<number>}\n */\n jAccess(filename, flags, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} filename \n * @param {Uint8Array} zOut \n * @returns {number|Promise<number>}\n */\n jFullPathname(filename, zOut) {\n // Copy the filename to the output buffer.\n const { read, written } = new TextEncoder().encodeInto(filename, zOut);\n if (read < filename.length) return VFS.SQLITE_IOERR;\n if (written >= zOut.length) return VFS.SQLITE_IOERR;\n zOut[written] = 0;\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {Uint8Array} zBuf \n * @returns {number|Promise<number>}\n */\n jGetLastError(zBuf) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n jClose(pFile) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {Uint8Array} pData \n * @param {number} iOffset \n * @returns {number|Promise<number>}\n */\n jRead(pFile, pData, iOffset) {\n pData.fill(0);\n return VFS.SQLITE_IOERR_SHORT_READ;\n }\n\n /**\n * @param {number} pFile \n * @param {Uint8Array} pData \n * @param {number} iOffset \n * @returns {number|Promise<number>}\n */\n jWrite(pFile, pData, iOffset) {\n return VFS.SQLITE_IOERR_WRITE;\n }\n\n /**\n * @param {number} pFile \n * @param {number} size \n * @returns {number|Promise<number>}\n */\n jTruncate(pFile, size) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n jSync(pFile, flags) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {DataView} pSize\n * @returns {number|Promise<number>}\n */\n jFileSize(pFile, pSize) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n jLock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n jUnlock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {DataView} pResOut \n * @returns {number|Promise<number>}\n */\n jCheckReservedLock(pFile, pResOut) {\n pResOut.setInt32(0, 0, true);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile\n * @param {number} op\n * @param {DataView} pArg\n * @returns {number|Promise<number>}\n */\n jFileControl(pFile, op, pArg) {\n return VFS.SQLITE_NOTFOUND;\n }\n\n /**\n * @param {number} pFile\n * @returns {number|Promise<number>}\n */\n jSectorSize(pFile) {\n return super.xSectorSize(pFile);\n }\n\n /**\n * @param {number} pFile\n * @returns {number|Promise<number>}\n */\n jDeviceCharacteristics(pFile) {\n return 0;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} pFile \n * @param {number} flags \n * @param {number} pOutFlags \n * @returns {number|Promise<number>}\n */\n xOpen(pVfs, zName, pFile, flags, pOutFlags) {\n const filename = this.#decodeFilename(zName, flags);\n const pOutFlagsView = this.#makeTypedDataView('Int32', pOutFlags);\n this['log']?.('jOpen', filename, pFile, '0x' + flags.toString(16));\n return this.jOpen(filename, pFile, flags, pOutFlagsView);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nByte \n * @param {number} pCharOut\n * @returns {number|Promise<number>}\n */\n xRandomness(pVfs, nByte, pCharOut) {\n const randomArray = new Uint8Array(nByte);\n crypto.getRandomValues(randomArray);\n // Copy randomArray to the WebAssembly memory\n const buffer = pCharOut; // Pointer to memory in WebAssembly\n this._module.HEAPU8.set(randomArray, buffer); // Copy randomArray into memory starting at buffer\n return nByte;\n }\n\n /**\n * Gets the current time as milliseconds since Unix epoch\n * @param {number} pVfs pointer to the VFS\n * @param {number} pTime pointer to write the time value\n * @returns {number} SQLite error code\n */\n xCurrentTimeInt64(pVfs, pTime) {\n // Create a DataView to write the current time\n const timeView = this.#makeTypedDataView('BigInt64', pTime);\n \n const currentTime = BigInt(Date.now());\n // Convert the current time to milliseconds since Unix epoch\n const value = UNIX_EPOCH + currentTime;\n \n // Write the time value to the pointer location\n timeView.setBigInt64(0, value, true);\n \n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n xDelete(pVfs, zName, syncDir) {\n const filename = this._module.UTF8ToString(zName);\n this['log']?.('jDelete', filename, syncDir);\n return this.jDelete(filename, syncDir);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} flags \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xAccess(pVfs, zName, flags, pResOut) {\n const filename = this._module.UTF8ToString(zName);\n const pResOutView = this.#makeTypedDataView('Int32', pResOut);\n this['log']?.('jAccess', filename, flags);\n return this.jAccess(filename, flags, pResOutView);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} nOut \n * @param {number} zOut \n * @returns {number|Promise<number>}\n */\n xFullPathname(pVfs, zName, nOut, zOut) {\n const filename = this._module.UTF8ToString(zName);\n const zOutArray = this._module.HEAPU8.subarray(zOut, zOut + nOut);\n this['log']?.('jFullPathname', filename, nOut);\n return this.jFullPathname(filename, zOutArray);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nBuf \n * @param {number} zBuf \n * @returns {number|Promise<number>}\n */\n xGetLastError(pVfs, nBuf, zBuf) {\n const zBufArray = this._module.HEAPU8.subarray(zBuf, zBuf + nBuf);\n this['log']?.('jGetLastError', nBuf);\n return this.jGetLastError(zBufArray);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xClose(pFile) {\n this['log']?.('jClose', pFile);\n return this.jClose(pFile);\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xRead(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n const pDataArray = this.#makeDataArray(pData, iAmt);\n const iOffset = delegalize(iOffsetLo, iOffsetHi);\n this['log']?.('jRead', pFile, iAmt, iOffset);\n return this.jRead(pFile, pDataArray, iOffset);\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xWrite(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n const pDataArray = this.#makeDataArray(pData, iAmt);\n const iOffset = delegalize(iOffsetLo, iOffsetHi);\n this['log']?.('jWrite', pFile, pDataArray, iOffset);\n return this.jWrite(pFile, pDataArray, iOffset);\n }\n\n /**\n * @param {number} pFile \n * @param {number} sizeLo \n * @param {number} sizeHi \n * @returns {number|Promise<number>}\n */\n xTruncate(pFile, sizeLo, sizeHi) {\n const size = delegalize(sizeLo, sizeHi);\n this['log']?.('jTruncate', pFile, size);\n return this.jTruncate(pFile, size);\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n xSync(pFile, flags) {\n this['log']?.('jSync', pFile, flags);\n return this.jSync(pFile, flags);\n }\n\n /**\n * \n * @param {number} pFile \n * @param {number} pSize \n * @returns {number|Promise<number>}\n */\n xFileSize(pFile, pSize) {\n const pSizeView = this.#makeTypedDataView('BigInt64', pSize);\n this['log']?.('jFileSize', pFile);\n return this.jFileSize(pFile, pSizeView);\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xLock(pFile, lockType) {\n this['log']?.('jLock', pFile, lockType);\n return this.jLock(pFile, lockType);\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xUnlock(pFile, lockType) {\n this['log']?.('jUnlock', pFile, lockType);\n return this.jUnlock(pFile, lockType);\n } \n\n /**\n * @param {number} pFile \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xCheckReservedLock(pFile, pResOut) {\n const pResOutView = this.#makeTypedDataView('Int32', pResOut);\n this['log']?.('jCheckReservedLock', pFile);\n return this.jCheckReservedLock(pFile, pResOutView);\n }\n\n /**\n * @param {number} pFile \n * @param {number} op \n * @param {number} pArg \n * @returns {number|Promise<number>}\n */\n xFileControl(pFile, op, pArg) {\n const pArgView = new DataView(\n this._module.HEAPU8.buffer,\n this._module.HEAPU8.byteOffset + pArg);\n this['log']?.('jFileControl', pFile, op, pArgView);\n return this.jFileControl(pFile, op, pArgView);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xSectorSize(pFile) {\n this['log']?.('jSectorSize', pFile);\n return this.jSectorSize(pFile);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xDeviceCharacteristics(pFile) {\n this['log']?.('jDeviceCharacteristics', pFile);\n return this.jDeviceCharacteristics(pFile);\n }\n\n /**\n * Wrapped DataView for pointer arguments.\n * Pointers to a single value are passed using a DataView-like class.\n * This wrapper class prevents use of incorrect type or endianness, and\n * reacquires the underlying buffer when the WebAssembly memory is resized.\n * @param {'Int32'|'BigInt64'} type \n * @param {number} byteOffset \n * @returns {DataView}\n */\n #makeTypedDataView(type, byteOffset) {\n // @ts-ignore\n return new DataViewProxy(this._module, byteOffset, type);\n }\n\n /**\n * Wrapped Uint8Array for buffer arguments.\n * Memory blocks are passed as a Uint8Array-like class. This wrapper\n * class reacquires the underlying buffer when the WebAssembly memory\n * is resized.\n * @param {number} byteOffset \n * @param {number} byteLength \n * @returns {Uint8Array}\n */\n #makeDataArray(byteOffset, byteLength) {\n // @ts-ignore\n return new Uint8ArrayProxy(this._module, byteOffset, byteLength);\n }\n\n #decodeFilename(zName, flags) {\n if (flags & VFS.SQLITE_OPEN_URI) {\n // The first null-terminated string is the URI path. Subsequent\n // strings are query parameter keys and values.\n // https://www.sqlite.org/c3ref/open.html#urifilenamesinsqlite3open\n let pName = zName;\n let state = 1;\n const charCodes = [];\n while (state) {\n const charCode = this._module.HEAPU8[pName++];\n if (charCode) {\n charCodes.push(charCode);\n } else {\n if (!this._module.HEAPU8[pName]) state = null;\n switch (state) {\n case 1: // path\n charCodes.push('?'.charCodeAt(0));\n state = 2;\n break;\n case 2: // key\n charCodes.push('='.charCodeAt(0));\n state = 3;\n break;\n case 3: // value\n charCodes.push('&'.charCodeAt(0));\n state = 2;\n break;\n }\n }\n }\n return new TextDecoder().decode(new Uint8Array(charCodes));\n }\n return zName ? this._module.UTF8ToString(zName) : null;\n }\n}\n\n// Emscripten \"legalizes\" 64-bit integer arguments by passing them as\n// two 32-bit signed integers.\nfunction delegalize(lo32, hi32) {\n return (hi32 * 0x100000000) + lo32 + (lo32 < 0 ? 2**32 : 0);\n}\n\n// This class provides a Uint8Array-like interface for a WebAssembly memory\n// buffer. It is used to access memory blocks passed as arguments to\n// xRead, xWrite, etc. The class reacquires the underlying buffer when the\n// WebAssembly memory is resized, which can happen when the memory is\n// detached and resized by the WebAssembly module.\n//\n// Note that although this class implements the same methods as Uint8Array,\n// it is not a real Uint8Array and passing it to functions that expect\n// a Uint8Array may not work. Use subarray() to get a real Uint8Array\n// if needed.\nclass Uint8ArrayProxy {\n #module;\n\n #_array = new Uint8Array()\n get #array() {\n if (this.#_array.buffer.byteLength === 0) {\n // WebAssembly memory resize detached the buffer so re-create the\n // array with the new buffer.\n this.#_array = this.#module.HEAPU8.subarray(\n this.byteOffset,\n this.byteOffset + this.byteLength);\n }\n return this.#_array;\n }\n\n /**\n * @param {*} module\n * @param {number} byteOffset \n * @param {number} byteLength \n */\n constructor(module, byteOffset, byteLength) {\n this.#module = module;\n this.byteOffset = byteOffset;\n this.length = this.byteLength = byteLength;\n }\n\n get buffer() {\n return this.#array.buffer;\n }\n\n at(index) {\n return this.#array.at(index);\n }\n copyWithin(target, start, end) {\n this.#array.copyWithin(target, start, end);\n }\n entries() {\n return this.#array.entries();\n }\n every(predicate) {\n return this.#array.every(predicate);\n }\n fill(value, start, end) {\n this.#array.fill(value, start, end);\n }\n filter(predicate) {\n return this.#array.filter(predicate);\n }\n find(predicate) {\n return this.#array.find(predicate);\n }\n findIndex(predicate) {\n return this.#array.findIndex(predicate);\n }\n findLast(predicate) {\n return this.#array.findLast(predicate);\n }\n findLastIndex(predicate) {\n return this.#array.findLastIndex(predicate);\n }\n forEach(callback) {\n this.#array.forEach(callback);\n }\n includes(value, start) {\n return this.#array.includes(value, start);\n }\n indexOf(value, start) {\n return this.#array.indexOf(value, start);\n }\n join(separator) {\n return this.#array.join(separator);\n }\n keys() {\n return this.#array.keys();\n }\n lastIndexOf(value, start) {\n return this.#array.lastIndexOf(value, start);\n }\n map(callback) {\n return this.#array.map(callback);\n }\n reduce(callback, initialValue) {\n return this.#array.reduce(callback, initialValue);\n }\n reduceRight(callback, initialValue) {\n return this.#array.reduceRight(callback, initialValue);\n }\n reverse() {\n this.#array.reverse();\n }\n set(array, offset) {\n this.#array.set(array, offset);\n }\n slice(start, end) {\n return this.#array.slice(start, end);\n }\n some(predicate) {\n return this.#array.some(predicate);\n }\n sort(compareFn) {\n this.#array.sort(compareFn);\n }\n subarray(begin, end) {\n return this.#array.subarray(begin, end);\n }\n toLocaleString(locales, options) {\n // @ts-ignore\n return this.#array.toLocaleString(locales, options);\n }\n toReversed() {\n return this.#array.toReversed();\n }\n toSorted(compareFn) {\n return this.#array.toSorted(compareFn);\n }\n toString() {\n return this.#array.toString();\n }\n values() {\n return this.#array.values();\n }\n with(index, value) {\n return this.#array.with(index, value);\n }\n [Symbol.iterator]() {\n return this.#array[Symbol.iterator]();\n }\n}\n\n// This class provides a DataView-like interface for a WebAssembly memory\n// buffer, restricted to either Int32 or BigInt64 types. It also reacquires\n// the underlying buffer when the WebAssembly memory is resized, which can\n// happen when the memory is detached and resized by the WebAssembly module.\nclass DataViewProxy {\n #module;\n #type;\n\n #_view = new DataView(new ArrayBuffer(0));\n get #view() {\n if (this.#_view.buffer.byteLength === 0) {\n // WebAssembly memory resize detached the buffer so re-create the\n // view with the new buffer.\n this.#_view = new DataView(\n this.#module.HEAPU8.buffer,\n this.#module.HEAPU8.byteOffset + this.byteOffset);\n }\n return this.#_view;\n }\n\n /**\n * @param {*} module\n * @param {number} byteOffset \n * @param {'Int32'|'BigInt64'} type\n */\n constructor(module, byteOffset, type) {\n this.#module = module;\n this.byteOffset = byteOffset;\n this.#type = type;\n }\n\n get buffer() {\n return this.#view.buffer;\n }\n get byteLength() {\n return this.#type === 'Int32' ? 4 : 8;\n }\n\n getInt32(byteOffset, littleEndian) {\n if (this.#type !== 'Int32') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n return this.#view.getInt32(byteOffset, littleEndian);\n }\n setInt32(byteOffset, value, littleEndian) {\n if (this.#type !== 'Int32') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n this.#view.setInt32(byteOffset, value, littleEndian);\n }\n getBigInt64(byteOffset, littleEndian) {\n if (this.#type !== 'BigInt64') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n return this.#view.getBigInt64(byteOffset, littleEndian);\n }\n setBigInt64(byteOffset, value, littleEndian) {\n if (this.#type !== 'BigInt64') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n this.#view.setBigInt64(byteOffset, value, littleEndian);\n }\n}","// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport * as VFS from './sqlite-constants.js';\nexport * from './sqlite-constants.js';\n\nconst DEFAULT_SECTOR_SIZE = 512;\n\n// Base class for a VFS.\nexport class Base {\n name;\n mxPathname = 64;\n _module;\n\n /**\n * @param {string} name \n * @param {object} module \n */\n constructor(name, module) {\n this.name = name;\n this._module = module;\n }\n\n /**\n * @returns {void|Promise<void>} \n */\n close() {\n }\n\n /**\n * @returns {boolean|Promise<boolean>}\n */\n isReady() {\n return true;\n }\n\n /**\n * Overload in subclasses to indicate which methods are asynchronous.\n * @param {string} methodName \n * @returns {boolean}\n */\n hasAsyncMethod(methodName) {\n return false;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} pFile \n * @param {number} flags \n * @param {number} pOutFlags \n * @returns {number|Promise<number>}\n */\n xOpen(pVfs, zName, pFile, flags, pOutFlags) {\n return VFS.SQLITE_CANTOPEN;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n xDelete(pVfs, zName, syncDir) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} flags \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xAccess(pVfs, zName, flags, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} nOut \n * @param {number} zOut \n * @returns {number|Promise<number>}\n */\n xFullPathname(pVfs, zName, nOut, zOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nBuf \n * @param {number} zBuf \n * @returns {number|Promise<number>}\n */\n xGetLastError(pVfs, nBuf, zBuf) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xClose(pFile) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xRead(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xWrite(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} sizeLo \n * @param {number} sizeHi \n * @returns {number|Promise<number>}\n */\n xTruncate(pFile, sizeLo, sizeHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n xSync(pFile, flags) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * \n * @param {number} pFile \n * @param {number} pSize \n * @returns {number|Promise<number>}\n */\n xFileSize(pFile, pSize) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xLock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xUnlock(pFile, lockType) {\n return VFS.SQLITE_OK;\n } \n\n /**\n * @param {number} pFile \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xCheckReservedLock(pFile, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} op \n * @param {number} pArg \n * @returns {number|Promise<number>}\n */\n xFileControl(pFile, op, pArg) {\n return VFS.SQLITE_NOTFOUND;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xSectorSize(pFile) {\n return DEFAULT_SECTOR_SIZE;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xDeviceCharacteristics(pFile) {\n return 0;\n }\n}\n\nexport const FILE_TYPE_MASK = [\n VFS.SQLITE_OPEN_MAIN_DB,\n VFS.SQLITE_OPEN_MAIN_JOURNAL,\n VFS.SQLITE_OPEN_TEMP_DB,\n VFS.SQLITE_OPEN_TEMP_JOURNAL,\n VFS.SQLITE_OPEN_TRANSIENT_DB,\n VFS.SQLITE_OPEN_SUBJOURNAL,\n VFS.SQLITE_OPEN_SUPER_JOURNAL,\n VFS.SQLITE_OPEN_WAL\n].reduce((mask, element) => mask | element);","// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport { FacadeVFS } from '../FacadeVFS.js';\nimport * as VFS from '../VFS.js';\n\nconst DEFAULT_TEMPORARY_FILES = 10;\nconst LOCK_NOTIFY_INTERVAL = 1000;\n\nconst DB_RELATED_FILE_SUFFIXES = ['', '-journal', '-wal'];\n\nconst finalizationRegistry = new FinalizationRegistry(releaser => releaser());\n\nclass File {\n /** @type {string} */ path\n /** @type {number} */ flags;\n /** @type {FileSystemSyncAccessHandle} */ accessHandle;\n\n /** @type {PersistentFile?} */ persistentFile;\n\n constructor(path, flags) {\n this.path = path;\n this.flags = flags;\n }\n}\n\nclass PersistentFile {\n /** @type {FileSystemFileHandle} */ fileHandle\n /** @type {FileSystemSyncAccessHandle} */ accessHandle = null\n\n // The following properties are for main database files.\n\n /** @type {boolean} */ isLockBusy = false;\n /** @type {boolean} */ isFileLocked = false;\n /** @type {boolean} */ isRequestInProgress = false;\n /** @type {function} */ handleLockReleaser = null;\n\n /** @type {BroadcastChannel} */ handleRequestChannel;\n /** @type {boolean} */ isHandleRequested = false;\n\n constructor(fileHandle) {\n this.fileHandle = fileHandle;\n }\n}\n\nexport class OPFSCoopSyncVFS extends FacadeVFS {\n /** @type {Map<number, File>} */ mapIdToFile = new Map();\n\n lastError = null;\n log = null; //function(...args) { console.log(`[${contextName}]`, ...args) };\n \n /** @type {Map<string, PersistentFile>} */ persistentFiles = new Map();\n /** @type {Map<string, FileSystemSyncAccessHandle>} */ boundAccessHandles = new Map();\n /** @type {Set<FileSystemSyncAccessHandle>} */ unboundAccessHandles = new Set();\n /** @type {Set<string>} */ accessiblePaths = new Set();\n releaser = null;\n\n static async create(name, module) {\n const vfs = new OPFSCoopSyncVFS(name, module);\n await Promise.all([\n vfs.isReady(),\n vfs.#initialize(DEFAULT_TEMPORARY_FILES),\n ]);\n return vfs;\n }\n\n constructor(name, module) {\n super(name, module);\n }\n\n async #initialize(nTemporaryFiles) {\n // Delete temporary directories no longer in use.\n const root = await navigator.storage.getDirectory();\n // @ts-ignore\n for await (const entry of root.values()) {\n if (entry.kind === 'directory' && entry.name.startsWith('.ahp-')) {\n // A lock with the same name as the directory protects it from\n // being deleted.\n await navigator.locks.request(entry.name, { ifAvailable: true }, async lock => {\n if (lock) {\n this.log?.(`Deleting temporary directory ${entry.name}`);\n await root.removeEntry(entry.name, { recursive: true });\n } else {\n this.log?.(`Temporary directory ${entry.name} is in use`);\n }\n });\n }\n }\n\n // Create our temporary directory.\n const tmpDirName = `.ahp-${Math.random().toString(36).slice(2)}`;\n this.releaser = await new Promise(resolve => {\n navigator.locks.request(tmpDirName, () => {\n return new Promise(release => {\n resolve(release);\n });\n });\n });\n finalizationRegistry.register(this, this.releaser);\n const tmpDir = await root.getDirectoryHandle(tmpDirName, { create: true });\n\n // Populate temporary directory.\n for (let i = 0; i < nTemporaryFiles; i++) {\n const tmpFile = await tmpDir.getFileHandle(`${i}.tmp`, { create: true });\n const tmpAccessHandle = await tmpFile.createSyncAccessHandle();\n this.unboundAccessHandles.add(tmpAccessHandle);\n }\n }\n\n /**\n * @param {string?} zName \n * @param {number} fileId \n * @param {number} flags \n * @param {DataView} pOutFlags \n * @returns {number}\n */\n jOpen(zName, fileId, flags, pOutFlags) {\n try {\n const url = new URL(zName || Math.random().toString(36).slice(2), 'file://');\n const path = url.pathname;\n\n if (flags & VFS.SQLITE_OPEN_MAIN_DB) {\n const persistentFile = this.persistentFiles.get(path);\n if (persistentFile?.isRequestInProgress) {\n // Should not reach here unless SQLite itself retries an open.\n // Otherwise, asynchronous operations started on a previous\n // open try should have completed.\n return VFS.SQLITE_BUSY;\n } else if (!persistentFile) {\n // This is the usual starting point for opening a database.\n // Register a Promise that resolves when the database and related\n // files are ready to be used.\n this.log?.(`creating persistent file for ${path}`);\n const create = !!(flags & VFS.SQLITE_OPEN_CREATE);\n this._module.retryOps.push((async () => {\n try {\n // Get the path directory handle.\n let dirHandle = await navigator.storage.getDirectory();\n const directories = path.split('/').filter(d => d);\n const filename = directories.pop();\n for (const directory of directories) {\n dirHandle = await dirHandle.getDirectoryHandle(directory, { create });\n }\n\n // Get file handles for the database and related files,\n // and create persistent file instances.\n for (const suffix of DB_RELATED_FILE_SUFFIXES) {\n const fileHandle = await dirHandle.getFileHandle(filename + suffix, { create });\n await this.#createPersistentFile(fileHandle);\n }\n\n // Get access handles for the files.\n const file = new File(path, flags);\n file.persistentFile = this.persistentFiles.get(path);\n await this.#requestAccessHandle(file);\n } catch (e) {\n // Use an invalid persistent file to signal this error\n // for the retried open.\n const persistentFile = new PersistentFile(null);\n this.persistentFiles.set(path, persistentFile);\n console.error(e);\n }\n })());\n return VFS.SQLITE_BUSY;\n } else if (!persistentFile.fileHandle) {\n // The asynchronous open operation failed.\n this.persistentFiles.delete(path);\n return VFS.SQLITE_CANTOPEN;\n } else if (!persistentFile.accessHandle) {\n // This branch is reached if the database was previously opened\n // and closed.\n this._module.retryOps.push((async () => {\n const file = new File(path, flags);\n file.persistentFile = this.persistentFiles.get(path);\n await this.#requestAccessHandle(file);\n })());\n return VFS.SQLITE_BUSY;\n }\n }\n\n if (!this.accessiblePaths.has(path) &&\n !(flags & VFS.SQLITE_OPEN_CREATE)) {\n throw new Error(`File ${path} not found`);\n }\n\n const file = new File(path, flags);\n this.mapIdToFile.set(fileId, file);\n\n if (this.persistentFiles.has(path)) {\n file.persistentFile = this.persistentFiles.get(path);\n } else if (this.boundAccessHandles.has(path)) {\n // This temporary file was previously created and closed. Reopen\n // the same access handle.\n file.accessHandle = this.boundAccessHandles.get(path);\n } else if (this.unboundAccessHandles.size) {\n // Associate an unbound access handle to this file.\n file.accessHandle = this.unboundAccessHandles.values().next().value;\n file.accessHandle.truncate(0);\n this.unboundAccessHandles.delete(file.accessHandle);\n this.boundAccessHandles.set(path, file.accessHandle);\n }\n this.accessiblePaths.add(path);\n \n pOutFlags.setInt32(0, flags, true);\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_CANTOPEN;\n }\n }\n\n /**\n * @param {string} zName \n * @param {number} syncDir \n * @returns {number}\n */\n jDelete(zName, syncDir) {\n try {\n const url = new URL(zName, 'file://');\n const path = url.pathname;\n if (this.persistentFiles.has(path)) {\n const persistentFile = this.persistentFiles.get(path);\n persistentFile.accessHandle.truncate(0);\n } else {\n this.boundAccessHandles.get(path)?.truncate(0);\n }\n this.accessiblePaths.delete(path);\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_DELETE;\n }\n }\n\n /**\n * @param {string} zName \n * @param {number} flags \n * @param {DataView} pResOut \n * @returns {number}\n */\n jAccess(zName, flags, pResOut) {\n try {\n const url = new URL(zName, 'file://');\n const path = url.pathname;\n pResOut.setInt32(0, this.accessiblePaths.has(path) ? 1 : 0, true);\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_ACCESS;\n } \n }\n\n /**\n * @param {number} fileId \n * @returns {number}\n */\n jClose(fileId) {\n try {\n const file = this.mapIdToFile.get(fileId);\n this.mapIdToFile.delete(fileId);\n\n if (file?.flags & VFS.SQLITE_OPEN_MAIN_DB) {\n if (file.persistentFile?.handleLockReleaser) {\n this.#releaseAccessHandle(file);\n }\n } else if (file?.flags & VFS.SQLITE_OPEN_DELETEONCLOSE) {\n file.accessHandle.truncate(0);\n this.accessiblePaths.delete(file.path);\n if (!this.persistentFiles.has(file.path)) {\n this.boundAccessHandles.delete(file.path);\n this.unboundAccessHandles.add(file.accessHandle);\n }\n }\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_CLOSE;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {Uint8Array} pData \n * @param {number} iOffset\n * @returns {number}\n */\n jRead(fileId, pData, iOffset) {\n try {\n const file = this.mapIdToFile.get(fileId);\n\n // On Chrome (at least), passing pData to accessHandle.read() is\n // an error because pData is a Proxy of a Uint8Array. Calling\n // subarray() produces a real Uint8Array and that works.\n const accessHandle = file.accessHandle || file.persistentFile.accessHandle;\n const bytesRead = accessHandle.read(pData.subarray(), { at: iOffset });\n\n // Opening a database file performs one read without a xLock call.\n if ((file.flags & VFS.SQLITE_OPEN_MAIN_DB) && !file.persistentFile.isFileLocked) {\n this.#releaseAccessHandle(file);\n }\n\n if (bytesRead < pData.byteLength) {\n pData.fill(0, bytesRead);\n return VFS.SQLITE_IOERR_SHORT_READ;\n }\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_READ;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {Uint8Array} pData \n * @param {number} iOffset\n * @returns {number}\n */\n jWrite(fileId, pData, iOffset) {\n try {\n const file = this.mapIdToFile.get(fileId);\n\n // On Chrome (at least), passing pData to accessHandle.write() is\n // an error because pData is a Proxy of a Uint8Array. Calling\n // subarray() produces a real Uint8Array and that works.\n const accessHandle = file.accessHandle || file.persistentFile.accessHandle;\n const nBytes = accessHandle.write(pData.subarray(), { at: iOffset });\n if (nBytes !== pData.byteLength) throw new Error('short write');\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_WRITE;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {number} iSize \n * @returns {number}\n */\n jTruncate(fileId, iSize) {\n try {\n const file = this.mapIdToFile.get(fileId);\n const accessHandle = file.accessHandle || file.persistentFile.accessHandle;\n accessHandle.truncate(iSize);\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_TRUNCATE;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {number} flags \n * @returns {number}\n */\n jSync(fileId, flags) {\n try {\n const file = this.mapIdToFile.get(fileId);\n const accessHandle = file.accessHandle || file.persistentFile.accessHandle;\n accessHandle.flush();\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_FSYNC;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {DataView} pSize64 \n * @returns {number}\n */\n jFileSize(fileId, pSize64) {\n try {\n const file = this.mapIdToFile.get(fileId);\n const accessHandle = file.accessHandle || file.persistentFile.accessHandle;\n const size = accessHandle.getSize();\n pSize64.setBigInt64(0, BigInt(size), true);\n return VFS.SQLITE_OK;\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR_FSTAT;\n }\n }\n\n /**\n * @param {number} fileId \n * @param {number} lockType \n * @returns {number}\n */\n jLock(fileId, lockType) {\n const file = this.mapIdToFile.get(fileId);\n if (file.persistentFile.isRequestInProgress) {\n file.persistentFile.isLockBusy = true;\n return VFS.SQLITE_BUSY;\n }\n\n file.persistentFile.isFileLocked = true;\n if (!file.persistentFile.handleLockReleaser) {\n // Start listening for notifications from other connections.\n // This is before we actually get access handles, but waiting to\n // listen until then allows a race condition where notifications\n // are missed. \n file.persistentFile.handleRequestChannel.onmessage = () => {\n this.log?.(`received notification for ${file.path}`);\n if (file.persistentFile.isFileLocked) {\n // We're still using the access handle, so mark it to be\n // released when we're done.\n file.persistentFile.isHandleRequested = true;\n } else {\n // Release the access handles immediately.\n this.#releaseAccessHandle(file);\n }\n file.persistentFile.handleRequestChannel.onmessage = null;\n };\n\n this.#requestAccessHandle(file);\n this.log?.('returning SQLITE_BUSY');\n file.persistentFile.isLockBusy = true;\n return VFS.SQLITE_BUSY;\n }\n file.persistentFile.isLockBusy = false;\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @param {number} lockType \n * @returns {number}\n */\n jUnlock(fileId, lockType) {\n const file = this.mapIdToFile.get(fileId);\n if (lockType === VFS.SQLITE_LOCK_NONE) {\n // Don't change any state if this unlock is because xLock returned\n // SQLITE_BUSY.\n if (!file.persistentFile.isLockBusy) {\n if (file.persistentFile.isHandleRequested) {\n // Another connection wants the access handle.\n this.#releaseAccessHandle(file);\n file.persistentFile.isHandleRequested = false;\n }\n file.persistentFile.isFileLocked = false;\n }\n }\n return VFS.SQLITE_OK;\n }\n \n /**\n * @param {number} fileId\n * @param {number} op\n * @param {DataView} pArg\n * @returns {number|Promise<number>}\n */\n jFileControl(fileId, op, pArg) {\n try {\n const file = this.mapIdToFile.get(fileId);\n switch (op) {\n case VFS.SQLITE_FCNTL_PRAGMA:\n const key = extractString(pArg, 4);\n const value = extractString(pArg, 8);\n this.log?.('xFileControl', file.path, 'PRAGMA', key, value);\n switch (key.toLowerCase()) {\n case 'journal_mode':\n if (value &&\n !['off', 'memory', 'delete', 'wal'].includes(value.toLowerCase())) {\n throw new Error('journal_mode must be \"off\", \"memory\", \"delete\", or \"wal\"');\n }\n break;\n }\n break;\n }\n } catch (e) {\n this.lastError = e;\n return VFS.SQLITE_IOERR;\n }\n return VFS.SQLITE_NOTFOUND;\n }\n\n /**\n * @param {Uint8Array} zBuf \n * @returns \n */\n jGetLastError(zBuf) {\n if (this.lastError) {\n console.error(this.lastError);\n const outputArray = zBuf.subarray(0, zBuf.byteLength - 1);\n const { written } = new TextEncoder().encodeInto(this.lastError.message, outputArray);\n zBuf[written] = 0;\n }\n return VFS.SQLITE_OK\n }\n\n /**\n * @param {FileSystemFileHandle} fileHandle \n * @returns {Promise<PersistentFile>}\n */\n async #createPersistentFile(fileHandle) {\n const persistentFile = new PersistentFile(fileHandle);\n const root = await navigator.storage.getDirectory();\n const relativePath = await root.resolve(fileHandle);\n const path = `/${relativePath.join('/')}`;\n persistentFile.handleRequestChannel = new BroadcastChannel(`ahp:${path}`);\n this.persistentFiles.set(path, persistentFile);\n\n const f = await fileHandle.getFile();\n if (f.size) {\n this.accessiblePaths.add(path);\n }\n return persistentFile;\n }\n\n /**\n * @param {File} file \n */\n #requestAccessHandle(file) {\n console.assert(!file.persistentFile.handleLockReleaser);\n if (!file.persistentFile.isRequestInProgress) {\n file.persistentFile.isRequestInProgress = true;\n this._module.retryOps.push((async () => {\n // Acquire the Web Lock.\n file.persistentFile.handleLockReleaser = await this.#acquireLock(file.persistentFile);\n try {\n // Get access handles for the database and releated files in parallel.\n this.log?.(`creating access handles for ${file.path}`)\n await Promise.all(DB_RELATED_FILE_SUFFIXES.map(async suffix => {\n const persistentFile = this.persistentFiles.get(file.path + suffix);\n if (persistentFile) {\n persistentFile.accessHandle =\n await persistentFile.fileHandle.createSyncAccessHandle();\n }\n }));\n } catch (e) {\n this.log?.(`failed to create access handles for ${file.path}`, e);\n // Close any of the potentially opened access handles\n this.#releaseAccessHandle(file);\n throw e;\n } finally {\n file.persistentFile.isRequestInProgress = false;\n }\n })());\n return this._module.retryOps.at(-1);\n }\n return Promise.resolve();\n }\n\n /**\n * @param {File} file \n */\n #releaseAccessHandle(file) {\n DB_RELATED_FILE_SUFFIXES.forEach(suffix => {\n const persistentFile = this.persistentFiles.get(file.path + suffix);\n if (persistentFile) {\n persistentFile.accessHandle?.close();\n persistentFile.accessHandle = null;\n }\n });\n this.log?.(`access handles closed for ${file.path}`)\n\n file.persistentFile.handleLockReleaser?.();\n file.persistentFile.handleLockReleaser = null;\n this.log?.(`lock released for ${file.path}`)\n }\n\n /**\n * @param {PersistentFile} persistentFile \n * @returns {Promise<function>} lock releaser\n */\n #acquireLock(persistentFile) {\n return new Promise(resolve => {\n // Tell other connections we want the access handle.\n const lockName = persistentFile.handleRequestChannel.name;\n const notify = () => {\n this.log?.(`notifying for ${lockName}`);\n persistentFile.handleRequestChannel.postMessage(null);\n }\n const notifyId = setInterval(notify, LOCK_NOTIFY_INTERVAL);\n setTimeout(notify);\n\n this.log?.(`lock requested: ${lockName}`)\n navigator.locks.request(lockName, lock => {\n // We have the lock. Stop asking other connections for it.\n this.log?.(`lock acquired: ${lockName}`, lock);\n clearInterval(notifyId);\n return new Promise(resolve);\n });\n });\n }\n}\n\nfunction extractString(dataView, offset) {\n const p = dataView.getUint32(offset, true);\n if (p) {\n const chars = new Uint8Array(dataView.buffer, p);\n return new TextDecoder().decode(chars.subarray(0, chars.indexOf(0)));\n }\n return null;\n}"],"names":[],"sourceRoot":""}
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@powersync/web",
3
+ "version": "1.38.7",
4
+ "description": "PowerSync Web SDK",
5
+ "main": "lib/src/index.js",
6
+ "module": "lib/src/index.js",
7
+ "type": "module",
8
+ "types": "lib/src/index.d.ts",
9
+ "bin": {
10
+ "powersync-web": "bin/powersync.cjs"
11
+ },
12
+ "files": [
13
+ "bin",
14
+ "lib",
15
+ "!lib/tests",
16
+ "dist",
17
+ "src"
18
+ ],
19
+ "exports": {
20
+ ".": {
21
+ "types": "./lib/src/index.d.ts",
22
+ "default": "./lib/src/index.js"
23
+ },
24
+ "./umd": {
25
+ "types": "./lib/src/index.d.ts",
26
+ "default": "./dist/index.umd.js"
27
+ },
28
+ "./umd/worker/db": {
29
+ "types": "./lib/src/index.d.ts",
30
+ "import": "./dist/worker/WASQLiteDB.umd.js",
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"
37
+ }
38
+ },
39
+ "repository": "https://github.com/powersync-ja/powersync-js",
40
+ "bugs": {
41
+ "url": "https://github.com/powersync-ja/powersync-js/issues"
42
+ },
43
+ "publishConfig": {
44
+ "registry": "https://registry.npmjs.org/",
45
+ "access": "public"
46
+ },
47
+ "homepage": "https://docs.powersync.com",
48
+ "scripts": {
49
+ "build:tsc": "tsc --build",
50
+ "build:webpack-main": "webpack",
51
+ "build:webpack-workers": "webpack --config webpack.workers.config.js",
52
+ "build": "pnpm run build:tsc && pnpm run build:webpack-main && pnpm run build:webpack-workers",
53
+ "build:prod": "pnpm run build:tsc --sourceMap false && pnpm run build:webpack-main && pnpm run build:webpack-workers",
54
+ "clean": "rm -rf lib dist tsconfig.tsbuildinfo",
55
+ "watch": "tsc --build -w",
56
+ "test": "pnpm build && vitest",
57
+ "test:exports": "attw --pack . --entrypoints . --profile=esm-only "
58
+ },
59
+ "keywords": [
60
+ "data sync",
61
+ "offline-first",
62
+ "sqlite",
63
+ "real-time data stream",
64
+ "live data"
65
+ ],
66
+ "author": "PowerSync",
67
+ "license": "Apache-2.0",
68
+ "peerDependencies": {
69
+ "@journeyapps/wa-sqlite": "catalog:",
70
+ "@powersync/common": "workspace:^1.57.1"
71
+ },
72
+ "dependencies": {
73
+ "@powersync/common": "workspace:*",
74
+ "comlink": "catalog:",
75
+ "commander": "^12.1.0"
76
+ },
77
+ "devDependencies": {
78
+ "@journeyapps/wa-sqlite": "^1.7.0",
79
+ "@types/uuid": "catalog:",
80
+ "bson": "catalog:",
81
+ "glob": "catalog:",
82
+ "p-defer": "catalog:",
83
+ "source-map-loader": "^5.0.0",
84
+ "terser-webpack-plugin": "^5.3.9",
85
+ "uuid": "catalog:",
86
+ "vite": "catalog:",
87
+ "webpack": "^5.90.1",
88
+ "webpack-cli": "^5.1.4",
89
+ "webpack-node-externals": "^3.0.0"
90
+ }
91
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IndexDBFileSystemAdapter.js","sourceRoot":"","sources":["../../../src/attachments/IndexDBFileSystemAdapter.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM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ACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,OAAO,IAAI,OAAO,CAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC/B,GAAG,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC5C,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY;QACxB,gEAAgE;IAClE,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAY;QACtB,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAC/C,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,EAAE,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5E,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChC,GAAG,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;YAChC,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import { TriggerClaimManager } from '@powersync/shared-internals';
1
+ import { TriggerClaimManager } from '@powersync/common';
2
2
  /**
3
3
  * @internal
4
4
  * @experimental
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavigatorTriggerClaimManager.js","sourceRoot":"","sources":["../../../src/db/NavigatorTriggerClaimManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAwB;IAClE,KAAK,CAAC,WAAW,CAAC,UAAkB;QAClC,OAAO,IAAI,OAAO,CAAC,CAAC,eAAe,EAAE,EAAE;YACrC,iBAAiB,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;gBACjD,MAAM,IAAI,OAAO,CAAO,CAAC,WAAW,EAAE,EAAE;oBACtC,eAAe,CAAC,KAAK,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;gBAC7C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,UAAkB;QACjC,MAAM,YAAY,GAAG,MAAM,iBAAiB,EAAE,CAAC,KAAK,EAAE,CAAC;QACvD,OAAO,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC;IACpF,CAAC;CACF,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { AbstractPowerSyncDatabase, DBAdapter, PowerSyncDatabaseOptions, PowerSyncDatabaseOptionsWithDBAdapter, PowerSyncDatabaseOptionsWithOpenFactory, PowerSyncDatabaseOptionsWithSettings, StreamingSyncImplementation, TriggerManagerConfig, Mutex, type BucketStorageAdapter, type PowerSyncBackendConnector, type PowerSyncCloseOptions, type RequiredAdditionalConnectionOptions } from '@powersync/common';
2
+ import { ResolvedWebSQLOpenOptions, WebSQLFlags } from './adapters/web-sql-flags.js';
3
+ export interface WebPowerSyncFlags extends WebSQLFlags {
4
+ /**
5
+ * @deprecated This flag is no longer used. Navigator locks now handle tab detection automatically.
6
+ * Externally unload open PowerSync database instances when the window closes.
7
+ * Setting this to `true` requires calling `close` on all open PowerSyncDatabase
8
+ * instances before the window unloads
9
+ */
10
+ externallyUnload?: boolean;
11
+ }
12
+ type WithWebFlags<Base> = Base & {
13
+ flags?: WebPowerSyncFlags;
14
+ };
15
+ export interface WebSyncOptions {
16
+ /**
17
+ * Allows you to override the default sync worker.
18
+ *
19
+ * You can either provide a path to the worker script
20
+ * or a factory method that returns a worker.
21
+ */
22
+ worker?: string | URL | ((options: ResolvedWebSQLOpenOptions) => SharedWorker);
23
+ }
24
+ type WithWebSyncOptions<Base> = Base & {
25
+ sync?: WebSyncOptions;
26
+ };
27
+ export interface WebEncryptionOptions {
28
+ /**
29
+ * Encryption key for the database.
30
+ * If set, the database will be encrypted using Multiple Ciphers.
31
+ */
32
+ encryptionKey?: string;
33
+ }
34
+ type WithWebEncryptionOptions<Base> = Base & WebEncryptionOptions;
35
+ export type WebPowerSyncDatabaseOptionsWithAdapter = WithWebSyncOptions<WithWebFlags<PowerSyncDatabaseOptionsWithDBAdapter>>;
36
+ export type WebPowerSyncDatabaseOptionsWithOpenFactory = WithWebSyncOptions<WithWebFlags<PowerSyncDatabaseOptionsWithOpenFactory>>;
37
+ export type WebPowerSyncDatabaseOptionsWithSettings = WithWebSyncOptions<WithWebFlags<WithWebEncryptionOptions<PowerSyncDatabaseOptionsWithSettings>>>;
38
+ export type WebPowerSyncDatabaseOptions = WithWebSyncOptions<WithWebFlags<PowerSyncDatabaseOptions>>;
39
+ export declare const DEFAULT_POWERSYNC_FLAGS: Required<WebPowerSyncFlags>;
40
+ export declare const resolveWebPowerSyncFlags: (flags?: WebPowerSyncFlags) => Required<WebPowerSyncFlags>;
41
+ /**
42
+ * A PowerSync database which provides SQLite functionality
43
+ * which is automatically synced.
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * export const db = new PowerSyncDatabase({
48
+ * schema: AppSchema,
49
+ * database: {
50
+ * dbFilename: 'example.db'
51
+ * }
52
+ * });
53
+ * ```
54
+ */
55
+ export declare class PowerSyncDatabase extends AbstractPowerSyncDatabase {
56
+ protected options: WebPowerSyncDatabaseOptions;
57
+ static SHARED_MUTEX: Mutex;
58
+ protected resolvedFlags: WebPowerSyncFlags;
59
+ constructor(options: WebPowerSyncDatabaseOptionsWithAdapter);
60
+ constructor(options: WebPowerSyncDatabaseOptionsWithOpenFactory);
61
+ constructor(options: WebPowerSyncDatabaseOptionsWithSettings);
62
+ constructor(options: WebPowerSyncDatabaseOptions);
63
+ _initialize(): Promise<void>;
64
+ protected generateTriggerManagerConfig(): TriggerManagerConfig;
65
+ protected openDBAdapter(options: WebPowerSyncDatabaseOptionsWithSettings): DBAdapter;
66
+ /**
67
+ * Closes the database connection.
68
+ * By default the sync stream client is only disconnected if
69
+ * multiple tabs are not enabled.
70
+ */
71
+ close(options?: PowerSyncCloseOptions): Promise<void>;
72
+ protected loadVersion(): Promise<void>;
73
+ protected resolveOfflineSyncStatus(): Promise<void>;
74
+ protected generateBucketStorageAdapter(): BucketStorageAdapter;
75
+ protected runExclusive<T>(cb: () => Promise<T>): Promise<T>;
76
+ protected generateSyncStreamImplementation(connector: PowerSyncBackendConnector, options: RequiredAdditionalConnectionOptions): StreamingSyncImplementation;
77
+ }
78
+ export {};
@@ -1,26 +1,58 @@
1
- import { LogLevels } from '@powersync/common';
2
- import { BasePowerSyncDatabase, Mutex, SqliteBucketStorage, openDatabase } from '@powersync/shared-internals';
1
+ import { AbstractPowerSyncDatabase, SqliteBucketStorage, isDBAdapter, isSQLOpenFactory, Mutex } from '@powersync/common';
3
2
  import { getNavigatorLocks } from '../shared/navigator.js';
4
3
  import { NAVIGATOR_TRIGGER_CLAIM_MANAGER } from './NavigatorTriggerClaimManager.js';
5
4
  import { WASQLiteOpenFactory } from './adapters/wa-sqlite/WASQLiteOpenFactory.js';
5
+ import { DEFAULT_WEB_SQL_FLAGS, isServerSide, resolveWebSQLFlags } from './adapters/web-sql-flags.js';
6
6
  import { SSRStreamingSyncImplementation } from './sync/SSRWebStreamingSyncImplementation.js';
7
7
  import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation.js';
8
8
  import { WebRemote } from './sync/WebRemote.js';
9
9
  import { WebStreamingSyncImplementation } from './sync/WebStreamingSyncImplementation.js';
10
10
  import { AsyncDbAdapter } from './adapters/AsyncWebAdapter.js';
11
- import { resolveAndValidateOptions } from './adapters/resolveAndValidateOptions.js';
11
+ export const DEFAULT_POWERSYNC_FLAGS = {
12
+ ...DEFAULT_WEB_SQL_FLAGS,
13
+ externallyUnload: false
14
+ };
15
+ export const resolveWebPowerSyncFlags = (flags) => {
16
+ return {
17
+ ...DEFAULT_POWERSYNC_FLAGS,
18
+ ...flags,
19
+ ...resolveWebSQLFlags(flags)
20
+ };
21
+ };
12
22
  /**
13
- * @internal Use {@link PowerSyncDatabase} instead, this class is only used by other SDKs also needing web support.
23
+ * Asserts that the database options are valid for custom database constructors.
14
24
  */
15
- export class WebPowerSyncDatabase extends BasePowerSyncDatabase {
25
+ function assertValidDatabaseOptions(options) {
26
+ if ('database' in options && 'encryptionKey' in options) {
27
+ const { database } = options;
28
+ if (isSQLOpenFactory(database) || isDBAdapter(database)) {
29
+ throw new Error(`Invalid configuration: 'encryptionKey' should only be included inside the database object when using a custom ${isSQLOpenFactory(database) ? 'WASQLiteOpenFactory' : 'WASQLiteDBAdapter'} constructor.`);
30
+ }
31
+ }
32
+ }
33
+ /**
34
+ * A PowerSync database which provides SQLite functionality
35
+ * which is automatically synced.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * export const db = new PowerSyncDatabase({
40
+ * schema: AppSchema,
41
+ * database: {
42
+ * dbFilename: 'example.db'
43
+ * }
44
+ * });
45
+ * ```
46
+ */
47
+ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
48
+ options;
16
49
  static SHARED_MUTEX = new Mutex();
17
- resolvedOpenOptions;
18
- enableBroadcastLogs;
50
+ resolvedFlags;
19
51
  constructor(options) {
20
- const resolvedOpenOptions = resolveAndValidateOptions('database' in options ? options.database : {});
21
52
  super(options);
22
- this.resolvedOpenOptions = resolvedOpenOptions;
23
- this.enableBroadcastLogs = options.broadcastLogs ?? true;
53
+ this.options = options;
54
+ assertValidDatabaseOptions(options);
55
+ this.resolvedFlags = resolveWebPowerSyncFlags(options.flags);
24
56
  }
25
57
  async _initialize() {
26
58
  if (this.database instanceof AsyncDbAdapter) {
@@ -47,14 +79,13 @@ export class WebPowerSyncDatabase extends BasePowerSyncDatabase {
47
79
  claimManager: NAVIGATOR_TRIGGER_CLAIM_MANAGER
48
80
  };
49
81
  }
50
- openDBAdapter() {
51
- return openDatabase(this.options, (options) => {
52
- const defaultFactory = new WASQLiteOpenFactory({
53
- logger: this.logger,
54
- open: options
55
- });
56
- return defaultFactory.openDB();
82
+ openDBAdapter(options) {
83
+ const defaultFactory = new WASQLiteOpenFactory({
84
+ ...options.database,
85
+ flags: resolveWebPowerSyncFlags(options.flags),
86
+ encryptionKey: options.encryptionKey
57
87
  });
88
+ return defaultFactory.openDB();
58
89
  }
59
90
  /**
60
91
  * Closes the database connection.
@@ -64,27 +95,27 @@ export class WebPowerSyncDatabase extends BasePowerSyncDatabase {
64
95
  close(options) {
65
96
  return super.close({
66
97
  // Don't disconnect by default if multiple tabs are enabled
67
- disconnect: options?.disconnect ?? !this.resolvedOpenOptions.enableMultiTabs
98
+ disconnect: options?.disconnect ?? !this.resolvedFlags.enableMultiTabs
68
99
  });
69
100
  }
70
101
  async loadVersion() {
71
- if (this.resolvedOpenOptions.ssrMode) {
102
+ if (isServerSide()) {
72
103
  return;
73
104
  }
74
105
  return super.loadVersion();
75
106
  }
76
107
  async resolveOfflineSyncStatus() {
77
- if (this.resolvedOpenOptions.ssrMode) {
108
+ if (isServerSide()) {
78
109
  return;
79
110
  }
80
111
  return super.resolveOfflineSyncStatus();
81
112
  }
82
113
  generateBucketStorageAdapter() {
83
- return new SqliteBucketStorage(this.database, this.logger);
114
+ return new SqliteBucketStorage(this.database);
84
115
  }
85
116
  async runExclusive(cb) {
86
- if (this.resolvedOpenOptions.ssrMode) {
87
- return WebPowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
117
+ if (this.resolvedFlags.ssrMode) {
118
+ return PowerSyncDatabase.SHARED_MUTEX.runExclusive(cb);
88
119
  }
89
120
  return getNavigatorLocks().request(`lock-${this.database.name}`, cb);
90
121
  }
@@ -93,6 +124,7 @@ export class WebPowerSyncDatabase extends BasePowerSyncDatabase {
93
124
  const syncOptions = {
94
125
  ...this.options,
95
126
  ...options,
127
+ flags: this.resolvedFlags,
96
128
  adapter: this.bucketStorageAdapter,
97
129
  remote,
98
130
  uploadCrud: async () => {
@@ -103,42 +135,24 @@ export class WebPowerSyncDatabase extends BasePowerSyncDatabase {
103
135
  logger: this.logger
104
136
  };
105
137
  switch (true) {
106
- case this.resolvedOpenOptions.ssrMode:
107
- return new SSRStreamingSyncImplementation();
108
- case this.resolvedOpenOptions.enableMultiTabs:
109
- if (!this.enableBroadcastLogs) {
138
+ case this.resolvedFlags.ssrMode:
139
+ return new SSRStreamingSyncImplementation(syncOptions);
140
+ case this.resolvedFlags.enableMultiTabs:
141
+ if (!this.resolvedFlags.broadcastLogs) {
110
142
  const warning = `
111
143
  Multiple tabs are enabled, but broadcasting of logs is disabled.
112
144
  Logs for shared sync worker will only be available in the shared worker context
113
145
  `;
114
146
  const logger = this.options.logger;
115
- logger ? logger.log({ level: LogLevels.warn, message: warning }) : console.warn(warning);
147
+ logger ? logger.warn(warning) : console.warn(warning);
116
148
  }
117
149
  return new SharedWebStreamingSyncImplementation({
118
150
  ...syncOptions,
119
- db: this.database, // This should always be the case
120
- logLevel: this.options.sync?.logLevel ?? LogLevels.info,
121
- enableBroadcastLogs: this.enableBroadcastLogs
151
+ db: this.database // This should always be the case
122
152
  });
123
153
  default:
124
154
  return new WebStreamingSyncImplementation(syncOptions);
125
155
  }
126
156
  }
127
157
  }
128
- /**
129
- * A PowerSync database which provides SQLite functionality
130
- * which is automatically synced.
131
- *
132
- * @example
133
- * ```typescript
134
- * export const db = new PowerSyncDatabase({
135
- * schema: AppSchema,
136
- * database: {
137
- * dbFilename: 'example.db'
138
- * }
139
- * });
140
- * ```
141
- */
142
- // Typed constructor to avoid leaking AbstractPowerSyncDatabase into the public interface
143
- export const PowerSyncDatabase = WebPowerSyncDatabase;
144
158
  //# sourceMappingURL=PowerSyncDatabase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PowerSyncDatabase.js","sourceRoot":"","sources":["../../../src/db/PowerSyncDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EAMzB,mBAAmB,EAGnB,WAAW,EACX,gBAAgB,EAChB,KAAK,EAKN,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AAClF,OAAO,EACL,qBAAqB,EAGrB,YAAY,EACZ,kBAAkB,EACnB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAC7F,OAAO,EAAE,oCAAoC,EAAE,MAAM,gDAAgD,CAAC;AACtG,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,8BAA8B,EAE/B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAkD/D,MAAM,CAAC,MAAM,uBAAuB,GAAgC;IAClE,GAAG,qBAAqB;IACxB,gBAAgB,EAAE,KAAK;CACxB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAyB,EAA+B,EAAE;IACjG,OAAO;QACL,GAAG,uBAAuB;QAC1B,GAAG,KAAK;QACR,GAAG,kBAAkB,CAAC,KAAK,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AC;QAC3D,CAAC;IACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { AbstractPowerSyncDatabase, AbstractPowerSyncDatabaseOpenFactory, PowerSyncDatabaseOptions, PowerSyncOpenFactoryOptions } from '@powersync/common';
2
+ import { WebPowerSyncDatabaseOptions, WebPowerSyncFlags } from '../../db/PowerSyncDatabase.js';
3
+ /**
4
+ * {@link WebPowerSyncFlags}
5
+ * Maintaining export for consistency with API from previous versions
6
+ * */
7
+ export interface WebPowerSyncOpenFlags extends WebPowerSyncFlags {
8
+ }
9
+ export interface WebPowerSyncOpenFactoryOptions extends PowerSyncOpenFactoryOptions {
10
+ flags?: WebPowerSyncOpenFlags;
11
+ }
12
+ /**
13
+ * Intermediate PowerSync Database Open factory for Web which uses a mock
14
+ * SSR DB Adapter if running on server side.
15
+ * Most SQLite DB implementations only run on client side, this will safely return
16
+ * empty query results in SSR which will allow for generating server partial views.
17
+ */
18
+ export declare abstract class AbstractWebPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseOpenFactory {
19
+ protected options: WebPowerSyncOpenFactoryOptions;
20
+ constructor(options: WebPowerSyncOpenFactoryOptions);
21
+ generateOptions(): WebPowerSyncDatabaseOptions;
22
+ generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase;
23
+ }
@@ -0,0 +1,27 @@
1
+ import { AbstractPowerSyncDatabaseOpenFactory } from '@powersync/common';
2
+ import { PowerSyncDatabase, resolveWebPowerSyncFlags } from '../../db/PowerSyncDatabase.js';
3
+ /**
4
+ * Intermediate PowerSync Database Open factory for Web which uses a mock
5
+ * SSR DB Adapter if running on server side.
6
+ * Most SQLite DB implementations only run on client side, this will safely return
7
+ * empty query results in SSR which will allow for generating server partial views.
8
+ */
9
+ export class AbstractWebPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseOpenFactory {
10
+ options;
11
+ constructor(options) {
12
+ super(options);
13
+ this.options = options;
14
+ }
15
+ generateOptions() {
16
+ return {
17
+ ...this.options,
18
+ database: this.openDB(),
19
+ schema: this.schema,
20
+ flags: resolveWebPowerSyncFlags(this.options.flags)
21
+ };
22
+ }
23
+ generateInstance(options) {
24
+ return new PowerSyncDatabase(options);
25
+ }
26
+ }
27
+ //# sourceMappingURL=AbstractWebPowerSyncDatabaseOpenFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AbstractWebPowerSyncDatabaseOpenFactory.js","sourceRoot":"","sources":["../../../../src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,oCAAoC,EAGrC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EAGjB,wBAAwB,EACzB,MAAM,+BAA+B,CAAC;AAYvC;;;;;GAKG;AACH,MAAM,OAAgB,uCAAwC,SAAQ,oCAAoC;IAClF;IAAtB,YAAsB,OAAuC;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QADK,YAAO,GAAP,OAAO,CAAgC;IAE7D,CAAC;IAED,eAAe;QACb,OAAO;YACL,GAAG,IAAI,CAAC,OAAO;YACf,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SACpD,CAAC;IACJ,CAAC;IAED,gBAAgB,CAAC,OAAiC;QAChD,OAAO,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import { ConnectionPool, DBAdapterListener, DBLockOptions, LockContext } from '@powersync/common';
2
+ import { SharedConnectionWorker, WebDBAdapter, WebDBAdapterConfiguration } from './WebDBAdapter.js';
3
+ import { DatabaseClient } from './wa-sqlite/DatabaseClient.js';
4
+ /**
5
+ * A connection pool implementation delegating to another pool opened asynchronnously.
6
+ */
7
+ declare class AsyncConnectionPool implements ConnectionPool {
8
+ readonly name: string;
9
+ protected readonly state: Promise<PoolState>;
10
+ protected resolvedWriter?: DatabaseClient;
11
+ private readonly pendingListeners;
12
+ constructor(inner: Promise<PoolConnection>, name: string);
13
+ init(): Promise<void>;
14
+ close(): Promise<void>;
15
+ readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
16
+ writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
17
+ refreshSchema(): Promise<void>;
18
+ registerListener(listener: Partial<DBAdapterListener>): () => void;
19
+ }
20
+ export interface PoolConnection {
21
+ writer: DatabaseClient;
22
+ additionalReaders: DatabaseClient[];
23
+ }
24
+ interface PoolState {
25
+ writer: DatabaseClient;
26
+ withConnection<T>(allowReadOnly: boolean, fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
27
+ close(): Promise<void>;
28
+ refreshSchema(): Promise<void>;
29
+ }
30
+ declare const AsyncDbAdapter_base: (new (...args: any[]) => {
31
+ readTransaction<T>(fn: (tx: import("@powersync/common").Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
32
+ writeTransaction<T>(fn: (tx: import("@powersync/common").Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
33
+ getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
34
+ getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
35
+ get<T>(sql: string, parameters?: any[]): Promise<T>;
36
+ execute(query: string, params?: any[]): Promise<import("@powersync/common").QueryResult>;
37
+ executeRaw(query: string, params?: any[]): Promise<any[][]>;
38
+ executeBatch(query: string, params?: any[][]): Promise<import("@powersync/common").QueryResult>;
39
+ name: string;
40
+ close: () => void | Promise<void>;
41
+ readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
42
+ writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
43
+ refreshSchema: () => Promise<void>;
44
+ registerListener(listener: Partial<DBAdapterListener>): () => void;
45
+ }) & typeof AsyncConnectionPool;
46
+ export declare class AsyncDbAdapter extends AsyncDbAdapter_base implements WebDBAdapter {
47
+ shareConnection(): Promise<SharedConnectionWorker>;
48
+ getConfiguration(): WebDBAdapterConfiguration;
49
+ }
50
+ export {};