@powersync/web 0.0.0-dev-20260305124002 → 0.0.0-dev-20260306114652

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.
@@ -14939,7 +14939,7 @@ function requireDist () {
14939
14939
 
14940
14940
  var distExports = requireDist();
14941
14941
 
14942
- var version = "1.47.0";
14942
+ var version = "1.48.0";
14943
14943
  var PACKAGE = {
14944
14944
  version: version};
14945
14945
 
@@ -16912,8 +16912,9 @@ class TriggerManagerImpl {
16912
16912
  ...config
16913
16913
  };
16914
16914
  }
16915
- generateTriggerName(operation, destinationTable, triggerId) {
16916
- return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
16915
+ generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
16916
+ const managedTerm = managedExternally ? '_external' : '';
16917
+ return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
16917
16918
  }
16918
16919
  /**
16919
16920
  * Cleanup any SQLite triggers or tables that are no longer in use.
@@ -16970,6 +16971,26 @@ class TriggerManagerImpl {
16970
16971
  }
16971
16972
  });
16972
16973
  }
16974
+ /**
16975
+ * Creates a diff trigger destination table on the database with the given configuration.
16976
+ * By default this is invoked internally when creating a diff trigger, but can
16977
+ * be used manually if `manageDestinationExternally` is set to true.
16978
+ */
16979
+ async createDiffDestinationTable(tableName, options) {
16980
+ const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
16981
+ const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
16982
+ const ctx = options?.lockContext ?? this.db.database;
16983
+ await ctx.execute(/* sql */ `
16984
+ CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
16985
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
16986
+ id TEXT,
16987
+ operation TEXT,
16988
+ timestamp TEXT,
16989
+ value TEXT,
16990
+ previous_value TEXT
16991
+ )
16992
+ `);
16993
+ }
16973
16994
  async createDiffTrigger(options) {
16974
16995
  await this.db.waitForReady();
16975
16996
  const { source, destination, columns, when, hooks, manageDestinationExternally = false,
@@ -17041,19 +17062,14 @@ class TriggerManagerImpl {
17041
17062
  // Allow user code to execute in this lock context before the trigger is created.
17042
17063
  await hooks?.beforeCreate?.(tx);
17043
17064
  if (!manageDestinationExternally) {
17044
- await tx.execute(/* sql */ `
17045
- CREATE ${tableTriggerTypeClause} TABLE ${destination} (
17046
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
17047
- id TEXT,
17048
- operation TEXT,
17049
- timestamp TEXT,
17050
- value TEXT,
17051
- previous_value TEXT
17052
- )
17053
- `);
17065
+ await this.createDiffDestinationTable(destination, {
17066
+ lockContext: tx,
17067
+ useStorage,
17068
+ onlyIfNotExists: false
17069
+ });
17054
17070
  }
17055
17071
  if (operations.includes(DiffTriggerOperation.INSERT)) {
17056
- const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
17072
+ const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
17057
17073
  triggerIds.push(insertTriggerId);
17058
17074
  await tx.execute(/* sql */ `
17059
17075
  CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
@@ -17071,7 +17087,7 @@ class TriggerManagerImpl {
17071
17087
  `);
17072
17088
  }
17073
17089
  if (operations.includes(DiffTriggerOperation.UPDATE)) {
17074
- const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
17090
+ const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
17075
17091
  triggerIds.push(updateTriggerId);
17076
17092
  await tx.execute(/* sql */ `
17077
17093
  CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
@@ -17091,7 +17107,7 @@ class TriggerManagerImpl {
17091
17107
  `);
17092
17108
  }
17093
17109
  if (operations.includes(DiffTriggerOperation.DELETE)) {
17094
- const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
17110
+ const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
17095
17111
  triggerIds.push(deleteTriggerId);
17096
17112
  // Create delete trigger for basic JSON
17097
17113
  await tx.execute(/* sql */ `