Skip to main content

swf_builders/services/task/
common.rs

1use super::*;
2
3// ============== InputDataModelDefinitionBuilder ==============
4/// Builder for constructing an `InputDataModelDefinition` that configures task input data processing.
5pub struct InputDataModelDefinitionBuilder {
6    input: InputDataModelDefinition,
7}
8
9impl InputDataModelDefinitionBuilder {
10    pub fn new() -> Self {
11        Self {
12            input: InputDataModelDefinition::default(),
13        }
14    }
15
16    /// Sets the `from` expression used to transform or filter task input data.
17    pub fn from(&mut self, value: Value) -> &mut Self {
18        self.input.from = Some(value);
19        self
20    }
21
22    /// Builds the `InputDataModelDefinition`.
23    pub fn build(self) -> InputDataModelDefinition {
24        self.input
25    }
26}
27
28impl Default for InputDataModelDefinitionBuilder {
29    fn default() -> Self {
30        Self::new()
31    }
32}
33
34// ============== OutputDataModelDefinitionBuilder ==============
35/// Builder for constructing an `OutputDataModelDefinition` that configures task output data processing.
36pub struct OutputDataModelDefinitionBuilder {
37    output: OutputDataModelDefinition,
38}
39
40impl OutputDataModelDefinitionBuilder {
41    pub fn new() -> Self {
42        Self {
43            output: OutputDataModelDefinition::default(),
44        }
45    }
46
47    /// Sets the `as` expression used to transform task output data.
48    pub fn r#as(&mut self, value: Value) -> &mut Self {
49        self.output.as_ = Some(value);
50        self
51    }
52
53    /// Builds the `OutputDataModelDefinition`.
54    pub fn build(self) -> OutputDataModelDefinition {
55        self.output
56    }
57}
58
59impl Default for OutputDataModelDefinitionBuilder {
60    fn default() -> Self {
61        Self::new()
62    }
63}
64
65// ============== EventDefinitionBuilder ==============
66/// Builder for constructing an `EventDefinition` used in emit and listen tasks.
67pub struct EventDefinitionBuilder {
68    event: EventDefinition,
69}
70
71impl EventDefinitionBuilder {
72    pub fn new() -> Self {
73        Self {
74            event: EventDefinition::default(),
75        }
76    }
77
78    /// Adds a single attribute to the event definition.
79    pub fn with(&mut self, name: &str, value: Value) -> &mut Self {
80        self.event.with.insert(name.to_string(), value);
81        self
82    }
83
84    /// Replaces all event attributes with the provided map.
85    pub fn with_attributes(&mut self, attrs: HashMap<String, Value>) -> &mut Self {
86        self.event.with = attrs;
87        self
88    }
89
90    /// Builds the `EventDefinition`.
91    pub fn build(self) -> EventDefinition {
92        self.event
93    }
94}
95
96impl Default for EventDefinitionBuilder {
97    fn default() -> Self {
98        Self::new()
99    }
100}