Skip to main content

plexus_substrate/activations/mustache/
types.rs

1//! Mustache activation types
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7/// Information about a registered template
8#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
9pub struct TemplateInfo {
10    /// Unique template ID
11    pub id: String,
12    /// Plugin that owns this template
13    pub plugin_id: Uuid,
14    /// Method this template is for
15    pub method: String,
16    /// Template name (e.g., "default", "compact", "verbose")
17    pub name: String,
18    /// When the template was created (Unix timestamp)
19    pub created_at: i64,
20    /// When the template was last updated (Unix timestamp)
21    pub updated_at: i64,
22}
23
24/// Error type for Mustache operations
25#[derive(Debug, Clone, Serialize, Deserialize, thiserror::Error)]
26pub enum MustacheError {
27    #[error("Template not found: {0}")]
28    TemplateNotFound(String),
29
30    #[error("Storage error: {0}")]
31    StorageError(String),
32
33    #[error("Render error: {0}")]
34    RenderError(String),
35
36    #[error("Invalid template: {0}")]
37    InvalidTemplate(String),
38}
39
40impl From<String> for MustacheError {
41    fn from(s: String) -> Self {
42        MustacheError::StorageError(s)
43    }
44}
45
46impl From<&str> for MustacheError {
47    fn from(s: &str) -> Self {
48        MustacheError::StorageError(s.to_string())
49    }
50}
51
52/// Events from mustache operations
53#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
54#[serde(tag = "type", rename_all = "snake_case")]
55pub enum MustacheEvent {
56    /// Template rendered successfully
57    Rendered {
58        /// The rendered output
59        output: String,
60    },
61
62    /// Template registered successfully
63    Registered {
64        /// Template info
65        template: TemplateInfo,
66    },
67
68    /// Template retrieved
69    Template {
70        /// The template content
71        template: String,
72    },
73
74    /// Template not found
75    NotFound {
76        /// Description of what was not found
77        message: String,
78    },
79
80    /// List of templates
81    Templates {
82        /// The templates
83        templates: Vec<TemplateInfo>,
84    },
85
86    /// Template deleted
87    Deleted {
88        /// Number of templates deleted
89        count: usize,
90    },
91
92    /// Error occurred
93    Error {
94        /// Error message
95        message: String,
96    },
97}