feat(app): R2 switch — the application runs its domain rules in the Rust core
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.
This commit is contained in:
1 parent
794dfd9d0b
commit
74fcb37564
65 files changed
+2227
-1678
No files matched your search
@@ -1,11 +1,109 @@
|
||||
import type { SheetIndex as DomainSheetIndex } from '@faunosteo/domain'
|
||||
import type { LoadedSheet } from '@/sheets/provider'
|
||||
import type {
|
||||
Annotation,
|
||||
AnatomicalSheetDocument,
|
||||
FindingZone,
|
||||
LocalizedText,
|
||||
ObservableAnnotation,
|
||||
SheetIndexData,
|
||||
SheetRef,
|
||||
SheetStatus,
|
||||
SheetView,
|
||||
VertebralRegion,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
import type { SheetOps } from '@/core/sheetOps'
|
||||
|
||||
/**
|
||||
* The sheet index lives in @faunosteo/domain since Step 6 (shared with the
|
||||
* PDF engine). This shim keeps the app's import path and binds the index to
|
||||
* the sheet the app loads, so `index.sheet` still carries the migration map.
|
||||
* The loaded sheet as React reads it (R2). Every lookup table is computed once by the
|
||||
* core (`SheetIndexData`): positions by id with the TypeScript `Map` semantics (last
|
||||
* duplicate wins), names, spine ids and the finding paths that exist. This class only reads
|
||||
* them, so no render calls the core; the sheet-bound rules go through `ops`.
|
||||
*/
|
||||
export { buildSheetIndex, isObservable, pickLabel } from '@faunosteo/domain'
|
||||
export type { ObservableAnnotation } from '@faunosteo/domain'
|
||||
export type SheetIndex = DomainSheetIndex<LoadedSheet>
|
||||
|
||||
export type { ObservableAnnotation }
|
||||
|
||||
/** What the screens read about the loaded sheet. */
|
||||
export interface LoadedSheetView {
|
||||
status: SheetStatus
|
||||
ref: SheetRef
|
||||
speciesId: string
|
||||
schemaVersion: number
|
||||
/** The document as the core parsed it (defaults filled in). */
|
||||
document: AnatomicalSheetDocument
|
||||
/** SVG text by `svg_asset_id` (the canvas draws them until R3). */
|
||||
assets: Readonly<Record<string, string>>
|
||||
}
|
||||
|
||||
function at<T>(
|
||||
list: readonly T[],
|
||||
positions: Readonly<Record<string, number>>,
|
||||
id: string,
|
||||
): T | undefined {
|
||||
return Object.hasOwn(positions, id) ? list[positions[id]!] : undefined
|
||||
}
|
||||
|
||||
export function isObservable(
|
||||
a: Annotation | undefined,
|
||||
): a is ObservableAnnotation {
|
||||
return a !== undefined && a.kind !== 'detail_trigger'
|
||||
}
|
||||
|
||||
export class SheetIndex {
|
||||
readonly sheet: LoadedSheetView
|
||||
/** The first `main` view of the document. */
|
||||
readonly mainViewId: string
|
||||
private readonly spine: ReadonlySet<string>
|
||||
private readonly nodes: ReadonlySet<string>
|
||||
|
||||
constructor(
|
||||
private readonly data: SheetIndexData,
|
||||
assets: Readonly<Record<string, string>>,
|
||||
readonly ops: SheetOps,
|
||||
) {
|
||||
const { document } = data
|
||||
this.sheet = {
|
||||
status: data.status,
|
||||
ref: data.ref,
|
||||
speciesId: data.speciesId,
|
||||
schemaVersion: data.schemaVersion,
|
||||
document,
|
||||
assets,
|
||||
}
|
||||
this.mainViewId = data.mainViewId
|
||||
this.spine = new Set(data.spineIds)
|
||||
this.nodes = new Set(data.nodeKeys)
|
||||
}
|
||||
|
||||
view(id: string): SheetView | undefined {
|
||||
return at(this.data.document.views, this.data.viewById, id)
|
||||
}
|
||||
|
||||
annotation(id: string): Annotation | undefined {
|
||||
return at(this.data.document.annotations, this.data.annotationById, id)
|
||||
}
|
||||
|
||||
findingZone(id: string): FindingZone | undefined {
|
||||
return at(this.data.document.finding_zones, this.data.findingZoneById, id)
|
||||
}
|
||||
|
||||
regions(): VertebralRegion[] {
|
||||
return this.data.document.vertebral_config.regions
|
||||
}
|
||||
|
||||
/** Whether an annotation opens the vertebra picker. */
|
||||
isSpine(annotationId: string): boolean {
|
||||
return this.spine.has(annotationId)
|
||||
}
|
||||
|
||||
/** The name the sheet gives an annotation (a trigger: its own or its view's). */
|
||||
name(annotation: Annotation): LocalizedText {
|
||||
const names = this.data.names
|
||||
return Object.hasOwn(names, annotation.id)
|
||||
? names[annotation.id]!
|
||||
: { fr: '', en: '' }
|
||||
}
|
||||
|
||||
/** Whether the finding zone holds this category or node path. */
|
||||
hasNode(zoneId: string, path: readonly string[]): boolean {
|
||||
return this.nodes.has(JSON.stringify([zoneId, ...path]))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user