feat(domain): R2.2 sheet integrity rules, publish check, SheetIndexData and SQL conformance in Rust

The 21 rules of validateSheetDocument ported with identical codes,
severities, paths and messages (frozen from the TypeScript on 26
conformance fixtures), createEmptySheetDocument, the publish check
(strict shape then rules), and the index data React reads once (positions
with Map semantics, names, spine ids, finding-path keys). The fixtures
also carry the codes private.sheet_document_issues returns: a cargo test
generates supabase/tests/011_sheet_conformance.sql and refuses drift
(PGlite 12/12 files, real stack 446/446). .prettierignore keeps the
byte-exact oracles and generated fixtures out of pnpm format.
This commit is contained in:
bchanot committed 2026-10-14 00:17:21 +02:00
1 parent 343d6f4c1f
commit 0c47d0f837
40 files changed
+3280 -1

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
//! The publication gate on the client side (`packages/supabase/src/anatomical-sheets.ts`):
//! the full strict shape, then every integrity rule. The database re-checks the referential
//! rules on its own (`private.sheet_document_issues`); this never replaces that guard.
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[cfg(feature = "ts")]
use ts_rs::TS;
use super::schema::AnatomicalSheetDocument;
use super::validate::{SheetIssue, is_publishable, validate_sheet_document};
/// The issues of a shape-valid document and whether they allow publication.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
pub struct SheetCheck {
pub issues: Vec<SheetIssue>,
pub publishable: bool,
}
/// Strict parse then rules; a document the shape refuses is an error, never a check.
pub fn check_sheet_document(value: Value) -> Result<SheetCheck, serde_json::Error> {
let document: AnatomicalSheetDocument = serde_json::from_value(value)?;
let issues = validate_sheet_document(&document);
let publishable = is_publishable(&issues);
Ok(SheetCheck {
issues,
publishable,
})
}
+36
View File
@@ -0,0 +1,36 @@
//! Starting point of a new sheet (`anatomical-sheet/create.ts`): shape-valid so it can be
//! saved as a draft at once, but not publishable until the main view gets its SVG asset.
use serde_json::json;
use super::schema::{AnatomicalSheetDocument, LocalizedText, SHEET_DOCUMENT_SCHEMA_VERSION};
pub const MAIN_VIEW_ID: &str = "view-main";
/// `createEmptySheetDocument`: the document passes the strict schema, as `Schema.parse` does
/// in TypeScript; an invalid species id or an empty label is refused the same way.
pub fn create_empty_sheet_document(
species_id: &str,
name: &LocalizedText,
) -> Result<AnatomicalSheetDocument, serde_json::Error> {
serde_json::from_value(json!({
"schema_version": SHEET_DOCUMENT_SCHEMA_VERSION,
"species_id": species_id,
"name": name,
"description": {},
"scope_disclaimer": {},
"attribution": { "authors": [], "license": null, "notes": null },
"vertebral_config": { "regions": [] },
"references": [],
"categories": [],
"views": [{
"id": MAIN_VIEW_ID,
"kind": "main",
"name": { "fr": "Vue principale", "en": "Main view" },
"svg_asset_id": null,
"view_box": null,
}],
"annotations": [],
"finding_zones": [],
}))
}
+125
View File
@@ -0,0 +1,125 @@
//! What React reads of the loaded sheet, computed once per session (review III.3 rule 2,
//! R2 plan rev 2 §5): plain data, no call in a render path. Positions point into the
//! normalized document's arrays; the duplicate-id policies are the TypeScript index's.
use std::collections::{BTreeMap, HashMap, HashSet};
use serde::Serialize;
#[cfg(feature = "ts")]
use ts_rs::TS;
use super::index::IndexedDocument;
use super::loaded::LoadedSheet;
use super::schema::{AnatomicalSheetDocument, LocalizedText};
use super::validate::FindingLevelItem;
use crate::domain::archive::SheetStatus;
use crate::domain::js::JsInt;
use crate::domain::report::SheetRef;
#[derive(Debug, Clone, PartialEq, Serialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
#[serde(rename_all = "camelCase")]
pub struct SheetIndexData {
pub status: SheetStatus,
#[serde(rename = "ref")]
pub reference: SheetRef,
pub species_id: String,
#[cfg_attr(feature = "ts", ts(type = "number"))]
pub schema_version: JsInt,
/// The first `main` view of the document.
pub main_view_id: String,
/// The document as parsed (defaults filled in).
pub document: AnatomicalSheetDocument,
/// Position in `document.views` by id; the last duplicate wins.
pub view_by_id: BTreeMap<String, usize>,
/// Position in `document.annotations` by id; the last duplicate wins.
pub annotation_by_id: BTreeMap<String, usize>,
/// Position in `document.finding_zones` by id; the last duplicate wins.
pub finding_zone_by_id: BTreeMap<String, usize>,
/// Display name of every annotation id (a trigger: its own, else its view's).
pub names: BTreeMap<String, LocalizedText>,
/// Ids that open the vertebra picker, in document order, each once.
pub spine_ids: Vec<String>,
/// Every finding path the sheet holds, as the JSON text of `[zoneId, ...path]`.
pub node_keys: Vec<String>,
}
fn sorted(positions: &HashMap<String, usize>) -> BTreeMap<String, usize> {
positions.iter().map(|(id, &p)| (id.clone(), p)).collect()
}
fn names(
indexed: IndexedDocument<'_>,
by_id: &HashMap<String, usize>,
) -> BTreeMap<String, LocalizedText> {
by_id
.iter()
.filter_map(|(id, &position)| {
let annotation = indexed.document.annotations.get(position)?;
Some((id.clone(), indexed.name(annotation)))
})
.collect()
}
fn spine_ids(indexed: IndexedDocument<'_>) -> Vec<String> {
let mut seen = HashSet::new();
indexed
.document
.annotations
.iter()
.map(|a| a.id())
.filter(|id| indexed.is_spine(id) && seen.insert(*id))
.map(str::to_owned)
.collect()
}
/// Paths of one sibling level and below, each id at its first occurrence only (the walk of
/// `nodeAt`, which takes the first child with a given id).
fn walk<'a, T: FindingLevelItem>(nodes: &'a [T], prefix: &mut Vec<&'a str>, out: &mut Vec<String>) {
let mut seen = HashSet::new();
for node in nodes {
if !seen.insert(node.id()) {
continue;
}
prefix.push(node.id());
if let Ok(key) = serde_json::to_string(prefix) {
out.push(key);
}
walk(node.children(), prefix, out);
prefix.pop();
}
}
fn node_keys(indexed: IndexedDocument<'_>, by_id: &HashMap<String, usize>) -> Vec<String> {
let mut out = Vec::new();
for (position, zone) in indexed.document.finding_zones.iter().enumerate() {
if by_id.get(&zone.id) != Some(&position) {
continue;
}
let mut prefix = vec![zone.id.as_str()];
walk(&zone.categories, &mut prefix, &mut out);
}
out
}
impl SheetIndexData {
pub fn of(sheet: &LoadedSheet) -> Self {
let indexed = sheet.indexed();
let index = sheet.index();
let main_view_id = indexed.main_view().id().to_owned();
Self {
status: sheet.status,
reference: sheet.reference.clone(),
species_id: sheet.species_id.clone(),
schema_version: sheet.schema_version,
main_view_id,
document: sheet.document.clone(),
view_by_id: sorted(index.view_positions()),
annotation_by_id: sorted(index.annotation_positions()),
finding_zone_by_id: sorted(index.zone_positions()),
names: names(indexed, index.annotation_positions()),
spine_ids: spine_ids(indexed),
node_keys: node_keys(indexed, index.zone_positions()),
}
}
}
+10 -1
View File
@@ -1,9 +1,18 @@
//! The anatomical sheet: document contract, index, the loaded sheet of a session.
//! The anatomical sheet: document contract, integrity rules, index, the loaded sheet of a
//! session and what React reads of it.
pub mod check;
pub mod create;
pub mod index;
pub mod index_data;
pub mod loaded;
pub mod schema;
pub mod validate;
pub use check::{SheetCheck, check_sheet_document};
pub use create::{MAIN_VIEW_ID, create_empty_sheet_document};
pub use index::{IndexedDocument, NoMainView, SheetIndex};
pub use index_data::SheetIndexData;
pub use loaded::{BundledSheetData, LoadError, LoadedSheet};
pub use schema::*;
pub use validate::{SheetIssue, SheetIssueSeverity, is_publishable, validate_sheet_document};
+563
View File
@@ -0,0 +1,563 @@
//! Integrity tier of the sheet model (`anatomical-sheet/validate.ts`,
//! ANATOMICAL_SHEET_MODEL.md §2.1).
//!
//! The shape tier (serde, as Zod) accepts dangling references so drafts can be saved
//! mid-edit; this tier lists every inconsistency for the editor and gates publication. Each
//! rule is one function, run in the TypeScript order; codes, paths and messages are the
//! contract shared with the SQL re-check (`private.sheet_document_issues`).
use std::collections::{HashMap, HashSet};
use serde::{Deserialize, Serialize};
#[cfg(feature = "ts")]
use ts_rs::TS;
use super::schema::{
AnatomicalSheetDocument, Annotation, DetailTriggerAnnotation, FindingCategory, FindingNode,
SheetView, VertebralRegion,
};
use crate::json::js_number;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
#[serde(rename_all = "lowercase")]
pub enum SheetIssueSeverity {
Error,
Warning,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
pub struct SheetIssue {
pub code: String,
pub severity: SheetIssueSeverity,
pub path: String,
pub message: String,
}
fn error(code: &str, path: String, message: String) -> SheetIssue {
SheetIssue {
code: code.to_owned(),
severity: SheetIssueSeverity::Error,
path,
message,
}
}
fn warning(code: &str, path: String, message: String) -> SheetIssue {
SheetIssue {
code: code.to_owned(),
severity: SheetIssueSeverity::Warning,
path,
message,
}
}
type Rule = fn(&AnatomicalSheetDocument) -> Vec<SheetIssue>;
/// A sibling level of the finding tree: categories or node children.
pub(crate) trait FindingLevelItem {
fn id(&self) -> &str;
fn reference_ids(&self) -> &[String];
fn children(&self) -> &[FindingNode];
}
impl FindingLevelItem for FindingCategory {
fn id(&self) -> &str {
&self.id
}
fn reference_ids(&self) -> &[String] {
&self.reference_ids
}
fn children(&self) -> &[FindingNode] {
&self.children
}
}
impl FindingLevelItem for FindingNode {
fn id(&self) -> &str {
&self.id
}
fn reference_ids(&self) -> &[String] {
&self.reference_ids
}
fn children(&self) -> &[FindingNode] {
&self.children
}
}
/// Indexes of entries whose value already appeared earlier in the list.
fn repeated_indexes(values: &[&str]) -> Vec<usize> {
let mut seen = HashSet::new();
values
.iter()
.enumerate()
.filter(|(_, value)| !seen.insert(**value))
.map(|(index, _)| index)
.collect()
}
fn duplicate_issues(
values: &[&str],
code: &str,
path_of: impl Fn(usize) -> String,
) -> Vec<SheetIssue> {
repeated_indexes(values)
.into_iter()
.map(|index| {
let value = values.get(index).copied().unwrap_or_default();
error(code, path_of(index), format!("Duplicate id \"{value}\""))
})
.collect()
}
/// Views by id, the first one wins (unlike the index, which keeps the last).
fn views_by_id(doc: &AnatomicalSheetDocument) -> HashMap<&str, &SheetView> {
let mut by_id = HashMap::new();
for view in &doc.views {
by_id.entry(view.id()).or_insert(view);
}
by_id
}
fn triggers(doc: &AnatomicalSheetDocument) -> impl Iterator<Item = &DetailTriggerAnnotation> {
doc.annotations.iter().filter_map(Annotation::trigger)
}
/// Rendering starts from a single root drawing.
fn check_main_view_count(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let count = doc.views.iter().filter(|view| view.is_main()).count();
if count == 1 {
return vec![];
}
vec![error(
"view.main.count",
"views".to_owned(),
format!("Expected 1 main view, found {count}"),
)]
}
fn check_view_ids_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: Vec<&str> = doc.views.iter().map(SheetView::id).collect();
duplicate_issues(&ids, "view.id.duplicate", |i| format!("views[{i}].id"))
}
fn check_view_parents_exist(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let by_id = views_by_id(doc);
doc.views
.iter()
.enumerate()
.filter_map(|(index, view)| {
let parent = view.parent_view_id()?;
(!by_id.contains_key(parent)).then(|| {
error(
"view.parent.missing",
format!("views[{index}].parent_view_id"),
format!("Parent view \"{parent}\" does not exist"),
)
})
})
.collect()
}
/// True when the parent chain loops before reaching the main view. A missing parent ends
/// the walk: that case is `view.parent.missing`.
fn loops_before_main(view: &SheetView, by_id: &HashMap<&str, &SheetView>) -> bool {
let mut visited = HashSet::from([view.id()]);
let mut current = view;
while let Some(parent_id) = current.parent_view_id() {
let Some(parent) = by_id.get(parent_id) else {
return false;
};
if !visited.insert(parent.id()) {
return true;
}
current = parent;
}
false
}
fn check_view_parent_cycles(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let by_id = views_by_id(doc);
doc.views
.iter()
.enumerate()
.filter(|(_, view)| !view.is_main() && loops_before_main(view, &by_id))
.map(|(index, view)| {
error(
"view.parent.cycle",
format!("views[{index}].parent_view_id"),
format!(
"Parent chain of \"{}\" never reaches the main view",
view.id()
),
)
})
.collect()
}
fn is_opened_from_parent(view_id: &str, parent_id: &str, doc: &AnatomicalSheetDocument) -> bool {
triggers(doc).any(|t| t.opens_view_id == view_id && t.view_id == parent_id)
}
/// A detail view nobody can open is dead content for the practitioner.
fn check_views_reachable(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let by_id = views_by_id(doc);
doc.views
.iter()
.enumerate()
.filter_map(|(index, view)| {
let parent = view.parent_view_id()?;
let unreachable =
by_id.contains_key(parent) && !is_opened_from_parent(view.id(), parent, doc);
unreachable.then(|| {
error(
"view.unreachable",
format!("views[{index}]"),
format!("No detail_trigger in \"{parent}\" opens \"{}\"", view.id()),
)
})
})
.collect()
}
/// Every view must have something to draw: its own asset or a crop.
fn view_asset_issue(view: &SheetView, index: usize) -> Option<SheetIssue> {
if view.svg_asset_id().is_some() {
return None;
}
if view.is_main() {
return Some(error(
"view.asset.missing",
format!("views[{index}].svg_asset_id"),
format!("Main view \"{}\" has no SVG asset", view.id()),
));
}
if view.view_box().is_some() {
return None;
}
Some(error(
"view.asset.missing",
format!("views[{index}].view_box"),
format!(
"Detail view \"{}\" has neither an asset nor a view_box",
view.id()
),
))
}
fn check_view_assets(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
doc.views
.iter()
.enumerate()
.filter_map(|(index, view)| view_asset_issue(view, index))
.collect()
}
/// Report points are keyed by annotation id across every view.
fn check_annotation_ids_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: Vec<&str> = doc.annotations.iter().map(Annotation::id).collect();
duplicate_issues(&ids, "annotation.id.duplicate", |i| {
format!("annotations[{i}].id")
})
}
fn check_annotation_views(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let by_id = views_by_id(doc);
doc.annotations
.iter()
.enumerate()
.filter(|(_, a)| !by_id.contains_key(a.view_id()))
.map(|(index, a)| {
error(
"annotation.view.missing",
format!("annotations[{index}].view_id"),
format!("View \"{}\" does not exist", a.view_id()),
)
})
.collect()
}
fn check_annotation_categories(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: HashSet<&str> = doc.categories.iter().map(|c| c.id.as_str()).collect();
doc.annotations
.iter()
.enumerate()
.filter(|(_, a)| !ids.contains(a.category_id()))
.map(|(index, a)| {
error(
"annotation.category.missing",
format!("annotations[{index}].category_id"),
format!("Category \"{}\" does not exist", a.category_id()),
)
})
.collect()
}
/// A trigger opens a direct child of the view it is drawn in.
fn opens_child_of_own_view(
trigger: &DetailTriggerAnnotation,
by_id: &HashMap<&str, &SheetView>,
) -> bool {
by_id
.get(trigger.opens_view_id.as_str())
.and_then(|target| target.parent_view_id())
.is_some_and(|parent| parent == trigger.view_id)
}
fn check_trigger_targets(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let by_id = views_by_id(doc);
doc.annotations
.iter()
.enumerate()
.filter_map(|(index, a)| {
let trigger = a.trigger()?;
(!opens_child_of_own_view(trigger, &by_id)).then(|| {
error(
"annotation.opens_view.invalid",
format!("annotations[{index}].opens_view_id"),
format!(
"\"{}\" is not a detail child of \"{}\"",
trigger.opens_view_id, trigger.view_id
),
)
})
})
.collect()
}
fn check_annotation_finding_zones(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: HashSet<&str> = doc.finding_zones.iter().map(|z| z.id.as_str()).collect();
doc.annotations
.iter()
.enumerate()
.filter_map(|(index, a)| {
let zone = a.observable()?.finding_zone_id.as_deref()?;
(!ids.contains(zone)).then(|| {
error(
"annotation.finding_zone.missing",
format!("annotations[{index}].finding_zone_id"),
format!("Finding zone \"{zone}\" does not exist"),
)
})
})
.collect()
}
fn check_annotation_regions(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let regions = &doc.vertebral_config.regions;
let codes: HashSet<&str> = regions.iter().map(|r| r.code.as_str()).collect();
doc.annotations
.iter()
.enumerate()
.filter_map(|(index, a)| {
let code = a.observable()?.vertebral_region_code.as_deref()?;
(!codes.contains(code)).then(|| {
error(
"annotation.region.missing",
format!("annotations[{index}].vertebral_region_code"),
format!("Vertebral region \"{code}\" is not configured"),
)
})
})
.collect()
}
/// Allowed in a draft, but a click on it would offer nothing to record.
fn check_annotations_have_findings(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
doc.annotations
.iter()
.enumerate()
.filter_map(|(index, a)| {
let observable = a.observable()?;
observable.finding_zone_id.is_none().then(|| {
warning(
"annotation.no_findings",
format!("annotations[{index}].finding_zone_id"),
format!(
"Annotation \"{}\" is linked to no finding zone",
observable.id
),
)
})
})
.collect()
}
fn check_region_codes_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let regions = &doc.vertebral_config.regions;
let codes: Vec<&str> = regions.iter().map(|r| r.code.as_str()).collect();
duplicate_issues(&codes, "region.code.duplicate", |i| {
format!("vertebral_config.regions[{i}].code")
})
}
fn check_category_ids_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: Vec<&str> = doc.categories.iter().map(|c| c.id.as_str()).collect();
duplicate_issues(&ids, "category.id.duplicate", |i| {
format!("categories[{i}].id")
})
}
fn check_finding_zone_ids_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: Vec<&str> = doc.finding_zones.iter().map(|z| z.id.as_str()).collect();
duplicate_issues(&ids, "finding_zone.id.duplicate", |i| {
format!("finding_zones[{i}].id")
})
}
/// Findings are addressed by (zone, path[]), so ids only need to be unique among siblings,
/// at every depth.
fn sibling_issues<T: FindingLevelItem>(nodes: &[T], path: &str) -> Vec<SheetIssue> {
let ids: Vec<&str> = nodes.iter().map(FindingLevelItem::id).collect();
let mut issues = duplicate_issues(&ids, "finding.id.duplicate", |i| format!("{path}[{i}].id"));
for (index, node) in nodes.iter().enumerate() {
issues.extend(sibling_issues(
node.children(),
&format!("{path}[{index}].children"),
));
}
issues
}
fn check_finding_siblings(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
doc.finding_zones
.iter()
.enumerate()
.flat_map(|(index, zone)| {
sibling_issues(
&zone.categories,
&format!("finding_zones[{index}].categories"),
)
})
.collect()
}
/// Allowed in a draft, but nothing on the drawing can reach this zone.
fn check_finding_zones_referenced(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let referenced: HashSet<&str> = doc
.annotations
.iter()
.filter_map(Annotation::observable)
.filter_map(|a| a.finding_zone_id.as_deref())
.collect();
doc.finding_zones
.iter()
.enumerate()
.filter(|(_, zone)| !referenced.contains(zone.id.as_str()))
.map(|(index, zone)| {
warning(
"finding_zone.unreferenced",
format!("finding_zones[{index}]"),
format!("No annotation points to finding zone \"{}\"", zone.id),
)
})
.collect()
}
fn check_reference_ids_unique(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let ids: Vec<&str> = doc.references.iter().map(|r| r.id.as_str()).collect();
duplicate_issues(&ids, "reference.id.duplicate", |i| {
format!("references[{i}].id")
})
}
/// A citation must point at a declared reference, at every depth.
fn citation_issues<T: FindingLevelItem>(
nodes: &[T],
path: &str,
known: &HashSet<&str>,
) -> Vec<SheetIssue> {
let mut issues = Vec::new();
for (index, node) in nodes.iter().enumerate() {
for (ref_index, id) in node.reference_ids().iter().enumerate() {
if !known.contains(id.as_str()) {
issues.push(error(
"finding.reference.missing",
format!("{path}[{index}].reference_ids[{ref_index}]"),
format!("Reference \"{id}\" is not declared in references"),
));
}
}
let nested = format!("{path}[{index}].children");
issues.extend(citation_issues(node.children(), &nested, known));
}
issues
}
fn check_finding_references(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
let known: HashSet<&str> = doc.references.iter().map(|r| r.id.as_str()).collect();
doc.finding_zones
.iter()
.enumerate()
.flat_map(|(index, zone)| {
let path = format!("finding_zones[{index}].categories");
citation_issues(&zone.categories, &path, &known)
})
.collect()
}
/// The usual count must sit inside the documented variation.
fn count_range_issue(region: &VertebralRegion, index: usize) -> Option<SheetIssue> {
let range = region.count_range.as_ref()?;
let count = region.count.get();
if range.min.get() <= count && count <= range.max.get() {
return None;
}
Some(error(
"region.count_range.invalid",
format!("vertebral_config.regions[{index}].count_range"),
format!(
"Region \"{}\": count {} outside {}\u{2013}{}",
region.code,
js_number(count),
js_number(range.min.get()),
js_number(range.max.get())
),
))
}
fn check_region_count_ranges(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
doc.vertebral_config
.regions
.iter()
.enumerate()
.filter_map(|(index, region)| count_range_issue(region, index))
.collect()
}
const RULES: [Rule; 21] = [
check_main_view_count,
check_view_ids_unique,
check_view_parents_exist,
check_view_parent_cycles,
check_views_reachable,
check_view_assets,
check_annotation_ids_unique,
check_annotation_views,
check_annotation_categories,
check_trigger_targets,
check_annotation_finding_zones,
check_annotation_regions,
check_annotations_have_findings,
check_region_codes_unique,
check_category_ids_unique,
check_finding_zone_ids_unique,
check_finding_siblings,
check_finding_zones_referenced,
check_reference_ids_unique,
check_finding_references,
check_region_count_ranges,
];
/// Lists every integrity issue of a shape-valid document.
pub fn validate_sheet_document(doc: &AnatomicalSheetDocument) -> Vec<SheetIssue> {
RULES.iter().flat_map(|rule| rule(doc)).collect()
}
/// Warnings never block publication; errors always do.
pub fn is_publishable(issues: &[SheetIssue]) -> bool {
!issues
.iter()
.any(|issue| issue.severity == SheetIssueSeverity::Error)
}