@powersync/common 0.0.0-dev-20260305124002 → 0.0.0-dev-20260306114652
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 +32 -16
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +32 -16
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +32 -16
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +32 -16
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/lib/client/triggers/TriggerManager.d.ts +6 -0
- package/lib/client/triggers/TriggerManagerImpl.d.ts +14 -1
- package/lib/client/triggers/TriggerManagerImpl.js +31 -15
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +6 -0
- package/src/client/triggers/TriggerManagerImpl.ts +63 -15
package/dist/bundle.cjs
CHANGED
|
@@ -10457,7 +10457,7 @@ function requireDist () {
|
|
|
10457
10457
|
|
|
10458
10458
|
var distExports = requireDist();
|
|
10459
10459
|
|
|
10460
|
-
var version = "1.
|
|
10460
|
+
var version = "1.48.0";
|
|
10461
10461
|
var PACKAGE = {
|
|
10462
10462
|
version: version};
|
|
10463
10463
|
|
|
@@ -12430,8 +12430,9 @@ class TriggerManagerImpl {
|
|
|
12430
12430
|
...config
|
|
12431
12431
|
};
|
|
12432
12432
|
}
|
|
12433
|
-
generateTriggerName(operation, destinationTable, triggerId) {
|
|
12434
|
-
|
|
12433
|
+
generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
|
|
12434
|
+
const managedTerm = managedExternally ? '_external' : '';
|
|
12435
|
+
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12435
12436
|
}
|
|
12436
12437
|
/**
|
|
12437
12438
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -12488,6 +12489,26 @@ class TriggerManagerImpl {
|
|
|
12488
12489
|
}
|
|
12489
12490
|
});
|
|
12490
12491
|
}
|
|
12492
|
+
/**
|
|
12493
|
+
* Creates a diff trigger destination table on the database with the given configuration.
|
|
12494
|
+
* By default this is invoked internally when creating a diff trigger, but can
|
|
12495
|
+
* be used manually if `manageDestinationExternally` is set to true.
|
|
12496
|
+
*/
|
|
12497
|
+
async createDiffDestinationTable(tableName, options) {
|
|
12498
|
+
const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
|
|
12499
|
+
const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
12500
|
+
const ctx = options?.lockContext ?? this.db.database;
|
|
12501
|
+
await ctx.execute(/* sql */ `
|
|
12502
|
+
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
|
|
12503
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12504
|
+
id TEXT,
|
|
12505
|
+
operation TEXT,
|
|
12506
|
+
timestamp TEXT,
|
|
12507
|
+
value TEXT,
|
|
12508
|
+
previous_value TEXT
|
|
12509
|
+
)
|
|
12510
|
+
`);
|
|
12511
|
+
}
|
|
12491
12512
|
async createDiffTrigger(options) {
|
|
12492
12513
|
await this.db.waitForReady();
|
|
12493
12514
|
const { source, destination, columns, when, hooks, manageDestinationExternally = false,
|
|
@@ -12559,19 +12580,14 @@ class TriggerManagerImpl {
|
|
|
12559
12580
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
12560
12581
|
await hooks?.beforeCreate?.(tx);
|
|
12561
12582
|
if (!manageDestinationExternally) {
|
|
12562
|
-
await
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
timestamp TEXT,
|
|
12568
|
-
value TEXT,
|
|
12569
|
-
previous_value TEXT
|
|
12570
|
-
)
|
|
12571
|
-
`);
|
|
12583
|
+
await this.createDiffDestinationTable(destination, {
|
|
12584
|
+
lockContext: tx,
|
|
12585
|
+
useStorage,
|
|
12586
|
+
onlyIfNotExists: false
|
|
12587
|
+
});
|
|
12572
12588
|
}
|
|
12573
12589
|
if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
|
|
12574
|
-
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
|
|
12590
|
+
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
|
|
12575
12591
|
triggerIds.push(insertTriggerId);
|
|
12576
12592
|
await tx.execute(/* sql */ `
|
|
12577
12593
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -12589,7 +12605,7 @@ class TriggerManagerImpl {
|
|
|
12589
12605
|
`);
|
|
12590
12606
|
}
|
|
12591
12607
|
if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
|
|
12592
|
-
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
|
|
12608
|
+
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
|
|
12593
12609
|
triggerIds.push(updateTriggerId);
|
|
12594
12610
|
await tx.execute(/* sql */ `
|
|
12595
12611
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -12609,7 +12625,7 @@ class TriggerManagerImpl {
|
|
|
12609
12625
|
`);
|
|
12610
12626
|
}
|
|
12611
12627
|
if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
|
|
12612
|
-
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
|
|
12628
|
+
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
|
|
12613
12629
|
triggerIds.push(deleteTriggerId);
|
|
12614
12630
|
// Create delete trigger for basic JSON
|
|
12615
12631
|
await tx.execute(/* sql */ `
|