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.
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 content_type;
35mod files;
36mod folder_store;
37mod frames_hash;
38mod headers;
39mod manifest;
40mod manifest_error;
41#[cfg(feature = "processor")]
42mod packs;
43mod refusal;
44mod respond;
45mod route;
46mod store;
47
48pub use bundle::{Bundle, MANIFEST};
49pub use bundle_error::BundleError;
50pub use content_type::content_type;
51pub use files::Files;
52pub use folder_store::FolderStore;
53pub use frames_hash::FramesHash;
54pub use headers::{refusal_headers, served_headers};
55pub use manifest::{BundledPack, FORMAT, Frames, Library, Manifest, Trust};
56pub use manifest_error::ManifestError;
57#[cfg(feature = "processor")]
58pub use packs::HostPacks;
59pub use refusal::Refusal;
60pub use respond::respond;
61pub use route::{Route, route};
62pub use store::{NoStore, Store, StoredRelease};