feat(domain): R2.2 report migration, rebase, sheet snapshot and layered archive reading in Rust; draft restore and archive import operations
migrateReportV2ToV3 / readReportDocument (version read on the raw value, JS truthiness kept, a malformed mapped path still fails the read), rebaseReportOnSheet (??= labels, archived names first-match), buildSheetSnapshot / assertSnapshot (raw depth, shape, caps in UTF-16 and UTF-8, integrity), readArchiveDocument (layered: report first, wrapper, snapshot gate, sheet invariant, unsupported_envelope origin quirk). Checked against 84 cases frozen from the TypeScript and 765 Zod verdicts (one declared difference: L1, a lone surrogate reads as U+FFFD), the ported report and archive suites and the 612 legacy leaves. Facade: draft.restore (content kinds invalid / unsupported_version, rebase_failed never a content kind), archive.import (incompatible_version with found, no_attachment), archive.snapshot.
This commit is contained in:
1 parent
6c0533c1da
commit
21906c4358
28 files changed
+5239
-213
No files matched your search
@@ -7,10 +7,12 @@ use serde_json::Value;
|
||||
#[cfg(feature = "ts")]
|
||||
use ts_rs::TS;
|
||||
|
||||
use crate::domain::archive::build_sheet_snapshot;
|
||||
use crate::domain::editor::{
|
||||
self, EditorError, LeafClick, MoveDirection, NewReportDraft, NewReportStamp, VertebraAction,
|
||||
};
|
||||
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::facade::{Failure, parse_input, to_value};
|
||||
|
||||
@@ -209,6 +211,9 @@ pub fn on_sheet(sheet: &LoadedSheet, op: &str, input: &str) -> Option<Outcome> {
|
||||
"vertebra.initial" => vertebra_initial(sheet, input),
|
||||
"vertebra.sync" => vertebra_sync(sheet, input),
|
||||
"finding.toggle" => finding_toggle(sheet, input),
|
||||
"draft.restore" => draft_restore(sheet, input),
|
||||
"archive.import" => archive_import(sheet, input),
|
||||
"archive.snapshot" => archive_snapshot(sheet, input),
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -274,3 +279,60 @@ fn finding_toggle(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
.map_err(editor_failure)
|
||||
.and_then(|observation| to_value(&observation))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DraftRestoreInput {
|
||||
/// The raw text of the tab's draft.
|
||||
pub draft: String,
|
||||
/// The raw text of the session's archive envelope, when one is stored.
|
||||
pub archive: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[cfg_attr(feature = "ts", derive(TS), ts(export))]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SnapshotInput {
|
||||
pub report: Report,
|
||||
}
|
||||
|
||||
/// A failure that names the document version a reader refused.
|
||||
fn versioned(kind: &'static str, found: Option<f64>) -> Failure {
|
||||
Failure {
|
||||
found,
|
||||
..Failure::new(kind, "")
|
||||
}
|
||||
}
|
||||
|
||||
/// Content kinds (`invalid`, `unsupported_version`) mean the draft itself is unreadable:
|
||||
/// the caller sets it aside. `rebase_failed` is a defect of the loaded sheet, never of the
|
||||
/// draft, and leaves it where it is.
|
||||
fn draft_restore(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
let input: DraftRestoreInput = parse_input(input)?;
|
||||
session::restore_draft(sheet, &input.draft, input.archive.as_deref())
|
||||
.map_err(|failure| match failure {
|
||||
RestoreFailure::UnsupportedVersion(found) => versioned("unsupported_version", found),
|
||||
RestoreFailure::Invalid(detail) => Failure::new("invalid", detail),
|
||||
RestoreFailure::Rebase(detail) => Failure::new("rebase_failed", detail),
|
||||
})
|
||||
.and_then(|restore| to_value(&restore))
|
||||
}
|
||||
|
||||
/// The input is the attachment's JSON as the byte scan read it (any shape).
|
||||
fn archive_import(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
session::import_archive(sheet, input)
|
||||
.map_err(|failure| match failure {
|
||||
ImportFailure::IncompatibleVersion(found) => {
|
||||
versioned("incompatible_version", Some(found))
|
||||
}
|
||||
ImportFailure::NoAttachment => Failure::new("no_attachment", ""),
|
||||
ImportFailure::Invalid(detail) => Failure::new("invalid", detail),
|
||||
})
|
||||
.and_then(|import| to_value(&import))
|
||||
}
|
||||
|
||||
fn archive_snapshot(sheet: &LoadedSheet, input: &str) -> Outcome {
|
||||
let input: SnapshotInput = parse_input(input)?;
|
||||
to_value(&build_sheet_snapshot(sheet, &input.report))
|
||||
}
|
||||
Reference in new issue
Block a user