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
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
83 changes: 83 additions & 0 deletions src/implementation/http.rs
Original file line number Diff line number Diff line change
@@ -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<Value, RuntimeError> {
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<Value, RuntimeError> {
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 })),
})
}
12 changes: 7 additions & 5 deletions src/implementation/mod.rs
Original file line number Diff line number Diff line change
@@ -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![];
Expand All @@ -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
}
6 changes: 0 additions & 6 deletions translation/de-DE.toml

This file was deleted.

6 changes: 0 additions & 6 deletions translation/en-US.toml

This file was deleted.