@powersync/common 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.
- package/dist/bundle.cjs +33 -42
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +33 -42
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +33 -42
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +33 -42
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +5 -34
- package/lib/client/triggers/TriggerManager.d.ts +2 -30
- package/lib/client/triggers/TriggerManagerImpl.d.ts +3 -4
- package/lib/client/triggers/TriggerManagerImpl.js +33 -42
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +2 -34
- package/src/client/triggers/TriggerManagerImpl.ts +31 -66
package/dist/bundle.cjs
CHANGED
|
@@ -12430,9 +12430,8 @@ class TriggerManagerImpl {
|
|
|
12430
12430
|
...config
|
|
12431
12431
|
};
|
|
12432
12432
|
}
|
|
12433
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
12434
|
-
|
|
12435
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12433
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
12434
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12436
12435
|
}
|
|
12437
12436
|
/**
|
|
12438
12437
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -12489,24 +12488,9 @@ class TriggerManagerImpl {
|
|
|
12489
12488
|
}
|
|
12490
12489
|
});
|
|
12491
12490
|
}
|
|
12492
|
-
async createDiffDestinationTable(tableName, options) {
|
|
12493
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
12494
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
12495
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
12496
|
-
await this.db.execute(/* sql */ `
|
|
12497
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
12498
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12499
|
-
id TEXT,
|
|
12500
|
-
operation TEXT,
|
|
12501
|
-
timestamp TEXT,
|
|
12502
|
-
value TEXT,
|
|
12503
|
-
previous_value TEXT
|
|
12504
|
-
)
|
|
12505
|
-
`);
|
|
12506
|
-
}
|
|
12507
12491
|
async createDiffTrigger(options) {
|
|
12508
12492
|
await this.db.waitForReady();
|
|
12509
|
-
const { source, destination, columns, when, hooks,
|
|
12493
|
+
const { source, destination, columns, when, hooks, setupContext,
|
|
12510
12494
|
// Fall back to the provided default if not given on this level
|
|
12511
12495
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
12512
12496
|
const operations = Object.keys(when);
|
|
@@ -12533,7 +12517,7 @@ class TriggerManagerImpl {
|
|
|
12533
12517
|
const internalSource = sourceDefinition.internalName;
|
|
12534
12518
|
const triggerIds = [];
|
|
12535
12519
|
const id = await this.getUUID();
|
|
12536
|
-
const releaseStorageClaim = useStorage
|
|
12520
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
12537
12521
|
/**
|
|
12538
12522
|
* We default to replicating all columns if no columns array is provided.
|
|
12539
12523
|
*/
|
|
@@ -12561,33 +12545,35 @@ class TriggerManagerImpl {
|
|
|
12561
12545
|
* we need to ensure we can cleanup the created resources.
|
|
12562
12546
|
* We unfortunately cannot rely on transaction rollback.
|
|
12563
12547
|
*/
|
|
12564
|
-
const cleanup = async () => {
|
|
12548
|
+
const cleanup = async (context) => {
|
|
12565
12549
|
disposeWarningListener();
|
|
12566
|
-
|
|
12550
|
+
const doCleanup = async (tx) => {
|
|
12567
12551
|
await this.removeTriggers(tx, triggerIds);
|
|
12568
|
-
|
|
12569
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
12570
|
-
}
|
|
12552
|
+
await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
|
|
12571
12553
|
await releaseStorageClaim?.();
|
|
12572
|
-
}
|
|
12554
|
+
};
|
|
12555
|
+
if (context) {
|
|
12556
|
+
await doCleanup(context);
|
|
12557
|
+
}
|
|
12558
|
+
else {
|
|
12559
|
+
await this.db.writeLock(doCleanup);
|
|
12560
|
+
}
|
|
12573
12561
|
};
|
|
12574
12562
|
const setup = async (tx) => {
|
|
12575
12563
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
12576
12564
|
await hooks?.beforeCreate?.(tx);
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
`);
|
|
12588
|
-
}
|
|
12565
|
+
await tx.execute(/* sql */ `
|
|
12566
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
12567
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12568
|
+
id TEXT,
|
|
12569
|
+
operation TEXT,
|
|
12570
|
+
timestamp TEXT,
|
|
12571
|
+
value TEXT,
|
|
12572
|
+
previous_value TEXT
|
|
12573
|
+
)
|
|
12574
|
+
`);
|
|
12589
12575
|
if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
|
|
12590
|
-
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id
|
|
12576
|
+
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
|
|
12591
12577
|
triggerIds.push(insertTriggerId);
|
|
12592
12578
|
await tx.execute(/* sql */ `
|
|
12593
12579
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -12605,7 +12591,7 @@ class TriggerManagerImpl {
|
|
|
12605
12591
|
`);
|
|
12606
12592
|
}
|
|
12607
12593
|
if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
|
|
12608
|
-
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id
|
|
12594
|
+
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
|
|
12609
12595
|
triggerIds.push(updateTriggerId);
|
|
12610
12596
|
await tx.execute(/* sql */ `
|
|
12611
12597
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -12625,7 +12611,7 @@ class TriggerManagerImpl {
|
|
|
12625
12611
|
`);
|
|
12626
12612
|
}
|
|
12627
12613
|
if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
|
|
12628
|
-
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id
|
|
12614
|
+
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
|
|
12629
12615
|
triggerIds.push(deleteTriggerId);
|
|
12630
12616
|
// Create delete trigger for basic JSON
|
|
12631
12617
|
await tx.execute(/* sql */ `
|
|
@@ -12645,7 +12631,12 @@ class TriggerManagerImpl {
|
|
|
12645
12631
|
}
|
|
12646
12632
|
};
|
|
12647
12633
|
try {
|
|
12648
|
-
|
|
12634
|
+
if (setupContext) {
|
|
12635
|
+
await setup(setupContext);
|
|
12636
|
+
}
|
|
12637
|
+
else {
|
|
12638
|
+
await this.db.writeLock(setup);
|
|
12639
|
+
}
|
|
12649
12640
|
return cleanup;
|
|
12650
12641
|
}
|
|
12651
12642
|
catch (error) {
|