1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
//! Holochain Zome Types: only the types needed by Holochain application
//! developers to use in their Zome code, and nothing more.
//!
//! This crate is intentionally kept as minimal as possible, since it is
//! typically included as a dependency in Holochain Zomes, which are
//! distributed as chunks of Wasm. In contrast, the
//! [holochain_types crate](https://crates.io/crates/holochain_types)
//! contains more types which are used by Holochain itself.
#![deny(missing_docs)]
#[allow(missing_docs)]
pub mod action;
#[allow(missing_docs)]
pub mod agent_activity;
pub mod bytes;
#[allow(missing_docs)]
pub mod call;
pub mod capability;
pub mod cell;
#[allow(missing_docs)]
pub mod chain;
pub mod countersigning;
#[allow(missing_docs)]
pub mod crdt;
pub mod dna_def;
pub mod entry;
#[allow(missing_docs)]
pub mod entry_def;
pub mod genesis;
#[allow(missing_docs)]
pub mod hash;
#[allow(missing_docs)]
pub mod info;
#[allow(missing_docs)]
pub mod init;
pub mod judged;
#[allow(missing_docs)]
pub mod link;
pub mod metadata;
#[allow(missing_docs)]
pub mod migrate_agent;
#[allow(missing_docs)]
pub mod op;
pub mod prelude;
#[cfg(feature = "properties")]
pub mod properties;
pub mod query;
pub mod rate_limit;
pub mod record;
pub mod request;
/// Schedule functions to run outside a direct zome call.
pub mod schedule;
pub mod signal;
pub mod signature;
pub use kitsune_p2p_timestamp as timestamp;
pub mod trace;
#[allow(missing_docs)]
pub mod validate;
/// Tracking versions between the WASM host and guests and other interfaces.
///
/// Needed to ensure compatibility as code develops.
pub mod version;
pub mod warrant;
#[allow(missing_docs)]
pub mod x_salsa20_poly1305;
#[allow(missing_docs)]
pub mod zome;
#[allow(missing_docs)]
pub mod zome_io;
#[allow(missing_docs)]
#[cfg(feature = "fixturators")]
pub mod fixt;
#[cfg(feature = "test_utils")]
pub mod test_utils;
pub use action::Action;
pub use entry::Entry;
pub use prelude::*;
/// Re-exported dependencies
pub mod dependencies {
pub use ::holochain_integrity_types;
pub use ::subtle;
}
use holochain_wasmer_common::WasmError;
#[allow(missing_docs)]
pub trait CallbackResult: Sized {
/// if a callback result is definitive we should halt any further iterations over remaining
/// calls e.g. over sparse names or subsequent zomes
/// typically a clear failure is definitive but success and missing dependencies are not
/// in the case of success or missing deps, a subsequent callback could give us a definitive
/// answer like a fail, and we don't want to over-optimise wasm calls and miss a clear failure
fn is_definitive(&self) -> bool;
/// when a WasmError is returned from a callback (e.g. via `?` operator) it might mean either:
///
/// - There was an error that prevented the callback from coming to a CallbackResult (e.g. failing to connect to database)
/// - There was an error that should be interpreted as a CallbackResult::Fail (e.g. data failed to deserialize)
///
/// Typically this can be split as host/wasm errors are the former, and serialization/guest errors the latter.
/// This function allows each CallbackResult to explicitly map itself.
fn try_from_wasm_error(wasm_error: WasmError) -> Result<Self, WasmError>;
}
/// Helper macro for implementing ToSql, when using rusqlite as a dependency
#[macro_export]
macro_rules! impl_to_sql_via_as_ref {
($s: ty) => {
impl ::rusqlite::ToSql for $s {
fn to_sql(&self) -> ::rusqlite::Result<::rusqlite::types::ToSqlOutput<'_>> {
Ok(::rusqlite::types::ToSqlOutput::Borrowed(
self.as_ref().into(),
))
}
}
};
}
/// Helper macro for implementing ToSql, when using rusqlite as a dependency
#[macro_export]
macro_rules! impl_to_sql_via_display {
($s: ty) => {
impl ::rusqlite::ToSql for $s {
fn to_sql(&self) -> ::rusqlite::Result<::rusqlite::types::ToSqlOutput<'_>> {
Ok(::rusqlite::types::ToSqlOutput::Owned(
self.to_string().into(),
))
}
}
};
}
/// 10MB of entropy free for the taking.
/// Useful for initializing arbitrary::Unstructured data
#[cfg(any(test, feature = "test_utils"))]
pub static NOISE: once_cell::sync::Lazy<Vec<u8>> = once_cell::sync::Lazy::new(|| {
use rand::Rng;
let mut rng = rand::thread_rng();
std::iter::repeat_with(|| rng.gen())
.take(10_000_000)
.collect()
});
/// 10MB of random Unstructured data for use with `arbitrary`
#[cfg(all(any(test, feature = "test_utils"), feature = "arbitrary"))]
pub fn unstructured_noise() -> arbitrary::Unstructured<'static> {
arbitrary::Unstructured::new(&NOISE)
}