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

Get links Count #1568

Merged
merged 66 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a1e1eb5
implemented get links system
StaticallyTypedAnxiety Jul 2, 2019
35be08a
Handle get links result implemented
StaticallyTypedAnxiety Jul 2, 2019
36003f0
put handle get links count
StaticallyTypedAnxiety Jul 2, 2019
2f1e016
Implemented nucleaus
StaticallyTypedAnxiety Jul 2, 2019
bac4799
Implementing filter on get_links
StaticallyTypedAnxiety Jul 2, 2019
b16a4fc
Added query using crud
StaticallyTypedAnxiety Jul 2, 2019
4ac5a43
Fixed up some misisng code
StaticallyTypedAnxiety Jul 2, 2019
29bcc94
cargo fmt
StaticallyTypedAnxiety Jul 2, 2019
aa9bfaf
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 2, 2019
550e21e
update proc macro
StaticallyTypedAnxiety Jul 2, 2019
8dcaaa3
Merge branch 'get-links-count' of https://www.github.com/holochain/ho…
StaticallyTypedAnxiety Jul 2, 2019
2687c7a
Update lib.rs
StaticallyTypedAnxiety Jul 2, 2019
656afcb
GetLinksCount enum
StaticallyTypedAnxiety Jul 3, 2019
e24601e
Made some changes for the tag
StaticallyTypedAnxiety Jul 3, 2019
0f77919
get_links_by_tag implemented
StaticallyTypedAnxiety Jul 3, 2019
85c5d4f
Update lib.rs
StaticallyTypedAnxiety Jul 3, 2019
5380335
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 3, 2019
504364a
Fixed problem with loop
StaticallyTypedAnxiety Jul 3, 2019
cbd0ec3
Updates to timeout
StaticallyTypedAnxiety Jul 3, 2019
e34657c
added get by tag test
StaticallyTypedAnxiety Jul 3, 2019
b8765df
Merge branch 'get-links-count' of https://www.github.com/holochain/ho…
StaticallyTypedAnxiety Jul 3, 2019
a24cf72
updated spacing
StaticallyTypedAnxiety Jul 3, 2019
408107c
Update lib.rs
StaticallyTypedAnxiety Jul 3, 2019
89ebdeb
Update lib.rs
StaticallyTypedAnxiety Jul 3, 2019
169cfdd
Update CHANGELOG-UNRELEASED.md
StaticallyTypedAnxiety Jul 3, 2019
6a2f87c
updated app_spec
StaticallyTypedAnxiety Jul 3, 2019
f58c576
updated docs
StaticallyTypedAnxiety Jul 3, 2019
26913eb
removed pritnln
StaticallyTypedAnxiety Jul 4, 2019
5934479
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 4, 2019
58533f0
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 4, 2019
3e0ed46
changes to test
StaticallyTypedAnxiety Jul 4, 2019
ee969fd
fixed double period
StaticallyTypedAnxiety Jul 4, 2019
7c2bb8e
fixed app_spec_tests
StaticallyTypedAnxiety Jul 5, 2019
19be4fa
cargo fmt
StaticallyTypedAnxiety Jul 5, 2019
ee932bd
change to trigger CI
StaticallyTypedAnxiety Jul 5, 2019
25fc7ed
commti revert merge get tag
StaticallyTypedAnxiety Jul 5, 2019
ba7fbb8
revert more tag issues
StaticallyTypedAnxiety Jul 6, 2019
e91ab6c
reverted app_spec test
StaticallyTypedAnxiety Jul 6, 2019
51eb5a5
cargo fmt after revert
StaticallyTypedAnxiety Jul 6, 2019
d20bf0c
Update CHANGELOG-UNRELEASED.md
StaticallyTypedAnxiety Jul 6, 2019
861bdc5
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 6, 2019
054dd9a
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 8, 2019
e889a95
Trigger CI again
StaticallyTypedAnxiety Jul 8, 2019
3f6352b
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 9, 2019
7643133
Merge branch 'develop' into get-links-count
zippy Jul 10, 2019
6438ee8
Merge branch 'develop' into get-links-count
lucksus Jul 11, 2019
eca611a
Changed to use enums
StaticallyTypedAnxiety Jul 15, 2019
1a46d86
links refactor
StaticallyTypedAnxiety Jul 15, 2019
0f2d83b
cargo fmt
StaticallyTypedAnxiety Jul 15, 2019
168f4e2
added case in test where different tag is added
StaticallyTypedAnxiety Jul 15, 2019
18e53f7
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 15, 2019
59554e3
Update lib.rs
StaticallyTypedAnxiety Jul 15, 2019
1617097
tigger cI
StaticallyTypedAnxiety Jul 15, 2019
bc566d4
Update test.js
StaticallyTypedAnxiety Jul 15, 2019
50a8c4a
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 16, 2019
247338c
changes to zome
StaticallyTypedAnxiety Jul 17, 2019
83c339b
Merge branch 'get-links-count' of https://www.github.com/holochain/ho…
StaticallyTypedAnxiety Jul 17, 2019
6d0f1fc
changes to zome
StaticallyTypedAnxiety Jul 17, 2019
f8454ec
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 17, 2019
df3700c
fixed app_spec
StaticallyTypedAnxiety Jul 17, 2019
193441a
Merge branch 'get-links-count' of https://www.github.com/holochain/ho…
StaticallyTypedAnxiety Jul 17, 2019
97d67fa
Merge branch 'develop' into get-links-count
StaticallyTypedAnxiety Jul 17, 2019
04b6285
trigger CI
StaticallyTypedAnxiety Jul 17, 2019
9982399
Merge branch 'get-links-count' of https://www.github.com/holochain/ho…
StaticallyTypedAnxiety Jul 17, 2019
d369c77
trigger CI
StaticallyTypedAnxiety Jul 17, 2019
9645f52
trigger CI again
StaticallyTypedAnxiety Jul 17, 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
7 changes: 7 additions & 0 deletions CHANGELOG-UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `properties` to entry definitions (not to the entries themselved). These can be retrieved using the `entry_type_properties` HDK function [#1337](https://github.com/holochain/holochain-rust/pull/1337)
StaticallyTypedAnxiety marked this conversation as resolved.
Show resolved Hide resolved
- *Breaking Change* Added type field to conductor network configuration. You must add `type="n3h"` for current config files to work. [#1540](https://github.com/holochain/holochain-rust/pull/1540)
- Added `Encryption` and `Decryption` methods in the HDK [#1534](https://github.com/holochain/holochain-rust/pull/1534)
- Adds `hc hash` CLI subcommand. Can be used to compute the hash of the DNA in the current dist directory or passed a path to a DNA with the --path flag [#1562](https://github.com/holochain/holochain-rust/pull/1562)
- Adds a --dna flag to the CLI so `hc run` can run DNAs outside the standard ./dist/ directory [1561](https://github.com/holochain/holochain-rust/pull/1561)
- Added a `get_links_count` and `get_links_count_by_tag` method which allows the user to get number of links by base , target or just by the tag. [#1568](https://github.com/holochain/holochain-rust/pull/1568)

StaticallyTypedAnxiety marked this conversation as resolved.
Show resolved Hide resolved
### Changed

### Deprecated
Expand Down
133 changes: 132 additions & 1 deletion app_spec/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ scenario('show_env', async (s, t, { alice }) => {
t.equal(result.Ok.agent_id, '{"nick":"alice::app","pub_sign_key":"' + alice.app.agentId + '"}')
t.equal(result.Ok.properties, '{"test_property":"test-property-value"}')

// don't compare the public token because it changes every time we change the dna.
// don't compare the public token because it changes every time we change the dna
t.deepEqual(result.Ok.cap_request.provenance, [ alice.app.agentId, 'HFQkrDmnSOcmGQnYNtaYZWj89rlIQVFg0PpEoeFyx/Qw6Oizy5PI+tcsO8wYrllkuVPPzF5P3pvbCctKkfyGBg==' ]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this just to trigger the CI again

);

Expand Down Expand Up @@ -851,6 +851,137 @@ scenario('get_links_crud', async (s, t, { alice, bob }) => {
t.equal("deleted",bob_posts_all.Ok.links[1].status);


})

scenario('get_links_crud_count', async (s, t, { alice, bob }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to add this test into app_spec_proc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought app_spec_proc copies over this from test.js?


//commits an entry and creates two links for alice
await alice.app.callSync("simple", "create_link",
{ "base": alice.app.agentId ,"target": "Holo world" }
);

const alice_result = await alice.app.callSync("simple", "create_link",
{ "base": alice.app.agentId ,"target": "Holo world 2" }
);

//get posts for alice from alice
const alice_posts_live= await alice.app.call("simple","get_my_links_count",
{
"base" : alice.app.agentId,"status_request":"Live"
})

//get posts for alice from bob
const bob_posts_live= await bob.app.call("simple","get_my_links_count",
{
"base" : alice.app.agentId,
"status_request":"Live"
})


//make sure count equals to 2
t.equal(2,alice_posts_live.Ok.count);
t.equal(2,bob_posts_live.Ok.count);


////delete the holo world post from the links alice created
await alice.app.callSync("simple","delete_link",
{
"base" : alice.app.agentId,
"target" : "Holo world"
});

//get all bob posts
const bob_posts_deleted = await bob.app.call("simple","get_my_links_count",
{
"base" : alice.app.agentId,
"status_request" : "Deleted"
});

// get all posts with a deleted status from alice
const alice_posts_deleted = await alice.app.call("simple","get_my_links_count",
{
"base" : alice.app.agentId,
"status_request" : "Deleted"
});

//make sure it is equal to 1
t.equal(1,alice_posts_deleted.Ok.count);
t.equal(1,bob_posts_deleted.Ok.count);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.





})


scenario('get_links_crud_count_tag', async (s, t, { alice, bob }) => {

//commits an entry and creates two links for alice
await alice.app.callSync("simple", "create_link_with_tag",
{ "base": alice.app.agentId ,"target": "Holo world","tag":"tag1" }
);

const alice_result = await alice.app.callSync("simple", "create_link_with_tag",
StaticallyTypedAnxiety marked this conversation as resolved.
Show resolved Hide resolved
{ "base": bob.app.agentId ,"target": "Holo world 2","tag":"tag1" }
);

//get posts for alice from alice
const alice_posts_live= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"Live"
})

//get posts for alice from bob
const bob_posts_live= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"Live"
})

//make sure count equals to 2
t.equal(2,alice_posts_live.Ok.count);
t.equal(2,bob_posts_live.Ok.count);

//delete link
let deleted_link = await alice.app.callSync("simple","delete_link_with_tag",
{
"base" : alice.app.agentId,
"target" : "Holo world",
"tag" : "tag1"
});


//get posts for alice from alice
const alice_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"Deleted"
})

//get posts for alice from bob
const bob_posts_deleted= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"Deleted"
})

t.equal(1,alice_posts_deleted.Ok.count);
t.equal(1,bob_posts_deleted.Ok.count);


const alice_posts_all= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"All"
})

