Skip to main content

chartml_core/plugin/
data_source.rs

1use async_trait::async_trait;
2use crate::data::DataTable;
3use crate::error::ChartError;
4
5/// Options for data fetching.
6#[derive(Debug, Clone, Default)]
7pub struct FetchOptions {
8    /// Optional cache TTL hint.
9    pub cache_ttl: Option<String>,
10}
11
12/// Specification for fetching data.
13#[derive(Debug, Clone)]
14pub struct DataSpec {
15    /// Provider type: "inline", "http", "api", etc.
16    pub provider: String,
17    /// Inline rows (if provider is "inline").
18    pub rows: Option<Vec<serde_json::Value>>,
19    /// URL for HTTP/API providers.
20    pub url: Option<String>,
21    /// API endpoint.
22    pub endpoint: Option<String>,
23}
24
25/// Data source plugin — fetches raw data from a provider.
26#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
27#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
28pub trait DataSource: Send + Sync {
29    /// Fetch data as an Arrow-backed DataTable.
30    async fn fetch(&self, spec: &DataSpec, options: &FetchOptions) -> Result<DataTable, ChartError>;
31}