json_eval_rs/
subform_methods.rs1use crate::JSONEval;
4use serde_json::Value;
5
6impl JSONEval {
7 pub fn evaluate_subform(
9 &mut self,
10 subform_path: &str,
11 data: &str,
12 context: Option<&str>,
13 ) -> Result<(), String> {
14 let subform = self.subforms.get_mut(subform_path)
15 .ok_or_else(|| format!("Subform not found: {}", subform_path))?;
16
17 subform.evaluate(data, context)
18 }
19
20 pub fn validate_subform(
22 &mut self,
23 subform_path: &str,
24 data: &str,
25 context: Option<&str>,
26 paths: Option<&[String]>,
27 ) -> Result<crate::ValidationResult, String> {
28 let subform = self.subforms.get_mut(subform_path)
29 .ok_or_else(|| format!("Subform not found: {}", subform_path))?;
30
31 subform.validate(data, context, paths)
32 }
33
34 pub fn evaluate_dependents_subform(
36 &mut self,
37 subform_path: &str,
38 changed_paths: &[String],
39 data: Option<&str>,
40 context: Option<&str>,
41 re_evaluate: bool,
42 ) -> Result<Value, String> {
43 let subform = self.subforms.get_mut(subform_path)
44 .ok_or_else(|| format!("Subform not found: {}", subform_path))?;
45
46 subform.evaluate_dependents(changed_paths, data, context, re_evaluate)
47 }
48
49 pub fn resolve_layout_subform(
51 &mut self,
52 subform_path: &str,
53 evaluate: bool,
54 ) -> Result<(), String> {
55 let subform = self.subforms.get_mut(subform_path)
56 .ok_or_else(|| format!("Subform not found: {}", subform_path))?;
57
58 subform.resolve_layout(evaluate)
59 }
60
61 pub fn get_evaluated_schema_subform(
63 &mut self,
64 subform_path: &str,
65 resolve_layout: bool,
66 ) -> Value {
67 if let Some(subform) = self.subforms.get_mut(subform_path) {
68 subform.get_evaluated_schema(resolve_layout)
69 } else {
70 Value::Null
71 }
72 }
73
74 pub fn get_schema_value_subform(
76 &mut self,
77 subform_path: &str,
78 ) -> Value {
79 if let Some(subform) = self.subforms.get_mut(subform_path) {
80 subform.get_schema_value()
81 } else {
82 Value::Null
83 }
84 }
85
86 pub fn get_evaluated_schema_without_params_subform(
88 &mut self,
89 subform_path: &str,
90 resolve_layout: bool,
91 ) -> Value {
92 if let Some(subform) = self.subforms.get_mut(subform_path) {
93 subform.get_evaluated_schema_without_params(resolve_layout)
94 } else {
95 Value::Null
96 }
97 }
98
99 pub fn get_evaluated_schema_by_path_subform(
101 &mut self,
102 subform_path: &str,
103 schema_path: &str,
104 skip_layout: bool,
105 ) -> Option<Value> {
106 if let Some(subform) = self.subforms.get_mut(subform_path) {
107 subform.get_evaluated_schema_by_path(schema_path, skip_layout)
108 } else {
109 None
110 }
111 }
112
113 pub fn get_evaluated_schema_by_paths_subform(
115 &mut self,
116 subform_path: &str,
117 schema_paths: &[String],
118 skip_layout: bool,
119 format: Option<crate::ReturnFormat>,
120 ) -> Value {
121 if let Some(subform) = self.subforms.get_mut(subform_path) {
122 subform.get_evaluated_schema_by_paths(schema_paths, skip_layout, format)
123 } else {
124 match format.unwrap_or_default() {
125 crate::ReturnFormat::Array => Value::Array(vec![]),
126 _ => Value::Object(serde_json::Map::new()),
127 }
128 }
129 }
130
131 pub fn get_schema_by_path_subform(
133 &self,
134 subform_path: &str,
135 schema_path: &str,
136 ) -> Option<Value> {
137 if let Some(subform) = self.subforms.get(subform_path) {
138 subform.get_schema_by_path(schema_path)
139 } else {
140 None
141 }
142 }
143
144 pub fn get_schema_by_paths_subform(
146 &self,
147 subform_path: &str,
148 schema_paths: &[String],
149 format: Option<crate::ReturnFormat>,
150 ) -> Value {
151 if let Some(subform) = self.subforms.get(subform_path) {
152 subform.get_schema_by_paths(schema_paths, format)
153 } else {
154 match format.unwrap_or_default() {
155 crate::ReturnFormat::Array => Value::Array(vec![]),
156 _ => Value::Object(serde_json::Map::new()),
157 }
158 }
159 }
160
161 pub fn get_subform_paths(&self) -> Vec<String> {
163 self.subforms.keys().cloned().collect()
164 }
165
166 pub fn has_subform(&self, subform_path: &str) -> bool {
168 self.subforms.contains_key(subform_path)
169 }
170}