@powersync/web 0.0.0-dev-20260414110516 → 0.0.0-dev-20260504100448

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 (76) hide show
  1. package/dist/2075a31bb151adbb9767.wasm +0 -0
  2. package/dist/3322bc84de986b63c2cd.wasm +0 -0
  3. package/dist/8e97452e297be23b5e50.wasm +0 -0
  4. package/dist/fbc178b70d530e8ce02b.wasm +0 -0
  5. package/dist/index.umd.js +4289 -4786
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/worker/SharedSyncImplementation.umd.js +37 -798
  8. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  9. package/dist/worker/WASQLiteDB.umd.js +99 -737
  10. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-cc5fcc.umd.js.map → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map} +1 -1
  17. 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
  18. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map} +1 -1
  19. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +3562 -0
  20. 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
  21. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-0df390.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js} +16 -16
  22. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-0df390.umd.js.map → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map} +1 -1
  23. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-151024.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js} +12 -12
  24. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-151024.umd.js.map → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map} +1 -1
  25. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-c01ef0.umd.js → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js} +14 -14
  26. package/dist/worker/{node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-c01ef0.umd.js.map → node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map} +1 -1
  27. package/lib/package.json +4 -7
  28. package/lib/src/db/PowerSyncDatabase.d.ts +1 -1
  29. package/lib/src/db/PowerSyncDatabase.js +0 -8
  30. package/lib/src/db/adapters/AsyncWebAdapter.d.ts +13 -3
  31. package/lib/src/db/adapters/AsyncWebAdapter.js +115 -21
  32. package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js +1 -2
  33. package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js +1 -1
  34. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +16 -2
  35. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +60 -38
  36. package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +7 -18
  37. package/lib/src/db/adapters/wa-sqlite/vfs.js +34 -49
  38. package/lib/src/db/sync/SSRWebStreamingSyncImplementation.d.ts +4 -0
  39. package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js +4 -0
  40. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +0 -1
  41. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +0 -3
  42. package/lib/src/db/sync/WebRemote.d.ts +1 -3
  43. package/lib/src/db/sync/WebRemote.js +0 -12
  44. package/lib/src/worker/db/MultiDatabaseServer.js +4 -1
  45. package/lib/src/worker/db/open-worker-database.js +2 -2
  46. package/lib/src/worker/sync/SharedSyncImplementation.d.ts +0 -2
  47. package/lib/src/worker/sync/SharedSyncImplementation.js +4 -16
  48. package/lib/src/worker/sync/WorkerClient.d.ts +0 -1
  49. package/lib/src/worker/sync/WorkerClient.js +0 -3
  50. package/lib/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +5 -8
  52. package/src/db/PowerSyncDatabase.ts +1 -9
  53. package/src/db/adapters/AsyncWebAdapter.ts +138 -22
  54. package/src/db/adapters/wa-sqlite/DatabaseServer.ts +4 -2
  55. package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +4 -1
  56. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +89 -44
  57. package/src/db/adapters/wa-sqlite/vfs.ts +33 -49
  58. package/src/db/sync/SSRWebStreamingSyncImplementation.ts +5 -0
  59. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +0 -4
  60. package/src/db/sync/WebRemote.ts +0 -16
  61. package/src/worker/db/MultiDatabaseServer.ts +4 -1
  62. package/src/worker/db/open-worker-database.ts +2 -2
  63. package/src/worker/sync/SharedSyncImplementation.ts +4 -18
  64. package/src/worker/sync/WorkerClient.ts +0 -4
  65. package/dist/26d61ca9f5694d064635.wasm +0 -0
  66. package/dist/b4c6283dc473b6b3fd24.wasm +0 -0
  67. package/dist/c78985091a0b22aaef03.wasm +0 -0
  68. package/dist/ca59e199e1138b553fad.wasm +0 -0
  69. package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js +0 -4646
  70. package/dist/worker/node_modules_pnpm_bson_6_10_4_node_modules_bson_lib_bson_mjs.umd.js.map +0 -1
  71. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-b9c070.umd.js +0 -31
  72. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-b9c070.umd.js.map +0 -1
  73. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-c99c07.umd.js +0 -31
  74. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-c99c07.umd.js.map +0 -1
  75. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-cc5fcc.umd.js +0 -31
  76. package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +0 -31
@@ -384,9 +384,9 @@ function generateUUID() {
384
384
 
385
385
  /***/ },
386
386
 
387
- /***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js"
387
+ /***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js"
388
388
  /*!*******************************************************************************************************************!*\
389
- !*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js ***!
389
+ !*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js ***!
390
390
  \*******************************************************************************************************************/
391
391
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
392
392
 
@@ -627,7 +627,7 @@ __webpack_require__.r(__webpack_exports__);
627
627
  /* harmony export */ SQLITE_WARNING: () => (/* reexport safe */ _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__.SQLITE_WARNING),
628
628
  /* harmony export */ SQLiteError: () => (/* binding */ SQLiteError)
629
629
  /* harmony export */ });
630
- /* harmony import */ var _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sqlite-constants.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js");
630
+ /* harmony import */ var _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./sqlite-constants.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js");
631
631
  // Copyright 2021 Roy T. Hashimoto. All Rights Reserved.
632
632
 
633
633
 
