use hdk::prelude::*;
use holochain_types::inline_zome::InlineZomeSet;
use serde::de::DeserializeOwned;
#[derive(Clone, Debug, derive_more::Constructor)]
pub struct SweetZome {
cell_id: CellId,
name: ZomeName,
}
impl SweetZome {
pub fn cell_id(&self) -> &CellId {
&self.cell_id
}
pub fn name(&self) -> &ZomeName {
&self.name
}
}
#[derive(Default, Clone)]
pub struct SweetInlineZomes(pub InlineZomeSet);
impl SweetInlineZomes {
pub const INTEGRITY: &'static str = "integrity";
pub const COORDINATOR: &'static str = "coordinator";
pub fn new(entry_defs: Vec<EntryDef>, num_link_types: u8) -> Self {
Self(
InlineZomeSet::new_unique(
[(Self::INTEGRITY, entry_defs, num_link_types)],
[Self::COORDINATOR],
[(Self::COORDINATOR.into(), Self::INTEGRITY.into())],
)
.with_dependency(Self::COORDINATOR, Self::INTEGRITY),
)
}
pub fn integrity_function<F, I, O>(self, name: &str, f: F) -> Self
where
F: Fn(BoxApi, I) -> InlineZomeResult<O> + 'static + Send + Sync,
I: DeserializeOwned + std::fmt::Debug,
O: Serialize + std::fmt::Debug,
{
Self(self.0.function(Self::INTEGRITY, name, f))
}
pub fn function<F, I, O>(self, name: &str, f: F) -> Self
where
F: Fn(BoxApi, I) -> InlineZomeResult<O> + 'static + Send + Sync,
I: DeserializeOwned + std::fmt::Debug,
O: Serialize + std::fmt::Debug,
{
Self(self.0.function(Self::COORDINATOR, name, f))
}
}
impl From<SweetInlineZomes> for InlineZomeSet {
fn from(s: SweetInlineZomes) -> Self {
s.0
}
}