Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions adapter/rest/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
184 changes: 184 additions & 0 deletions adapter/rest/src/types.rs
Original file line number Diff line number Diff line change
@@ -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<FlowType> {
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<DataType> {
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"),
})),
},
],
},
]
}
1 change: 0 additions & 1 deletion definitions/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
```

## Defined DataTypes

```json
[
{
Expand Down