@powersync/web 0.0.0-dev-20260309101613 → 0.0.0-dev-20260311081226

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.
@@ -16912,9 +16912,8 @@ class TriggerManagerImpl {
16912
16912
  ...config
16913
16913
  };
16914
16914
  }
16915
- generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
16916
- const managedTerm = managedExternally ? '_external' : '';
16917
- return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
16915
+ generateTriggerName(operation, destinationTable, triggerId) {
16916
+ return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
16918
16917
  }
16919
16918
  /**
16920
16919
  * Cleanup any SQLite triggers or tables that are no longer in use.
@@ -16971,24 +16970,9 @@ class TriggerManagerImpl {
16971
16970
  }
16972
16971
  });
16973
16972
  }
16974
- async createDiffDestinationTable(tableName, options) {
16975
- const { temporary = true, onlyIfNotExists = false } = options ?? {};
16976
- const tableTriggerTypeClause = temporary ? 'TEMP' : '';
16977
- const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
16978
- await this.db.execute(/* sql */ `
16979
- CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
16980
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
16981
- id TEXT,
16982
- operation TEXT,
16983
- timestamp TEXT,
16984
- value TEXT,
16985
- previous_value TEXT
16986
- )
16987
- `);
16988
- }
16989
16973
  async createDiffTrigger(options) {
16990
16974
  await this.db.waitForReady();
16991
- const { source, destination, columns, when, hooks, manageDestinationExternally = false,
16975
+ const { source, destination, columns, when, hooks, setupContext,
16992
16976
  // Fall back to the provided default if not given on this level
16993
16977
  useStorage = this.defaultConfig.useStorageByDefault } = options;
16994
16978
  const operations = Object.keys(when);
@@ -17015,7 +16999,7 @@ class TriggerManagerImpl {
17015
16999
  const internalSource = sourceDefinition.internalName;
17016
17000
  const triggerIds = [];
17017
17001
  const id = await this.getUUID();
17018
- const releaseStorageClaim = useStorage && !manageDestinationExternally ? await this.options.claimManager.obtainClaim(id) : null;
17002
+ const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
17019
17003
  /**
17020
17004
  * We default to replicating all columns if no columns array is provided.
17021
17005
  */
@@ -17043,33 +17027,35 @@ class TriggerManagerImpl {
17043
17027
  * we need to ensure we can cleanup the created resources.
17044
17028
  * We unfortunately cannot rely on transaction rollback.
17045
17029
  */
17046
- const cleanup = async () => {
17030
+ const cleanup = async (context) => {
17047
17031
  disposeWarningListener();
17048
- return this.db.writeLock(async (tx) => {
17032
+ const doCleanup = async (tx) => {
17049
17033
  await this.removeTriggers(tx, triggerIds);
17050
- if (!manageDestinationExternally) {
17051
- await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
17052
- }
17034
+ await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
17053
17035
  await releaseStorageClaim?.();
17054
- });
17036
+ };
17037
+ if (context) {
17038
+ await doCleanup(context);
17039
+ }
17040
+ else {
17041
+ await this.db.writeLock(doCleanup);
17042
+ }
17055
17043
  };
17056
17044
  const setup = async (tx) => {
17057
17045
  // Allow user code to execute in this lock context before the trigger is created.
17058
17046
  await hooks?.beforeCreate?.(tx);
17059
- if (!manageDestinationExternally) {
17060
- await tx.execute(/* sql */ `
17061
- CREATE ${tableTriggerTypeClause} TABLE ${destination} (
17062
- operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
17063
- id TEXT,
17064
- operation TEXT,
17065
- timestamp TEXT,
17066
- value TEXT,
17067
- previous_value TEXT
17068
- )
17069
- `);
17070
- }
17047
+ await tx.execute(/* sql */ `
17048
+ CREATE ${tableTriggerTypeClause} TABLE ${destination} (
17049
+ operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
17050
+ id TEXT,
17051
+ operation TEXT,
17052
+ timestamp TEXT,
17053
+ value TEXT,
17054
+ previous_value TEXT
17055
+ )
17056
+ `);
17071
17057
  if (operations.includes(DiffTriggerOperation.INSERT)) {
17072
- const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
17058
+ const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
17073
17059
  triggerIds.push(insertTriggerId);
17074
17060
  await tx.execute(/* sql */ `
17075
17061
  CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
@@ -17087,7 +17073,7 @@ class TriggerManagerImpl {
17087
17073
  `);
17088
17074
  }
17089
17075
  if (operations.includes(DiffTriggerOperation.UPDATE)) {
17090
- const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
17076
+ const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
17091
17077
  triggerIds.push(updateTriggerId);
17092
17078
  await tx.execute(/* sql */ `
17093
17079
  CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
@@ -17107,7 +17093,7 @@ class TriggerManagerImpl {
17107
17093
  `);
17108
17094
  }
17109
17095
  if (operations.includes(DiffTriggerOperation.DELETE)) {
17110
- const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
17096
+ const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
17111
17097
  triggerIds.push(deleteTriggerId);
17112
17098
  // Create delete trigger for basic JSON
17113
17099
  await tx.execute(/* sql */ `
@@ -17127,7 +17113,12 @@ class TriggerManagerImpl {
17127
17113
  }
17128
17114
  };
17129
17115
  try {
17130
- await this.db.writeLock(setup);
17116
+ if (setupContext) {
17117
+ await setup(setupContext);
17118
+ }
17119
+ else {
17120
+ await this.db.writeLock(setup);
17121
+ }
17131
17122
  return cleanup;
17132
17123
  }
17133
17124
  catch (error) {