mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
Implicitly flatten array with one JValue according to a function signature (#54)
This commit is contained in:
parent
725f6e65f3
commit
f022a2dec4
60
Cargo.lock
generated
60
Cargo.lock
generated
@ -41,7 +41,7 @@ checksum = "68803225a7b13e47191bab76f2687382b60d259e8cf37f6e1893658b84bb9479"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aquamarine-vm"
|
name = "aquamarine-vm"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-faas",
|
"fluence-faas",
|
||||||
"maplit",
|
"maplit",
|
||||||
@ -722,6 +722,15 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
||||||
|
dependencies = [
|
||||||
|
"fluence-sdk-macro 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
|
"fluence-sdk-main 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence"
|
name = "fluence"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
@ -732,18 +741,9 @@ dependencies = [
|
|||||||
"fluence-sdk-main 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-main 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fluence"
|
|
||||||
version = "0.2.13"
|
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
|
||||||
dependencies = [
|
|
||||||
"fluence-sdk-macro 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
|
||||||
"fluence-sdk-main 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-app-service"
|
name = "fluence-app-service"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-faas",
|
"fluence-faas",
|
||||||
"log",
|
"log",
|
||||||
@ -757,7 +757,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-faas"
|
name = "fluence-faas"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cmd_lib",
|
"cmd_lib",
|
||||||
"env_logger 0.7.1",
|
"env_logger 0.7.1",
|
||||||
@ -779,6 +779,14 @@ dependencies = [
|
|||||||
"wasmer-wasi-fl",
|
"wasmer-wasi-fl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence-sdk-macro"
|
||||||
|
version = "0.2.13"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
||||||
|
dependencies = [
|
||||||
|
"fluence-sdk-wit 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-macro"
|
name = "fluence-sdk-macro"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
@ -789,11 +797,13 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-macro"
|
name = "fluence-sdk-main"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-wit 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-macro 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -807,21 +817,10 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fluence-sdk-main"
|
|
||||||
version = "0.2.13"
|
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
|
||||||
dependencies = [
|
|
||||||
"fluence-sdk-macro 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
|
||||||
"log",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-wit"
|
name = "fluence-sdk-wit"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
||||||
checksum = "8da5f51cddeae52ff5b91d1a5d8be90e54629f4887f89f8d7501b829b374fe6a"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -834,7 +833,8 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-wit"
|
name = "fluence-sdk-wit"
|
||||||
version = "0.2.13"
|
version = "0.2.13"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#71591f412cb65879d74e8c38838e827ab74d8802"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8da5f51cddeae52ff5b91d1a5d8be90e54629f4887f89f8d7501b829b374fe6a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -877,7 +877,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "frepl"
|
name = "frepl"
|
||||||
version = "0.1.22"
|
version = "0.1.23"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
@ -2205,9 +2205,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "stepper-interface"
|
name = "stepper-interface"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/fluencelabs/aquamarine#b967a63abca9742d6764e9b27926025d5e2b2efb"
|
source = "git+https://github.com/fluencelabs/aquamarine#724117547205d8ccc742d325b542af8f3df801b8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence 0.2.13 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde",
|
"serde",
|
||||||
"wasmer-interface-types-fl",
|
"wasmer-interface-types-fl",
|
||||||
]
|
]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "aquamarine-vm"
|
name = "aquamarine-vm"
|
||||||
description = "Fluence Aquamarine VM"
|
description = "Fluence Aquamarine VM"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
@ -11,7 +11,7 @@ name = "aquamarine_vm"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-faas = { path = "../fluence-faas", version = "0.1.17" }
|
fluence-faas = { path = "../fluence-faas", version = "0.1.18" }
|
||||||
stepper-interface = { git = "https://github.com/fluencelabs/aquamarine", branch = "master" }
|
stepper-interface = { git = "https://github.com/fluencelabs/aquamarine", branch = "master" }
|
||||||
|
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fluence-app-service"
|
name = "fluence-app-service"
|
||||||
description = "Fluence Application Service"
|
description = "Fluence Application Service"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-faas = { path = "../fluence-faas", version = "0.1.17" }
|
fluence-faas = { path = "../fluence-faas", version = "0.1.18" }
|
||||||
|
|
||||||
maplit = "1.0.2"
|
maplit = "1.0.2"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fluence-faas"
|
name = "fluence-faas"
|
||||||
description = "Fluence FaaS"
|
description = "Fluence FaaS"
|
||||||
version = "0.1.17"
|
version = "0.1.18"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
@ -37,8 +37,8 @@ pub(crate) fn json_to_ivalues<'a, 'b>(
|
|||||||
JValue::Array(json_array) => {
|
JValue::Array(json_array) => {
|
||||||
json_array_to_ivalues(json_array, arg_types.map(|arg| arg.1), &record_types)?
|
json_array_to_ivalues(json_array, arg_types.map(|arg| arg.1), &record_types)?
|
||||||
}
|
}
|
||||||
JValue::Null => json_null_to_ivalue(arg_types)?,
|
JValue::Null => json_null_to_ivalues(arg_types)?,
|
||||||
json_value => json_value_to_ivalue(json_value, arg_types)?,
|
json_value => json_value_to_ivalues(json_value, arg_types)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ivalues)
|
Ok(ivalues)
|
||||||
@ -95,23 +95,27 @@ fn json_array_to_ivalues<'a, 'b>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert json value (Number, String or Bool) to an array of ivalues according to the supplied argument types.
|
/// Convert json value (Number, String or Bool) to an array of ivalues according to the supplied argument types.
|
||||||
fn json_value_to_ivalue<'a>(
|
fn json_value_to_ivalues<'a>(
|
||||||
json_value: JValue,
|
json_value: JValue,
|
||||||
mut arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
|
mut arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
|
||||||
) -> Result<Vec<IValue>> {
|
) -> Result<Vec<IValue>> {
|
||||||
if arg_types.len() != 1 {
|
if arg_types.len() != 1 {
|
||||||
return Err(ArgDeError(format!(
|
return Err(ArgDeError(format!(
|
||||||
"the called function has the following signature: {:?}, but only one string argument is provided",
|
"called function has the following signature: '{:?}', and it isn't suitable for an argument '{:?}' provided",
|
||||||
arg_types.collect::<Vec<_>>()
|
arg_types.collect::<Vec<_>>(),
|
||||||
|
json_value,
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ivalue = jvalue_to_ivalue(json_value, arg_types.next().unwrap().1, &HashMap::new())?;
|
// unwrap is safe here because iterator size's been checked
|
||||||
|
let arg_type = arg_types.next().unwrap().1;
|
||||||
|
let ivalue = jvalue_to_ivalue(json_value, arg_type, &HashMap::new())?;
|
||||||
|
|
||||||
Ok(vec![ivalue])
|
Ok(vec![ivalue])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert json Null to an empty array of ivalues.
|
/// Convert json Null to an empty array of ivalues.
|
||||||
fn json_null_to_ivalue<'a>(
|
fn json_null_to_ivalues<'a>(
|
||||||
arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
|
arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
|
||||||
) -> Result<Vec<IValue>> {
|
) -> Result<Vec<IValue>> {
|
||||||
if arg_types.len() != 0 {
|
if arg_types.len() != 0 {
|
||||||
@ -129,12 +133,17 @@ fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &RecordTypes) -> R
|
|||||||
macro_rules! to_ivalue(
|
macro_rules! to_ivalue(
|
||||||
($json_value:expr, $ty:ident) => {
|
($json_value:expr, $ty:ident) => {
|
||||||
{
|
{
|
||||||
let value = serde_json::from_value($json_value).map_err(|e| {
|
let value = match $json_value {
|
||||||
ArgDeError(format!(
|
// if there is an array with only one element try to implicitly flatten it,
|
||||||
"error {:?} occurred while deserialize output result to a json value",
|
// this is needed mostly because jsonpath lib returns Vec<&JValue> and
|
||||||
e
|
// could be changed in future
|
||||||
))
|
JValue::Array(mut json_array) if json_array.len() == 1 => {
|
||||||
})?;
|
serde_json::from_value(json_array.remove(0))
|
||||||
|
},
|
||||||
|
jvalue => serde_json::from_value(jvalue),
|
||||||
|
}.map_err(|e|
|
||||||
|
ArgDeError(format!("error {:?} occurred while deserialize output result to a json value",e))
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(IValue::$ty(value))
|
Ok(IValue::$ty(value))
|
||||||
}
|
}
|
||||||
|
@ -359,6 +359,9 @@ pub fn i32_type() {
|
|||||||
|
|
||||||
let result4 = call_faas!(faas, "arguments_passing_pure", "i32_type", json!(1));
|
let result4 = call_faas!(faas, "arguments_passing_pure", "i32_type", json!(1));
|
||||||
assert_eq!(result4, right_result);
|
assert_eq!(result4, right_result);
|
||||||
|
|
||||||
|
let result5 = call_faas!(faas, "arguments_passing_pure", "i32_type", json!([[1]]));
|
||||||
|
assert_eq!(result5, right_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -393,6 +396,9 @@ pub fn i64_type() {
|
|||||||
|
|
||||||
let result4 = call_faas!(faas, "arguments_passing_pure", "i64_type", json!(1));
|
let result4 = call_faas!(faas, "arguments_passing_pure", "i64_type", json!(1));
|
||||||
assert_eq!(result4, right_result);
|
assert_eq!(result4, right_result);
|
||||||
|
|
||||||
|
let result5 = call_faas!(faas, "arguments_passing_pure", "i64_type", json!([1]));
|
||||||
|
assert_eq!(result5, right_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -607,6 +613,14 @@ pub fn bytearray_type() {
|
|||||||
json!([[0x13, 0x37]])
|
json!([[0x13, 0x37]])
|
||||||
);
|
);
|
||||||
assert_eq!(result4, right_result);
|
assert_eq!(result4, right_result);
|
||||||
|
|
||||||
|
let result5 = call_faas!(
|
||||||
|
faas,
|
||||||
|
"arguments_passing_pure",
|
||||||
|
"bytearray_type",
|
||||||
|
json!([[0x13]])
|
||||||
|
);
|
||||||
|
assert_eq!(result5, json!([0x13, 1, 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "frepl"
|
name = "frepl"
|
||||||
description = "Fluence FCE REPL intended for testing purposes"
|
description = "Fluence FCE REPL intended for testing purposes"
|
||||||
version = "0.1.22"
|
version = "0.1.23"
|
||||||
authors = ["Fluence Labs"]
|
authors = ["Fluence Labs"]
|
||||||
repository = "https://github.com/fluencelabs/fce/tools/repl"
|
repository = "https://github.com/fluencelabs/fce/tools/repl"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
@ -12,7 +12,7 @@ name = "fce-repl"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-app-service = { path = "../../fluence-app-service", version = "0.1.17", features = ["raw-module-api"] }
|
fluence-app-service = { path = "../../fluence-app-service", version = "0.1.18", features = ["raw-module-api"] }
|
||||||
fluence-sdk-main = { version = "=0.2.13", features = ["logger"] }
|
fluence-sdk-main = { version = "=0.2.13", features = ["logger"] }
|
||||||
|
|
||||||
anyhow = "1.0.31"
|
anyhow = "1.0.31"
|
||||||
|
Loading…
Reference in New Issue
Block a user