feat(domain): sheet.empty free op for a new sheet's document (V1-2.5 C)
Wraps create_empty_sheet_document; refusals invalid_shape / invalid_json; ts-rs SheetEmptyInput, core-wasm proof, app wrapper emptySheetDocument.
This commit is contained in:
1 parent
b0a4cbe588
commit
bbab0e61cb
8 files changed
+159
-4
No files matched your search
+20
-1
@@ -22,7 +22,8 @@ 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,
|
||||
AnatomicalSheetDocument, LoadedSheet, LocalizedText, SheetIndexData, check_sheet_document,
|
||||
create_empty_sheet_document,
|
||||
};
|
||||
use crate::facade::{Failure, parse_input, to_value};
|
||||
use crate::pdf::json_js::{MAX_JSON_VALUES, prescan};
|
||||
@@ -105,6 +106,7 @@ pub struct VertebraSelectInput {
|
||||
pub fn free(op: &str, input: &str) -> Option<Outcome> {
|
||||
Some(match op {
|
||||
"sheet.check" => sheet_check(input),
|
||||
"sheet.empty" => sheet_empty(input),
|
||||
"report.new" => report_new(input),
|
||||
"report.add_observation" => report_add(input),
|
||||
"report.remove_observation" => report_remove(input),
|
||||
@@ -123,6 +125,23 @@ fn sheet_check(input: &str) -> Outcome {
|
||||
to_value(&check)
|
||||
}
|
||||
|
||||
/// A new sheet's starting point (V1-2 contract §7.4): the slug is not part of the document.
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SheetEmptyInput {
|
||||
pub species_id: String,
|
||||
pub name: LocalizedText,
|
||||
}
|
||||
|
||||
/// An empty label is refused by the input's shape, an invalid species id by the document's.
|
||||
fn sheet_empty(input: &str) -> Outcome {
|
||||
let input: SheetEmptyInput = parse_input(input)?;
|
||||
create_empty_sheet_document(&input.species_id, &input.name)
|
||||
.map_err(|error| Failure::new("invalid_shape", error))
|
||||
.and_then(|document| to_value(&document))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(deny_unknown_fields)]
|
||||
|
||||
Reference in new issue
Block a user