riffdb_client_rust/generated/
mod.rs1use std::error::Error;
4use std::fmt;
5
6use riffdb_proto::{app::v1 as app_v1, v1};
7use riffdb_types::RequestId;
8
9use crate::{
10 ApplicationClientError, ApplicationEvent, ApplicationEventConsumer, ApplicationLiveQueryUpdate,
11 ApplicationReactiveOperation, CommandShapeError, IdempotentCommand, NamedQuery,
12 NamedQueryResult, QueryOptions,
13};
14
15pub trait GeneratedEventConsumer {
17 type Event;
19
20 fn event_consumer(self) -> Result<ApplicationEventConsumer, ApplicationClientError>;
22
23 fn decode_event(event: ApplicationEvent) -> Result<Self::Event, ApplicationClientError>;
25}
26
27pub trait GeneratedLiveQuery {
29 type Update;
31
32 fn live_operation(self) -> Result<ApplicationReactiveOperation, ApplicationClientError>;
34
35 fn decode_update(
37 update: ApplicationLiveQueryUpdate,
38 ) -> Result<Self::Update, ApplicationClientError>;
39}
40
41pub trait GeneratedQuery {
43 type Output;
45
46 fn named_query(self, options: QueryOptions) -> Result<NamedQuery, ApplicationClientError>;
48
49 fn decode_result(response: NamedQueryResult) -> Result<Self::Output, ApplicationClientError>;
51
52 fn decode_compact_result(
55 _outcome: String,
56 _response: app_v1::CompactResultField,
57 ) -> Result<Self::Output, ApplicationClientError> {
58 Err(ApplicationClientError::InvalidResponse)
59 }
60
61 fn decode_packed_result(
64 _outcome: String,
65 _response: app_v1::PackedResultField,
66 ) -> Result<Self::Output, ApplicationClientError> {
67 Err(ApplicationClientError::InvalidResponse)
68 }
69}
70
71pub trait GeneratedCommand {
76 type Outcome;
78
79 fn idempotent_command(&self) -> Result<IdempotentCommand, GeneratedCommandError>;
81
82 fn outcome_request(
87 &self,
88 request_id: RequestId,
89 ) -> Result<v1::GetOutcomeRequest, GeneratedCommandError>;
90
91 fn decode_outcome(
93 &self,
94 response: &v1::ExecuteCommandResponse,
95 ) -> Result<Self::Outcome, GeneratedCommandError>;
96
97 fn workflow_successor_revisions(
106 &self,
107 _response: &v1::ExecuteCommandResponse,
108 ) -> Result<Vec<WorkflowSuccessorRevision>, GeneratedCommandError> {
109 Ok(Vec::new())
110 }
111}
112
113#[derive(Clone, Debug, Eq, PartialEq)]
115pub struct WorkflowSuccessorRevision {
116 binding: &'static str,
117 revision: u64,
118}
119
120impl WorkflowSuccessorRevision {
121 #[must_use]
123 pub const fn generated(binding: &'static str, revision: u64) -> Self {
124 Self { binding, revision }
125 }
126
127 #[must_use]
129 pub const fn binding(&self) -> &'static str {
130 self.binding
131 }
132
133 #[must_use]
135 pub const fn revision(&self) -> u64 {
136 self.revision
137 }
138}
139
140#[derive(Clone, Copy, Debug, Eq, PartialEq)]
142pub enum GeneratedInputBudgetCause {
143 CollectionCount,
145 IndividualValueBytes,
147 AggregateCanonicalElementBytes,
149}
150
151impl GeneratedInputBudgetCause {
152 #[must_use]
154 pub const fn as_str(self) -> &'static str {
155 match self {
156 Self::CollectionCount => "collection_count",
157 Self::IndividualValueBytes => "individual_value_bytes",
158 Self::AggregateCanonicalElementBytes => "aggregate_canonical_element_bytes",
159 }
160 }
161}
162
163#[derive(Clone, Copy, Debug, Eq, PartialEq)]
165pub struct GeneratedInputBudgetError {
166 cause: GeneratedInputBudgetCause,
167 collection: &'static str,
168 index: Option<usize>,
169 leaf: Option<&'static str>,
170}
171
172impl GeneratedInputBudgetError {
173 #[must_use]
175 pub const fn new(
176 cause: GeneratedInputBudgetCause,
177 collection: &'static str,
178 index: Option<usize>,
179 leaf: Option<&'static str>,
180 ) -> Self {
181 Self {
182 cause,
183 collection,
184 index,
185 leaf,
186 }
187 }
188
189 #[must_use]
191 pub const fn cause(&self) -> GeneratedInputBudgetCause {
192 self.cause
193 }
194
195 #[must_use]
197 pub const fn collection(&self) -> &'static str {
198 self.collection
199 }
200
201 #[must_use]
203 pub const fn index(&self) -> Option<usize> {
204 self.index
205 }
206
207 #[must_use]
209 pub const fn leaf(&self) -> Option<&'static str> {
210 self.leaf
211 }
212}
213
214#[derive(Clone, Copy, Debug, Eq, PartialEq)]
216pub enum GeneratedCommandError {
217 InvalidInputShape,
219 InvalidOutcomeShape,
221 InputBudget(GeneratedInputBudgetError),
223}
224
225impl GeneratedCommandError {
226 #[must_use]
228 pub const fn input_budget(
229 cause: GeneratedInputBudgetCause,
230 collection: &'static str,
231 index: Option<usize>,
232 leaf: Option<&'static str>,
233 ) -> Self {
234 Self::InputBudget(GeneratedInputBudgetError::new(
235 cause, collection, index, leaf,
236 ))
237 }
238}
239
240impl From<CommandShapeError> for GeneratedCommandError {
241 fn from(_: CommandShapeError) -> Self {
242 Self::InvalidInputShape
243 }
244}
245
246impl fmt::Display for GeneratedCommandError {
247 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
248 formatter.write_str(match self {
249 Self::InvalidInputShape => "generated command input is invalid",
250 Self::InvalidOutcomeShape => "generated command outcome is invalid",
251 Self::InputBudget(_) => "generated command input exceeds its compiled budget",
252 })
253 }
254}
255
256impl Error for GeneratedCommandError {}
257
258pub mod legal_spend;