diff --git a/Cargo.lock b/Cargo.lock index 8a6f607..f919c69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1707,8 +1707,6 @@ dependencies = [ "log", "prost", "rand 0.9.2", - "serde", - "serde_json", "tokio", "tonic", "tonic-health", diff --git a/Cargo.toml b/Cargo.toml index c413cd1..1a93fb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,6 @@ edition = "2024" [dependencies] code0-flow = { version = "0.0.14" } tucana = { version = "0.0.33" } -serde = "1.0.219" -serde_json = "1.0.140" tokio = { version = "1.44.1", features = ["rt-multi-thread"] } log = "0.4.27" futures-lite = "2.6.0" diff --git a/src/implementation/http.rs b/src/implementation/http.rs new file mode 100644 index 0000000..a09a31f --- /dev/null +++ b/src/implementation/http.rs @@ -0,0 +1,83 @@ +use tucana::shared::{Struct, Value}; +use tucana::shared::value::Kind; +use crate::context::Context; +use crate::error::RuntimeError; +use crate::registry::HandlerFn; + +pub fn collect_http_functions() -> Vec<(&'static str, HandlerFn)> { + vec![ + ("http::request::create", create_request), + ("http::response::create", create_response), + ] +} + +fn create_request(values: &[Value], _ctx: &mut Context) -> Result { + let [Value { + kind: Some(Kind::StringValue(http_method)), + }, + Value { + kind: Some(Kind::StructValue(headers)), + }, + Value { + kind: Some(Kind::StringValue(http_url)), + }, + payload + ] = values + else { + return Err(RuntimeError::simple( + "InvalidArgumentRuntimeError", + format!("Expected [method, headers, url, payload] but received {:?}", values), + )); + }; + + let mut fields = std::collections::HashMap::new(); + + fields.insert("method".to_string(), Value { + kind: Some(Kind::StringValue(http_method.clone())), + }); + + fields.insert("url".to_string(), Value { + kind: Some(Kind::StringValue(http_url.clone())), + }); + + fields.insert("headers".to_string(),Value { + kind: Some(Kind::StructValue(headers.clone())), + }); + fields.insert("body".to_string(), payload.clone()); + + Ok(Value { + kind: Some(Kind::StructValue(Struct { fields })), + }) +} + +fn create_response(values: &[Value], _ctx: &mut Context) -> Result { + let [Value { + kind: Some(Kind::NumberValue(http_status_code)), + }, + Value { + kind: Some(Kind::StructValue(headers)), + }, + payload + ] = values + else { + return Err(RuntimeError::simple( + "InvalidArgumentRuntimeError", + format!("Expected [http_status_code, headers, payload] but received {:?}", values), + )); + }; + + let mut fields = std::collections::HashMap::new(); + + fields.insert("method".to_string(), Value { + kind: Some(Kind::NumberValue(http_status_code.clone())), + }); + + fields.insert("headers".to_string(),Value { + kind: Some(Kind::StructValue(headers.clone())), + }); + fields.insert("body".to_string(), payload.clone()); + + Ok(Value { + kind: Some(Kind::StructValue(Struct { fields })), + }) +} \ No newline at end of file diff --git a/src/implementation/mod.rs b/src/implementation/mod.rs index 0c1ad93..4666337 100644 --- a/src/implementation/mod.rs +++ b/src/implementation/mod.rs @@ -1,11 +1,12 @@ use crate::registry::HandlerFn; -pub mod array; -pub mod boolean; +mod array; +mod boolean; mod control; -pub mod number; -pub mod object; -pub mod text; +mod number; +mod object; +mod text; +mod http; pub fn collect() -> Vec<(&'static str, HandlerFn)> { let mut result = vec![]; @@ -16,6 +17,7 @@ pub fn collect() -> Vec<(&'static str, HandlerFn)> { result.extend(text::collect_text_functions()); result.extend(object::collect_object_functions()); result.extend(control::collect_control_functions()); + result.extend(http::collect_http_functions()); result } diff --git a/translation/de-DE.toml b/translation/de-DE.toml deleted file mode 100644 index cb12939..0000000 --- a/translation/de-DE.toml +++ /dev/null @@ -1,6 +0,0 @@ -greeting = "Guten Tag!" -farewell = "Auf Wiedersehen!" - -[debug] -enabled = "Ja" -level = "Information" diff --git a/translation/en-US.toml b/translation/en-US.toml deleted file mode 100644 index e1c2a58..0000000 --- a/translation/en-US.toml +++ /dev/null @@ -1,6 +0,0 @@ -greeting = "Hello There!" -farewell = "Goodbye!" - -[debug] -enabled = "yes" -level = "information"