Skip to content

Commit 039a2b3

Browse files
Merge pull request #179 from code0-tech/renovate/tucana-0.x
Update Rust crate tucana to 0.0.65
2 parents da57346 + cde4ad7 commit 039a2b3

3 files changed

Lines changed: 18 additions & 48 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2024"
88

99
[workspace.dependencies]
1010
code0-flow = { version = "0.0.28" }
11-
tucana = { version = "0.0.62", features = ["aquila"] }
11+
tucana = { version = "0.0.65", features = ["aquila"] }
1212
serde_json = { version = "1.0.138" }
1313
log = "0.4.27"
1414
env_logger = "0.11.8"

adapter/rest/src/main.rs

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use hyper::{
1414
server::conn::http1,
1515
};
1616
use hyper_util::rt::TokioIo;
17-
use serde_json::{Map, Number, Value as J};
1817
use std::collections::HashMap;
1918
use std::convert::Infallible;
2019
use std::net::SocketAddr;
@@ -82,45 +81,6 @@ fn json_error(status: StatusCode, msg: &str) -> Response<Full<Bytes>> {
8281
.unwrap()
8382
}
8483

85-
fn pb_value_to_json(v: &Value) -> serde_json::Value {
86-
match v.kind.as_ref() {
87-
None => J::Null,
88-
89-
Some(Kind::NullValue(_)) => J::Null,
90-
91-
Some(Kind::BoolValue(b)) => J::Bool(*b),
92-
93-
Some(Kind::StringValue(s)) => J::String(s.clone()),
94-
95-
Some(Kind::NumberValue(n)) => {
96-
if let Some(num) = Number::from_f64(*n) {
97-
J::Number(num)
98-
} else if n.is_nan() {
99-
J::String("NaN".to_string())
100-
} else if n.is_infinite() {
101-
if n.is_sign_positive() {
102-
J::String("Infinity".to_string())
103-
} else {
104-
J::String("-Infinity".to_string())
105-
}
106-
} else {
107-
// Fallback for unexpected cases where from_f64 returns None.
108-
J::Null
109-
}
110-
}
111-
112-
Some(Kind::ListValue(lv)) => J::Array(lv.values.iter().map(pb_value_to_json).collect()),
113-
114-
Some(Kind::StructValue(st)) => {
115-
let mut obj = Map::new();
116-
for (k, v) in &st.fields {
117-
obj.insert(k.clone(), pb_value_to_json(v));
118-
}
119-
J::Object(obj)
120-
}
121-
}
122-
}
123-
12484
fn build_response(
12585
status: StatusCode,
12686
headers: HashMap<String, String>,
@@ -243,7 +203,7 @@ async fn execute_flow_to_hyper_response(
243203
};
244204

245205
// payload -> json bytes
246-
let json_val = pb_value_to_json(payload_val);
206+
let json_val = tucana::shared::helper::value::to_json_value(payload_val.clone());
247207
let json = serde_json::to_vec_pretty(&json_val).unwrap_or_else(|err| {
248208
let fallback = serde_json::json!({
249209
"error": format!("Serialization failed: {}", err),
@@ -252,8 +212,18 @@ async fn execute_flow_to_hyper_response(
252212
.unwrap_or_else(|_| br#"{"error":"Serialization failed"}"#.to_vec())
253213
});
254214

215+
let http_code = match code.number {
216+
Some(num) => match num {
217+
tucana::shared::number_value::Number::Integer(int) => int as u16,
218+
tucana::shared::number_value::Number::Float(float) => float as u16,
219+
},
220+
None => {
221+
return json_error(StatusCode::INTERNAL_SERVER_ERROR, "Flow execution failed");
222+
}
223+
};
224+
255225
let status =
256-
StatusCode::from_u16(code as u16).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
226+
StatusCode::from_u16(http_code).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR);
257227
build_response(status, http_headers, json)
258228
}
259229
None => {

0 commit comments

Comments
 (0)