@@ -669,6 +669,7 @@ function Factory(Module) {
669
669
  /** @type {SQLiteAPI} */ const sqlite3 = {};
670
670
 
671
671
  Module.retryOps = [];
672
+ Module.pendingOps = [];
672
673
  const sqliteFreeAddress = Module._getSqliteFree();
673
674
 
674
675
  // Allocate some space for 32-bit returned values.
@@ -1524,7 +1525,7 @@ function Factory(Module) {
1524
1525
  // succeed.
1525
1526
  async function retry(f) {
1526
1527
  let rc;
1527
- do {
1528
+ for (let retryCount = 0; retryCount < 2; ++retryCount) {
1528
1529
  // Wait for all pending retry operations to complete. This is
1529
1530
  // normally empty on the first loop iteration.
1530
1531
  if (Module.retryOps.length) {
@@ -1536,9 +1537,20 @@ function Factory(Module) {
1536
1537
  }
1537
1538
 
1538
1539
  rc = await f();
1539
-
1540
- // Retry on failure with new pending retry operations.
1541
- } while (rc && Module.retryOps.length);
1540
+ if (rc === _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__.SQLITE_OK || Module.retryOps.length === 0) {
1541
+ if (Module.pendingOps.length) {
1542
+ try {
1543
+ await Promise.all(Module.pendingOps);
1544
+ } catch (e) {
1545
+ console.error('Error in pendingOps:', e);
1546
+ return e.code || _sqlite_constants_js__WEBPACK_IMPORTED_MODULE_0__.SQLITE_ERROR;
1547
+ } finally {
1548
+ Module.pendingOps = [];
1549
+ }
1550
+ }
1551
+ return rc;
1552
+ }
1553
+ }
1542
1554
  return rc;
1543
1555
  }
1544
1556
 
@@ -1579,9 +1591,9 @@ function decl(s) {
1579
1591
 
1580
1592
  /***/ },
1581
1593
 
1582
- /***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js"
1594
+ /***/ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js"
1583
1595
  /*!*************************************************************************************************************************!*\
1584
- !*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js ***!
1596
+ !*** ../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js ***!
1585
1597
  \*************************************************************************************************************************/
1586
1598
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
1587
1599
 
@@ -2332,8 +2344,7 @@ class DatabaseServer {
2332
2344
  },
2333
2345
  requestAccess: async (write, timeoutMs) => {
2334
2346
  requireOpen();
2335
- // TODO: Support timeouts, they don't seem to be supported by the async-mutex package.
2336
- const lease = await this.#inner.acquireConnection();
2347
+ const lease = await this.#inner.acquireConnection(timeoutMs != null ? AbortSignal.timeout(timeoutMs) : undefined);
2337
2348
  if (!isOpen) {
2338
2349
  // Race between requestAccess and close(), the connection was closed while we tried to acquire a lease.
2339
2350
  await lease.returnLease();
@@ -2405,7 +2416,7 @@ __webpack_require__.r(__webpack_exports__);
2405
2416
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2406
2417
  /* harmony export */ RawSqliteConnection: () => (/* binding */ RawSqliteConnection)
2407
2418
  /* harmony export */ });
2408
- /* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
2419
+ /* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
2409
2420
  /* harmony import */ var _vfs_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./vfs.js */ "./lib/src/db/adapters/wa-sqlite/vfs.js");
2410
2421
 
2411
2422
 
@@ -2432,7 +2443,7 @@ class RawSqliteConnection {
2432
2443
  }
2433
2444
  async init() {
2434
2445
  const api = (this._sqliteAPI = await this.openSQLiteAPI());
2435
- this.db = await api.open_v2(this.options.dbFilename);
2446
+ this.db = await api.open_v2(this.options.dbFilename, this.options.isReadOnly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */);
2436
2447
  await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
2437
2448
  if (this.options.encryptionKey) {
2438
2449
  const escapedKey = this.options.encryptionKey.replace("'", "''");
@@ -2566,11 +2577,7 @@ class RawSqliteConnection {
2566
2577
 
2567
2578
  __webpack_require__.r(__webpack_exports__);
2568
2579
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2569
- /* harmony export */ AsyncWASQLiteModuleFactory: () => (/* binding */ AsyncWASQLiteModuleFactory),
2570
2580
  /* harmony export */ DEFAULT_MODULE_FACTORIES: () => (/* binding */ DEFAULT_MODULE_FACTORIES),
2571
- /* harmony export */ MultiCipherAsyncWASQLiteModuleFactory: () => (/* binding */ MultiCipherAsyncWASQLiteModuleFactory),
2572
- /* harmony export */ MultiCipherSyncWASQLiteModuleFactory: () => (/* binding */ MultiCipherSyncWASQLiteModuleFactory),
2573
- /* harmony export */ SyncWASQLiteModuleFactory: () => (/* binding */ SyncWASQLiteModuleFactory),
2574
2581
  /* harmony export */ WASQLiteVFS: () => (/* binding */ WASQLiteVFS),
2575
2582
  /* harmony export */ vfsRequiresDedicatedWorkers: () => (/* binding */ vfsRequiresDedicatedWorkers)
2576
2583
  /* harmony export */ });
@@ -2582,51 +2589,38 @@ var WASQLiteVFS;
2582
2589
  WASQLiteVFS["IDBBatchAtomicVFS"] = "IDBBatchAtomicVFS";
2583
2590
  WASQLiteVFS["OPFSCoopSyncVFS"] = "OPFSCoopSyncVFS";
2584
2591
  WASQLiteVFS["AccessHandlePoolVFS"] = "AccessHandlePoolVFS";
2592
+ WASQLiteVFS["OPFSWriteAheadVFS"] = "OPFSWriteAheadVFS";
2585
2593
  })(WASQLiteVFS || (WASQLiteVFS = {}));
2586
2594
  function vfsRequiresDedicatedWorkers(vfs) {
2587
2595
  return vfs != WASQLiteVFS.IDBBatchAtomicVFS;
2588
2596
  }
2589
- /**
2590
- * @internal
2591
- */
2592
- const AsyncWASQLiteModuleFactory = async () => {
2593
- const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-cc5fcc").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs"));
2594
- return factory();
2595
- };
2596
- /**
2597
- * @internal
2598
- */
2599
- const MultiCipherAsyncWASQLiteModuleFactory = async () => {
2600
- const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-c99c07").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs"));
2601
- return factory();
2602
- };
2603
- /**
2604
- * @internal
2605
- */
2606
- const SyncWASQLiteModuleFactory = async () => {
2607
- const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite.mjs"));
2608
- return factory();
2609
- };
2610
- /**
2611
- * @internal
2612
- */
2613
- const MultiCipherSyncWASQLiteModuleFactory = async () => {
2614
- const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-b9c070").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs"));
2615
- return factory();
2616
- };
2597
+ async function asyncModuleFactory(encryptionKey) {
2598
+ if (encryptionKey) {
2599
+ const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite-async.mjs"));
2600
+ return factory();
2601
+ }
2602
+ else {
2603
+ const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs"));
2604
+ return factory();
2605
+ }
2606
+ }
2607
+ async function syncModuleFactory(encryptionKey) {
2608
+ if (encryptionKey) {
2609
+ const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/dist/mc-wa-sqlite.mjs"));
2610
+ return factory();
2611
+ }
2612
+ else {
2613
+ const { default: factory } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/dist/wa-sqlite.mjs */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/dist/wa-sqlite.mjs"));
2614
+ return factory();
2615
+ }
2616
+ }
2617
2617
  /**
2618
2618
  * @internal
2619
2619
  */
2620
2620
  const DEFAULT_MODULE_FACTORIES = {
2621
2621
  [WASQLiteVFS.IDBBatchAtomicVFS]: async (options) => {
2622
- let module;
2623
- if (options.encryptionKey) {
2624
- module = await MultiCipherAsyncWASQLiteModuleFactory();
2625
- }
2626
- else {
2627
- module = await AsyncWASQLiteModuleFactory();
2628
- }
2629
- const { IDBBatchAtomicVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-0df390").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js"));
2622
+ const module = await asyncModuleFactory(options.encryptionKey);
2623
+ const { IDBBatchAtomicVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js"));
2630
2624
  return {
2631
2625
  module,
2632
2626
  // @ts-expect-error The types for this static method are missing upstream
@@ -2634,35 +2628,33 @@ const DEFAULT_MODULE_FACTORIES = {
2634
2628
  };
2635
2629
  },
2636
2630
  [WASQLiteVFS.AccessHandlePoolVFS]: async (options) => {
2637
- let module;
2638
- if (options.encryptionKey) {
2639
- module = await MultiCipherSyncWASQLiteModuleFactory();
2640
- }
2641
- else {
2642
- module = await SyncWASQLiteModuleFactory();
2643
- }
2631
+ const module = await syncModuleFactory(options.encryptionKey);
2644
2632
  // @ts-expect-error The types for this static method are missing upstream
2645
- const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-151024").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js"));
2633
+ const { AccessHandlePoolVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js"));
2646
2634
  return {
2647
2635
  module,
2648
2636
  vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
2649
2637
  };
2650
2638
  },
2651
2639
  [WASQLiteVFS.OPFSCoopSyncVFS]: async (options) => {
2652
- let module;
2653
- if (options.encryptionKey) {
2654
- module = await MultiCipherSyncWASQLiteModuleFactory();
2655
- }
2656
- else {
2657
- module = await SyncWASQLiteModuleFactory();
2658
- }
2640
+ const module = await syncModuleFactory(options.encryptionKey);
2659
2641
  // @ts-expect-error The types for this static method are missing upstream
2660
- const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_5_0_node_modules_journeyapps_wa-sqlite_src_examples-c01ef0").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
2642
+ const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
2661
2643
  const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
2662
2644
  return {
2663
2645
  module,
2664
2646
  vfs
2665
2647
  };
2648
+ },
2649
+ [WASQLiteVFS.OPFSWriteAheadVFS]: async (options) => {
2650
+ const module = await syncModuleFactory(options.encryptionKey);
2651
+ // @ts-expect-error The types for this static method are missing upstream
2652
+ const { OPFSWriteAheadVFS } = await __webpack_require__.e(/*! import() */ "node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js"));
2653
+ const vfs = await OPFSWriteAheadVFS.create(options.dbFileName, module, {});
2654
+ return {
2655
+ module,
2656
+ vfs
2657
+ };
2666
2658
  }
