Skip to main content

compmd_host/
lib.rs

1//! `compmd-host`: what every host of [CompMD](https://compmd.dev/) documents shares, whatever its platform
2//! ([hosting], decision 1).
3//!
4//! A host builds a **bundle** before anyone reads (`@compmd/vite`, or `buildBundle`): the sandbox's frames under a
5//! content hash, the packs it installs by their place, and a `manifest.json` describing it all. This crate reads that
6//! bundle ([`Bundle`], [`Manifest`]), keeps the packs it fetches later in a [`Store`], and answers requests for both
7//! with [`respond`], the serving contract every adapter puts behind its origin: a Tauri scheme, an Electron protocol,
8//! a web server's route.
9//!
10//! ```
11//! use compmd_host::{respond, Bundle, NoStore};
12//!
13//! let bundle = Bundle::from_files([
14//!     ("manifest.json", br#"{"format": 1, "frames": {"hash": "1df336e75685de8c"}}"#.to_vec()),
15//!     ("frames/1df336e75685de8c/strict.html", b"<!doctype html>".to_vec()),
16//! ])?;
17//! let request = http::Request::get("/frames/1df336e75685de8c/strict.html").body(())?;
18//! let response = respond(&bundle, &NoStore, &request);
19//! assert_eq!(response.status(), http::StatusCode::OK);
20//! # Ok::<(), Box<dyn std::error::Error>>(())
21//! ```
22//!
23//! With the `processor` feature, [`HostPacks`] gives the processor (`compmd`) the same packs the frames load. With the
24//! `registry` feature, [`registry`] has the registry rules: resolving packs from registries, as a state machine the
25//! host drives with its own I/O.
26//! Packs, releases, places and integrities are `compmd-pack`'s types, re-exported here as [`pack`], the same the
27//! processor uses.
28//!
29//! [hosting]: https://github.com/comp-markdown/compmd/blob/main/docs/hosting.md
30
31/// The names packs and their files are known by.
32pub use compmd_pack as pack;
33
34mod bundle;
35mod bundle_error;
36mod bundled_pack;
37#[cfg(feature = "processor")]
38mod chained_packs;
39mod content_type;
40mod fetched_by;
41mod files;
42mod folder_store;
43mod frames;
44mod frames_hash;
45mod headers;
46mod library;
47mod manifest;
48mod manifest_error;
49mod no_store;
50#[cfg(feature = "processor")]
51mod packs;
52mod refusal;
53#[cfg(feature = "registry")]
54pub mod registry;
55mod respond;
56mod route;
57mod store;
58mod stored_release;
59mod trust;
60
61pub use bundle::{Bundle, MANIFEST};
62pub use bundle_error::BundleError;
63pub use bundled_pack::BundledPack;
64#[cfg(feature = "processor")]
65pub use chained_packs::ChainedPacks;
66pub use content_type::content_type;
67pub use fetched_by::FetchedBy;
68pub use folder_store::FolderStore;
69pub use frames::Frames;
70pub use frames_hash::FramesHash;
71pub use headers::{refusal_headers, served_headers};
72pub use library::Library;
73pub use manifest::{FORMAT, Manifest};
74pub use manifest_error::ManifestError;
75pub use no_store::NoStore;
76#[cfg(feature = "processor")]
77pub use packs::HostPacks;
78pub use refusal::Refusal;
79pub use respond::{refused, respond};
80pub use route::{Route, route};
81pub use store::Store;
82pub use stored_release::StoredRelease;
83pub use trust::Trust;