use uuid::Uuid;
use crate::error::{RuntimeError, RuntimeResult};
use crate::runtime::{KhiveRuntime, NamespaceToken};
impl KhiveRuntime {
pub async fn resolve_uuid_or_prefix(
&self,
token: &NamespaceToken,
s: &str,
) -> RuntimeResult<Uuid> {
if let Ok(uuid) = s.parse::<Uuid>() {
return Ok(uuid);
}
if s.len() >= 8 && s.chars().all(|c| c.is_ascii_hexdigit()) {
return match self.resolve_prefix(token, s).await? {
Some(uuid) => Ok(uuid),
None => Err(RuntimeError::InvalidInput(format!(
"no record matches prefix: {s:?}"
))),
};
}
Err(RuntimeError::InvalidInput(format!(
"invalid UUID (expected full UUID or 8+ hex prefix): {s:?}"
)))
}
}