2667
2659
  };
2668
2660
 
@@ -2756,7 +2748,10 @@ class MultiDatabaseServer {
2756
2748
  const { dbFilename } = options;
2757
2749
  let server = this.activeDatabases.get(dbFilename);
2758
2750
  if (server == null) {
2759
- const needsNavigatorLocks = !isSharedWorker;
2751
+ // We don't need navigator locks for shared workers because all queries run in this shared worker exclusively.
2752
+ // For read-only connections, we use a VFS that supports concurrent reads (so a single lock on the connection is
2753
+ // fine).
2754
+ const needsNavigatorLocks = !(isSharedWorker || options.isReadOnly);
2760
2755
  const connection = new _db_adapters_wa_sqlite_RawSqliteConnection_js__WEBPACK_IMPORTED_MODULE_3__.RawSqliteConnection(options);
2761
2756
  const withSafeConcurrency = new _db_adapters_wa_sqlite_ConcurrentConnection_js__WEBPACK_IMPORTED_MODULE_4__.ConcurrentSqliteConnection(connection, needsNavigatorLocks);
2762
2757
  // Initializing the RawSqliteConnection will run some pragmas that might write to the database file, so we want
@@ -2862,9 +2857,6 @@ __webpack_require__.r(__webpack_exports__);
2862
2857
  /* harmony export */ MEMORY_TRIGGER_CLAIM_MANAGER: () => (/* binding */ MEMORY_TRIGGER_CLAIM_MANAGER),
2863
2858
  /* harmony export */ Mutex: () => (/* binding */ Mutex),
2864
2859
  /* harmony export */ OnChangeQueryProcessor: () => (/* binding */ OnChangeQueryProcessor),
2865
- /* harmony export */ OpType: () => (/* binding */ OpType),
2866
- /* harmony export */ OpTypeEnum: () => (/* binding */ OpTypeEnum),
2867
- /* harmony export */ OplogEntry: () => (/* binding */ OplogEntry),
2868
2860
  /* harmony export */ PSInternalTable: () => (/* binding */ PSInternalTable),
2869
2861
  /* harmony export */ PowerSyncControlCommand: () => (/* binding */ PowerSyncControlCommand),
2870
2862
  /* harmony export */ RowUpdateType: () => (/* binding */ RowUpdateType),
@@ -2872,8 +2864,6 @@ __webpack_require__.r(__webpack_exports__);
2872
2864
  /* harmony export */ Semaphore: () => (/* binding */ Semaphore),
2873
2865
  /* harmony export */ SqliteBucketStorage: () => (/* binding */ SqliteBucketStorage),
2874
2866
  /* harmony export */ SyncClientImplementation: () => (/* binding */ SyncClientImplementation),
2875
- /* harmony export */ SyncDataBatch: () => (/* binding */ SyncDataBatch),
2876
- /* harmony export */ SyncDataBucket: () => (/* binding */ SyncDataBucket),
2877
2867
  /* harmony export */ SyncProgress: () => (/* binding */ SyncProgress),
2878
2868
  /* harmony export */ SyncStatus: () => (/* binding */ SyncStatus),
2879
2869
  /* harmony export */ SyncStreamConnectionMethod: () => (/* binding */ SyncStreamConnectionMethod),
@@ -2891,18 +2881,10 @@ __webpack_require__.r(__webpack_exports__);
2891
2881
  /* harmony export */ createLogger: () => (/* binding */ createLogger),
2892
2882
  /* harmony export */ extractTableUpdates: () => (/* binding */ extractTableUpdates),
2893
2883
  /* harmony export */ isBatchedUpdateNotification: () => (/* binding */ isBatchedUpdateNotification),
2894
- /* harmony export */ isContinueCheckpointRequest: () => (/* binding */ isContinueCheckpointRequest),
2895
2884
  /* harmony export */ isDBAdapter: () => (/* binding */ isDBAdapter),
2896
2885
  /* harmony export */ isPowerSyncDatabaseOptionsWithSettings: () => (/* binding */ isPowerSyncDatabaseOptionsWithSettings),
2897
2886
  /* harmony export */ isSQLOpenFactory: () => (/* binding */ isSQLOpenFactory),
2898
2887
  /* harmony export */ isSQLOpenOptions: () => (/* binding */ isSQLOpenOptions),
2899
- /* harmony export */ isStreamingKeepalive: () => (/* binding */ isStreamingKeepalive),
2900
- /* harmony export */ isStreamingSyncCheckpoint: () => (/* binding */ isStreamingSyncCheckpoint),
2901
- /* harmony export */ isStreamingSyncCheckpointComplete: () => (/* binding */ isStreamingSyncCheckpointComplete),
2902
- /* harmony export */ isStreamingSyncCheckpointDiff: () => (/* binding */ isStreamingSyncCheckpointDiff),
2903
- /* harmony export */ isStreamingSyncCheckpointPartiallyComplete: () => (/* binding */ isStreamingSyncCheckpointPartiallyComplete),
2904
- /* harmony export */ isStreamingSyncData: () => (/* binding */ isStreamingSyncData),
2905
- /* harmony export */ isSyncNewCheckpointRequest: () => (/* binding */ isSyncNewCheckpointRequest),
2906
2888
  /* harmony export */ parseQuery: () => (/* binding */ parseQuery),
2907
2889
  /* harmony export */ runOnSchemaChange: () => (/* binding */ runOnSchemaChange),
2908
2890
  /* harmony export */ sanitizeSQL: () => (/* binding */ sanitizeSQL),
@@ -5040,16 +5022,12 @@ class SyncStatus {
5040
5022
  *
5041
5023
  * This returns null when the database is currently being opened and we don't have reliable information about all
5042
5024
  * included streams yet.
5043
- *
5044
- * @experimental Sync streams are currently in alpha.
5045
5025
  */
5046
5026
  get syncStreams() {
5047
5027
  return this.options.dataFlow?.internalStreamSubscriptions?.map((core) => new SyncStreamStatusView(this, core));
5048
5028
  }
5049
5029
  /**
5050
5030
  * If the `stream` appears in {@link syncStreams}, returns the current status for that stream.
5051
- *
5052
- * @experimental Sync streams are currently in alpha.
5053
5031
  */
5054
5032
  forStream(stream) {
5055
5033
  const asJson = JSON.stringify(stream.parameters);
@@ -6402,103 +6380,6 @@ class AbortOperation extends Error {
6402
6380
  }
6403
6381
  }
6404
6382
 
6405
- var OpTypeEnum;
6406
- (function (OpTypeEnum) {
6407
- OpTypeEnum[OpTypeEnum["CLEAR"] = 1] = "CLEAR";
6408
- OpTypeEnum[OpTypeEnum["MOVE"] = 2] = "MOVE";
6409
- OpTypeEnum[OpTypeEnum["PUT"] = 3] = "PUT";
6410
- OpTypeEnum[OpTypeEnum["REMOVE"] = 4] = "REMOVE";
6411
- })(OpTypeEnum || (OpTypeEnum = {}));
6412
- /**
6413
- * Used internally for sync buckets.
6414
- */
6415
- class OpType {
6416
- value;
6417
- static fromJSON(jsonValue) {
6418
- return new OpType(OpTypeEnum[jsonValue]);
6419
- }
6420
- constructor(value) {
6421
- this.value = value;
6422
- }
6423
- toJSON() {
6424
- return Object.entries(OpTypeEnum).find(([, value]) => value === this.value)[0];
6425
- }
6426
- }
6427
-
6428
- class OplogEntry {
6429
- op_id;
6430
- op;
6431
- checksum;
6432
- subkey;
6433
- object_type;
6434
- object_id;
6435
- data;
6436
- static fromRow(row) {
6437
- return new OplogEntry(row.op_id, OpType.fromJSON(row.op), row.checksum, row.subkey, row.object_type, row.object_id, row.data);
6438
- }
6439
- constructor(op_id, op, checksum, subkey, object_type, object_id, data) {
6440
- this.op_id = op_id;
6441
- this.op = op;
6442
- this.checksum = checksum;
6443
- this.subkey = subkey;
6444
- this.object_type = object_type;
6445
- this.object_id = object_id;
6446
- this.data = data;
6447
- }
6448
- toJSON(fixedKeyEncoding = false) {
6449
- return {
6450
- op_id: this.op_id,
6451
- op: this.op.toJSON(),
6452
- object_type: this.object_type,
6453
- object_id: this.object_id,
6454
- checksum: this.checksum,
6455
- data: this.data,
6456
- // Older versions of the JS SDK used to always JSON.stringify here. That has always been wrong,
6457
- // but we need to migrate gradually to not break existing databases.
6458
- subkey: fixedKeyEncoding ? this.subkey : JSON.stringify(this.subkey)
6459
- };
6460
- }
6461
- }
6462
-
6463
- class SyncDataBucket {
6464
- bucket;
6465
- data;
6466
- has_more;
6467
- after;
6468
- next_after;
6469
- static fromRow(row) {
6470
- return new SyncDataBucket(row.bucket, row.data.map((entry) => OplogEntry.fromRow(entry)), row.has_more ?? false, row.after, row.next_after);
6471
- }
6472
- constructor(bucket, data,
6473
- /**
6474
- * True if the response does not contain all the data for this bucket, and another request must be made.
6475
- */
6476
- has_more,
6477
- /**
6478
- * The `after` specified in the request.
6479
- */
6480
- after,
6481
- /**
6482
- * Use this for the next request.
6483
- */
6484
- next_after) {
6485
- this.bucket = bucket;
6486
- this.data = data;
6487
- this.has_more = has_more;
6488
- this.after = after;
6489
- this.next_after = next_after;
6490
- }
6491
- toJSON(fixedKeyEncoding = false) {
6492
- return {
6493
- bucket: this.bucket,
6494
- has_more: this.has_more,
6495
- after: this.after,
6496
- next_after: this.next_after,
6497
- data: this.data.map((entry) => entry.toJSON(fixedKeyEncoding))
6498
- };
6499
- }
6500
- }
6501
-
6502
6383
  var buffer = {};
6503
6384
 
6504
6385
  var base64Js = {};
@@ -13654,7 +13535,7 @@ function requireDist () {
13654
13535
 
13655
13536
  var distExports = requireDist();
13656
13537
 
13657
- var version = "1.51.0";
13538
+ var version = "1.52.0";
13658
13539
  var PACKAGE = {
13659
13540
  version: version};
13660
13541
 
@@ -14211,22 +14092,12 @@ class AbstractRemote {
14211
14092
  * Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
14212
14093
  *
14213
14094
  * The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
14214
- *
14215
- * @param bson A BSON encoder and decoder. When set, the data stream will be requested with a BSON payload
14216
- * (required for compatibility with older sync services).
14217
14095
  */
14218
- async socketStreamRaw(options, bson) {
14096
+ async socketStreamRaw(options) {
14219
14097
  const { path, fetchStrategy = FetchStrategy.Buffered } = options;
14220
- const mimeType = bson == null ? 'application/json' : 'application/bson';
14098
+ const mimeType = 'application/json';
14221
14099
  function toBuffer(js) {
14222
- let contents;
14223
- if (bson != null) {
14224
- contents = bson.serialize(js);
14225
- }
14226
- else {
14227
- contents = JSON.stringify(js);
14228
- }
14229
- return bufferExports.Buffer.from(contents);
14100
+ return bufferExports.Buffer.from(JSON.stringify(js));
14230
14101
  }
14231
14102
  const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;
14232
14103
  const request = await this.buildRequest(path);
@@ -14528,32 +14399,6 @@ function coreStatusToJs(status) {
14528
14399
  };
14529
14400
  }
14530
14401
 
14531
- function isStreamingSyncData(line) {
14532
- return line.data != null;
14533
- }
14534
- function isStreamingKeepalive(line) {
14535
- return line.token_expires_in != null;
14536
- }
14537
- function isStreamingSyncCheckpoint(line) {
14538
- return line.checkpoint != null;
14539
- }
14540
- function isStreamingSyncCheckpointComplete(line) {
14541
- return line.checkpoint_complete != null;
14542
- }
14543
- function isStreamingSyncCheckpointPartiallyComplete(line) {
14544
- return line.partial_checkpoint_complete != null;
14545
- }
14546
- function isStreamingSyncCheckpointDiff(line) {
14547
- return line.checkpoint_diff != null;
14548
- }
14549
- function isContinueCheckpointRequest(request) {
14550
- return (Array.isArray(request.buckets) &&
14551
- typeof request.checkpoint_token == 'string');
14552
- }
14553
- function isSyncNewCheckpointRequest(request) {
14554
- return typeof request.request_checkpoint == 'object';
14555
- }
14556
-
14557
14402
  var LockType;
14558
14403
  (function (LockType) {
14559
14404
  LockType["CRUD"] = "crud";
@@ -14566,35 +14411,21 @@ var SyncStreamConnectionMethod;
14566
14411
  })(SyncStreamConnectionMethod || (SyncStreamConnectionMethod = {}));
14567
14412
  var SyncClientImplementation;
14568
14413
  (function (SyncClientImplementation) {
14569
- /**
14570
- * Decodes and handles sync lines received from the sync service in JavaScript.
14571
- *
14572
- * This is the default option.
14573
- *
14574
- * @deprecated We recommend the {@link RUST} client implementation for all apps. If you have issues with
14575
- * the Rust client, please file an issue or reach out to us. The JavaScript client will be removed in a future
14576
- * version of the PowerSync SDK.
14577
- */
14578
- SyncClientImplementation["JAVASCRIPT"] = "js";
14579
14414
  /**
14580
14415
  * This implementation offloads the sync line decoding and handling into the PowerSync
14581
14416
  * core extension.
14582
14417
  *
14583
- * This option is more performant than the {@link JAVASCRIPT} client, enabled by default and the
14584
- * recommended client implementation for all apps.
14418
+ * This is the only option, as an older JavaScript client implementation has been removed from the SDK.
14585
14419
  *
14586
14420
  * ## Compatibility warning
14587
14421
  *
14588
14422
  * The Rust sync client stores sync data in a format that is slightly different than the one used
14589
- * by the old {@link JAVASCRIPT} implementation. When adopting the {@link RUST} client on existing
14590
- * databases, the PowerSync SDK will migrate the format automatically.
14591
- * Further, the {@link JAVASCRIPT} client in recent versions of the PowerSync JS SDK (starting from
14592
- * the version introducing {@link RUST} as an option) also supports the new format, so you can switch
14593
- * back to {@link JAVASCRIPT} later.
14423
+ * by the old JavaScript client. When adopting the {@link RUST} client on existing databases, the PowerSync SDK will
14424
+ * migrate the format automatically.
14594
14425
  *
14595
- * __However__: Upgrading the SDK version, then adopting {@link RUST} as a sync client and later
14596
- * downgrading the SDK to an older version (necessarily using the JavaScript-based implementation then)
14597
- * can lead to sync issues.
14426
+ * SDK versions supporting both the JavaScript and the Rust client support both formats with the JavaScript client
14427
+ * implementaiton. However, downgrading to an SDK version that only supports the JavaScript client would not be
14428
+ * possible anymore. Problematic SDK versions have been released before 2025-06-09.
14598
14429
  */
14599
14430
  SyncClientImplementation["RUST"] = "rust";
14600
14431
  })(SyncClientImplementation || (SyncClientImplementation = {}));
@@ -14617,13 +14448,7 @@ const DEFAULT_STREAM_CONNECTION_OPTIONS = {
14617
14448
  serializedSchema: undefined,
14618
14449
  includeDefaultStreams: true
14619
14450
  };
14620
- // The priority we assume when we receive checkpoint lines where no priority is set.
14621
- // This is the default priority used by the sync service, but can be set to an arbitrary
14622
- // value since sync services without priorities also won't send partial sync completion
14623
- // messages.
14624
- const FALLBACK_PRIORITY = 3;
14625
14451
  class AbstractStreamingSyncImplementation extends BaseObserver {
14626
- _lastSyncedAt;
14627
14452
  options;
14628
14453
  abortController;
14629
14454
  // In rare cases, mostly for tests, uploads can be triggered without being properly connected.
@@ -14633,6 +14458,7 @@ class AbstractStreamingSyncImplementation extends BaseObserver {
14633
14458
  streamingSyncPromise;
14634
14459
  logger;
14635
14460
  activeStreams;
14461
+ connectionMayHaveChanged = false;
14636
14462
  isUploadingCrud = false;
14637
14463
  notifyCompletedUploads;
14638
14464
  handleActiveStreamsChange;
@@ -14712,9 +14538,6 @@ class AbstractStreamingSyncImplementation extends BaseObserver {
14712
14538
  this.crudUpdateListener = undefined;
14713
14539
  this.uploadAbortController?.abort();
14714
14540
  }
14715
- async hasCompletedSync() {
14716
- return this.options.adapter.hasCompletedSync();
14717
- }
14718
14541
  async getWriteCheckpoint() {
14719
14542
  const clientId = await this.options.adapter.getClientId();
14720
14543
  let path = `/write-checkpoint2.json?client_id=${clientId}`;
@@ -14796,7 +14619,7 @@ The next upload iteration will be delayed.`);
14796
14619
  });
14797
14620
  }
14798
14621
  }
14799
- this.uploadAbortController = null;
14622
+ this.uploadAbortController = undefined;
14800
14623
  }
14801
14624
  });
14802
14625
  }
@@ -14912,6 +14735,11 @@ The next upload iteration will be delayed.`);
14912
14735
  shouldDelayRetry = false;
14913
14736
  // A disconnect was requested, we should not delay since there is no explicit retry
14914
14737
  }
14738
+ else if (this.connectionMayHaveChanged && ex.message?.indexOf('No iteration is active') >= 0) {
14739
+ this.connectionMayHaveChanged = false;
14740
+ this.logger.info('Sync error after changed connection, retrying immediately');
14741
+ shouldDelayRetry = false;
14742
+ }
14915
14743
  else {
14916
14744
  this.logger.error(ex);
14917
14745
  }
@@ -14942,17 +14770,14 @@ The next upload iteration will be delayed.`);
14942
14770
  // Mark as disconnected if here
14943
14771
  this.updateSyncStatus({ connected: false, connecting: false });
14944
14772
  }
14945
- async collectLocalBucketState() {
14946
- const bucketEntries = await this.options.adapter.getBucketStates();
14947
- const req = bucketEntries.map((entry) => ({
14948
- name: entry.bucket,
14949
- after: entry.op_id
14950
- }));
14951
- const localDescriptions = new Map();
14952
- for (const entry of bucketEntries) {
14953
- localDescriptions.set(entry.bucket, null);
14954
- }
14955
- return [req, localDescriptions];
14773
+ markConnectionMayHaveChanged() {
14774
+ // By setting this field, we'll immediately retry if the next sync event causes an error triggered by us not having
14775
+ // an active sync iteration on the connection in use.
14776
+ this.connectionMayHaveChanged = true;
14777
+ // This triggers a `powersync_control` invocation if a sync iteration is currently active. This is a cheap call to
14778
+ // make when no subscriptions have actually changed, we're mainly interested in this immediately throwing if no
14779
+ // iteration is active. That allows us to reconnect ASAP, instead of having to wait for the next sync line.
14780
+ this.handleActiveStreamsChange?.();
14956
14781
  }
14957
14782
  /**
14958
14783
  * Older versions of the JS SDK used to encode subkeys as JSON in {@link OplogEntry.toJSON}.
@@ -14995,19 +14820,13 @@ The next upload iteration will be delayed.`);
14995
14820
  }
14996
14821
  const clientImplementation = resolvedOptions.clientImplementation;
14997
14822
  this.updateSyncStatus({ clientImplementation });
14998
- if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
14999
- await this.legacyStreamingSyncIteration(signal, resolvedOptions);
15000
- return null;
15001
- }
15002
- else {
15003
- await this.requireKeyFormat(true);
15004
- return await this.rustSyncIteration(signal, resolvedOptions);
15005
- }
14823
+ await this.requireKeyFormat(true);
14824
+ return await this.rustSyncIteration(signal, resolvedOptions);
15006
14825
  }
15007
14826
  });
15008
14827
  }
