reifydb_core/interface/catalog/
flow.rs1use std::{
5 fmt,
6 fmt::{Display, Formatter},
7 ops::Deref,
8};
9
10use reifydb_type::value::{blob::Blob, duration::Duration};
11use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::interface::catalog::id::NamespaceId;
14
15#[repr(transparent)]
16#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
17pub struct FlowId(pub u64);
18
19impl Deref for FlowId {
20 type Target = u64;
21
22 fn deref(&self) -> &Self::Target {
23 &self.0
24 }
25}
26
27impl PartialEq<u64> for FlowId {
28 fn eq(&self, other: &u64) -> bool {
29 self.0.eq(other)
30 }
31}
32
33impl From<FlowId> for u64 {
34 fn from(value: FlowId) -> Self {
35 value.0
36 }
37}
38
39impl FlowId {
40 #[inline]
41 pub fn to_u64(self) -> u64 {
42 self.0
43 }
44}
45
46impl From<u64> for FlowId {
47 fn from(value: u64) -> Self {
48 Self(value)
49 }
50}
51
52impl Serialize for FlowId {
53 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
54 where
55 S: Serializer,
56 {
57 serializer.serialize_u64(self.0)
58 }
59}
60
61impl<'de> Deserialize<'de> for FlowId {
62 fn deserialize<D>(deserializer: D) -> Result<FlowId, D::Error>
63 where
64 D: Deserializer<'de>,
65 {
66 struct U64Visitor;
67
68 impl Visitor<'_> for U64Visitor {
69 type Value = FlowId;
70
71 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
72 formatter.write_str("an unsigned 64-bit number")
73 }
74
75 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
76 Ok(FlowId(value))
77 }
78 }
79
80 deserializer.deserialize_u64(U64Visitor)
81 }
82}
83
84#[repr(transparent)]
85#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
86pub struct FlowNodeId(pub u64);
87
88impl Display for FlowNodeId {
89 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
90 Display::fmt(&self.0, f)
91 }
92}
93
94impl Deref for FlowNodeId {
95 type Target = u64;
96
97 fn deref(&self) -> &Self::Target {
98 &self.0
99 }
100}
101
102impl PartialEq<u64> for FlowNodeId {
103 fn eq(&self, other: &u64) -> bool {
104 self.0.eq(other)
105 }
106}
107
108impl From<FlowNodeId> for u64 {
109 fn from(value: FlowNodeId) -> Self {
110 value.0
111 }
112}
113
114impl FlowNodeId {
115 #[inline]
116 pub fn to_u64(self) -> u64 {
117 self.0
118 }
119}
120
121impl From<&FlowNodeId> for FlowNodeId {
122 fn from(value: &FlowNodeId) -> Self {
123 *value
124 }
125}
126
127impl From<u64> for FlowNodeId {
128 fn from(value: u64) -> Self {
129 Self(value)
130 }
131}
132
133impl Serialize for FlowNodeId {
134 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
135 where
136 S: Serializer,
137 {
138 serializer.serialize_u64(self.0)
139 }
140}
141
142impl<'de> Deserialize<'de> for FlowNodeId {
143 fn deserialize<D>(deserializer: D) -> Result<FlowNodeId, D::Error>
144 where
145 D: Deserializer<'de>,
146 {
147 struct U64Visitor;
148
149 impl Visitor<'_> for U64Visitor {
150 type Value = FlowNodeId;
151
152 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
153 formatter.write_str("an unsigned 64-bit number")
154 }
155
156 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
157 Ok(FlowNodeId(value))
158 }
159 }
160
161 deserializer.deserialize_u64(U64Visitor)
162 }
163}
164
165#[repr(transparent)]
166#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
167pub struct FlowEdgeId(pub u64);
168
169impl Deref for FlowEdgeId {
170 type Target = u64;
171
172 fn deref(&self) -> &Self::Target {
173 &self.0
174 }
175}
176
177impl PartialEq<u64> for FlowEdgeId {
178 fn eq(&self, other: &u64) -> bool {
179 self.0.eq(other)
180 }
181}
182
183impl From<FlowEdgeId> for u64 {
184 fn from(value: FlowEdgeId) -> Self {
185 value.0
186 }
187}
188
189impl From<u64> for FlowEdgeId {
190 fn from(value: u64) -> Self {
191 Self(value)
192 }
193}
194
195impl Serialize for FlowEdgeId {
196 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
197 where
198 S: Serializer,
199 {
200 serializer.serialize_u64(self.0)
201 }
202}
203
204impl<'de> Deserialize<'de> for FlowEdgeId {
205 fn deserialize<D>(deserializer: D) -> Result<FlowEdgeId, D::Error>
206 where
207 D: Deserializer<'de>,
208 {
209 struct U64Visitor;
210
211 impl Visitor<'_> for U64Visitor {
212 type Value = FlowEdgeId;
213
214 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
215 formatter.write_str("an unsigned 64-bit number")
216 }
217
218 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
219 Ok(FlowEdgeId(value))
220 }
221 }
222
223 deserializer.deserialize_u64(U64Visitor)
224 }
225}
226
227#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
228pub enum FlowStatus {
229 Active,
230 Paused,
231 Failed,
232}
233
234impl FlowStatus {
235 pub fn to_u8(self) -> u8 {
236 match self {
237 FlowStatus::Active => 0,
238 FlowStatus::Paused => 1,
239 FlowStatus::Failed => 2,
240 }
241 }
242
243 pub fn from_u8(value: u8) -> Self {
244 match value {
245 0 => FlowStatus::Active,
246 1 => FlowStatus::Paused,
247 2 => FlowStatus::Failed,
248 _ => FlowStatus::Failed,
249 }
250 }
251}
252
253#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
254pub struct Flow {
255 pub id: FlowId,
256 pub namespace: NamespaceId,
257 pub name: String,
258 pub status: FlowStatus,
259 pub tick: Option<Duration>,
260}
261
262#[derive(Debug, Clone, PartialEq)]
263pub struct FlowNode {
264 pub id: FlowNodeId,
265 pub flow: FlowId,
266 pub node_type: u8,
267 pub data: Blob,
268}
269
270#[derive(Debug, Clone, PartialEq)]
271pub struct FlowEdge {
272 pub id: FlowEdgeId,
273 pub flow: FlowId,
274 pub source: FlowNodeId,
275 pub target: FlowNodeId,
276}