@powersync/web 1.29.1 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +1 -1
  2. package/dist/0b19af1befc07ce338dd.wasm +0 -0
  3. package/dist/2632c3bda9473da74fd5.wasm +0 -0
  4. package/dist/64f5351ba3784bfe2f3e.wasm +0 -0
  5. package/dist/9318ca94aac4d0fe0135.wasm +0 -0
  6. package/dist/index.umd.js +7258 -1847
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/worker/SharedSyncImplementation.umd.js +548 -290
  9. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  10. package/dist/worker/WASQLiteDB.umd.js +192 -126
  11. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  12. package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js +3 -3
  13. package/dist/worker/node_modules_bson_lib_bson_mjs.umd.js.map +1 -1
  14. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js +22 -9
  15. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite-async_mjs.umd.js.map +1 -1
  16. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js +22 -9
  17. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_mc-wa-sqlite_mjs.umd.js.map +1 -1
  18. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js +22 -9
  19. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite-async_mjs.umd.js.map +1 -1
  20. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +22 -9
  21. package/dist/worker/node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -1
  22. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js +9 -9
  23. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js.umd.js.map +1 -1
  24. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js +32 -35
  25. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_IDBBatchAtomicVFS_js.umd.js.map +1 -1
  26. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js +27 -20
  27. package/dist/worker/node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js.umd.js.map +1 -1
  28. package/lib/package.json +5 -5
  29. package/lib/src/db/PowerSyncDatabase.d.ts +1 -1
  30. package/lib/src/db/PowerSyncDatabase.js +4 -4
  31. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +17 -0
  32. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +109 -19
  33. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +5 -1
  34. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +14 -7
  35. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +11 -2
  36. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +1 -1
  37. package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +2 -2
  38. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +2 -5
  39. package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +51 -35
  40. package/lib/src/worker/sync/SharedSyncImplementation.d.ts +18 -8
  41. package/lib/src/worker/sync/SharedSyncImplementation.js +204 -108
  42. package/lib/src/worker/sync/SharedSyncImplementation.worker.js +1 -1
  43. package/lib/src/worker/sync/WorkerClient.d.ts +4 -5
  44. package/lib/src/worker/sync/WorkerClient.js +7 -9
  45. package/lib/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +6 -6
  47. package/src/db/PowerSyncDatabase.ts +13 -15
  48. package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +126 -25
  49. package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +18 -6
  50. package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +11 -3
  51. package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +3 -3
  52. package/src/db/sync/SharedWebStreamingSyncImplementation.ts +65 -47
  53. package/src/worker/db/WASQLiteDB.worker.ts +0 -1
  54. package/src/worker/sync/SharedSyncImplementation.ts +234 -119
  55. package/src/worker/sync/SharedSyncImplementation.worker.ts +1 -1
  56. package/src/worker/sync/WorkerClient.ts +9 -13
  57. package/dist/10072fe45f0a8fab0a0e.wasm +0 -0
  58. package/dist/6e435e51534839845554.wasm +0 -0
  59. package/dist/a730f7ca717b02234beb.wasm +0 -0
  60. package/dist/aa2f408d64445fed090e.wasm +0 -0
@@ -3,11 +3,11 @@ var sdk_web;
3
3
  /******/ "use strict";
4
4
  /******/ var __webpack_modules__ = ({
5
5
 
6
- /***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js":
6
+ /***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js"
7
7
  /*!*******************************************************************!*\
8
8
  !*** ../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js ***!
9
9
  \*******************************************************************/
10
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
10
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
11
11
 
12
12
  __webpack_require__.r(__webpack_exports__);
13
13
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -1147,8 +1147,11 @@ function Factory(Module) {
1147
1147
  // Wait for all pending retry operations to complete. This is
1148
1148
  // normally empty on the first loop iteration.
1149
1149
  if (Module.retryOps.length) {
1150
- await Promise.all(Module.retryOps);
1151
- Module.retryOps = [];
1150
+ try {
1151
+ await Promise.all(Module.retryOps);
1152
+ } finally {
1153
+ Module.retryOps = [];
1154
+ }
1152
1155
  }
1153
1156
 
1154
1157
  rc = await f();
@@ -1193,13 +1196,13 @@ function decl(s) {
1193
1196
  }
1194
1197
 
1195
1198
 
1196
- /***/ }),
1199
+ /***/ },
1197
1200
 
1198
- /***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js":
1201
+ /***/ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js"
1199
1202
  /*!*************************************************************************!*\
1200
1203
  !*** ../../node_modules/@journeyapps/wa-sqlite/src/sqlite-constants.js ***!
1201
1204
  \*************************************************************************/
1202
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1205
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
1203
1206
 
1204
1207
  __webpack_require__.r(__webpack_exports__);
1205
1208
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -1712,13 +1715,13 @@ const SQLITE_PREPARE_PERSISTENT = 0x01;
1712
1715
  const SQLITE_PREPARE_NORMALIZED = 0x02;
1713
1716
  const SQLITE_PREPARE_NO_VTAB = 0x04;
1714
1717
 
1715
- /***/ }),
1718
+ /***/ },
1716
1719
 
1717
- /***/ "../../node_modules/async-mutex/index.mjs":
1720
+ /***/ "../../node_modules/async-mutex/index.mjs"
1718
1721
  /*!************************************************!*\
1719
1722
  !*** ../../node_modules/async-mutex/index.mjs ***!
1720
1723
  \************************************************/
1721
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1724
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
1722
1725
 
1723
1726
  __webpack_require__.r(__webpack_exports__);
1724
1727
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -2023,13 +2026,13 @@ function tryAcquire(sync, alreadyAcquiredError = E_ALREADY_LOCKED) {
2023
2026
 
2024
2027
 
2025
2028
 
2026
- /***/ }),
2029
+ /***/ },
2027
2030
 
2028
- /***/ "../../node_modules/comlink/dist/esm/comlink.mjs":
2031
+ /***/ "../../node_modules/comlink/dist/esm/comlink.mjs"
2029
2032
  /*!*******************************************************!*\
2030
2033
  !*** ../../node_modules/comlink/dist/esm/comlink.mjs ***!
2031
2034
  \*******************************************************/
2032
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2035
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
2033
2036
 
2034
2037
  __webpack_require__.r(__webpack_exports__);
2035
2038
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -2404,13 +2407,13 @@ function generateUUID() {
2404
2407
  //# sourceMappingURL=comlink.mjs.map
2405
2408
 
2406
2409
 
2407
- /***/ }),
2410
+ /***/ },
2408
2411
 
