@powersync/web 0.0.0-dev-20251119142638 → 0.0.0-dev-20251120085122

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 (27) hide show
  1. package/dist/index.umd.js +21 -6
  2. package/dist/index.umd.js.map +1 -1
  3. package/dist/worker/SharedSyncImplementation.umd.js +14 -6
  4. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  5. package/dist/worker/WASQLiteDB.umd.js +28 -34
  6. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  7. package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +13 -0
  8. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +1 -0
  9. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +7 -2
  10. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +5 -0
  11. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +7 -0
  12. package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +4 -3
  13. package/lib/src/worker/db/SharedWASQLiteConnection.js +17 -17
  14. package/lib/src/worker/db/WASQLiteDB.worker.js +2 -2
  15. package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +3 -3
  16. package/lib/src/worker/db/WorkerWASQLiteConnection.js +2 -14
  17. package/lib/src/worker/sync/SharedSyncImplementation.d.ts +2 -2
  18. package/lib/src/worker/sync/SharedSyncImplementation.js +7 -4
  19. package/lib/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +1 -1
  21. package/src/db/adapters/AsyncDatabaseConnection.ts +13 -0
  22. package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +8 -2
  23. package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +8 -0
  24. package/src/worker/db/SharedWASQLiteConnection.ts +23 -20
  25. package/src/worker/db/WASQLiteDB.worker.ts +2 -2
  26. package/src/worker/db/WorkerWASQLiteConnection.ts +3 -18
  27. package/src/worker/sync/SharedSyncImplementation.ts +15 -12
package/dist/index.umd.js CHANGED
@@ -39126,10 +39126,13 @@ class WorkerWrappedAsyncDatabaseConnection {
39126
39126
  this.notifyRemoteClosed.abort();
39127
39127
  }
39128
39128
  markHold() {
39129
- return this.baseConnection.markHold();
39129
+ return this.withRemote(() => this.baseConnection.markHold());
39130
39130
  }
39131
39131
  releaseHold(holdId) {
39132
- return this.baseConnection.releaseHold(holdId);
39132
+ return this.withRemote(() => this.baseConnection.releaseHold(holdId));
39133
+ }
39134
+ isAutoCommit() {
39135
+ return this.baseConnection.isAutoCommit();
39133
39136
  }
39134
39137
  withRemote(workerPromise) {
39135
39138
  const controller = this.notifyRemoteClosed;
@@ -39137,6 +39140,8 @@ class WorkerWrappedAsyncDatabaseConnection {
39137
39140
  return new Promise((resolve, reject) => {
39138
39141
  if (controller.signal.aborted) {
39139
39142
  reject(new Error('Called operation on closed remote'));
39143
+ // Don't run the operation if we're going to reject
39144
+ return;
39140
39145
  }
39141
39146
  function handleAbort() {
39142
39147
  reject(new Error('Remote peer closed with request in flight'));
@@ -39396,6 +39401,13 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39396
39401
  }
39397
39402
  return this._dbP;
39398
39403
  }
39404
+ /**
39405
+ * Checks if the database connection is in autocommit mode.
39406
+ * @returns true if in autocommit mode, false if in a transaction
39407
+ */
39408
+ async isAutoCommit() {
39409
+ return this.sqliteAPI.get_autocommit(this.dbP) != 0;
39410
+ }
39399
39411
  async markHold() {
39400
39412
  const previousHoldId = this._holdId;
39401
39413
  this._holdId = `${++this._holdCounter}`;
@@ -40943,11 +40955,14 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
40943
40955
  return () => { };
40944
40956
  }
40945
40957
  for (const closeListener of trackedPort.closeListeners) {
40946
- closeListener();
40958
+ await closeListener();
40947
40959
  }
40948
40960
  if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
40949
40961
  // Unconditionally close the connection because the database it's writing to has just been closed.
40950
- await this.connectionManager.disconnect();
40962
+ // The connection has been closed previously, this might throw. We should be able to ignore it.
40963
+ await this.connectionManager
40964
+ .disconnect()
40965
+ .catch((ex) => this.logger.warn('Error while disconnecting. Will attempt to reconnect.', ex));
40951
40966
  // Clearing the adapter will result in a new one being opened in connect
40952
40967
  this.dbAdapter = null;
40953
40968
  if (shouldReconnect) {
@@ -41076,9 +41091,9 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
41076
41091
  // that and ensure pending requests are aborted when the tab is closed.
41077
41092
  remoteCanCloseUnexpectedly: true
41078
41093
  });
41079
- lastClient.closeListeners.push(() => {
41094
+ lastClient.closeListeners.push(async () => {
41080
41095
  this.logger.info('Aborting open connection because associated tab closed.');
41081
- wrapped.close();
41096
+ await wrapped.close().catch((ex) => this.logger.warn('error closing database connection', ex));
41082
41097
  wrapped.markRemoteClosed();
41083
41098
  });
41084
41099
  return wrapped;