Skip to content

Commit 0a50225

Browse files
committed
alter code to conform to hc 0.3 standards
1 parent beb2300 commit 0a50225

File tree

72 files changed

+179
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+179
-163
lines changed

Cargo.lock

+15-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/repository-structure.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Third-party code using the [interface struct crates](#1-interface-struct-crates-
113113

114114
**You should create your own customised zome definitions if:**
115115

116-
- You wish to combine multiple separate hREA zomes in the same DNA and isolate the storage into different `entry_def` types.
116+
- You wish to combine multiple separate hREA zomes in the same DNA and isolate the storage into different `entry_type` types.
117117
- You wish to define private variants of ValueFlows record types or customise sharding and validation rules.
118118
- You wish to add handling of bespoke organisational logic and related records that needs to be validated tightly against REA data or coordinated as a coherent unit of information.
119119

@@ -137,7 +137,7 @@ Each module exports an `EntryData` for the record information of relevance, and
137137

138138
In cases where records have standard CRUD features, `EntryData` is convertible `From<CreateRequest>` in its associated [interface struct crate](#1-interface-struct-crates-rust-interface); and implements `Updateable<UpdateRequest>` from the [`hdk_records`](#hdk_records) library. These traits are used by [library crates](#3-library-crates-system-core) to handle the underlying storage logic.
139139

140-
It is unlikely that there should be a need to create customised versions of these files. For maintenance reasons it is much better to compose additional fields and functionality onto the REA record types as *new* `entry_defs` in zome crates if adding additional fields is a requirement for your use-case.
140+
It is unlikely that there should be a need to create customised versions of these files. For maintenance reasons it is much better to compose additional fields and functionality onto the REA record types as *new* `entry_types` in zome crates if adding additional fields is a requirement for your use-case.
141141

142142
#### 6. Storage constants (database internals)
143143

lib/hdk_records/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ edition = "2018"
77
[dependencies]
88
thiserror = "1.0"
99
serde = { workspace = true }
10-
chrono = { version = "=0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
10+
chrono = { version = "0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
1111
hdk = { workspace = true }
1212
holo_hash = { workspace = true }
13+
zome_utils = { workspace = true }
1314

1415
serde_maybe_undefined = { path = "../serde_maybe_undefined" }
1516
hdk_rpc_errors = { path = "../hdk_rpc_errors" }

lib/hdk_records/src/anchored_record_helpers.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @since 2021-09-15
1111
*/
1212
use hdk::prelude::*;
13+
use zome_utils::*;
1314
use hdk_uuid_types::{
1415
DnaAddressable, DnaIdentifiable,
1516
};
@@ -63,11 +64,11 @@ fn read_entry_anchor_id(
6364
link_type: impl LinkTypeFilterExt,
6465
identity_path_address: &EntryHash,
6566
) -> RecordAPIResult<String> {
66-
get_links(
67+
get_links(link_input(
6768
identity_path_address.to_owned(),
6869
link_type,
6970
Some(LinkTag::new(crate::identifiers::RECORD_IDENTITY_ANCHOR_LINK_TAG))
70-
)?
71+
))?
7172
.first()
7273
.map(|link| {
7374
let bytes = &link.tag.to_owned().into_inner()[3..];
@@ -83,11 +84,11 @@ fn read_anchor_identity(
8384
link_type: impl LinkTypeFilterExt,
8485
anchor_path_address: &EntryHash,
8586
) -> RecordAPIResult<EntryHash> {
86-
get_links(
87+
get_links(link_input(
8788
anchor_path_address.to_owned(),
8889
link_type,
8990
Some(LinkTag::new(crate::identifiers::RECORD_IDENTITY_ANCHOR_LINK_TAG))
90-
)?
91+
))?
9192
.first()
9293
.map(|l| Ok(l.target.to_owned().into_entry_hash().unwrap()))
9394
.ok_or(SemanticIndexError::IndexNotFound((*anchor_path_address).clone()))?
@@ -130,7 +131,7 @@ pub fn read_anchored_record_entry<LT, T, R, B, A, I>(
130131
pub fn create_anchored_record<LT, I, B, A, C, R, T, E, S, F, G>(
131132
link_type: LT,
132133
indexing_zome_name_from_config: F,
133-
entry_def_id: &S,
134+
entry_type_id: &S,
134135
create_payload: C,
135136
) -> RecordAPIResult<(SignedActionHashed, A, I)>
136137
where S: AsRef<str> + std::fmt::Display,
@@ -157,7 +158,7 @@ pub fn create_anchored_record<LT, I, B, A, C, R, T, E, S, F, G>(
157158
// write base record and identity index path
158159
let (meta, entry_internal_id, entry_data) = create_record::<T, I, R,_,_,_,_,_,_>(
159160
indexing_zome_name_from_config,
160-
&entry_def_id, create_payload,
161+
&entry_type_id, create_payload,
161162
)?;
162163

163164
// link the hash identifier to a new manually assigned identifier so we can determine the anchor when reading & updating
@@ -217,11 +218,11 @@ pub fn update_anchored_record<LT, I, R, A, B, U, E>(
217218
Some(new_id) => {
218219
if new_id != final_id {
219220
// clear any old identity path, ensuring the link structure is as expected
220-
let mut addrs = get_links(
221+
let mut addrs = get_links(link_input(
221222
identity_hash.to_owned(),
222223
[link_type.to_owned()],
223224
Some(LinkTag::new(crate::identifiers::RECORD_IDENTITY_ANCHOR_LINK_TAG))
224-
)?;
225+
))?;
225226
if addrs.len() != 1 {
226227
return Err(DataIntegrityError::IndexNotFound(identity_hash.to_owned()));
227228
}
@@ -306,7 +307,9 @@ fn link_if_not_linked<LT, E>(
306307
ScopedLinkType: TryFrom<LT, Error = E>,
307308
WasmError: From<E>,
308309
{
309-
if false == get_links(origin_hash.to_owned(), link_type.to_owned(), Some(link_tag.to_owned()))?
310+
if false == get_links(link_input(
311+
origin_hash.to_owned(), link_type.to_owned(), Some(link_tag.to_owned())
312+
))?
310313
.iter().any(|l| { l.target.to_owned().into_entry_hash().unwrap() == dest_hash })
311314
{
312315
Ok(Some(create_link(

lib/hdk_records/src/entry_helpers.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub (crate) fn try_decode_entry<T>(entry: Entry) -> RecordAPIResult<T>
5353
pub fn get_entry_by_address<R>(address: &EntryHash) -> RecordAPIResult<(SignedActionHashed, R)>
5454
where SerializedBytes: TryInto<R, Error = SerializedBytesError>,
5555
{
56-
let maybe_result = get((*address).clone(), GetOptions { strategy: GetStrategy::Latest });
56+
let maybe_result = get((*address).clone(), GetOptions { strategy: GetStrategy::Network });
5757
let record = match maybe_result {
5858
Ok(Some(el)) => el,
5959
_ => return Err(DataIntegrityError::EntryNotFound),
@@ -75,7 +75,7 @@ pub fn get_entry_by_address<R>(address: &EntryHash) -> RecordAPIResult<(SignedAc
7575
pub fn get_entry_by_action<R>(address: &ActionHash) -> RecordAPIResult<(SignedActionHashed, R)>
7676
where SerializedBytes: TryInto<R, Error = SerializedBytesError>,
7777
{
78-
let maybe_result = get(address.clone(), GetOptions { strategy: GetStrategy::Latest });
78+
let maybe_result = get(address.clone(), GetOptions { strategy: GetStrategy::Network });
7979
let record = match maybe_result {
8080
Ok(Some(el)) => el,
8181
_ => return Err(DataIntegrityError::EntryNotFound),
@@ -129,7 +129,7 @@ pub fn create_entry<T, I: Clone, E>(
129129
let action_hash = hdk_create(create_input)?;
130130

131131
// retrieve written `Record` for returning signature information
132-
let maybe_result = get(action_hash, GetOptions { strategy: GetStrategy::Latest });
132+
let maybe_result = get(action_hash, GetOptions { strategy: GetStrategy::Network });
133133
let record = match maybe_result {
134134
Ok(Some(el)) => el,
135135
_ => return Err(DataIntegrityError::EntryNotFound),
@@ -172,7 +172,7 @@ pub fn update_entry<'a, I: Clone, E>(
172172
};
173173
let updated_action = hdk_update(input)?;
174174

175-
let maybe_result = get(updated_action, GetOptions { strategy: GetStrategy::Latest });
175+
let maybe_result = get(updated_action, GetOptions { strategy: GetStrategy::Network });
176176
let record = match maybe_result {
177177
Ok(Some(el)) => el,
178178
_ => return Err(DataIntegrityError::EntryNotFound),
@@ -205,7 +205,7 @@ pub fn delete_entry<T>(
205205
mod tests {
206206
use super::*;
207207

208-
#[hdk_entry_defs]
208+
#[hdk_entry_types]
209209
#[derive(Clone)]
210210
#[unit_enum(UnitTypes)]
211211
enum EntryTypes {

lib/hdk_records/src/identity_helpers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn infer_local_entry_identity<A>(
6565
///
6666
pub fn create_entry_identity<A, S, F, C>(
6767
zome_name_from_config: F,
68-
entry_def_id: S,
68+
entry_type_id: S,
6969
initial_address: &A,
7070
) -> RecordAPIResult<bool>
7171
where S: AsRef<str> + std::fmt::Display,
@@ -75,7 +75,7 @@ pub fn create_entry_identity<A, S, F, C>(
7575
SerializedBytes: TryInto<C, Error = SerializedBytesError>,
7676
{
7777
// @see hdk_semantic_indexes_zome_derive::index_zome
78-
let append_fn_name = format!("record_new_{}", entry_def_id);
78+
let append_fn_name = format!("record_new_{}", entry_type_id);
7979

8080
// :TODO: use timestamp from written Record action rather than system time at time of RPC call
8181
let now = sys_time()?.as_seconds_and_nanos();
@@ -89,5 +89,5 @@ pub fn create_entry_identity<A, S, F, C>(
8989
address: initial_address.to_owned(),
9090
timestamp: now_stamp,
9191
},
92-
).map_err(|e| { DataIntegrityError::LocalIndexNotConfigured(entry_def_id.to_string(), e.to_string()) })?)
92+
).map_err(|e| { DataIntegrityError::LocalIndexNotConfigured(entry_type_id.to_string(), e.to_string()) })?)
9393
}

lib/hdk_records/src/metadata_helpers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn read_revision_metadata_abbreviated(header: &SignedActionHashed) -> Record
5151
*/
5252
pub fn read_revision_metadata_full(header: &SignedActionHashed) -> RecordAPIResult<RecordMeta>
5353
{
54-
match get_details(get_action_hash(header), GetOptions { strategy: GetStrategy::Latest }) {
54+
match get_details(get_action_hash(header), GetOptions { strategy: GetStrategy::Network }) {
5555
Ok(Some(Details::Record(details))) => match details.validation_status {
5656
ValidationStatus::Valid => {
5757
// find previous Element first so we can reuse it to recurse backwards to original
@@ -138,15 +138,15 @@ fn get_previous_revision(signed_action: &SignedActionHashed) -> RecordAPIResult<
138138
},
139139
// this is an Update, so previous revision exists
140140
SignedHashed { hashed: HoloHashed { content: Action::Update(update), .. }, .. } => {
141-
let previous_record = get(update.original_action_address.clone(), GetOptions { strategy: GetStrategy::Latest })?;
141+
let previous_record = get(update.original_action_address.clone(), GetOptions { strategy: GetStrategy::Network })?;
142142
match previous_record {
143143
None => Ok(None),
144144
Some(el) => Ok(Some(el)),
145145
}
146146
},
147147
// this is a Delete, so previous revision is what was deleted
148148
SignedHashed { hashed: HoloHashed { content: Action::Delete(delete), .. }, .. } => {
149-
let previous_record = get(delete.deletes_address.clone(), GetOptions { strategy: GetStrategy::Latest })?;
149+
let previous_record = get(delete.deletes_address.clone(), GetOptions { strategy: GetStrategy::Network })?;
150150
match previous_record {
151151
None => Ok(None),
152152
Some(el) => Ok(Some(el)),
@@ -184,7 +184,7 @@ fn find_latest_revision(updates: &[SignedActionHashed], revisions_until: u32) ->
184184
sortlist.sort_by_key(by_action_time);
185185
let most_recent = sortlist.last().unwrap().to_owned();
186186

187-
match get_details(get_action_hash(&most_recent), GetOptions { strategy: GetStrategy::Latest }) {
187+
match get_details(get_action_hash(&most_recent), GetOptions { strategy: GetStrategy::Network }) {
188188
Ok(Some(Details::Record(details))) => match details.validation_status {
189189
ValidationStatus::Valid => match details.updates.len() {
190190
// found latest revision

lib/hdk_records/src/record_helpers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ use crate::{
4343
/// changes outlined in issue https://github.com/h-REA/hREA/issues/196
4444
///
4545
pub fn get_latest_action_hash(entry_hash: EntryHash) -> RecordAPIResult<ActionHash> {
46-
match get_details(entry_hash.clone(), GetOptions { strategy: GetStrategy::Latest })? {
46+
match get_details(entry_hash.clone(), GetOptions { strategy: GetStrategy::Network })? {
4747
Some(Details::Entry(details)) => match details.entry_dht_status {
48-
metadata::EntryDhtStatus::Live => match details.updates.len() {
48+
EntryDhtStatus::Live => match details.updates.len() {
4949
0 => {
5050
// https://docs.rs/hdk/latest/hdk/prelude/struct.EntryDetails.html#structfield.actions
5151
Ok(get_action_hash(details.actions.first().unwrap()))
@@ -140,7 +140,7 @@ pub fn read_record_entry<T, R, B>(
140140
///
141141
pub fn create_record<T, I, R: Clone, B, C, E, S, F, G>(
142142
indexing_zome_name_from_config: F,
143-
entry_def_id: S,
143+
entry_type_id: S,
144144
create_payload: C,
145145
) -> RecordAPIResult<(SignedActionHashed, B, I)>
146146
where S: AsRef<str> + std::fmt::Display,
@@ -170,7 +170,7 @@ pub fn create_record<T, I, R: Clone, B, C, E, S, F, G>(
170170
let identity = B::new(dna_info()?.hash, entry_hash.clone());
171171
create_entry_identity(
172172
indexing_zome_name_from_config,
173-
&entry_def_id, &identity,
173+
&entry_type_id, &identity,
174174
)?;
175175

176176
Ok((meta, identity, entry_data))

lib/hdk_semantic_indexes/rpc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
serde = { workspace = true }
9-
chrono = { version = "=0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
9+
chrono = { version = "0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
1010
holochain_serialized_bytes = { workspace = true }
1111
hdk_rpc_errors = { path = "../../hdk_rpc_errors" }
1212
hdk_uuid_types = { path = "../../hdk_uuid_types" }

lib/hdk_semantic_indexes/zome/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ edition = "2018"
66

77
[dependencies]
88
serde = { workspace = true }
9-
chrono = { version = "=0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
9+
chrono = { version = "0.4.22", default-features = false, features = ["clock", "std", "oldtime", "serde"] }
1010
hdk = { workspace = true }
11+
zome_utils = { workspace = true }
1112

1213
hdk_semantic_indexes_error = { path = "../error" }
1314
hdk_semantic_indexes_zome_rpc = { path = "../rpc" }

0 commit comments

Comments
 (0)