@powersync/web 0.0.0-dev-20250728083821 → 0.0.0-dev-20250728130541

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -38569,11 +38569,17 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38569
38569
  _db = null;
38570
38570
  _disposeTableChangeListener = null;
38571
38571
  _config = null;
38572
+ pendingAbortControllers;
38573
+ closing;
38574
+ closed;
38572
38575
  constructor(options) {
38573
38576
  super();
38574
38577
  this.options = options;
38575
38578
  this._dbIdentifier = options.name;
38576
38579
  this.logger = options.logger ?? (0,_powersync_common__WEBPACK_IMPORTED_MODULE_0__.createLogger)(`LockedAsyncDatabaseAdapter - ${this._dbIdentifier}`);
38580
+ this.pendingAbortControllers = new Set();
38581
+ this.closed = false;
38582
+ this.closing = false;
38577
38583
  // Set the name if provided. We can query for the name if not available yet
38578
38584
  this.debugMode = options.debugMode ?? false;
38579
38585
  if (this.debugMode) {
@@ -38663,8 +38669,11 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38663
38669
  * tabs are still using it.
38664
38670
  */
38665
38671
  async close() {
38672
+ this.closing = true;
38666
38673
  this._disposeTableChangeListener?.();
38674
+ this.pendingAbortControllers.forEach((controller) => controller.abort('Closed'));
38667
38675
  await this.baseDB?.close?.();
38676
+ this.closed = true;
38668
38677
  }
38669
38678
  async getAll(sql, parameters) {
38670
38679
  await this.waitForInitialized();
@@ -38680,14 +38689,37 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38680
38689
  }
38681
38690
  async readLock(fn, options) {
38682
38691
  await this.waitForInitialized();
38683
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
38692
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })), {
38693
+ timeoutMs: options?.timeoutMs
38694
+ });
38684
38695
  }
38685
38696
  async writeLock(fn, options) {
38686
38697
  await this.waitForInitialized();
38687
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
38698
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })), {
38699
+ timeoutMs: options?.timeoutMs
38700
+ });
38688
38701
  }
38689
- acquireLock(callback) {
38690
- return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, callback);
38702
+ async acquireLock(callback, options) {
38703
+ await this.waitForInitialized();
38704
+ if (this.closing) {
38705
+ throw new Error(`Cannot acquire lock, the database is closing`);
38706
+ }
38707
+ const abortController = new AbortController();
38708
+ this.pendingAbortControllers.add(abortController);
38709
+ const { timeoutMs } = options ?? {};
38710
+ const timoutId = timeoutMs
38711
+ ? setTimeout(() => {
38712
+ abortController.abort(`Timeout after ${timeoutMs}ms`);
38713
+ this.pendingAbortControllers.delete(abortController);
38714
+ }, timeoutMs)
38715
+ : null;
38716
+ return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
38717
+ this.pendingAbortControllers.delete(abortController);
38718
+ if (timoutId) {
38719
+ clearTimeout(timoutId);
38720
+ }
38721
+ return callback();
38722
+ });
38691
38723
  }
38692
38724
  async readTransaction(fn, options) {
38693
38725
  return this.readLock(this.wrapTransaction(fn));
@@ -39929,6 +39961,7 @@ class SharedWebStreamingSyncImplementation extends _WebStreamingSyncImplementati
39929
39961
  }
39930
39962
  async dispose() {
39931
39963
  await this.waitForReady();
39964
+ await super.dispose();
39932
39965
  await new Promise((resolve) => {
39933
39966
  // Listen for the close acknowledgment from the worker
39934
39967
  this.messagePort.addEventListener('message', (event) => {
@@ -40778,8 +40811,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
40778
40811
  */
40779
40812
  async _testUpdateAllStatuses(status) {
40780
40813
  if (!this.connectionManager.syncStreamImplementation) {
40781
- // This is just for testing purposes
40782
- this.connectionManager.syncStreamImplementation = this.generateStreamingImplementation();
40814
+ throw new Error('Cannot update status without a sync stream implementation');
40783
40815
  }
40784
40816
  // Only assigning, don't call listeners for this test
40785
40817
  this.connectionManager.syncStreamImplementation.syncStatus = new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.SyncStatus(status);