2409
- /***/ "../common/dist/bundle.mjs":
2412
+ /***/ "../common/dist/bundle.mjs"
2410
2413
  /*!*********************************!*\
2411
2414
  !*** ../common/dist/bundle.mjs ***!
2412
2415
  \*********************************/
2413
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
2416
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
2414
2417
 
2415
2418
  __webpack_require__.r(__webpack_exports__);
2416
2419
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -2424,6 +2427,7 @@ __webpack_require__.r(__webpack_exports__);
2424
2427
  /* harmony export */ BaseObserver: () => (/* binding */ BaseObserver),
2425
2428
  /* harmony export */ Column: () => (/* binding */ Column),
2426
2429
  /* harmony export */ ColumnType: () => (/* binding */ ColumnType),
2430
+ /* harmony export */ ConnectionClosedError: () => (/* binding */ ConnectionClosedError),
2427
2431
  /* harmony export */ ConnectionManager: () => (/* binding */ ConnectionManager),
2428
2432
  /* harmony export */ ControlledExecutor: () => (/* binding */ ControlledExecutor),
2429
2433
  /* harmony export */ CrudBatch: () => (/* binding */ CrudBatch),
@@ -3228,12 +3232,30 @@ class SyncStatus {
3228
3232
  return {
3229
3233
  connected: this.connected,
3230
3234
  connecting: this.connecting,
3231
- dataFlow: this.dataFlowStatus,
3235
+ dataFlow: {
3236
+ ...this.dataFlowStatus,
3237
+ uploadError: this.serializeError(this.dataFlowStatus.uploadError),
3238
+ downloadError: this.serializeError(this.dataFlowStatus.downloadError)
3239
+ },
3232
3240
  lastSyncedAt: this.lastSyncedAt,
3233
3241
  hasSynced: this.hasSynced,
3234
3242
  priorityStatusEntries: this.priorityStatusEntries
3235
3243
  };
3236
3244
  }
3245
+ /**
3246
+ * Not all errors are serializable over a MessagePort. E.g. some `DomExceptions` fail to be passed across workers.
3247
+ * This explicitly serializes errors in the SyncStatus.
3248
+ */
3249
+ serializeError(error) {
3250
+ if (typeof error == 'undefined') {
3251
+ return undefined;
3252
+ }
3253
+ return {
3254
+ name: error.name,
3255
+ message: error.message,
3256
+ stack: error.stack
3257
+ };
3258
+ }
3237
3259
  static comparePriorities(a, b) {
3238
3260
  return b.priority - a.priority; // Reverse because higher priorities have lower numbers
3239
3261
  }
@@ -4846,7 +4868,7 @@ var hasRequiredBuffer$1;
4846
4868
  function requireBuffer$1 () {
4847
4869
  if (hasRequiredBuffer$1) return buffer$1;
4848
4870
  hasRequiredBuffer$1 = 1;
4849
- (function (exports) {
4871
+ (function (exports$1) {
4850
4872
 
4851
4873
  const base64 = requireBase64Js();
4852
4874
  const ieee754 = requireIeee754();
@@ -4855,12 +4877,12 @@ function requireBuffer$1 () {
4855
4877
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
4856
4878
  : null;
4857
4879
 
4858
- exports.Buffer = Buffer;
4859
- exports.SlowBuffer = SlowBuffer;
4860
- exports.INSPECT_MAX_BYTES = 50;
4880
+ exports$1.Buffer = Buffer;
4881
+ exports$1.SlowBuffer = SlowBuffer;
4882
+ exports$1.INSPECT_MAX_BYTES = 50;
4861
4883
 
4862
4884
  const K_MAX_LENGTH = 0x7fffffff;
4863
- exports.kMaxLength = K_MAX_LENGTH;
4885
+ exports$1.kMaxLength = K_MAX_LENGTH;
4864
4886
 
4865
4887
  /**
4866
4888
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -5456,7 +5478,7 @@ function requireBuffer$1 () {
5456
5478
 
5457
5479
  Buffer.prototype.inspect = function inspect () {
5458
5480
  let str = '';
5459
- const max = exports.INSPECT_MAX_BYTES;
5481
+ const max = exports$1.INSPECT_MAX_BYTES;
5460
5482
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
5461
5483
  if (this.length > max) str += ' ... ';
5462
5484
  return '<Buffer ' + str + '>'
@@ -6964,7 +6986,7 @@ var hasRequiredBuffer;
6964
6986
  function requireBuffer () {
6965
6987
  if (hasRequiredBuffer) return buffer;
6966
6988
  hasRequiredBuffer = 1;
6967
- (function (exports) {
6989
+ (function (exports$1) {
6968
6990
 
6969
6991
  var base64 = requireBase64Js();
6970
6992
  var ieee754 = requireIeee754();
@@ -6973,12 +6995,12 @@ function requireBuffer () {
6973
6995
  ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
6974
6996
  : null;
6975
6997
 
6976
- exports.Buffer = Buffer;
6977
- exports.SlowBuffer = SlowBuffer;
6978
- exports.INSPECT_MAX_BYTES = 50;
6998
+ exports$1.Buffer = Buffer;
6999
+ exports$1.SlowBuffer = SlowBuffer;
7000
+ exports$1.INSPECT_MAX_BYTES = 50;
6979
7001
 
6980
7002
  var K_MAX_LENGTH = 0x7fffffff;
6981
- exports.kMaxLength = K_MAX_LENGTH;
7003
+ exports$1.kMaxLength = K_MAX_LENGTH;
6982
7004
 
6983
7005
  /**
6984
7006
  * If `Buffer.TYPED_ARRAY_SUPPORT`:
@@ -7575,7 +7597,7 @@ function requireBuffer () {
7575
7597
 
7576
7598
  Buffer.prototype.inspect = function inspect () {
7577
7599
  var str = '';
7578
- var max = exports.INSPECT_MAX_BYTES;
7600
+ var max = exports$1.INSPECT_MAX_BYTES;
7579
7601
  str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
7580
7602
  if (this.length > max) str += ' ... ';
7581
7603
  return '<Buffer ' + str + '>'
@@ -8788,7 +8810,7 @@ var hasRequiredFrames;
8788
8810
  function requireFrames () {
8789
8811
  if (hasRequiredFrames) return Frames;
8790
8812
  hasRequiredFrames = 1;
8791
- (function (exports) {
8813
+ (function (exports$1) {
8792
8814
  /*
8793
8815
  * Copyright 2021-2022 the original author or authors.
8794
8816
  *
@@ -8804,8 +8826,8 @@ function requireFrames () {
8804
8826
  * See the License for the specific language governing permissions and
8805
8827
  * limitations under the License.
8806
8828
  */
8807
- Object.defineProperty(exports, "__esModule", { value: true });
8808
- exports.Frame = exports.Lengths = exports.Flags = exports.FrameTypes = void 0;
8829
+ Object.defineProperty(exports$1, "__esModule", { value: true });
8830
+ exports$1.Frame = exports$1.Lengths = exports$1.Flags = exports$1.FrameTypes = void 0;
8809
8831
  var FrameTypes;
8810
8832
  (function (FrameTypes) {
8811
8833
  FrameTypes[FrameTypes["RESERVED"] = 0] = "RESERVED";
@@ -8824,7 +8846,7 @@ function requireFrames () {
8824
8846
  FrameTypes[FrameTypes["RESUME"] = 13] = "RESUME";
8825
8847
  FrameTypes[FrameTypes["RESUME_OK"] = 14] = "RESUME_OK";
8826
8848
  FrameTypes[FrameTypes["EXT"] = 63] = "EXT";
8827
- })(FrameTypes = exports.FrameTypes || (exports.FrameTypes = {}));
8849
+ })(FrameTypes = exports$1.FrameTypes || (exports$1.FrameTypes = {}));
8828
8850
  (function (Flags) {
8829
8851
  Flags[Flags["NONE"] = 0] = "NONE";
8830
8852
  Flags[Flags["COMPLETE"] = 64] = "COMPLETE";
@@ -8835,7 +8857,7 @@ function requireFrames () {
8835
8857
  Flags[Flags["NEXT"] = 32] = "NEXT";
8836
8858
  Flags[Flags["RESPOND"] = 128] = "RESPOND";
8837
8859
  Flags[Flags["RESUME_ENABLE"] = 128] = "RESUME_ENABLE";
8838
- })(exports.Flags || (exports.Flags = {}));
8860
+ })(exports$1.Flags || (exports$1.Flags = {}));
8839
8861
  (function (Flags) {
8840
8862
  function hasMetadata(flags) {
8841
8863
  return (flags & Flags.METADATA) === Flags.METADATA;
@@ -8869,13 +8891,13 @@ function requireFrames () {
8869
8891
  return (flags & Flags.RESUME_ENABLE) === Flags.RESUME_ENABLE;
8870
8892
  }
8871
8893
  Flags.hasResume = hasResume;
8872
- })(exports.Flags || (exports.Flags = {}));
8894
+ })(exports$1.Flags || (exports$1.Flags = {}));
8873
8895
  (function (Lengths) {
8874
8896
  Lengths[Lengths["FRAME"] = 3] = "FRAME";
8875
8897
  Lengths[Lengths["HEADER"] = 6] = "HEADER";
8876
8898
  Lengths[Lengths["METADATA"] = 3] = "METADATA";
8877
8899
  Lengths[Lengths["REQUEST"] = 3] = "REQUEST";
8878
- })(exports.Lengths || (exports.Lengths = {}));
8900
+ })(exports$1.Lengths || (exports$1.Lengths = {}));
8879
8901
  (function (Frame) {
8880
8902
  function isConnection(frame) {
8881
8903
  return frame.streamId === 0;
@@ -8886,7 +8908,7 @@ function requireFrames () {
8886
8908
  frame.type <= FrameTypes.REQUEST_CHANNEL);
8887
8909
  }
8888
8910
  Frame.isRequest = isRequest;
8889
- })(exports.Frame || (exports.Frame = {}));
8911
+ })(exports$1.Frame || (exports$1.Frame = {}));
8890
8912
 
