Skip to main content

a3s_flow/
protocol.rs

1use serde::{Deserialize, Serialize};
2
3use crate::model::JsonValue;
4
5pub const NATIVE_RUNTIME_PROTOCOL: &str = "a3s.flow.native_ts.v1";
6
7#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
8#[serde(rename_all = "snake_case")]
9pub enum NativeRuntimeKind {
10    Workflow,
11    Step,
12}
13
14impl NativeRuntimeKind {
15    pub fn as_str(self) -> &'static str {
16        match self {
17            Self::Workflow => "workflow",
18            Self::Step => "step",
19        }
20    }
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
24pub struct NativeRuntimeRequest<T> {
25    pub protocol: String,
26    pub kind: NativeRuntimeKind,
27    #[serde(rename = "exportName")]
28    pub export_name: String,
29    #[serde(rename = "sourceHash")]
30    pub source_hash: String,
31    pub payload: T,
32}
33
34impl<T> NativeRuntimeRequest<T> {
35    pub fn new(
36        kind: NativeRuntimeKind,
37        export_name: impl Into<String>,
38        source_hash: impl Into<String>,
39        payload: T,
40    ) -> Self {
41        Self {
42            protocol: NATIVE_RUNTIME_PROTOCOL.to_string(),
43            kind,
44            export_name: export_name.into(),
45            source_hash: source_hash.into(),
46            payload,
47        }
48    }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
52pub struct NativeRuntimeResponse {
53    pub protocol: String,
54    pub kind: NativeRuntimeKind,
55    pub ok: bool,
56    #[serde(default)]
57    pub output: Option<JsonValue>,
58    #[serde(default)]
59    pub error: Option<String>,
60}