Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Add dynamic link tagging #1402

Merged
merged 54 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4119509
makes changes to back-end references. Still some to go
willemolding May 13, 2019
6582282
test passing with changes amde
willemolding May 13, 2019
e65133c
updates app specv
willemolding May 13, 2019
a106a9e
fmt
willemolding May 13, 2019
8345f49
changelog
willemolding May 13, 2019
23c5c72
adds link tag field but not used by eav or hdk
willemolding May 13, 2019
487781e
adds test that different tagged links have a different hash
willemolding May 13, 2019
eddb65d
adds test for dedup and unique tag retrieval of links
willemolding May 13, 2019
3329e86
something get links
willemolding May 14, 2019
b916b9b
changes how links are handled to include a tag
willemolding May 14, 2019
e1e9766
adds required tag field to GetLinksArgs. tests passing
willemolding May 14, 2019
4c45220
makes EAV filter for links more verbose to enable filtering on option…
willemolding May 14, 2019
294a9c7
adds dummy return value for tag on LinkResult
willemolding May 14, 2019
7973bdd
makes tag optional in GetLinkKey for wildcard requests
willemolding May 14, 2019
2f08840
returns request tag rather than no tag from get_links_workflow
willemolding May 14, 2019
99f548d
updates tests to reflect expected behaviour of returned tags
willemolding May 14, 2019
72a9d16
Merge branch 'develop' into add-dynamic-link-tag-core
willemolding May 14, 2019
fe2a23d
fmt
willemolding May 14, 2019
46fbfb7
merge
willemolding May 14, 2019
ab6d48e
Added new scenarios in app_spec which showcase using link tags for st…
jdeepee May 15, 2019
a966645
Changed hdk crate functions: link_entries and get_links to accept tag…
jdeepee May 15, 2019
7d9accf
fmt
jdeepee May 15, 2019
921db50
query result assertions now check for ok rather than incorrect hash -…
jdeepee May 15, 2019
fc87d6c
Added query_type parameter to get_posts_by_topic & fixed test.js file…
jdeepee May 15, 2019
7f8f7f3
Update hdk-rust/src/api.rs
jdeepee May 16, 2019
2dbd253
Merge branch 'develop' into add-dynamic-link-tag-core
willemolding May 19, 2019
ac763e5
merge change to using LinkAdd entry address as EAV value
willemolding May 20, 2019
ae09d40
comments out combination of tests that is flaky
willemolding May 20, 2019
77e4e32
Merge branch 'add-dynamic-link-tag-core' of https://github.com/holoch…
willemolding May 20, 2019
3bc4b24
Merge branch 'add-dynamic-link-tag-core' of https://github.com/jdeepe…
willemolding May 20, 2019
7859e9c
makes changes to hdk
willemolding May 20, 2019
cad6f12
adds new function and tests to app spec to test tagging
willemolding May 20, 2019
6771a88
fmt
willemolding May 20, 2019
298c9d9
adds test for validation based on tag. Updates docstrings in hdk
willemolding May 20, 2019
467f95b
adds network name to tests so they dont interfere
willemolding May 20, 2019
7073511
fmt
willemolding May 20, 2019
487a15d
merge with develop
willemolding May 21, 2019
3afc821
adds tests cases for retrieving exact match both app spec and rust test
willemolding May 21, 2019
69039c1
adds optional type also
willemolding May 21, 2019
40f6df8
Re-add mistakenly removed changelog items
lucksus May 21, 2019
65ae9d7
Merge branch 'develop' into add-dynamic-link-tag-core
lucksus May 21, 2019
39a828d
Merge branch 'develop' into add-dynamic-link-tag-core
May 21, 2019
7d47d7d
adds breaking change note to changelog
willemolding May 21, 2019
2502831
merge latest develop
willemolding May 21, 2019
b4baf11
fix type error in core_types/links
willemolding May 21, 2019
82d8f95
update comment describing GetLinksKey
willemolding May 21, 2019
96745b3
update first_steps now links work slightly differently
willemolding May 21, 2019
59da60e
Update hdk-rust/src/api/get_links.rs
willemolding May 21, 2019
76fa33f
update docs in api_functions
willemolding May 21, 2019
c62fcc8
merge changes made on GH
willemolding May 21, 2019
76badd7
fmt
willemolding May 21, 2019
bd232f1
fixed typo
zippy May 21, 2019
882b25c
fix weird testing thing in dht_reducers
willemolding May 21, 2019
976a65d
Merge branch 'add-dynamic-link-tag-core' of https://github.com/holoch…
willemolding May 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG-UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Option to show NPM output when pulling deps during `hc test` [PR#1401](https://github.com/holochain/holochain-rust/pull/1401)
- Adds scaffolding/skeleton for a future WASM conductor [#894](https://github.com/holochain/holochain-rust/pull/894)
- Adds PROPERTIES static to the HDK which contains a JsonString with the DNA properties object. Also adds a body to the `hdk::properties` stub which allows retrieving fields from the properties object as JsonString. [#1418](https://github.com/holochain/holochain-rust/pull/1418)

### Changed

- **Breaking Change** Renames link tags to link_type. Adds new link tag which can be any string. This is available in validation of links and links can be retrieved based on their tag+type, just tag, just type or retrieve all. `hdk::link_entries` and `hdk::get_links` now required an extra parameter. [#1402](https://github.com/holochain/holochain-rust/pull/1402).
- Option to show NPM output when pulling deps during `hc test` [PR#1401](https://github.com/holochain/holochain-rust/pull/1401)
- Adds scaffolding/skeleton for a future WASM conductor [#894](https://github.com/holochain/holochain-rust/pull/894)
- Adds PROPERTIES static to the HDK which contains a JsonString with the DNA properties object. Also adds a body to the `hdk::properties` stub which allows retrieving fields from the properties object as JsonString. [#1418](https://github.com/holochain/holochain-rust/pull/1418)
- Conductor now persists its config in the config root (e.g. `home/peter/.config/holochain/conductor` rather than `~/.holochain`) [#1386](https://github.com/holochain/holochain-rust/pull/1386)
- Default N3H mode as set when spawned by the conductor got set to "REAL". [#1282](https://github.com/holochain/holochain-rust/pull/1282)

willemolding marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
6 changes: 3 additions & 3 deletions app_spec/test/regressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ scenario.runTape('alice create & publish post -> recommend own post to self', as
agent_address: alice.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmQja9SJhYWA5B3myrtnd9bR6dNeaFj6Lr3DRjumfTPWaX")
t.equal(linked.Ok, "QmZr5F34uGZjAEwmU574VwiRtXGHQmvbUnNgA2MJz7YcTr")

const recommendedPosts = alice.call('blog', 'my_recommended_posts', {})
console.log("recommendedPosts", recommendedPosts)
Expand All @@ -94,7 +94,7 @@ scenario.runTape('alice create & publish post -> tash recommend to self', async
agent_address: tash.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmYZKfRGykurtW96zv9ra8D9cof7Ki4Df8XFSgupWP711Y")
t.equal(linked.Ok, "QmT2Z8Hdkgxkt7X4ZeEkoDt3YTQBzyJa1RNPhfkj9icsQ4")

const recommendedPosts = tash.call("blog", "my_recommended_posts", {})
console.log("recommendedPosts", recommendedPosts)
Expand All @@ -118,7 +118,7 @@ scenario.runTape('create & publish post -> recommend to other agent', async (t,
agent_address: tash.agentId
})
console.log("linked: ", linked)
t.equal(linked.Ok, "QmZg7WfQhyUMzfd68VJZg9ah6WhtpLSZQe9BHaz8pmN3Pz")
t.equal(linked.Ok, "QmUFkn3kTXuFmBvynEMQ4ox3WyvkkG4GtfvPkNqb5b7Ge7")

const recommendedPosts = tash.call('blog', 'my_recommended_posts', {})
console.log("recommendedPosts", recommendedPosts)
Expand Down
51 changes: 51 additions & 0 deletions app_spec/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,57 @@ scenario1.runTape('create_post', async (t, { alice }) => {
t.equal(result.Ok, "QmY6MfiuhHnQ1kg7RwNZJNUQhwDxTFL45AAPnpJMNPEoxk")
})

scenario1.runTape('create_tagged_post and retrieve all tags', async (t, { alice }) => {
const result1 = await alice.callSync("blog", "create_tagged_post", {
content: "Tutorial on amazing Holochain design patterns",
tag: "work"
})
t.ok(result1.Ok)

const result2 = await alice.callSync("blog", "create_tagged_post", {
content: "Fly tying, is it for you?",
tag: "fishing"
})
t.ok(result2.Ok)

const getResult = await alice.callSync("blog", "my_posts", {})
t.equal(getResult.Ok.links.length, 2)
let tags = getResult.Ok.links.map(l => l.tag)
t.ok(tags.includes("work"))
t.ok(tags.includes("fishing"))
})

scenario1.runTape('create_tagged_post and retrieve exact tag match', async (t, { alice }) => {
const result1 = await alice.callSync("blog", "create_tagged_post", {
content: "Tutorial on amazing Holochain design patterns",
tag: "work"
})
t.ok(result1.Ok)

const result2 = await alice.callSync("blog", "create_tagged_post", {
content: "Fly tying, is it for you?",
tag: "fishing"
})
t.ok(result2.Ok)

const getResult = await alice.callSync("blog", "my_posts", {tag: "fishing"})
t.equal(getResult.Ok.links.length, 1)
let tags = getResult.Ok.links.map(l => l.tag)
t.notOk(tags.includes("work"))
t.ok(tags.includes("fishing"))
})

scenario1.runTape('tagged link validation', async (t, { alice }) => {
const result1 = await alice.callSync("blog", "create_tagged_post", {
content: "Achieving a light and fluffy texture",
tag: "muffins"
})
t.ok(result1.Err) // the linking of the entry should fail because `muffins` is the banned tag

const getResult = await alice.callSync("blog", "my_posts", {})
t.equal(getResult.Ok.links.length, 0)
})

scenario2.runTape('create_post_countersigned', async (t, { alice, bob }) => {

const content = "Holo world"
Expand Down
36 changes: 22 additions & 14 deletions app_spec/zomes/blog/code/src/blog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,23 @@ pub fn handle_memo_address(content: String) -> ZomeApiResult<Address> {
pub fn handle_create_post(content: String, in_reply_to: Option<Address>) -> ZomeApiResult<Address> {
let address = hdk::commit_entry(&post_entry(content))?;

hdk::link_entries(&AGENT_ADDRESS, &address, "authored_posts")?;
hdk::link_entries(&AGENT_ADDRESS, &address, "authored_posts", "")?;

if let Some(in_reply_to_address) = in_reply_to {
// return with Err if in_reply_to_address points to missing entry
hdk::get_entry_result(&in_reply_to_address, GetEntryOptions::default())?;
hdk::link_entries(&in_reply_to_address, &address, "comments")?;
hdk::link_entries(&in_reply_to_address, &address, "comments", "")?;
}

Ok(address)
}

pub fn handle_create_tagged_post(content: String, tag: String) -> ZomeApiResult<Address> {
let address = hdk::commit_entry(&post_entry(content))?;
hdk::link_entries(&AGENT_ADDRESS, &address, "authored_posts", tag.as_ref())?;
Ok(address)
}

pub fn handle_create_post_countersigned(content: String, in_reply_to: Option<Address>,
counter_signature: Provenance) -> ZomeApiResult<Address> {

Expand All @@ -348,12 +354,12 @@ pub fn handle_create_post_countersigned(content: String, in_reply_to: Option<Add

let address = hdk::commit_entry_result(&entry, options).unwrap().address();

hdk::link_entries(&AGENT_ADDRESS, &address, "authored_posts")?;
hdk::link_entries(&AGENT_ADDRESS, &address, "authored_posts", "")?;

if let Some(in_reply_to_address) = in_reply_to {
// return with Err if in_reply_to_address points to missing entry
hdk::get_entry_result(&in_reply_to_address, GetEntryOptions::default())?;
hdk::link_entries(&in_reply_to_address, &address, "comments")?;
hdk::link_entries(&in_reply_to_address, &address, "comments", "")?;
}

Ok(address)
Expand All @@ -367,12 +373,12 @@ pub fn handle_create_post_with_agent(
) -> ZomeApiResult<Address> {
let address = hdk::commit_entry(&post_entry(content))?;

hdk::link_entries(&agent_id, &address, "authored_posts")?;
hdk::link_entries(&agent_id, &address, "authored_posts", "")?;

if let Some(in_reply_to_address) = in_reply_to {
// return with Err if in_reply_to_address points to missing entry
hdk::get_entry_result(&in_reply_to_address, GetEntryOptions::default())?;
hdk::link_entries(&in_reply_to_address, &address, "comments")?;
hdk::link_entries(&in_reply_to_address, &address, "comments", "")?;
}

Ok(address)
Expand All @@ -386,16 +392,16 @@ pub fn handle_create_memo(content: String) -> ZomeApiResult<Address> {

pub fn handle_delete_post(content: String) -> ZomeApiResult<Address> {
let address = hdk::entry_address(&post_entry(content))?;
hdk::remove_link(&AGENT_ADDRESS, &address.clone(), "authored_posts")?;
hdk::remove_link(&AGENT_ADDRESS, &address.clone(), "authored_posts", "")?;
Ok(address)
}

pub fn handle_posts_by_agent(agent: Address) -> ZomeApiResult<GetLinksResult> {
hdk::get_links(&agent, "authored_posts")
hdk::get_links(&agent, Some("authored_posts".into()), None)
}

pub fn handle_my_posts() -> ZomeApiResult<GetLinksResult> {
hdk::get_links(&AGENT_ADDRESS, "authored_posts")
pub fn handle_my_posts(tag: Option<String>) -> ZomeApiResult<GetLinksResult> {
hdk::get_links(&AGENT_ADDRESS, Some("authored_posts".into()), tag)
}

pub fn handle_my_memos() -> ZomeApiResult<Vec<Address>> {
Expand All @@ -410,7 +416,8 @@ pub fn handle_get_memo(address: Address) -> ZomeApiResult<Option<Entry>> {
pub fn handle_my_posts_immediate_timeout() -> ZomeApiResult<GetLinksResult> {
hdk::get_links_with_options(
&AGENT_ADDRESS,
"authored_posts",
Some("authored_posts".into()),
None,
GetLinksOptions {
timeout: 0.into(),
..Default::default()
Expand All @@ -421,7 +428,8 @@ pub fn handle_my_posts_immediate_timeout() -> ZomeApiResult<GetLinksResult> {
pub fn handle_my_posts_get_my_sources(agent: Address) -> ZomeApiResult<GetLinksResult> {
hdk::get_links_with_options(
&agent,
"authored_posts",
Some("authored_posts".into()),
None,
GetLinksOptions {
headers: true,
..Default::default()
Expand Down Expand Up @@ -500,11 +508,11 @@ pub fn handle_update_post(post_address: Address, new_content: String) -> ZomeApi
pub fn handle_recommend_post(post_address: Address, agent_address: Address) -> ZomeApiResult<Address> {
hdk::debug(format!("my address:\n{:?}", AGENT_ADDRESS.to_string()))?;
hdk::debug(format!("other address:\n{:?}", agent_address.to_string()))?;
hdk::link_entries(&agent_address, &post_address, "recommended_posts")
hdk::link_entries(&agent_address, &post_address, "recommended_posts", "")
}

pub fn handle_my_recommended_posts() -> ZomeApiResult<GetLinksResult> {
hdk::get_links(&AGENT_ADDRESS, "recommended_posts")
hdk::get_links(&AGENT_ADDRESS, Some("recommended_posts".into()), None)
}

pub fn handle_get_post_bridged(post_address: Address) -> ZomeApiResult<Option<Entry>> {
Expand Down
10 changes: 8 additions & 2 deletions app_spec/zomes/blog/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ define_zome! {
handler: blog::handle_create_post
}

create_tagged_post: {
inputs: |content: String, tag: String|,
outputs: |result: ZomeApiResult<Address>|,
handler: blog::handle_create_tagged_post
}

create_post_with_agent: {
inputs: |agent_id:Address, content: String, in_reply_to: Option<Address>|,
outputs: |result: ZomeApiResult<Address>|,
Expand Down Expand Up @@ -189,7 +195,7 @@ define_zome! {
}

my_posts: {
inputs: | |,
inputs: |tag: Option<String>|,
outputs: |post_hashes: ZomeApiResult<GetLinksResult>|,
handler: blog::handle_my_posts
}
Expand Down Expand Up @@ -245,6 +251,6 @@ define_zome! {
]

traits: {
hc_public [show_env, get_test_properties, check_sum, ping, get_sources, post_address, create_post, create_post_countersigned, delete_post, delete_entry_post, update_post, posts_by_agent, get_post, my_posts, memo_address, get_memo, my_memos, create_memo, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts,get_initial_post, get_history_post, get_post_with_options, get_post_with_options_latest, authored_posts_with_sources, create_post_with_agent, request_post_grant, get_grants, commit_post_claim, create_post_with_claim, get_post_bridged]
hc_public [show_env, get_test_properties, check_sum, ping, get_sources, post_address, create_post, create_tagged_post, create_post_countersigned, delete_post, delete_entry_post, update_post, posts_by_agent, get_post, my_posts, memo_address, get_memo, my_memos, create_memo, my_posts_as_committed, my_posts_immediate_timeout, recommend_post, my_recommended_posts,get_initial_post, get_history_post, get_post_with_options, get_post_with_options_latest, authored_posts_with_sources, create_post_with_agent, request_post_grant, get_grants, commit_post_claim, create_post_with_claim, get_post_bridged]
}
}
25 changes: 17 additions & 8 deletions app_spec/zomes/blog/code/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,26 @@ pub fn definition() -> ValidatingEntryType {
links: [
from!(
"%agent_id",
tag: "authored_posts",
link_type: "authored_posts",
validation_package: || {
hdk::ValidationPackageDefinition::ChainFull
},
validation: | _validation_data: hdk::LinkValidationData | {
Ok(())
validation: | validation_data: hdk::LinkValidationData | {
// test validation of links based on their tag
if let hdk::LinkValidationData::LinkAdd{link, ..} = validation_data {
if link.link.tag() == "muffins" {
Err("This is the one tag that is not allowed!".into())
} else {
Ok(())
}
} else {
Ok(())
}
}
),
from!(
"%agent_id",
tag: "recommended_posts",
link_type: "recommended_posts",
validation_package: || {
hdk::ValidationPackageDefinition::ChainFull
},
Expand Down Expand Up @@ -143,11 +152,11 @@ mod tests {
linked_from: vec![
LinkedFrom {
base_type: "%agent_id".to_string(),
tag: "authored_posts".to_string(),
link_type: "authored_posts".to_string(),
},
LinkedFrom {
base_type: "%agent_id".to_string(),
tag: "recommended_posts".to_string(),
link_type: "recommended_posts".to_string(),
},
],
links_to: Vec::new(),
Expand Down Expand Up @@ -209,11 +218,11 @@ mod tests {

let expected_link_direction = LinkDirection::From;
assert_eq!(
post_definition_link.link_type.to_owned(),
post_definition_link.direction.to_owned(),
expected_link_direction,
);

let expected_link_tag = "authored_posts";
assert_eq!(post_definition_link.tag.to_owned(), expected_link_tag,);
assert_eq!(post_definition_link.link_type.to_owned(), expected_link_tag,);
}
}
2 changes: 1 addition & 1 deletion cas_implementations/src/eav/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub mod tests {
eav_storage,
vec!["a_", "b_", "c_", "d_"]
.into_iter()
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many"))
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many", "".into()))
.collect(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion cas_implementations/src/eav/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub mod tests {
eav_storage,
vec!["a_", "b_", "c_", "d_"]
.into_iter()
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many"))
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many", "".into()))
.collect(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion cas_implementations/src/eav/pickle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub mod tests {
eav_storage,
vec!["a_", "b_", "c_", "d_"]
.into_iter()
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many"))
.map(|p| Attribute::LinkTag(p.to_string() + "one_to_many", "".into()))
.collect(),
);
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ pub enum Action {
///
GetEntryTimeout(GetEntryKey),

/// get links from entry address and tag name
/// get links from entry address and link_type name
/// Last string is the stringified process unique id of this `hdk::get_links` call.
GetLinks(GetLinksKey),
GetLinksTimeout(GetLinksKey),
RespondGetLinks((FetchMetaData, Vec<Address>)),
HandleGetLinksResult((FetchMetaResultData, String)),
HandleGetLinksResult((FetchMetaResultData, String, String)),

/// Makes the network module send a direct (node-to-node) message
/// to the address given in [DirectMessageData](struct.DirectMessageData.html)
Expand Down Expand Up @@ -237,8 +237,11 @@ pub struct GetLinksKey {
/// The address of the Link base
pub base_address: Address,

/// The link tag
pub tag: String,
/// The link type
pub link_type: Option<String>,

/// The link tag, None means get all the tags for a given type
pub tag: Option<String>,

/// A unique ID that is used to pair the eventual result to this request
pub id: String,
Expand Down
4 changes: 2 additions & 2 deletions core/src/dht/actions/add_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod tests {
nucleus::actions::tests::commit(base.clone(), &context);

let target = base.clone();
let link = Link::new(&base.address(), &target.address(), "test-tag");
let link = Link::new(&base.address(), &target.address(), "test-link", "test-tag");

let result = context.block_on(add_link(&link, &context.clone()));

Expand All @@ -87,7 +87,7 @@ mod tests {

let base = test_entry();
let target = base.clone();
let link = Link::new(&base.address(), &target.address(), "test-tag");
let link = Link::new(&base.address(), &target.address(), "test-link", "test-tag");

let result = context.block_on(add_link(&link, &context.clone()));

Expand Down
Loading