Skip to main content

stepflow_flow/values/
step_context.rs

1// Copyright 2025 DataStax Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4// in compliance with the License. You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software distributed under the License
9// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10// or implied. See the License for the specific language governing permissions and limitations under
11// the License.
12
13//! Context trait for expression evaluation.
14//!
15//! The `StepContext` trait provides access to execution state during
16//! expression evaluation, including step results, workflow input, and variables.
17
18use crate::FlowResult;
19use crate::values::{Secrets, ValueRef};
20
21/// Provides access to execution state for expression evaluation.
22///
23/// This trait allows `ValueExpr::needed_steps()` to determine which steps
24/// are needed to evaluate an expression, and `ValueExpr::resolve()` to
25/// evaluate expressions using available state.
26pub trait StepContext {
27    /// Get the index of a step by its ID.
28    ///
29    /// Returns `None` if the step ID is not found in the workflow.
30    fn step_index(&self, step_id: &str) -> Option<usize>;
31
32    /// Check if a step has completed execution.
33    ///
34    /// A step is completed if it has a result (success, skipped, or failed).
35    fn is_completed(&self, step_index: usize) -> bool;
36
37    /// Get the result of a completed step.
38    ///
39    /// Returns `None` if the step has not completed or the index is invalid.
40    fn get_result(&self, step_index: usize) -> Option<&FlowResult>;
41
42    /// Get the workflow input value.
43    ///
44    /// Returns `None` if input is not available in this context.
45    fn get_input(&self) -> Option<&ValueRef>;
46
47    /// Get a variable value by name.
48    ///
49    /// Returns `None` if the variable is not defined. The implementation
50    /// may fall back to schema defaults before returning `None`.
51    /// Returns an owned `ValueRef` since defaults may be computed.
52    fn get_variable(&self, name: &str) -> Option<ValueRef>;
53
54    /// Get the secrets configuration for a variable.
55    ///
56    /// Used for redacting sensitive values in logs.
57    fn get_variable_secrets(&self, name: &str) -> Secrets;
58}