Skip to main content

butterflow_models/
state.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4use ts_rs::TS;
5/// Type of state schema property
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
7#[serde(rename_all = "lowercase")]
8pub enum StateSchemaType {
9    /// Array type
10    Array,
11
12    /// Object type
13    Object,
14
15    /// String type
16    String,
17
18    /// Number type
19    Number,
20
21    /// Boolean type
22    Boolean,
23}
24
25/// Represents a state schema property
26#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
27pub struct StateSchemaProperty {
28    /// Type of the property
29    pub r#type: StateSchemaType,
30
31    /// Description of the property
32    #[serde(default)]
33    #[ts(optional=nullable)]
34    pub description: Option<String>,
35}
36
37/// Represents a state schema definition
38#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
39pub struct StateSchema {
40    /// Name of the state schema
41    pub name: String,
42
43    /// Type of the state schema
44    pub r#type: StateSchemaType,
45
46    /// For array types, the schema of the items
47    #[serde(default)]
48    #[ts(optional=nullable)]
49    pub items: Option<Box<StateSchemaItems>>,
50
51    /// Description of the state schema
52    #[serde(default)]
53    #[ts(optional=nullable)]
54    pub description: Option<String>,
55}
56
57/// Represents the schema for items in an array
58#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, TS)]
59pub struct StateSchemaItems {
60    /// Type of the items
61    pub r#type: StateSchemaType,
62
63    /// For object types, the properties of the object
64    #[serde(default)]
65    #[ts(optional=nullable)]
66    pub properties: Option<HashMap<String, StateSchemaProperty>>,
67}