Skip to main content

Crate packdiff_dto

Crate packdiff_dto 

Source
Expand description

§packdiff-dto — the data model

This crate is the single source of truth for every piece of data packdiff handles. It is pure logic: no filesystem, no subprocess, no clock, no randomness — those all live in the callers (packdiff-cli natively, packdiff-wasm in the browser). That is what lets the same compiled semantics run on both sides of the tool.

Two document families:

  • diff::DiffDocument — the immutable build artifact: everything the CLI extracted from git (refs, commits, per-file hunks and lines). It is produced once per render and embedded/consumed read-only.
  • review::ReviewDocument — the mutable review state: the comments a human leaves on the page. It lives in the browser’s localStorage, and every mutation (upsert, delete, merge/import) goes through this crate via WASM — the page’s JavaScript never edits the document itself.

Schema rules:

  • JSON field names are snake_case; union variants are CamelCase and encode as single-key objects — { "VariantName": { ...payload } } — with no discriminator field.
  • Every struct strict-rejects unknown fields (deny_unknown_fields): a typo or a drifted producer is a hard, loud error, never a silently ignored key.
  • Both documents carry schema_version (SCHEMA_VERSION). This is the one deliberate opt-in to long-term compatibility (review documents live in users’ localStorage): parsers reject documents from a newer schema than they understand and accept older ones (there is only v1 today, so “accept” means “equal”).
  • Determinism: same inputs → byte-identical outputs. Ordering is always explicit (review::ReviewDocument::sort), timestamps and ids are caller-supplied, and exports are stable.

Modules§

diff
The diff document: what a build extracted from git, plus the parser that turns raw git diff text into typed data.
export
Export renderers for a ReviewDocument: Markdown, CSV, and the canonical JSON. Pure string builders — deterministic given the document (which ReviewDocument::sort keeps in canonical order).
markdown
Minimal, safety-first Markdown → HTML: used for comment bodies and for the rendered view of markdown files on the generated page.
review
The review document: the comments a reviewer leaves on a diff, and every operation that may change them.
snapshot
Commit-boundary file snapshots and the pure line diff over them — what lets the generated page re-diff any contiguous commit sub-range without touching git: the CLI collects contents once, the page (via WASM) calls range_diff with a pair of boundary indices.

Structs§

RefInfo
A named ref pinned to the commit it resolved to at build time.

Enums§

ModelError
Errors surfaced by any model operation. Typed so callers branch on variants; the WASM ABI ships them as { "Error": { "message": ... } }.

Constants§

SCHEMA_VERSION
Version stamped into (and required of) every document this crate touches.
TOOL
Tool identifier stamped into documents.

Functions§

storage_key
The localStorage key a review document is filed under.