@powersync/common 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.
@@ -7935,7 +7935,7 @@ function requireDist () {
7935
7935
 
7936
7936
  var distExports = requireDist();
7937
7937
 
7938
- var version = "1.47.0";
7938
+ var version = "1.48.0";
7939
7939
  var PACKAGE = {
7940
7940
  version: version};
7941
7941
 
@@ -9908,8 +9908,9 @@ class TriggerManagerImpl {
9908
9908
  ...config
9909
9909
  };
9910
9910
  }
9911
- generateTriggerName(operation, destinationTable, triggerId) {
9912
- return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
9911
+ generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
9912
+ const managedTerm = managedExternally ? '_external' : '';
9913
+ return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
9913
9914
  }
9914
9915
  /**
9915
9916
  * Cleanup any SQLite triggers or tables that are no longer in use.
@@ -9966,6 +9967,26 @@ class TriggerManagerImpl {
9966
9967
  }
9967
9968
  });
9968
9969
  }
9970
+ /**
9971
+ * Creates a diff trigger destination table on the database with the given configuration.
9972
+ * By default this is invoked internally when creating a diff trigger, but can
9973
+ * be used manually if `manageDestinationExternally` is set to true.
9974
+ */
9975
+ async createDiffDestinationTable(tableName, options) {
9976
+ const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
9977
+ const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
9978
+ const ctx = options?.lockContext ?? this.db.database;
9979
+ await ctx.execute(/* sql */ `
9980
+ CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
9981
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
9982
+ id TEXT,
9983
+ operation TEXT,
9984
+ timestamp TEXT,
9985
+ value TEXT,
9986
+ previous_value TEXT
9987
+ )
9988
+ `);
9989
+ }
9969
9990
  async createDiffTrigger(options) {
9970
9991
  await this.db.waitForReady();
9971
9992
  const { source, destination, columns, when, hooks, manageDestinationExternally = false,
@@ -10037,19 +10058,14 @@ class TriggerManagerImpl {
10037
10058
  // Allow user code to execute in this lock context before the trigger is created.
10038
10059
  await hooks?.beforeCreate?.(tx);
10039
10060
  if (!manageDestinationExternally) {
10040
- await tx.execute(/* sql */ `
10041
- CREATE ${tableTriggerTypeClause} TABLE ${destination} (
10042
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
10043
- id TEXT,
10044
- operation TEXT,
10045
- timestamp TEXT,
10046
- value TEXT,
10047
- previous_value TEXT
10048
- )
10049
- `);
10061
+ await this.createDiffDestinationTable(destination, {
10062
+ lockContext: tx,
10063
+ useStorage,
10064
+ onlyIfNotExists: false
10065
+ });
10050
10066
  }
10051
10067
  if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
10052
- const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
10068
+ const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
10053
10069
  triggerIds.push(insertTriggerId);
10054
10070
  await tx.execute(/* sql */ `
10055
10071
  CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
@@ -10067,7 +10083,7 @@ class TriggerManagerImpl {
10067
10083
  `);
10068
10084
  }
10069
10085
  if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
10070
- const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
10086
+ const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
10071
10087
  triggerIds.push(updateTriggerId);
10072
10088
  await tx.execute(/* sql */ `
10073
10089
  CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
@@ -10087,7 +10103,7 @@ class TriggerManagerImpl {
10087
10103
  `);
10088
10104
  }
10089
10105
  if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
10090
- const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
10106
+ const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
10091
10107
  triggerIds.push(deleteTriggerId);
10092
10108
  // Create delete trigger for basic JSON
10093
10109
  await tx.execute(/* sql */ `