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:
1 parent
ac71c5b662
commit
64a43840ce
21 files changed
+5204
-17
No files matched your search
+109
-10
@@ -16,7 +16,14 @@ use crate::domain::editor::{
|
||||
use crate::domain::js::parse_json;
|
||||
use crate::domain::report::{LateralSide, Observation, Report, SheetRef, Vertebra};
|
||||
use crate::domain::session::{self, ImportFailure, RestoreFailure};
|
||||
use crate::domain::sheet::{LoadedSheet, SheetIndexData, check_sheet_document};
|
||||
use crate::domain::sheet::edit::{Dependent, EditCommand, apply_edit, dependents};
|
||||
use crate::domain::sheet::keys::ElementKey;
|
||||
use crate::domain::sheet::loaded::Drawing;
|
||||
use crate::domain::sheet::preview::PreviewSheet;
|
||||
use crate::domain::sheet::verdict::MAX_DOCUMENT_TEXT_BYTES;
|
||||
use crate::domain::sheet::{
|
||||
AnatomicalSheetDocument, LoadedSheet, SheetIndexData, check_sheet_document,
|
||||
};
|
||||
use crate::facade::{Failure, parse_input, to_value};
|
||||
use crate::pdf::json_js::{MAX_JSON_VALUES, prescan};
|
||||
|
||||
@@ -103,6 +110,8 @@ pub fn free(op: &str, input: &str) -> Option<Outcome> {
|
||||
"report.remove_observation" => report_remove(input),
|
||||
"report.move_observation" => report_move(input),
|
||||
"vertebra.select" => vertebra_select(input),
|
||||
"sheet.edit" => sheet_edit(input),
|
||||
"sheet.dependents" => sheet_dependents(input),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -114,6 +123,63 @@ fn sheet_check(input: &str) -> Outcome {
|
||||
to_value(&check)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SheetEditInput {
|
||||
pub document: AnatomicalSheetDocument,
|
||||
pub command: EditCommand,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
pub struct SheetEditOutput {
|
||||
pub document: AnatomicalSheetDocument,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SheetDependentsInput {
|
||||
pub document: AnatomicalSheetDocument,
|
||||
pub key: ElementKey,
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
pub struct SheetDependents {
|
||||
pub dependents: Vec<Dependent>,
|
||||
}
|
||||
|
||||
/// A sheet input the core reads: the document's own bound with room for the command, and
|
||||
/// the OD-3 value budget, before the parser allocates its tree.
|
||||
fn sheet_input<T: serde::de::DeserializeOwned>(input: &str) -> Result<T, Failure> {
|
||||
if input.len() > MAX_DOCUMENT_TEXT_BYTES + MAX_COMMAND_BYTES || over_value_budget(input) {
|
||||
return Err(Failure::new(
|
||||
"too_large",
|
||||
"the input is over the size budget",
|
||||
));
|
||||
}
|
||||
parse_input(input)
|
||||
}
|
||||
|
||||
/// Room for a command beside the document (an inserted zone with its whole tree).
|
||||
const MAX_COMMAND_BYTES: usize = 2 * 1024 * 1024;
|
||||
|
||||
fn sheet_edit(input: &str) -> Outcome {
|
||||
let input: SheetEditInput = sheet_input(input)?;
|
||||
let document = apply_edit(&input.document, input.command)
|
||||
.map_err(|error| Failure::new(error.kind(), ""))?;
|
||||
to_value(&SheetEditOutput { document })
|
||||
}
|
||||
|
||||
fn sheet_dependents(input: &str) -> Outcome {
|
||||
let input: SheetDependentsInput = sheet_input(input)?;
|
||||
to_value(&SheetDependents {
|
||||
dependents: dependents(&input.document, &input.key),
|
||||
})
|
||||
}
|
||||
|
||||
fn report_new(input: &str) -> Outcome {
|
||||
let input: NewReportInput = parse_input(input)?;
|
||||
let stamp = NewReportStamp {
|
||||
@@ -386,20 +452,31 @@ pub const MAX_COMPOSED_BYTES: usize = 4 * 1024 * 1024;
|
||||
|
||||
fn view_canvas(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
let input: CanvasViewInput = parse_input(input)?;
|
||||
let document = &sheet.document;
|
||||
if !document.views.iter().any(|v| v.id() == input.view_id) {
|
||||
return Err(Failure::new("unknown_view", &input.view_id));
|
||||
canvas_of(&sheet.document, &input.view_id, |asset| {
|
||||
sheet.drawing(asset)
|
||||
})
|
||||
}
|
||||
|
||||
/// The canvas of `view_id` on `document`, its drawings looked up by asset id: the one
|
||||
/// composition of the report editor's sheet and of a previewed version.
|
||||
fn canvas_of<'a>(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
drawing_of: impl Fn(&str) -> Option<&'a Drawing>,
|
||||
) -> Outcome {
|
||||
if !document.views.iter().any(|v| v.id() == view_id) {
|
||||
return Err(Failure::new("unknown_view", view_id));
|
||||
}
|
||||
let asset_id = asset_id_of_view(document, &input.view_id)
|
||||
.ok_or_else(|| Failure::new("no_asset", &input.view_id))?;
|
||||
let drawing = match sheet.drawing(asset_id) {
|
||||
let asset_id =
|
||||
asset_id_of_view(document, view_id).ok_or_else(|| Failure::new("no_asset", view_id))?;
|
||||
let drawing = match drawing_of(asset_id) {
|
||||
None => return Err(Failure::new("no_asset", asset_id)),
|
||||
Some(Err(reason)) => return Err(Failure::new("svg_rejected", reason)),
|
||||
Some(Ok(drawing)) => drawing,
|
||||
};
|
||||
let canvas = compose_canvas(document, &input.view_id, drawing).map_err(|e| match e {
|
||||
ComposeError::UnknownView => Failure::new("unknown_view", &input.view_id),
|
||||
ComposeError::InvalidCharacter => Failure::new("invalid_character", &input.view_id),
|
||||
let canvas = compose_canvas(document, view_id, drawing).map_err(|e| match e {
|
||||
ComposeError::UnknownView => Failure::new("unknown_view", view_id),
|
||||
ComposeError::InvalidCharacter => Failure::new("invalid_character", view_id),
|
||||
})?;
|
||||
let svg = serialize(&canvas);
|
||||
if svg.len() > MAX_COMPOSED_BYTES {
|
||||
@@ -407,3 +484,25 @@ fn view_canvas(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
}
|
||||
to_value(&CanvasView { svg })
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Previewed versions (V1-2.2, contract §10)
|
||||
|
||||
/// Runs an operation on a previewed version; `None` when `op` is not one of them.
|
||||
pub fn on_preview(preview: &PreviewSheet, op: &str, input: &str) -> Option<Outcome> {
|
||||
Some(match op {
|
||||
"preview.state" => preview
|
||||
.state()
|
||||
.map_err(|_| Failure::new("internal", "a review group has no digest"))
|
||||
.and_then(|state| to_value(&state)),
|
||||
"view.canvas" => preview_canvas(preview, input),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
fn preview_canvas(preview: &PreviewSheet, input: &str) -> Outcome {
|
||||
let input: CanvasViewInput = parse_input(input)?;
|
||||
canvas_of(preview.document(), &input.view_id, |asset| {
|
||||
preview.drawing(asset)
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user