@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.node.cjs
CHANGED
|
@@ -9908,9 +9908,8 @@ class TriggerManagerImpl {
|
|
|
9908
9908
|
...config
|
|
9909
9909
|
};
|
|
9910
9910
|
}
|
|
9911
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
9912
|
-
|
|
9913
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
9911
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
9912
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
9914
9913
|
}
|
|
9915
9914
|
/**
|
|
9916
9915
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -9967,24 +9966,9 @@ class TriggerManagerImpl {
|
|
|
9967
9966
|
}
|
|
9968
9967
|
});
|
|
9969
9968
|
}
|
|
9970
|
-
async createDiffDestinationTable(tableName, options) {
|
|
9971
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
9972
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
9973
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
9974
|
-
await this.db.execute(/* sql */ `
|
|
9975
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
9976
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
9977
|
-
id TEXT,
|
|
9978
|
-
operation TEXT,
|
|
9979
|
-
timestamp TEXT,
|
|
9980
|
-
value TEXT,
|
|
9981
|
-
previous_value TEXT
|
|
9982
|
-
)
|
|
9983
|
-
`);
|
|
9984
|
-
}
|
|
9985
9969
|
async createDiffTrigger(options) {
|
|
9986
9970
|
await this.db.waitForReady();
|
|
9987
|
-
const { source, destination, columns, when, hooks,
|
|
9971
|
+
const { source, destination, columns, when, hooks, setupContext,
|
|
9988
9972
|
// Fall back to the provided default if not given on this level
|
|
9989
9973
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
9990
9974
|
const operations = Object.keys(when);
|
|
@@ -10011,7 +9995,7 @@ class TriggerManagerImpl {
|
|
|
10011
9995
|
const internalSource = sourceDefinition.internalName;
|
|
10012
9996
|
const triggerIds = [];
|
|
10013
9997
|
const id = await this.getUUID();
|
|
10014
|
-
const releaseStorageClaim = useStorage
|
|
9998
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
10015
9999
|
/**
|
|
10016
10000
|
* We default to replicating all columns if no columns array is provided.
|
|
10017
10001
|
*/
|
|
@@ -10039,33 +10023,35 @@ class TriggerManagerImpl {
|
|
|
10039
10023
|
* we need to ensure we can cleanup the created resources.
|
|
10040
10024
|
* We unfortunately cannot rely on transaction rollback.
|
|
10041
10025
|
*/
|
|
10042
|
-
const cleanup = async () => {
|
|
10026
|
+
const cleanup = async (context) => {
|
|
10043
10027
|
disposeWarningListener();
|
|
10044
|
-
|
|
10028
|
+
const doCleanup = async (tx) => {
|
|
10045
10029
|
await this.removeTriggers(tx, triggerIds);
|
|
10046
|
-
|
|
10047
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
10048
|
-
}
|
|
10030
|
+
await tx.execute(`DROP TABLE IF EXISTS ${destination};`);
|
|
10049
10031
|
await releaseStorageClaim?.();
|
|
10050
|
-
}
|
|
10032
|
+
};
|
|
10033
|
+
if (context) {
|
|
10034
|
+
await doCleanup(context);
|
|
10035
|
+
}
|
|
10036
|
+
else {
|
|
10037
|
+
await this.db.writeLock(doCleanup);
|
|
10038
|
+
}
|
|
10051
10039
|
};
|
|
10052
10040
|
const setup = async (tx) => {
|
|
10053
10041
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
10054
10042
|
await hooks?.beforeCreate?.(tx);
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
`);
|
|
10066
|
-
}
|
|
10043
|
+
await tx.execute(/* sql */ `
|
|
10044
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
10045
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10046
|
+
id TEXT,
|
|
10047
|
+
operation TEXT,
|
|
10048
|
+
timestamp TEXT,
|
|
10049
|
+
value TEXT,
|
|
10050
|
+
previous_value TEXT
|
|
10051
|
+
)
|
|
10052
|
+
`);
|
|
10067
10053
|
if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
|
|
10068
|
-
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id
|
|
10054
|
+
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
|
|
10069
10055
|
triggerIds.push(insertTriggerId);
|
|
10070
10056
|
await tx.execute(/* sql */ `
|
|
10071
10057
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -10083,7 +10069,7 @@ class TriggerManagerImpl {
|
|
|
10083
10069
|
`);
|
|
10084
10070
|
}
|
|
10085
10071
|
if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
|
|
10086
|
-
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id
|
|
10072
|
+
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
|
|
10087
10073
|
triggerIds.push(updateTriggerId);
|
|
10088
10074
|
await tx.execute(/* sql */ `
|
|
10089
10075
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -10103,7 +10089,7 @@ class TriggerManagerImpl {
|
|
|
10103
10089
|
`);
|
|
10104
10090
|
}
|
|
10105
10091
|
if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
|
|
10106
|
-
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id
|
|
10092
|
+
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
|
|
10107
10093
|
triggerIds.push(deleteTriggerId);
|
|
10108
10094
|
// Create delete trigger for basic JSON
|
|
10109
10095
|
await tx.execute(/* sql */ `
|
|
@@ -10123,7 +10109,12 @@ class TriggerManagerImpl {
|
|
|
10123
10109
|
}
|
|
10124
10110
|
};
|
|
10125
10111
|
try {
|
|
10126
|
-
|
|
10112
|
+
if (setupContext) {
|
|
10113
|
+
await setup(setupContext);
|
|
10114
|
+
}
|
|
10115
|
+
else {
|
|
10116
|
+
await this.db.writeLock(setup);
|
|
10117
|
+
}
|
|
10127
10118
|
return cleanup;
|
|
10128
10119
|
}
|
|
10129
10120
|
catch (error) {
|