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
use holochain_core_types::{
    chain_header::ChainHeader,
    crud_status::CrudStatus,
    network::query::{Pagination, SortOrder},
    time::Timeout,
};
use holochain_json_api::{error::JsonError, json::*};
use holochain_persistence_api::cas::content::Address;

#[derive(Deserialize, Default, Debug, Serialize, Clone, PartialEq, Eq, Hash, DefaultJson)]
pub struct GetLinksArgs {
    pub entry_address: Address,
    pub link_type: Option<String>,
    pub tag: Option<String>,
    pub options: GetLinksOptions,
}

#[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Eq, Hash)]
pub enum LinksStatusRequestKind {
    Live,
    Deleted,
    All,
}

impl Default for LinksStatusRequestKind {
    fn default() -> Self {
        LinksStatusRequestKind::Live
    }
}

#[derive(Deserialize, Default, Debug, Serialize, DefaultJson, Clone, PartialEq, Hash, Eq)]
pub struct GetLinksOptions {
    pub status_request: LinksStatusRequestKind,
    pub headers: bool,
    pub timeout: Timeout,
    pub pagination: Option<Pagination>,
    pub sort_order: Option<SortOrder>,
}

#[derive(Deserialize, Clone, Serialize, Debug, DefaultJson, PartialEq)]
pub struct LinksResult {
    pub address: Address,
    pub headers: Vec<ChainHeader>,
    pub tag: String,
    pub status: CrudStatus,
}

#[derive(Deserialize, Clone, Serialize, Debug, DefaultJson, PartialEq)]
pub struct GetLinksResult {
    links: Vec<LinksResult>,
}

#[derive(Deserialize, Serialize, Debug, DefaultJson)]
pub struct GetLinksResultCount {
    pub count: usize,
}

impl GetLinksResult {
    pub fn new(links: Vec<LinksResult>) -> GetLinksResult {
        GetLinksResult { links }
    }

    pub fn tags(&self) -> Vec<String> {
        self.links.iter().map(|s| s.tag.clone()).collect()
    }

    pub fn links(&self) -> Vec<LinksResult> {
        self.links.clone()
    }

    pub fn addresses(&self) -> Vec<Address> {
        self.links.iter().map(|s| s.address.clone()).collect()
    }
}