/* tslint:disable */ /* eslint-disable */ /** * A proposed fix as shown to the user. The apply logic stays in Rust; JS only * sees this description and passes `index` to `Session.repair`. */ export interface Fix { /** * This fix's handle in `Session.repair`'s `approved` list. **0-based** — it * indexes this array. * * The envelope's [`Data::index`], on a report item, is the same fix's * **1-based** plan position, because that is the handle `epubsana --apply` * takes and the two documents have to agree. Do not pass one where the * other is wanted. */ index: number; /** * `"AutoSafe"` (safe to auto-apply) or `"ConfirmNeeded"` (a visible change). * epubsana's own axis: how much judgement the fix needs. Orthogonal to * `severity`, which describes the *defect*. */ tier: string; /** * The epubcheck-compatible ID this addresses, e.g. `"RSC-016"`. */ id: string; /** * Lowercase severity of the finding this fix clears, **inherited** from * epubveri: `"fatal" | "error" | "warning" | "info" | "usage"`. A fatal is * what stops the book from opening at all. */ severity: string; /** * One-line summary. */ title: string; /** * Why the fix is safe / what the spec says. */ rationale: string; /** * The exact edits it would make. */ preview: Change[]; /** * `"proposed"` until [`Session::repair`] runs; then `"applied"`, * `"skipped"` (not approved) or `"reverted"` (approved, applied, and undone * because it made a finding more frequent). */ outcome: string; /** * For a `"reverted"` fix, the finding whose count applying it raised, as * `"RSC-005 (opf.package.schema_violation)"` — the line the CLI prints. */ reverted_for: string | undefined; } /** * One concrete edit a fix would make (mirrors `epubsana::Change`). */ export interface Change { path: string; note: string; } /** * One edit: the container entry it touches, and what it does there. Mirrors the * CLI's JSON exactly, so a browser consumer and a plugin read the same shape. */ export interface ChangeItem { path: string; note: string; } /** * One fix, in the shared item shape (FORMATS.md §1.3). */ export interface Item { /** * Always `"fix"` for a repairer. */ type: string; /** * `"applied"`, `"skipped"`, `"proposed"` or `"reverted"` — what became of * this fix. * Required on a fix item: a report that cannot say which fixes the user * approved is not a report of what changed. */ outcome: string; /** * epubcheck-compatible message ID this fix addresses, e.g. `"RSC-016"`. */ code: string; /** * epubveri's finer semantic sub-code, when the finding carries one. */ rule: string | undefined; /** * Lowercase severity, inherited from the finding this fix addresses. */ severity: string; /** * Container-relative path the fix touches, when it touches just one. */ location: string | undefined; message: string; data: Data; } /** * Per-input counts, mirroring the envelope's `summary`. * * Including its naming rule, which is written out on `epubsana::envelope::Summary`: * a severity count here is **plural with a tense**, `s_before` / * `s_after`. Do not follow epubveri's singular `summary` keys when * adding one — theirs is a histogram of a single report, these are a repair * run's delta, and mixing the two spellings inside one object is the failure * that note exists to prevent. `Plan::warnings_before` is the shipped * precedent. */ export interface Summary { fatals_before: number; fatals_after: number; errors_before: number; errors_after: number; warnings_before: number; warnings_after: number; infos_before: number; infos_after: number; usages_before: number; usages_after: number; applied: number; skipped: number; /** * Planned and neither applied nor declined — every fix, before * [`Session::repair`] has run. Counted because `outcome` is a closed set * and a summary that reports some of its members disagrees with its own * `items` (conventions #30, rule 1). */ proposed: number; /** * Approved and applied, then undone because applying it made a finding * more frequent, exactly as in the CLI envelope. The identity is the CLI's: * `applied + skipped + proposed + reverted == items.len()`. */ reverted: number; /** * The bar this result was measured against: `"valid"` or `"openable"`. */ goal: string; } /** * The re-validated result — the envelope's `inputs[i]` object without * `path`/`error` (a wasm caller has no path, and in-memory bytes are always * readable, so there is no unprocessable/`"error"` case here). */ export interface Report { /** * `"ok"` (the goal was met) or `"problems"` (it was not). */ status: string; summary: Summary; items: Item[]; } /** * The session's plan: the book's state before repair, and every proposed fix. * * Fatals are counted apart from errors, as epubveri reports them — a book whose * defects are all fatal has `errors_before: 0` and does not even open. */ export interface Plan { fatals_before: number; errors_before: number; warnings_before: number; fixes: Fix[]; } /** * Tool-specific extras: epubsana's tier, and the exact edits. */ export interface Data { /** * This fix's **1-based** position in the plan, mirroring the CLI * envelope's `data.index` — the selector `epubsana --apply` accepts. * * **Not the handle `Session.repair` takes.** That one is [`Fix::index`], * which is 0-based because it indexes the `Plan.fixes` array JS already * holds. The two differ on purpose: this field exists so a report saved * from the browser is the *same document* a plugin gets from the CLI, and * silently re-basing it would make the two disagree. Subtract one to cross * between them. * * It was missing until 2026-08-22 — this struct is hand-written to get a * TypeScript type out of Tsify rather than built on `epubsana::envelope`, * so "keep them in step" (see the module docs) was a comment and not a * mechanism. epubveri hit the identical gap in its own binding on the same * day and told us to look. */ index: number; fix_id: string; tier: string; changes: ChangeItem[]; } /** * A repair session over one EPUB, held in WASM memory across calls. */ export class Session { private constructor(); free(): void; [Symbol.dispose](): void; /** * Load an EPUB from its raw bytes, detect its defects, and plan the fixes. */ static load(bytes: Uint8Array | number[]): Session; /** * The session's plan: the starting counts and every proposed fix (each with * its current `outcome`). Cheap — it re-validates nothing. */ plan(): Plan; /** * Run the repair with the fixes at `approved` (0-based [`Fix::index`] * values) and return the result — **the core's `epubsana::repair`, the * function the CLI runs**, so the same book with the same approvals comes * back identical from both. * * Every approved fix is applied, the book is validated, and a fix that * made any finding more frequent is undone and reported `"reverted"`, * except for findings a fix revealed (see [`Session::revealed`]). A fix not * in `approved` is `"skipped"`, as it is under the CLI's `--apply`. * * Starts from the book as loaded every time, so calling it again with a * different selection replaces the previous run. An index out of range is * an error and changes nothing. */ repair(approved: Uint32Array | number[], goal?: string | null): Report; /** * **Re-validate** the current EPUB with epubveri and return the result in * the shared envelope shape — the same independent check the CLI reports. * `goal` is `"valid"` (the default: no fatals and no errors remain) or * `"openable"` (no fatals remain — the book opens). Before any * [`Session::repair`] every item is `"proposed"` and the book is unchanged. */ report(goal?: string | null): Report; /** * The repaired EPUB's bytes — download these as `_fixed.epub`. */ result_bytes(): Uint8Array; /** * How many findings the last [`Session::repair`] accepted as **revealed**: * always in the book, and visible only once a fix let the validator in — * by making an unreadable document readable, or by correcting a package * version no validator recognises. They were not in the plan, so running * again on [`Session::result_bytes`] can repair some of them. `0` before * any repair. * * Not in the envelope's `summary`, which the conventions own; the CLI * prints the same number as a note after its report. */ revealed(): number; } /** * The version string — the same one the CLI's `-V` and the json envelope's * `tool_version` print, git build metadata included. */ export function version(): string;