allora_runtime/spec/service_spec.rs
1//! ServiceActivatorSpec: specification for a single processing service (activator) binding logic between channels.
2//!
3//! # Purpose
4//! Represents a unit of executable logic (a processor) wired between an inbound (`from`) and
5//! outbound (`to`) channel. The `ref_name` field is a symbolic reference matching the
6//! `#[service(name=...)]` macro parameter used to locate the registered implementation (not a file path).
7//!
8//! # Field Semantics
9//! * `id` (optional): Explicit identifier for referencing/diagnostics. Missing ids may be assigned
10//! deterministically by a future collection builder (`service:auto.N`).
11//! * `ref_name` (required, non-empty): Reference identifier matching the service macro name; links YAML spec to runtime descriptor.
12//! * `from` (required, non-empty): Inbound channel id the service consumes messages from.
13//! * `to` (required, non-empty): Outbound channel id the service publishes processed messages to.
14//!
15//! # Uniqueness & Validation
16//! * Parser enforces presence and non-empty strings for required fields; uniqueness of `id` deferred.
17//! * Validation does not enforce any naming pattern for `ref_name` beyond non-empty.
18//!
19//! # Runtime Mapping
20//! `ServiceActivatorSpec` does not itself execute code; builders transform the spec into a runtime
21//! processor abstraction matched against inventory descriptors submitted by the macro.
22//!
23//! # Construction Helpers
24//! * `new(ref_name, from, to)` – minimal spec without id.
25//! * `with_id(id, ref_name, from, to)` – explicit id.
26//! * `id()` / `ref_name()` / `from()` / `to()` – accessors.
27//! * `set_id(id)` – internal builder use for auto-id assignment.
28//!
29//! # Example
30//! ```rust
31//! use allora_runtime::spec::ServiceActivatorSpec;
32//! let spec = ServiceActivatorSpec::new("hello_world", "inbound.orders", "vetted.orders");
33//! assert_eq!(spec.ref_name(), "hello_world");
34//! assert_eq!(spec.from(), "inbound.orders");
35//! assert_eq!(spec.to(), "vetted.orders");
36//! ```
37
38#[derive(Debug, Clone)]
39pub struct ServiceActivatorSpec {
40 id: Option<String>,
41 ref_name: String,
42 from: String,
43 to: String,
44}
45
46impl ServiceActivatorSpec {
47 pub fn new<I: Into<String>, F: Into<String>, T: Into<String>>(
48 ref_name: I,
49 from: F,
50 to: T,
51 ) -> Self {
52 Self {
53 id: None,
54 ref_name: ref_name.into(),
55 from: from.into(),
56 to: to.into(),
57 }
58 }
59 pub fn with_id<ID: Into<String>, I: Into<String>, F: Into<String>, T: Into<String>>(
60 id: ID,
61 ref_name: I,
62 from: F,
63 to: T,
64 ) -> Self {
65 Self {
66 id: Some(id.into()),
67 ref_name: ref_name.into(),
68 from: from.into(),
69 to: to.into(),
70 }
71 }
72 pub fn id(&self) -> Option<&str> {
73 self.id.as_deref()
74 }
75 pub fn ref_name(&self) -> &str {
76 &self.ref_name
77 }
78 pub fn from(&self) -> &str {
79 &self.from
80 }
81 pub fn to(&self) -> &str {
82 &self.to
83 }
84 pub fn set_id(&mut self, id: String) {
85 self.id = Some(id);
86 }
87}