Skip to main content

dataflow_rs/
lib.rs

1//! A high-performance rules engine for IFTTT-style automation and data
2//! processing pipelines in Rust.
3//!
4//! Workflows are JSON definitions whose tasks run built-in or host functions
5//! over a [`Message`]'s context, with JSONLogic conditions and expressions
6//! compiled once at build time.
7//!
8//! - [`def`]: parse and lint authored workflow JSON into a [`WorkflowDef`].
9//! - [`program`]: compile definitions against a [`Registry`] into an immutable
10//!   [`program::Program`].
11//! - [`run`]: execute a program over a [`Message`] with [`Engine::run`] or
12//!   [`Engine::run_with`], returning a [`Run`] on every outcome.
13//! - [`function`]: implement [`Function`] with a `#[derive(FunctionConfig)]`
14//!   config for typed async host actions, or wrap calls in a
15//!   [`function::CallLayer`].
16//! - [`expr`]: compiled [`Expr<T>`], [`Path`], [`expr::Output`],
17//!   [`expr::Interpolated`] documents, and [`expr::Secrets`].
18//! - [`observe`]: inline [`Observer`] events and replayable [`observe::Trace`]s.
19//! - [`compat`]: migrate 3.x definitions to the 4.0 spelling with
20//!   [`compat::migrate_v3`].
21//!
22//! # Features
23//!
24//! None is on by default. The six standard extension operator families
25//! (`ExtString`, `ExtArray`, `ExtMath`, `ExtControl`, `ExtObject` and
26//! `ErrorHandling`) are compiled in unconditionally and selected at runtime on
27//! [`expr::ExprEngineBuilder`], which defaults to [`expr::OperatorFamily::Core`]
28//! (and `secret`) only.
29//!
30//! - `datetime`: compiles in the [`expr::OperatorFamily::Datetime`] operators
31//!   (still selected at runtime on [`expr::ExprEngineBuilder`]) and changes
32//!   `==` and the ordering operators on plain date-shaped strings across the
33//!   build.
34//! - `tensor`: the `Tensor` value and [`expr::OperatorFamily::Tensor`]
35//!   operators (selected at runtime on [`expr::ExprEngineBuilder`]). Not in
36//!   [`expr::ExprEngineBuilder::all_operators`], since names like `shape`,
37//!   `full`, `cast` and `concat` are ordinary JSON keys.
38//! - `budget`: a ceiling on the operations of one evaluation, which
39//!   `ExprEngineBuilder::ops_budget` sets.
40//! - `wasm-web`: the browser's clock and randomness, which
41//!   `wasm32-unknown-unknown` needs and native targets must not pull in.
42//! - `ts`: derives `ts_rs::TS` on the wire shapes, from which
43//!   `tests/ts_types.rs` renders `bindings/dataflow.d.ts`, which ships in the
44//!   package. **`ts` is outside semver:** the wire shapes are covered by
45//!   semver, but the generator, its output's layout and this feature's
46//!   dependencies may change in any release.
47//!
48//! # Dependencies in the API
49//!
50//! [`datalogic_rs`] and [`datavalue`] are re-exported, and part of this
51//! crate's API: a value is a [`datavalue::OwnedDataValue`] (a context, a
52//! secret, a resolved config), and a host's custom operator is a
53//! [`datalogic_rs::CustomOperator`]. A host names both through these
54//! re-exports, so its versions are always the engine's. A major version of
55//! either is a major version of this crate.
56
57#![forbid(unsafe_code)]
58#![warn(missing_docs, missing_debug_implementations)]
59
60extern crate self as dataflow_rs;
61
62/// The crate version.
63pub const VERSION: &str = env!("CARGO_PKG_VERSION");
64
65mod base;
66pub mod compat;
67pub mod def;
68pub mod expr;
69pub mod function;
70pub mod observe;
71pub mod program;
72pub mod run;
73mod state;
74
75pub use crate::base::{Error, ErrorKind, Issue, Result};
76pub use crate::def::WorkflowDef;
77pub use crate::expr::{Expr, Path};
78pub use crate::function::{Ctx, Function, Outcome, Registry};
79pub use crate::observe::Observer;
80pub use crate::run::{Engine, Message, Run, RunOptions};
81pub use datalogic_rs;
82pub use datavalue;