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

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.
@@ -9966,7 +9966,7 @@ class TriggerManagerImpl {
9966
9966
  }
9967
9967
  async createDiffTrigger(options) {
9968
9968
  await this.db.waitForReady();
9969
- const { source, destination, columns, when, hooks,
9969
+ const { source, destination, columns, when, hooks, setupContext,
9970
9970
  // Fall back to the provided default if not given on this level
9971
9971
  useStorage = this.defaultConfig.useStorageByDefault } = options;
9972
9972
  const operations = Object.keys(when);
@@ -10021,13 +10021,20 @@ class TriggerManagerImpl {
10021
10021
  * we need to ensure we can cleanup the created resources.
10022
10022
  * We unfortunately cannot rely on transaction rollback.
10023
10023
  */
10024
- const cleanup = async () => {
10024
+ const cleanup = async (options) => {
10025
+ const { context } = options ?? {};
10025
10026
  disposeWarningListener();
10026
- return this.db.writeLock(async (tx) => {
10027
+ const doCleanup = async (tx) => {
10027
10028
  await this.removeTriggers(tx, triggerIds);
10028
- await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
10029
+ await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
10029
10030
  await releaseStorageClaim?.();
10030
- });
10031
+ };
10032
+ if (context) {
10033
+ await doCleanup(context);
10034
+ }
10035
+ else {
10036
+ await this.db.writeLock(doCleanup);
10037
+ }
10031
10038
  };
10032
10039
  const setup = async (tx) => {
10033
10040
  // Allow user code to execute in this lock context before the trigger is created.
@@ -10101,12 +10108,17 @@ class TriggerManagerImpl {
10101
10108
  }
10102
10109
  };
10103
10110
  try {
10104
- await this.db.writeLock(setup);
10111
+ if (setupContext) {
10112
+ await setup(setupContext);
10113
+ }
10114
+ else {
10115
+ await this.db.writeLock(setup);
10116
+ }
10105
10117
  return cleanup;
10106
10118
  }
10107
10119
  catch (error) {
10108
10120
  try {
10109
- await cleanup();
10121
+ await cleanup(setupContext ? { context: setupContext } : undefined);
10110
10122
  }
10111
10123
  catch (cleanupError) {
10112
10124
  throw new AggregateError([error, cleanupError], 'Error during operation and cleanup');