Consumers now fed by the core (crates/core through @faunosteo/core-wasm):
- the sheet: the bundled payload is parsed and indexed by the core
(SheetHandle, SheetIndexData); SheetIndex reads precomputed tables only;
- the store: new report, add / remove / move observation, draft restore
(v2 migration + rebase) through the core, actions answering { ok };
- the editor click chain (zone.click), laterality and vertebra pickers
(zone.add_sides, vertebra.initial / sync / select), the findings picker
(finding.toggle by clicked leaf position), zone removal;
- the import: engine byte scan (TypeScript until R4), then the core's
layered reading and rebase in one call; the export: the core builds the
sheet snapshot, the frozen TypeScript engine writes the PDF (R4).
Lazy core: Home and the new-report form read the sheet availability from
the bundle and load the module on import / submit only; the auth shell
never references it. Degraded states (core_unavailable, invalid_sheet)
show the validated notice with a retry and never redirect or touch the
draft; an unreadable draft or archive is set aside under
osteo:quarantine:* (only content kinds; a failed write keeps it in place
and the editor stays), a rebase that flags items keeps the raw pre-rebase
draft. Four strings, wording validated by the owner.
Deleted: services/zoneInteraction.ts and its suite (13 cases ported to
cargo), the TypeScript Finding builder and vertebra selection rules of the
pickers, store rules, persistence parsing, hydrateReport. ESLint forbids
@faunosteo/domain in apps/app/src; the report:compare CLI keeps the frozen
domain until R4 (scripts/compare/sheet.ts). App suite 313/313 on the real
core (24 new tests: quarantine, degraded editor, core failures, N-1
reader); step6 goldens and the frozen envelopes unchanged.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { z } from 'zod'
|
|
import type { Practitioner } from '@faunosteo/core-wasm/types'
|
|
|
|
/**
|
|
* Prefill of the practitioner form (D-R7: form validation stays TypeScript, the core is
|
|
* not loaded on the new-report page): the cached value is used only when it still has the
|
|
* shape of the report's practitioner (name required, the rest optional text).
|
|
*/
|
|
const CachedPractitionerSchema: z.ZodType<Practitioner> = z.object({
|
|
name: z.string().min(1),
|
|
cabinet: z.string().optional(),
|
|
contact: z.string().optional(),
|
|
siret: z.string().optional(),
|
|
})
|
|
|
|
const STORAGE_KEY = 'osteo:lastPractitioner'
|
|
|
|
export function readCachedPractitioner(): Practitioner | undefined {
|
|
if (typeof localStorage === 'undefined') return undefined
|
|
const raw = localStorage.getItem(STORAGE_KEY)
|
|
if (!raw) return undefined
|
|
try {
|
|
const data = JSON.parse(raw)
|
|
const parsed = CachedPractitionerSchema.safeParse(data)
|
|
return parsed.success ? parsed.data : undefined
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
export function writeCachedPractitioner(practitioner: Practitioner): void {
|
|
if (typeof localStorage === 'undefined') return
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(practitioner))
|
|
}
|
|
|
|
export function clearPractitionerCache(): void {
|
|
if (typeof localStorage === 'undefined') return
|
|
localStorage.removeItem(STORAGE_KEY)
|
|
}
|