greentic_flow/
lib.rs

1#![forbid(unsafe_code)]
2
3pub mod error;
4pub mod ir;
5pub mod lint;
6pub mod loader;
7pub mod model;
8pub mod registry;
9pub mod resolve;
10pub mod util;
11
12use crate::{
13    error::Result,
14    ir::{FlowIR, NodeIR, RouteIR},
15    model::FlowDoc,
16};
17use indexmap::IndexMap;
18
19/// Convert a `FlowDoc` into its compact intermediate representation.
20pub fn to_ir(flow: FlowDoc) -> Result<FlowIR> {
21    let mut nodes: IndexMap<String, NodeIR> = IndexMap::new();
22    for (id, node) in flow.nodes {
23        nodes.insert(
24            id,
25            NodeIR {
26                component: node.component,
27                payload_expr: node.payload,
28                routes: node
29                    .routing
30                    .into_iter()
31                    .map(|route| RouteIR {
32                        to: route.to,
33                        out: route.out.unwrap_or(false),
34                    })
35                    .collect(),
36            },
37        );
38    }
39
40    Ok(FlowIR {
41        id: flow.id,
42        flow_type: flow.flow_type,
43        start: flow.start,
44        parameters: flow.parameters,
45        nodes,
46    })
47}