refactor(pdf): R4.8 the TypeScript PDF engine leaves: packages/pdf, pdf-lib, the TS CLI and import path, the oracle generators deleted; test read-back on an own reader of the writer's files (pdfFile.ts), view goldens from the session's SVGs, import helper on the module's reader, N-1 scanner exported by core-wasm/n-1; app no longer depends on @faunosteo/domain; r4.census suite

This commit is contained in:
bchanot committed 2026-10-19 12:17:01 +02:00
1 parent 77e11a53e4
commit 0dc1ba27c7
96 files changed
+743 -15769

No files matched your search

-88
View File
@@ -1,88 +0,0 @@
import type { ArchiveImport } from '@faunosteo/core-wasm/types'
import {
ArchiveReadError,
readAttachedDocument,
type ArchiveReadErrorKind,
} from '@faunosteo/pdf'
import type { SheetIndex } from '@/services/sheetIndex'
export { MAX_ATTACHMENT_BYTES, MAX_PDF_BYTES } from '@faunosteo/pdf'
/**
* `lone_surrogate`: the attachment escapes a lone UTF-16 surrogate, which the
* core cannot read without altering it (L1): refused, the file untouched.
* `invalid_copy`: a file offered as a rescue copy that this build cannot read.
*/
export type ImportErrorKind =
| ArchiveReadErrorKind
| 'core_unavailable'
| 'lone_surrogate'
| 'invalid_copy'
/**
* Localization-agnostic import error. Carries a kind discriminant + an
* optional foundVersion so the caller (UI layer) can resolve the
* user-facing message via the active i18n dict.
*/
export class ImportError extends Error {
constructor(
public readonly kind: ImportErrorKind,
public readonly foundVersion?: number | null,
) {
super(kind)
this.name = 'ImportError'
}
}
/**
* 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 readAttachment(pdfBytes: Uint8Array): Promise<unknown> {
try {
return await readAttachedDocument(pdfBytes)
} catch (err) {
if (err instanceof ArchiveReadError) {
throw new ImportError(err.kind, err.foundVersion)
}
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`,
* a text the core would alter `lone_surrogate`, 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 'lone_surrogate':
throw new ImportError('lone_surrogate')
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)
}