json_eval_rs/jsoneval/
types.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use indexmap::IndexMap;
4
5/// Return format for path-based methods
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub enum ReturnFormat {
8    /// Nested object preserving the path hierarchy (default)
9    /// Example: { "user": { "profile": { "name": "John" } } }
10    #[default]
11    Nested,
12    /// Flat object with dotted keys
13    /// Example: { "user.profile.name": "John" }
14    Flat,
15    /// Array of values in the order of requested paths
16    /// Example: ["John"]
17    Array,
18}
19
20/// Dependent item structure for transitive dependency tracking
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct DependentItem {
23    pub ref_path: String,
24    pub clear: Option<Value>, // Can be $evaluation or boolean
25    pub value: Option<Value>, // Can be $evaluation or primitive value
26}
27
28/// Validation error for a field
29#[derive(Debug, Clone, Serialize, Deserialize)]
30pub struct ValidationError {
31    #[serde(rename = "type")]
32    pub rule_type: String,
33    pub message: String,
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub code: Option<String>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub pattern: Option<String>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub field_value: Option<String>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub data: Option<Value>,
42}
43
44/// Result of validation
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct ValidationResult {
47    pub has_error: bool,
48    pub errors: IndexMap<String, ValidationError>,
49}