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.
24//! Packs, releases, places and integrities are `compmd-pack`'s types, re-exported here as [`pack`], the same the
25//! processor uses.
26//!
27//! [hosting]: https://github.com/comp-markdown/compmd/blob/main/docs/hosting.md
28
29/// The names packs and their files are known by.
30pub use compmd_pack as pack;
31
32mod bundle;
33mod bundle_error;
34mod bundled_pack;
35mod content_type;
36mod files;
37mod folder_store;
38mod frames;
39mod frames_hash;
40mod headers;
41mod library;
42mod manifest;
43mod manifest_error;
44mod no_store;
45#[cfg(feature = "processor")]
46mod packs;
47mod refusal;
48mod respond;
49mod route;
50mod store;
51mod stored_release;
52mod trust;
53
54pub use bundle::{Bundle, MANIFEST};
55pub use bundle_error::BundleError;
56pub use bundled_pack::BundledPack;
57pub use content_type::content_type;
58pub use folder_store::FolderStore;
59pub use frames::Frames;
60pub use frames_hash::FramesHash;
61pub use headers::{refusal_headers, served_headers};
62pub use library::Library;
63pub use manifest::{FORMAT, Manifest};
64pub use manifest_error::ManifestError;
65pub use no_store::NoStore;
66#[cfg(feature = "processor")]
67pub use packs::HostPacks;
68pub use refusal::Refusal;
69pub use respond::{refused, respond};
70pub use route::{Route, route};
71pub use store::Store;
72pub use stored_release::StoredRelease;
73pub use trust::Trust;