@powersync/web 0.0.0-dev-20251111122755 → 0.0.0-dev-20251119150914

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 (28) hide show
  1. package/dist/index.umd.js +39 -2
  2. package/dist/index.umd.js.map +1 -1
  3. package/dist/worker/SharedSyncImplementation.umd.js +35 -12
  4. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  5. package/dist/worker/WASQLiteDB.umd.js +217 -54
  6. package/dist/worker/WASQLiteDB.umd.js.map +1 -1
  7. package/lib/package.json +2 -2
  8. package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +10 -0
  9. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +1 -1
  10. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +8 -2
  11. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +2 -0
  12. package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +6 -0
  13. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +17 -0
  14. package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +25 -0
  15. package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +41 -0
  16. package/lib/src/worker/db/SharedWASQLiteConnection.js +86 -0
  17. package/lib/src/worker/db/WASQLiteDB.worker.js +22 -39
  18. package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +9 -0
  19. package/lib/src/worker/db/WorkerWASQLiteConnection.js +24 -0
  20. package/lib/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +3 -3
  22. package/src/db/adapters/AsyncDatabaseConnection.ts +10 -0
  23. package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +19 -10
  24. package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +8 -0
  25. package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +37 -0
  26. package/src/worker/db/SharedWASQLiteConnection.ts +126 -0
  27. package/src/worker/db/WASQLiteDB.worker.ts +25 -54
  28. package/src/worker/db/WorkerWASQLiteConnection.ts +29 -0
package/dist/index.umd.js CHANGED
@@ -38862,12 +38862,18 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38862
38862
  this.pendingAbortControllers.delete(abortController);
38863
38863
  }, timeoutMs)
38864
38864
  : null;
38865
- return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
38865
+ return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, async () => {
38866
38866
  this.pendingAbortControllers.delete(abortController);
38867
38867
  if (timoutId) {
38868
38868
  clearTimeout(timoutId);
38869
38869
  }
38870
- return callback();
38870
+ const holdId = await this.baseDB.markHold();
38871
+ try {
38872
+ return await callback();
38873
+ }
38874
+ finally {
38875
+ await this.baseDB.releaseHold(holdId);
38876
+ }
38871
38877
  });
38872
38878
  }
38873
38879
  async readTransaction(fn, options) {
@@ -39119,6 +39125,12 @@ class WorkerWrappedAsyncDatabaseConnection {
39119
39125
  // set.
39120
39126
  this.notifyRemoteClosed.abort();
39121
39127
  }
39128
+ markHold() {
39129
+ return this.baseConnection.markHold();
39130
+ }
39131
+ releaseHold(holdId) {
39132
+ return this.baseConnection.releaseHold(holdId);
39133
+ }
39122
39134
  withRemote(workerPromise) {
39123
39135
  const controller = this.notifyRemoteClosed;
39124
39136
  if (controller) {
@@ -39351,6 +39363,8 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39351
39363
  * notification loops.
39352
39364
  */
39353
39365
  connectionId;
39366
+ _holdCounter;
39367
+ _holdId;
39354
39368
  constructor(options) {
39355
39369
  super();
39356
39370
  this.options = options;
@@ -39360,6 +39374,15 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39360
39374
  this.connectionId = new Date().valueOf() + Math.random();
39361
39375
  this.statementMutex = new async_mutex__WEBPACK_IMPORTED_MODULE_2__.Mutex();
39362
39376
  this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
39377
+ this._holdCounter = 0;
39378
+ this._holdId = null;
39379
+ }
39380
+ /**
39381
+ * Gets the id for the current hold.
39382
+ * This can be used to check for invalid states.
39383
+ */
39384
+ get currentHoldId() {
39385
+ return this._holdId;
39363
39386
  }
39364
39387
  get sqliteAPI() {
39365
39388
  if (!this._sqliteAPI) {
@@ -39373,6 +39396,20 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39373
39396
  }
39374
39397
  return this._dbP;
39375
39398
  }
39399
+ async markHold() {
39400
+ const previousHoldId = this._holdId;
39401
+ this._holdId = `${++this._holdCounter}`;
39402
+ if (previousHoldId) {
39403
+ await this.iterateAsyncListeners(async (cb) => cb.holdOverwritten?.(previousHoldId));
39404
+ }
39405
+ return this._holdId;
39406
+ }
39407
+ async releaseHold(holdId) {
39408
+ if (holdId != this._holdId) {
39409
+ throw new Error(`Invalid hold state, expected ${this._holdId} but got ${holdId}`);
39410
+ }
39411
+ this._holdId = null;
39412
+ }
39376
39413
  async openDB() {
39377
39414
  this._dbP = await this.sqliteAPI.open_v2(this.options.dbFilename);
39378
39415
  return this._dbP;