Skip to main content

butterflow_models/
state_diff.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use ts_rs::TS;
4use uuid::Uuid;
5
6/// Represents a diff operation
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)]
8pub enum DiffOperation {
9    /// Add a new value
10    Add,
11    /// Update an existing value
12    Update,
13    /// Remove an existing value
14    Remove,
15    /// Append to an array
16    Append,
17}
18
19/// Represents a diff for a single field
20#[derive(Debug, Clone, Serialize, Deserialize, TS)]
21pub struct FieldDiff {
22    /// The operation to perform
23    pub operation: DiffOperation,
24    /// The new value (for Add and Update operations)
25    pub value: Option<serde_json::Value>,
26}
27
28/// Represents a diff for a workflow run
29#[derive(Debug, Clone, Serialize, Deserialize, TS)]
30pub struct WorkflowRunDiff {
31    /// The ID of the workflow run
32    pub workflow_run_id: Uuid,
33    /// The fields to update
34    pub fields: HashMap<String, FieldDiff>,
35}
36
37/// Represents a diff for a task
38#[derive(Debug, Clone, Serialize, Deserialize, TS)]
39pub struct TaskDiff {
40    /// The ID of the task
41    pub task_id: Uuid,
42    /// The fields to update
43    pub fields: HashMap<String, FieldDiff>,
44}
45
46/// Represents a diff for workflow state
47#[derive(Debug, Clone, Serialize, Deserialize, TS)]
48pub struct StateDiff {
49    /// The ID of the workflow run
50    pub workflow_run_id: Uuid,
51    /// The fields to update
52    pub fields: HashMap<String, FieldDiff>,
53}