@powersync/web 0.0.0-dev-20250714144421 → 0.0.0-dev-20250715080712

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
@@ -38387,7 +38387,7 @@ class PowerSyncDatabase extends _powersync_common__WEBPACK_IMPORTED_MODULE_0__.A
38387
38387
  return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_2__.getNavigatorLocks)().request(`lock-${this.database.name}`, cb);
38388
38388
  }
38389
38389
  generateSyncStreamImplementation(connector, options) {
38390
- const remote = new _sync_WebRemote__WEBPACK_IMPORTED_MODULE_7__.WebRemote(connector, this.logger);
38390
+ const remote = new _sync_WebRemote__WEBPACK_IMPORTED_MODULE_7__.WebRemote(connector);
38391
38391
  const syncOptions = {
38392
38392
  ...this.options,
38393
38393
  retryDelayMs: options.retryDelayMs,
@@ -38399,8 +38399,7 @@ class PowerSyncDatabase extends _powersync_common__WEBPACK_IMPORTED_MODULE_0__.A
38399
38399
  await this.waitForReady();
38400
38400
  await connector.uploadData(this);
38401
38401
  },
38402
- identifier: this.database.name,
38403
- logger: this.logger
38402
+ identifier: this.database.name
38404
38403
  };
38405
38404
  switch (true) {
38406
38405
  case this.resolvedFlags.ssrMode:
@@ -38556,11 +38555,17 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38556
38555
  _db = null;
38557
38556
  _disposeTableChangeListener = null;
38558
38557
  _config = null;
38558
+ pendingAbortControllers;
38559
+ closing;
38560
+ closed;
38559
38561
  constructor(options) {
38560
38562
  super();
38561
38563
  this.options = options;
38562
38564
  this._dbIdentifier = options.name;
38563
38565
  this.logger = options.logger ?? (0,_powersync_common__WEBPACK_IMPORTED_MODULE_0__.createLogger)(`LockedAsyncDatabaseAdapter - ${this._dbIdentifier}`);
38566
+ this.pendingAbortControllers = new Set();
38567
+ this.closed = false;
38568
+ this.closing = false;
38564
38569
  // Set the name if provided. We can query for the name if not available yet
38565
38570
  this.debugMode = options.debugMode ?? false;
38566
38571
  if (this.debugMode) {
@@ -38650,8 +38655,11 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38650
38655
  * tabs are still using it.
38651
38656
  */
38652
38657
  async close() {
38658
+ this.closing = true;
38653
38659
  this._disposeTableChangeListener?.();
38660
+ this.pendingAbortControllers.forEach((controller) => controller.abort('Closed'));
38654
38661
  await this.baseDB?.close?.();
38662
+ this.closed = true;
38655
38663
  }
38656
38664
  async getAll(sql, parameters) {
38657
38665
  await this.waitForInitialized();
@@ -38667,14 +38675,37 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38667
38675
  }
38668
38676
  async readLock(fn, options) {
38669
38677
  await this.waitForInitialized();
38670
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
38678
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })), {
38679
+ timeoutMs: options?.timeoutMs
38680
+ });
38671
38681
  }
38672
38682
  async writeLock(fn, options) {
38673
38683
  await this.waitForInitialized();
38674
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
38684
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })), {
38685
+ timeoutMs: options?.timeoutMs
38686
+ });
38675
38687
  }
38676
- acquireLock(callback) {
38677
- return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, callback);
38688
+ async acquireLock(callback, options) {
38689
+ await this.waitForInitialized();
38690
+ if (this.closing) {
38691
+ throw new Error(`Cannot acquire lock, the database is closing`);
38692
+ }
38693
+ const abortController = new AbortController();
38694
+ this.pendingAbortControllers.add(abortController);
38695
+ const { timeoutMs } = options ?? {};
38696
+ const timoutId = timeoutMs
38697
+ ? setTimeout(() => {
38698
+ abortController.abort(`Timeout after ${timeoutMs}ms`);
38699
+ this.pendingAbortControllers.delete(abortController);
38700
+ }, timeoutMs)
38701
+ : null;
38702
+ return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
38703
+ this.pendingAbortControllers.delete(abortController);
38704
+ if (timoutId) {
38705
+ clearTimeout(timoutId);
38706
+ }
38707
+ return callback();
38708
+ });
38678
38709
  }
38679
38710
  async readTransaction(fn, options) {
38680
38711
  return this.readLock(this.wrapTransaction(fn));
@@ -39916,6 +39947,7 @@ class SharedWebStreamingSyncImplementation extends _WebStreamingSyncImplementati
39916
39947
  }
39917
39948
  async dispose() {
39918
39949
  await this.waitForReady();
39950
+ await super.dispose();
39919
39951
  await new Promise((resolve) => {
39920
39952
  // Listen for the close acknowledgment from the worker
39921
39953
  this.messagePort.addEventListener('message', (event) => {
@@ -40558,7 +40590,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
40558
40590
  */
40559
40591
  async connect(options) {
40560
40592
  this.lastConnectOptions = options;
40561
- return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options);
40593
+ return this.connectionManager.connect(CONNECTOR_PLACEHOLDER, options ?? {});
40562
40594
  }
40563
40595
  async disconnect() {
40564
40596
  return this.connectionManager.disconnect();
@@ -40623,7 +40655,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
40623
40655
  // Clearing the adapter will result in a new one being opened in connect
40624
40656
  this.dbAdapter = null;
40625
40657
  if (shouldReconnect) {
40626
- await this.connectionManager.connect(CONNECTOR_PLACEHOLDER, this.lastConnectOptions);
40658
+ await this.connectionManager.connect(CONNECTOR_PLACEHOLDER, this.lastConnectOptions ?? {});
40627
40659
  }
40628
40660
  }
40629
40661
  if (trackedPort.db) {
@@ -40765,8 +40797,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
40765
40797
  */
40766
40798
  async _testUpdateAllStatuses(status) {
40767
40799
  if (!this.connectionManager.syncStreamImplementation) {
40768
- // This is just for testing purposes
40769
- this.connectionManager.syncStreamImplementation = this.generateStreamingImplementation();
40800
+ throw new Error('Cannot update status without a sync stream implementation');
40770
40801
  }
40771
40802
  // Only assigning, don't call listeners for this test
40772
40803
  this.connectionManager.syncStreamImplementation.syncStatus = new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.SyncStatus(status);