Resolve a full operation identity or unambiguous Base32 prefix.
(&self, selector: &str)
| 277 | impl 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( |