Skip to main content

dpp_plugin_traits/
plugin.rs

1//! [`DppSectorPlugin`] — the trait every sector plugin implements.
2
3use crate::error::PluginError;
4use crate::meta::{PluginCapabilities, PluginMeta};
5use crate::result::PluginResult;
6
7/// Raw JSON input passed from the host to a plugin entry point.
8pub type PluginInput = serde_json::Value;
9
10/// The entry points every sector plugin must export.
11///
12/// The Wasm host calls these after deserialising JSON sector data from the
13/// passport payload. Implementations must be deterministic and free of I/O.
14pub trait DppSectorPlugin: Send + Sync {
15    /// Returns static metadata about this plugin.
16    fn meta(&self) -> PluginMeta;
17
18    /// Returns the plugin's capability declaration for version negotiation.
19    fn capabilities(&self) -> PluginCapabilities;
20
21    /// Validate the structure and field constraints of the sector input.
22    ///
23    /// Returns `Ok(())` if the input is structurally valid, or a descriptive
24    /// error if a required field is missing or out of range. Prefer
25    /// `PluginError::ValidationErrors` with per-field detail over
26    /// `PluginError::InvalidInput` for better error reporting.
27    fn validate_input(&self, input: &PluginInput) -> Result<(), PluginError>;
28
29    /// Compute compliance metrics from the sector input.
30    ///
31    /// May return `None` for fields that do not apply to this sector.
32    fn calculate_metrics(&self, input: &PluginInput) -> Result<PluginResult, PluginError>;
33
34    /// Generate a passport-ready sector data JSON payload.
35    ///
36    /// Applies any normalisation or enrichment required by the sector schema
37    /// (e.g. rounding, unit conversion). The output is stored verbatim in the DPP.
38    fn generate_passport(&self, input: &PluginInput) -> Result<serde_json::Value, PluginError>;
39}