json_eval_rs/jsoneval/
mod.rs

1use std::sync::{Arc, Mutex};
2
3use crate::jsoneval::eval_cache::EvalCache;
4use crate::jsoneval::eval_data::EvalData;
5
6use crate::jsoneval::table_metadata::TableMetadata;
7
8use crate::rlogic::{
9    LogicId, RLogic,
10};
11use crate::jsoneval::types::DependentItem;
12
13use indexmap::{IndexMap, IndexSet};
14
15use serde_json::Value;
16
17pub mod cache;
18pub mod dependents;
19pub mod eval_cache;
20pub mod eval_data;
21pub mod evaluate;
22pub mod getters;
23pub mod core;
24pub mod json_parser;
25pub mod layout;
26pub mod logic;
27pub mod parsed_schema;
28pub mod parsed_schema_cache;
29pub mod path_utils;
30pub mod subform_methods;
31pub mod table_evaluate;
32pub mod table_metadata;
33pub mod types;
34pub mod validation;
35
36pub struct JSONEval {
37    pub schema: Arc<Value>,
38    pub engine: Arc<RLogic>,
39    /// Zero-copy Arc-wrapped collections (shared from ParsedSchema)
40    pub evaluations: Arc<IndexMap<String, LogicId>>,
41    pub tables: Arc<IndexMap<String, Value>>,
42    /// Pre-compiled table metadata (computed at parse time for zero-copy evaluation)
43    pub table_metadata: Arc<IndexMap<String, TableMetadata>>,
44    pub dependencies: Arc<IndexMap<String, IndexSet<String>>>,
45    /// Evaluations grouped into parallel-executable batches
46    /// Each inner Vec contains evaluations that can run concurrently
47    pub sorted_evaluations: Arc<Vec<Vec<String>>>,
48    /// Evaluations categorized for result handling
49    /// Dependents: map from source field to list of dependent items
50    pub dependents_evaluations: Arc<IndexMap<String, Vec<DependentItem>>>,
51    /// Rules: evaluations with "/rules/" in path
52    pub rules_evaluations: Arc<Vec<String>>,
53    /// Fields with rules: dotted paths of all fields that have rules (for efficient validation)
54    pub fields_with_rules: Arc<Vec<String>>,
55    /// Others: all other evaluations not in sorted_evaluations (for evaluated_schema output)
56    pub others_evaluations: Arc<Vec<String>>,
57    /// Value: evaluations ending with ".value" in path
58    pub value_evaluations: Arc<Vec<String>>,
59    /// Cached layout paths (collected at parse time)
60    pub layout_paths: Arc<Vec<String>>,
61    /// Options URL templates (url_path, template_str, params_path) collected at parse time
62    pub options_templates: Arc<Vec<(String, String, String)>>,
63    /// Subforms: isolated JSONEval instances for array fields with items
64    /// Key is the schema path (e.g., "#/riders"), value is the sub-JSONEval
65    pub subforms: IndexMap<String, Box<JSONEval>>,
66
67    /// Cached reference to parsed schema mappings (reffed_by)
68    pub reffed_by: Arc<IndexMap<String, Vec<String>>>,
69
70    /// Cached paths of fields that have hidden conditions
71    pub conditional_hidden_fields: Arc<Vec<String>>,
72    /// Cached paths of fields that have disabled conditions and value property
73    pub conditional_readonly_fields: Arc<Vec<String>>,
74
75    pub context: Value,
76    pub data: Value,
77    pub evaluated_schema: Value,
78    pub eval_data: EvalData,
79    /// Evaluation cache with content-based hashing and zero-copy storage
80    pub eval_cache: EvalCache,
81    /// Flag to enable/disable evaluation caching
82    /// Set to false for web API usage where each request creates a new JSONEval instance
83    pub cache_enabled: bool,
84    /// Mutex for synchronous execution of evaluate and evaluate_dependents
85    pub(crate) eval_lock: Mutex<()>,
86    /// Cached MessagePack bytes for zero-copy schema retrieval
87    /// Stores original MessagePack if initialized from binary, cleared on schema mutations
88    pub(crate) cached_msgpack_schema: Option<Vec<u8>>,
89}