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