use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::Record;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct PipelineMetadata {
pub data_source: DataSource,
pub path_columns: Vec<String>,
pub content_type: Option<String>,
#[serde(default)]
pub custom: Record,
}
impl PipelineMetadata {
pub fn with_data_source(self, data_source: DataSource) -> Self {
Self {
data_source,
..self
}
}
pub fn with_path_columns(self, path_columns: Vec<String>) -> Self {
Self {
path_columns,
..self
}
}
pub fn with_content_type(self, content_type: Option<String>) -> Self {
Self {
content_type,
..self
}
}
pub fn for_collect(self) -> Option<Self> {
let Self {
data_source,
path_columns,
content_type,
custom,
} = self;
let data_source = match data_source {
DataSource::FilePath(_) => DataSource::None,
other => other,
};
if matches!(data_source, DataSource::None)
&& path_columns.is_empty()
&& content_type.is_none()
&& custom.is_empty()
{
None
} else {
Some(Self {
data_source,
path_columns,
content_type,
custom,
})
}
}
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub enum DataSource {
#[deprecated(
since = "0.111.0",
note = "Use `PipelineMetadata { path_columns: vec![\"name\".to_string()], .. }` instead."
)]
Ls,
HtmlThemes,
FilePath(PathBuf),
#[default]
None,
}