8891
8913
  } (Frames));
8892
8914
  return Frames;
@@ -8897,7 +8919,7 @@ var hasRequiredCodecs;
8897
8919
  function requireCodecs () {
8898
8920
  if (hasRequiredCodecs) return Codecs;
8899
8921
  hasRequiredCodecs = 1;
8900
- (function (exports) {
8922
+ (function (exports$1) {
8901
8923
  var __generator = (Codecs && Codecs.__generator) || function (thisArg, body) {
8902
8924
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
8903
8925
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
@@ -8925,22 +8947,22 @@ function requireCodecs () {
8925
8947
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
8926
8948
  }
8927
8949
  };
8928
- Object.defineProperty(exports, "__esModule", { value: true });
8929
- exports.Deserializer = exports.sizeOfFrame = exports.serializeFrame = exports.deserializeFrame = exports.serializeFrameWithLength = exports.deserializeFrames = exports.deserializeFrameWithLength = exports.writeUInt64BE = exports.readUInt64BE = exports.writeUInt24BE = exports.readUInt24BE = exports.MAX_VERSION = exports.MAX_TTL = exports.MAX_STREAM_ID = exports.MAX_RESUME_LENGTH = exports.MAX_REQUEST_N = exports.MAX_REQUEST_COUNT = exports.MAX_MIME_LENGTH = exports.MAX_METADATA_LENGTH = exports.MAX_LIFETIME = exports.MAX_KEEPALIVE = exports.MAX_CODE = exports.FRAME_TYPE_OFFFSET = exports.FLAGS_MASK = void 0;
8950
+ Object.defineProperty(exports$1, "__esModule", { value: true });
8951
+ exports$1.Deserializer = exports$1.sizeOfFrame = exports$1.serializeFrame = exports$1.deserializeFrame = exports$1.serializeFrameWithLength = exports$1.deserializeFrames = exports$1.deserializeFrameWithLength = exports$1.writeUInt64BE = exports$1.readUInt64BE = exports$1.writeUInt24BE = exports$1.readUInt24BE = exports$1.MAX_VERSION = exports$1.MAX_TTL = exports$1.MAX_STREAM_ID = exports$1.MAX_RESUME_LENGTH = exports$1.MAX_REQUEST_N = exports$1.MAX_REQUEST_COUNT = exports$1.MAX_MIME_LENGTH = exports$1.MAX_METADATA_LENGTH = exports$1.MAX_LIFETIME = exports$1.MAX_KEEPALIVE = exports$1.MAX_CODE = exports$1.FRAME_TYPE_OFFFSET = exports$1.FLAGS_MASK = void 0;
8930
8952
  var Frames_1 = requireFrames();
8931
- exports.FLAGS_MASK = 0x3ff; // low 10 bits
8932
- exports.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
8933
- exports.MAX_CODE = 0x7fffffff; // uint31
8934
- exports.MAX_KEEPALIVE = 0x7fffffff; // uint31
8935
- exports.MAX_LIFETIME = 0x7fffffff; // uint31
8936
- exports.MAX_METADATA_LENGTH = 0xffffff; // uint24
8937
- exports.MAX_MIME_LENGTH = 0xff; // int8
8938
- exports.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
8939
- exports.MAX_REQUEST_N = 0x7fffffff; // uint31
8940
- exports.MAX_RESUME_LENGTH = 0xffff; // uint16
8941
- exports.MAX_STREAM_ID = 0x7fffffff; // uint31
8942
- exports.MAX_TTL = 0x7fffffff; // uint31
8943
- exports.MAX_VERSION = 0xffff; // uint16
8953
+ exports$1.FLAGS_MASK = 0x3ff; // low 10 bits
8954
+ exports$1.FRAME_TYPE_OFFFSET = 10; // frame type is offset 10 bytes within the uint16 containing type + flags
8955
+ exports$1.MAX_CODE = 0x7fffffff; // uint31
8956
+ exports$1.MAX_KEEPALIVE = 0x7fffffff; // uint31
8957
+ exports$1.MAX_LIFETIME = 0x7fffffff; // uint31
8958
+ exports$1.MAX_METADATA_LENGTH = 0xffffff; // uint24
8959
+ exports$1.MAX_MIME_LENGTH = 0xff; // int8
8960
+ exports$1.MAX_REQUEST_COUNT = 0x7fffffff; // uint31
8961
+ exports$1.MAX_REQUEST_N = 0x7fffffff; // uint31
8962
+ exports$1.MAX_RESUME_LENGTH = 0xffff; // uint16
8963
+ exports$1.MAX_STREAM_ID = 0x7fffffff; // uint31
8964
+ exports$1.MAX_TTL = 0x7fffffff; // uint31
8965
+ exports$1.MAX_VERSION = 0xffff; // uint16
8944
8966
  /**
8945
8967
  * Mimimum value that would overflow bitwise operators (2^32).
8946
8968
  */
@@ -8954,7 +8976,7 @@ function requireCodecs () {
8954
8976
  var val3 = buffer.readUInt8(offset + 2);
8955
8977
  return val1 | val2 | val3;
8956
8978
  }
8957
- exports.readUInt24BE = readUInt24BE;
8979
+ exports$1.readUInt24BE = readUInt24BE;
8958
8980
  /**
8959
8981
  * Writes a uint24 to a buffer starting at the given offset, returning the
8960
8982
  * offset of the next byte.
@@ -8964,7 +8986,7 @@ function requireCodecs () {
8964
8986
  offset = buffer.writeUInt8((value >>> 8) & 0xff, offset); // 2nd byte
8965
8987
  return buffer.writeUInt8(value & 0xff, offset); // 1st byte
8966
8988
  }
8967
- exports.writeUInt24BE = writeUInt24BE;
8989
+ exports$1.writeUInt24BE = writeUInt24BE;
8968
8990
  /**
8969
8991
  * Read a uint64 (technically supports up to 53 bits per JS number
8970
8992
  * representation).
@@ -8974,7 +8996,7 @@ function requireCodecs () {
8974
8996
  var low = buffer.readUInt32BE(offset + 4);
8975
8997
  return high * BITWISE_OVERFLOW + low;
8976
8998
  }
8977
- exports.readUInt64BE = readUInt64BE;
8999
+ exports$1.readUInt64BE = readUInt64BE;
8978
9000
  /**
8979
9001
  * Write a uint64 (technically supports up to 53 bits per JS number
8980
9002
  * representation).
@@ -8985,7 +9007,7 @@ function requireCodecs () {
8985
9007
  offset = buffer.writeUInt32BE(high, offset); // first half of uint64
8986
9008
  return buffer.writeUInt32BE(low, offset); // second half of uint64
8987
9009
  }
8988
- exports.writeUInt64BE = writeUInt64BE;
9010
+ exports$1.writeUInt64BE = writeUInt64BE;
8989
9011
  /**
8990
9012
  * Frame header is:
8991
9013
  * - stream id (uint32 = 4)
@@ -9003,7 +9025,7 @@ function requireCodecs () {
9003
9025
  var frameLength = readUInt24BE(buffer, 0);
9004
9026
  return deserializeFrame(buffer.slice(UINT24_SIZE, UINT24_SIZE + frameLength));
9005
9027
  }
9006
- exports.deserializeFrameWithLength = deserializeFrameWithLength;
9028
+ exports$1.deserializeFrameWithLength = deserializeFrameWithLength;
9007
9029
  /**
9008
9030
  * Given a buffer that may contain zero or more length-prefixed frames followed
9009
9031
  * by zero or more bytes of a (partial) subsequent frame, returns an array of
@@ -9036,7 +9058,7 @@ function requireCodecs () {
9036
9058
  }
9037
9059
  });
9038
9060
  }
9039
- exports.deserializeFrames = deserializeFrames;
9061
+ exports$1.deserializeFrames = deserializeFrames;
9040
9062
  /**
9041
9063
  * Writes a frame to a buffer with a length prefix.
9042
9064
  */
@@ -9047,7 +9069,7 @@ function requireCodecs () {
9047
9069
  buffer.copy(lengthPrefixed, UINT24_SIZE);
9048
9070
  return lengthPrefixed;
9049
9071
  }
9050
- exports.serializeFrameWithLength = serializeFrameWithLength;
9072
+ exports$1.serializeFrameWithLength = serializeFrameWithLength;
9051
9073
  /**
9052
9074
  * Read a frame from the buffer.
9053
9075
  */
@@ -9062,8 +9084,8 @@ function requireCodecs () {
9062
9084
  // );
9063
9085
  var typeAndFlags = buffer.readUInt16BE(offset);
9064
9086
  offset += 2;
9065
- var type = typeAndFlags >>> exports.FRAME_TYPE_OFFFSET; // keep highest 6 bits
9066
- var flags = typeAndFlags & exports.FLAGS_MASK; // keep lowest 10 bits
9087
+ var type = typeAndFlags >>> exports$1.FRAME_TYPE_OFFFSET; // keep highest 6 bits
9088
+ var flags = typeAndFlags & exports$1.FLAGS_MASK; // keep lowest 10 bits
9067
9089
  switch (type) {
9068
9090
  case Frames_1.FrameTypes.SETUP:
9069
9091
  return deserializeSetupFrame(buffer, streamId, flags);
@@ -9100,7 +9122,7 @@ function requireCodecs () {
9100
9122
  // );
9101
9123
  }
9102
9124
  }
9103
- exports.deserializeFrame = deserializeFrame;
9125
+ exports$1.deserializeFrame = deserializeFrame;
9104
9126
  /**
9105
9127
  * Convert the frame to a (binary) buffer.
9106
9128
  */
@@ -9139,7 +9161,7 @@ function requireCodecs () {
9139
9161
  // );
9140
9162
  }
9141
9163
  }
9142
- exports.serializeFrame = serializeFrame;
9164
+ exports$1.serializeFrame = serializeFrame;
9143
9165
  /**
9144
9166
  * Byte size of frame without size prefix
9145
9167
  */
@@ -9178,7 +9200,7 @@ function requireCodecs () {
9178
9200
  // );
9179
9201
  }
9180
9202
  }
9181
- exports.sizeOfFrame = sizeOfFrame;
9203
+ exports$1.sizeOfFrame = sizeOfFrame;
9182
9204
  /**
9183
9205
  * Writes a SETUP frame into a new buffer and returns it.
9184
9206
  *
@@ -9813,7 +9835,7 @@ function requireCodecs () {
9813
9835
  function writeHeader(frame, buffer) {
9814
9836
  var offset = buffer.writeInt32BE(frame.streamId, 0);
9815
9837
  // shift frame to high 6 bits, extract lowest 10 bits from flags
9816
- return buffer.writeUInt16BE((frame.type << exports.FRAME_TYPE_OFFFSET) | (frame.flags & exports.FLAGS_MASK), offset);
9838
+ return buffer.writeUInt16BE((frame.type << exports$1.FRAME_TYPE_OFFFSET) | (frame.flags & exports$1.FLAGS_MASK), offset);
9817
9839
  }
9818
9840
  /**
9819
9841
  * Determine the length of the payload section of a frame. Only applies to
@@ -9894,7 +9916,7 @@ function requireCodecs () {
9894
9916
  };
9895
9917
  return Deserializer;
9896
9918
  }());
9897
- exports.Deserializer = Deserializer;
9919
+ exports$1.Deserializer = Deserializer;
9898
9920
 
9899
9921
  } (Codecs));
9900
9922
  return Codecs;
@@ -10040,7 +10062,7 @@ var hasRequiredErrors;
10040
10062
  function requireErrors () {
10041
10063
  if (hasRequiredErrors) return Errors;
10042
10064
  hasRequiredErrors = 1;
10043
- (function (exports) {
10065
+ (function (exports$1) {
10044
10066
  /*
10045
10067
  * Copyright 2021-2022 the original author or authors.
10046
10068
  *
@@ -10071,8 +10093,8 @@ function requireErrors () {
10071
10093
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10072
10094
  };
10073
10095
  })();
10074
- Object.defineProperty(exports, "__esModule", { value: true });
10075
- exports.ErrorCodes = exports.RSocketError = void 0;
10096
+ Object.defineProperty(exports$1, "__esModule", { value: true });
10097
+ exports$1.ErrorCodes = exports$1.RSocketError = void 0;
10076
10098
  var RSocketError = /** @class */ (function (_super) {
10077
10099
  __extends(RSocketError, _super);
10078
10100
  function RSocketError(code, message) {
@@ -10082,7 +10104,7 @@ function requireErrors () {
10082
10104
  }
10083
10105
  return RSocketError;
10084
10106
  }(Error));
10085
- exports.RSocketError = RSocketError;
10107
+ exports$1.RSocketError = RSocketError;
10086
10108
  (function (ErrorCodes) {
10087
10109
  ErrorCodes[ErrorCodes["RESERVED"] = 0] = "RESERVED";
10088
10110
  ErrorCodes[ErrorCodes["INVALID_SETUP"] = 1] = "INVALID_SETUP";
@@ -10096,7 +10118,7 @@ function requireErrors () {
10096
10118
  ErrorCodes[ErrorCodes["CANCELED"] = 515] = "CANCELED";
10097
10119
  ErrorCodes[ErrorCodes["INVALID"] = 516] = "INVALID";
10098
10120
  ErrorCodes[ErrorCodes["RESERVED_EXTENSION"] = 4294967295] = "RESERVED_EXTENSION";
10099
- })(exports.ErrorCodes || (exports.ErrorCodes = {}));
10121
+ })(exports$1.ErrorCodes || (exports$1.ErrorCodes = {}));
10100
10122
 
10101
10123
  } (Errors));
10102
10124
  return Errors;
@@ -10138,7 +10160,7 @@ var hasRequiredClientServerMultiplexerDemultiplexer;
10138
10160
  function requireClientServerMultiplexerDemultiplexer () {
10139
10161
  if (hasRequiredClientServerMultiplexerDemultiplexer) return ClientServerMultiplexerDemultiplexer;
10140
10162
  hasRequiredClientServerMultiplexerDemultiplexer = 1;
10141
- (function (exports) {
10163
+ (function (exports$1) {
10142
10164
  /*
10143
10165
  * Copyright 2021-2022 the original author or authors.
10144
10166
  *
@@ -10205,8 +10227,8 @@ function requireClientServerMultiplexerDemultiplexer () {
10205
10227
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
10206
10228
  }
10207
10229
  };
10208
- Object.defineProperty(exports, "__esModule", { value: true });
10209
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports.ResumableClientServerInputMultiplexerDemultiplexer = exports.ClientServerInputMultiplexerDemultiplexer = exports.StreamIdGenerator = void 0;
10230
+ Object.defineProperty(exports$1, "__esModule", { value: true });
10231
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = exports$1.ResumableClientServerInputMultiplexerDemultiplexer = exports$1.ClientServerInputMultiplexerDemultiplexer = exports$1.StreamIdGenerator = void 0;
10210
10232
  var _1 = requireDist();
10211
10233
  var Deferred_1 = requireDeferred();
10212
10234
  var Errors_1 = requireErrors();
@@ -10229,7 +10251,7 @@ function requireClientServerMultiplexerDemultiplexer () {
10229
10251
  };
10230
10252
  return StreamIdGeneratorImpl;
10231
10253
  }());
10232
- })(exports.StreamIdGenerator || (exports.StreamIdGenerator = {}));
10254
+ })(exports$1.StreamIdGenerator || (exports$1.StreamIdGenerator = {}));
10233
10255
  var ClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
10234
10256
  __extends(ClientServerInputMultiplexerDemultiplexer, _super);
10235
10257
  function ClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable) {
@@ -10318,7 +10340,7 @@ function requireClientServerMultiplexerDemultiplexer () {
10318
10340
  };
10319
10341
  return ClientServerInputMultiplexerDemultiplexer;
10320
10342
  }(Deferred_1.Deferred));
10321
- exports.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
10343
+ exports$1.ClientServerInputMultiplexerDemultiplexer = ClientServerInputMultiplexerDemultiplexer;
10322
10344
  var ResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function (_super) {
10323
10345
  __extends(ResumableClientServerInputMultiplexerDemultiplexer, _super);
10324
10346
  function ResumableClientServerInputMultiplexerDemultiplexer(streamIdSupplier, outbound, closeable, frameStore, token, sessionStoreOrReconnector, sessionTimeout) {
@@ -10475,7 +10497,7 @@ function requireClientServerMultiplexerDemultiplexer () {
10475
10497
  };
10476
10498
  return ResumableClientServerInputMultiplexerDemultiplexer;
10477
10499
  }(ClientServerInputMultiplexerDemultiplexer));
10478
- exports.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
10500
+ exports$1.ResumableClientServerInputMultiplexerDemultiplexer = ResumableClientServerInputMultiplexerDemultiplexer;
10479
10501
  var ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = /** @class */ (function () {
10480
10502
  function ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer(outbound, closeable, delegate) {
10481
10503
  this.outbound = outbound;
@@ -10532,7 +10554,7 @@ function requireClientServerMultiplexerDemultiplexer () {
10532
10554
  };
10533
10555
  return ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
10534
10556
  }());
10535
- exports.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
10557
+ exports$1.ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer = ResumeOkAwaitingResumableClientServerInputMultiplexerDemultiplexer;
10536
10558
 
10537
10559
  } (ClientServerMultiplexerDemultiplexer));
10538
10560
  return ClientServerMultiplexerDemultiplexer;
@@ -13518,7 +13540,7 @@ var hasRequiredDist;
13518
13540
  function requireDist () {
13519
13541
  if (hasRequiredDist) return dist;
13520
13542
  hasRequiredDist = 1;
13521
- (function (exports) {
13543
+ (function (exports$1) {
13522
13544
  /*
13523
13545
  * Copyright 2021-2022 the original author or authors.
13524
13546
  *
@@ -13541,19 +13563,19 @@ function requireDist () {
13541
13563
  if (k2 === undefined) k2 = k;
13542
13564
  o[k2] = m[k];
13543
13565
  }));
13544
- var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
13545
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
13566
+ var __exportStar = (dist && dist.__exportStar) || function(m, exports$1) {
13567
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
13546
13568
  };
13547
- Object.defineProperty(exports, "__esModule", { value: true });
13548
- __exportStar(requireCodecs(), exports);
13549
- __exportStar(requireCommon(), exports);
13550
- __exportStar(requireDeferred(), exports);
13551
- __exportStar(requireErrors(), exports);
13552
- __exportStar(requireFrames(), exports);
13553
- __exportStar(requireRSocket(), exports);
13554
- __exportStar(requireRSocketConnector(), exports);
13555
- __exportStar(requireRSocketServer(), exports);
13556
- __exportStar(requireTransport(), exports);
13569
+ Object.defineProperty(exports$1, "__esModule", { value: true });
13570
+ __exportStar(requireCodecs(), exports$1);
13571
+ __exportStar(requireCommon(), exports$1);
13572
+ __exportStar(requireDeferred(), exports$1);
13573
+ __exportStar(requireErrors(), exports$1);
13574
+ __exportStar(requireFrames(), exports$1);
13575
+ __exportStar(requireRSocket(), exports$1);
13576
+ __exportStar(requireRSocketConnector(), exports$1);
13577
+ __exportStar(requireRSocketServer(), exports$1);
13578
+ __exportStar(requireTransport(), exports$1);
13557
13579
 
13558
13580
  } (dist));
13559
13581
  return dist;
@@ -13561,7 +13583,7 @@ function requireDist () {
13561
13583
 
13562
13584
  var distExports = requireDist();
13563
13585
 
13564
- var version = "1.43.1";
13586
+ var version = "1.45.0";
13565
13587
  var PACKAGE = {
13566
13588
  version: version};
13567
13589
 
@@ -14488,6 +14510,7 @@ const DEFAULT_STREAMING_SYNC_OPTIONS = {
14488
14510
  crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
14489
14511
  };
14490
14512
  const DEFAULT_STREAM_CONNECTION_OPTIONS = {
14513
+ appMetadata: {},
14491
14514
  connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,
14492
14515
  clientImplementation: DEFAULT_SYNC_CLIENT_IMPLEMENTATION,
14493
14516
  fetchStrategy: FetchStrategy.Buffered,
@@ -14866,6 +14889,11 @@ The next upload iteration will be delayed.`);
14866
14889
  ...DEFAULT_STREAM_CONNECTION_OPTIONS,
14867
14890
  ...(options ?? {})
14868
14891
  };
14892
+ // Validate app metadata
14893
+ const invalidMetadata = Object.entries(resolvedOptions.appMetadata).filter(([_, value]) => typeof value != 'string');
14894
+ if (invalidMetadata.length > 0) {
14895
+ throw new Error(`Invalid appMetadata provided. Only string values are allowed. Invalid values: ${invalidMetadata.map(([key, value]) => `${key}: ${value}`).join(', ')}`);
14896
+ }
14869
14897
  const clientImplementation = resolvedOptions.clientImplementation;
14870
14898
  this.updateSyncStatus({ clientImplementation });
14871
14899
  if (clientImplementation == SyncClientImplementation.JAVASCRIPT) {
@@ -14901,6 +14929,7 @@ The next upload iteration will be delayed.`);
14901
14929
  include_checksum: true,
14902
14930
  raw_data: true,
14903
14931
  parameters: resolvedOptions.params,
14932
+ app_metadata: resolvedOptions.appMetadata,
14904
14933
  client_id: clientId
14905
14934
  }
14906
14935
  };
@@ -15260,6 +15289,7 @@ The next upload iteration will be delayed.`);
15260
15289
  try {
15261
15290
  const options = {
15262
15291
  parameters: resolvedOptions.params,
15292
+ app_metadata: resolvedOptions.appMetadata,
15263
15293
  active_streams: this.activeStreams,
15264
15294
  include_defaults: resolvedOptions.includeDefaultStreams
15265
15295
  };
@@ -15918,11 +15948,11 @@ class AbstractPowerSyncDatabase extends BaseObserver {
15918
15948
  .map((n) => parseInt(n));
15919
15949
  }
15920
15950
  catch (e) {
15921
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
15951
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}. Details: ${e.message}`);
15922
15952
  }
15923
- // Validate >=0.4.5 <1.0.0
15924
- if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 5)) {
15925
- throw new Error(`Unsupported powersync extension version. Need >=0.4.5 <1.0.0, got: ${this.sdkVersion}`);
15953
+ // Validate >=0.4.10 <1.0.0
15954
+ if (versionInts[0] != 0 || versionInts[1] < 4 || (versionInts[1] == 4 && versionInts[2] < 10)) {
15955
+ throw new Error(`Unsupported powersync extension version. Need >=0.4.10 <1.0.0, got: ${this.sdkVersion}`);
15926
15956
  }
15927
15957
  }
15928
15958
  async resolveOfflineSyncStatus() {
@@ -17042,6 +17072,27 @@ class SyncDataBatch {
17042
17072
  }
17043
17073
  }
17044
17074
 
17075
+ /**
17076
+ * Thrown when an underlying database connection is closed.
17077
+ * This is particularly relevant when worker connections are marked as closed while
17078
+ * operations are still in progress.
17079
+ */
17080
+ class ConnectionClosedError extends Error {
17081
+ static NAME = 'ConnectionClosedError';
17082
+ static MATCHES(input) {
17083
+ /**
17084
+ * If there are weird package issues which cause multiple versions of classes to be present, the instanceof
17085
+ * check might fail. This also performs a failsafe check.
17086
+ * This might also happen if the Error is serialized and parsed over a bridging channel like a MessagePort.
17087
+ */
17088
+ return (input instanceof ConnectionClosedError || (input instanceof Error && input.name == ConnectionClosedError.NAME));
17089
+ }
17090
+ constructor(message) {
17091
+ super(message);
17092
+ this.name = ConnectionClosedError.NAME;
17093
+ }
17094
+ }
17095
+
17045
17096
  // https://www.sqlite.org/lang_expr.html#castexpr
17046
17097
  var ColumnType;
17047
17098
  (function (ColumnType) {
@@ -17600,13 +17651,13 @@ const parseQuery = (query, parameters) => {
17600
17651
  //# sourceMappingURL=bundle.mjs.map
17601
17652
 
17602
17653
 
17603
- /***/ }),
17654
+ /***/ },
17604
17655
 
17605
- /***/ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js":
17656
+ /***/ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js"
17606
17657
  /*!*************************************************************!*\
17607
17658
  !*** ./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js ***!
17608
17659
  \*************************************************************/
17609
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
17660
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
17610
17661
 
17611
17662
  __webpack_require__.r(__webpack_exports__);
17612
17663
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -17705,9 +17756,10 @@ const DEFAULT_MODULE_FACTORIES = {
17705
17756
  }
17706
17757
  // @ts-expect-error The types for this static method are missing upstream
17707
17758
  const { OPFSCoopSyncVFS } = await __webpack_require__.e(/*! import() */ "node_modules_journeyapps_wa-sqlite_src_examples_OPFSCoopSyncVFS_js").then(__webpack_require__.bind(__webpack_require__, /*! @journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js */ "../../node_modules/@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js"));
17759
+ const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
17708
17760
  return {
17709
17761
  module,
17710
- vfs: await OPFSCoopSyncVFS.create(options.dbFileName, module)
17762
+ vfs
17711
17763
  };
17712
17764
  }
17713
17765
  };
@@ -17933,7 +17985,15 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
17933
17985
  }
17934
17986
  async close() {
17935
17987
  this.broadcastChannel?.close();
17936
- await this.sqliteAPI.close(this.dbP);
17988
+ await this.acquireExecuteLock(async () => {
17989
+ /**
17990
+ * Running the close operation inside the same execute mutex prevents errors like:
17991
+ * ```
17992
+ * unable to close due to unfinalized statements or unfinished backups
17993
+ * ```
17994
+ */
17995
+ await this.sqliteAPI.close(this.dbP);
17996
+ });
17937
17997
  }
17938
17998
  async registerOnTableChange(callback) {
17939
17999
  return this.registerListener({
@@ -18015,13 +18075,13 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
18015
18075
  }
18016
18076
 
18017
18077
 
18018
- /***/ }),
18078
+ /***/ },
18019
18079
 
18020
- /***/ "./lib/src/shared/navigator.js":
18080
+ /***/ "./lib/src/shared/navigator.js"
18021
18081
  /*!*************************************!*\
18022
18082
  !*** ./lib/src/shared/navigator.js ***!
18023
18083
  \*************************************/
18024
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
18084
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
18025
18085
 
18026
18086
  __webpack_require__.r(__webpack_exports__);
18027
18087
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -18035,13 +18095,13 @@ const getNavigatorLocks = () => {
18035
18095
  };
18036
18096
 
18037
18097
 
18038
- /***/ }),
18098
+ /***/ },
18039
18099
 
18040
- /***/ "./lib/src/worker/db/SharedWASQLiteConnection.js":
18100
+ /***/ "./lib/src/worker/db/SharedWASQLiteConnection.js"
18041
18101
  /*!*******************************************************!*\
18042
18102
  !*** ./lib/src/worker/db/SharedWASQLiteConnection.js ***!
18043
18103
  \*******************************************************/
18044
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
18104
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
18045
18105
 
18046
18106
  __webpack_require__.r(__webpack_exports__);
18047
18107
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
@@ -18139,35 +18199,35 @@ class SharedWASQLiteConnection {
18139
18199
  }
18140
18200
 
18141
18201
 
18142
- /***/ }),
18202
+ /***/ },
18143
18203
 
18144
- /***/ "./lib/src/worker/db/WorkerWASQLiteConnection.js":
18204
+ /***/ "./lib/src/worker/db/WorkerWASQLiteConnection.js"
18145
18205
  /*!*******************************************************!*\
18146
18206
  !*** ./lib/src/worker/db/WorkerWASQLiteConnection.js ***!
18147
18207
  \*******************************************************/
18148
- /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
18208
+ (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
18149
18209
 
18150
18210
  __webpack_require__.r(__webpack_exports__);
18151
18211
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
18152
18212
  /* harmony export */ WorkerWASQLiteConnection: () => (/* binding */ WorkerWASQLiteConnection)
18153
18213
  /* harmony export */ });
