feat(app): export and import through @faunosteo/pdf — snapshot, archived branding and labels, browser rasterizer, imported archive kept in session, explicit rebase with messages; legacy PDF modules removed
This commit is contained in:
1 parent
20dafc0b00
commit
9bd5173a9c
43 files changed
+1492
-1989
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
ReportV2Schema,
|
||||
findingPathKey,
|
||||
type ArchiveReadOutcome,
|
||||
type Finding,
|
||||
type FindingV2,
|
||||
type MigrationOutcome,
|
||||
type ObservationZoneV2,
|
||||
type Report,
|
||||
type ReportZone,
|
||||
@@ -15,7 +15,8 @@ import { pickLabel, type SheetIndex } from '../../src/services/sheetIndex'
|
||||
* Pure comparison of a report document found in a PDF with its v3 reading:
|
||||
* a v2 archive is shown legacy id → canonical id line by line, a v3 report
|
||||
* is checked against the bundled sheet. Every item the sheet cannot place is
|
||||
* marked `!! UNRESOLVED` with the reason, nothing is summarised away.
|
||||
* marked `!! UNRESOLVED` with the reason, nothing is summarised away. A Step 6
|
||||
* envelope adds one header line saying whether its snapshot was kept.
|
||||
*/
|
||||
|
||||
export const UNRESOLVED = '!! UNRESOLVED'
|
||||
@@ -186,13 +187,22 @@ function observationLines(
|
||||
return lines
|
||||
}
|
||||
|
||||
/** The report document inside the attachment: the envelope's, or the bare one. */
|
||||
function reportDataOf(raw: unknown): unknown {
|
||||
const isEnvelope =
|
||||
typeof raw === 'object' &&
|
||||
raw !== null &&
|
||||
typeof (raw as { envelopeVersion?: unknown }).envelopeVersion === 'number'
|
||||
return isEnvelope ? (raw as { report: unknown }).report : raw
|
||||
}
|
||||
|
||||
function migratedObservationLines(
|
||||
raw: unknown,
|
||||
report: Report,
|
||||
sheet: SheetIndex,
|
||||
opts: CompareOptions,
|
||||
): string[][] {
|
||||
const v2 = ReportV2Schema.parse(raw)
|
||||
const v2 = ReportV2Schema.parse(reportDataOf(raw))
|
||||
return v2.observations.map((legacy, i) => {
|
||||
const out = report.observations[i]!
|
||||
const severity = legacy.severity
|
||||
@@ -230,12 +240,22 @@ function countsOf(report: Report): Counts {
|
||||
}
|
||||
}
|
||||
|
||||
/** The envelope line: present only when the attachment was an archive. */
|
||||
function archiveLine(outcome: ArchiveReadOutcome): string[] {
|
||||
if (outcome.archive) return ['archive v1 (snapshot kept)']
|
||||
if (outcome.snapshotRejected) {
|
||||
return [`archive v1 (snapshot rejected: ${esc(outcome.snapshotRejected)})`]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
function headerLines(
|
||||
source: 'v2' | 'v3',
|
||||
report: Report,
|
||||
outcome: ArchiveReadOutcome,
|
||||
sheet: SheetIndex,
|
||||
opts: CompareOptions,
|
||||
): string[] {
|
||||
const { report } = outcome
|
||||
const ref = sheet.sheet.ref
|
||||
const sameSheet =
|
||||
report.sheet.sheetId === ref.sheetId &&
|
||||
@@ -246,6 +266,7 @@ function headerLines(
|
||||
const c = countsOf(report)
|
||||
const lines = [
|
||||
source === 'v2' ? 'v2 → v3 (migrated)' : 'v3 (read as is)',
|
||||
...archiveLine(outcome),
|
||||
sheetLine,
|
||||
`id ${esc(report.id)} · date ${esc(report.date)} · ${c.observations} observations · ${c.zones} zones (${c.unresolvedZones} unresolved) · ${c.findings} findings (${c.unresolvedFindings} unresolved)`,
|
||||
]
|
||||
@@ -273,17 +294,17 @@ function footerLines(report: Report, full: boolean): string[] {
|
||||
}
|
||||
|
||||
/**
|
||||
* `raw` is the attachment as found in the PDF, `outcome` its v3 reading
|
||||
* (`readReportDocument`); `migrated` tells which vocabulary the lines use.
|
||||
* `raw` is the attachment as found in the PDF (bare report or envelope),
|
||||
* `outcome` its layered reading (`readArchiveDocument`); `outcome.migrated`
|
||||
* tells which vocabulary the lines use.
|
||||
*/
|
||||
export function compareReport(
|
||||
raw: unknown,
|
||||
outcome: MigrationOutcome,
|
||||
migrated: boolean,
|
||||
outcome: ArchiveReadOutcome,
|
||||
sheet: SheetIndex,
|
||||
opts: CompareOptions,
|
||||
): Comparison {
|
||||
const { report } = outcome
|
||||
const { report, migrated } = outcome
|
||||
const source = migrated ? 'v2' : 'v3'
|
||||
const v3Lines = report.observations.map((o) =>
|
||||
observationLines(o, sheet, opts),
|
||||
@@ -295,7 +316,7 @@ export function compareReport(
|
||||
]
|
||||
return {
|
||||
source,
|
||||
header: headerLines(source, report, sheet, opts),
|
||||
header: headerLines(source, outcome, sheet, opts),
|
||||
observations: migrated
|
||||
? migratedObservationLines(raw, report, sheet, opts)
|
||||
: v3Lines,
|
||||
|
||||
Reference in new issue
Block a user