@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
@@ -7914,7 +7914,7 @@ function requireDist () {
7914
7914
 
7915
7915
  var distExports = requireDist();
7916
7916
 
7917
- var version = "1.41.0";
7917
+ var version = "1.42.0";
7918
7918
  var PACKAGE = {
7919
7919
  version: version};
7920
7920
 
@@ -8662,9 +8662,11 @@ class AbstractRemote {
8662
8662
  // Create a new stream splitting the response at line endings while also handling cancellations
8663
8663
  // by closing the reader.
8664
8664
  const reader = res.body.getReader();
8665
+ let readerReleased = false;
8665
8666
  // This will close the network request and read stream
8666
8667
  const closeReader = async () => {
8667
8668
  try {
8669
+ readerReleased = true;
8668
8670
  await reader.cancel();
8669
8671
  }
8670
8672
  catch (ex) {
@@ -8672,17 +8674,21 @@ class AbstractRemote {
8672
8674
  }
8673
8675
  reader.releaseLock();
8674
8676
  };
8677
+ const stream = new DataStream({
8678
+ logger: this.logger,
8679
+ mapLine: mapLine
8680
+ });
8675
8681
  abortSignal?.addEventListener('abort', () => {
8676
8682
  closeReader();
8683
+ stream.close();
8677
8684
  });
8678
8685
  const decoder = this.createTextDecoder();
8679
8686
  let buffer = '';
8680
- const stream = new DataStream({
8681
- logger: this.logger,
8682
- mapLine: mapLine
8683
- });
8684
8687
  const l = stream.registerListener({
8685
8688
  lowWater: async () => {
8689
+ if (stream.closed || abortSignal?.aborted || readerReleased) {
8690
+ return;
8691
+ }
8686
8692
  try {
8687
8693
  let didCompleteLine = false;
8688
8694
  while (!didCompleteLine) {
@@ -9842,6 +9848,7 @@ class TriggerManagerImpl {
9842
9848
  await hooks?.beforeCreate?.(tx);
9843
9849
  await tx.execute(/* sql */ `
9844
9850
  CREATE TEMP TABLE ${destination} (
9851
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
9845
9852
  id TEXT,
9846
9853
  operation TEXT,
9847
9854
  timestamp TEXT,
@@ -9952,17 +9959,20 @@ class TriggerManagerImpl {
9952
9959
  const callbackResult = await options.onChange({
9953
9960
  ...tx,
9954
9961
  destinationTable: destination,
9955
- withDiff: async (query, params) => {
9962
+ withDiff: async (query, params, options) => {
9956
9963
  // Wrap the query to expose the destination table
9964
+ const operationIdSelect = options?.castOperationIdAsText
9965
+ ? 'id, operation, CAST(operation_id AS TEXT) as operation_id, timestamp, value, previous_value'
9966
+ : '*';
9957
9967
  const wrappedQuery = /* sql */ `
9958
9968
  WITH
9959
9969
  DIFF AS (
9960
9970
  SELECT
9961
- *
9971
+ ${operationIdSelect}
9962
9972
  FROM
9963
9973
  ${destination}
9964
9974
  ORDER BY
9965
- timestamp ASC
9975
+ operation_id ASC
9966
9976
  ) ${query}
9967
9977
  `;
9968
9978
  return tx.getAll(wrappedQuery, params);
@@ -9976,13 +9986,14 @@ class TriggerManagerImpl {
9976
9986
  id,
9977
9987
  ${contextColumns.length > 0
9978
9988
  ? `${contextColumns.map((col) => `json_extract(value, '$.${col}') as ${col}`).join(', ')},`
9979
- : ''} operation as __operation,
9989
+ : ''} operation_id as __operation_id,
9990
+ operation as __operation,
9980
9991
  timestamp as __timestamp,
9981
9992
  previous_value as __previous_value
9982
9993
  FROM
9983
9994
  ${destination}
9984
9995
  ORDER BY
9985
- __timestamp ASC
9996
+ __operation_id ASC
9986
9997
  ) ${query}
9987
9998
  `;
9988
9999
  return tx.getAll(wrappedQuery, params);
@@ -14112,15 +14123,11 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
14112
14123
  const start = performance.now();
14113
14124
  try {
14114
14125
  const r = await originalExecute(sql, bindings);
14115
- const duration = performance.now() - start;
14116
14126
  performance.measure(`[SQL] ${sql}`, { start });
14117
- 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);
14118
14127
  return r;
14119
14128
  }
14120
14129
  catch (e) {
14121
- const duration = performance.now() - start;
14122
14130
  performance.measure(`[SQL] [ERROR: ${e.message}] ${sql}`, { start });
14123
- 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);
14124
14131
  throw e;
14125
14132
  }
14126
14133
  };
@@ -14241,12 +14248,18 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
14241
14248
  this.pendingAbortControllers.delete(abortController);
14242
14249
  }, timeoutMs)
14243
14250
  : null;
14244
- return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
14251
+ return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, async () => {
14245
14252
  this.pendingAbortControllers.delete(abortController);
14246
14253
  if (timoutId) {
14247
14254
  clearTimeout(timoutId);
14248
14255
  }
14249
- return callback();
14256
+ const holdId = await this.baseDB.markHold();
14257
+ try {
14258
+ return await callback();
14259
+ }
14260
+ finally {
14261
+ await this.baseDB.releaseHold(holdId);
14262
+ }
14250
14263
  });
14251
14264
  }
14252
14265
  async readTransaction(fn, options) {
@@ -14360,17 +14373,6 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
14360
14373
  };
14361
14374
  };
14362
14375
  }
14363
- function durationStyle(duration) {
14364
- if (duration < 30) {
14365
- return 'color: grey; font-weight: normal';
14366
- }
14367
- else if (duration < 300) {
14368
- return 'color: blue; font-weight: normal';
14369
- }
14370
- else {
14371
- return 'color: red; font-weight: normal';
14372
- }
14373
- }
14374
14376
 
14375
14377
 
14376
14378
  /***/ }),
@@ -14420,6 +14422,12 @@ class WorkerWrappedAsyncDatabaseConnection {
14420
14422
  // set.
14421
14423
  this.notifyRemoteClosed.abort();
14422
14424
  }
14425
+ markHold() {
14426
+ return this.baseConnection.markHold();
14427
+ }
14428
+ releaseHold(holdId) {
14429
+ return this.baseConnection.releaseHold(holdId);
14430
+ }
14423
14431
  withRemote(workerPromise) {
14424
14432
  const controller = this.notifyRemoteClosed;
14425
14433
  if (controller) {