@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.mjs
CHANGED
|
@@ -9906,9 +9906,8 @@ class TriggerManagerImpl {
|
|
|
9906
9906
|
...config
|
|
9907
9907
|
};
|
|
9908
9908
|
}
|
|
9909
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
9910
|
-
|
|
9911
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
9909
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
9910
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
9912
9911
|
}
|
|
9913
9912
|
/**
|
|
9914
9913
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -9965,24 +9964,9 @@ class TriggerManagerImpl {
|
|
|
9965
9964
|
}
|
|
9966
9965
|
});
|
|
9967
9966
|
}
|
|
9968
|
-
async createDiffDestinationTable(tableName, options) {
|
|
9969
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
9970
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
9971
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
9972
|
-
await this.db.execute(/* sql */ `
|
|
9973
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
9974
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
9975
|
-
id TEXT,
|
|
9976
|
-
operation TEXT,
|
|
9977
|
-
timestamp TEXT,
|
|
9978
|
-
value TEXT,
|
|
9979
|
-
previous_value TEXT
|
|
9980
|
-
)
|
|
9981
|
-
`);
|
|
9982
|
-
}
|
|
9983
9967
|
async createDiffTrigger(options) {
|
|
9984
9968
|
await this.db.waitForReady();
|
|
9985
|
-
const { source, destination, columns, when, hooks,
|
|
9969
|
+
const { source, destination, columns, when, hooks,
|
|
9986
9970
|
// Fall back to the provided default if not given on this level
|
|
9987
9971
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
9988
9972
|
const operations = Object.keys(when);
|
|
@@ -10009,7 +9993,7 @@ class TriggerManagerImpl {
|
|
|
10009
9993
|
const internalSource = sourceDefinition.internalName;
|
|
10010
9994
|
const triggerIds = [];
|
|
10011
9995
|
const id = await this.getUUID();
|
|
10012
|
-
const releaseStorageClaim = useStorage
|
|
9996
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
10013
9997
|
/**
|
|
10014
9998
|
* We default to replicating all columns if no columns array is provided.
|
|
10015
9999
|
*/
|
|
@@ -10041,29 +10025,25 @@ class TriggerManagerImpl {
|
|
|
10041
10025
|
disposeWarningListener();
|
|
10042
10026
|
return this.db.writeLock(async (tx) => {
|
|
10043
10027
|
await this.removeTriggers(tx, triggerIds);
|
|
10044
|
-
|
|
10045
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
10046
|
-
}
|
|
10028
|
+
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
10047
10029
|
await releaseStorageClaim?.();
|
|
10048
10030
|
});
|
|
10049
10031
|
};
|
|
10050
10032
|
const setup = async (tx) => {
|
|
10051
10033
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
10052
10034
|
await hooks?.beforeCreate?.(tx);
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
`);
|
|
10064
|
-
}
|
|
10035
|
+
await tx.execute(/* sql */ `
|
|
10036
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
10037
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
10038
|
+
id TEXT,
|
|
10039
|
+
operation TEXT,
|
|
10040
|
+
timestamp TEXT,
|
|
10041
|
+
value TEXT,
|
|
10042
|
+
previous_value TEXT
|
|
10043
|
+
)
|
|
10044
|
+
`);
|
|
10065
10045
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
10066
|
-
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id
|
|
10046
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
10067
10047
|
triggerIds.push(insertTriggerId);
|
|
10068
10048
|
await tx.execute(/* sql */ `
|
|
10069
10049
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -10081,7 +10061,7 @@ class TriggerManagerImpl {
|
|
|
10081
10061
|
`);
|
|
10082
10062
|
}
|
|
10083
10063
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
10084
|
-
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id
|
|
10064
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
10085
10065
|
triggerIds.push(updateTriggerId);
|
|
10086
10066
|
await tx.execute(/* sql */ `
|
|
10087
10067
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -10101,7 +10081,7 @@ class TriggerManagerImpl {
|
|
|
10101
10081
|
`);
|
|
10102
10082
|
}
|
|
10103
10083
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
10104
|
-
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id
|
|
10084
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
10105
10085
|
triggerIds.push(deleteTriggerId);
|
|
10106
10086
|
// Create delete trigger for basic JSON
|
|
10107
10087
|
await tx.execute(/* sql */ `
|