1use crate::action::ChainTopOrdering;
9use holochain_integrity_types::EntryDefIndex;
10use holochain_integrity_types::EntryType;
11use holochain_integrity_types::EntryVisibility;
12use holochain_integrity_types::ScopedEntryDefIndex;
13use holochain_integrity_types::ZomeIndex;
14use holochain_serialized_bytes::prelude::*;
15
16mod app_entry_bytes;
17pub use app_entry_bytes::*;
18
19pub use holochain_integrity_types::entry::*;
20
21#[derive(
22 Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
23)]
24pub enum EntryDefLocation {
30 App(AppEntryDefLocation),
33 CapClaim,
36 CapGrant,
39}
40
41#[derive(
42 Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
43)]
44pub struct AppEntryDefLocation {
46 pub zome_index: ZomeIndex,
48 pub entry_def_index: EntryDefIndex,
50}
51
52#[derive(PartialEq, Debug, Clone, Serialize, Deserialize)]
53pub struct GetOptions {
55 pub strategy: GetStrategy,
58}
59
60impl GetOptions {
61 pub fn network() -> Self {
67 Self {
68 strategy: GetStrategy::Network,
69 }
70 }
71 pub fn local() -> Self {
74 Self {
75 strategy: GetStrategy::Local,
76 }
77 }
78}
79
80impl Default for GetOptions {
81 fn default() -> Self {
82 Self::network()
83 }
84}
85
86#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
87pub enum GetStrategy {
90 Network,
96 Local,
99}
100
101#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes)]
103pub struct CreateInput {
104 pub entry_location: EntryDefLocation,
106 pub entry_visibility: EntryVisibility,
108 pub entry: crate::entry::Entry,
110 pub chain_top_ordering: ChainTopOrdering,
112}
113
114impl CreateInput {
115 pub fn new(
117 entry_location: impl Into<EntryDefLocation>,
118 entry_visibility: EntryVisibility,
119 entry: crate::entry::Entry,
120 chain_top_ordering: ChainTopOrdering,
121 ) -> Self {
122 Self {
123 entry_location: entry_location.into(),
124 entry_visibility,
125 entry,
126 chain_top_ordering,
127 }
128 }
129
130 pub fn into_entry(self) -> Entry {
132 self.entry
133 }
134
135 pub fn chain_top_ordering(&self) -> &ChainTopOrdering {
137 &self.chain_top_ordering
138 }
139}
140
141impl AsRef<crate::Entry> for CreateInput {
142 fn as_ref(&self) -> &crate::Entry {
143 &self.entry
144 }
145}
146
147#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
149pub struct GetInput {
150 pub any_dht_hash: holo_hash::AnyDhtHash,
152 pub get_options: crate::entry::GetOptions,
154}
155
156impl GetInput {
157 pub fn new(any_dht_hash: holo_hash::AnyDhtHash, get_options: crate::entry::GetOptions) -> Self {
159 Self {
160 any_dht_hash,
161 get_options,
162 }
163 }
164}
165
166#[derive(PartialEq, Debug, Deserialize, Serialize, Clone)]
168pub struct UpdateInput {
169 pub original_action_address: holo_hash::ActionHash,
171 pub entry: crate::entry::Entry,
173 pub chain_top_ordering: ChainTopOrdering,
175}
176
177#[derive(PartialEq, Debug, Deserialize, Serialize, Clone)]
179pub struct DeleteInput {
180 pub deletes_action_hash: holo_hash::ActionHash,
182 pub chain_top_ordering: ChainTopOrdering,
184}
185
186impl DeleteInput {
187 pub fn new(
189 deletes_action_hash: holo_hash::ActionHash,
190 chain_top_ordering: ChainTopOrdering,
191 ) -> Self {
192 Self {
193 deletes_action_hash,
194 chain_top_ordering,
195 }
196 }
197}
198
199impl From<holo_hash::ActionHash> for DeleteInput {
200 fn from(deletes_action_hash: holo_hash::ActionHash) -> Self {
202 Self {
203 deletes_action_hash,
204 chain_top_ordering: ChainTopOrdering::default(),
205 }
206 }
207}
208
209impl EntryDefLocation {
210 pub fn app(
212 zome_index: impl Into<ZomeIndex>,
213 entry_def_index: impl Into<EntryDefIndex>,
214 ) -> Self {
215 Self::App(AppEntryDefLocation {
216 zome_index: zome_index.into(),
217 entry_def_index: entry_def_index.into(),
218 })
219 }
220}
221
222impl From<ScopedEntryDefIndex> for AppEntryDefLocation {
223 fn from(s: ScopedEntryDefIndex) -> Self {
224 Self {
225 zome_index: s.zome_index,
226 entry_def_index: s.zome_type,
227 }
228 }
229}
230
231impl From<ScopedEntryDefIndex> for EntryDefLocation {
232 fn from(s: ScopedEntryDefIndex) -> Self {
233 Self::App(s.into())
234 }
235}
236
237pub fn entry_type_matches(entry_type: &EntryType, entry: &Entry) -> bool {
239 #[allow(clippy::match_like_matches_macro)]
240 match (entry_type, entry) {
241 (EntryType::AgentPubKey, Entry::Agent(_)) => true,
242 (EntryType::App(_), Entry::App(_)) => true,
243 (EntryType::App(_), Entry::CounterSign(_, _)) => true,
244 (EntryType::CapClaim, Entry::CapClaim(_)) => true,
245 (EntryType::CapGrant, Entry::CapGrant(_)) => true,
246 _ => false,
247 }
248}