18154
- /* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
18155
- /* harmony import */ var _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/WASQLiteConnection */ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js");
18214
+ /* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
18215
+ /* harmony import */ var _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../db/adapters/wa-sqlite/WASQLiteConnection */ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js");
18156
18216
 
18157
18217
 
18158
18218
  /**
18159
18219
  * A Small proxy wrapper around the WASqliteConnection.
18160
18220
  * This ensures that certain return types are properly proxied.
18161
18221
  */
18162
- class WorkerWASQLiteConnection extends _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_0__.WASqliteConnection {
18222
+ class WorkerWASQLiteConnection extends _db_adapters_wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_1__.WASqliteConnection {
18163
18223
  async registerOnTableChange(callback) {
18164
18224
  // Proxy the callback remove function
18165
- return comlink__WEBPACK_IMPORTED_MODULE_1__.proxy(await super.registerOnTableChange(callback));
18225
+ return comlink__WEBPACK_IMPORTED_MODULE_0__.proxy(await super.registerOnTableChange(callback));
18166
18226
  }
18167
18227
  }
18168
18228
 
18169
18229
 
18170
- /***/ })
18230
+ /***/ }
18171
18231
 
18172
18232
  /******/ });
18173
18233
  /************************************************************************/
@@ -18181,6 +18241,12 @@ class WorkerWASQLiteConnection extends _db_adapters_wa_sqlite_WASQLiteConnection
18181
18241
  /******/ if (cachedModule !== undefined) {
18182
18242
  /******/ return cachedModule.exports;
18183
18243
  /******/ }
