Skip to content

Commit

Permalink
updating module imports, link fetching, hash types, and relevant conv…
Browse files Browse the repository at this point in the history
…ersions to 0.4.0
  • Loading branch information
weswalla committed Jun 28, 2024
1 parent 76df704 commit 88fda87
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 40 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[package]
name = "hdk_crud"
description = "A library to help quickly and easily create a consistent set of create-read-update-delete functions for an Entry type in Holochain, complete with signaling options"
version = "0.12.0"
version = "0.13.0"
license = "CAL-1.0"
repository = "https://github.com/lightningrodlabs/hdk_crud"
authors = ["Connor Turland <[email protected]>", "Wesley Finck <[email protected]"]
edition = "2021"

[dependencies]
hdk = "=0.1.4"
holo_hash = { version = "=0.1.4", features = ["encoding"] }
paste = "1.0.5"
serde = "1.0.123"
hdk = "0.4.0-dev.5"
holo_hash = { version = "0.4.0-dev.5", features = ["encoding"] }
paste = "*"
serde = "*"
thiserror = "1"
mockall = "0.9"
fixt = { version = "0.1.0", optional = true }
fixt = { version = "0.4.0-dev.2", optional = true }
mockall_double = { version = "0.2.0", optional = true }
# specific so as to avoid wasm-bindgen dependency
chrono = { version = "=0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
chrono = { version = "*", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
assert_matches = "1.5.0"
holochain_types = { version = "0.1.6", optional = true }
holochain_types = { version = "0.4.0-dev.4", optional = true }

[dev-dependencies]
rand = "0.7"
Expand Down
16 changes: 8 additions & 8 deletions src/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
/// ```ignore
/// use hdk::prelude::*;
/// use hdk_crud::*;
///
///
/// #[hdk_entry_helper]
/// #[derive(Clone, PartialEq)]
/// pub struct Example {
/// pub number: i32,
/// }
///
///
/// #[hdk_entry_defs]
/// #[unit_enum(UnitEntryTypes)]
/// #[derive(Clone)]
/// pub enum EntryTypes {
/// #[entry_def(required_validations = 5)]
/// Example(Example),
/// }
///
///
/// #[hdk_link_types]
/// pub enum LinkTypes {
/// All,
/// }
///
///
/// // TestSignal pops out of the crud! macro
/// #[derive(Debug, Serialize, Deserialize, SerializedBytes)]
/// #[serde(untagged)]
Expand Down Expand Up @@ -73,7 +73,7 @@ macro_rules! crud {

/// Retrieve the Path for these entry types
/// to which all entries are linked
pub fn [<get_ $i _path>]<TY, E>(link_type: TY) -> ExternResult<hdk::hash_path::path::TypedPath>
pub fn [<get_ $i _path>]<TY, E>(link_type: TY) -> ExternResult<TypedPath>
where
ScopedLinkType: TryFrom<TY, Error = E>,
WasmError: From<E>,
Expand Down Expand Up @@ -134,7 +134,7 @@ macro_rules! crud {
&fetch_links,
&get_latest,
fetch_options,
GetOptions::latest(),
GetOptions::network(),
link_type_filter,
None, // link_tag
[< get_ $i _path >]($link_type)?,
Expand Down Expand Up @@ -208,11 +208,11 @@ pub mod example {
pub number: i32,
}

#[hdk_entry_defs]
#[hdk_entry_types]
#[unit_enum(UnitEntryTypes)]
#[derive(Clone)]
pub enum EntryTypes {
#[entry_def(required_validations = 5)]
#[entry_type(required_validations = 5)]
Example(Example),
}

Expand Down
2 changes: 1 addition & 1 deletion src/datetime_queries/fetch_by_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod tests {
// // set up for expected get call
let path_get_input = vec![GetInput::new(
AnyDhtHash::from(path_entry_hash.clone()),
GetOptions::content(),
GetOptions::local(),
)];
let expected_get_output = vec![Some(fixt!(Record))]; // this should return the path
mock_hdk
Expand Down
15 changes: 10 additions & 5 deletions src/datetime_queries/fetch_by_hour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ impl FetchByHour {
TY: Clone,
WasmError: From<E>,
{
let path = hour_path_from_date(link_type, base_component.clone(), year, month, day, hour)?;
let links = get_links(path.path_entry_hash()?, link_type_filter, None)?;
let path = hour_path_from_date(link_type, base_component.clone(), year, month, day, hour)?;
let mut input = GetLinksInputBuilder::try_new(path.path_entry_hash()?, link_type_filter)?;
let links = get_links(input.build())?;

let entries: Vec<WireRecord<EntryType>> = links
.into_iter()
.map(|link| {
get_latest_entry
.get_latest_for_entry::<EntryType>(link.target.into(), GetOptions::latest())
get_latest_entry.get_latest_for_entry::<EntryType>(
link.target.try_into().map_err(|_| {
wasm_error!(WasmErrorInner::Guest("Target is not an entry".to_string()))
})?,
GetOptions::network(),
)
})
.filter_map(Result::ok)
.filter_map(identity)
Expand Down Expand Up @@ -119,7 +124,7 @@ mod tests {
.expect_get_latest_for_entry::<Example>()
.with(
mockall::predicate::eq(link_output.target),
mockall::predicate::eq(GetOptions::latest()),
mockall::predicate::eq(GetOptions::network()),
)
.times(1)
.return_const(Ok(get_latest_output.clone()));
Expand Down
5 changes: 1 addition & 4 deletions src/datetime_queries/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use super::inputs::FetchEntriesTime;
use chrono::{DateTime, Datelike, Duration, NaiveDate, Utc};
use hdk::{
hash_path::path::{Component, TypedPath},
prelude::*,
};
use hdk::prelude::*;

pub fn is_valid_date_range(
start: FetchEntriesTime,
Expand Down
4 changes: 2 additions & 2 deletions src/modify_chain/do_create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::wire_record::WireRecord;
use crate::{datetime_queries::utils::serialize_err, modify_chain::utils::add_current_time_path};
use hdk::{hash_path::path::TypedPath, prelude::*};
use hdk::prelude::*;
use holo_hash::{ActionHashB64, AgentPubKey, EntryHashB64};

#[cfg(feature = "mock")]
Expand Down Expand Up @@ -121,7 +121,7 @@ impl DoCreate {
};
let signal = S::from(action_signal);
let payload = ExternIO::encode(signal).map_err(serialize_err)?;
remote_signal(payload, vec_peers)?;
send_remote_signal(payload, vec_peers)?;
}
}
Ok(wire_entry)
Expand Down
2 changes: 1 addition & 1 deletion src/modify_chain/do_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl DoDelete {
};
let signal = S::from(action_signal);
let payload = ExternIO::encode(signal).map_err(serialize_err)?;
remote_signal(payload, vec_peers)?;
send_remote_signal(payload, vec_peers)?;
}
}
Ok(action_hash)
Expand Down
2 changes: 1 addition & 1 deletion src/modify_chain/do_fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::retrieval::fetch_links::MockFetchLinks as FetchLinks;
use crate::retrieval::get_latest_for_entry::MockGetLatestEntry as GetLatestEntry;

use crate::wire_record::WireRecord;
use hdk::hash_path::path::TypedPath;
use hdi::hash_path::path::TypedPath;
use hdk::prelude::*;

#[cfg(feature = "mock")]
Expand Down
2 changes: 1 addition & 1 deletion src/modify_chain/do_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl DoUpdate {
};
let signal = S::from(action_signal);
let payload = ExternIO::encode(signal).map_err(serialize_err)?;
remote_signal(payload, vec_peers)?;
send_remote_signal(payload, vec_peers)?;
}
}
Ok(wire_entry)
Expand Down
11 changes: 8 additions & 3 deletions src/retrieval/fetch_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::retrieval::get_latest_for_entry::MockGetLatestEntry as GetLatestEntry

#[cfg(feature = "mock")]
use ::mockall::automock;
use hdk::hash_path::path::TypedPath;

use crate::retrieval::inputs::FetchOptions;
use crate::wire_record::WireRecord;
Expand Down Expand Up @@ -38,15 +37,21 @@ impl FetchEntries {
match fetch_options {
FetchOptions::All => {
let path_hash = entry_path.path_entry_hash()?;
fetch_links.fetch_links::<EntryType>(get_latest, path_hash, link_type, link_tag, get_options)
fetch_links.fetch_links::<EntryType>(
get_latest,
path_hash,
link_type,
link_tag,
get_options,
)
// TODO: will have to instantiate or pass in the struct
}
FetchOptions::Specific(vec_entry_hash) => {
let entries = vec_entry_hash
.iter()
.map(|entry_hash| {
get_latest.get_latest_for_entry::<EntryType>(
entry_hash.clone().into(),
EntryHash::from(entry_hash.clone()).into(),
get_options.clone(),
)
})
Expand Down
12 changes: 9 additions & 3 deletions src/retrieval/fetch_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ impl FetchLinks {
link_tag: Option<LinkTag>,
get_options: GetOptions,
) -> Result<Vec<WireRecord<EntryType>>, WasmError> {
Ok(get_links(entry_hash, link_type, link_tag)?
let mut input = GetLinksInputBuilder::try_new(entry_hash, link_type)?;
if let Some(link_tag_inner) = link_tag {
input = input.tag_prefix(link_tag_inner);
}
Ok(get_links(input.build())?
.into_iter()
.map(|link: link::Link| {
.map(|link: Link| {
get_latest.get_latest_for_entry::<EntryType>(
link.target.clone().into(),
link.target.try_into().map_err(|_| {
wasm_error!(WasmErrorInner::Guest("Target is not an entry".to_string()))
})?,
get_options.clone(),
)
})
Expand Down
5 changes: 3 additions & 2 deletions src/retrieval/get_latest_for_entry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use hash_type::{AnyDht, AnyLinkable};
use hdk::prelude::*;

use crate::{datetime_queries::utils::serialize_err, retrieval::utils::*, wire_record::WireRecord};
Expand Down Expand Up @@ -26,7 +27,7 @@ impl GetLatestEntry {
) -> ExternResult<Option<WireRecord<T>>> {
match get_details(entry_hash.clone(), get_options.clone())? {
Some(Details::Entry(details)) => match details.entry_dht_status {
metadata::EntryDhtStatus::Live => {
EntryDhtStatus::Live => {
let first_action = details.actions.first().unwrap();
let created_at = first_action.action().timestamp();
match details.updates.len() {
Expand Down Expand Up @@ -72,7 +73,7 @@ impl GetLatestEntry {
}
}
}
metadata::EntryDhtStatus::Dead => Ok(None),
EntryDhtStatus::Dead => Ok(None),
_ => Ok(None),
},
_ => Ok(None),
Expand Down
2 changes: 1 addition & 1 deletion src/retrieval/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use hdk::prelude::*;

/// convert a SignedActionHashed which are like raw contents
/// into the ActionHash of itself
pub fn get_action_hash(signed_action_hashed: record::SignedActionHashed) -> ActionHash {
pub fn get_action_hash(signed_action_hashed: SignedActionHashed) -> ActionHash {
signed_action_hashed.as_hash().to_owned()
}

0 comments on commit 88fda87

Please sign in to comment.