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

Method resolve_operation_id

atomic-repository/src/repository/operation.rs:279–320  ·  view source on GitHub ↗

Resolve a full operation identity or unambiguous Base32 prefix.

(&self, selector: &str)

Source from the content-addressed store, hash-verified

277impl Repository {
278 /// Resolve a full operation identity or unambiguous Base32 prefix.
279 pub fn resolve_operation_id(&self, selector: &str) -> Result<OperationId, RepositoryError> {
280 let selector = selector.trim();
281 let normalized = selector.to_ascii_uppercase();
282 if normalized.len() < MIN_OPERATION_PREFIX_LEN {
283 return Err(RepositoryError::InvalidOperationSelector {
284 selector: selector.to_string(),
285 reason: format!(
286 "prefixes must contain at least {MIN_OPERATION_PREFIX_LEN} Base32 characters"
287 ),
288 });
289 }
290 if normalized.len() > 52
291 || !normalized
292 .bytes()
293 .all(|byte| byte.is_ascii_uppercase() || (b'2'..=b'7').contains(&byte))
294 {
295 return Err(RepositoryError::InvalidOperationSelector {
296 selector: selector.to_string(),
297 reason: "expected a Base32 operation identity or prefix".to_string(),
298 });
299 }
300
301 let txn = self.pristine.read_txn().map_err(pristine_error)?;
302 let mut matches: Vec<OperationId> = txn
303 .list_operations()
304 .map_err(pristine_error)?
305 .into_iter()
306 .map(|operation| operation.id())
307 .filter(|id| id.to_string().starts_with(&normalized))
308 .collect();
309 matches.sort_unstable();
310 match matches.as_slice() {
311 [id] => Ok(*id),
312 [] => Err(RepositoryError::OperationNotFound {
313 selector: selector.to_string(),
314 }),
315 _ => Err(RepositoryError::AmbiguousOperation {
316 prefix: selector.to_string(),
317 matches: matches.iter().map(ToString::to_string).collect(),
318 }),
319 }
320 }
321
322 /// Return full operation data, receipts, verification, and current head scopes.
323 pub fn operation_details(

Callers 1

runMethod · 0.80

Calls 11

read_txnMethod · 0.80
lenMethod · 0.45
allMethod · 0.45
bytesMethod · 0.45
containsMethod · 0.45
collectMethod · 0.45
into_iterMethod · 0.45
list_operationsMethod · 0.45
idMethod · 0.45
as_sliceMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected