#![warn(clippy::unwrap_used)]
pub mod cache;
pub mod common;
pub mod external;
pub mod identity;
pub mod issue;
pub mod op;
pub mod patch;
pub mod store;
pub mod stream;
pub mod thread;
#[cfg(test)]
pub mod test;
#[cfg(test)]
pub use radicle_cob::stable;
pub use cache::{migrate, MigrateCallback};
pub use common::*;
pub use op::{ActorId, Op};
pub use radicle_cob::{
change, history::EntryId, object, object::collaboration::error, type_name::TypeNameParse,
CollaborativeObject, Contents, Create, Embed, Entry, Evaluate, History, Manifest, ObjectId,
Store, TypeName, Update, Updated, Version,
};
pub use radicle_cob::{create, get, list, remove, update};
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize)]
pub struct TypedId {
pub id: ObjectId,
pub type_name: TypeName,
}
impl std::fmt::Display for TypedId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}/{}", self.type_name, self.id)
}
}
#[derive(Debug, thiserror::Error)]
pub enum ParseIdentifierError {
#[error(transparent)]
TypeName(#[from] TypeNameParse),
#[error(transparent)]
ObjectId(#[from] object::ParseObjectId),
}
impl TypedId {
pub fn is_issue(&self) -> bool {
self.type_name == *issue::TYPENAME
}
pub fn is_patch(&self) -> bool {
self.type_name == *patch::TYPENAME
}
pub fn is_identity(&self) -> bool {
self.type_name == *identity::TYPENAME
}
pub fn from_namespaced(
n: &crate::git::fmt::Namespaced,
) -> Result<Option<Self>, ParseIdentifierError> {
Self::from_qualified(&n.strip_namespace_recursive())
}
pub fn from_qualified(
q: &crate::git::fmt::Qualified,
) -> Result<Option<Self>, ParseIdentifierError> {
match q.non_empty_iter() {
("refs", "cobs", type_name, mut id) => {
let Some(id) = id.next() else {
return Ok(None);
};
Ok(Some(Self {
id: id.parse()?,
type_name: type_name.parse()?,
}))
}
_ => Ok(None),
}
}
}