Skip to main content

Crate packdiff_wasm

Crate packdiff_wasm 

Source
Expand description

WASM ABI over packdiff-dto — the comment engine the generated HTML page calls into. Every model mutation and export the browser performs goes through here; the page’s JavaScript is only a view layer.

ABI (no wasm-bindgen, empty import object, works from file://):

  • Strings cross the boundary as (ptr: u32, len: u32) UTF-8 buffers. JS allocates inputs with pd_alloc, writes, calls, then frees them with pd_free.
  • Every API function returns a packed u64 = (ptr << 32) | len naming a fresh UTF-8 buffer the CALLER must free with pd_free after copying.
  • Every returned buffer is a single-key union document (§ house style): { "Ok": <result> } on success or { "Error": { "message": "…" } } on failure. The Ok payload is a document object for mutations and a plain string for exports/keys.

Purity: the module has no clock and no entropy — comment ids and RFC 3339 timestamps come in from JS as part of the comment JSON.

Functions§

pd_alloc
Allocate len bytes for the caller to write an input buffer into.
pd_delete_comment
Delete a comment by id (the id arrives as a plain UTF-8 string, not JSON). Returns the updated document; deleting a missing id is not an error.
pd_export_csv
pd_export_json
pd_export_markdown
pd_free
Free a buffer previously returned by pd_alloc or by any API function.
pd_markdown_html
Render markdown to safe HTML (the subset in packdiff_dto::markdown). The input is the raw markdown text — a plain UTF-8 string, not JSON — and Ok carries the HTML string. Never fails on any input.
pd_merge
Merge an imported document into the current one (union by id, newer updated_at wins). Returns the merged document.
pd_new_document
meta = {"repo": "...", "base": {"name","sha"}, "head": {"name","sha"}}. Returns a fresh empty review document.
pd_parse_document
Parse, validate, and normalize a stored document (the load path).
pd_range_diff
Diff a contiguous commit sub-range from the page’s embedded snapshots. snapshots is a RangeSnapshots JSON; params is {"from": <boundary index>, "to": <boundary index>, "context": N} with from < to (commit k alone is from = k - 1, to = k). Ok carries the FileDiff array — the same shape the build-time parser emits.
pd_storage_key
meta as in pd_new_document; returns the localStorage key string.
pd_upsert_comment
Insert or replace (by id) one comment. Returns the updated document.