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

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 -17
  2. package/dist/index.umd.js.map +1 -1
  3. package/dist/worker/SharedSyncImplementation.umd.js +35 -27
  4. package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
  5. package/dist/worker/WASQLiteDB.umd.js +220 -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 +2 -0
  9. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +1 -1
  10. package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +8 -17
  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 +89 -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 +2 -0
  23. package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +19 -40
  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 +127 -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
@@ -38737,15 +38737,11 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38737
38737
  const start = performance.now();
38738
38738
  try {
38739
38739
  const r = await originalExecute(sql, bindings);
38740
- const duration = performance.now() - start;
38741
38740
  performance.measure(`[SQL] ${sql}`, { start });
38742
- console.log('%c[SQL] %c%s %c%s', 'color: grey; font-weight: normal', durationStyle(duration), `[${duration.toFixed(1)}ms]`, 'color: grey; font-weight: normal', sql);
38743
38741
  return r;
38744
38742
  }
38745
38743
  catch (e) {
38746
- const duration = performance.now() - start;
38747
38744
  performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });
38748
- console.error('%c[SQL] %c%s %c%s %c%s', 'color: grey; font-weight: normal', 'color: red; font-weight: normal', `[ERROR: ${e.message}]`, durationStyle(duration), `[${duration.toFixed(1)}ms]`, 'color: grey; font-weight: normal', sql);
38749
38745
  throw e;
38750
38746
  }
38751
38747
  };
@@ -38866,12 +38862,18 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38866
38862
  this.pendingAbortControllers.delete(abortController);
38867
38863
  }, timeoutMs)
38868
38864
  : null;
38869
- 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 () => {
38870
38866
  this.pendingAbortControllers.delete(abortController);
38871
38867
  if (timoutId) {
38872
38868
  clearTimeout(timoutId);
38873
38869
  }
38874
- 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
+ }
38875
38877
  });
38876
38878
  }
38877
38879
  async readTransaction(fn, options) {
@@ -38985,17 +38987,6 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
38985
38987
  };
38986
38988
  };
38987
38989
  }
38988
- function durationStyle(duration) {
38989
- if (duration < 30) {
38990
- return 'color: grey; font-weight: normal';
38991
- }
38992
- else if (duration < 300) {
38993
- return 'color: blue; font-weight: normal';
38994
- }
38995
- else {
38996
- return 'color: red; font-weight: normal';
38997
- }
38998
- }
38999
38990
 
39000
38991
 
39001
38992
  /***/ }),
@@ -39134,6 +39125,12 @@ class WorkerWrappedAsyncDatabaseConnection {
39134
39125
  // set.
39135
39126
  this.notifyRemoteClosed.abort();
39136
39127
  }
39128
+ markHold() {
39129
+ return this.baseConnection.markHold();
39130
+ }
39131
+ releaseHold(holdId) {
39132
+ return this.baseConnection.releaseHold(holdId);
39133
+ }
39137
39134
  withRemote(workerPromise) {
39138
39135
  const controller = this.notifyRemoteClosed;
39139
39136
  if (controller) {
@@ -39366,6 +39363,8 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39366
39363
  * notification loops.
39367
39364
  */
39368
39365
  connectionId;
39366
+ _holdCounter;
39367
+ _holdId;
39369
39368
  constructor(options) {
39370
39369
  super();
39371
39370
  this.options = options;
@@ -39375,6 +39374,15 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39375
39374
  this.connectionId = new Date().valueOf() + Math.random();
39376
39375
  this.statementMutex = new async_mutex__WEBPACK_IMPORTED_MODULE_2__.Mutex();
39377
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;
39378
39386
  }
39379
39387
  get sqliteAPI() {
39380
39388
  if (!this._sqliteAPI) {
@@ -39388,6 +39396,20 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
39388
39396
  }
39389
39397
  return this._dbP;
39390
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
+ }
39391
39413
  async openDB() {
39392
39414
  this._dbP = await this.sqliteAPI.open_v2(this.options.dbFilename);
39393
39415
  return this._dbP;