Skip to main content

icydb_schema/validate/
mod.rs

1//! Schema validation orchestration and shared helpers.
2
3pub mod naming;
4
5use crate::{
6    error::ErrorTree,
7    node::{Schema, VisitableNode},
8    visit::ValidateVisitor,
9};
10
11/// Run full schema validation in a staged, deterministic order.
12pub(crate) fn validate_schema(schema: &Schema) -> Result<(), ErrorTree> {
13    // Phase 1: validate each node (structural + local invariants).
14    let mut errors = validate_nodes(schema);
15
16    // Phase 2: enforce schema-wide invariants.
17    validate_global(schema, &mut errors);
18
19    errors.result()
20}
21
22// Validate all nodes via a visitor to retain route-aware error aggregation.
23fn validate_nodes(schema: &Schema) -> ErrorTree {
24    let mut visitor = ValidateVisitor::new();
25    schema.accept(&mut visitor);
26
27    visitor.errors
28}
29
30// Run global validation passes that require a full schema view.
31fn validate_global(schema: &Schema, errors: &mut ErrorTree) {
32    naming::validate_entity_naming(schema, errors);
33}