moduforge_rules_engine/handler/
node.rs

1use crate::model::DecisionNode;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::fmt::{Display, Formatter};
5use std::sync::Arc;
6use thiserror::Error;
7use moduforge_rules_expression::variable::Variable;
8
9#[derive(Debug, Deserialize, Serialize)]
10#[serde(rename_all = "camelCase")]
11pub struct NodeResponse {
12    pub output: Variable,
13    pub trace_data: Option<Value>,
14}
15
16#[derive(Debug, Serialize, Clone)]
17pub struct NodeRequest {
18    pub input: Variable,
19    pub iteration: u8,
20    pub node: Arc<DecisionNode>,
21}
22
23#[derive(Error, Debug)]
24pub struct NodeError {
25    pub node_id: String,
26    pub trace: Option<Value>,
27    #[source]
28    pub source: anyhow::Error,
29}
30
31impl Display for NodeError {
32    fn fmt(
33        &self,
34        f: &mut Formatter<'_>,
35    ) -> std::fmt::Result {
36        write!(f, "{:?}", self)
37    }
38}
39
40#[derive(Debug)]
41pub(crate) struct PartialTraceError {
42    pub trace: Option<Value>,
43    pub message: String,
44}
45
46impl Display for PartialTraceError {
47    fn fmt(
48        &self,
49        f: &mut Formatter<'_>,
50    ) -> std::fmt::Result {
51        write!(f, "{}", self.message)
52    }
53}
54
55pub type NodeResult = anyhow::Result<NodeResponse>;