Skip to main content

Crate compmd_host

Crate compmd_host 

Source
Expand description

compmd-host: what every host of CompMD documents shares, whatever its platform (hosting, decision 1).

A host builds a bundle before anyone reads (@compmd/vite, or buildBundle): the sandbox’s frames under a content hash, the packs it installs by their place, and a manifest.json describing it all. This crate reads that bundle (Bundle, Manifest), keeps the packs it fetches later in a Store, and answers requests for both with respond, the serving contract every adapter puts behind its origin: a Tauri scheme, an Electron protocol, a web server’s route.

use compmd_host::{respond, Bundle, NoStore};

let bundle = Bundle::from_files([
    ("manifest.json", br#"{"format": 1, "frames": {"hash": "1df336e75685de8c"}}"#.to_vec()),
    ("frames/1df336e75685de8c/strict.html", b"<!doctype html>".to_vec()),
])?;
let request = http::Request::get("/frames/1df336e75685de8c/strict.html").body(())?;
let response = respond(&bundle, &NoStore, &request);
assert_eq!(response.status(), http::StatusCode::OK);

With the processor feature, [HostPacks] gives the processor (compmd) the same packs the frames load. Packs, releases, places and integrities are compmd-pack’s types, re-exported here as pack, the same the processor uses.

Re-exports§

pub use compmd_pack as pack;

Structs§

Bundle
A bundle the host serves.
BundledPack
A pack the bundle holds. In JSON its release is flat: {"pack", "version", "integrity", "trust", "modules"}.
FolderStore
A folder of kept releases.
Frames
The frames’ build: its folder, frames/<hash>/.
FramesHash
A frames’ build’s hash: the first 16 hex digits, lowercase, of a SHA-256 over each file’s path and bytes, so it can’t name another folder.
Library
A library the frames offer: an npm package the app installs, which needn’t be scoped (d3).
Manifest
A bundle’s manifest.
NoStore
No store: the host serves the bundle’s packs alone.
StoredRelease
A release a store holds.

Enums§

BundleError
What is wrong with a bundle.
Files
A bundle’s files, each by its path in the bundle, its parts joined by /.
ManifestError
What is wrong with a manifest.json.
Trust
The trust a configuration gives a pack (spec §15).

Constants§

FORMAT
The manifest’s format this crate reads; a bundle of another is refused, with what to upgrade.
MANIFEST
The manifest’s path in a bundle.

Traits§

Store
Where a host keeps packs beyond the bundle.

Functions§

content_type
The type of the file at path, by its extension; application/octet-stream for any other.
respond
The answer to request: the frames’ file or pack file it names, from the bundle or, for a pack the bundle doesn’t hold, from store; a 405 for another method than GET; a 404 for anything else. Each refusal says why.