Skip to content

Commit 7e7cb1e

Browse files
committed
docs: Update README and docs for v2.1.1 features
Document filter, log, channel routing, workflow lifecycle, engine hot reload, and typed integration configs across README and mdbook.
1 parent 58e09aa commit 7e7cb1e

10 files changed

Lines changed: 618 additions & 8 deletions

File tree

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,13 @@ let engine = RulesEngine::new(vec![rule], None);
122122
- **Full Context Access:** Conditions can access any field — `data`, `metadata`, `temp_data`.
123123
- **Async-First Architecture:** Native async/await support with Tokio for high-throughput processing.
124124
- **Execution Tracing:** Step-by-step debugging with message snapshots after each action.
125-
- **Built-in Functions:** Parse (JSON/XML), Map, Validate, and Publish (JSON/XML) for complete data pipelines.
125+
- **Built-in Functions:** Parse, Map, Validate, Filter, Log, and Publish for complete data pipelines.
126+
- **Pipeline Control Flow:** Filter/gate function to halt workflows or skip tasks based on conditions.
127+
- **Channel Routing:** Route messages to specific workflow channels with O(1) lookup.
128+
- **Workflow Lifecycle:** Manage workflow status (active/paused/archived), versioning, and tagging.
129+
- **Hot Reload:** Swap workflows at runtime without re-registering custom functions.
126130
- **Extensible:** Add custom async actions by implementing the `AsyncFunctionHandler` trait.
131+
- **Typed Integration Configs:** Pre-validated configs for HTTP, Enrich, and Kafka integrations.
127132
- **WebAssembly Support:** Run rules in the browser with `@goplasmatic/dataflow-wasm`.
128133
- **React UI Components:** Visualize and debug rules with `@goplasmatic/dataflow-ui`.
129134
- **Auditing:** Full audit trail of all changes as data flows through the pipeline.
@@ -200,9 +205,104 @@ let engine = Engine::new(workflows, Some(custom_functions));
200205
| `parse_xml` | Parse XML string into JSON data structure | Yes |
201206
| `map` | Data transformation using JSONLogic | Yes |
202207
| `validation` | Rule-based data validation | No (read-only) |
208+
| `filter` | Pipeline control flow — halt workflow or skip task | No |
209+
| `log` | Structured logging with JSONLogic expressions | No |
203210
| `publish_json` | Serialize data to JSON string | Yes |
204211
| `publish_xml` | Serialize data to XML string | Yes |
205212

213+
### Filter (Pipeline Control Flow)
214+
215+
The `filter` function evaluates a JSONLogic condition and controls pipeline execution:
216+
217+
```json
218+
{
219+
"function": {
220+
"name": "filter",
221+
"input": {
222+
"condition": {"==": [{"var": "data.status"}, "active"]},
223+
"on_reject": "halt"
224+
}
225+
}
226+
}
227+
```
228+
229+
- `on_reject: "halt"` — stops the entire workflow when the condition is false
230+
- `on_reject: "skip"` — skips just the current task and continues
231+
232+
### Log (Structured Logging)
233+
234+
The `log` function outputs structured log messages using the `log` crate:
235+
236+
```json
237+
{
238+
"function": {
239+
"name": "log",
240+
"input": {
241+
"level": "info",
242+
"message": {"cat": ["Processing order ", {"var": "data.order.id"}]},
243+
"fields": {
244+
"total": {"var": "data.order.total"},
245+
"user": {"var": "data.user.name"}
246+
}
247+
}
248+
}
249+
}
250+
```
251+
252+
Log levels: `trace`, `debug`, `info`, `warn`, `error`. Messages and fields support JSONLogic expressions.
253+
254+
## Channel Routing
255+
256+
Route messages to specific workflow channels for efficient O(1) dispatch:
257+
258+
```rust
259+
// Workflows define their channel
260+
// { "id": "order_rule", "channel": "orders", "status": "active", ... }
261+
262+
// Process only workflows on a specific channel
263+
engine.process_message_for_channel("orders", &mut message).await?;
264+
```
265+
266+
Only `active` workflows are included in channel routing. Workflows default to the `"default"` channel.
267+
268+
## Workflow Lifecycle
269+
270+
Workflows support lifecycle management fields:
271+
272+
```json
273+
{
274+
"id": "my_rule",
275+
"channel": "orders",
276+
"version": 2,
277+
"status": "active",
278+
"tags": ["premium", "high-priority"],
279+
"created_at": "2025-01-15T10:00:00Z",
280+
"updated_at": "2025-06-01T14:30:00Z",
281+
"tasks": [...]
282+
}
283+
```
284+
285+
| Field | Type | Default | Description |
286+
|-------|------|---------|-------------|
287+
| `channel` | string | `"default"` | Channel for message routing |
288+
| `version` | number | `1` | Workflow version |
289+
| `status` | string | `"active"` | `active`, `paused`, or `archived` |
290+
| `tags` | array | `[]` | Arbitrary tags for organization |
291+
| `created_at` | datetime | `null` | Creation timestamp (ISO 8601) |
292+
| `updated_at` | datetime | `null` | Last update timestamp (ISO 8601) |
293+
294+
All fields are optional and backward-compatible with existing configurations.
295+
296+
## Engine Hot Reload
297+
298+
Swap workflows at runtime without losing custom function registrations:
299+
300+
```rust
301+
let new_workflows = vec![Workflow::from_json(r#"{ ... }"#)?];
302+
let new_engine = engine.with_new_workflows(new_workflows);
303+
// Old engine remains valid for in-flight messages
304+
```
305+
206306
## Related Packages
207307

