mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 06:45:32 +00:00
Return only facade interface in AppService get_interface (#44)
This commit is contained in:
parent
afa612a563
commit
1094d8e504
177
Cargo.lock
generated
177
Cargo.lock
generated
@ -96,9 +96,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "backtrace"
|
||||
version = "0.3.54"
|
||||
version = "0.3.55"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2baad346b2d4e94a24347adeee9c7a93f412ee94b9cc26e5b59dea23848e9f28"
|
||||
checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"cfg-if 1.0.0",
|
||||
@ -114,6 +114,12 @@ version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "1.3.1"
|
||||
@ -189,9 +195,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.62"
|
||||
version = "1.0.65"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40"
|
||||
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
@ -248,6 +254,16 @@ version = "0.7.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "475bd7aa7680b4ed8f6bb59745e882bcbaeb39326532bb79ffb1716480d9a274"
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const_fn"
|
||||
version = "0.4.3"
|
||||
@ -538,12 +554,6 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
@ -729,15 +739,6 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.9"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
"fluence-sdk-main 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.9"
|
||||
@ -748,6 +749,15 @@ dependencies = [
|
||||
"fluence-sdk-main 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence"
|
||||
version = "0.2.9"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
"fluence-sdk-main 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-app-service"
|
||||
version = "0.1.12"
|
||||
@ -786,14 +796,6 @@ dependencies = [
|
||||
"wasmer-wasi-fl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.9"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"fluence-sdk-wit 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.9"
|
||||
@ -804,13 +806,11 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-main"
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.2.9"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
"log",
|
||||
"serde",
|
||||
"fluence-sdk-wit 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -825,9 +825,20 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.2.9"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||
"log",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9c68c4d07e821e1be23b01c278acdae4e825d03c46879f453426ea3160b3e25"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -840,8 +851,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9c68c4d07e821e1be23b01c278acdae4e825d03c46879f453426ea3160b3e25"
|
||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -950,7 +960,7 @@ checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project 1.0.1",
|
||||
"pin-project 1.0.2",
|
||||
"pin-utils",
|
||||
]
|
||||
|
||||
@ -1144,7 +1154,7 @@ dependencies = [
|
||||
"httparse",
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project 1.0.1",
|
||||
"pin-project 1.0.2",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
@ -1678,11 +1688,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee41d838744f60d959d7074e3afb6b35c7456d0f61cad38a24e35e6553f73841"
|
||||
checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7"
|
||||
dependencies = [
|
||||
"pin-project-internal 1.0.1",
|
||||
"pin-project-internal 1.0.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1698,9 +1708,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-internal"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81a4ffa594b66bff340084d4081df649a7dc049ac8d7fc458d8e628bfbbb2f86"
|
||||
checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1713,6 +1723,12 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
version = "0.1.0"
|
||||
@ -1917,11 +1933,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.10.8"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9eaa17ac5d7b838b7503d118fa16ad88f440498bf9ffe5424e621f93190d61e"
|
||||
checksum = "fb15d6255c792356a0f578d8a645c677904dc02e862bebe2ecc18e0c01b9a0ce"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.13.0",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-core",
|
||||
@ -1938,7 +1954,7 @@ dependencies = [
|
||||
"mime_guess",
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.2.0",
|
||||
"serde",
|
||||
"serde_urlencoded",
|
||||
"tokio",
|
||||
@ -1946,6 +1962,7 @@ dependencies = [
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-test",
|
||||
"web-sys",
|
||||
"winreg",
|
||||
]
|
||||
@ -1956,7 +1973,7 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9dab61250775933275e84053ac235621dfb739556d5c54a2f2e9313b7cf43a19"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"base64 0.12.3",
|
||||
"blake2b_simd",
|
||||
"constant_time_eq",
|
||||
"crossbeam-utils 0.7.2",
|
||||
@ -2035,6 +2052,12 @@ dependencies = [
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scoped-tls"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@ -2131,14 +2154,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.6.1"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97"
|
||||
checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
|
||||
dependencies = [
|
||||
"dtoa",
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2189,9 +2212,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.4.2"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
|
||||
checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
@ -2285,9 +2308,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.0"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
|
||||
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
@ -2359,9 +2382,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b78a366903f506d2ad52ca8dc552102ffdd3e937ba8a227f024dc1d1eae28575"
|
||||
checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
@ -2374,9 +2397,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "0.2.22"
|
||||
version = "0.2.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd"
|
||||
checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@ -2385,7 +2408,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"mio",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"slab",
|
||||
"tokio-macros",
|
||||
]
|
||||
@ -2421,7 +2444,7 @@ dependencies = [
|
||||
"futures-core",
|
||||
"futures-sink",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@ -2448,7 +2471,7 @@ checksum = "b0987850db3733619253fe60e17cb59b82d37c7e6c0236bb81e4d6b87c879f27"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"pin-project-lite 0.1.11",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
@ -2541,18 +2564,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "unicode-normalization"
|
||||
version = "0.1.14"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7f98e67a4d84f730d343392f9bfff7d21e3fca562b9cb7a43b768350beeddc6"
|
||||
checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606"
|
||||
dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.6.0"
|
||||
version = "1.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||
checksum = "db8716a166f290ff49dabc18b44aa407cb7c6dbe1aa0971b44b8a24b0ca35aae"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
@ -2748,6 +2771,30 @@ version = "0.2.68"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d649a3145108d7d3fbcde896a468d1bd636791823c9921135218ad89be08307"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34d1cdc8b98a557f24733d50a1199c4b0635e465eecba9c45b214544da197f64"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"js-sys",
|
||||
"scoped-tls",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-bindgen-test-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-test-macro"
|
||||
version = "0.3.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8fb9c67be7439ee8ab1b7db502a49c05e51e2835b66796c705134d9b8e1a585"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-greeting"
|
||||
version = "0.1.0"
|
||||
|
@ -18,12 +18,14 @@ use super::*;
|
||||
use crate::module::FCEModule;
|
||||
use crate::module::RecordTypes;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// Represent FCE module interface.
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
|
||||
pub struct FCEModuleInterface<'a> {
|
||||
pub record_types: &'a RecordTypes,
|
||||
pub function_signatures: Vec<FCEFunctionSignature>,
|
||||
|
@ -29,6 +29,9 @@ use wasmer_runtime::compile;
|
||||
use wasmer_runtime::ImportObject;
|
||||
use wasmer_wit::interpreter::Interpreter;
|
||||
|
||||
use serde::Serialize;
|
||||
use serde::Deserialize;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::mem::MaybeUninit;
|
||||
@ -46,7 +49,7 @@ pub(super) struct WITModuleFunc {
|
||||
}
|
||||
|
||||
/// Represent a function type inside FCE module.
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
|
||||
pub struct FCEFunctionSignature {
|
||||
pub name: Rc<String>,
|
||||
pub arguments: Rc<Vec<IFunctionArg>>,
|
||||
|
@ -27,20 +27,20 @@
|
||||
mod config;
|
||||
mod errors;
|
||||
mod service;
|
||||
mod service_interface;
|
||||
mod raw_toml_config;
|
||||
|
||||
pub(crate) type Result<T> = std::result::Result<T, AppServiceError>;
|
||||
|
||||
pub use errors::AppServiceError;
|
||||
pub use service::AppService;
|
||||
pub use service_interface::FunctionSignature;
|
||||
pub use service_interface::RecordType;
|
||||
pub use service_interface::ServiceInterface;
|
||||
|
||||
pub use config::AppServiceConfig;
|
||||
pub use raw_toml_config::TomlAppServiceConfig;
|
||||
|
||||
pub use fluence_faas::FaaSInterface as ServiceInterface;
|
||||
pub use fluence_faas::FaaSModuleInterface as ServiceModuleInterface;
|
||||
pub use fluence_faas::FaaSFunctionSignature as ServiceFunctionSignature;
|
||||
|
||||
pub use fluence_faas::FaaSConfig;
|
||||
pub use fluence_faas::FaaSModuleConfig;
|
||||
pub use fluence_faas::FaaSWASIConfig;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use crate::Result;
|
||||
use crate::config::AppServiceConfig;
|
||||
use crate::service_interface::ServiceInterface;
|
||||
use super::AppServiceError;
|
||||
|
||||
use fluence_faas::FluenceFaaS;
|
||||
@ -86,9 +87,19 @@ impl AppService {
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Return all export functions (name and signatures) of loaded modules.
|
||||
pub fn get_interface(&self) -> fluence_faas::FaaSInterface<'_> {
|
||||
self.faas.get_interface()
|
||||
/// Return interface (function signatures and record types) of this service.
|
||||
pub fn get_interface(&self) -> ServiceInterface {
|
||||
use crate::service_interface::into_service_interface;
|
||||
|
||||
let faas_facade_interface = self
|
||||
.faas
|
||||
.get_interface()
|
||||
.modules
|
||||
.remove(self.facade_module_name.as_str())
|
||||
// facade module must be loaded in FaaS, so unwrap is safe here
|
||||
.unwrap();
|
||||
|
||||
into_service_interface(faas_facade_interface)
|
||||
}
|
||||
|
||||
/// Prepare service before starting by:
|
||||
@ -200,6 +211,11 @@ impl AppService {
|
||||
self.faas.unload_module(module_name).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Return raw interface of the underlying [[FluenceFaaS]] instance
|
||||
pub fn get_full_interface(&self) -> fluence_faas::FaaSInterface<'_> {
|
||||
self.faas.get_interface()
|
||||
}
|
||||
|
||||
pub fn get_wasi_state<S: AsRef<str>>(
|
||||
&mut self,
|
||||
module_name: S,
|
||||
|
106
fluence-app-service/src/service_interface.rs
Normal file
106
fluence-app-service/src/service_interface.rs
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2020 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use fluence_faas::FaaSModuleInterface;
|
||||
use fluence_faas::FaaSFunctionSignature;
|
||||
use fluence_faas::IRecordType;
|
||||
use fluence_faas::RecordTypes;
|
||||
use fluence_faas::itype_text_view;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct FunctionSignature {
|
||||
pub name: String,
|
||||
pub arguments: Vec<(String, String)>,
|
||||
pub output_types: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RecordType {
|
||||
pub name: String,
|
||||
pub id: u64,
|
||||
pub fields: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ServiceInterface {
|
||||
pub function_signatures: Vec<FunctionSignature>,
|
||||
pub record_types: Vec<RecordType>,
|
||||
}
|
||||
|
||||
pub(crate) fn into_service_interface(faas_interface: FaaSModuleInterface<'_>) -> ServiceInterface {
|
||||
let record_types = faas_interface.record_types;
|
||||
|
||||
let function_signatures = faas_interface
|
||||
.function_signatures
|
||||
.into_iter()
|
||||
.map(|sign| serialize_function_signature(sign, record_types))
|
||||
.collect();
|
||||
|
||||
let record_types = record_types
|
||||
.iter()
|
||||
.map(|(id, record)| serialize_record_type(*id, record.clone(), record_types))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
ServiceInterface {
|
||||
record_types,
|
||||
function_signatures,
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_function_signature(
|
||||
signature: FaaSFunctionSignature,
|
||||
record_types: &RecordTypes,
|
||||
) -> FunctionSignature {
|
||||
let arguments = signature
|
||||
.arguments
|
||||
.iter()
|
||||
.map(|arg| (arg.name.clone(), itype_text_view(&arg.ty, record_types)))
|
||||
.collect();
|
||||
|
||||
let output_types = signature
|
||||
.outputs
|
||||
.iter()
|
||||
.map(|itype| itype_text_view(itype, record_types))
|
||||
.collect();
|
||||
|
||||
FunctionSignature {
|
||||
name: signature.name.to_string(),
|
||||
arguments,
|
||||
output_types,
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_record_type<'a, 'b>(
|
||||
id: u64,
|
||||
record: Rc<IRecordType>,
|
||||
record_types: &RecordTypes,
|
||||
) -> RecordType {
|
||||
let fields = record
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| (field.name.clone(), itype_text_view(&field.ty, record_types)))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RecordType {
|
||||
name: record.name.clone(),
|
||||
id,
|
||||
fields,
|
||||
}
|
||||
}
|
@ -17,40 +17,22 @@
|
||||
use super::IType;
|
||||
use super::IRecordType;
|
||||
use crate::FaaSModuleInterface;
|
||||
use crate::FaaSFunctionSignature;
|
||||
|
||||
use fce::RecordTypes;
|
||||
use itertools::Itertools;
|
||||
use serde::Serialize;
|
||||
use serde::Serializer;
|
||||
|
||||
use std::fmt;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
|
||||
pub struct FaaSInterface<'a> {
|
||||
pub modules: HashMap<&'a str, FaaSModuleInterface<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fn type_text_view(arg_ty: &IType, record_types: &RecordTypes) -> String {
|
||||
match arg_ty {
|
||||
IType::Record(record_type_id) => {
|
||||
// unwrap is safe because FaaSInterface here is well-formed
|
||||
// (it was checked on the module startup stage)
|
||||
let record = record_types.get(record_type_id).unwrap();
|
||||
record.name.clone()
|
||||
}
|
||||
IType::Array(array_ty) => {
|
||||
format!("Array<{}>", type_text_view(array_ty, record_types))
|
||||
}
|
||||
t => format!("{:?}", t),
|
||||
}
|
||||
};
|
||||
|
||||
let mut printed_record_types: HashSet<&IRecordType> = HashSet::new();
|
||||
|
||||
for (_, module_interface) in self.modules.iter() {
|
||||
@ -67,7 +49,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
f,
|
||||
" {}: {}",
|
||||
field.name,
|
||||
type_text_view(&field.ty, &module_interface.record_types)
|
||||
itype_text_view(&field.ty, &module_interface.record_types)
|
||||
)?;
|
||||
}
|
||||
|
||||
@ -88,7 +70,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
format!(
|
||||
"{}: {}",
|
||||
arg.name,
|
||||
type_text_view(&arg.ty, &module_interface.record_types)
|
||||
itype_text_view(&arg.ty, &module_interface.record_types)
|
||||
)
|
||||
})
|
||||
.join(", ");
|
||||
@ -101,7 +83,7 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
f,
|
||||
"{}) -> {}",
|
||||
args,
|
||||
type_text_view(&outputs[0], &module_interface.record_types)
|
||||
itype_text_view(&outputs[0], &module_interface.record_types)
|
||||
)?;
|
||||
} else {
|
||||
// At now, multi values aren't supported - only one output type is possible
|
||||
@ -114,92 +96,15 @@ impl<'a> fmt::Display for FaaSInterface<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Serialize for FaaSInterface<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
#[derive(Serialize)]
|
||||
pub struct FunctionSignature<'a> {
|
||||
pub name: &'a Rc<String>,
|
||||
pub arguments: Vec<(&'a String, &'a IType)>,
|
||||
pub output_types: &'a Rc<Vec<IType>>,
|
||||
pub fn itype_text_view(arg_ty: &IType, record_types: &RecordTypes) -> String {
|
||||
match arg_ty {
|
||||
IType::Record(record_type_id) => {
|
||||
// unwrap is safe because FaaSInterface here is well-formed
|
||||
// (it was checked on the module startup stage)
|
||||
let record = record_types.get(record_type_id).unwrap();
|
||||
record.name.clone()
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RecordType<'a> {
|
||||
pub name: &'a str,
|
||||
pub id: u64,
|
||||
pub fields: Vec<(&'a String, &'a IType)>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Module<'a> {
|
||||
pub name: &'a str,
|
||||
pub function_signatures: Vec<FunctionSignature<'a>>,
|
||||
pub record_types: Vec<RecordType<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Interface<'a> {
|
||||
pub modules: Vec<Module<'a>>,
|
||||
}
|
||||
|
||||
fn serialize_function_signature(
|
||||
signature: &FaaSFunctionSignature,
|
||||
) -> FunctionSignature<'_> {
|
||||
let arguments = signature
|
||||
.arguments
|
||||
.iter()
|
||||
.map(|arg| (&arg.name, &arg.ty))
|
||||
.collect();
|
||||
|
||||
FunctionSignature {
|
||||
name: &signature.name,
|
||||
arguments,
|
||||
output_types: &signature.outputs,
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize_record_type<'a, 'b>(record: (&'a u64, &'b Rc<IRecordType>)) -> RecordType<'b> {
|
||||
let fields = record
|
||||
.1
|
||||
.fields
|
||||
.iter()
|
||||
.map(|field| (&field.name, &field.ty))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
RecordType {
|
||||
name: record.1.name.as_str(),
|
||||
id: *record.0,
|
||||
fields,
|
||||
}
|
||||
}
|
||||
|
||||
let modules: Vec<_> = self
|
||||
.modules
|
||||
.iter()
|
||||
.map(|(name, interface)| {
|
||||
let function_signatures = interface
|
||||
.function_signatures
|
||||
.iter()
|
||||
.map(serialize_function_signature)
|
||||
.collect();
|
||||
|
||||
let record_types: Vec<_> = interface
|
||||
.record_types
|
||||
.iter()
|
||||
.map(serialize_record_type)
|
||||
.collect();
|
||||
|
||||
Module {
|
||||
name,
|
||||
function_signatures,
|
||||
record_types,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
Interface { modules }.serialize(serializer)
|
||||
IType::Array(array_ty) => format!("Array<{}>", itype_text_view(array_ty, record_types)),
|
||||
t => format!("{:?}", t),
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ pub(crate) type Result<T> = std::result::Result<T, FaaSError>;
|
||||
|
||||
pub use faas::FluenceFaaS;
|
||||
pub use faas_interface::FaaSInterface;
|
||||
pub use faas_interface::itype_text_view;
|
||||
|
||||
pub use config::FaaSConfig;
|
||||
pub use config::FaaSModuleConfig;
|
||||
@ -58,6 +59,7 @@ pub use fce::IFunctionArg;
|
||||
pub use fce::IType;
|
||||
pub use fce::FCEModuleInterface as FaaSModuleInterface;
|
||||
pub use fce::FCEFunctionSignature as FaaSFunctionSignature;
|
||||
pub use fce::RecordTypes;
|
||||
pub use fce::HostExportedFunc;
|
||||
pub use fce::HostImportDescriptor;
|
||||
pub use fce::HostImportError;
|
||||
|
@ -144,7 +144,7 @@ impl REPL {
|
||||
};
|
||||
}
|
||||
Some("interface") => {
|
||||
let interface = self.app_service.get_interface();
|
||||
let interface = self.app_service.get_full_interface();
|
||||
print!("Application service interface:\n{}", interface);
|
||||
}
|
||||
Some("h") | Some("help") | None => {
|
||||
|
Loading…
Reference in New Issue
Block a user