15009
14828
  async receiveSyncLines(data) {
15010
- const { options, connection, bson } = data;
14829
+ const { options, connection } = data;
15011
14830
  const remote = this.options.remote;
15012
14831
  if (connection.connectionMethod == SyncStreamConnectionMethod.HTTP) {
15013
14832
  return await remote.fetchStream(options);
@@ -15016,232 +14835,8 @@ The next upload iteration will be delayed.`);
15016
14835
  return await this.options.remote.socketStreamRaw({
15017
14836
  ...options,
15018
14837
  ...{ fetchStrategy: connection.fetchStrategy }
15019
- }, bson);
15020
- }
15021
- }
15022
- async legacyStreamingSyncIteration(signal, resolvedOptions) {
15023
- const rawTables = resolvedOptions.serializedSchema?.raw_tables;
15024
- if (rawTables != null && rawTables.length) {
15025
- this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.');
15026
- }
15027
- if (this.activeStreams.length) {
15028
- this.logger.error('Sync streams require `clientImplementation: SyncClientImplementation.RUST` when connecting.');
15029
- }
15030
- this.logger.debug('Streaming sync iteration started');
15031
- this.options.adapter.startSession();
15032
- let [req, bucketMap] = await this.collectLocalBucketState();
15033
- let targetCheckpoint = null;
15034
- // A checkpoint that has been validated but not applied (e.g. due to pending local writes)
15035
- let pendingValidatedCheckpoint = null;
15036
- const clientId = await this.options.adapter.getClientId();
15037
- const usingFixedKeyFormat = await this.requireKeyFormat(false);
15038
- this.logger.debug('Requesting stream from server');
15039
- const syncOptions = {
15040
- path: '/sync/stream',
15041
- abortSignal: signal,
15042
- data: {
15043
- buckets: req,
15044
- include_checksum: true,
15045
- raw_data: true,
15046
- parameters: resolvedOptions.params,
15047
- app_metadata: resolvedOptions.appMetadata,
15048
- client_id: clientId
15049
- }
15050
- };
15051
- const bson = await this.options.remote.getBSON();
15052
- const source = await this.receiveSyncLines({
15053
- options: syncOptions,
15054
- connection: resolvedOptions,
15055
- bson
15056
- });
15057
- const stream = injectable(map(source, (line) => {
15058
- if (typeof line == 'string') {
15059
- return JSON.parse(line);
15060
- }
15061
- else {
15062
- return bson.deserialize(line);
15063
- }
15064
- }));
15065
- this.logger.debug('Stream established. Processing events');
15066
- this.notifyCompletedUploads = () => {
15067
- stream.inject({ crud_upload_completed: null });
15068
- };
15069
- while (true) {
15070
- const { value: line, done } = await stream.next();
15071
- if (done) {
15072
- // The stream has closed while waiting
15073
- return;
15074
- }
15075
- if ('crud_upload_completed' in line) {
15076
- if (pendingValidatedCheckpoint != null) {
15077
- const { applied, endIteration } = await this.applyCheckpoint(pendingValidatedCheckpoint);
15078
- if (applied) {
15079
- pendingValidatedCheckpoint = null;
15080
- }
15081
- else if (endIteration) {
15082
- break;
15083
- }
15084
- }
15085
- continue;
15086
- }
15087
- // A connection is active and messages are being received
15088
- if (!this.syncStatus.connected) {
15089
- // There is a connection now
15090
- Promise.resolve().then(() => this.triggerCrudUpload());
15091
- this.updateSyncStatus({
15092
- connected: true
15093
- });
15094
- }
15095
- if (isStreamingSyncCheckpoint(line)) {
15096
- targetCheckpoint = line.checkpoint;
15097
- // New checkpoint - existing validated checkpoint is no longer valid
15098
- pendingValidatedCheckpoint = null;
15099
- const bucketsToDelete = new Set(bucketMap.keys());
15100
- const newBuckets = new Map();
15101
- for (const checksum of line.checkpoint.buckets) {
15102
- newBuckets.set(checksum.bucket, {
15103
- name: checksum.bucket,
15104
- priority: checksum.priority ?? FALLBACK_PRIORITY
15105
- });
15106
- bucketsToDelete.delete(checksum.bucket);
15107
- }
15108
- if (bucketsToDelete.size > 0) {
15109
- this.logger.debug('Removing buckets', [...bucketsToDelete]);
15110
- }
15111
- bucketMap = newBuckets;
15112
- await this.options.adapter.removeBuckets([...bucketsToDelete]);
15113
- await this.options.adapter.setTargetCheckpoint(targetCheckpoint);
15114
- await this.updateSyncStatusForStartingCheckpoint(targetCheckpoint);
15115
- }
15116
- else if (isStreamingSyncCheckpointComplete(line)) {
15117
- const result = await this.applyCheckpoint(targetCheckpoint);
15118
- if (result.endIteration) {
15119
- return;
15120
- }
15121
- else if (!result.applied) {
15122
- // "Could not apply checkpoint due to local data". We need to retry after
15123
- // finishing uploads.
15124
- pendingValidatedCheckpoint = targetCheckpoint;
15125
- }
15126
- else {
15127
- // Nothing to retry later. This would likely already be null from the last
15128
- // checksum or checksum_diff operation, but we make sure.
15129
- pendingValidatedCheckpoint = null;
15130
- }
15131
- }
15132
- else if (isStreamingSyncCheckpointPartiallyComplete(line)) {
15133
- const priority = line.partial_checkpoint_complete.priority;
15134
- this.logger.debug('Partial checkpoint complete', priority);
15135
- const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint, priority);
15136
- if (!result.checkpointValid) {
15137
- // This means checksums failed. Start again with a new checkpoint.
15138
- // TODO: better back-off
15139
- await new Promise((resolve) => setTimeout(resolve, 50));
15140
- return;
15141
- }
15142
- else if (!result.ready) ;
15143
- else {
15144
- // We'll keep on downloading, but can report that this priority is synced now.
15145
- this.logger.debug('partial checkpoint validation succeeded');
15146
- // All states with a higher priority can be deleted since this partial sync includes them.
15147
- const priorityStates = this.syncStatus.priorityStatusEntries.filter((s) => s.priority <= priority);
15148
- priorityStates.push({
15149
- priority,
15150
- lastSyncedAt: new Date(),
15151
- hasSynced: true
15152
- });
15153
- this.updateSyncStatus({
15154
- connected: true,
15155
- priorityStatusEntries: priorityStates
15156
- });
15157
- }
15158
- }
15159
- else if (isStreamingSyncCheckpointDiff(line)) {
15160
- // TODO: It may be faster to just keep track of the diff, instead of the entire checkpoint
15161
- if (targetCheckpoint == null) {
15162
- throw new Error('Checkpoint diff without previous checkpoint');
15163
- }
15164
- // New checkpoint - existing validated checkpoint is no longer valid
15165
- pendingValidatedCheckpoint = null;
15166
- const diff = line.checkpoint_diff;
15167
- const newBuckets = new Map();
15168
- for (const checksum of targetCheckpoint.buckets) {
15169
- newBuckets.set(checksum.bucket, checksum);
15170
- }
15171
- for (const checksum of diff.updated_buckets) {
15172
- newBuckets.set(checksum.bucket, checksum);
15173
- }
15174
- for (const bucket of diff.removed_buckets) {
15175
- newBuckets.delete(bucket);
15176
- }
15177
- const newCheckpoint = {
15178
- last_op_id: diff.last_op_id,
15179
- buckets: [...newBuckets.values()],
15180
- write_checkpoint: diff.write_checkpoint
15181
- };
15182
- targetCheckpoint = newCheckpoint;
15183
- await this.updateSyncStatusForStartingCheckpoint(targetCheckpoint);
15184
- bucketMap = new Map();
15185
- newBuckets.forEach((checksum, name) => bucketMap.set(name, {
15186
- name: checksum.bucket,
15187
- priority: checksum.priority ?? FALLBACK_PRIORITY
15188
- }));
15189
- const bucketsToDelete = diff.removed_buckets;
15190
- if (bucketsToDelete.length > 0) {
15191
- this.logger.debug('Remove buckets', bucketsToDelete);
15192
- }
15193
- await this.options.adapter.removeBuckets(bucketsToDelete);
15194
- await this.options.adapter.setTargetCheckpoint(targetCheckpoint);
15195
- }
15196
- else if (isStreamingSyncData(line)) {
15197
- const { data } = line;
15198
- const previousProgress = this.syncStatus.dataFlowStatus.downloadProgress;
15199
- let updatedProgress = null;
15200
- if (previousProgress) {
15201
- updatedProgress = { ...previousProgress };
15202
- const progressForBucket = updatedProgress[data.bucket];
15203
- if (progressForBucket) {
15204
- updatedProgress[data.bucket] = {
15205
- ...progressForBucket,
15206
- since_last: progressForBucket.since_last + data.data.length
15207
- };
15208
- }
15209
- }
15210
- this.updateSyncStatus({
15211
- dataFlow: {
15212
- downloading: true,
15213
- downloadProgress: updatedProgress
15214
- }
15215
- });
15216
- await this.options.adapter.saveSyncData({ buckets: [SyncDataBucket.fromRow(data)] }, usingFixedKeyFormat);
15217
- }
15218
- else if (isStreamingKeepalive(line)) {
15219
- const remaining_seconds = line.token_expires_in;
15220
- if (remaining_seconds == 0) {
15221
- // Connection would be closed automatically right after this
15222
- this.logger.debug('Token expiring; reconnect');
15223
- /**
15224
- * For a rare case where the backend connector does not update the token
15225
- * (uses the same one), this should have some delay.
15226
- */
15227
- await this.delayRetry();
15228
- return;
15229
- }
15230
- else if (remaining_seconds < 30) {
15231
- this.logger.debug('Token will expire soon; reconnect');
15232
- // Pre-emptively refresh the token
15233
- this.options.remote.invalidateCredentials();
15234
- return;
15235
- }
15236
- this.triggerCrudUpload();
15237
- }
15238
- else {
15239
- this.logger.debug('Received unknown sync line', line);
15240
- }
14838
+ });
15241
14839
  }
15242
- this.logger.debug('Stream input empty');
15243
- // Connection closed. Likely due to auth issue.
15244
- return;
15245
14840
  }
15246
14841
  async rustSyncIteration(signal, resolvedOptions) {
15247
14842
  const syncImplementation = this;
@@ -15314,6 +14909,10 @@ The next upload iteration will be delayed.`);
15314
14909
  const rawResponse = await adapter.control(op, payload ?? null);
15315
14910
  const logger = syncImplementation.logger;
15316
14911
  logger.trace('powersync_control', op, payload == null || typeof payload == 'string' ? payload : '<bytes>', rawResponse);
14912
+ if (op != PowerSyncControlCommand.STOP) {
14913
+ // Evidently we have a working connection here, otherwise powersync_control would have failed.
14914
+ syncImplementation.connectionMayHaveChanged = false;
14915
+ }
15317
14916
  await handleInstructions(JSON.parse(rawResponse));
15318
14917
  }
