MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / apply_insert_only

Function apply_insert_only

atomic-core/src/crdt/apply/branch.rs:216–263  ·  view source on GitHub ↗

Applies an Insert operation without nested leaf operations.

(
    txn: &mut T,
    context: &mut ApplyContext,
    trunk_id: TrunkId,
    branch_id: BranchId,
    after: Option<BranchId>,
)

Source from the content-addressed store, hash-verified

214
215/// Applies an Insert operation without nested leaf operations.
216fn 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

Callers 2

apply_branch_op_onlyFunction · 0.85
apply_insertFunction · 0.85

Calls 9

storage_errFunction · 0.85
allow_duplicate_idsMethod · 0.80
validate_referencesMethod · 0.80
has_branchMethod · 0.45
optionsMethod · 0.45
record_skippedMethod · 0.45
has_trunkMethod · 0.45
put_branchMethod · 0.45

Tested by

no test coverage detected