@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.
package/dist/bundle.mjs CHANGED
@@ -12488,7 +12488,7 @@ class TriggerManagerImpl {
12488
12488
  }
12489
12489
  async createDiffTrigger(options) {
12490
12490
  await this.db.waitForReady();
12491
- const { source, destination, columns, when, hooks,
12491
+ const { source, destination, columns, when, hooks, setupContext,
12492
12492
  // Fall back to the provided default if not given on this level
12493
12493
  useStorage = this.defaultConfig.useStorageByDefault } = options;
12494
12494
  const operations = Object.keys(when);
@@ -12543,13 +12543,20 @@ class TriggerManagerImpl {
12543
12543
  * we need to ensure we can cleanup the created resources.
12544
12544
  * We unfortunately cannot rely on transaction rollback.
12545
12545
  */
12546
- const cleanup = async () => {
12546
+ const cleanup = async (options) => {
12547
+ const { context } = options ?? {};
12547
12548
  disposeWarningListener();
12548
- return this.db.writeLock(async (tx) => {
12549
+ const doCleanup = async (tx) => {
12549
12550
  await this.removeTriggers(tx, triggerIds);
12550
- await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
12551
+ await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
12551
12552
  await releaseStorageClaim?.();
12552
- });
12553
+ };
12554
+ if (context) {
12555
+ await doCleanup(context);
12556
+ }
12557
+ else {
12558
+ await this.db.writeLock(doCleanup);
12559
+ }
12553
12560
  };
12554
12561
  const setup = async (tx) => {
12555
12562
  // Allow user code to execute in this lock context before the trigger is created.
@@ -12623,12 +12630,17 @@ class TriggerManagerImpl {
12623
12630
  }
12624
12631
  };
12625
12632
  try {
12626
- await this.db.writeLock(setup);
12633
+ if (setupContext) {
12634
+ await setup(setupContext);
12635
+ }
12636
+ else {
12637
+ await this.db.writeLock(setup);
12638
+ }
12627
12639
  return cleanup;
12628
12640
  }
12629
12641
  catch (error) {
12630
12642
  try {
12631
- await cleanup();
12643
+ await cleanup(setupContext ? { context: setupContext } : undefined);
12632
12644
  }
12633
12645
  catch (cleanupError) {
12634
12646
  throw new AggregateError([error, cleanupError], 'Error during operation and cleanup');