@powersync/common 0.0.0-dev-20260309101613 → 0.0.0-dev-20260311080613
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 +18 -38
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +18 -38
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +18 -38
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +18 -38
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +2 -32
- package/lib/client/triggers/TriggerManager.d.ts +0 -29
- package/lib/client/triggers/TriggerManagerImpl.d.ts +2 -3
- package/lib/client/triggers/TriggerManagerImpl.js +18 -38
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +0 -33
- package/src/client/triggers/TriggerManagerImpl.ts +17 -62
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,
|
|
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
|
*/
|
|
@@ -10043,29 +10027,25 @@ class TriggerManagerImpl {
|
|
|
10043
10027
|
disposeWarningListener();
|
|
10044
10028
|
return this.db.writeLock(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(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
10049
10031
|
await releaseStorageClaim?.();
|
|
10050
10032
|
});
|
|
10051
10033
|
};
|
|
10052
10034
|
const setup = async (tx) => {
|
|
10053
10035
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
10054
10036
|
await hooks?.beforeCreate?.(tx);
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
`);
|
|
10066
|
-
}
|
|
10037
|
+
await tx.execute(/* sql */ `
|
|
10038
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
10039
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10040
|
+
id TEXT,
|
|
10041
|
+
operation TEXT,
|
|
10042
|
+
timestamp TEXT,
|
|
10043
|
+
value TEXT,
|
|
10044
|
+
previous_value TEXT
|
|
10045
|
+
)
|
|
10046
|
+
`);
|
|
10067
10047
|
if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
|
|
10068
|
-
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id
|
|
10048
|
+
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
|
|
10069
10049
|
triggerIds.push(insertTriggerId);
|
|
10070
10050
|
await tx.execute(/* sql */ `
|
|
10071
10051
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -10083,7 +10063,7 @@ class TriggerManagerImpl {
|
|
|
10083
10063
|
`);
|
|
10084
10064
|
}
|
|
10085
10065
|
if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
|
|
10086
|
-
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id
|
|
10066
|
+
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
|
|
10087
10067
|
triggerIds.push(updateTriggerId);
|
|
10088
10068
|
await tx.execute(/* sql */ `
|
|
10089
10069
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -10103,7 +10083,7 @@ class TriggerManagerImpl {
|
|
|
10103
10083
|
`);
|
|
10104
10084
|
}
|
|
10105
10085
|
if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
|
|
10106
|
-
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id
|
|
10086
|
+
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
|
|
10107
10087
|
triggerIds.push(deleteTriggerId);
|
|
10108
10088
|
// Create delete trigger for basic JSON
|
|
10109
10089
|
await tx.execute(/* sql */ `
|