Applies an Insert operation without nested leaf operations.
(
txn: &mut T,
context: &mut ApplyContext,
trunk_id: TrunkId,
branch_id: BranchId,
after: Option<BranchId>,
)
| 214 | |
| 215 | /// Applies an Insert operation without nested leaf operations. |
| 216 | fn apply_insert_only<T: MutCrdtTxnT>( |
| 217 | txn: &mut T, |
| 218 | context: &mut ApplyContext, |
| 219 | trunk_id: TrunkId, |
| 220 | branch_id: BranchId, |
| 221 | after: Option<BranchId>, |
| 222 | ) -> ApplyResult<()> { |
| 223 | // Check for duplicate ID |
| 224 | if txn |
| 225 | .has_branch(branch_id) |
| 226 | .map_err(|e| storage_err(e, "checking branch exists"))? |
| 227 | { |
| 228 | if context.options().allow_duplicate_ids() { |
| 229 | context.record_skipped(); |
| 230 | return Ok(()); |
| 231 | } |
| 232 | return Err(ApplyError::branch_already_exists(branch_id)); |
| 233 | } |
| 234 | |
| 235 | // Validate trunk exists (optional based on validation settings) |
| 236 | if context.options().validate_references() |
| 237 | && !txn |
| 238 | .has_trunk(trunk_id) |
| 239 | .map_err(|e| storage_err(e, "checking trunk exists"))? |
| 240 | { |
| 241 | return Err(ApplyError::trunk_not_found(trunk_id)); |
| 242 | } |
| 243 | |
| 244 | // Validate "after" reference if provided |
| 245 | if context.options().validate_references() { |
| 246 | if let Some(after_id) = after { |
| 247 | if !txn |
| 248 | .has_branch(after_id) |
| 249 | .map_err(|e| storage_err(e, "checking after branch"))? |
| 250 | { |
| 251 | return Err(ApplyError::branch_not_found(after_id)); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Create and store the branch |
| 257 | let branch = Branch::new(branch_id, trunk_id); |
| 258 | txn.put_branch(&branch, after) |
| 259 | .map_err(|e| storage_err(e, "inserting branch"))?; |
| 260 | |
| 261 | context.record_branch_inserted(); |
| 262 | Ok(()) |
| 263 | } |
| 264 | |
| 265 | // Delete Operation |
| 266 |
no test coverage detected