phlow_engine/
collector.rs

1use crate::id::ID;
2use crossbeam::channel;
3use phlow_sdk::{crossbeam, prelude::*};
4use serde::Serialize;
5use std::{collections::HashMap, fmt::Debug};
6
7pub type ContextSender = channel::Sender<Step>;
8
9#[derive(Clone, Default, PartialEq, Serialize)]
10pub struct Step {
11    pub id: ID,
12    pub label: Option<String>,
13    pub module: Option<String>,
14    pub input: Option<Value>,
15    pub condition: Option<Value>,
16    pub payload: Option<Value>,
17    pub return_case: Option<Value>,
18}
19
20impl ToValueBehavior for Step {
21    fn to_value(&self) -> Value {
22        let mut value = HashMap::new();
23
24        value.insert("id", self.id.to_value());
25        value.insert("label", self.label.to_value());
26        value.insert("condition", self.condition.to_value());
27        value.insert("payload", self.payload.to_value());
28        value.insert("return_case", self.return_case.to_value());
29
30        value.to_value()
31    }
32}
33
34impl Debug for Step {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        let mut value = self.to_value();
37        let id = match value.get("id") {
38            Some(id) => id.to_string(),
39            None => "unknown".to_string(),
40        };
41        value.remove(&"id");
42        value.insert("step_id", id);
43
44        write!(f, "{}", value.to_json(JsonMode::Inline))
45    }
46}