18244
+ /******/ // Check if module exists (development only)
18245
+ /******/ if (__webpack_modules__[moduleId] === undefined) {
18246
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
18247
+ /******/ e.code = 'MODULE_NOT_FOUND';
18248
+ /******/ throw e;
18249
+ /******/ }
18184
18250
  /******/ // Create a new module (and put it into the cache)
18185
18251
  /******/ var module = __webpack_module_cache__[moduleId] = {
18186
18252
  /******/ // no module.id needed
@@ -18335,10 +18401,10 @@ var __webpack_exports__ = {};
18335
18401
  __webpack_require__.r(__webpack_exports__);
18336
18402
  /* harmony import */ var _journeyapps_wa_sqlite__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @journeyapps/wa-sqlite */ "../../node_modules/@journeyapps/wa-sqlite/src/sqlite-api.js");
18337
18403
  /* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @powersync/common */ "../common/dist/bundle.mjs");
18338
- /* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
18339
- /* harmony import */ var _shared_navigator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../shared/navigator */ "./lib/src/shared/navigator.js");
18340
- /* harmony import */ var _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./SharedWASQLiteConnection */ "./lib/src/worker/db/SharedWASQLiteConnection.js");
18341
- /* harmony import */ var _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./WorkerWASQLiteConnection */ "./lib/src/worker/db/WorkerWASQLiteConnection.js");
18404
+ /* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
18405
+ /* harmony import */ var _shared_navigator__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../shared/navigator */ "./lib/src/shared/navigator.js");
18406
+ /* harmony import */ var _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./SharedWASQLiteConnection */ "./lib/src/worker/db/SharedWASQLiteConnection.js");
18407
+ /* harmony import */ var _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./WorkerWASQLiteConnection */ "./lib/src/worker/db/WorkerWASQLiteConnection.js");
18342
18408
  /**
18343
18409
  * Supports both shared and dedicated workers, based on how the worker is constructed (new SharedWorker vs new Worker()).
18344
18410
  */
