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