1use crate::id::ID;
2use serde::Serialize;
3use std::collections::HashMap;
4use valu3::prelude::*;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Default)]
7pub struct Context {
8 pub params: Option<Value>,
9 pub steps: HashMap<ID, Value>,
10 pub main: Option<Value>,
11 pub payload: Option<Value>,
12 pub input: Option<Value>,
13}
14
15impl Context {
16 pub fn new(params: Option<Value>) -> Self {
17 Self {
18 params,
19 main: None,
20 steps: HashMap::new(),
21 payload: None,
22 input: None,
23 }
24 }
25
26 pub fn from_main(main: Value) -> Self {
27 Self {
28 params: None,
29 main: Some(main),
30 steps: HashMap::new(),
31 payload: None,
32 input: None,
33 }
34 }
35
36 pub fn add_module_input(&self, output: Value) -> Self {
37 Self {
38 params: self.params.clone(),
39 main: self.main.clone(),
40 steps: self.steps.clone(),
41 payload: self.payload.clone(),
42 input: Some(output),
43 }
44 }
45
46 pub fn add_module_output(&self, output: Value) -> Self {
47 Self {
48 params: self.params.clone(),
49 main: self.main.clone(),
50 steps: self.steps.clone(),
51 payload: Some(output),
52 input: self.input.clone(),
53 }
54 }
55
56 pub fn add_step_output(&mut self, id: ID, output: Value) {
57 self.steps.insert(id, output);
58 }
59
60 pub fn get_step_output(&self, id: &ID) -> Option<&Value> {
61 self.steps.get(&id)
62 }
63}