@powersync/common 0.0.0-dev-20260305092446 → 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 +37 -19
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +37 -19
- package/dist/bundle.mjs.map +1 -1
- package/dist/bundle.node.cjs +37 -19
- package/dist/bundle.node.cjs.map +1 -1
- package/dist/bundle.node.mjs +37 -19
- package/dist/bundle.node.mjs.map +1 -1
- package/dist/index.d.cts +25 -5
- package/lib/client/triggers/TriggerManager.d.ts +10 -3
- package/lib/client/triggers/TriggerManagerImpl.d.ts +15 -2
- package/lib/client/triggers/TriggerManagerImpl.js +36 -18
- package/lib/client/triggers/TriggerManagerImpl.js.map +1 -1
- package/package.json +1 -1
- package/src/client/triggers/TriggerManager.ts +10 -3
- package/src/client/triggers/TriggerManagerImpl.ts +68 -18
package/dist/bundle.mjs
CHANGED
|
@@ -10455,7 +10455,7 @@ function requireDist () {
|
|
|
10455
10455
|
|
|
10456
10456
|
var distExports = requireDist();
|
|
10457
10457
|
|
|
10458
|
-
var version = "1.
|
|
10458
|
+
var version = "1.48.0";
|
|
10459
10459
|
var PACKAGE = {
|
|
10460
10460
|
version: version};
|
|
10461
10461
|
|
|
@@ -12428,8 +12428,9 @@ class TriggerManagerImpl {
|
|
|
12428
12428
|
...config
|
|
12429
12429
|
};
|
|
12430
12430
|
}
|
|
12431
|
-
generateTriggerName(operation, destinationTable, triggerId) {
|
|
12432
|
-
|
|
12431
|
+
generateTriggerName(operation, destinationTable, triggerId, managedExternally = false) {
|
|
12432
|
+
const managedTerm = managedExternally ? '_external' : '';
|
|
12433
|
+
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12433
12434
|
}
|
|
12434
12435
|
/**
|
|
12435
12436
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -12486,9 +12487,29 @@ class TriggerManagerImpl {
|
|
|
12486
12487
|
}
|
|
12487
12488
|
});
|
|
12488
12489
|
}
|
|
12490
|
+
/**
|
|
12491
|
+
* Creates a diff trigger destination table on the database with the given configuration.
|
|
12492
|
+
* By default this is invoked internally when creating a diff trigger, but can
|
|
12493
|
+
* be used manually if `manageDestinationExternally` is set to true.
|
|
12494
|
+
*/
|
|
12495
|
+
async createDiffDestinationTable(tableName, options) {
|
|
12496
|
+
const tableTriggerTypeClause = !options?.useStorage ? 'TEMP' : '';
|
|
12497
|
+
const onlyIfNotExists = options?.onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
12498
|
+
const ctx = options?.lockContext ?? this.db.database;
|
|
12499
|
+
await ctx.execute(/* sql */ `
|
|
12500
|
+
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExists} ${tableName} (
|
|
12501
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12502
|
+
id TEXT,
|
|
12503
|
+
operation TEXT,
|
|
12504
|
+
timestamp TEXT,
|
|
12505
|
+
value TEXT,
|
|
12506
|
+
previous_value TEXT
|
|
12507
|
+
)
|
|
12508
|
+
`);
|
|
12509
|
+
}
|
|
12489
12510
|
async createDiffTrigger(options) {
|
|
12490
12511
|
await this.db.waitForReady();
|
|
12491
|
-
const { source, destination, columns, when, hooks,
|
|
12512
|
+
const { source, destination, columns, when, hooks, manageDestinationExternally = false,
|
|
12492
12513
|
// Fall back to the provided default if not given on this level
|
|
12493
12514
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
12494
12515
|
const operations = Object.keys(when);
|
|
@@ -12543,11 +12564,11 @@ class TriggerManagerImpl {
|
|
|
12543
12564
|
* we need to ensure we can cleanup the created resources.
|
|
12544
12565
|
* We unfortunately cannot rely on transaction rollback.
|
|
12545
12566
|
*/
|
|
12546
|
-
const cleanup = async (
|
|
12567
|
+
const cleanup = async () => {
|
|
12547
12568
|
disposeWarningListener();
|
|
12548
12569
|
return this.db.writeLock(async (tx) => {
|
|
12549
12570
|
await this.removeTriggers(tx, triggerIds);
|
|
12550
|
-
if (!
|
|
12571
|
+
if (!manageDestinationExternally) {
|
|
12551
12572
|
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
12552
12573
|
}
|
|
12553
12574
|
await releaseStorageClaim?.();
|
|
@@ -12556,18 +12577,15 @@ class TriggerManagerImpl {
|
|
|
12556
12577
|
const setup = async (tx) => {
|
|
12557
12578
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
12558
12579
|
await hooks?.beforeCreate?.(tx);
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
previous_value TEXT
|
|
12567
|
-
)
|
|
12568
|
-
`);
|
|
12580
|
+
if (!manageDestinationExternally) {
|
|
12581
|
+
await this.createDiffDestinationTable(destination, {
|
|
12582
|
+
lockContext: tx,
|
|
12583
|
+
useStorage,
|
|
12584
|
+
onlyIfNotExists: false
|
|
12585
|
+
});
|
|
12586
|
+
}
|
|
12569
12587
|
if (operations.includes(DiffTriggerOperation.INSERT)) {
|
|
12570
|
-
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id);
|
|
12588
|
+
const insertTriggerId = this.generateTriggerName(DiffTriggerOperation.INSERT, destination, id, manageDestinationExternally);
|
|
12571
12589
|
triggerIds.push(insertTriggerId);
|
|
12572
12590
|
await tx.execute(/* sql */ `
|
|
12573
12591
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -12585,7 +12603,7 @@ class TriggerManagerImpl {
|
|
|
12585
12603
|
`);
|
|
12586
12604
|
}
|
|
12587
12605
|
if (operations.includes(DiffTriggerOperation.UPDATE)) {
|
|
12588
|
-
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id);
|
|
12606
|
+
const updateTriggerId = this.generateTriggerName(DiffTriggerOperation.UPDATE, destination, id, manageDestinationExternally);
|
|
12589
12607
|
triggerIds.push(updateTriggerId);
|
|
12590
12608
|
await tx.execute(/* sql */ `
|
|
12591
12609
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -12605,7 +12623,7 @@ class TriggerManagerImpl {
|
|
|
12605
12623
|
`);
|
|
12606
12624
|
}
|
|
12607
12625
|
if (operations.includes(DiffTriggerOperation.DELETE)) {
|
|
12608
|
-
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id);
|
|
12626
|
+
const deleteTriggerId = this.generateTriggerName(DiffTriggerOperation.DELETE, destination, id, manageDestinationExternally);
|
|
12609
12627
|
triggerIds.push(deleteTriggerId);
|
|
12610
12628
|
// Create delete trigger for basic JSON
|
|
12611
12629
|
await tx.execute(/* sql */ `
|