1mod csv;
24pub mod dali_compat;
25mod error;
26mod extract;
27mod html;
28mod join_export;
29mod json;
30mod mermaid;
31mod naming;
32mod schema;
33mod sql_backend;
34mod xlsx;
35
36#[cfg(feature = "duckdb")]
37mod duckdb_backend;
38
39pub use error::ExportError;
40pub use extract::{ColumnMapping, ScriptInfo, TableDependency, TableInfo, TableType};
41pub use mermaid::MermaidView;
42pub use naming::ExportNaming;
43
44use flowscope_core::AnalyzeResult;
45
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum ExportFormat {
49 DuckDb,
50 Sql { schema: bool },
51 Json { compact: bool },
52 Mermaid { view: MermaidView },
53 Html,
54 CsvBundle,
55 Xlsx,
56 Png,
57}
58
59pub type Format = ExportFormat;
60
61pub fn export(result: &AnalyzeResult, format: ExportFormat) -> Result<Vec<u8>, ExportError> {
66 match format {
67 #[cfg(feature = "duckdb")]
68 ExportFormat::DuckDb => duckdb_backend::export(result),
69 #[cfg(not(feature = "duckdb"))]
70 ExportFormat::DuckDb => Err(ExportError::UnsupportedFormat("DuckDB feature not enabled")),
71 ExportFormat::Sql { .. } => Ok(sql_backend::export_sql(result, None)?.into_bytes()),
72 ExportFormat::Json { compact } => Ok(json::export_json(result, compact)?.into_bytes()),
73 ExportFormat::Mermaid { view } => Ok(mermaid::export_mermaid(result, view).into_bytes()),
74 ExportFormat::Html => {
75 Ok(html::export_html(result, "FlowScope", chrono::Utc::now()).into_bytes())
76 }
77 ExportFormat::CsvBundle => csv::export_csv_bundle(result),
78 ExportFormat::Xlsx => xlsx::export_xlsx(result),
79 ExportFormat::Png => Err(ExportError::UnsupportedFormat("PNG export is UI-only")),
80 }
81}
82
83#[cfg(feature = "duckdb")]
87pub fn export_duckdb(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
88 duckdb_backend::export(result)
89}
90
91pub fn export_sql(result: &AnalyzeResult, schema: Option<&str>) -> Result<String, ExportError> {
101 sql_backend::export_sql(result, schema)
102}
103
104pub fn export_json(result: &AnalyzeResult, compact: bool) -> Result<String, ExportError> {
105 json::export_json(result, compact)
106}
107
108pub fn export_mermaid(result: &AnalyzeResult, view: MermaidView) -> Result<String, ExportError> {
109 Ok(mermaid::export_mermaid(result, view))
110}
111
112pub fn export_csv_bundle(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
113 csv::export_csv_bundle(result)
114}
115
116pub fn export_xlsx(result: &AnalyzeResult) -> Result<Vec<u8>, ExportError> {
117 xlsx::export_xlsx(result)
118}
119
120pub fn export_html(
121 result: &AnalyzeResult,
122 project_name: &str,
123 exported_at: chrono::DateTime<chrono::Utc>,
124) -> Result<String, ExportError> {
125 Ok(html::export_html(result, project_name, exported_at))
126}