Files
faunosteo/packages/core-wasm/src/outcome.ts
T
bchanot 6d1cce6e06 feat(app): R4.3b/c import worker, client, controller; HomeRoute on the disposable worker
Protocol v1 (task → ready → result | failed with phase and kind), the worker entry with
the glue bundled statically and the page's compiled Module posted, the file streamed into
the module's memory; client with start and task timers (paused while hidden), settle-once,
terminate always, error events never masked; module-level controller (one import at a
time, cancel on leaving Home, worker chunk prefetched once the engine is loaded); the
settlement mapped to the B.1.8 messages (OD-5: a trap, a timeout or an unreadable file is
« Erreur de lecture du PDF. », never a corrupt PDF). HomeRoute keeps its routing and size
pre-checks, loads its own index after acceptance, drops a result when the session changed.
Tests: handler and client in-process, the corpus message test (O8 51, O7 stored inputs,
O2/O3/Step 5), the six existing suites migrated to the real worker logic.
2026-10-18 18:10:42 +02:00

32 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')
}
}