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