//get posts for alice from bob
const bob_posts_all= await alice.app.call("simple","get_my_links_count_by_tag",
{
"tag" : "tag1","status_request":"All"
})

t.equal(2,alice_posts_all.Ok.count);
t.equal(2,bob_posts_all.Ok.count);



})

scenario('create/get_post roundtrip', async (s, t, { alice }) => {
Expand Down
55 changes: 53 additions & 2 deletions app_spec/zomes/simple/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use hdk::holochain_json_api::{
};


use hdk::holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions};
use hdk::holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions,GetLinksResultCount};


// see https://developer.holochain.org/api/0.0.18-alpha1/hdk/ for info on using the hdk library
Expand Down Expand Up @@ -58,12 +58,24 @@ pub fn handle_create_my_link(base: Address,target : String) -> ZomeApiResult<()>
Ok(())
}

pub fn handle_create_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> {
let address = hdk::commit_entry(&simple_entry(target))?;
hdk::link_entries(&base, &HashString::from(address), "authored_simple_posts", &tag)?;
Ok(())
}

pub fn handle_delete_my_link(base: Address,target : String) -> ZomeApiResult<()> {
let address = hdk::entry_address(&simple_entry(target))?;
hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", "")?;
Ok(())
}

pub fn handle_delete_my_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> {
let address = hdk::entry_address(&simple_entry(target))?;
hdk::remove_link(&base, &HashString::from(address), "authored_simple_posts", &tag)?;
Ok(())
}


