#[macro_export]
macro_rules! crud {
(
$crud_type:ident, $entry_types:ident, $entry_type:expr, $link_types:ident, $link_type:expr, $i:ident, $path:expr, $get_peers:ident, $signal_type:ident
) => {
::paste::paste! {
pub const [<$i:upper _PATH>]: &str = $path;
pub fn [<get_ $i _path>]<TY, E>(link_type: TY) -> ExternResult<TypedPath>
where
ScopedLinkType: TryFrom<TY, Error = E>,
WasmError: From<E>,
{
Path::from([<$i:upper _PATH>]).typed(link_type)
}
#[doc ="This is what is expected by a call to [update_" $path "]"]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, SerializedBytes)]
#[serde(rename_all = "camelCase")]
pub struct [<$crud_type UpdateInput>] {
pub entry: $crud_type,
pub action_hash: ::holo_hash::ActionHashB64,
}
#[cfg(not(feature = "exclude_zome_fns"))]
#[hdk_extern]
pub fn [<create_ $i>](entry: $crud_type) -> ExternResult<$crate::wire_record::WireRecord<[<$crud_type>]>> {
let do_create = $crate::modify_chain::do_create::DoCreate {};
let full_entry = $entry_type(entry.clone());
do_create.do_create::<$entry_types, $crud_type, ::hdk::prelude::WasmError, $signal_type, $link_types> (
full_entry,
entry,
Some($crate::modify_chain::do_create::TypedPathOrEntryHash::TypedPath([< get_ $i _path >]($link_type)?)),
$path.to_string(),
$link_type,
Some($get_peers()?),
None,
)
}
#[cfg(not(feature = "exclude_zome_fns"))]
#[hdk_extern]
pub fn [<fetch_ $i s>](fetch_options: $crate::retrieval::inputs::FetchOptions) -> ExternResult<Vec<$crate::wire_record::WireRecord<[<$crud_type>]>>> {
let do_fetch = $crate::modify_chain::do_fetch::DoFetch {};
let fetch_entries = $crate::retrieval::fetch_entries::FetchEntries {};
let fetch_links = $crate::retrieval::fetch_links::FetchLinks {};
let get_latest = $crate::retrieval::get_latest_for_entry::GetLatestEntry {};
let link_type_filter = LinkTypeFilter::try_from($link_type)?;
do_fetch.do_fetch::<$crud_type, ::hdk::prelude::WasmError>(
&fetch_entries,
&fetch_links,
&get_latest,
fetch_options,
GetOptions::network(),
link_type_filter,
None, [< get_ $i _path >]($link_type)?,
)
}
#[cfg(not(feature = "exclude_zome_fns"))]
#[hdk_extern]
pub fn [<update_ $i>](update: [<$crud_type UpdateInput>]) -> ExternResult<$crate::wire_record::WireRecord<[<$crud_type>]>> {
let do_update = $crate::modify_chain::do_update::DoUpdate {};
do_update.do_update::<$crud_type, ::hdk::prelude::WasmError, $signal_type, $link_types>(
update.entry,
update.action_hash,
$path.to_string(),
$link_type,
Some($get_peers()?),
None,
)
}
#[cfg(not(feature = "exclude_zome_fns"))]
#[doc="It will no longer be returned by [fetch_" $i "s]."]
#[hdk_extern]
pub fn [<delete_ $i>](address: ::holo_hash::ActionHashB64) -> ExternResult<::holo_hash::ActionHashB64> {
let do_delete = $crate::modify_chain::do_delete::DoDelete {};
do_delete.do_delete::<$crud_type, ::hdk::prelude::WasmError, $signal_type>(
address,
$path.to_string(),
Some($get_peers()?),
)
}
}
};
}
#[cfg(not(feature = "no_example"))]
pub mod example {
use crate::signals::*;
use hdk::prelude::*;
#[hdk_entry_helper]
#[derive(Clone, PartialEq)]
pub struct Example {
pub number: i32,
}
#[hdk_entry_types]
#[unit_enum(UnitEntryTypes)]
#[derive(Clone)]
pub enum EntryTypes {
#[entry_type(required_validations = 5)]
Example(Example),
}
#[hdk_link_types]
pub enum LinkTypes {
All,
}
#[derive(Debug, Serialize, Deserialize, SerializedBytes)]
#[serde(untagged)]
pub enum SignalTypes {
Example(ActionSignal<Example>),
}
impl From<ActionSignal<Example>> for SignalTypes {
fn from(value: ActionSignal<Example>) -> Self {
SignalTypes::Example(value)
}
}
pub fn recv_remote_signal(signal: ExternIO) -> ExternResult<()> {
Ok(emit_signal(&signal)?)
}
pub fn get_peers() -> ExternResult<Vec<AgentPubKey>> {
Ok(Vec::new())
}
#[cfg(not(feature = "mock"))]
crud!(
Example,
EntryTypes,
EntryTypes::Example,
LinkTypes,
LinkTypes::All,
example,
"example",
get_peers,
SignalTypes
);
}