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