feat(domain): V1-2.2 wasm facade, contract types, module proofs

PreviewBuilder, PreviewSheet and clean_svg on the browser module, the
31 ts-rs types and their index, the glue interface, and the proofs on
the shipped module; the module stays under its 600 KB budget.
This commit is contained in:
bchanot committed 2026-10-29 13:14:22 +01:00
1 parent cf37aa265a
commit 8ae756534c
37 files changed
+558

No files matched your search

+80
View File
@@ -4,6 +4,7 @@
//! the application behind the sheet and import paths (`packages/core-wasm/src/runtime.ts`).
use faunosteo_core::domain::sheet::LoadedSheet;
use faunosteo_core::domain::sheet::preview::PreviewDrawing;
use faunosteo_core::pdf::read::MAX_PDF_BYTES;
use wasm_bindgen::prelude::{JsError, wasm_bindgen};
@@ -63,6 +64,85 @@ impl SheetHandle {
}
}
/// A stored sheet version being gathered for preview (V1-2.2, contract §10): the page adds
/// each downloaded drawing with the sha256 of its row, then builds the `PreviewSheet` from
/// the version's status, document text and stored fingerprint. The bytes are copied once
/// into the module's memory by the glue; nothing is read before `build`.
#[wasm_bindgen]
pub struct PreviewBuilder {
drawings: Vec<PreviewDrawing>,
}
#[wasm_bindgen]
impl PreviewBuilder {
#[wasm_bindgen(constructor)]
pub fn new() -> PreviewBuilder {
PreviewBuilder {
drawings: Vec::new(),
}
}
pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) {
self.drawings.push(PreviewDrawing {
asset_id: asset_id.to_owned(),
sha256: sha256.to_owned(),
bytes: bytes.to_vec(),
});
}
/// Consumes the builder; throws an `Error` worded `<kind>: <detail>` (`invalid_document`,
/// `drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`, or
/// `invalid_shape` / `invalid_json` for the input).
pub fn build(self, input: &str) -> Result<PreviewSheet, JsError> {
faunosteo_core::facade::load_preview(input, self.drawings)
.map(|sheet| PreviewSheet { sheet })
.map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail)))
}
}
impl Default for PreviewBuilder {
fn default() -> Self {
Self::new()
}
}
/// A stored version loaded for the catalogue, the admin preview and the editor: no report
/// migration map, never a report session.
#[wasm_bindgen]
pub struct PreviewSheet {
sheet: faunosteo_core::domain::sheet::preview::PreviewSheet,
}
#[wasm_bindgen]
impl PreviewSheet {
/// `preview.state` or `view.canvas`; the envelope of `call`.
pub fn call(&self, op: &str, input: &str) -> String {
faunosteo_core::facade::call_with_preview(&self.sheet, op, input)
}
/// A draft's document after an edit; the drawings are not read again.
pub fn replace_document(&mut self, text: &str) -> String {
faunosteo_core::facade::replace_preview_document(&mut self.sheet, text)
}
/// A drawing uploaded while the draft is open.
pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) -> String {
let drawing = PreviewDrawing {
asset_id: asset_id.to_owned(),
sha256: sha256.to_owned(),
bytes: bytes.to_vec(),
};
faunosteo_core::facade::add_preview_drawing(&mut self.sheet, drawing)
}
}
/// The cleaning answer for a file picked for upload (contract §9.2): the envelope of `call`
/// with an `SvgCleaning` value.
#[wasm_bindgen]
pub fn clean_svg(bytes: &[u8]) -> String {
faunosteo_core::facade::clean_svg(bytes)
}
/// The incremental PDF export (R4.6, plan §B.1.4, OD-2): the application opens a session on
/// its `ExportInput` JSON, then alternates `next()` (the rasters the next step needs) with
/// `add_raster` or `raster_failed` per key, and closes with `finish()`. Every answer is the