@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.node.mjs
CHANGED
|
@@ -7933,7 +7933,7 @@ function requireDist () {
|
|
|
7933
7933
|
|
|
7934
7934
|
var distExports = requireDist();
|
|
7935
7935
|
|
|
7936
|
-
var version = "1.
|
|
7936
|
+
var version = "1.48.0";
|
|
7937
7937
|
var PACKAGE = {
|
|
7938
7938
|
version: version};
|
|
7939
7939
|
|
|
@@ -9906,8 +9906,9 @@ class TriggerManagerImpl {
|
|
|
9906
9906
|
...config
|
|
9907
9907
|
};
|
|
9908
9908
|
}
|
|
9909
|
-
generateTriggerName(operation, destinationTable, triggerId) {
|
|
9910
|
-
|
|
9909
|
+
generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
|
|
9910
|
+
const managedTerm = managedExternally ? '_external' : '';
|
|
9911
|
+
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
9911
9912
|
}
|
|
9912
9913
|
/**
|
|
9913
9914
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -9964,6 +9965,26 @@ class TriggerManagerImpl {
|
|
|
9964
9965
|
}
|
|
9965
9966
|
});
|
|
9966
9967
|
}
|
|
9968
|
+
/**
|
|
9969
|
+
* Creates a diff trigger destination table on the database with the given configuration.
|
|
9970
|
+
* By default this is invoked internally when creating a diff trigger, but can
|
|
9971
|
+
* be used manually if `manageDestinationExternally` is set to true.
|
|
9972
|
+
*/
|
|
9973
|
+
async createDiffDestinationTable(tableName, options) {
|
|
9974
|
+
const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
|
|
9975
|
+
const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
9976
|
+
const ctx = options?.lockContext ?? this.db.database;
|
|
9977
|
+
await ctx.execute(/* sql */ `
|
|
9978
|
+
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
|
|
9979
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
9980
|
+
id TEXT,
|
|
9981
|
+
operation TEXT,
|
|
9982
|
+
timestamp TEXT,
|
|
9983
|
+
value TEXT,
|
|
9984
|
+
previous_value TEXT
|
|
9985
|
+
)
|
|
9986
|
+
`);
|
|
9987
|
+
}
|
|
9967
9988
|
async createDiffTrigger(options) {
|
|
9968
9989
|
await this.db.waitForReady();
|
|
9969
9990
|
const { source, destination, columns, when, hooks, manageDestinationExternally = false,
|
|
@@ -10035,19 +10056,14 @@ class TriggerManagerImpl {
|
|
|
10035
10056
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
10036
10057
|
await hooks?.beforeCreate?.(tx);
|
|
10037
10058
|
if (!manageDestinationExternally) {
|
|
10038
|
-
await
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
timestamp TEXT,
|
|
10044
|
-
value TEXT,
|
|
10045
|
-
previous_value TEXT
|
|
10046
|
-
)
|
|
10047
|
-
`);
|
|
10059
|
+
await this.createDiffDestinationTable(destination, {
|
|
10060
|
+
lockContext: tx,
|
|
10061
|
+
useStorage,
|
|
10062
|
+
onlyIfNotExists: false
|
|
10063
|
+
});
|
|
10048
10064
|
}
|
|
10049
10065
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
10050
|
-
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
10066
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
|
|
10051
10067
|
triggerIds.push(insertTriggerId);
|
|
10052
10068
|
await tx.execute(/* sql */ `
|
|
10053
10069
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -10065,7 +10081,7 @@ class TriggerManagerImpl {
|
|
|
10065
10081
|
`);
|
|
10066
10082
|
}
|
|
10067
10083
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
10068
|
-
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
10084
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
|
|
10069
10085
|
triggerIds.push(updateTriggerId);
|
|
10070
10086
|
await tx.execute(/* sql */ `
|
|
10071
10087
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -10085,7 +10101,7 @@ class TriggerManagerImpl {
|
|
|
10085
10101
|
`);
|
|
10086
10102
|
}
|
|
10087
10103
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
10088
|
-
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
10104
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
|
|
10089
10105
|
triggerIds.push(deleteTriggerId);
|
|
10090
10106
|
// Create delete trigger for basic JSON
|
|
10091
10107
|
await tx.execute(/* sql */ `
|