pub mod data;
mod server;
pub use data::{
Bytes, ContextCodec, ContextDict, ContextSet, Data, DecodeError, JsonValue, PayloadView,
parse_json,
};
pub use flow_abi::{DecodeErrorKind, Json, ValidatedTypes};
pub use flow_value::{Decimal, Duration, Instant, Int};
pub use server::{Context, Problem};
mod function;
#[doc(hidden)]
pub mod prepare;
pub use flow_toolkit_macros::{Flow, lifecycle, tool};
pub use function::{FlowType, Resource, Value};
#[doc(hidden)]
pub mod __bridge {
pub use crate::function::{
Function, Lifecycle, Shape, Start, Types, block_on, decode_field, encode_field, extract,
};
use crate::server::{Args, Declaration};
use crate::{Context, Data, DecodeError, Json, Problem};
use flow_abi::TypeSpec;
pub fn function(
identity: (&'static str, &[&str]),
docs: &'static str,
params: Vec<(String, String)>,
ok: String,
err: String,
types: Types,
factory: fn(&str, TypeSpec) -> Adapter,
) -> Function {
Function::new(identity.0, docs, params, ok, err, types, factory).with_generics(identity.1)
}
pub struct Adapter(pub(crate) Declaration);
pub fn typed<T: Data, E: Data, F>(entry: &str, spec: TypeSpec, call: F) -> Adapter
where
F: Fn(&Context, &Args<'_>) -> Result<Result<T, Problem<E>>, DecodeError>
+ Send
+ Sync
+ 'static,
{
Adapter(Declaration::new(entry, spec, call))
}
pub fn contextual<F>(entry: &str, spec: TypeSpec, call: F) -> Adapter
where
F: Fn(&Context, &Args<'_>) -> Result<Result<Json, Problem<Json>>, DecodeError>
+ Send
+ Sync
+ 'static,
{
Adapter(Declaration::contextual(entry, spec, call))
}
pub fn run(functions: &[Function], start: Option<Start>) -> Result<(), String> {
crate::function::launcher_with_lifecycle(functions, start)
}
}
#[cfg(test)]
extern crate self as flow_toolkit;
#[cfg(test)]
mod test_contextual;
#[cfg(test)]
mod test_protocol;
#[cfg(test)]
mod test_contract;
#[cfg(test)]
#[path = "../tests/common/mod.rs"]
mod test_common;