@tanstack/db 0.1.5 → 0.1.6
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/src/collection.ts
CHANGED
|
@@ -66,6 +66,7 @@ interface PendingSyncedTransaction<T extends object = Record<string, unknown>> {
|
|
|
66
66
|
committed: boolean
|
|
67
67
|
operations: Array<OptimisticChangeMessage<T>>
|
|
68
68
|
truncate?: boolean
|
|
69
|
+
deletedKeys: Set<string | number>
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
/**
|
|
@@ -542,6 +543,7 @@ export class CollectionImpl<
|
|
|
542
543
|
this.pendingSyncedTransactions.push({
|
|
543
544
|
committed: false,
|
|
544
545
|
operations: [],
|
|
546
|
+
deletedKeys: new Set(),
|
|
545
547
|
})
|
|
546
548
|
},
|
|
547
549
|
write: (messageWithoutKey: Omit<ChangeMessage<T>, `key`>) => {
|
|
@@ -560,9 +562,8 @@ export class CollectionImpl<
|
|
|
560
562
|
// Check if an item with this key already exists when inserting
|
|
561
563
|
if (messageWithoutKey.type === `insert`) {
|
|
562
564
|
const insertingIntoExistingSynced = this.syncedData.has(key)
|
|
563
|
-
const hasPendingDeleteForKey =
|
|
564
|
-
(
|
|
565
|
-
)
|
|
565
|
+
const hasPendingDeleteForKey =
|
|
566
|
+
pendingTransaction.deletedKeys.has(key)
|
|
566
567
|
const isTruncateTransaction = pendingTransaction.truncate === true
|
|
567
568
|
// Allow insert after truncate in the same transaction even if it existed in syncedData
|
|
568
569
|
if (
|
|
@@ -579,6 +580,10 @@ export class CollectionImpl<
|
|
|
579
580
|
key,
|
|
580
581
|
}
|
|
581
582
|
pendingTransaction.operations.push(message)
|
|
583
|
+
|
|
584
|
+
if (messageWithoutKey.type === `delete`) {
|
|
585
|
+
pendingTransaction.deletedKeys.add(key)
|
|
586
|
+
}
|
|
582
587
|
},
|
|
583
588
|
commit: () => {
|
|
584
589
|
const pendingTransaction =
|
|
@@ -619,6 +624,7 @@ export class CollectionImpl<
|
|
|
619
624
|
|
|
620
625
|
// Clear all operations from the current transaction
|
|
621
626
|
pendingTransaction.operations = []
|
|
627
|
+
pendingTransaction.deletedKeys.clear()
|
|
622
628
|
|
|
623
629
|
// Mark the transaction as a truncate operation. During commit, this triggers:
|
|
624
630
|
// - Delete events for all previously synced keys (excluding optimistic-deleted keys)
|