@powersync/common 1.41.1 → 1.43.0

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.
@@ -6704,7 +6704,7 @@ function requireDist () {
6704
6704
 
6705
6705
  var distExports = requireDist();
6706
6706
 
6707
- var version = "1.41.1";
6707
+ var version = "1.43.0";
6708
6708
  var PACKAGE = {
6709
6709
  version: version};
6710
6710
 
@@ -7452,9 +7452,11 @@ class AbstractRemote {
7452
7452
  // Create a new stream splitting the response at line endings while also handling cancellations
7453
7453
  // by closing the reader.
7454
7454
  const reader = res.body.getReader();
7455
+ let readerReleased = false;
7455
7456
  // This will close the network request and read stream
7456
7457
  const closeReader = async () => {
7457
7458
  try {
7459
+ readerReleased = true;
7458
7460
  await reader.cancel();
7459
7461
  }
7460
7462
  catch (ex) {
@@ -7462,17 +7464,21 @@ class AbstractRemote {
7462
7464
  }
7463
7465
  reader.releaseLock();
7464
7466
  };
7467
+ const stream = new DataStream({
7468
+ logger: this.logger,
7469
+ mapLine: mapLine
7470
+ });
7465
7471
  abortSignal?.addEventListener('abort', () => {
7466
7472
  closeReader();
7473
+ stream.close();
7467
7474
  });
7468
7475
  const decoder = this.createTextDecoder();
7469
7476
  let buffer = '';
7470
- const stream = new DataStream({
7471
- logger: this.logger,
7472
- mapLine: mapLine
7473
- });
7474
7477
  const l = stream.registerListener({
7475
7478
  lowWater: async () => {
7479
+ if (stream.closed || abortSignal?.aborted || readerReleased) {
7480
+ return;
7481
+ }
7476
7482
  try {
7477
7483
  let didCompleteLine = false;
7478
7484
  while (!didCompleteLine) {
@@ -8632,6 +8638,7 @@ class TriggerManagerImpl {
8632
8638
  await hooks?.beforeCreate?.(tx);
8633
8639
  await tx.execute(/* sql */ `
8634
8640
  CREATE TEMP TABLE ${destination} (
8641
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
8635
8642
  id TEXT,
8636
8643
  operation TEXT,
8637
8644
  timestamp TEXT,
@@ -8742,17 +8749,20 @@ class TriggerManagerImpl {
8742
8749
  const callbackResult = await options.onChange({
8743
8750
  ...tx,
8744
8751
  destinationTable: destination,
8745
- withDiff: async (query, params) => {
8752
+ withDiff: async (query, params, options) => {
8746
8753
  // Wrap the query to expose the destination table
8754
+ const operationIdSelect = options?.castOperationIdAsText
8755
+ ? 'id, operation, CAST(operation_id AS TEXT) as operation_id, timestamp, value, previous_value'
8756
+ : '*';
8747
8757
  const wrappedQuery = /* sql */ `
8748
8758
  WITH
8749
8759
  DIFF AS (
8750
8760
  SELECT
8751
- *
8761
+ ${operationIdSelect}
8752
8762
  FROM
8753
8763
  ${destination}
8754
8764
  ORDER BY
8755
- timestamp ASC
8765
+ operation_id ASC
8756
8766
  ) ${query}
8757
8767
  `;
8758
8768
  return tx.getAll(wrappedQuery, params);
@@ -8766,13 +8776,14 @@ class TriggerManagerImpl {
8766
8776
  id,
8767
8777
  ${contextColumns.length > 0
8768
8778
  ? `${contextColumns.map((col) => `json_extract(value, '$.${col}') as ${col}`).join(', ')},`
8769
- : ''} operation as __operation,
8779
+ : ''} operation_id as __operation_id,
8780
+ operation as __operation,
8770
8781
  timestamp as __timestamp,
8771
8782
  previous_value as __previous_value
8772
8783
  FROM
8773
8784
  ${destination}
8774
8785
  ORDER BY
8775
- __timestamp ASC
8786
+ __operation_id ASC
8776
8787
  ) ${query}
8777
8788
  `;
8778
8789
  return tx.getAll(wrappedQuery, params);