@@ -18356,14 +18422,14 @@ const OPEN_DB_LOCK = 'open-wasqlite-db';
18356
18422
  let nextClientId = 1;
18357
18423
  const openDBShared = async (options) => {
18358
18424
  // Prevent multiple simultaneous opens from causing race conditions
18359
- return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_2__.getNavigatorLocks)().request(OPEN_DB_LOCK, async () => {
18425
+ return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_3__.getNavigatorLocks)().request(OPEN_DB_LOCK, async () => {
18360
18426
  const clientId = nextClientId++;
18361
18427
  const { dbFilename, logLevel } = options;
18362
18428
  logger.setLevel(logLevel);
18363
18429
  if (!DBMap.has(dbFilename)) {
18364
18430
  const clientIds = new Set();
18365
18431
  // This format returns proxy objects for function callbacks
18366
- const connection = new _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__.WorkerWASQLiteConnection(options);
18432
+ const connection = new _WorkerWASQLiteConnection__WEBPACK_IMPORTED_MODULE_5__.WorkerWASQLiteConnection(options);
18367
18433
  await connection.init();
18368
18434
  connection.registerListener({
18369
18435
  holdOverwritten: async () => {
@@ -18381,13 +18447,13 @@ const openDBShared = async (options) => {
18381
18447
  });
18382
18448
  }
18383
18449
  // Associates this clientId with the shared connection entry
18384
- const sharedConnection = new _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__.SharedWASQLiteConnection({
18450
+ const sharedConnection = new _SharedWASQLiteConnection__WEBPACK_IMPORTED_MODULE_4__.SharedWASQLiteConnection({
18385
18451
  dbMap: DBMap,
18386
18452
  dbFilename,
18387
18453
  clientId,
18388
18454
  logger
18389
18455
  });
18390
- return comlink__WEBPACK_IMPORTED_MODULE_5__.proxy(sharedConnection);
18456
+ return comlink__WEBPACK_IMPORTED_MODULE_2__.proxy(sharedConnection);
18391
18457
  });
18392
18458
  };
18393
18459
  // Check if we're in a SharedWorker context
@@ -18395,12 +18461,12 @@ if (typeof SharedWorkerGlobalScope !== 'undefined') {
18395
18461
  const _self = self;
18396
18462
  _self.onconnect = function (event) {
18397
18463
  const port = event.ports[0];
18398
- comlink__WEBPACK_IMPORTED_MODULE_5__.expose(openDBShared, port);
18464
+ comlink__WEBPACK_IMPORTED_MODULE_2__.expose(openDBShared, port);
18399
18465
  };
18400
18466
  }
18401
18467
  else {
18402
18468
  // A dedicated worker can be shared externally
18403
- comlink__WEBPACK_IMPORTED_MODULE_5__.expose(openDBShared);
18469
+ comlink__WEBPACK_IMPORTED_MODULE_2__.expose(openDBShared);
18404
18470
  }
18405
18471
  addEventListener('unload', () => {
18406
18472
  Array.from(DBMap.values()).forEach(async (dbConnection) => {