Skip to content

Commit

Permalink
removed old triggers implementation, removed legacy keypair argument …
Browse files Browse the repository at this point in the history
…in Network, apex: changed struct to any, apex: changed link to Link
  • Loading branch information
jsoverson committed Sep 28, 2022
1 parent 2a76851 commit 93e5050
Show file tree
Hide file tree
Showing 42 changed files with 210 additions and 518 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions codegen/templates/rust/partials/common/collection-signature.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ wasmflow_sdk::v1::types::CollectionSignature {
types: std::collections::HashMap::from([
{{#each types}}
{{#switch type}}
{{#case "any"}}
(
"{{@key}}".to_owned(),
wasmflow_sdk::v1::types::TypeDefinition::Struct(wasmflow_sdk::v1::types::StructSignature{
name:"{{name}}".to_owned(),
fields: std::collections::HashMap::from([
{{#each fields}}
("{{@key}}".to_owned(),{{> type-signature .}}),
{{/each}}
]).into()
})
),
{{/case}}
{{#case "struct"}}
(
"{{@key}}".to_owned(),
Expand Down
1 change: 1 addition & 0 deletions codegen/templates/rust/partials/common/expand-type.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{#case "string"}}String{{/case}}
{{#case "bytes"}}Vec<u8>{{/case}}
{{#case "raw"}}RawPacket{{/case}}
{{#case "any"}}serde_json::Value{{/case}}
{{#case "struct"}}serde_json::Value{{/case}}
{{#case "link"}}wasmflow_sdk::v1::CollectionLink{{/case}}
{{#case "internal"}}
Expand Down
1 change: 0 additions & 1 deletion crates/bins/wasmflow/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use wasmflow_manifest::WasmflowManifest;
use crate::commands::FetchOptions;

#[allow(clippy::too_many_lines)]
#[must_use]
pub(crate) fn merge_config(
def: &WasmflowManifest,
local_cli_opts: &FetchOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace "main"

alias Link = string

type Inputs {
args: [string]
isInteractive: Interactive
program: link?
program: Link?
}

type Interactive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ impl wasmflow_sdk::v1::ephemeral::BatchedComponent for Component {
_config: Option<Self::Config>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let tty = input.is_interactive;
println!("args: {:?}, interactive: {{ stdin: {}, stdout: {}, stderr: {} }}",
input.args, tty.stdin, tty.stdout, tty.stderr);
println!(
"args: {:?}, interactive: {{ stdin: {}, stdout: {}, stderr: {} }}",
input.args, tty.stdin, tty.stdout, tty.stderr
);

let isatty = false; // input.is_interactive.stdin
if !isatty {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace "reverse-uppercase"

alias Link = string

type Inputs {
input: string
link: link
link: Link
}

type Outputs {
Expand Down
5 changes: 1 addition & 4 deletions crates/wasmflow/wasmflow-collection-grpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ pub enum GrpcError {
SendError,
#[error("Internal Error : {0}")]
Other(String),
#[error("Internal Error : {0}")]
InternalError(u32),
#[error("Could not create KeyPair from invalid seed")]
KeyPairFailed,

#[error("Component '{0}' not found. Valid components are: {}", .1.join(", "))]
ComponentNotFound(String, Vec<String>),
}
3 changes: 1 addition & 2 deletions crates/wasmflow/wasmflow-collection-grpctar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub enum ParError {
Other(String),
#[error("Internal Error : {0}")]
InternalError(u32),
#[error("Could not create KeyPair from invalid seed")]
KeyPairFailed,

#[error("Component '{0}' not found. Valid components are: {}", .1.join(", "))]
ComponentNotFound(String, Vec<String>),

Expand Down
38 changes: 1 addition & 37 deletions crates/wasmflow/wasmflow-collection-wasm/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::sync::Arc;

use async_trait::async_trait;
use tokio_stream::StreamExt;
pub use wapc::WasiParams;
use wasmflow_manifest::Permissions;
use wasmflow_rpc::error::RpcError;
Expand All @@ -11,7 +10,7 @@ use wasmflow_sdk::v1::codec::{json, messagepack};
use wasmflow_sdk::v1::packet::{PacketMap, PacketWrapper};
use wasmflow_sdk::v1::transport::{MessageTransport, Serialized, TransportMap, TransportStream};
use wasmflow_sdk::v1::types::HostedType;
use wasmflow_sdk::v1::{BoxedFuture, CollectionLink, Entity, Invocation};
use wasmflow_sdk::v1::{BoxedFuture, Invocation};

use crate::error::LinkError;
use crate::wapc_module::WapcModule;
Expand Down Expand Up @@ -78,41 +77,6 @@ impl Collection {

Ok(Self { pool: Arc::new(host) })
}

pub async fn exec_main(&self, origin: Entity, argv: Vec<String>) -> u32 {
let mut transport_map = TransportMap::default();
transport_map.insert("argv", MessageTransport::success(&argv));
let target = Entity::component(origin.namespace(), "main");
let link = CollectionLink::new(origin.clone(), target.clone());

transport_map.insert("network", MessageTransport::success(&link));
let invocation = Invocation::new(origin, target, transport_map, None);
let result = self.invoke(invocation).await;
if let Err(e) = result {
error!("main() died with fatal error: {}", e);
return 6;
}
let output = result.unwrap();
let packets: Vec<_> = output.collect().await;
for packet in packets {
if packet.port == "code" {
return if let MessageTransport::Failure(err) = packet.payload {
error!("main() component returned error: {}", err.message());
1
} else {
match packet.payload.deserialize::<u32>() {
Ok(code) => code,
Err(e) => {
error!("Could not get code from main() component: {}", e);
2
}
}
};
}
}
error!("No exit code received");
3
}
}

#[async_trait]
Expand Down
3 changes: 0 additions & 3 deletions crates/wasmflow/wasmflow-collection-wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ pub enum WasmCollectionError {
#[error("Internal Error : {0}")]
InternalError(u32),

#[error("Could not create KeyPair from invalid seed")]
KeyPairFailed,

#[error("Component '{0}' not found. Valid components are: {}", .1.join(", "))]
ComponentNotFound(String, Vec<String>),
}
Expand Down
1 change: 0 additions & 1 deletion crates/wasmflow/wasmflow-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ wasmflow-invocation-server = { path = "../wasmflow-invocation-server" }
tracing = "0.1"

thiserror = "1.0"
nkeys = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
async-trait = "0.1"
Expand Down
2 changes: 0 additions & 2 deletions crates/wasmflow/wasmflow-host/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub enum HostError {
ConfigurationDeserialization(String),
#[error("Async error: {0}")]
AsyncRT(String),
#[error(transparent)]
KeyPairError(#[from] nkeys::error::Error),
#[error("General error : {0}")]
Other(String),
#[error("{0}")]
Expand Down
16 changes: 2 additions & 14 deletions crates/wasmflow/wasmflow-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;

use nkeys::KeyPair;
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use seeded_random::Seed;
Expand Down Expand Up @@ -37,7 +36,6 @@ fn from_registry(id: Uuid) -> Arc<dyn RpcHandler + Send + Sync + 'static> {
#[derive(Debug)]
pub struct Host {
id: String,
kp: KeyPair,
network: Option<Network>,
mesh: Option<Arc<Mesh>>,
manifest: WasmflowManifest,
Expand Down Expand Up @@ -129,9 +127,8 @@ impl Host {
self.network.is_none(),
crate::Error::InvalidHostState("Host already has a network running".into())
);
let kp_seed = self.kp.seed()?;

let mut network_builder = NetworkBuilder::from_definition(self.manifest.clone(), &kp_seed)?;
let mut network_builder = NetworkBuilder::from_definition(self.manifest.clone())?;
if let Some(mesh) = &self.mesh {
network_builder = network_builder.mesh(mesh.clone());
}
Expand Down Expand Up @@ -205,13 +202,6 @@ impl Host {
}
}

pub async fn exec_main(&self, argv: Vec<String>) -> Result<u32> {
match &self.network {
Some(network) => Ok(network.exec_main(argv).await),
None => Err(crate::Error::InvalidHostState("No network available".into())),
}
}

pub async fn invoke(&self, invocation: Invocation) -> Result<TransportStream> {
match &self.network {
Some(network) => Ok(network.invoke(invocation).await?),
Expand Down Expand Up @@ -270,11 +260,9 @@ impl HostBuilder {

/// Constructs an instance of a Wasmflow host.
pub fn build(self) -> Host {
let kp = KeyPair::new_server();
let host_id = kp.public_key();
let host_id = Uuid::new_v4().to_string();

Host {
kp,
id: host_id,
network: None,
mesh: None,
Expand Down
2 changes: 0 additions & 2 deletions crates/wasmflow/wasmflow-loader/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ pub enum LoadError {
Other(String),
#[error("Internal Error : {0}")]
InternalError(u32),
#[error("Could not create KeyPair from invalid seed")]
KeyPairFailed,
#[error("Component '{0}' not found. Valid components are: {}", .1.join(", "))]
ComponentNotFound(String, Vec<String>),
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type EntrypointDefinition {
component: string,

"Data or configuration used to initialize the collection."
data: struct,
data: any,
}

"A collection definition."
Expand All @@ -121,7 +121,7 @@ type CollectionDefinition {
reference: string,

"Data or configuration used to initialize the collection."
data: struct,
data: any,
}

"Kind of collection."
Expand Down Expand Up @@ -166,7 +166,7 @@ type ComponentDefinition {
id: string @required,

"Data to associate with the reference."
data: struct?,
data: any?,
}

"A connection between components. This can be specified in short-form syntax (where applicable). See <a href='https://wasmflow.com/docs/configuration/short-form-syntax/'>wasmflow.com</a> for more information."
Expand All @@ -188,5 +188,5 @@ type ConnectionTargetDefinition {
"The component's port."
port: string @required,
"Data to associate with a connection."
data: struct?,
data: any?,
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{{/case}}
{{#case "Named"~}}
{{#switch name.value~}}
{{#case "struct"}}"type":"object"{{/case}}
{{#case "any"}}"type":"object"{{/case}}
{{#case "string"}}"type":"string"{{/case}}
{{#case "i8"}}"type":"number"{{/case}}
{{#case "u8"}}"type":"number"{{/case}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#switch kind ~}}
{{#case "Named"}}
{{#switch name.value}}
{{#case "struct"}}Value{{/case}}
{{#case "any"}}Value{{/case}}
{{#case "string"}}String{{/case}}
{{#default}}{{name.value}}{{/default}}
{{/switch}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct {{name.value}} {
{{#case "f32"}}#[serde(deserialize_with="with_expand_envs")]{{/case}}
{{#case "f64"}}#[serde(deserialize_with="with_expand_envs")]{{/case}}
{{#case "bool"}}#[serde(deserialize_with="with_expand_envs")]{{/case}}
{{#case "struct"}}#[serde(deserialize_with = "crate::helpers::deserialize_json_env")]{{/case}}
{{#case "any"}}#[serde(deserialize_with = "crate::helpers::deserialize_json_env")]{{/case}}
{{#case "ConnectionTargetDefinition"}}#[serde(deserialize_with = "connection_target_shortform")]{{/case}}
{{/switch}}
{{/case}}
Expand Down
Loading

0 comments on commit 93e5050

Please sign in to comment.