/** * Shared validation context. * * Checkers share XML parsing work through this context. Relationships, * content types, and parsed XML DOMs are parsed at most once and cached. * Every checker consumes from the same cache so they all see identical * parse results (this matters for "rels malformed" propagation — the * malformed entry is reported once, and every downstream checker simply * sees the empty parse result). */ import type { ExtractedFile } from "../../../archive/unzip/extract.js"; import type { XmlDocument, XmlElement } from "../../../xml/types.js"; import type { Reporter } from "./reporter.js"; export interface ContentTypesData { defaults: Map; overrides: Map; /** * `true` if the file was parsed as a `` root successfully. * `false` if the file is missing, malformed or has an unexpected root. */ parseOk: boolean; /** * Duplicate override part names encountered during parse. Emitted as * problems by the content-types checker. */ duplicateOverrides: string[]; } export interface Relationship { id: string; type: string; target: string; targetMode?: string; } export interface RelsData { rels: Relationship[]; byId: Map; parseOk: boolean; /** * Raw rel entries that lacked Id/Type/Target attributes. Emitted * separately so the rels checker can flag them without us dropping * them from the data entirely. */ malformedEntries: Array<{ missingId: boolean; missingType: boolean; missingTarget: boolean; id?: string; type?: string; }>; } export declare class ValidationContext { readonly entries: Map; readonly reporter: Reporter; private readonly textCache; private readonly domCache; private readonly relsCache; private contentTypes?; constructor(entries: Map, reporter: Reporter); /** `true` if `path` points to a file (not a directory) in the package. */ has(path: string): boolean; /** Iterate every file (skip directories). */ files(): IterableIterator; /** Decode a part as UTF-8 text. Cached. */ readText(path: string): string | undefined; /** * Parse a part as XML DOM. Cached. Returns `undefined` if the part is * missing or malformed. Callers that need to distinguish those cases * should check `has(path)` first. */ readDom(path: string, onMalformed?: (err: Error) => void): XmlDocument | undefined; /** * Read and cache the content-types table. On first call, parse * `[Content_Types].xml`; subsequent calls return the cache. * Reports malformed-XML problems via the reporter but never throws. */ readContentTypes(): ContentTypesData; /** * Read and cache a relationships file. Every .rels in the package is * parsed lazily on first request. Malformed files are reported once * and return an empty relationships array. */ readRels(relsPath: string): RelsData; } /** Get the root element of a DOM; returns undefined for missing DOM. */ export declare function domRoot(dom: XmlDocument | undefined): XmlElement | undefined;