@powersync/common 0.0.0-dev-20260309101613 → 0.0.0-dev-20260311080613

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.
package/dist/bundle.mjs CHANGED
@@ -12428,9 +12428,8 @@ class TriggerManagerImpl {
12428
12428
  ...config
12429
12429
  };
12430
12430
  }
12431
- generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
12432
- const managedTerm = managedExternally ? '_external' : '';
12433
- return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
12431
+ generateTriggerName(operation, destinationTable, triggerId) {
12432
+ return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
12434
12433
  }
12435
12434
  /**
12436
12435
  * Cleanup any SQLite triggers or tables that are no longer in use.
@@ -12487,24 +12486,9 @@ class TriggerManagerImpl {
12487
12486
  }
12488
12487
  });
12489
12488
  }
12490
- async createDiffDestinationTable(tableName, options) {
12491
- const { temporary = true, onlyIfNotExists = false } = options ?? {};
12492
- const tableTriggerTypeClause = temporary ? 'TEMP' : '';
12493
- const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
12494
- await this.db.execute(/* sql */ `
12495
- CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
12496
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
12497
- id TEXT,
12498
- operation TEXT,
12499
- timestamp TEXT,
12500
- value TEXT,
12501
- previous_value TEXT
12502
- )
12503
- `);
12504
- }
12505
12489
  async createDiffTrigger(options) {
12506
12490
  await this.db.waitForReady();
12507
- const { source, destination, columns, when, hooks, manageDestinationExternally = false,
12491
+ const { source, destination, columns, when, hooks,
12508
12492
  // Fall back to the provided default if not given on this level
12509
12493
  useStorage = this.defaultConfig.useStorageByDefault } = options;
12510
12494
  const operations = Object.keys(when);
@@ -12531,7 +12515,7 @@ class TriggerManagerImpl {
12531
12515
  const internalSource = sourceDefinition.internalName;
12532
12516
  const triggerIds = [];
12533
12517
  const id = await this.getUUID();
12534
- const releaseStorageClaim = useStorage && !manageDestinationExternally ? await this.options.claimManager.obtainClaim(id) : null;
12518
+ const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
12535
12519
  /**
12536
12520
  * We default to replicating all columns if no columns array is provided.
12537
12521
  */
@@ -12563,29 +12547,25 @@ class TriggerManagerImpl {
12563
12547
  disposeWarningListener();
12564
12548
  return this.db.writeLock(async (tx) => {
12565
12549
  await this.removeTriggers(tx, triggerIds);
12566
- if (!manageDestinationExternally) {
12567
- await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
12568
- }
12550
+ await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
12569
12551
  await releaseStorageClaim?.();
12570
12552
  });
12571
12553
  };
12572
12554
  const setup = async (tx) => {
12573
12555
  // Allow user code to execute in this lock context before the trigger is created.
12574
12556
  await hooks?.beforeCreate?.(tx);
12575
- if (!manageDestinationExternally) {
12576
- await tx.execute(/* sql */ `
12577
- CREATE ${tableTriggerTypeClause} TABLE ${destination} (
12578
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
12579
- id TEXT,
12580
- operation TEXT,
12581
- timestamp TEXT,
12582
- value TEXT,
12583
- previous_value TEXT
12584
- )
12585
- `);
12586
- }
12557
+ await tx.execute(/* sql */ `
12558
+ CREATE ${tableTriggerTypeClause} TABLE ${destination} (
12559
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
12560
+ id TEXT,
12561
+ operation TEXT,
12562
+ timestamp TEXT,
12563
+ value TEXT,
12564
+ previous_value TEXT
12565
+ )
12566
+ `);
12587
12567
  if (operations.includes(DiffTriggerOperation.INSERT)) {
12588
- const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
12568
+ const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
12589
12569
  triggerIds.push(insertTriggerId);
12590
12570
  await tx.execute(/* sql */ `
12591
12571
  CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
@@ -12603,7 +12583,7 @@ class TriggerManagerImpl {
12603
12583
  `);
12604
12584
  }
12605
12585
  if (operations.includes(DiffTriggerOperation.UPDATE)) {
12606
- const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
12586
+ const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
12607
12587
  triggerIds.push(updateTriggerId);
12608
12588
  await tx.execute(/* sql */ `
12609
12589
  CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
@@ -12623,7 +12603,7 @@ class TriggerManagerImpl {
12623
12603
  `);
12624
12604
  }
12625
12605
  if (operations.includes(DiffTriggerOperation.DELETE)) {
12626
- const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
12606
+ const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
12627
12607
  triggerIds.push(deleteTriggerId);
12628
12608
  // Create delete trigger for basic JSON
12629
12609
  await tx.execute(/* sql */ `