1use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7use std::path::PathBuf;
8use thiserror::Error;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub struct ModuleInfo {
13 pub name: String,
15 pub version: String,
17 pub description: Option<String>,
19 pub author: Option<String>,
21 pub capabilities: Vec<String>,
23 pub dependencies: HashMap<String, String>,
25 pub entry_point: String,
27 pub directory: Option<PathBuf>,
29 pub binary_path: Option<PathBuf>,
31 pub config_schema: HashMap<String, String>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37pub enum ModuleSource {
38 Path(PathBuf),
40 Registry {
42 url: String,
43 #[serde(skip_serializing_if = "Option::is_none")]
44 name: Option<String>,
45 },
46 Git { url: String, tag: Option<String> },
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
52pub enum ModuleStatus {
53 NotInstalled,
55 Stopped,
57 Initializing,
59 Running,
61 Stopping,
63 Error(String),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
69pub enum ModuleHealth {
70 Healthy,
72 Degraded,
74 Unhealthy(String),
76 Unknown,
78}
79
80#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
82pub enum NetworkType {
83 Mainnet,
85 Testnet,
87 Regtest,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct NodeSpec {
94 pub name: String,
96 pub version: Option<String>,
98 pub network: NetworkType,
100 pub modules: Vec<ModuleSpec>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct ModuleSpec {
107 pub name: String,
109 pub version: Option<String>,
111 pub enabled: bool,
113 #[serde(default)]
115 pub config: HashMap<String, serde_json::Value>,
116}
117
118#[derive(Debug, Clone)]
120pub struct LoadedModule {
121 pub info: ModuleInfo,
123 pub status: ModuleStatus,
125 pub health: ModuleHealth,
127}
128
129#[derive(Debug, Clone)]
131pub struct ComposedNode {
132 pub spec: NodeSpec,
134 pub modules: Vec<LoadedModule>,
136 pub status: NodeStatus,
138}
139
140#[derive(Debug, Clone, PartialEq, Eq)]
142pub enum NodeStatus {
143 Stopped,
145 Starting,
147 Running,
149 Stopping,
151 Error(String),
153}
154
155#[derive(Debug, Clone)]
157pub struct ValidationResult {
158 pub valid: bool,
160 pub errors: Vec<String>,
162 pub warnings: Vec<String>,
164 pub dependencies: Vec<ModuleInfo>,
166}
167
168#[derive(Debug, Error)]
170pub enum CompositionError {
171 #[error("Module not found: {0}")]
172 ModuleNotFound(String),
173
174 #[error("Module version not found: {0} {1}")]
175 ModuleVersionNotFound(String, String),
176
177 #[error("Dependency resolution failed: {0}")]
178 DependencyResolutionFailed(String),
179
180 #[error("Module installation failed: {0}")]
181 InstallationFailed(String),
182
183 #[error("Invalid configuration: {0}")]
184 InvalidConfiguration(String),
185
186 #[error("Composition validation failed: {0}")]
187 ValidationFailed(String),
188
189 #[error("IO error: {0}")]
190 IoError(#[from] std::io::Error),
191
192 #[error("Serialization error: {0}")]
193 SerializationError(String),
194}
195
196pub type Result<T> = std::result::Result<T, CompositionError>;