feat(workspace): R2.4 core runtime — lazy load, poison on trap, offline re-instantiation, per-generation sheet handles
packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready; a WebAssembly.RuntimeError poisons the instance, the call answers internal, a fresh instance comes from the kept compiled module and a glue record imported in advance; at most 3 recoveries per page; retry after a load failure), SheetSession (handle rebuilt per instance generation, never called on a dropped one; invalid_sheet without poisoning), Node source. crates/wasm: SheetHandle (sheet held in the module memory). Two builds: pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap tests; BUILD_STAMP (hash of the Rust sources) refused when missing or stale by the vitest global setup instead of skipping. Failure envelope carries a numeric found version; compact JS-number output.
This commit is contained in:
1 parent
22fea8736d
commit
343d6f4c1f
22 files changed
+783
-180
No files matched your search
+29
-3
@@ -1,8 +1,10 @@
|
||||
//! wasm-bindgen facade over `faunosteo-core` (review III.3): JSON strings in and out, closed
|
||||
//! outcome kinds. Built by `scripts/wasm-build.sh` into `packages/core-wasm/pkg`; loaded
|
||||
//! lazily by the application from R2 on (never at R0).
|
||||
//! outcome kinds. Built by `scripts/wasm-build.sh` into `packages/core-wasm/pkg` (shipped)
|
||||
//! and `packages/core-wasm/pkg-proofs` (with the trap exports, tests only); loaded lazily by
|
||||
//! the application behind the sheet and import paths (`packages/core-wasm/src/runtime.ts`).
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
use faunosteo_core::domain::sheet::LoadedSheet;
|
||||
use wasm_bindgen::prelude::{JsError, wasm_bindgen};
|
||||
|
||||
/// Version of the core compiled into this module.
|
||||
#[wasm_bindgen]
|
||||
@@ -17,6 +19,30 @@ pub fn call(op: &str, input: &str) -> String {
|
||||
faunosteo_core::facade::call(op, input)
|
||||
}
|
||||
|
||||
/// The session's anatomical sheet, held in the module's memory and built once from the
|
||||
/// bundled payload, so the per-action calls carry only the observation or the report.
|
||||
#[wasm_bindgen]
|
||||
pub struct SheetHandle {
|
||||
sheet: LoadedSheet,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl SheetHandle {
|
||||
/// Loads the bundled sheet payload; throws an `Error` whose message is
|
||||
/// `invalid_sheet: <detail>` when the payload, the document or the map is refused.
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(bundle: &str) -> Result<SheetHandle, JsError> {
|
||||
faunosteo_core::facade::load_sheet(bundle)
|
||||
.map(|sheet| SheetHandle { sheet })
|
||||
.map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail)))
|
||||
}
|
||||
|
||||
/// Runs one operation on this sheet; same envelope as `call`.
|
||||
pub fn call(&self, op: &str, input: &str) -> String {
|
||||
faunosteo_core::facade::call_with_sheet(&self.sheet, op, input)
|
||||
}
|
||||
}
|
||||
|
||||
/// R0 proof: on wasm32 a panic is a trap (panic = abort), reaching JavaScript as a
|
||||
/// `WebAssembly.RuntimeError`; the caller re-instantiates the module.
|
||||
#[cfg(feature = "proofs")]
|
||||
|
||||
Reference in new issue
Block a user