feat(domain): R2.2 report migration, rebase, sheet snapshot and layered archive reading in Rust; draft restore and archive import operations
migrateReportV2ToV3 / readReportDocument (version read on the raw value, JS truthiness kept, a malformed mapped path still fails the read), rebaseReportOnSheet (??= labels, archived names first-match), buildSheetSnapshot / assertSnapshot (raw depth, shape, caps in UTF-16 and UTF-8, integrity), readArchiveDocument (layered: report first, wrapper, snapshot gate, sheet invariant, unsupported_envelope origin quirk). Checked against 84 cases frozen from the TypeScript and 765 Zod verdicts (one declared difference: L1, a lone surrogate reads as U+FFFD), the ported report and archive suites and the 612 legacy leaves. Facade: draft.restore (content kinds invalid / unsupported_version, rebase_failed never a content kind), archive.import (incompatible_version with found, no_attachment), archive.snapshot.
This commit is contained in:
1 parent
6c0533c1da
commit
21906c4358
28 files changed
+5239
-213
No files matched your search
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* The TypeScript types generated from the Rust contracts (ts-rs, `../types`) against the
|
||||
* output types of the Zod schemas they replace (the frozen N-1 copy): optional, nullable,
|
||||
* required and literal attributes, field by field. Checked by `tsc` (`pnpm typecheck`);
|
||||
* `expectTypeOf` is a no-op at run time.
|
||||
*/
|
||||
import { expectTypeOf } from 'vitest'
|
||||
import type { z } from 'zod'
|
||||
import type {
|
||||
BrandingSchema,
|
||||
FindingSchema,
|
||||
ObservationSchema,
|
||||
PdfLabelSetSchema,
|
||||
ReportArchiveEnvelopeSchema,
|
||||
ReportSchema,
|
||||
ReportZoneSchema,
|
||||
SheetRefSchema,
|
||||
SheetSnapshotSchema,
|
||||
} from './n-1/domain'
|
||||
import type {
|
||||
Branding,
|
||||
Finding,
|
||||
Observation,
|
||||
PdfLabelSet,
|
||||
Report,
|
||||
ReportArchiveEnvelope,
|
||||
ReportZone,
|
||||
SheetRef,
|
||||
SheetSnapshot,
|
||||
} from '../types'
|
||||
|
||||
describe('ts-rs contract types', () => {
|
||||
it('equal the Zod output types of the report', () => {
|
||||
expectTypeOf<Report>().toEqualTypeOf<z.output<typeof ReportSchema>>()
|
||||
expectTypeOf<Observation>().toEqualTypeOf<
|
||||
z.output<typeof ObservationSchema>
|
||||
>()
|
||||
expectTypeOf<ReportZone>().toEqualTypeOf<
|
||||
z.output<typeof ReportZoneSchema>
|
||||
>()
|
||||
expectTypeOf<Finding>().toEqualTypeOf<z.output<typeof FindingSchema>>()
|
||||
expectTypeOf<SheetRef>().toEqualTypeOf<z.output<typeof SheetRefSchema>>()
|
||||
})
|
||||
|
||||
it('equal the Zod output types of the archive parts', () => {
|
||||
expectTypeOf<Branding>().toEqualTypeOf<z.output<typeof BrandingSchema>>()
|
||||
expectTypeOf<PdfLabelSet>().toEqualTypeOf<
|
||||
z.output<typeof PdfLabelSetSchema>
|
||||
>()
|
||||
})
|
||||
|
||||
// The sheet document inside a snapshot is a union of one object per annotation kind in
|
||||
// Zod and one object with a `kind: 'point' | 'zone'` field in Rust: same values, another
|
||||
// form. The snapshot and the envelope are therefore checked for mutual assignability.
|
||||
it('are mutually assignable with the snapshot and the envelope', () => {
|
||||
type ZodSnapshot = z.output<typeof SheetSnapshotSchema>
|
||||
type ZodEnvelope = z.output<typeof ReportArchiveEnvelopeSchema>
|
||||
expectTypeOf<SheetSnapshot>().toMatchTypeOf<ZodSnapshot>()
|
||||
expectTypeOf<ZodSnapshot>().toMatchTypeOf<SheetSnapshot>()
|
||||
expectTypeOf<ReportArchiveEnvelope>().toMatchTypeOf<ZodEnvelope>()
|
||||
expectTypeOf<ZodEnvelope>().toMatchTypeOf<ReportArchiveEnvelope>()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ArchiveReadOutcome } from "./ArchiveReadOutcome";
|
||||
import type { RebaseOutcome } from "./RebaseOutcome";
|
||||
|
||||
/**
|
||||
* An imported attachment read and rebased onto the loaded sheet.
|
||||
*/
|
||||
export type ArchiveImport = { read: ArchiveReadOutcome, rebase: RebaseOutcome, };
|
||||
@@ -0,0 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type ArchiveOrigin = "envelope_v1" | "bare_v3" | "v2";
|
||||
@@ -0,0 +1,22 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { ArchiveOrigin } from "./ArchiveOrigin";
|
||||
import type { Report } from "./Report";
|
||||
import type { ReportArchiveEnvelope } from "./ReportArchiveEnvelope";
|
||||
import type { SnapshotRejection } from "./SnapshotRejection";
|
||||
|
||||
/**
|
||||
* What an attachment gave back: always the report, the envelope when accepted.
|
||||
*/
|
||||
export type ArchiveReadOutcome = { report: Report, origin: ArchiveOrigin, migrated: boolean,
|
||||
/**
|
||||
* From the v2 migration; 0 for a v3 report.
|
||||
*/
|
||||
unresolvedZones: number, unresolvedFindings: number,
|
||||
/**
|
||||
* The validated envelope, when accepted.
|
||||
*/
|
||||
archive: ReportArchiveEnvelope | null,
|
||||
/**
|
||||
* Envelope present but dropped, with the reason.
|
||||
*/
|
||||
snapshotRejected?: SnapshotRejection, };
|
||||
@@ -0,0 +1,16 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { RebaseOutcome } from "./RebaseOutcome";
|
||||
import type { ReportArchiveEnvelope } from "./ReportArchiveEnvelope";
|
||||
|
||||
/**
|
||||
* A restored draft: the rebase outcome carries the report the store opens.
|
||||
*/
|
||||
export type DraftRestore = { rebase: RebaseOutcome,
|
||||
/**
|
||||
* The session's archive envelope, when one was stored and still parses.
|
||||
*/
|
||||
archive: ReportArchiveEnvelope | null,
|
||||
/**
|
||||
* An archive text was stored but no longer parses (the caller sets it aside).
|
||||
*/
|
||||
archiveRejected: boolean, };
|
||||
@@ -0,0 +1,11 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type DraftRestoreInput = {
|
||||
/**
|
||||
* The raw text of the tab's draft.
|
||||
*/
|
||||
draft: string,
|
||||
/**
|
||||
* The raw text of the session's archive envelope, when one is stored.
|
||||
*/
|
||||
archive: string | null, };
|
||||
@@ -0,0 +1,15 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Report } from "./Report";
|
||||
|
||||
/**
|
||||
* The report as v3 and what the migration could not place (0 for a v3 document).
|
||||
*/
|
||||
export type MigrationOutcome = { report: Report,
|
||||
/**
|
||||
* Zones whose legacy id has no annotation in the map.
|
||||
*/
|
||||
unresolvedZones: number,
|
||||
/**
|
||||
* Findings whose legacy path no longer exists in the sheet.
|
||||
*/
|
||||
unresolvedFindings: number, };
|
||||
@@ -0,0 +1,8 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Report } from "./Report";
|
||||
|
||||
export type RebaseOutcome = { report: Report,
|
||||
/**
|
||||
* Zones and findings newly flagged by this rebase.
|
||||
*/
|
||||
unresolvedZones: number, unresolvedFindings: number, rebased: boolean, };
|
||||
@@ -0,0 +1,4 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
import type { Report } from "./Report";
|
||||
|
||||
export type SnapshotInput = { report: Report, };
|
||||
@@ -0,0 +1,6 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
/**
|
||||
* Why an imported snapshot (or its envelope) is dropped; the import reports it.
|
||||
*/
|
||||
export type SnapshotRejection = "unsupported_envelope" | "schema" | "caps" | "integrity" | "sheet_mismatch";
|
||||
@@ -6,6 +6,9 @@ export type { AnatomicalSheetDocument } from './AnatomicalSheetDocument'
|
||||
export type { Animal } from './Animal'
|
||||
export type { AnnotationCategory } from './AnnotationCategory'
|
||||
export type { Annotation } from './Annotation'
|
||||
export type { ArchiveImport } from './ArchiveImport'
|
||||
export type { ArchiveOrigin } from './ArchiveOrigin'
|
||||
export type { ArchiveReadOutcome } from './ArchiveReadOutcome'
|
||||
export type { Attribution } from './Attribution'
|
||||
export type { Branding } from './Branding'
|
||||
export type { Circle } from './Circle'
|
||||
@@ -13,6 +16,8 @@ export type { CountRange } from './CountRange'
|
||||
export type { Credit } from './Credit'
|
||||
export type { DetailTriggerAnnotation } from './DetailTriggerAnnotation'
|
||||
export type { DetailView } from './DetailView'
|
||||
export type { DraftRestoreInput } from './DraftRestoreInput'
|
||||
export type { DraftRestore } from './DraftRestore'
|
||||
export type { FindingCategoryKind } from './FindingCategoryKind'
|
||||
export type { FindingCategory } from './FindingCategory'
|
||||
export type { FindingNode } from './FindingNode'
|
||||
@@ -28,6 +33,7 @@ export type { Locale } from './Locale'
|
||||
export type { LocalizedOptionalText } from './LocalizedOptionalText'
|
||||
export type { LocalizedText } from './LocalizedText'
|
||||
export type { MainView } from './MainView'
|
||||
export type { MigrationOutcome } from './MigrationOutcome'
|
||||
export type { MoveDirection } from './MoveDirection'
|
||||
export type { MoveObservationInput } from './MoveObservationInput'
|
||||
export type { NewReportDraft } from './NewReportDraft'
|
||||
@@ -47,6 +53,7 @@ export type { PngAsset } from './PngAsset'
|
||||
export type { Point } from './Point'
|
||||
export type { Polygon } from './Polygon'
|
||||
export type { Practitioner } from './Practitioner'
|
||||
export type { RebaseOutcome } from './RebaseOutcome'
|
||||
export type { Reference } from './Reference'
|
||||
export type { ReferenceType } from './ReferenceType'
|
||||
export type { ReportArchiveEnvelope } from './ReportArchiveEnvelope'
|
||||
@@ -66,6 +73,8 @@ export type { SheetSnapshotRef } from './SheetSnapshotRef'
|
||||
export type { SheetSnapshot } from './SheetSnapshot'
|
||||
export type { SheetStatus } from './SheetStatus'
|
||||
export type { SheetView } from './SheetView'
|
||||
export type { SnapshotInput } from './SnapshotInput'
|
||||
export type { SnapshotRejection } from './SnapshotRejection'
|
||||
export type { SvgAsset } from './SvgAsset'
|
||||
export type { VertebraAction } from './VertebraAction'
|
||||
export type { VertebralConfig } from './VertebralConfig'
|
||||
|
||||
Reference in new issue
Block a user