1#[allow(
13 clippy::too_many_arguments,
14 clippy::same_length_and_capacity,
15 reason = "generated by wit_bindgen"
16)]
17pub mod bindings {
18 wit_bindgen::generate!({
19 path: "wit",
20 world: "plugin",
21 generate_all,
22 pub_export_macro: true,
23 default_bindings_module: "moonlit_pdk::bindings",
24 });
25}
26
27pub use bindings::export;
28
29pub use moonlit_pdk_macros::moonlit_plugin;
30
31mod result;
32pub use result::MiddlewareResult;
33
34pub mod config;
35
36mod context;
37pub use context::{Context, Host, LogLevel};
38
39#[cfg(target_arch = "wasm32")]
40mod real_host;
41#[cfg(target_arch = "wasm32")]
42pub use real_host::RealHost;
43
44pub mod env;
45
46pub mod process;
47
48pub mod state;
49
50pub mod http;
51
52pub mod clock;
53
54pub mod random;
55
56pub mod testing;
57
58mod middleware;
59pub use middleware::Middleware;
60
61#[doc(hidden)]
67#[must_use]
68pub fn __schema_json<T: schemars::JsonSchema>() -> String {
69 serde_json::to_string(&schemars::schema_for!(T)).unwrap_or_default()
70}
71
72#[derive(serde::Deserialize, Default, schemars::JsonSchema)]
76pub struct NoInput {}
77
78#[derive(serde::Serialize, schemars::JsonSchema)]
81pub struct NoOutput {}
82
83mod plugin_config;
84pub use plugin_config::PluginConfig;
85
86pub mod prelude {
87 pub use crate::PluginConfig;
88 pub use crate::config::from_json_value;
89 pub use crate::moonlit_plugin;
90 pub use crate::process::LineHandler;
91 pub use crate::state::Shared;
92 pub use crate::{Context, LogLevel, Middleware, MiddlewareResult, NoInput, NoOutput};
93 pub use serde::{Deserialize, Serialize};
94}
95
96#[cfg(test)]
97mod markers {
98 use super::NoInput;
99
100 #[test]
103 fn no_input_deserializes_from_an_empty_object() {
104 serde_json::from_str::<NoInput>("{}").expect("NoInput binds from an empty object");
105 }
106}
107
108#[cfg(test)]
109mod wit_abi {
110 #[test]
114 fn crate_doc_states_the_shipped_abi_version() {
115 let wit = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("wit/moonlit-plugin.wit");
116 let text = std::fs::read_to_string(wit).unwrap();
117 let abi = text
118 .lines()
119 .find_map(|l| l.trim().strip_prefix("package "))
120 .expect("WIT declares a package")
121 .trim()
122 .trim_end_matches(';');
123
124 let doc: String = include_str!("lib.rs")
125 .lines()
126 .take_while(|l| l.starts_with("//!"))
127 .collect::<Vec<_>>()
128 .join("\n");
129
130 assert!(
131 doc.contains(abi),
132 "moonlit-pdk's crate doc must name the shipped ABI `{abi}`. It currently reads:\n{doc}"
133 );
134 }
135}