15319
14918
  async function handleInstruction(instruction) {
@@ -15400,68 +14999,6 @@ The next upload iteration will be delayed.`);
15400
14999
  }
15401
15000
  return { immediateRestart: hideDisconnectOnRestart };
15402
15001
  }
15403
- async updateSyncStatusForStartingCheckpoint(checkpoint) {
15404
- const localProgress = await this.options.adapter.getBucketOperationProgress();
15405
- const progress = {};
15406
- let invalidated = false;
15407
- for (const bucket of checkpoint.buckets) {
15408
- const savedProgress = localProgress[bucket.bucket];
15409
- const atLast = savedProgress?.atLast ?? 0;
15410
- const sinceLast = savedProgress?.sinceLast ?? 0;
15411
- progress[bucket.bucket] = {
15412
- // The fallback priority doesn't matter here, but 3 is the one newer versions of the sync service
15413
- // will use by default.
15414
- priority: bucket.priority ?? 3,
15415
- at_last: atLast,
15416
- since_last: sinceLast,
15417
- target_count: bucket.count ?? 0
15418
- };
15419
- if (bucket.count != null && bucket.count < atLast + sinceLast) {
15420
- // Either due to a defrag / sync rule deploy or a compaction operation, the size
15421
- // of the bucket shrank so much that the local ops exceed the ops in the updated
15422
- // bucket. We can't prossibly report progress in this case (it would overshoot 100%).
15423
- invalidated = true;
15424
- }
15425
- }
15426
- if (invalidated) {
15427
- for (const bucket in progress) {
15428
- const bucketProgress = progress[bucket];
15429
- bucketProgress.at_last = 0;
15430
- bucketProgress.since_last = 0;
15431
- }
15432
- }
15433
- this.updateSyncStatus({
15434
- dataFlow: {
15435
- downloading: true,
15436
- downloadProgress: progress
15437
- }
15438
- });
15439
- }
15440
- async applyCheckpoint(checkpoint) {
15441
- let result = await this.options.adapter.syncLocalDatabase(checkpoint);
15442
- if (!result.checkpointValid) {
15443
- this.logger.debug(`Checksum mismatch in checkpoint ${checkpoint.last_op_id}, will reconnect`);
15444
- // This means checksums failed. Start again with a new checkpoint.
15445
- // TODO: better back-off
15446
- await new Promise((resolve) => setTimeout(resolve, 50));
15447
- return { applied: false, endIteration: true };
15448
- }
15449
- else if (!result.ready) {
15450
- this.logger.debug(`Could not apply checkpoint ${checkpoint.last_op_id} due to local data. We will retry applying the checkpoint after that upload is completed.`);
15451
- return { applied: false, endIteration: false };
15452
- }
15453
- this.logger.debug(`Applied checkpoint ${checkpoint.last_op_id}`, checkpoint);
15454
- this.updateSyncStatus({
15455
- connected: true,
15456
- lastSyncedAt: new Date(),
15457
- dataFlow: {
15458
- downloading: false,
15459
- downloadProgress: null,
15460
- downloadError: undefined
15461
- }
15462
- });
15463
- return { applied: true, endIteration: false };
15464
- }
15465
15002
  updateSyncStatus(options) {
15466
15003
  const updatedStatus = new SyncStatus({
15467
15004
  connected: options.connected ?? this.syncStatus.connected,
@@ -17000,14 +16537,12 @@ class SqliteBucketStorage extends BaseObserver {
17000
16537
  db;
17001
16538
  logger;
17002
16539
  tableNames;
17003
- _hasCompletedSync;
17004
16540
  updateListener;
17005
16541
  _clientId;
17006
16542
  constructor(db, logger = Logger.get('SqliteBucketStorage')) {
17007
16543
  super();
17008
16544
  this.db = db;
17009
16545
  this.logger = logger;
17010
- this._hasCompletedSync = false;
17011
16546
  this.tableNames = new Set();
17012
16547
  this.updateListener = db.registerListener({
17013
16548
  tablesUpdated: (update) => {
@@ -17019,7 +16554,6 @@ class SqliteBucketStorage extends BaseObserver {
17019
16554
  });
17020
16555
  }
17021
16556
  async init() {
17022
- this._hasCompletedSync = false;
17023
16557
  const existingTableRows = await this.db.getAll(`SELECT name FROM sqlite_master WHERE type='table' AND name GLOB 'ps_data_*'`);
17024
16558
  for (const row of existingTableRows ?? []) {
17025
16559
  this.tableNames.add(row.name);
@@ -17041,156 +16575,6 @@ class SqliteBucketStorage extends BaseObserver {
17041
16575
  getMaxOpId() {
17042
16576
  return MAX_OP_ID;
17043
16577
  }
17044
- /**
17045
- * Reset any caches.
17046
- */
17047
- startSession() { }
17048
- async getBucketStates() {
17049
- const result = await this.db.getAll("SELECT name as bucket, cast(last_op as TEXT) as op_id FROM ps_buckets WHERE pending_delete = 0 AND name != '$local'");
17050
- return result;
17051
- }
17052
- async getBucketOperationProgress() {
17053
- const rows = await this.db.getAll('SELECT name, count_at_last, count_since_last FROM ps_buckets');
17054
- return Object.fromEntries(rows.map((r) => [r.name, { atLast: r.count_at_last, sinceLast: r.count_since_last }]));
17055
- }
17056
- async saveSyncData(batch, fixedKeyFormat = false) {
17057
- await this.writeTransaction(async (tx) => {
17058
- for (const b of batch.buckets) {
17059
- await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
17060
- 'save',
17061
- JSON.stringify({ buckets: [b.toJSON(fixedKeyFormat)] })
17062
- ]);
17063
- this.logger.debug(`Saved batch of data for bucket: ${b.bucket}, operations: ${b.data.length}`);
17064
- }
17065
- });
17066
- }
17067
- async removeBuckets(buckets) {
17068
- for (const bucket of buckets) {
17069
- await this.deleteBucket(bucket);
17070
- }
17071
- }
17072
- /**
17073
- * Mark a bucket for deletion.
17074
- */
17075
- async deleteBucket(bucket) {
17076
- await this.writeTransaction(async (tx) => {
17077
- await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', ['delete_bucket', bucket]);
17078
- });
17079
- this.logger.debug(`Done deleting bucket ${bucket}`);
17080
- }
17081
- async hasCompletedSync() {
17082
- if (this._hasCompletedSync) {
17083
- return true;
17084
- }
17085
- const r = await this.db.get(`SELECT powersync_last_synced_at() as synced_at`);
17086
- const completed = r.synced_at != null;
17087
- if (completed) {
17088
- this._hasCompletedSync = true;
17089
- }
17090
- return completed;
17091
- }
17092
- async syncLocalDatabase(checkpoint, priority) {
17093
- const r = await this.validateChecksums(checkpoint, priority);
17094
- if (!r.checkpointValid) {
17095
- this.logger.error('Checksums failed for', r.checkpointFailures);
17096
- for (const b of r.checkpointFailures ?? []) {
17097
- await this.deleteBucket(b);
17098
- }
17099
- return { ready: false, checkpointValid: false, checkpointFailures: r.checkpointFailures };
17100
- }
17101
- if (priority == null) {
17102
- this.logger.debug(`Validated checksums checkpoint ${checkpoint.last_op_id}`);
17103
- }
17104
- else {
17105
- this.logger.debug(`Validated checksums for partial checkpoint ${checkpoint.last_op_id}, priority ${priority}`);
17106
- }
17107
- let buckets = checkpoint.buckets;
17108
- if (priority !== undefined) {
17109
- buckets = buckets.filter((b) => hasMatchingPriority(priority, b));
17110
- }
17111
- const bucketNames = buckets.map((b) => b.bucket);
17112
- await this.writeTransaction(async (tx) => {
17113
- await tx.execute(`UPDATE ps_buckets SET last_op = ? WHERE name IN (SELECT json_each.value FROM json_each(?))`, [
17114
- checkpoint.last_op_id,
17115
- JSON.stringify(bucketNames)
17116
- ]);
17117
- if (priority == null && checkpoint.write_checkpoint) {
17118
- await tx.execute("UPDATE ps_buckets SET last_op = ? WHERE name = '$local'", [checkpoint.write_checkpoint]);
17119
- }
17120
- });
17121
- const valid = await this.updateObjectsFromBuckets(checkpoint, priority);
17122
- if (!valid) {
17123
- return { ready: false, checkpointValid: true };
17124
- }
17125
- return {
17126
- ready: true,
17127
- checkpointValid: true
17128
- };
17129
- }
17130
- /**
17131
- * Atomically update the local state to the current checkpoint.
17132
- *
17133
- * This includes creating new tables, dropping old tables, and copying data over from the oplog.
17134
- */
17135
- async updateObjectsFromBuckets(checkpoint, priority) {
17136
- let arg = '';
17137
- if (priority !== undefined) {
17138
- const affectedBuckets = [];
17139
- for (const desc of checkpoint.buckets) {
17140
- if (hasMatchingPriority(priority, desc)) {
17141
- affectedBuckets.push(desc.bucket);
17142
- }
17143
- }
17144
- arg = JSON.stringify({ priority, buckets: affectedBuckets });
17145
- }
17146
- return this.writeTransaction(async (tx) => {
17147
- const { insertId: result } = await tx.execute('INSERT INTO powersync_operations(op, data) VALUES(?, ?)', [
17148
- 'sync_local',
17149
- arg
17150
- ]);
17151
- if (result == 1) {
17152
- if (priority == null) {
17153
- const bucketToCount = Object.fromEntries(checkpoint.buckets.map((b) => [b.bucket, b.count]));
17154
- // The two parameters could be replaced with one, but: https://github.com/powersync-ja/better-sqlite3/pull/6
17155
- const jsonBucketCount = JSON.stringify(bucketToCount);
17156
- await tx.execute("UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?->name WHERE name != '$local' AND ?->name IS NOT NULL", [jsonBucketCount, jsonBucketCount]);
17157
- }
17158
- return true;
17159
- }
17160
- else {
17161
- return false;
17162
- }
17163
- });
17164
- }
17165
- async validateChecksums(checkpoint, priority) {
17166
- if (priority !== undefined) {
17167
- // Only validate the buckets within the priority we care about
17168
- const newBuckets = checkpoint.buckets.filter((cs) => hasMatchingPriority(priority, cs));
17169
- checkpoint = { ...checkpoint, buckets: newBuckets };
17170
- }
17171
- const rs = await this.db.execute('SELECT powersync_validate_checkpoint(?) as result', [
17172
- JSON.stringify({ ...checkpoint })
17173
- ]);
17174
- const resultItem = rs.rows?.item(0);
17175
- if (!resultItem) {
17176
- return {
17177
- checkpointValid: false,
17178
- ready: false,
17179
- checkpointFailures: []
17180
- };
17181
- }
17182
- const result = JSON.parse(resultItem['result']);
17183
- if (result['valid']) {
17184
- return { ready: true, checkpointValid: true };
17185
- }
17186
- else {
17187
- return {
17188
- checkpointValid: false,
17189
- ready: false,
17190
- checkpointFailures: result['failed_buckets']
17191
- };
17192
- }
17193
- }
17194
16578
  async updateLocalTarget(cb) {
17195
16579
  const rs1 = await this.db.getAll("SELECT target_op FROM ps_buckets WHERE name = '$local' AND target_op = CAST(? as INTEGER)", [MAX_OP_ID]);
17196
16580
  if (!rs1.length) {
@@ -17281,12 +16665,6 @@ class SqliteBucketStorage extends BaseObserver {
17281
16665
  async writeTransaction(callback, options) {
17282
16666
  return this.db.writeTransaction(callback, options);
17283
16667
  }
17284
- /**
17285
- * Set a target checkpoint.
17286
- */
17287
- async setTargetCheckpoint(checkpoint) {
17288
- // No-op for now
17289
- }
17290
16668
  async control(op, payload) {
17291
16669
  return await this.writeTransaction(async (tx) => {
17292
16670
  const [[raw]] = await tx.executeRaw('SELECT powersync_control(?, ?)', [op, payload]);
@@ -17310,20 +16688,6 @@ class SqliteBucketStorage extends BaseObserver {
17310
16688
  }
17311
16689
  static _subkeyMigrationKey = 'powersync_js_migrated_subkeys';
17312
16690
  }
17313
- function hasMatchingPriority(priority, bucket) {
17314
- return bucket.priority != null && bucket.priority <= priority;
17315
- }
17316
-
17317
- // TODO JSON
17318
- class SyncDataBatch {
17319
- buckets;
17320
- static fromJSON(json) {
17321
- return new SyncDataBatch(json.buckets.map((bucket) => SyncDataBucket.fromRow(bucket)));
17322
- }
17323
- constructor(buckets) {
17324
- this.buckets = buckets;
17325
- }
17326
- }
17327
16691
 
17328
16692
  /**
17329
16693
  * Thrown when an underlying database connection is closed.
@@ -17383,10 +16747,8 @@ class Schema {
17383
16747
  * developer instead of automatically by PowerSync.
17384
16748
  * Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
17385
16749
  * using client-side table and column constraints.
17386
- * Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
17387
16750
  *
17388
16751
  * @param tables An object of (table name, raw table definition) entries.
17389
- * @experimental Note that the raw tables API is still experimental and may change in the future.
17390
16752
  */
17391
16753
  withRawTables(tables) {
17392
16754
  for (const [name, rawTableDefinition] of Object.entries(tables)) {
@@ -17759,7 +17121,7 @@ var __webpack_exports__ = {};
17759
17121
  !*** ./lib/src/worker/db/WASQLiteDB.worker.js ***!
17760
17122
  \************************************************/
17761
17123
  __webpack_require__.r(__webpack_exports__);
17762
- /* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.5.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
17124
+ /* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
17763
17125
  /* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @powersync/common */ "../common/dist/bundle.mjs");
17764
17126
  /* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! comlink */ "../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/dist/esm/comlink.mjs");
17765
17127
  /* harmony import */ var _MultiDatabaseServer_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./MultiDatabaseServer.js */ "./lib/src/worker/db/MultiDatabaseServer.js");