Skip to content

Commit

Permalink
Merge pull request #44 from code0-tech/update-flow-definitions
Browse files Browse the repository at this point in the history
Update Flow & Flow-Definition
  • Loading branch information
raphael-goetz authored Feb 3, 2025
2 parents fd05efa + 7e6f04a commit c36bfa0
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ jobs:
run: PATH=${{ runner.temp }}/proto/bin:$PATH cargo build
env:
RUST_BACKTRACE: 'full'
- name: Test De/Serialization from/to json
run: PATH=${{ runner.temp }}/proto/bin:$PATH cargo test --features sagittarius
env:
RUST_BACKTRACE: 'full'
- name: Package crate
run: cargo package --allow-dirty
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ services that Sagittarius must implement as a server.
├── sagittarius
│ ├── action - Action service (manages logon/logoff requests for action configurations)
│ ├── datatype - DataType service
│ ├── flow - Flow service (handles flow updates)
│ ├── flow_definition - Defines types for flows
│ ├── node - Defines types for nodes
│ ├── flow - Flow service & Flow types (handles flow updates)
│ ├── flow_definition - Defines a definition for a Flow
│ ├── ping - Ping service (performs life checks)
│ └── runtime_function - Service for updating the runtime functions
└── shared
├── datatype - Defines types for data types
├── event - Defines types for events
├── runtime_function_definition - Defines types for runtime functions
├── struct - Defines types for json representations
└── translation - Contains translations with country codes and translated messages
```
19 changes: 19 additions & 0 deletions build/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ serde = { version = "1.0.217", features = ["derive"] }
prost-types = "0.13.4"
prost = "0.13.4"
tonic = "0.12.3"
serde_json = "1.0.138"

[build-dependencies]
tonic-build = "0.12.3"
Expand Down
52 changes: 31 additions & 21 deletions build/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ fn main() -> Result<()> {
"sagittarius.datatype.proto",
"sagittarius.flow.proto",
"sagittarius.flow_definition.proto",
"sagittarius.node.proto",
"sagittarius.ping.proto",
"sagittarius.runtime_function.proto",
// shared
"shared.datatype.proto",
"shared.runtime_function.proto",
"shared.translation.proto",
"shared.event.proto"
"shared.struct.proto",
"shared.event.proto",
];

let inclusions = &[
Expand All @@ -27,31 +28,40 @@ fn main() -> Result<()> {
];

let out_path = "src/generated";
let serde_attribute = "#[derive(serde::Serialize, serde::Deserialize)]";

if !std::path::Path::new(&out_path).exists() {
create_dir(out_path)?;
match create_dir(out_path) {
Err(error) => panic!("Cannot create the `generated` folder! Reason: {:?}", error),
_ => {}
};
}


tonic_build::configure()
let build_result = tonic_build::configure()
.out_dir(out_path)
.build_server(true)
.build_client(true)
.type_attribute("NullValue", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Value", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("ValueList", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Struct", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Translation", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("DataTypeRule", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("DataType", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("FlowDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("RuntimeParameterDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("RuntimeFunctionDefinition", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Parameter", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Node", "#[derive(serde::Serialize, serde::Deserialize)]")
.type_attribute("Flow", "#[derive(serde::Serialize, serde::Deserialize)]")
.compile(proto, inclusions)
.expect("Cannot compile internal protos");
.type_attribute("kind", serde_attribute)
.type_attribute("NullValue", serde_attribute)
.type_attribute("Value", serde_attribute)
.type_attribute("ListValue", serde_attribute)
.type_attribute("Struct", serde_attribute)
.type_attribute("Translation", serde_attribute)
.type_attribute("DataTypeRule", serde_attribute)
.type_attribute("DataType", serde_attribute)
.type_attribute("RuntimeParameterDefinition", serde_attribute)
.type_attribute("RuntimeFunctionDefinition", serde_attribute)
.type_attribute("FlowSetting", serde_attribute)
.type_attribute("NodeParameterDefinition", serde_attribute)
.type_attribute("NodeFunctionDefinition", serde_attribute)
.type_attribute("NodeParameter", serde_attribute)
.type_attribute("NodeFunction", serde_attribute)
.type_attribute("Flow", serde_attribute)
.type_attribute("Flows", serde_attribute)
.compile_protos(proto, inclusions);

Ok(())
match build_result {
Ok(_) => Ok(()),
Err(error) => panic!("Cannot build the proto files! Reason: {:?}", error),
}
}
51 changes: 51 additions & 0 deletions build/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
#[cfg(feature = "sagittarius")]
pub mod sagittarius {
include!("generated/sagittarius.rs");

#[cfg(test)]
pub mod tests {
use crate::sagittarius::Flow;
use serde_json;

#[test]
fn test_serialize() {
let flow = Flow {
flow_id: 0,
r#type: "no".to_string(),
settings: vec![],
starting_node: None,
};

let str_flow = serde_json::to_string(&flow).expect("Serialization failed");
let json_flow: serde_json::Value = serde_json::from_str(&str_flow).expect("Failed to parse JSON");

let expected_json: serde_json::Value = serde_json::json!({
"flow_id": 0,
"type": "no",
"settings": [],
"starting_node": null
});

assert_eq!(json_flow, expected_json);
}

#[test]
fn test_deserialize() {
let json_data = r#"{
"flow_id": 0,
"type": "no",
"settings": [],
"starting_node": null
}"#;

let deserialized: Result<Flow, _> = serde_json::from_str(json_data);
assert!(deserialized.is_ok());

let expected_flow = Flow {
flow_id: 0,
r#type: "no".to_string(),
settings: vec![],
starting_node: None,
};

assert_eq!(deserialized.unwrap(), expected_flow);
}
}

}

#[cfg(feature = "aquila")]
Expand Down
36 changes: 32 additions & 4 deletions proto/sagittarius/sagittarius.flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,41 @@ option ruby_package = "Tucana::Sagittarius";

package sagittarius;

import "sagittarius.node.proto";
import "sagittarius.flow_definition.proto";
import "shared.struct.proto";

message Flow {
// Database ID -> req. for Aquila to identify in FlowStore
int64 flow_id = 1;
Node start_node = 2;
FlowDefinition definition = 3;
string type = 2;
repeated FlowSetting settings = 3;
NodeFunction starting_node = 4;
}

message FlowSetting {
string definition = 1;
shared.Struct object = 2;
}

message NodeFunction {
NodeFunctionDefinition definition = 1;
repeated NodeParameter parameters = 2;
optional NodeFunction next_node = 3;
}

message NodeParameter {
NodeParameterDefinition definition = 1;
shared.Struct object = 2;
NodeFunction sub_node = 3;
}

message NodeParameterDefinition {
string parameter_id = 1;
string runtime_parameter_id = 2;
}

message NodeFunctionDefinition {
string function_id = 1;
string runtime_function_id = 2;
}

message Flows {
Expand Down
20 changes: 20 additions & 0 deletions proto/sagittarius/sagittarius.flow_definition.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,25 @@ option ruby_package = "Tucana::Sagittarius";

package sagittarius;

import "shared.translation.proto";
import "shared.datatype.proto";
import "shared.struct.proto";

message FlowType {
FlowDefinition definition = 1;
repeated shared.Translation name = 2;
}

message FlowDefinitionSetting {
bool unique = 1;
shared.DataType type = 2;
optional shared.Struct default_value = 3;
repeated shared.Translation name = 4;
repeated shared.Translation description = 5;
}

message FlowDefinition {
repeated FlowDefinitionSetting settings = 1;
shared.DataType input_type = 2;
bool editable = 3;
}
19 changes: 0 additions & 19 deletions proto/sagittarius/sagittarius.node.proto

This file was deleted.

19 changes: 19 additions & 0 deletions proto/shared/shared.runtime_function.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ option ruby_package = "Tucana::Shared";
package shared;

import "shared.translation.proto";
import "shared.datatype.proto";
import "shared.struct.proto";

// Definition of a function used for execution
message RuntimeFunctionDefinition {
Expand All @@ -19,4 +21,21 @@ message RuntimeParameterDefinition {
string data_type_identifier = 1;
string runtime_name = 2;
repeated Translation name = 3;
}

message FunctionDefinition {
RuntimeFunctionDefinition runtime_function = 1;
optional DataType return_type = 2;
repeated ParameterDefinition parameters = 3;
repeated Translation name = 4;
repeated Translation description = 5;
repeated Translation documentation = 6;
}

message ParameterDefinition {
DataType type = 1;
optional Struct default_value = 2;
repeated Translation name = 3;
repeated Translation description = 4;
repeated Translation documentation = 5;
}

0 comments on commit c36bfa0

Please sign in to comment.