feat(wfe-core): add step config API for attaching runtime JSON config
Adds StepBuilder::config() to attach arbitrary JSON configuration to individual steps, readable at runtime via context.step.step_config. Bumps version to 1.6.1.
This commit is contained in:
@@ -3,7 +3,7 @@ members = ["wfe-core", "wfe-sqlite", "wfe-postgres", "wfe-opensearch", "wfe-valk
|
||||
resolver = "2"
|
||||
|
||||
[workspace.package]
|
||||
version = "1.6.0"
|
||||
version = "1.6.1"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://src.sunbeam.pt/studio/wfe"
|
||||
|
||||
@@ -43,6 +43,14 @@ impl<D: WorkflowData> StepBuilder<D> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Attach arbitrary JSON configuration to this step.
|
||||
///
|
||||
/// The step can read it at runtime via `context.step.step_config`.
|
||||
pub fn config(mut self, config: serde_json::Value) -> Self {
|
||||
self.builder.steps[self.step_id].step_config = Some(config);
|
||||
self
|
||||
}
|
||||
|
||||
/// Add a compensation step for saga rollback.
|
||||
pub fn compensate_with<C: StepBody + Default + 'static>(mut self) -> Self {
|
||||
let comp_id = self.builder.add_step(std::any::type_name::<C>());
|
||||
|
||||
@@ -341,6 +341,51 @@ mod tests {
|
||||
assert!(def.steps[1].step_type.contains("StepB"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_sets_step_config() {
|
||||
let cfg = serde_json::json!({"namespace": "ory", "timeout": 30});
|
||||
let def = WorkflowBuilder::<TestData>::new()
|
||||
.start_with::<StepA>()
|
||||
.config(cfg.clone())
|
||||
.end_workflow()
|
||||
.build("test", 1);
|
||||
assert_eq!(def.steps[0].step_config, Some(cfg));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_chains_with_name() {
|
||||
let cfg = serde_json::json!({"namespace": "data"});
|
||||
let def = WorkflowBuilder::<TestData>::new()
|
||||
.start_with::<StepA>()
|
||||
.name("apply-data")
|
||||
.config(cfg.clone())
|
||||
.then::<StepB>()
|
||||
.end_workflow()
|
||||
.build("test", 1);
|
||||
assert_eq!(def.steps[0].name, Some("apply-data".into()));
|
||||
assert_eq!(def.steps[0].step_config, Some(cfg));
|
||||
assert_eq!(def.steps[0].outcomes[0].next_step, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_on_multiple_steps_of_same_type() {
|
||||
let cfg_a = serde_json::json!({"namespace": "ory"});
|
||||
let cfg_b = serde_json::json!({"namespace": "data"});
|
||||
let def = WorkflowBuilder::<TestData>::new()
|
||||
.start_with::<StepA>()
|
||||
.name("apply-ory")
|
||||
.config(cfg_a.clone())
|
||||
.then::<StepA>()
|
||||
.name("apply-data")
|
||||
.config(cfg_b.clone())
|
||||
.end_workflow()
|
||||
.build("test", 1);
|
||||
assert_eq!(def.steps[0].step_config, Some(cfg_a));
|
||||
assert_eq!(def.steps[1].step_config, Some(cfg_b));
|
||||
// Both are StepA
|
||||
assert_eq!(def.steps[0].step_type, def.steps[1].step_type);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_step_via_then_fn() {
|
||||
let def = WorkflowBuilder::<TestData>::new()
|
||||
|
||||
Reference in New Issue
Block a user