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.
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
/**
|
|
* Outcome envelope of every core call (closed kinds, never an exception for content):
|
|
* `{ ok: true, value }` or `{ ok: false, kind, detail?, found? }`. Two kinds come from the
|
|
* runtime itself: `core_unavailable` (the module is not loaded, failed to load or is being
|
|
* re-created after a trap) and `internal` (the call trapped; the instance was dropped).
|
|
*/
|
|
export type CoreOutcome<T> =
|
|
| { ok: true; value: T }
|
|
| { ok: false; kind: string; detail?: string; found?: number }
|
|
|
|
export type CoreFailure = Extract<CoreOutcome<never>, { ok: false }>
|
|
|
|
export const CORE_UNAVAILABLE: CoreFailure = {
|
|
ok: false,
|
|
kind: 'core_unavailable',
|
|
}
|
|
|
|
export function failure(kind: string, detail?: string): CoreFailure {
|
|
return detail === undefined ? { ok: false, kind } : { ok: false, kind, detail }
|
|
}
|
|
|
|
/** Parses the JSON text a core call returned. */
|
|
export function parseOutcome<T>(text: string): CoreOutcome<T> {
|
|
try {
|
|
return JSON.parse(text) as CoreOutcome<T>
|
|
} catch {
|
|
return failure('internal', 'unreadable outcome')
|
|
}
|
|
}
|