Skip to content
Source
Sign inSign up
TanStack/db

feat: handle delete-insert in transaction merging #1068

Closedmarbemac(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/1068/headopened

Showing 3 changed files with 121 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/fine-planets-wash.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/db': patch
+---
+​
+Add support for delete-then-insert on the same record within a transaction, enabling undo workflows by either canceling both mutations (if data matches) or converting to an update.
31 additions and 2 deletionspackages/db/src/transactions.tsModified
View file
@@ -1,5 +1,6 @@
import { createDeferred } from './deferred'
import './duplicate-instance-check'
+import { deepEquals } from './utils'
import {
MissingMutationFunctionError,
TransactionAlreadyCompletedRollbackError,
@@ -31,9 +32,10 @@
* - (update, update) → update (replace with latest, union changes)
* - (delete, delete) → delete (replace with latest)
* - (insert, insert) → insert (replace with latest)
+ * - (delete, insert) → null if restoring original, otherwise update
- * Note: (delete, update) and (delete, insert) should never occur as the collection
- * layer prevents operations on deleted items within the same transaction.
+ * Note: (delete, update) should never occur as the collection layer prevents
+ * update operations on deleted items within the same transaction.