Skip to main content

worldinterface_core/flowspec/
transform.rs

1//! Pure transform node types for FlowSpec.
2
3use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6/// A pure transform node with no side effects. Reshapes data between
7/// boundary crossings.
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct TransformNode {
10    /// The type of transform to apply.
11    pub transform: TransformType,
12    /// Transform-specific input configuration.
13    #[serde(default = "default_input")]
14    pub input: Value,
15}
16
17fn default_input() -> Value {
18    Value::Object(serde_json::Map::new())
19}
20
21/// Available transform types. This is a closed set in v1.0-alpha.
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum TransformType {
25    /// Passthrough — forwards input unchanged. Useful for testing.
26    Identity,
27    /// Rename and restructure fields via explicit mappings.
28    FieldMapping(FieldMappingSpec),
29}
30
31/// Specification for field-level data mapping.
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33pub struct FieldMappingSpec {
34    pub mappings: Vec<FieldMapping>,
35}
36
37/// A single field mapping from a source path to a target path.
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39pub struct FieldMapping {
40    /// Source path in dot-notation (e.g., "body.data.items").
41    pub from: String,
42    /// Target path in dot-notation.
43    pub to: String,
44}