all jspg tests now passing

This commit is contained in:
2026-03-04 01:02:32 -05:00
parent e7f20e2cb6
commit 566b599512
32 changed files with 531 additions and 1068 deletions

View File

@ -120,11 +120,6 @@ pub struct SchemaObject {
#[serde(default)]
pub extensible: Option<bool>,
// Compiled Fields (Hidden from JSON/Serde)
#[serde(skip)]
pub compiled_ref: Option<Arc<Schema>>,
#[serde(skip)]
pub compiled_variations: Option<std::collections::HashSet<String>>,
#[serde(skip)]
pub compiled_format: Option<CompiledFormat>,
#[serde(skip)]
@ -153,7 +148,7 @@ impl std::fmt::Debug for CompiledFormat {
#[derive(Debug, Clone)]
pub struct CompiledRegex(pub regex::Regex);
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Default)]
pub struct Schema {
#[serde(flatten)]
pub obj: SchemaObject,
@ -161,15 +156,6 @@ pub struct Schema {
pub always_fail: bool,
}
impl Default for Schema {
fn default() -> Self {
Schema {
obj: SchemaObject::default(),
always_fail: false,
}
}
}
impl std::ops::Deref for Schema {
type Target = SchemaObject;
fn deref(&self) -> &Self::Target {
@ -186,16 +172,16 @@ impl Schema {
pub fn compile_internals(&mut self) {
self.map_children(|child| child.compile_internals());
if let Some(format_str) = &self.obj.format {
if let Some(fmt) = crate::database::formats::FORMATS.get(format_str.as_str()) {
self.obj.compiled_format = Some(crate::database::schema::CompiledFormat::Func(fmt.func));
}
if let Some(format_str) = &self.obj.format
&& let Some(fmt) = crate::database::formats::FORMATS.get(format_str.as_str())
{
self.obj.compiled_format = Some(crate::database::schema::CompiledFormat::Func(fmt.func));
}
if let Some(pattern_str) = &self.obj.pattern {
if let Ok(re) = regex::Regex::new(pattern_str) {
self.obj.compiled_pattern = Some(crate::database::schema::CompiledRegex(re));
}
if let Some(pattern_str) = &self.obj.pattern
&& let Ok(re) = regex::Regex::new(pattern_str)
{
self.obj.compiled_pattern = Some(crate::database::schema::CompiledRegex(re));
}
if let Some(pattern_props) = &self.obj.pattern_properties {
@ -211,46 +197,6 @@ impl Schema {
}
}
pub fn link_refs(&mut self, schemas: &std::collections::HashMap<String, Schema>) {
if let Some(ref_str) = &self.obj.ref_string {
if let Some(target) = schemas.get(ref_str) {
self.obj.compiled_ref = Some(Arc::new(target.clone()));
// Viral Infection: Inherit physical entity boundaries across the $ref pointer recursively
if self.obj.compiled_variations.is_none() {
let mut visited = std::collections::HashSet::new();
self.obj.compiled_variations = Self::resolve_variations(ref_str, schemas, &mut visited);
}
}
}
self.map_children(|child| child.link_refs(schemas));
}
fn resolve_variations(
ref_str: &str,
schemas: &std::collections::HashMap<String, Schema>,
visited: &mut std::collections::HashSet<String>,
) -> Option<std::collections::HashSet<String>> {
if !visited.insert(ref_str.to_string()) {
return None; // Cycle detected
}
if let Some(target) = schemas.get(ref_str) {
if let Some(vars) = &target.obj.compiled_variations {
return Some(vars.clone());
}
if let Some(next_ref) = &target.obj.ref_string {
return Self::resolve_variations(next_ref, schemas, visited);
}
}
None
}
pub fn stamp_variations(&mut self, variations: Option<std::collections::HashSet<String>>) {
self.obj.compiled_variations = variations.clone();
self.map_children(|child| child.stamp_variations(variations.clone()));
}
pub fn harvest(&mut self, to_insert: &mut Vec<(String, Schema)>) {
if let Some(id) = &self.obj.id {
to_insert.push((id.clone(), self.clone()));
@ -263,7 +209,7 @@ impl Schema {
F: FnMut(&mut Schema),
{
if let Some(props) = &mut self.obj.properties {
for (_, v) in props {
for v in props.values_mut() {
let mut inner = (**v).clone();
f(&mut inner);
*v = Arc::new(inner);
@ -271,7 +217,7 @@ impl Schema {
}
if let Some(pattern_props) = &mut self.obj.pattern_properties {
for (_, v) in pattern_props {
for v in pattern_props.values_mut() {
let mut inner = (**v).clone();
f(&mut inner);
*v = Arc::new(inner);