Files
faunosteo/crates/core/src/domain/sheet/check.rs
T
bchanot 0c47d0f837 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.
2026-10-14 00:17:21 +02:00

31 lines
1.2 KiB
Rust

//! 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,
})
}