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:
1 parent
77e11a53e4
commit
0dc1ba27c7
96 files changed
+743
-15769
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import type { ArchiveImport } from '@faunosteo/core-wasm/types'
|
||||
import { coreRuntime } from '@/core/runtime'
|
||||
import { ImportError, pdfImportOf } from '@/core/worker/outcome'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { bundledSheet } from './sheet'
|
||||
|
||||
export { ImportError }
|
||||
|
||||
/**
|
||||
* The application's PDF import, in-process for the tests (R4.8, the TypeScript scanner
|
||||
* gone): the module's reader (`SheetHandle.import_pdf`, R4.2) on a handle of the bundled
|
||||
* sheet, its envelope mapped as HomeRoute maps the worker's settlement (`pdfImportOf`). The
|
||||
* page never runs the reader on its main instance (OD-1: the import worker does, on a
|
||||
* handle of its own); these helpers give the tests the same reading, same kinds, without a
|
||||
* worker thread. The route suites cover the worker itself.
|
||||
*/
|
||||
export async function importReportFromPdf(
|
||||
bytes: Uint8Array,
|
||||
): Promise<ArchiveImport> {
|
||||
const bundle = JSON.stringify(await bundledSheet())
|
||||
const runtime = coreRuntime()
|
||||
if (!(await runtime.ready())) throw new ImportError('core_unavailable')
|
||||
const out = runtime.invoke<string>((glue) => {
|
||||
const handle = new glue.SheetHandle(bundle)
|
||||
try {
|
||||
return { ok: true, value: handle.import_pdf(bytes) }
|
||||
} finally {
|
||||
handle.free()
|
||||
}
|
||||
})
|
||||
if (!out.ok) throw new ImportError('core_unavailable', null, out.kind)
|
||||
return pdfImportOf({
|
||||
kind: 'result',
|
||||
out: out.value,
|
||||
diag: { ms: 0, linearBytes: null, chunks: 0 },
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* The core's layered reading of an attachment already parsed (`archive.import` on the
|
||||
* loaded sheet): the v3 report as is, a v2 migrated through the sheet's map, the envelope
|
||||
* kept or its snapshot dropped with a reason, then the rebase onto that sheet. The kinds
|
||||
* are the worker's.
|
||||
*/
|
||||
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':
|
||||
case 'lone_surrogate':
|
||||
throw new ImportError(outcome.kind)
|
||||
default:
|
||||
throw new ImportError('core_unavailable', null, outcome.kind)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user