feat(domain): V1-2.2 document measure, review groups, verdict, preview, edits

The core's authoring surface of contract §16.3: the server's document
measure, review groups with digests and removal groups, the change list,
the pure server verdict in the shape M5 reads, PreviewSheet with draft
and published modes, and the editor's commands with the §6.6 markings.
This commit is contained in:
bchanot committed 2026-10-29 13:14:21 +01:00
1 parent ac71c5b662
commit 64a43840ce
21 files changed
+5204 -17

No files matched your search

+47
View File
@@ -8,6 +8,7 @@ use serde::de::DeserializeOwned;
use serde_json::{Map, Value};
use crate::domain::js::{JsonReadError, parse_json};
use crate::domain::sheet::preview::{PreviewDrawing, PreviewFailure, PreviewInput, PreviewSheet};
use crate::domain::sheet::{BundledSheetData, LoadError, LoadedSheet};
use crate::domain::{ReportZone, SheetRef};
use crate::json::{pretty_js_round_trip, to_js_compact};
@@ -57,6 +58,52 @@ pub fn load_sheet(bundle: &str) -> Result<LoadedSheet, Failure> {
})
}
/// Loads a stored version for preview (V1-2.2, contract §10): `input` is the
/// `PreviewInput` JSON, the drawings came in as bytes. The failure names a closed kind
/// (`invalid_document`, `drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`,
/// `caps`), or `invalid_shape` / `invalid_json` / `lone_surrogate` for the input itself.
pub fn load_preview(input: &str, drawings: Vec<PreviewDrawing>) -> Result<PreviewSheet, Failure> {
let input: PreviewInput = parse_input(input)?;
PreviewSheet::load(input, drawings).map_err(preview_failure)
}
fn preview_failure(failure: PreviewFailure) -> Failure {
Failure::new(failure.kind(), failure.detail())
}
/// Runs the operation `op` on a previewed version (`preview.state`, `view.canvas`).
pub fn call_with_preview(preview: &PreviewSheet, op: &str, input: &str) -> String {
render(crate::ops::on_preview(preview, op, input).unwrap_or_else(|| Err(unknown(op))))
}
/// Replaces a previewed draft's document by the text an edit produced: `{"ok":true}` or a
/// closed refusal (`invalid_document`, `read_only`); the drawings are not read again.
pub fn replace_preview_document(preview: &mut PreviewSheet, text: &str) -> String {
render(
preview
.replace_document(text)
.map(|()| Value::Null)
.map_err(preview_failure),
)
}
/// Adds a drawing to a previewed draft: `{"ok":true}` or `drawing_hash_mismatch`,
/// `read_only`.
pub fn add_preview_drawing(preview: &mut PreviewSheet, drawing: PreviewDrawing) -> String {
render(
preview
.add_drawing(drawing)
.map(|()| Value::Null)
.map_err(preview_failure),
)
}
/// The cleaning answer for a file picked for upload (contract §9.2): always `ok`, the value
/// says clean, cleanable or rejected.
pub fn clean_svg(bytes: &[u8]) -> String {
render(to_value(&crate::anatomy::svg::clean::clean_svg(bytes)))
}
/// Runs the operation `op` that needs the session's sheet.
pub fn call_with_sheet(sheet: &LoadedSheet, op: &str, input: &str) -> String {
render(crate::ops::on_sheet(sheet, op, input).unwrap_or_else(|| Err(unknown(op))))