diff --git a/adapter/rest/src/main.rs b/adapter/rest/src/main.rs index 1bcd33e..152b84a 100644 --- a/adapter/rest/src/main.rs +++ b/adapter/rest/src/main.rs @@ -1,7 +1,6 @@ pub mod queue; pub mod store; - -use std::{future::Future, pin::Pin, sync::Arc}; +mod types; use code0_flow::{ flow_queue::service::RabbitmqClient, flow_store::connection::create_flow_store_connection, @@ -13,7 +12,8 @@ use http::{ server::{self, AsyncHandler}, }; use queue::queue::handle_connection; -use tucana::shared::{DataType, FlowType, Translation}; +use std::{future::Future, pin::Pin, sync::Arc}; +use types::{get_data_types, get_flow_types}; pub struct FlowConnectionHandler { flow_store: code0_flow::flow_store::connection::FlowStore, @@ -61,31 +61,10 @@ async fn main() { let config = Config::from_file("./.env"); if !config.is_static { - let rest_flow_type = FlowType { - name: vec![Translation { - code: "en-US".to_string(), - content: "Rest Endpoint".to_string(), - }], - definition: None, - }; - - let data_type = DataType { - variant: 1, - identifier: "string".to_string(), - rules: vec![], - name: vec![Translation { - code: "en-US".to_string(), - content: "String".to_string(), - }], - input_types: vec![], - return_type: None, - parent_type_identifier: None, - }; - let update_client = code0_flow::flow_definition::FlowUpdateService::from_url(config.aquila_url.clone()) - .with_data_types(vec![data_type]) - .with_flow_types(vec![rest_flow_type]); + .with_data_types(get_data_types()) + .with_flow_types(get_flow_types()); update_client.send().await; } diff --git a/adapter/rest/src/types.rs b/adapter/rest/src/types.rs new file mode 100644 index 0000000..670ecac --- /dev/null +++ b/adapter/rest/src/types.rs @@ -0,0 +1,184 @@ +use tucana::shared::{ + data_type_rule::Config, value::Kind, DataType, DataTypeContainsKeyRuleConfig, + DataTypeContainsTypeRuleConfig, DataTypeRegexRuleConfig, DataTypeRule, FlowType, Translation, + Value, +}; + +pub fn get_flow_types() -> Vec { + vec![FlowType { + identifier: String::from("REST"), + settings: vec![], + input_type_identifier: Some(String::from("HTTP_REQUEST_OBJECT")), + return_type_identifier: Some(String::from("HTTP_RESPONSE_OBJECT")), + editable: true, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("Rest Endpoint"), + }], + description: vec![Translation { + code: String::from("en-US"), + content: String::from("A REST API is a web service that lets clients interact with data on a server using standard HTTP methods like GET, POST, PUT, and DELETE, usually returning results in JSON format."), + }], + }] +} + +pub fn get_data_types() -> Vec { + vec![ + DataType { + variant: 2, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Method"), + }], + identifier: String::from("HTTP_METHOD"), + input_types: vec![], + return_type: None, + parent_type_identifier: None, + rules: vec![DataTypeRule { + config: Some(Config::ItemOfCollection( + tucana::shared::DataTypeItemOfCollectionRuleConfig { + items: vec![ + Value { + kind: Some(Kind::StringValue(String::from("GET"))), + }, + Value { + kind: Some(Kind::StringValue(String::from("POST"))), + }, + Value { + kind: Some(Kind::StringValue(String::from("PUT"))), + }, + Value { + kind: Some(Kind::StringValue(String::from("DELETE"))), + }, + Value { + kind: Some(Kind::StringValue(String::from("PATCH"))), + }, + Value { + kind: Some(Kind::StringValue(String::from("HEAD"))), + }, + ], + }, + )), + }], + }, + DataType { + variant: 2, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Route"), + }], + identifier: String::from("HTTP_URL"), + input_types: vec![], + return_type: None, + parent_type_identifier: None, + rules: vec![DataTypeRule { + config: Some(Config::Regex(DataTypeRegexRuleConfig { + pattern: String::from(r"/^\/\w+(?:[.:~-]\w+)*(?:\/\w+(?:[.:~-]\w+)*)*$/"), + })), + }], + }, + DataType { + variant: 5, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Headers"), + }], + identifier: String::from("HTTP_HEADER_MAP"), + input_types: vec![], + return_type: None, + parent_type_identifier: Some(String::from("ARRAY")), + rules: vec![DataTypeRule { + config: Some(Config::ContainsType(DataTypeContainsTypeRuleConfig { + data_type_identifier: String::from("HTTP_HEADER_ENTRY"), + })), + }], + }, + DataType { + variant: 3, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Header Entry"), + }], + identifier: String::from("HTTP_HEADER_ENTRY"), + input_types: vec![], + return_type: None, + parent_type_identifier: Some(String::from("OBJECT")), + rules: vec![ + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("key"), + data_type_identifier: String::from("TEXT"), + })), + }, + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("value"), + data_type_identifier: String::from("TEXT"), + })), + }, + ], + }, + DataType { + variant: 3, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Request"), + }], + identifier: String::from("HTTP_REQUEST_OBJECT"), + input_types: vec![], + return_type: None, + parent_type_identifier: Some(String::from("OBJECT")), + rules: vec![ + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("method"), + data_type_identifier: String::from("HTTP_METHOD"), + })), + }, + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("url"), + data_type_identifier: String::from("HTTP_URL"), + })), + }, + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("body"), + data_type_identifier: String::from("OBJECT"), + })), + }, + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("headers"), + data_type_identifier: String::from("HTTP_HEADER_MAP"), + })), + }, + ], + }, + DataType { + variant: 3, + name: vec![Translation { + code: String::from("en-US"), + content: String::from("HTTP Response"), + }], + identifier: String::from("HTTP_RESPONSE_OBJECT"), + input_types: vec![], + return_type: None, + parent_type_identifier: Some(String::from("OBJECT")), + rules: vec![ + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("body"), + data_type_identifier: String::from("OBJECT"), + })), + }, + DataTypeRule { + config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig { + key: String::from("headers"), + data_type_identifier: String::from("HTTP_HEADER_MAP"), + })), + }, + ], + }, + ] +} diff --git a/definitions/rest.md b/definitions/rest.md index 97d3e39..c17727c 100644 --- a/definitions/rest.md +++ b/definitions/rest.md @@ -22,7 +22,6 @@ ``` ## Defined DataTypes - ```json [ {