Skip to main content

etdl_parser/
lib.rs

1pub mod ast;
2pub mod asyncapi;
3pub mod ecel;
4pub mod jsonptr;
5
6use ast::EtlDocument;
7use asyncapi::AsyncApiRegistry;
8use std::path::Path;
9
10pub fn parse_document(yaml_str: &str) -> Result<EtlDocument, String> {
11    let doc: EtlDocument =
12        serde_yaml::from_str(yaml_str).map_err(|e| format!("YAML parse error: {}", e))?;
13    Ok(doc)
14}
15
16pub fn parse_document_from_file(path: &Path) -> Result<EtlDocument, String> {
17    let content =
18        std::fs::read_to_string(path).map_err(|e| format!("cannot read file: {}", e))?;
19
20    if content.starts_with('\u{feff}') {
21        return Err("E-102: document contains a byte-order mark (BOM)".to_string());
22    }
23
24    parse_document(&content)
25}
26
27pub fn load_asyncapi_imports(
28    doc: &EtlDocument,
29    base_dir: &Path,
30) -> Result<AsyncApiRegistry, String> {
31    let mut registry = AsyncApiRegistry::new();
32    for (alias, location) in &doc.asyncapi_imports {
33        registry.load(alias, location, base_dir)?;
34    }
35    Ok(registry)
36}