Skip to content

Commit 97a417b

Browse files
author
nicosammito
committed
Merge remote-tracking branch 'origin/main'
2 parents de1202f + 03cbd98 commit 97a417b

5 files changed

Lines changed: 68 additions & 34 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ version = "0.0.0"
77
edition = "2024"
88

99
[workspace.dependencies]
10-
code0-flow = { version = "0.0.25" }
11-
tucana = { version = "0.0.52", features = ["aquila"] }
10+
code0-flow = { version = "0.0.27" }
11+
tucana = { version = "0.0.56", features = ["aquila"] }
1212
serde_json = { version = "1.0.138" }
1313
log = "0.4.27"
1414
env_logger = "0.11.8"

adapter/rest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rest"
3-
version = "0.1.0"
3+
version.workspace = true
44
edition.workspace = true
55

66
[dependencies]

adapter/rest/src/main.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use hyper::{
1414
server::conn::http1,
1515
};
1616
use hyper_util::rt::TokioIo;
17+
use serde_json::{Map, Number, Value as J};
1718
use std::collections::HashMap;
1819
use std::convert::Infallible;
1920
use std::net::SocketAddr;
@@ -58,6 +59,45 @@ fn json_error(status: StatusCode, msg: &str) -> Response<Full<Bytes>> {
5859
.unwrap()
5960
}
6061

62+
fn pb_value_to_json(v: &Value) -> serde_json::Value {
63+
match v.kind.as_ref() {
64+
None => J::Null,
65+
66+
Some(Kind::NullValue(_)) => J::Null,
67+
68+
Some(Kind::BoolValue(b)) => J::Bool(*b),
69+
70+
Some(Kind::StringValue(s)) => J::String(s.clone()),
71+
72+
Some(Kind::NumberValue(n)) => {
73+
if let Some(num) = Number::from_f64(*n) {
74+
J::Number(num)
75+
} else if n.is_nan() {
76+
J::String("NaN".to_string())
77+
} else if n.is_infinite() {
78+
if n.is_sign_positive() {
79+
J::String("Infinity".to_string())
80+
} else {
81+
J::String("-Infinity".to_string())
82+
}
83+
} else {
84+
// Fallback for unexpected cases where from_f64 returns None.
85+
J::Null
86+
}
87+
}
88+
89+
Some(Kind::ListValue(lv)) => J::Array(lv.values.iter().map(pb_value_to_json).collect()),
90+
91+
Some(Kind::StructValue(st)) => {
92+
let mut obj = Map::new();
93+
for (k, v) in &st.fields {
94+
obj.insert(k.clone(), pb_value_to_json(v));
95+
}
96+
J::Object(obj)
97+
}
98+
}
99+
}
100+
61101
fn build_response(
62102
status: StatusCode,
63103
headers: HashMap<String, String>,
@@ -210,8 +250,13 @@ async fn execute_flow_to_hyper_response(
210250
};
211251

212252
// payload -> json bytes
213-
let json = serde_json::to_vec_pretty(payload_val).unwrap_or_else(|err| {
214-
format!(r#"{{"error":"Serialization failed: {}"}}"#, err).into_bytes()
253+
let json_val = pb_value_to_json(payload_val);
254+
let json = serde_json::to_vec_pretty(&json_val).unwrap_or_else(|err| {
255+
let fallback = serde_json::json!({
256+
"error": format!("Serialization failed: {}", err),
257+
});
258+
serde_json::to_vec(&fallback)
259+
.unwrap_or_else(|_| br#"{"error":"Serialization failed"}"#.to_vec())
215260
});
216261

217262
let status =

crates/base/src/store.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::traits::IdentifiableFlow;
22
use async_nats::jetstream::kv::Config;
3-
use code0_flow::flow_validator::verify_flow;
43
use futures_lite::StreamExt;
54
use prost::Message;
65
use tucana::shared::{ExecutionFlow, ValidationFlow, Value};
@@ -119,17 +118,7 @@ impl AdapterStore {
119118
flow: ValidationFlow,
120119
input_value: Option<Value>,
121120
) -> Option<Value> {
122-
if let Some(body) = input_value.clone() {
123-
let verify_result = verify_flow(flow.clone(), body);
124-
125-
match verify_result {
126-
Ok(()) => {}
127-
Err(_err) => {
128-
return None;
129-
}
130-
};
131-
}
132-
121+
// TODO: Replace body vaidation with triangulus when its ready
133122
let uuid = uuid::Uuid::new_v4().to_string();
134123
let flow_id = flow.flow_id;
135124
let execution_flow: ExecutionFlow = Self::convert_validation_flow(flow, input_value);

0 commit comments

Comments
 (0)