Skip to main content

walk_authored_steps

Function walk_authored_steps 

Source
pub fn walk_authored_steps(tasks: &Value) -> AuthoredSteps<'_> 
Expand description

Walk an authored tasks array, yielding every node with its path.

Traversal is document order, pre-order: a group is yielded before its members, so filtering to StepKind::Leaf reproduces the engine’s flattened Workflow::tasks exactly, in order.

This walker never fails. Where [flatten] returns Err on the first malformed element, an empty group or an over-deep group, the walker yields those nodes so a validator can collect every violation in one pass. A tasks value that is not an array yields nothing at all — whether tasks is a non-empty array is a rule for the caller to report, not for this walk to fail on.

use dataflow_rs::engine::steps::{StepKind, walk_authored_steps};
use serde_json::json;

let tasks = json!([
    {"id": "first", "function": {"name": "map", "input": {"mappings": []}}},
    {"id": "guard", "condition": true, "tasks": [
        {"id": "inner", "function": {"name": "map", "input": {"mappings": []}}}
    ]}
]);

let steps: Vec<_> = walk_authored_steps(&tasks).collect();
let seen: Vec<(&str, StepKind)> =
    steps.iter().map(|s| (s.path.as_str(), s.kind)).collect();

assert_eq!(seen, vec![
    ("tasks[0]", StepKind::Leaf),
    ("tasks[1]", StepKind::Group),
    ("tasks[1].tasks[0]", StepKind::Leaf),
]);