Applies a Delete operation to mark a token as deleted. # Behavior 1. Verifies the leaf exists 2. Verifies the leaf is not already deleted 3. Updates the leaf's state to Deleted Note: The leaf entry remains in the database (tombstone). # Errors - `LeafNotFound` - The leaf doesn't exist - `InvalidLeafState` - The leaf is already deleted
(
txn: &mut T,
context: &mut ApplyContext,
leaf_id: LeafId,
)
| 222 | /// - `LeafNotFound` - The leaf doesn't exist |
| 223 | /// - `InvalidLeafState` - The leaf is already deleted |
| 224 | fn apply_delete<T: MutCrdtTxnT>( |
| 225 | txn: &mut T, |
| 226 | context: &mut ApplyContext, |
| 227 | leaf_id: LeafId, |
| 228 | ) -> ApplyResult<()> { |
| 229 | // Verify leaf exists |
| 230 | let leaf = txn |
| 231 | .get_leaf(leaf_id) |
| 232 | .map_err(|e| storage_err(e, "getting leaf"))? |
| 233 | .ok_or_else(|| ApplyError::leaf_not_found(leaf_id))?; |
| 234 | |
| 235 | // Check current state |
| 236 | if leaf.state().is_deleted() { |
| 237 | if context.options().allow_duplicate_ids() { |
| 238 | context.record_skipped(); |
| 239 | return Ok(()); |
| 240 | } |
| 241 | return Err(ApplyError::invalid_leaf_state(leaf_id, "deleted", "delete")); |
| 242 | } |
| 243 | |
| 244 | // Update state to deleted |
| 245 | txn.update_leaf_state(leaf_id, LeafState::Deleted) |
| 246 | .map_err(|e| storage_err(e, "updating leaf state"))?; |
| 247 | |
| 248 | context.record_leaf_deleted(); |
| 249 | Ok(()) |
| 250 | } |
| 251 | |
| 252 | // Replace Operation |
| 253 |
no test coverage detected