allora_runtime/spec/
allora_spec.rs

1//! AlloraSpec: top-level configuration spec aggregating inner component specs (currently channels only).
2//!
3//! # Responsibilities
4//! * Capture version once for all nested component collections.
5//! * Provide structured access to nested specs (`channels_spec`).
6//! * Act as stable expansion point for future components (endpoints, filters, adapters) without
7//!   changing the external DSL facade return type (`AlloraRuntime`).
8//!
9//! # Not Responsible For
10//! * Parsing (handled by `AlloraSpecYamlParser`).
11//! * Runtime instantiation (handled by `dsl/component_builders.rs` via `build_channels_from_spec`).
12//! * Validation beyond version presence (nested parsers validate their own structures).
13//!
14//! # Future Extensions
15//! Additional fields (e.g. `endpoints: EndpointsSpec`, `filters: FiltersSpec`) can be added while
16//! preserving existing methods. Accessor naming should stay consistent (`*_spec()` for borrowing,
17//! `into_*_spec()` for ownership transfer).
18//!
19//! # Example
20//! ```rust
21//! use allora_runtime::spec::{AlloraSpec, ChannelsSpec, ChannelSpec};
22//! // Programmatic construction
23//! let channels = ChannelsSpec::new(1).add(ChannelSpec::queue().id("orders"));
24//! let all = AlloraSpec::new(1, channels);
25//! assert_eq!(all.version(), 1);
26//! assert_eq!(all.channels_spec().channels().len(), 1);
27//! ```
28//!
29
30use crate::spec::{ChannelsSpec, FiltersSpec, ServiceActivatorsSpec, HttpInboundAdaptersSpec, HttpOutboundAdaptersSpec};
31
32#[derive(Debug, Clone)]
33pub struct AlloraSpec {
34    version: u32,
35    channels: ChannelsSpec,
36    filters: Option<FiltersSpec>,
37    services: Option<ServiceActivatorsSpec>,
38    http_inbound_adapters: Option<HttpInboundAdaptersSpec>,
39    http_outbound_adapters: Option<HttpOutboundAdaptersSpec>,
40}
41
42impl AlloraSpec {
43    pub fn new(version: u32, channels: ChannelsSpec) -> Self {
44        Self {
45            version,
46            channels,
47            filters: None,
48            services: None,
49            http_inbound_adapters: None,
50            http_outbound_adapters: None,
51        }
52    }
53    /// Construct with an optional filters collection in a single call (ergonomic alternative to chaining `with_filters`).
54    /// When `filters` is `None`, behaves the same as `new`.
55    pub fn new_with_filters(
56        version: u32,
57        channels: ChannelsSpec,
58        filters: Option<FiltersSpec>,
59    ) -> Self {
60        Self {
61            version,
62            channels,
63            filters,
64            services: None,
65            http_inbound_adapters: None,
66            http_outbound_adapters: None,
67        }
68    }
69    pub fn with_filters(mut self, filters: FiltersSpec) -> Self {
70        self.filters = Some(filters);
71        self
72    }
73    pub fn with_services(mut self, services: ServiceActivatorsSpec) -> Self {
74        self.services = Some(services);
75        self
76    }
77    pub fn with_http_inbound_adapters(mut self, adapters: HttpInboundAdaptersSpec) -> Self {
78        self.http_inbound_adapters = Some(adapters);
79        self
80    }
81    pub fn with_http_outbound_adapters(mut self, adapters: HttpOutboundAdaptersSpec) -> Self {
82        self.http_outbound_adapters = Some(adapters);
83        self
84    }
85    pub fn version(&self) -> u32 {
86        self.version
87    }
88    pub fn channels_spec(&self) -> &ChannelsSpec {
89        &self.channels
90    }
91    pub fn filters_spec(&self) -> Option<&FiltersSpec> {
92        self.filters.as_ref()
93    }
94    pub fn services_spec(&self) -> Option<&ServiceActivatorsSpec> {
95        self.services.as_ref()
96    }
97    pub fn http_inbound_adapters_spec(&self) -> Option<&HttpInboundAdaptersSpec> {
98        self.http_inbound_adapters.as_ref()
99    }
100    pub fn http_outbound_adapters_spec(&self) -> Option<&HttpOutboundAdaptersSpec> {
101        self.http_outbound_adapters.as_ref()
102    }
103    pub fn into_channels_spec(self) -> ChannelsSpec {
104        self.channels
105    }
106    pub fn into_filters_spec(self) -> Option<FiltersSpec> {
107        self.filters
108    }
109    pub fn into_services_spec(self) -> Option<ServiceActivatorsSpec> {
110        self.services
111    }
112    pub fn into_http_inbound_adapters_spec(self) -> Option<HttpInboundAdaptersSpec> {
113        self.http_inbound_adapters
114    }
115    pub fn into_http_outbound_adapters_spec(self) -> Option<HttpOutboundAdaptersSpec> {
116        self.http_outbound_adapters
117    }
118}