208308
| Package | Description |

docs/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- [Parse](./built-in-functions/parse.md)
2525
- [Map](./built-in-functions/map.md)
2626
- [Validation](./built-in-functions/validation.md)
27+
- [Filter](./built-in-functions/filter.md)
28+
- [Log](./built-in-functions/log.md)
2729
- [Publish](./built-in-functions/publish.md)
2830

2931
# JavaScript/TypeScript

docs/src/api/reference.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,20 @@ pub async fn process_message(&self, message: &mut Message) -> Result<()>
4242
// Process with execution trace for debugging
4343
pub async fn process_message_with_trace(&self, message: &mut Message) -> Result<ExecutionTrace>
4444

45-
// Get registered rules
46-
pub fn workflows(&self) -> &HashMap<String, Workflow>
45+
// Process only workflows on a specific channel (O(1) lookup)
46+
pub async fn process_message_for_channel(&self, channel: &str, message: &mut Message) -> Result<()>
47+
48+
// Channel routing with execution trace
49+
pub async fn process_message_for_channel_with_trace(&self, channel: &str, message: &mut Message) -> Result<ExecutionTrace>
50+
51+
// Get registered rules (sorted by priority)
52+
pub fn workflows(&self) -> &Arc<Vec<Workflow>>
53+
54+
// Find a workflow by ID
55+
pub fn workflow_by_id(&self, id: &str) -> Option<&Workflow>
56+
57+
// Create a new engine with different workflows, preserving custom functions
58+
pub fn with_new_workflows(&self, workflows: Vec<Workflow>) -> Self
4759
```
4860

4961
## Workflow (Rule)
@@ -76,7 +88,13 @@ pub fn rule(id: &str, name: &str, condition: Value, tasks: Vec<Task>) -> Self
7688
"priority": "number (optional, default: 0)",
7789
"condition": "JSONLogic (optional, evaluated against full context)",
7890
"continue_on_error": "boolean (optional, default: false)",
79-
"tasks": "array of Task (required)"
91+
"tasks": "array of Task (required)",
92+
"channel": "string (optional, default: 'default')",
93+
"version": "number (optional, default: 1)",
94+
"status": "'active' | 'paused' | 'archived' (optional, default: 'active')",
95+
"tags": "array of string (optional, default: [])",
96+
"created_at": "ISO 8601 datetime (optional)",
97+
"updated_at": "ISO 8601 datetime (optional)"
8098
}
8199
```
82100

@@ -246,6 +264,24 @@ pub enum DataflowError {
246264
}
247265
```
248266

267+
## WorkflowStatus
268+
269+
Lifecycle status for workflows.
270+
271+
```rust
272+
use dataflow_rs::WorkflowStatus;
273+
```
274+
275+
### Variants
276+
277+
```rust
278+
pub enum WorkflowStatus {
279+
Active, // Default — workflow executes normally
280+
Paused, // Excluded from channel routing
281+
Archived, // Permanently retired
282+
}
283+
```
284+
249285
## Built-in Functions
250286

251287
### map
@@ -284,6 +320,41 @@ Rule-based data validation.
284320
}
285321
```
286322

323+
### filter
324+
325+
Pipeline control flow — halt workflow or skip task.
326+
327+
```json
328+
{
329+
"name": "filter",
330+
"input": {
331+
"condition": "JSONLogic expression",
332+
"on_reject": "halt | skip (default: halt)"
333+
}
334+
}
335+
```
336+
337+
Status codes: 200 (pass), 298 (skip), 299 (halt).
338+
339+
### log
340+
341+
Structured logging with JSONLogic expressions.
342+
343+
```json
344+
{
345+
"name": "log",
346+
"input": {
347+
"level": "trace | debug | info | warn | error (default: info)",
348+
"message": "JSONLogic expression",
349+
"fields": {
350+
"key": "JSONLogic expression"
351+
}
352+
}
353+
}
354+
```
355+
356+
Always returns (200, []) — never modifies the message.
357+
287358
## WASM API (dataflow-wasm)
288359

289360
For browser/JavaScript usage.

0 commit comments

Comments
 (0)