@powersync/common 0.0.0-dev-20251111122755 → 0.0.0-dev-20251203144301

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.
@@ -569,12 +569,26 @@ class SyncStatus {
569
569
  return {
570
570
  connected: this.connected,
571
571
  connecting: this.connecting,
572
- dataFlow: this.dataFlowStatus,
572
+ dataFlow: {
573
+ ...this.dataFlowStatus,
574
+ uploadError: this.serializeError(this.dataFlowStatus.uploadError),
575
+ downloadError: this.serializeError(this.dataFlowStatus.downloadError)
576
+ },
573
577
  lastSyncedAt: this.lastSyncedAt,
574
578
  hasSynced: this.hasSynced,
575
579
  priorityStatusEntries: this.priorityStatusEntries
576
580
  };
577
581
  }
582
+ serializeError(error) {
583
+ if (typeof error == 'undefined') {
584
+ return undefined;
585
+ }
586
+ return {
587
+ name: error.name,
588
+ message: error.message,
589
+ stack: error.stack
590
+ };
591
+ }
578
592
  static comparePriorities(a, b) {
579
593
  return b.priority - a.priority; // Reverse because higher priorities have lower numbers
580
594
  }
@@ -6702,7 +6716,7 @@ function requireDist () {
6702
6716
 
6703
6717
  var distExports = requireDist();
6704
6718
 
6705
- var version = "1.41.0";
6719
+ var version = "1.43.1";
6706
6720
  var PACKAGE = {
6707
6721
  version: version};
6708
6722
 
@@ -7450,9 +7464,11 @@ class AbstractRemote {
7450
7464
  // Create a new stream splitting the response at line endings while also handling cancellations
7451
7465
  // by closing the reader.
7452
7466
  const reader = res.body.getReader();
7467
+ let readerReleased = false;
7453
7468
  // This will close the network request and read stream
7454
7469
  const closeReader = async () => {
7455
7470
  try {
7471
+ readerReleased = true;
7456
7472
  await reader.cancel();
7457
7473
  }
7458
7474
  catch (ex) {
@@ -7460,17 +7476,21 @@ class AbstractRemote {
7460
7476
  }
7461
7477
  reader.releaseLock();
7462
7478
  };
7479
+ const stream = new DataStream({
7480
+ logger: this.logger,
7481
+ mapLine: mapLine
7482
+ });
7463
7483
  abortSignal?.addEventListener('abort', () => {
7464
7484
  closeReader();
7485
+ stream.close();
7465
7486
  });
7466
7487
  const decoder = this.createTextDecoder();
7467
7488
  let buffer = '';
7468
- const stream = new DataStream({
7469
- logger: this.logger,
7470
- mapLine: mapLine
7471
- });
7472
7489
  const l = stream.registerListener({
7473
7490
  lowWater: async () => {
7491
+ if (stream.closed || abortSignal?.aborted || readerReleased) {
7492
+ return;
7493
+ }
7474
7494
  try {
7475
7495
  let didCompleteLine = false;
7476
7496
  while (!didCompleteLine) {
@@ -8630,6 +8650,7 @@ class TriggerManagerImpl {
8630
8650
  await hooks?.beforeCreate?.(tx);
8631
8651
  await tx.execute(/* sql */ `
8632
8652
  CREATE TEMP TABLE ${destination} (
8653
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
8633
8654
  id TEXT,
8634
8655
  operation TEXT,
8635
8656
  timestamp TEXT,
@@ -8740,17 +8761,20 @@ class TriggerManagerImpl {
8740
8761
  const callbackResult = await options.onChange({
8741
8762
  ...tx,
8742
8763
  destinationTable: destination,
8743
- withDiff: async (query, params) => {
8764
+ withDiff: async (query, params, options) => {
8744
8765
  // Wrap the query to expose the destination table
8766
+ const operationIdSelect = options?.castOperationIdAsText
8767
+ ? 'id, operation, CAST(operation_id AS TEXT) as operation_id, timestamp, value, previous_value'
8768
+ : '*';
8745
8769
  const wrappedQuery = /* sql */ `
8746
8770
  WITH
8747
8771
  DIFF AS (
8748
8772
  SELECT
8749
- *
8773
+ ${operationIdSelect}
8750
8774
  FROM
8751
8775
  ${destination}
8752
8776
  ORDER BY
8753
- timestamp ASC
8777
+ operation_id ASC
8754
8778
  ) ${query}
8755
8779
  `;
8756
8780
  return tx.getAll(wrappedQuery, params);
@@ -8764,13 +8788,14 @@ class TriggerManagerImpl {
8764
8788
  id,
8765
8789
  ${contextColumns.length > 0
8766
8790
  ? `${contextColumns.map((col) => `json_extract(value, '$.${col}') as ${col}`).join(', ')},`
8767
- : ''} operation as __operation,
8791
+ : ''} operation_id as __operation_id,
8792
+ operation as __operation,
8768
8793
  timestamp as __timestamp,
8769
8794
  previous_value as __previous_value
8770
8795
  FROM
8771
8796
  ${destination}
8772
8797
  ORDER BY
8773
- __timestamp ASC
8798
+ __operation_id ASC
8774
8799
  ) ${query}
8775
8800
  `;
8776
8801
  return tx.getAll(wrappedQuery, params);
@@ -10044,7 +10069,7 @@ class SqliteBucketStorage extends BaseObserver {
10044
10069
  // Nothing to update
10045
10070
  return false;
10046
10071
  }
10047
- const rs = await this.db.getAll("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
10072
+ const rs = await this.db.getAll("SELECT seq FROM main.sqlite_sequence WHERE name = 'ps_crud'");
10048
10073
  if (!rs.length) {
10049
10074
  // Nothing to update
10050
10075
  return false;
@@ -10058,7 +10083,7 @@ class SqliteBucketStorage extends BaseObserver {
10058
10083
  this.logger.debug(`New data uploaded since write checkpoint ${opId} - need new write checkpoint`);
10059
10084
  return false;
10060
10085
  }
10061
- const rs = await tx.execute("SELECT seq FROM sqlite_sequence WHERE name = 'ps_crud'");
10086
+ const rs = await tx.execute("SELECT seq FROM main.sqlite_sequence WHERE name = 'ps_crud'");
10062
10087
  if (!rs.rows?.length) {
10063
10088
  // assert isNotEmpty
10064
10089
  throw new Error('SQLite Sequence should not be empty');