Skip to content

Commit 8c52694

Browse files
committed
feat: added rest flow & data types
1 parent 484f24b commit 8c52694

File tree

3 files changed

+197
-27
lines changed

3 files changed

+197
-27
lines changed

adapter/rest/src/main.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub mod queue;
22
pub mod store;
3-
4-
use std::{future::Future, pin::Pin, sync::Arc};
3+
mod types;
54

65
use code0_flow::{
76
flow_queue::service::RabbitmqClient, flow_store::connection::create_flow_store_connection,
@@ -13,7 +12,8 @@ use http::{
1312
server::{self, AsyncHandler},
1413
};
1514
use queue::queue::handle_connection;
16-
use tucana::shared::{DataType, FlowType, Translation};
15+
use std::{future::Future, pin::Pin, sync::Arc};
16+
use types::{get_data_types, get_flow_types};
1717

1818
pub struct FlowConnectionHandler {
1919
flow_store: code0_flow::flow_store::connection::FlowStore,
@@ -61,31 +61,10 @@ async fn main() {
6161
let config = Config::from_file("./.env");
6262

6363
if !config.is_static {
64-
let rest_flow_type = FlowType {
65-
name: vec![Translation {
66-
code: "en-US".to_string(),
67-
content: "Rest Endpoint".to_string(),
68-
}],
69-
definition: None,
70-
};
71-
72-
let data_type = DataType {
73-
variant: 1,
74-
identifier: "string".to_string(),
75-
rules: vec![],
76-
name: vec![Translation {
77-
code: "en-US".to_string(),
78-
content: "String".to_string(),
79-
}],
80-
input_types: vec![],
81-
return_type: None,
82-
parent_type_identifier: None,
83-
};
84-
8564
let update_client =
8665
code0_flow::flow_definition::FlowUpdateService::from_url(config.aquila_url.clone())
87-
.with_data_types(vec![data_type])
88-
.with_flow_types(vec![rest_flow_type]);
66+
.with_data_types(get_data_types())
67+
.with_flow_types(get_flow_types());
8968

9069
update_client.send().await;
9170
}

adapter/rest/src/types.rs

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
use tucana::shared::{
2+
data_type_rule::Config, value::Kind, DataType, DataTypeContainsKeyRuleConfig,
3+
DataTypeContainsTypeRuleConfig, DataTypeRegexRuleConfig, DataTypeRule, FlowType, Translation,
4+
Value,
5+
};
6+
7+
pub fn get_flow_types() -> Vec<FlowType> {
8+
vec![FlowType {
9+
identifier: String::from("REST"),
10+
settings: vec![],
11+
input_type_identifier: Some(String::from("HTTP_REQUEST_OBJECT")),
12+
return_type_identifier: Some(String::from("HTTP_RESPONSE_OBJECT")),
13+
editable: true,
14+
name: vec![Translation {
15+
code: String::from("en-US"),
16+
content: String::from("Rest Endpoint"),
17+
}],
18+
description: vec![Translation {
19+
code: String::from("en-US"),
20+
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."),
21+
}],
22+
}]
23+
}
24+
25+
pub fn get_data_types() -> Vec<DataType> {
26+
vec![
27+
DataType {
28+
variant: 2,
29+
name: vec![Translation {
30+
code: String::from("en-US"),
31+
content: String::from("HTTP Method"),
32+
}],
33+
identifier: String::from("HTTP_METHOD"),
34+
input_types: vec![],
35+
return_type: None,
36+
parent_type_identifier: None,
37+
rules: vec![DataTypeRule {
38+
config: Some(Config::ItemOfCollection(
39+
tucana::shared::DataTypeItemOfCollectionRuleConfig {
40+
items: vec![
41+
Value {
42+
kind: Some(Kind::StringValue(String::from("GET"))),
43+
},
44+
Value {
45+
kind: Some(Kind::StringValue(String::from("POST"))),
46+
},
47+
Value {
48+
kind: Some(Kind::StringValue(String::from("PUT"))),
49+
},
50+
Value {
51+
kind: Some(Kind::StringValue(String::from("DELETE"))),
52+
},
53+
Value {
54+
kind: Some(Kind::StringValue(String::from("PATCH"))),
55+
},
56+
Value {
57+
kind: Some(Kind::StringValue(String::from("HEAD"))),
58+
},
59+
],
60+
},
61+
)),
62+
}],
63+
},
64+
DataType {
65+
variant: 2,
66+
name: vec![Translation {
67+
code: String::from("en-US"),
68+
content: String::from("HTTP Route"),
69+
}],
70+
identifier: String::from("HTTP_URL"),
71+
input_types: vec![],
72+
return_type: None,
73+
parent_type_identifier: None,
74+
rules: vec![DataTypeRule {
75+
config: Some(Config::Regex(DataTypeRegexRuleConfig {
76+
pattern: String::from(r"/^\/\w+(?:[.:~-]\w+)*(?:\/\w+(?:[.:~-]\w+)*)*$/"),
77+
})),
78+
}],
79+
},
80+
DataType {
81+
variant: 5,
82+
name: vec![Translation {
83+
code: String::from("en-US"),
84+
content: String::from("HTTP Headers"),
85+
}],
86+
identifier: String::from("HTTP_HEADER_MAP"),
87+
input_types: vec![],
88+
return_type: None,
89+
parent_type_identifier: Some(String::from("ARRAY")),
90+
rules: vec![DataTypeRule {
91+
config: Some(Config::ContainsType(DataTypeContainsTypeRuleConfig {
92+
data_type_identifier: String::from("HTTP_HEADER_ENTRY"),
93+
})),
94+
}],
95+
},
96+
DataType {
97+
variant: 3,
98+
name: vec![Translation {
99+
code: String::from("en-US"),
100+
content: String::from("HTTP Header Entry"),
101+
}],
102+
identifier: String::from("HTTP_HEADER_ENTRY"),
103+
input_types: vec![],
104+
return_type: None,
105+
parent_type_identifier: Some(String::from("OBJECT")),
106+
rules: vec![
107+
DataTypeRule {
108+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
109+
key: String::from("key"),
110+
data_type_identifier: String::from("TEXT"),
111+
})),
112+
},
113+
DataTypeRule {
114+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
115+
key: String::from("value"),
116+
data_type_identifier: String::from("TEXT"),
117+
})),
118+
},
119+
],
120+
},
121+
DataType {
122+
variant: 3,
123+
name: vec![Translation {
124+
code: String::from("en-US"),
125+
content: String::from("HTTP Request"),
126+
}],
127+
identifier: String::from("HTTP_REQUEST_OBJECT"),
128+
input_types: vec![],
129+
return_type: None,
130+
parent_type_identifier: Some(String::from("OBJECT")),
131+
rules: vec![
132+
DataTypeRule {
133+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
134+
key: String::from("method"),
135+
data_type_identifier: String::from("HTTP_METHOD"),
136+
})),
137+
},
138+
DataTypeRule {
139+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
140+
key: String::from("url"),
141+
data_type_identifier: String::from("HTTP_URL"),
142+
})),
143+
},
144+
DataTypeRule {
145+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
146+
key: String::from("body"),
147+
data_type_identifier: String::from("OBJECT"),
148+
})),
149+
},
150+
DataTypeRule {
151+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
152+
key: String::from("headers"),
153+
data_type_identifier: String::from("HTTP_HEADER_MAP"),
154+
})),
155+
},
156+
],
157+
},
158+
DataType {
159+
variant: 3,
160+
name: vec![Translation {
161+
code: String::from("en-US"),
162+
content: String::from("HTTP Response"),
163+
}],
164+
identifier: String::from("HTTP_RESPONSE_OBJECT"),
165+
input_types: vec![],
166+
return_type: None,
167+
parent_type_identifier: Some(String::from("OBJECT")),
168+
rules: vec![
169+
DataTypeRule {
170+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
171+
key: String::from("body"),
172+
data_type_identifier: String::from("OBJECT"),
173+
})),
174+
},
175+
DataTypeRule {
176+
config: Some(Config::ContainsKey(DataTypeContainsKeyRuleConfig {
177+
key: String::from("headers"),
178+
data_type_identifier: String::from("HTTP_HEADER_MAP"),
179+
})),
180+
},
181+
],
182+
},
183+
]
184+
}

definitions/rest.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
```
2323

2424
## Defined DataTypes
25-
25+
Unknown = 0,
26+
Primitive = 1,
27+
Type = 2,
28+
Object = 3,
29+
Datatype = 4,
30+
Array = 5,
31+
Generic = 6,
32+
Function = 7,
2633
```json
2734
[
2835
{

0 commit comments

Comments
 (0)