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,4 +1,4 @@
|
||||
import type { Branding, ImageAsset } from '@faunosteo/domain'
|
||||
import type { Branding, ImageAsset } from '@faunosteo/core-wasm/types'
|
||||
import headerLogoDataUrl from '@/assets/brand/faunosteo-logo-horizontal-512.png?inline'
|
||||
import footerLogoDataUrl from '@/assets/brand/faunosteo-horizontal-com-512.png?inline'
|
||||
import poweredByLogoDataUrl from '@/assets/brand/zenquality-logo-fr.png?inline'
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { buildSheetSnapshot, type Report } from '@faunosteo/domain'
|
||||
import type { Report } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
defaultPdfLabels,
|
||||
exportReportArchive,
|
||||
type ExportInput,
|
||||
type ExportWarning,
|
||||
} from '@faunosteo/pdf'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
@@ -20,19 +21,24 @@ export interface PdfExportResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the report as an archive PDF through the engine: the loaded sheet
|
||||
* becomes the snapshot the pages are drawn from and the attachment carries,
|
||||
* the branding comes from the bundled logos, the browser rasterises the
|
||||
* views. Warnings are logged and returned for the caller to surface.
|
||||
* Exports the report as an archive PDF through the engine: the core builds
|
||||
* the snapshot of the loaded sheet the pages are drawn from and the
|
||||
* attachment carries (R2), the branding comes from the bundled logos, the
|
||||
* browser rasterises the views, the TypeScript engine writes the file (the
|
||||
* writer moves to the core at R4). The core's report and snapshot are the
|
||||
* same JSON contracts the engine's Zod types describe. Warnings are logged
|
||||
* and returned for the caller to surface.
|
||||
*/
|
||||
export async function exportReportToPdf(
|
||||
report: Report,
|
||||
index: SheetIndex,
|
||||
opts: PdfExportOptions,
|
||||
): Promise<PdfExportResult> {
|
||||
const snapshot = index.ops.snapshot(report)
|
||||
if (!snapshot.ok) throw new Error(`snapshot failed: ${snapshot.kind}`)
|
||||
const result = await exportReportArchive({
|
||||
report,
|
||||
sheet: buildSheetSnapshot(index.sheet, report),
|
||||
report: report as ExportInput['report'],
|
||||
sheet: snapshot.value as ExportInput['sheet'],
|
||||
branding: await loadBranding(),
|
||||
labels: defaultPdfLabels,
|
||||
locale: opts.locale,
|
||||
|
||||
+42
-11
@@ -1,13 +1,14 @@
|
||||
import type { ArchiveReadOutcome, ReportMigrationMap } from '@faunosteo/domain'
|
||||
import type { ArchiveImport } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
ArchiveReadError,
|
||||
readReportArchive,
|
||||
readAttachedDocument,
|
||||
type ArchiveReadErrorKind,
|
||||
} from '@faunosteo/pdf'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
|
||||
export { MAX_PDF_BYTES } from '@faunosteo/pdf'
|
||||
|
||||
export type ImportErrorKind = ArchiveReadErrorKind
|
||||
export type ImportErrorKind = ArchiveReadErrorKind | 'core_unavailable'
|
||||
|
||||
/**
|
||||
* Localization-agnostic import error. Carries a kind discriminant + an
|
||||
@@ -25,17 +26,13 @@ export class ImportError extends Error {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a Faunosteo PDF back through the engine: the report (v3 as is, v2
|
||||
* migrated through the sheet's map) and, when the file is a Step 6 archive,
|
||||
* the validated envelope or the reason its snapshot was dropped. Engine
|
||||
* Step 1, no core needed: the JSON a Faunosteo PDF carries, located by the
|
||||
* engine's byte scan (BLK-009; the scanner moves to the core at R4). Engine
|
||||
* failures become ImportError kinds, one to one.
|
||||
*/
|
||||
export async function importReportFromPdf(
|
||||
pdfBytes: Uint8Array,
|
||||
map: ReportMigrationMap,
|
||||
): Promise<ArchiveReadOutcome> {
|
||||
export async function readAttachment(pdfBytes: Uint8Array): Promise<unknown> {
|
||||
try {
|
||||
return await readReportArchive(pdfBytes, map)
|
||||
return await readAttachedDocument(pdfBytes)
|
||||
} catch (err) {
|
||||
if (err instanceof ArchiveReadError) {
|
||||
throw new ImportError(err.kind, err.foundVersion)
|
||||
@@ -43,3 +40,37 @@ export async function importReportFromPdf(
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 2, in the core on the loaded sheet: the layered reading of the
|
||||
* attachment (report first, v2 migrated through the sheet's map, then the
|
||||
* envelope kept or its snapshot dropped with a reason) and the rebase onto
|
||||
* that sheet. An unknown numeric report version is `incompatible_version`,
|
||||
* any other unreadable content `no_attachment`, as the engine reported them.
|
||||
*/
|
||||
export function importAttachment(
|
||||
attachment: unknown,
|
||||
index: SheetIndex,
|
||||
): ArchiveImport {
|
||||
const outcome = index.ops.importArchive(attachment)
|
||||
if (outcome.ok) return outcome.value
|
||||
switch (outcome.kind) {
|
||||
case 'incompatible_version':
|
||||
throw new ImportError('incompatible_version', outcome.found ?? null)
|
||||
case 'no_attachment':
|
||||
throw new ImportError('no_attachment')
|
||||
case 'core_unavailable':
|
||||
case 'internal':
|
||||
throw new ImportError('core_unavailable')
|
||||
default:
|
||||
throw new Error(`import failed: ${outcome.kind}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Both steps on a sheet already loaded in the core. */
|
||||
export async function importReportFromPdf(
|
||||
pdfBytes: Uint8Array,
|
||||
index: SheetIndex,
|
||||
): Promise<ArchiveImport> {
|
||||
return importAttachment(await readAttachment(pdfBytes), index)
|
||||
}
|
||||
Reference in new issue
Block a user