restflow_core/models/
workflow.rs

1use super::node::Node;
2use super::trigger::TriggerConfig;
3use serde::{Deserialize, Serialize};
4use ts_rs::TS;
5
6#[derive(Debug, Clone, Serialize, Deserialize, TS)]
7#[ts(export)]
8pub struct Workflow {
9    pub id: String,
10    pub name: String,
11    pub nodes: Vec<Node>,
12    pub edges: Vec<Edge>,
13    // trigger_config removed - now stored in trigger nodes
14}
15
16impl Workflow {
17    /// Extract trigger configurations from workflow nodes
18    /// Returns all trigger configurations found in the workflow
19    pub fn extract_trigger_configs(&self) -> Vec<(String, TriggerConfig)> {
20        let mut configs = Vec::new();
21
22        for node in &self.nodes {
23            if let Some(config) = node.extract_trigger_config() {
24                configs.push((node.id.clone(), config));
25            }
26        }
27
28        configs
29    }
30
31    /// Get all trigger nodes
32    pub fn get_trigger_nodes(&self) -> Vec<&Node> {
33        self.nodes.iter().filter(|n| n.is_trigger()).collect()
34    }
35
36    /// Check if workflow has a trigger node
37    pub fn has_trigger_node(&self) -> bool {
38        self.nodes.iter().any(|node| node.is_trigger())
39    }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, TS)]
43#[ts(export)]
44pub struct Edge {
45    pub from: String,
46    pub to: String,
47}