Skip to main content

chartml_core/plugin/
transform.rs

1use async_trait::async_trait;
2use std::collections::HashMap;
3use crate::data::DataTable;
4use crate::error::ChartError;
5use crate::spec::TransformSpec;
6
7/// Context available during transform execution.
8#[derive(Debug, Clone, Default)]
9pub struct TransformContext {
10    /// Parameter values resolved from the spec.
11    pub params: HashMap<String, serde_json::Value>,
12}
13
14/// Result of a transform operation.
15#[derive(Debug, Clone)]
16pub struct TransformResult {
17    pub data: DataTable,
18    pub metadata: HashMap<String, serde_json::Value>,
19}
20
21/// Transform middleware — processes data between fetch and render.
22#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
23#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
24pub trait TransformMiddleware: Send + Sync {
25    /// Transform input data according to the spec.
26    async fn transform(
27        &self,
28        data: DataTable,
29        spec: &TransformSpec,
30        context: &TransformContext,
31    ) -> Result<TransformResult, ChartError>;
32}