@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.cjs
CHANGED
|
@@ -12430,9 +12430,8 @@ class TriggerManagerImpl {
|
|
|
12430
12430
|
...config
|
|
12431
12431
|
};
|
|
12432
12432
|
}
|
|
12433
|
-
generateTriggerName(operation, destinationTable, triggerId
|
|
12434
|
-
|
|
12435
|
-
return `__ps${managedTerm}_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12433
|
+
generateTriggerName(operation, destinationTable, triggerId) {
|
|
12434
|
+
return `__ps_temp_trigger_${operation.toLowerCase()}__${destinationTable}__${triggerId}`;
|
|
12436
12435
|
}
|
|
12437
12436
|
/**
|
|
12438
12437
|
* Cleanup any SQLite triggers or tables that are no longer in use.
|
|
@@ -12489,24 +12488,9 @@ class TriggerManagerImpl {
|
|
|
12489
12488
|
}
|
|
12490
12489
|
});
|
|
12491
12490
|
}
|
|
12492
|
-
async createDiffDestinationTable(tableName, options) {
|
|
12493
|
-
const { temporary = true, onlyIfNotExists = false } = options ?? {};
|
|
12494
|
-
const tableTriggerTypeClause = temporary ? 'TEMP' : '';
|
|
12495
|
-
const onlyIfNotExistsClause = onlyIfNotExists ? 'IF NOT EXISTS' : '';
|
|
12496
|
-
await this.db.execute(/* sql */ `
|
|
12497
|
-
CREATE ${tableTriggerTypeClause} TABLE ${onlyIfNotExistsClause} ${tableName} (
|
|
12498
|
-
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12499
|
-
id TEXT,
|
|
12500
|
-
operation TEXT,
|
|
12501
|
-
timestamp TEXT,
|
|
12502
|
-
value TEXT,
|
|
12503
|
-
previous_value TEXT
|
|
12504
|
-
)
|
|
12505
|
-
`);
|
|
12506
|
-
}
|
|
12507
12491
|
async createDiffTrigger(options) {
|
|
12508
12492
|
await this.db.waitForReady();
|
|
12509
|
-
const { source, destination, columns, when, hooks,
|
|
12493
|
+
const { source, destination, columns, when, hooks,
|
|
12510
12494
|
// Fall back to the provided default if not given on this level
|
|
12511
12495
|
useStorage = this.defaultConfig.useStorageByDefault } = options;
|
|
12512
12496
|
const operations = Object.keys(when);
|
|
@@ -12533,7 +12517,7 @@ class TriggerManagerImpl {
|
|
|
12533
12517
|
const internalSource = sourceDefinition.internalName;
|
|
12534
12518
|
const triggerIds = [];
|
|
12535
12519
|
const id = await this.getUUID();
|
|
12536
|
-
const releaseStorageClaim = useStorage
|
|
12520
|
+
const releaseStorageClaim = useStorage ? await this.options.claimManager.obtainClaim(id) : null;
|
|
12537
12521
|
/**
|
|
12538
12522
|
* We default to replicating all columns if no columns array is provided.
|
|
12539
12523
|
*/
|
|
@@ -12565,29 +12549,25 @@ class TriggerManagerImpl {
|
|
|
12565
12549
|
disposeWarningListener();
|
|
12566
12550
|
return this.db.writeLock(async (tx) => {
|
|
12567
12551
|
await this.removeTriggers(tx, triggerIds);
|
|
12568
|
-
|
|
12569
|
-
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
12570
|
-
}
|
|
12552
|
+
await tx.execute(/* sql */ `DROP TABLE IF EXISTS ${destination};`);
|
|
12571
12553
|
await releaseStorageClaim?.();
|
|
12572
12554
|
});
|
|
12573
12555
|
};
|
|
12574
12556
|
const setup = async (tx) => {
|
|
12575
12557
|
// Allow user code to execute in this lock context before the trigger is created.
|
|
12576
12558
|
await hooks?.beforeCreate?.(tx);
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
`);
|
|
12588
|
-
}
|
|
12559
|
+
await tx.execute(/* sql */ `
|
|
12560
|
+
CREATE ${tableTriggerTypeClause} TABLE ${destination} (
|
|
12561
|
+
operation_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
12562
|
+
id TEXT,
|
|
12563
|
+
operation TEXT,
|
|
12564
|
+
timestamp TEXT,
|
|
12565
|
+
value TEXT,
|
|
12566
|
+
previous_value TEXT
|
|
12567
|
+
)
|
|
12568
|
+
`);
|
|
12589
12569
|
if (operations.includes(exports.DiffTriggerOperation.INSERT)) {
|
|
12590
|
-
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id
|
|
12570
|
+
const insertTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.INSERT, destination, id);
|
|
12591
12571
|
triggerIds.push(insertTriggerId);
|
|
12592
12572
|
await tx.execute(/* sql */ `
|
|
12593
12573
|
CREATE ${tableTriggerTypeClause} TRIGGER ${insertTriggerId} AFTER INSERT ON ${internalSource} ${whenClauses[exports.DiffTriggerOperation.INSERT]} BEGIN
|
|
@@ -12605,7 +12585,7 @@ class TriggerManagerImpl {
|
|
|
12605
12585
|
`);
|
|
12606
12586
|
}
|
|
12607
12587
|
if (operations.includes(exports.DiffTriggerOperation.UPDATE)) {
|
|
12608
|
-
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id
|
|
12588
|
+
const updateTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.UPDATE, destination, id);
|
|
12609
12589
|
triggerIds.push(updateTriggerId);
|
|
12610
12590
|
await tx.execute(/* sql */ `
|
|
12611
12591
|
CREATE ${tableTriggerTypeClause} TRIGGER ${updateTriggerId} AFTER
|
|
@@ -12625,7 +12605,7 @@ class TriggerManagerImpl {
|
|
|
12625
12605
|
`);
|
|
12626
12606
|
}
|
|
12627
12607
|
if (operations.includes(exports.DiffTriggerOperation.DELETE)) {
|
|
12628
|
-
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id
|
|
12608
|
+
const deleteTriggerId = this.generateTriggerName(exports.DiffTriggerOperation.DELETE, destination, id);
|
|
12629
12609
|
triggerIds.push(deleteTriggerId);
|
|
12630
12610
|
// Create delete trigger for basic JSON
|
|
12631
12611
|
await tx.execute(/* sql */ `
|