diff --git a/build/ruby/lib/tucana/shared/shared.data_type.rb b/build/ruby/lib/tucana/shared/shared.data_type.rb index 7b0f7ba..85e919f 100644 --- a/build/ruby/lib/tucana/shared/shared.data_type.rb +++ b/build/ruby/lib/tucana/shared/shared.data_type.rb @@ -5,7 +5,7 @@ module Shared UnexpectedRuleType = Class.new(Tucana::Error) UnexpectedType = Class.new(Tucana::Error) - DataTypeRule.class_eval do + DefinitionDataTypeRule.class_eval do def variant self.config end @@ -34,9 +34,9 @@ def rule_config def create(variant, config) case variant when :contains_key - self.contains_key = DataTypeContainsKeyRuleConfig.new(config) + self.contains_key = DefinitionDataTypeContainsKeyRuleConfig.new(config) when :contains_type - self.contains_type = DataTypeContainsTypeRuleConfig.new(config) + self.contains_type = DefinitionDataTypeContainsTypeRuleConfig.new(config) when :item_of_collection self.item_of_collection = DataTypeItemOfCollectionRuleConfig.from_hash(config) when :number_range @@ -44,9 +44,9 @@ def create(variant, config) when :regex self.regex = DataTypeRegexRuleConfig.new(config) when :input_types - self.input_types = DataTypeInputTypesRuleConfig.new(config) + self.input_types = DefinitionDataTypeInputTypesRuleConfig.new(config) when :return_type - self.return_type = DataTypeReturnTypeRuleConfig.new(config) + self.return_type = DefinitionDataTypeReturnTypeRuleConfig.new(config) else raise UnexpectedRuleType, "Unknown rule type #{variant}" end @@ -59,7 +59,7 @@ def self.create(variant, config) end end - DataTypeContainsKeyRuleConfig.class_eval do + DefinitionDataTypeContainsKeyRuleConfig.class_eval do def to_h { key: self.key, @@ -75,7 +75,7 @@ def self.from_hash(config) end end - DataTypeContainsTypeRuleConfig.class_eval do + DefinitionDataTypeContainsTypeRuleConfig.class_eval do def to_h { data_type_identifier: self.data_type_identifier.to_h, @@ -117,7 +117,7 @@ def to_h end end - DataTypeInputTypesRuleConfig.class_eval do + DefinitionDataTypeInputTypesRuleConfig.class_eval do def to_h { input_types: self.input_types.map { |input_type| input_type.to_h } @@ -131,7 +131,7 @@ def self.from_hash(hash) end end - DataTypeInputTypesRuleConfig::DataTypeInputType.class_eval do + DefinitionDataTypeInputTypesRuleConfig::DataTypeInputType.class_eval do def to_h { data_type_identifier: self.data_type_identifier, @@ -147,7 +147,7 @@ def self.from_hash(config) end end - DataTypeReturnTypeRuleConfig.class_eval do + DefinitionDataTypeReturnTypeRuleConfig.class_eval do def to_h { data_type_identifier: self.data_type_identifier, diff --git a/build/ruby/spec/tucana/shared/shared.data_type_spec.rb b/build/ruby/spec/tucana/shared/shared.data_type_spec.rb index a85b2c8..511284c 100644 --- a/build/ruby/spec/tucana/shared/shared.data_type_spec.rb +++ b/build/ruby/spec/tucana/shared/shared.data_type_spec.rb @@ -2,13 +2,13 @@ Tucana.load_protocol(:shared) -RSpec.describe Tucana::Shared::DataTypeRule do +RSpec.describe Tucana::Shared::DefinitionDataTypeRule do describe "#create" do context "with :contains_key variant" do it "sets the contains_key field" do config = { key: "test_key", data_type_identifier: { data_type_identifier: "test_type" } } rule = described_class.create(:contains_key, config) - expect(rule.contains_key).to be_a(Tucana::Shared::DataTypeContainsKeyRuleConfig) + expect(rule.contains_key).to be_a(Tucana::Shared::DefinitionDataTypeContainsKeyRuleConfig) end end @@ -16,7 +16,7 @@ it "sets the contains_type field" do config = { data_type_identifier: { data_type_identifier: "test_type" } } rule = described_class.create(:contains_type, config) - expect(rule.contains_type).to be_a(Tucana::Shared::DataTypeContainsTypeRuleConfig) + expect(rule.contains_type).to be_a(Tucana::Shared::DefinitionDataTypeContainsTypeRuleConfig) end end @@ -48,7 +48,7 @@ it "sets the input_types field" do config = { input_types: [{ data_type_identifier: { data_type_identifier: "test_type" }, input_identifier: "test_input" }] } rule = described_class.create(:input_types, config) - expect(rule.input_types).to be_a(Tucana::Shared::DataTypeInputTypesRuleConfig) + expect(rule.input_types).to be_a(Tucana::Shared::DefinitionDataTypeInputTypesRuleConfig) end end @@ -56,7 +56,7 @@ it "sets the return_type field" do config = { data_type_identifier: { data_type_identifier: "test_type" } } rule = described_class.create(:return_type, config) - expect(rule.return_type).to be_a(Tucana::Shared::DataTypeReturnTypeRuleConfig) + expect(rule.return_type).to be_a(Tucana::Shared::DefinitionDataTypeReturnTypeRuleConfig) end end diff --git a/build/rust/src/lib.rs b/build/rust/src/lib.rs index 0af1367..24e4e22 100644 --- a/build/rust/src/lib.rs +++ b/build/rust/src/lib.rs @@ -5,12 +5,12 @@ pub mod shared { #[cfg(test)] pub mod tests { - use crate::shared::Flow; + use crate::shared::ValidationFlow; use serde_json; #[test] fn test_serialize() { - let flow = Flow { + let flow = ValidationFlow { flow_id: 0, project_id: 0, data_types: vec![], @@ -52,10 +52,10 @@ pub mod shared { "starting_node": null }"#; - let deserialized: Result = serde_json::from_str(json_data); + let deserialized: Result = serde_json::from_str(json_data); assert!(deserialized.is_ok()); - let expected_flow = Flow { + let expected_flow = ValidationFlow { flow_id: 0, project_id: 0, r#type: "no".to_string(), diff --git a/build/rust/src/shared/helper/rule.rs b/build/rust/src/shared/helper/rule.rs index 6f6f68f..ea85920 100644 --- a/build/rust/src/shared/helper/rule.rs +++ b/build/rust/src/shared/helper/rule.rs @@ -1,13 +1,11 @@ -use crate::shared::DataTypeIdentifier; -use crate::shared::data_type_input_types_rule_config::DataTypeInputType; use crate::shared::{ - DataTypeContainsKeyRuleConfig, DataTypeContainsTypeRuleConfig, DataTypeInputTypesRuleConfig, DataTypeItemOfCollectionRuleConfig, DataTypeNumberRangeRuleConfig, DataTypeRegexRuleConfig, - DataTypeReturnTypeRuleConfig, DataTypeRule, Value, data_type_rule::Config, + ExecutionDataTypeContainsKeyRuleConfig, ExecutionDataTypeContainsTypeRuleConfig, + ExecutionDataTypeRule, Value, execution_data_type_rule::Config, }; pub struct RuleBuilder { - rules: Vec, + rules: Vec, } impl RuleBuilder { @@ -15,31 +13,31 @@ impl RuleBuilder { Self { rules: Vec::new() } } - pub fn add_contains_key( - mut self, - key: String, - data_type_identifier: DataTypeIdentifier, - ) -> Self { - self.rules.push(DataTypeRule { - config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { - key, - data_type_identifier: Some(data_type_identifier), - })), + pub fn add_contains_key(mut self, key: String, data_type_identifier: &str) -> Self { + self.rules.push(ExecutionDataTypeRule { + config: Some(Config::ContainsKey( + ExecutionDataTypeContainsKeyRuleConfig { + key, + data_type_identifier: data_type_identifier.to_string(), + }, + )), }); self } - pub fn add_contains_type(mut self, data_type_identifier: DataTypeIdentifier) -> Self { - self.rules.push(DataTypeRule { - config: Some(Config::ContainsType(DataTypeContainsTypeRuleConfig { - data_type_identifier: Some(data_type_identifier), - })), + pub fn add_contains_type(mut self, data_type_identifier: &str) -> Self { + self.rules.push(ExecutionDataTypeRule { + config: Some(Config::ContainsType( + ExecutionDataTypeContainsTypeRuleConfig { + data_type_identifier: data_type_identifier.to_string(), + }, + )), }); self } pub fn add_item_of_collection(mut self, items: Vec) -> Self { - self.rules.push(DataTypeRule { + self.rules.push(ExecutionDataTypeRule { config: Some(Config::ItemOfCollection( DataTypeItemOfCollectionRuleConfig { items }, )), @@ -48,7 +46,7 @@ impl RuleBuilder { } pub fn add_number_range(mut self, from: i64, to: i64, steps: Option) -> Self { - self.rules.push(DataTypeRule { + self.rules.push(ExecutionDataTypeRule { config: Some(Config::NumberRange(DataTypeNumberRangeRuleConfig { from, to, @@ -59,59 +57,33 @@ impl RuleBuilder { } pub fn add_regex(mut self, pattern: String) -> Self { - self.rules.push(DataTypeRule { + self.rules.push(ExecutionDataTypeRule { config: Some(Config::Regex(DataTypeRegexRuleConfig { pattern })), }); self } - pub fn add_input_types(mut self, input_types: Vec) -> Self { - self.rules.push(DataTypeRule { - config: Some(Config::InputTypes(DataTypeInputTypesRuleConfig { - input_types, - })), - }); - self - } - - pub fn add_return_type(mut self, data_type_identifier: DataTypeIdentifier) -> Self { - self.rules.push(DataTypeRule { - config: Some(Config::ReturnType(DataTypeReturnTypeRuleConfig { - data_type_identifier: Some(data_type_identifier), - })), - }); - self - } - - pub fn build(self) -> Vec { + pub fn build(self) -> Vec { self.rules } } #[cfg(test)] mod tests { + use crate::shared::helper::value::ToValue; + use super::*; - use crate::shared::{ - data_type_identifier::Type, data_type_input_types_rule_config::DataTypeInputType, - data_type_rule::Config, helper::value::ToValue, - }; - - fn to_data_type(str: &str) -> DataTypeIdentifier { - DataTypeIdentifier { - r#type: Some(Type::DataTypeIdentifier(str.into())), - } - } #[test] fn test_add_contains_key() { let rules = RuleBuilder::new() - .add_contains_key("id".into(), to_data_type("User")) + .add_contains_key("id".into(), "User") .build(); match &rules[0].config { Some(Config::ContainsKey(cfg)) => { assert_eq!(cfg.key, "id"); - assert_eq!(cfg.data_type_identifier, Some(to_data_type("User"))); + assert_eq!(cfg.data_type_identifier, String::from("User")); } _ => panic!("Expected ContainsKey config"), } @@ -119,13 +91,11 @@ mod tests { #[test] fn test_add_contains_type() { - let rules = RuleBuilder::new() - .add_contains_type(to_data_type("User")) - .build(); + let rules = RuleBuilder::new().add_contains_type("User").build(); match &rules[0].config { Some(Config::ContainsType(cfg)) => { - assert_eq!(cfg.data_type_identifier, Some(to_data_type("User"))); + assert_eq!(cfg.data_type_identifier, String::from("User")); } _ => panic!("Expected ContainsType config"), } @@ -172,80 +142,33 @@ mod tests { } } - #[test] - fn test_add_input_types() { - let input_types = vec![ - DataTypeInputType { - data_type_identifier: Some(to_data_type("Type1")), - input_identifier: "input1".into(), - }, - DataTypeInputType { - data_type_identifier: Some(to_data_type("Type2")), - input_identifier: "input2".into(), - }, - ]; - - let rules = RuleBuilder::new() - .add_input_types(input_types.clone()) - .build(); - - match &rules[0].config { - Some(Config::InputTypes(cfg)) => { - assert_eq!(cfg.input_types, input_types); - } - _ => panic!("Expected InputTypes config"), - } - } - - #[test] - fn test_add_return_type() { - let rules = RuleBuilder::new() - .add_return_type(to_data_type("Result")) - .build(); - - match &rules[0].config { - Some(Config::ReturnType(cfg)) => { - assert_eq!(cfg.data_type_identifier, Some(to_data_type("Result"))); - } - _ => panic!("Expected ReturnType config"), - } - } - #[test] fn test_add_many_rules() { let rules = RuleBuilder::new() - .add_contains_key("id".into(), to_data_type("User")) - .add_return_type(to_data_type("Result")) + .add_contains_key("id".into(), "User") .add_regex(r"^\d+$".into()) - .add_contains_key("id".into(), to_data_type("User")) + .add_contains_key("id".into(), "User") .build(); match &rules[0].config { Some(Config::ContainsKey(cfg)) => { assert_eq!(cfg.key, "id"); - assert_eq!(cfg.data_type_identifier, Some(to_data_type("User"))); + assert_eq!(cfg.data_type_identifier, String::from("User")); } _ => panic!("Expected ContainsKey config"), } match &rules[1].config { - Some(Config::ReturnType(cfg)) => { - assert_eq!(cfg.data_type_identifier, Some(to_data_type("Result"))); - } - _ => panic!("Expected ReturnType config"), - } - - match &rules[2].config { Some(Config::Regex(cfg)) => { assert_eq!(cfg.pattern, r"^\d+$"); } _ => panic!("Expected Regex config"), } - match &rules[3].config { + match &rules[2].config { Some(Config::ContainsKey(cfg)) => { assert_eq!(cfg.key, "id"); - assert_eq!(cfg.data_type_identifier, Some(to_data_type("User"))); + assert_eq!(cfg.data_type_identifier, String::from("User")); } _ => panic!("Expected ContainsKey config"), } diff --git a/proto/aquila/aquila.action.proto b/proto/aquila/aquila.action.proto index 743b2c6..d8ebd87 100644 --- a/proto/aquila/aquila.action.proto +++ b/proto/aquila/aquila.action.proto @@ -33,7 +33,7 @@ message Configuration { message ActionConfiguration { repeated shared.Translation name = 1; repeated shared.Translation description = 2; - shared.DataType type = 3; + shared.DefinitionDataType type = 3; optional shared.Value default_value = 4; } diff --git a/proto/aquila/aquila.data_type.proto b/proto/aquila/aquila.data_type.proto index 3099b61..f24d119 100644 --- a/proto/aquila/aquila.data_type.proto +++ b/proto/aquila/aquila.data_type.proto @@ -9,7 +9,7 @@ import "shared.data_type.proto"; // Request for updating a data type message DataTypeUpdateRequest { // List of data types that should be updated - repeated shared.DataType data_types = 1; + repeated shared.DefinitionDataType data_types = 1; } // Response of updating a data type diff --git a/proto/sagittarius/sagittarius.data_type.proto b/proto/sagittarius/sagittarius.data_type.proto index 9fb39a3..ad06c3a 100644 --- a/proto/sagittarius/sagittarius.data_type.proto +++ b/proto/sagittarius/sagittarius.data_type.proto @@ -9,7 +9,7 @@ import "shared.data_type.proto"; // Request for updating a data type message DataTypeUpdateRequest { // List of data types that should be updated - repeated shared.DataType data_types = 1; + repeated shared.DefinitionDataType data_types = 1; } // Response of updating a data type diff --git a/proto/sagittarius/sagittarius.flow.proto b/proto/sagittarius/sagittarius.flow.proto index e109680..f1f7414 100644 --- a/proto/sagittarius/sagittarius.flow.proto +++ b/proto/sagittarius/sagittarius.flow.proto @@ -14,7 +14,7 @@ message FlowLogonRequest { message FlowResponse { oneof data { // Updates a single flow - shared.Flow updated_flow = 1; + shared.ValidationFlow updated_flow = 1; // Deletes a single flow int64 deleted_flow_id = 2; // Replaces all flows in Aquila (only on startup and for releases) diff --git a/proto/shared/shared.data_type.proto b/proto/shared/shared.data_type.proto index f0aab51..5dbc667 100644 --- a/proto/shared/shared.data_type.proto +++ b/proto/shared/shared.data_type.proto @@ -11,7 +11,7 @@ import "shared.translation.proto"; A data type is a custom implementation that could be compared to an object It could be as simple as a primitive but can be as complex as a structured object with rules */ -message DataType { +message DefinitionDataType { enum Variant { UNKNOWN = 0; PRIMITIVE = 1; @@ -29,36 +29,64 @@ message DataType { string identifier = 2; repeated Translation name = 3; // Rules of the data type (e.g. Regex, contains...) - repeated DataTypeRule rules = 4; + repeated DefinitionDataTypeRule rules = 4; // Optional identifier it the given data type is a child of another optional DataTypeIdentifier parent_type = 5; // List of generic keys repeated string generic_keys = 6; } -message DataTypeRule { +message ExecutionDataType { + // Unique identifier of the data type + string identifier = 1; + // Rules of the data type (e.g. Regex, contains...) + repeated ExecutionDataTypeRule rules = 2; + // Optional identifier it the given data type is a child of another + optional string parent_type = 3; +} + +message DefinitionDataTypeRule { + oneof config { + DefinitionDataTypeContainsKeyRuleConfig contains_key = 1; + DefinitionDataTypeContainsTypeRuleConfig contains_type = 2; + DataTypeItemOfCollectionRuleConfig item_of_collection = 3; + DataTypeNumberRangeRuleConfig number_range = 4; + DataTypeRegexRuleConfig regex = 5; + DefinitionDataTypeInputTypesRuleConfig input_types = 6; + DefinitionDataTypeReturnTypeRuleConfig return_type = 7; + } +} + +message ExecutionDataTypeRule { oneof config { - DataTypeContainsKeyRuleConfig contains_key = 1; - DataTypeContainsTypeRuleConfig contains_type = 2; + ExecutionDataTypeContainsKeyRuleConfig contains_key = 1; + ExecutionDataTypeContainsTypeRuleConfig contains_type = 2; DataTypeItemOfCollectionRuleConfig item_of_collection = 3; DataTypeNumberRangeRuleConfig number_range = 4; DataTypeRegexRuleConfig regex = 5; - DataTypeInputTypesRuleConfig input_types = 6; - DataTypeReturnTypeRuleConfig return_type = 7; } } // Rule to check that the given key is contained in the given object -message DataTypeContainsKeyRuleConfig { +message DefinitionDataTypeContainsKeyRuleConfig { string key = 1; DataTypeIdentifier data_type_identifier = 2; } +message ExecutionDataTypeContainsKeyRuleConfig { + string key = 1; + string data_type_identifier = 2; +} + // Rule to check that the given type is contained in the given array -message DataTypeContainsTypeRuleConfig { +message DefinitionDataTypeContainsTypeRuleConfig { DataTypeIdentifier data_type_identifier = 1; } +message ExecutionDataTypeContainsTypeRuleConfig { + string data_type_identifier = 1; +} + // Rule to check that the given item is contained inside the array of items message DataTypeItemOfCollectionRuleConfig { repeated shared.Value items = 1; @@ -76,7 +104,7 @@ message DataTypeRegexRuleConfig { string pattern = 1; } -message DataTypeInputTypesRuleConfig { +message DefinitionDataTypeInputTypesRuleConfig { message DataTypeInputType { DataTypeIdentifier data_type_identifier = 1; string input_identifier = 2; @@ -85,7 +113,7 @@ message DataTypeInputTypesRuleConfig { repeated DataTypeInputType input_types = 1; } -message DataTypeReturnTypeRuleConfig { +message DefinitionDataTypeReturnTypeRuleConfig { DataTypeIdentifier data_type_identifier = 1; } diff --git a/proto/shared/shared.event.proto b/proto/shared/shared.event.proto index 96ac582..a8dec76 100644 --- a/proto/shared/shared.event.proto +++ b/proto/shared/shared.event.proto @@ -17,7 +17,7 @@ message EventDefinitionSettings { // Description of current configuration repeated Translation description = 3; // Type of setting - DataType type = 4; + DefinitionDataType type = 4; // Optional default value (primitive, string, list or json) optional shared.Value default_value = 5; } @@ -25,7 +25,7 @@ message EventDefinitionSettings { message EventDefinition { // List of settings that configures the type repeated EventDefinitionSettings settings = 1; - DataType input_type = 2; + DefinitionDataType input_type = 2; // True if the definition can be edited live bool editable = 3; } diff --git a/proto/shared/shared.flow.proto b/proto/shared/shared.flow.proto index 1d19cb7..5a31334 100644 --- a/proto/shared/shared.flow.proto +++ b/proto/shared/shared.flow.proto @@ -7,14 +7,14 @@ package shared; import "shared.struct.proto"; import "shared.data_type.proto"; -message Flow { +message ValidationFlow { // Database ID -> req. for Aquila to identify in FlowStore int64 flow_id = 1; int64 project_id = 2; // The FlowType´s identifier string type = 3; // All custom data types used in this flow - repeated shared.DataType data_types = 4; + repeated shared.ExecutionDataType data_types = 4; // These reference data_types by its identifiers, which is are string optional string input_type_identifier = 5; optional string return_type_identifier = 6; @@ -22,6 +22,13 @@ message Flow { NodeFunction starting_node = 8; } +message ExecutionFlow { + // Database ID -> req. for Aquila to identify in FlowStore + int64 flow_id = 1; + NodeFunction starting_node = 2; + optional shared.Value input_value = 3; +} + message FlowSetting { // The database id from sagittarius int64 database_id = 1; @@ -149,5 +156,5 @@ message ReferencePath { // Used in sagittarius´s FlowService because oneof can only // take in a single message type and not a repeated one message Flows { - repeated Flow flows = 1; + repeated ValidationFlow flows = 1; }