Skip to content

Commit

Permalink
Implement result, fix invalid returns (#213)
Browse files Browse the repository at this point in the history
* Implementing result

* Fixing result, don't panick when nothing is returned

* Jest tests, typescript files
  • Loading branch information
andreespirela authored Oct 28, 2022
1 parent 0555da8 commit 747b552
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 149 deletions.
18 changes: 13 additions & 5 deletions crates/cli/dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,20 @@ pub async fn dry_run(
) -> Result<(), AnyError> {
let execution = dry_run_result(port, host, protocol, file).await;

if let ExecuteResult::V8(value, validity_table, _) = execution {
if let ExecuteResult::V8(data) = execution {
let (state, validity, result) = (
data.state,
data.validity,
data.result.unwrap_or(Value::default()),
);
let value = if show_validity {
serde_json::json!({
"state": value,
"validity": validity_table
"state": state,
"validity": validity,
"result": result
})
} else {
value
state
};

if pretty_print {
Expand Down Expand Up @@ -185,7 +191,9 @@ mod tests {
)
.await;

if let ExecuteResult::V8(value, validity_table, _) = execution {
if let ExecuteResult::V8(data) = execution {
let value = data.state;
let validity_table = data.validity;
assert_eq!(
value,
serde_json::json!({
Expand Down
11 changes: 8 additions & 3 deletions crates/cli/local_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,23 @@ async fn echo(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
match execute_result {
Ok(result) => {
match result {
ExecuteResult::V8(val, validity, _) => {
ExecuteResult::V8(data) => {
let val = data.state;
let validity = data.validity;
let result = data.result.unwrap_or(serde_json::Value::Null);
if show_validity {
response_result = Some(Response::new(Body::from(
serde_json::json!({
"state": val,
"validity": validity
"validity": validity,
"result": result
}).to_string()
)));
} else {
response_result = Some(Response::new(Body::from(
serde_json::json!({
"state": val
"state": val,
"result": result
}).to_string()
)));
}
Expand Down
13 changes: 9 additions & 4 deletions crates/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ pub async fn run(
}

match execution {
ExecuteResult::V8(value, validity_table, _) => {
ExecuteResult::V8(data) => {
let state = data.state;
let validity_table = data.validity;
let result = data.result.unwrap_or(serde_json::Value::Null);

let value = if show_validity {
serde_json::json!({
"state": value,
"validity": validity_table
"state": state,
"validity": validity_table,
"result": result
})
} else {
value
state
};

if !no_print {
Expand Down
Loading

0 comments on commit 747b552

Please sign in to comment.