allora_runtime/spec/services_spec.rs
1//! ServiceActivatorsSpec: collection of ServiceActivatorSpec entries (v1) sharing a version.
2//! Mirrors FiltersSpec semantics for ordered aggregation and deferred uniqueness enforcement.
3//!
4//! # Responsibilities
5//! * Preserve declaration order (Vec internally).
6//! * Carry a single `version` validated by parser (future parser TBD).
7//! * Allow optional / duplicate service activator ids; uniqueness & auto-id handled in builder.
8//!
9//! # Auto-ID Strategy (Builder Level)
10//! * Missing `service-activator.id` values assigned deterministic `service:auto.N` IDs starting at 1.
11//! * Duplicate explicit ids trigger a build error.
12//!
13//! # Field Semantics
14//! * `ref_name` is a reference identifier matching the `#[service(name=...)]` macro parameter,
15//! NOT a file path. It links the YAML configuration to the registered service implementation.
16//!
17//! # Example (programmatic construction)
18//! ```rust
19//! use allora_runtime::spec::{ServiceActivatorSpec, ServiceActivatorsSpec};
20//! let spec = ServiceActivatorsSpec::new(1)
21//! .add(ServiceActivatorSpec::with_id("svc.hello", "hello_world", "inbound.a", "outbound.b"))
22//! .add(ServiceActivatorSpec::new("worker_service", "inbound.b", "outbound.c"));
23//! assert_eq!(spec.services_activators().len(), 2);
24//! assert_eq!(spec.services_activators()[0].id(), Some("svc.hello"));
25//! assert!(spec.services_activators()[1].id().is_none());
26//! ```
27
28use crate::spec::ServiceActivatorSpec;
29
30#[derive(Debug, Clone)]
31pub struct ServiceActivatorsSpec {
32 version: u32,
33 services: Vec<ServiceActivatorSpec>,
34}
35
36impl ServiceActivatorsSpec {
37 pub fn new(version: u32) -> Self {
38 Self {
39 version,
40 services: Vec::new(),
41 }
42 }
43 pub fn add(mut self, s: ServiceActivatorSpec) -> Self {
44 self.services.push(s);
45 self
46 }
47 pub fn push(&mut self, s: ServiceActivatorSpec) {
48 self.services.push(s);
49 }
50 pub fn version(&self) -> u32 {
51 self.version
52 }
53 pub fn services_activators(&self) -> &[ServiceActivatorSpec] {
54 &self.services
55 }
56 pub fn into_service_activators(self) -> Vec<ServiceActivatorSpec> {
57 self.services
58 }
59}