pub fn handle_get_my_links(agent : Address,status_request:Option<LinksStatusRequestKind>) ->ZomeApiResult<GetLinksResult>
{
Expand All @@ -74,6 +86,24 @@ pub fn handle_get_my_links(agent : Address,status_request:Option<LinksStatusRequ
hdk::get_links_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options)
}

pub fn handle_get_my_links_count(agent : Address,status_request:Option<LinksStatusRequestKind>) ->ZomeApiResult<GetLinksResultCount>
{
let options = GetLinksOptions{
status_request : status_request.unwrap_or(LinksStatusRequestKind::All),
..GetLinksOptions::default()
};
hdk::get_links_count_with_options(&agent, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options)
}

pub fn handle_get_my_links_by_tag_count(tag : String,status_request:Option<LinksStatusRequestKind>) ->ZomeApiResult<GetLinksResultCount>
{
let options = GetLinksOptions{
status_request : status_request.unwrap_or(LinksStatusRequestKind::All),
..GetLinksOptions::default()
};
hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options)
}

pub fn handle_test_emit_signal(message: String) -> ZomeApiResult<()> {
#[derive(Debug, Serialize, Deserialize, DefaultJson)]
struct SignalPayload {
Expand Down Expand Up @@ -140,16 +170,36 @@ define_zome! {
outputs: |result: ZomeApiResult<()>|,
handler: handle_create_my_link
}
create_link_with_tag: {
inputs: |base : Address,target:String,tag:String|,
outputs: |result: ZomeApiResult<()>|,
handler: handle_create_my_link_with_tag
}
delete_link: {
inputs: |base : Address,target:String|,
outputs: |result: ZomeApiResult<()>|,
handler: handle_delete_my_link
}
delete_link_with_tag: {
inputs: |base : Address,target:String,tag:String|,
outputs: |result: ZomeApiResult<()>|,
handler: handle_delete_my_link_with_tag
}
get_my_links: {
inputs: |base: Address,status_request:Option<LinksStatusRequestKind>|,
outputs: |result: ZomeApiResult<GetLinksResult>|,
handler: handle_get_my_links
}
get_my_links_count: {
inputs: |base: Address,status_request:Option<LinksStatusRequestKind>|,
outputs: |result: ZomeApiResult<GetLinksResultCount>|,
handler: handle_get_my_links_count
}
get_my_links_count_by_tag: {
inputs: |tag: String,status_request:Option<LinksStatusRequestKind>|,
outputs: |result: ZomeApiResult<GetLinksResultCount>|,
handler: handle_get_my_links_by_tag_count
}
encrypt :{
inputs : |payload: String|,
outputs: |result: ZomeApiResult<String>|,
Expand All @@ -168,7 +218,8 @@ define_zome! {
]

traits: {
hc_public [create_link, delete_link, get_my_links, test_emit_signal, encrypt, decrypt]
hc_public [create_link, delete_link, get_my_links, test_emit_signal,get_my_links_count,create_link_with_tag,get_my_links_count_by_tag,delete_link_with_tag,encrypt,decrypt]

}
}

37 changes: 36 additions & 1 deletion app_spec_proc_macro/zomes/simple/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use hdk::{
json::JsonString,
error::JsonError
},
holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions}
holochain_wasm_utils::api_serialization::get_links::{GetLinksResult,LinksStatusRequestKind,GetLinksOptions,GetLinksResultCount}
};


