@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.
|
@@ -15528,9 +15528,8 @@ class TriggerManagerImpl {
|
|
|
15528
15528
|
...config
|
|
15529
15529
|
};
|
|
15530
15530
|
}
|
|
15531
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
15532
|
-
|
|
15533
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
15531
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
15532
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
15534
15533
|
}
|
|
15535
15534
|
/**
|
|
15536
15535
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -15587,24 +15586,9 @@ class TriggerManagerImpl {
|
|
|
15587
15586
|
}
|
|
15588
15587
|
});
|
|
15589
15588
|
}
|
|
15590
|
-
async createDiffDestinationTable(tableName, options) {
|
|
15591
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
15592
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
15593
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
15594
|
-
await this.db.execute(/* sql */ `
|
|
15595
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
15596
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15597
|
-
id TEXT,
|
|
15598
|
-
operation TEXT,
|
|
15599
|
-
timestamp TEXT,
|
|
15600
|
-
value TEXT,
|
|
15601
|
-
previous_value TEXT
|
|
15602
|
-
)
|
|
15603
|
-
`);
|
|
15604
|
-
}
|
|
15605
15589
|
async createDiffTrigger(options) {
|
|
15606
15590
|
await this.db.waitForReady();
|
|
15607
|
-
const { source, destination, columns, when, hooks,
|
|
15591
|
+
const { source, destination, columns, when, hooks, setupContext,
|
|
15608
15592
|
// Fall back to the provided default if not given on this level
|
|
15609
15593
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
15610
15594
|
const operations = Object.keys(when);
|
|
@@ -15631,7 +15615,7 @@ class TriggerManagerImpl {
|
|
|
15631
15615
|
const internalSource = sourceDefinition.internalName;
|
|
15632
15616
|
const triggerIds = [];
|
|
15633
15617
|
const id = await this.getUUID();
|
|
15634
|
-
const releaseStorageClaim = useStorage
|
|
15618
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
15635
15619
|
/**
|
|
15636
15620
|
* We default to replicating all columns if no columns array is provided.
|
|
15637
15621
|
*/
|
|
@@ -15659,33 +15643,35 @@ class TriggerManagerImpl {
|
|
|
15659
15643
|
* we need to ensure we can cleanup the created resources.
|
|
15660
15644
|
* We unfortunately cannot rely on transaction rollback.
|
|
15661
15645
|
*/
|
|
15662
|
-
const cleanup = async () => {
|
|
15646
|
+
const cleanup = async (context) => {
|
|
15663
15647
|
disposeWarningListener();
|
|
15664
|
-
|
|
15648
|
+
const doCleanup = async (tx) => {
|
|
15665
15649
|
await this.removeTriggers(tx, triggerIds);
|
|
15666
|
-
|
|
15667
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
15668
|
-
}
|
|
15650
|
+
await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
|
|
15669
15651
|
await releaseStorageClaim?.();
|
|
15670
|
-
}
|
|
15652
|
+
};
|
|
15653
|
+
if (context) {
|
|
15654
|
+
await doCleanup(context);
|
|
15655
|
+
}
|
|
15656
|
+
else {
|
|
15657
|
+
await this.db.writeLock(doCleanup);
|
|
15658
|
+
}
|
|
15671
15659
|
};
|
|
15672
15660
|
const setup = async (tx) => {
|
|
15673
15661
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
15674
15662
|
await hooks?.beforeCreate?.(tx);
|
|
15675
|
-
|
|
15676
|
-
|
|
15677
|
-
|
|
15678
|
-
|
|
15679
|
-
|
|
15680
|
-
|
|
15681
|
-
|
|
15682
|
-
|
|
15683
|
-
|
|
15684
|
-
|
|
15685
|
-
`);
|
|
15686
|
-
}
|
|
15663
|
+
await tx.execute(/* sql */ `
|
|
15664
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
15665
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
15666
|
+
id TEXT,
|
|
15667
|
+
operation TEXT,
|
|
15668
|
+
timestamp TEXT,
|
|
15669
|
+
value TEXT,
|
|
15670
|
+
previous_value TEXT
|
|
15671
|
+
)
|
|
15672
|
+
`);
|
|
15687
15673
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
15688
|
-
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id
|
|
15674
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
15689
15675
|
triggerIds.push(insertTriggerId);
|
|
15690
15676
|
await tx.execute(/* sql */ `
|
|
15691
15677
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -15703,7 +15689,7 @@ class TriggerManagerImpl {
|
|
|
15703
15689
|
`);
|
|
15704
15690
|
}
|
|
15705
15691
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
15706
|
-
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id
|
|
15692
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
15707
15693
|
triggerIds.push(updateTriggerId);
|
|
15708
15694
|
await tx.execute(/* sql */ `
|
|
15709
15695
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -15723,7 +15709,7 @@ class TriggerManagerImpl {
|
|
|
15723
15709
|
`);
|
|
15724
15710
|
}
|
|
15725
15711
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
15726
|
-
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id
|
|
15712
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
15727
15713
|
triggerIds.push(deleteTriggerId);
|
|
15728
15714
|
// Create delete trigger for basic JSON
|
|
15729
15715
|
await tx.execute(/* sql */ `
|
|
@@ -15743,7 +15729,12 @@ class TriggerManagerImpl {
|
|
|
15743
15729
|
}
|
|
15744
15730
|
};
|
|
15745
15731
|
try {
|
|
15746
|
-
|
|
15732
|
+
if (setupContext) {
|
|
15733
|
+
await setup(setupContext);
|
|
15734
|
+
}
|
|
15735
|
+
else {
|
|
15736
|
+
await this.db.writeLock(setup);
|
|
15737
|
+
}
|
|
15747
15738
|
return cleanup;
|
|
15748
15739
|
}
|
|
15749
15740
|
catch (error) {
|