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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crate::{
    chain_header::ChainHeader, crud_status::CrudStatus, entry::EntryWithMetaAndHeader,
    time::Iso8601,
};
use holochain_json_api::{error::JsonError, json::JsonString};
use holochain_persistence_api::{cas::content::Address, eav::Value};

//makes more sense semantically to have this as an enum instead of a boolean.
//it adds more meaning to what sorting mechanism it is
#[derive(Deserialize, Debug, Serialize, DefaultJson, Clone, PartialEq, Eq, Hash)]
pub enum SortOrder {
    Ascending,
    Descending,
}

impl Default for SortOrder {
    fn default() -> Self {
        Self::Descending
    }
}

#[derive(Deserialize, Debug, Serialize, Clone, PartialEq, Eq, Hash, DefaultJson)]
pub struct TimePagination {
    pub from_time: Iso8601,
    pub limit: usize,
}
#[derive(Deserialize, Default, Debug, Serialize, Clone, PartialEq, Eq, Hash, DefaultJson)]
pub struct SizePagination {
    pub page_number: usize,
    pub page_size: usize,
}
#[derive(Deserialize, Debug, Serialize, Clone, PartialEq, Eq, Hash, DefaultJson)]
pub enum Pagination {
    Size(SizePagination),
    Time(TimePagination),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone, Default)]
pub struct GetLinksQueryConfiguration {
    pub headers: bool,
    pub pagination: Option<Pagination>,
    pub sort_order: Option<SortOrder>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)]
pub enum GetLinksNetworkQuery {
    Count,
    Links(GetLinksQueryConfiguration),
}

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

impl GetLinkData {
    pub fn new(
        address: Address,
        crud_status: CrudStatus,
        target: Value,
        tag: String,
        headers: Option<Vec<ChainHeader>>,
    ) -> GetLinkData {
        GetLinkData {
            address,
            crud_status,
            target,
            tag,
            headers,
        }
    }
}
#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)]
pub enum GetLinksNetworkResult {
    Count(usize),
    Links(Vec<GetLinkData>),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)]
pub enum NetworkQuery {
    GetEntry,
    GetLinks(
        Option<String>,
        Option<String>,
        Option<CrudStatus>,
        GetLinksNetworkQuery,
    ),
}

#[derive(Debug, Serialize, Deserialize, PartialEq, DefaultJson, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum NetworkQueryResult {
    Entry(Option<EntryWithMetaAndHeader>),
    Links(GetLinksNetworkResult, Option<String>, Option<String>),
}