@powersync/web 0.0.0-dev-20260305092446 → 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.
@@ -13555,7 +13555,7 @@ function requireDist () {
13555
13555
 
13556
13556
  var distExports = requireDist();
13557
13557
 
13558
- var version = "1.47.0";
13558
+ var version = "1.48.0";
13559
13559
  var PACKAGE = {
13560
13560
  version: version};
13561
13561
 
@@ -15528,8 +15528,9 @@ class TriggerManagerImpl {
15528
15528
  ...config
15529
15529
  };
15530
15530
  }
15531
- generateTriggerName(operation, destinationTable, triggerId) {
15532
- return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
15531
+ generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
15532
+ const managedTerm = managedExternally ? '_external' : '';
15533
+ return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
15533
15534
  }
15534
15535
  /**
15535
15536
  * Cleanup any SQLite triggers or tables that are no longer in use.
@@ -15586,9 +15587,29 @@ class TriggerManagerImpl {
15586
15587
  }
15587
15588
  });
15588
15589
  }
15590
+ /**
15591
+ * Creates a diff trigger destination table on the database with the given configuration.
15592
+ * By default this is invoked internally when creating a diff trigger, but can
15593
+ * be used manually if `manageDestinationExternally` is set to true.
15594
+ */
15595
+ async createDiffDestinationTable(tableName, options) {
15596
+ const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
15597
+ const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
15598
+ const ctx = options?.lockContext ?? this.db.database;
15599
+ await ctx.execute(/* sql */ `
15600
+ CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
15601
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
15602
+ id TEXT,
15603
+ operation TEXT,
15604
+ timestamp TEXT,
15605
+ value TEXT,
15606
+ previous_value TEXT
15607
+ )
15608
+ `);
15609
+ }
15589
15610
  async createDiffTrigger(options) {
15590
15611
  await this.db.waitForReady();
15591
- const { source, destination, columns, when, hooks, persistDestination = false,
15612
+ const { source, destination, columns, when, hooks, manageDestinationExternally = false,
15592
15613
  // Fall back to the provided default if not given on this level
15593
15614
  useStorage = this.defaultConfig.useStorageByDefault } = options;
15594
15615
  const operations = Object.keys(when);
@@ -15643,11 +15664,11 @@ class TriggerManagerImpl {
15643
15664
  * we need to ensure we can cleanup the created resources.
15644
15665
  * We unfortunately cannot rely on transaction rollback.
15645
15666
  */
15646
- const cleanup = async (force) => {
15667
+ const cleanup = async () => {
15647
15668
  disposeWarningListener();
15648
15669
  return this.db.writeLock(async (tx) => {
15649
15670
  await this.removeTriggers(tx, triggerIds);
15650
- if (!persistDestination || force) {
15671
+ if (!manageDestinationExternally) {
15651
15672
  await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
15652
15673
  }
15653
15674
  await releaseStorageClaim?.();
@@ -15656,18 +15677,15 @@ class TriggerManagerImpl {
15656
15677
  const setup = async (tx) => {
15657
15678
  // Allow user code to execute in this lock context before the trigger is created.
15658
15679
  await hooks?.beforeCreate?.(tx);
15659
- await tx.execute(/* sql */ `
15660
- CREATE ${tableTriggerTypeClause} TABLE ${persistDestination ? 'IF NOT EXISTS ' : ''}${destination} (
15661
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
15662
- id TEXT,
15663
- operation TEXT,
15664
- timestamp TEXT,
15665
- value TEXT,
15666
- previous_value TEXT
15667
- )
15668
- `);
15680
+ if (!manageDestinationExternally) {
15681
+ await this.createDiffDestinationTable(destination, {
15682
+ lockContext: tx,
15683
+ useStorage,
15684
+ onlyIfNotExists: false
15685
+ });
15686
+ }
15669
15687
  if (operations.includes(DiffTriggerOperation.INSERT)) {
15670
- const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
15688
+ const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
15671
15689
  triggerIds.push(insertTriggerId);
15672
15690
  await tx.execute(/* sql */ `
15673
15691
  CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
@@ -15685,7 +15703,7 @@ class TriggerManagerImpl {
15685
15703
  `);
15686
15704
  }
15687
15705
  if (operations.includes(DiffTriggerOperation.UPDATE)) {
15688
- const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
15706
+ const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
15689
15707
  triggerIds.push(updateTriggerId);
15690
15708
  await tx.execute(/* sql */ `
15691
15709
  CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
@@ -15705,7 +15723,7 @@ class TriggerManagerImpl {
15705
15723
  `);
15706
15724
  }
15707
15725
  if (operations.includes(DiffTriggerOperation.DELETE)) {
15708
- const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
15726
+ const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
15709
15727
  triggerIds.push(deleteTriggerId);
15710
15728
  // Create delete trigger for basic JSON
15711
15729
  await tx.execute(/* sql */ `