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.
125 lines
3.4 KiB
TypeScript
125 lines
3.4 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { resolve } from 'node:path'
|
|
import type { LocalizedText } from '@faunosteo/core-wasm/types'
|
|
|
|
/**
|
|
* The legacy catalog as the application's archive knew it: every leaf of the
|
|
* generated baseline (`legacy-import/document.json`) becomes a Report v2
|
|
* finding, grouped in one observation per zone. Mirrors the anatomy package
|
|
* helper of the same name; both read the committed seed, never a copy. The
|
|
* baseline is read as its authoring form (leaves carry no `children` key);
|
|
* the core reads the v2 report built from it.
|
|
*/
|
|
|
|
const BASELINE = resolve(
|
|
fileURLToPath(import.meta.url),
|
|
'../../../../../supabase/seed/anatomical-sheets/equine/legacy-import/document.json',
|
|
)
|
|
|
|
/** A category or node of the baseline in its authoring form. */
|
|
interface BaselineNode {
|
|
id: string
|
|
name: LocalizedText
|
|
requires_vet_referral?: boolean
|
|
children?: BaselineNode[]
|
|
}
|
|
|
|
export interface LegacyBaseline {
|
|
finding_zones: { id: string; categories: BaselineNode[] }[]
|
|
}
|
|
|
|
export interface LegacyLeaf {
|
|
zoneId: string
|
|
path: string[]
|
|
name: { fr: string; en: string }
|
|
vet: boolean
|
|
}
|
|
|
|
/** A Report v2 document as the deployed application wrote it (input of the migration). */
|
|
export interface ReportV2Fixture {
|
|
version: 2
|
|
id: string
|
|
createdAt: string
|
|
date: string
|
|
practitioner: { name: string }
|
|
animal: { speciesId: string; name: string }
|
|
owner: { name: string }
|
|
observations: {
|
|
id: string
|
|
zones: unknown[]
|
|
findings: {
|
|
zoneId: string
|
|
path: string[]
|
|
labelFrSnapshot: string
|
|
labelEnSnapshot: string
|
|
requiresVetReferral?: true
|
|
}[]
|
|
freeTextFindings: string[]
|
|
comment: string
|
|
}[]
|
|
conclusion: string
|
|
recommendations: string
|
|
}
|
|
|
|
export function loadLegacyBaseline(): LegacyBaseline {
|
|
return JSON.parse(readFileSync(BASELINE, 'utf8')) as LegacyBaseline
|
|
}
|
|
|
|
export function legacyLeaves(doc: LegacyBaseline): LegacyLeaf[] {
|
|
const out: LegacyLeaf[] = []
|
|
const walk = (
|
|
zoneId: string,
|
|
nodes: readonly BaselineNode[],
|
|
prefix: string[],
|
|
) => {
|
|
for (const node of nodes) {
|
|
const path = [...prefix, node.id]
|
|
const children = node.children ?? []
|
|
if (children.length > 0) walk(zoneId, children, path)
|
|
else {
|
|
const vet = node.requires_vet_referral === true
|
|
out.push({ zoneId, path, name: node.name, vet })
|
|
}
|
|
}
|
|
}
|
|
for (const zone of doc.finding_zones) walk(zone.id, zone.categories, [])
|
|
return out
|
|
}
|
|
|
|
export function leavesAsV2Report(leaves: LegacyLeaf[]): ReportV2Fixture {
|
|
const byZone = new Map<string, ReportV2Fixture['observations'][number]>()
|
|
for (const leaf of leaves) {
|
|
let obs = byZone.get(leaf.zoneId)
|
|
if (!obs) {
|
|
obs = {
|
|
id: `obs-${leaf.zoneId}`,
|
|
zones: [],
|
|
findings: [],
|
|
freeTextFindings: [],
|
|
comment: '',
|
|
}
|
|
byZone.set(leaf.zoneId, obs)
|
|
}
|
|
obs.findings.push({
|
|
zoneId: leaf.zoneId,
|
|
path: leaf.path,
|
|
labelFrSnapshot: leaf.name.fr,
|
|
labelEnSnapshot: leaf.name.en || leaf.name.fr,
|
|
...(leaf.vet ? { requiresVetReferral: true as const } : {}),
|
|
})
|
|
}
|
|
return {
|
|
version: 2,
|
|
id: 'all-leaves',
|
|
createdAt: '2026-10-10T00:00:00Z',
|
|
date: '2026-10-10',
|
|
practitioner: { name: 'Synthetic' },
|
|
animal: { speciesId: 'equine', name: 'Synthetic' },
|
|
owner: { name: 'Synthetic' },
|
|
observations: [...byZone.values()],
|
|
conclusion: '',
|
|
recommendations: '',
|
|
}
|
|
}
|