fluvio_controlplane_metadata/tableformat/
spec.rs1#![allow(clippy::assign_op_pattern)]
2
3use fluvio_protocol::{Encoder, Decoder};
4
5#[derive(Encoder, Decoder, Default, Debug, Eq, PartialEq, Clone)]
6#[cfg_attr(
7 feature = "use_serde",
8 derive(serde::Serialize, serde::Deserialize),
9 serde(rename_all = "camelCase")
10)]
11pub struct TableFormatSpec {
12 pub name: String,
13 pub input_format: Option<DataFormat>,
14 pub columns: Option<Vec<TableFormatColumnConfig>>,
15 #[cfg_attr(feature = "use_serde", serde(skip_serializing_if = "Option::is_none"))]
16 pub smartmodule: Option<String>,
17}
18
19impl TableFormatSpec {
20 pub fn get_primary_keys(&self) -> Vec<String> {
21 if let Some(columns) = &self.columns {
22 let mut primary_keys = Vec::new();
23
24 for c in columns {
25 if let Some(is_primary_key) = c.primary_key {
26 if is_primary_key {
27 primary_keys.push(c.key_path.clone());
28 }
29 }
30 }
31
32 primary_keys
33 } else {
34 Vec::new()
35 }
36 }
37}
38
39#[derive(Encoder, Decoder, Debug, Eq, PartialEq, Clone)]
40#[cfg_attr(
41 feature = "use_serde",
42 derive(serde::Serialize, serde::Deserialize),
43 serde(rename_all = "UPPERCASE")
44)]
45pub enum DataFormat {
46 #[fluvio(tag = 0)]
47 JSON,
48 }
51
52impl Default for DataFormat {
53 fn default() -> Self {
54 Self::JSON
55 }
56}
57#[derive(Encoder, Decoder, Default, Debug, Eq, PartialEq, Clone)]
58#[cfg_attr(
59 feature = "use_serde",
60 derive(serde::Serialize, serde::Deserialize),
61 serde(rename_all = "camelCase")
62)]
63pub struct TableFormatColumnConfig {
64 pub header_label: Option<String>,
65 pub width: Option<String>,
66 pub alignment: Option<TableFormatAlignment>,
67 pub key_path: String,
68 pub format: Option<String>,
69 pub display: Option<bool>,
70 pub primary_key: Option<bool>,
71 pub header_bg_color: Option<Color>,
72 pub header_text_color: Option<Color>,
73}
74
75#[cfg_attr(
76 feature = "use_serde",
77 derive(serde::Serialize, serde::Deserialize),
78 serde(rename_all = "UPPERCASE")
79)]
80#[derive(Encoder, Decoder, Debug, Eq, PartialEq, Clone)]
81pub enum TableFormatAlignment {
82 #[fluvio(tag = 0)]
83 Left,
84 #[fluvio(tag = 1)]
85 Right,
86 #[fluvio(tag = 2)]
87 Center,
88}
89
90impl Default for TableFormatAlignment {
91 fn default() -> Self {
92 Self::Center
93 }
94}
95
96impl TableFormatColumnConfig {
97 pub fn new(key_path: String) -> Self {
98 Self {
99 key_path,
100 ..Default::default()
101 }
102 }
103
104 pub fn with_primary_key(mut self, is_primary_key: Option<bool>) -> Self {
105 self.primary_key = is_primary_key;
106 self
107 }
108
109 pub fn with_display(mut self, do_display_column: Option<bool>) -> Self {
110 self.display = do_display_column;
111 self
112 }
113
114 pub fn with_header_label(mut self, header_label: Option<String>) -> Self {
115 self.header_label = header_label;
116 self
117 }
118
119 pub fn with_alignment(mut self, alignment: Option<TableFormatAlignment>) -> Self {
120 self.alignment = alignment;
121 self
122 }
123
124 pub fn with_header_text_color(mut self, header_text_color: Option<Color>) -> Self {
125 self.header_text_color = header_text_color;
126 self
127 }
128
129 pub fn with_header_bg_color(mut self, header_bg_color: Option<Color>) -> Self {
130 self.header_bg_color = header_bg_color;
131 self
132 }
133}
134
135#[cfg_attr(
136 feature = "use_serde",
137 derive(serde::Serialize, serde::Deserialize),
138 serde(rename_all = "UPPERCASE")
139)]
140#[derive(Encoder, Decoder, Debug, Eq, PartialEq, Clone)]
141pub enum Color {
142 #[fluvio(tag = 0)]
143 Blue,
144 #[fluvio(tag = 1)]
145 Yellow,
146 #[fluvio(tag = 2)]
147 Green,
148}
149
150impl Default for Color {
151 fn default() -> Self {
152 Self::Blue
153 }
154}