Expand Down Expand Up @@ -107,13 +107,28 @@ pub mod simple {
hdk::link_entries(&base, &address, "authored_simple_posts", "")?;
Ok(())
}

#[zome_fn("hc_public")]
pub fn create_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()>
{
let address = hdk::commit_entry(&simple_entry(target))?;
hdk::link_entries(&base, &address, "authored_simple_posts", &tag)?;
Ok(())
}
#[zome_fn("hc_public")]
pub fn delete_link(base: Address,target : String) -> ZomeApiResult<()> {
let address = hdk::entry_address(&simple_entry(target))?;
hdk::remove_link(&base, &address, "authored_simple_posts", "")?;
Ok(())
}

#[zome_fn("hc_public")]
pub fn delete_link_with_tag(base: Address,target : String,tag:String) -> ZomeApiResult<()> {
let address = hdk::entry_address(&simple_entry(target))?;
hdk::remove_link(&base, &address, "authored_simple_posts", &tag)?;
Ok(())
}

#[zome_fn("hc_public")]
pub fn get_my_links(base: Address,status_request : Option<LinksStatusRequestKind>) -> ZomeApiResult<GetLinksResult>
{
Expand All @@ -124,6 +139,26 @@ pub mod simple {
hdk::get_links_with_options(&base, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options)
}

#[zome_fn("hc_public")]
pub fn get_my_links_count(base: Address,status_request : Option<LinksStatusRequestKind>) -> ZomeApiResult<GetLinksResultCount>
{
let options = GetLinksOptions{
status_request : status_request.unwrap_or(LinksStatusRequestKind::All),
..GetLinksOptions::default()
};
hdk::get_links_count_with_options(&base, LinkMatch::Exactly("authored_simple_posts"), LinkMatch::Any,options)
}

#[zome_fn("hc_public")]
pub fn get_my_links_count_by_tag(tag : String,status_request:Option<LinksStatusRequestKind>) ->ZomeApiResult<GetLinksResultCount>
{
let options = GetLinksOptions{
status_request : status_request.unwrap_or(LinksStatusRequestKind::All),
..GetLinksOptions::default()
};
hdk::get_links_count_by_tag(LinkMatch::Exactly(&tag),options)
}

#[zome_fn("hc_public")]
pub fn test_emit_signal(message: String) -> ZomeApiResult<()> {
#[derive(Debug, Serialize, Deserialize, DefaultJson)]
Expand Down
18 changes: 18 additions & 0 deletions core/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,15 @@ pub enum Action {
/// Last string is the stringified process unique id of this `hdk::get_links` call.
GetLinks(GetLinksKey),
GetLinksTimeout(GetLinksKey),
GetLinksTimeoutByTag(GetLinksKeyByTag),
GetLinksCount((GetLinksKey, Option<CrudStatus>)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed merging Get* / RespondGet* to Query / RespondQuery. That would make this PR already smaller as we would need all that cruft including a new future etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this and just used GetLinks with an enum because one thing I was worried about was the disconnect between what happens on the from the request point of view and the sever point of view. The reason why GetLinksCount was implemented explicitly because following it down the workflow is easy in terms of "new developers" and someone who isn't just new to the system. But I just used an enum as a parameter instead because doesn't over complicate what is happening there.

RespondGet merges and RespondQuery I think is something that should come into play as a later PR imo because some of this stuff can really propagate through a lot of changes making the scope much bigger as it goes.

GetLinksCountByTag((GetLinksKeyByTag, Option<CrudStatus>)),
RespondGetLinks((QueryEntryData, Vec<(Address, CrudStatus)>, String, String)),
RespondGetLinksCount((QueryEntryData, usize, String, String)),
RespondGetLinksCountByTag((QueryEntryData, usize, String)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could have to be more comonized but having explicit enums like this tells you exactly what it is doing.

HandleGetLinksResult((Vec<(Address, CrudStatus)>, GetLinksKey)),
HandleGetLinksResultCount((usize, GetLinksKey)),
HandleGetLinksResultCountByTag((usize, GetLinksKeyByTag)),

/// Makes the network module send a direct (node-to-node) message
/// to the address given in [DirectMessageData](struct.DirectMessageData.html)
Expand Down Expand Up @@ -257,6 +264,17 @@ pub struct GetLinksKey {
pub id: String,
}

/// The unique key that represents a GetLinksCountByTag request, used to associate the eventual
/// response with this GetLinks request
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
pub struct GetLinksKeyByTag {
/// The link tag, None means get all the tags for a given type
pub tag: String,

/// A unique ID that is used to pair the eventual result to this request
pub id: String,
}

/// The unique key that represents a Get request, used to associate the eventual
/// response with this Get request
#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize)]
Expand Down
Loading