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.
- Bundled
Pack - A pack the bundle holds. In JSON its release is flat:
{"pack", "version", "integrity", "trust", "modules"}. - Folder
Store - A folder of kept releases.
- Frames
- The frames’ build: its folder,
frames/<hash>/. - Frames
Hash - 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.
- Host
Packs - The bundle’s packs, then the store’s, as
compmd::host::Packs, with the policy and the ambient packs the bundle’s configuration made, so a document processed in Rust is held to what the page’s path holds it to (hosting, decision 7). It shares the bundle and the store, which the host keeps, so the processor, which keeps its packs while it processes, can be given it. - 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.
- Refusal
- A refused request: its status, and why, which the answer says in plain text to any origin.
- Stored
Release - A release a store holds.
Enums§
- Bundle
Error - What is wrong with a bundle.
- Manifest
Error - What is wrong with a
manifest.json. - Route
- What a request asks for: a file of the frames, a pack’s file, or nothing the host serves.
- 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-streamfor any other. - refusal_
headers - The headers of a refusal: plain text, readable from any origin, so a page reads why.
- refused
- The answer refusing a request for
refusal’s reason: its status, why in plain text, and the contract’s headers, so any origin reads it. An adapter’s own refusal, such as having no bundle, is answered with it too. - 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, fromstore; a405for another method thanGET; a404for anything else. Each refusal says why. - route
- What a
methodrequest forpathasks for, from a bundle whose frames’ hash ishash. - served_
headers - The headers of the file at
path, served: its type, by its extension, and those that sandbox it.