teo_runtime/model/property/
property.rs1use std::collections::BTreeMap;
2use std::sync::Arc;
3use serde::{Serialize, Serializer};
4use teo_parser::r#type::Type;
5use crate::comment::Comment;
6use crate::database::r#type::DatabaseType;
7use crate::model::field::column_named::ColumnNamed;
8use crate::model::field::Index;
9use crate::model::field::indexable::{Indexable};
10use crate::model::field::is_optional::IsOptional;
11use crate::traits::named::Named;
12use crate::model::field::typed::Typed;
13use crate::optionality::Optionality;
14use crate::pipeline::pipeline::Pipeline;
15use crate::traits::documentable::Documentable;
16use crate::value::Value;
17
18#[derive(Debug, Clone)]
19pub struct Property {
20 pub(super) inner: Arc<Inner>
21}
22
23#[derive(Debug)]
24pub(super) struct Inner {
25 pub(super) name: String,
26 pub(super) comment: Option<Comment>,
27 pub(super) column_name: String,
28 pub(super) optionality: Optionality,
29 pub(super) r#type: Type,
30 pub(super) database_type: DatabaseType,
31 pub(super) dependencies: Vec<String>,
32 pub(super) setter: Option<Pipeline>,
33 pub(super) getter: Option<Pipeline>,
34 pub(super) input_omissible: bool,
35 pub(super) output_omissible: bool,
36 pub(super) cached: bool,
37 pub(super) index: Option<Index>,
38 pub(super) data: BTreeMap<String, Value>,
39}
40
41impl Property {
42
43 pub fn optionality(&self) -> &Optionality {
44 &self.inner.optionality
45 }
46
47 pub fn database_type(&self) -> &DatabaseType {
48 &self.inner.database_type
49 }
50
51 pub fn dependencies(&self) -> &Vec<String> {
52 &self.inner.dependencies
53 }
54
55 pub fn setter(&self) -> Option<&Pipeline> {
56 self.inner.setter.as_ref()
57 }
58
59 pub fn getter(&self) -> Option<&Pipeline> {
60 self.inner.getter.as_ref()
61 }
62
63 pub fn input_omissible(&self) -> bool {
64 self.inner.input_omissible
65 }
66
67 pub fn output_omissible(&self) -> bool {
68 self.inner.output_omissible
69 }
70
71 pub fn cached(&self) -> bool {
72 self.inner.cached
73 }
74
75 pub fn data(&self) -> &BTreeMap<String, Value> {
76 &self.inner.data
77 }
78}
79
80impl Named for Property {
81
82 fn name(&self) -> &str {
83 self.inner.name.as_str()
84 }
85}
86
87impl ColumnNamed for Property {
88
89 fn column_name(&self) -> &str {
90 self.inner.column_name.as_str()
91 }
92}
93
94impl Indexable for Property {
95
96 fn index(&self) -> Option<&Index> {
97 self.inner.index.as_ref()
98 }
99}
100
101impl IsOptional for Property {
102
103 fn is_optional(&self) -> bool {
104 self.inner.optionality.is_any_optional()
105 }
106
107 fn is_required(&self) -> bool {
108 self.inner.optionality.is_required()
109 }
110}
111
112impl Typed for Property {
113
114 fn r#type(&self) -> &Type {
115 &self.inner.r#type
116 }
117}
118
119impl Documentable for Property {
120
121 fn comment(&self) -> Option<&Comment> {
122 self.inner.comment.as_ref()
123 }
124
125 fn kind(&self) -> &'static str {
126 "property"
127 }
128}
129
130impl Serialize for Property {
131 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
132 where
133 S: Serializer
134 {
135 todo!()
136 }
137}