edifact_mapper/lib.rs
1//! # edifact-mapper
2//!
3//! EDIFACT to BO4E bidirectional conversion for the German energy market.
4//!
5//! This crate provides a high-level [`Mapper`] API that loads precompiled
6//! [`DataBundle`] files and exposes [`ConversionService`] and [`MappingEngine`]
7//! instances for specific format versions, message variants, and PIDs.
8//!
9//! # Quick Start — Outbound (BO4E → EDIFACT)
10//!
11//! ```ignore
12//! use edifact_mapper::{DataDir, Mapper};
13//!
14//! let mapper = Mapper::from_data_dir(DataDir::auto())?;
15//!
16//! let edifact = mapper.to_edifact(
17//! &msg_stammdaten, &tx_stammdaten,
18//! "FV2504", "UTILMD_Strom", "55001",
19//! )?;
20//! ```
21//!
22//! # Quick Start — Inbound (EDIFACT → BO4E)
23//!
24//! For inbound messages where the PID is not known upfront, use
25//! [`Mapper::detect_pid`] to extract it from the EDIFACT content:
26//!
27//! ```ignore
28//! use edifact_mapper::{DataDir, Mapper};
29//!
30//! let mapper = Mapper::from_data_dir(DataDir::auto())?;
31//!
32//! // Step 1: Detect PID from raw EDIFACT (reads RFF+Z13 or BGM+STS)
33//! let pid = mapper.detect_pid(edifact_str)?;
34//!
35//! // Step 2: Convert to typed BO4E interchange
36//! let interchange: DynamicInterchange =
37//! mapper.from_edifact(edifact_str, "FV2504", "UTILMD_Strom", &pid)?;
38//! ```
39//!
40//! # Mid-level Access
41//!
42//! For advanced use cases, key types from internal crates are re-exported:
43//!
44//! - [`ConversionService`] — tokenize EDIFACT input and assemble MIG trees
45//! - [`MappingEngine`] — convert between MIG trees and BO4E JSON
46//! - [`DataBundle`] / [`VariantCache`] — precompiled mapping data
47//! - [`edifact_parser`] — standalone EDIFACT parser (no BO4E dependency)
48
49mod conditional_validation;
50pub mod data_dir;
51pub mod error;
52pub mod evaluator_factory;
53pub mod mapper;
54mod tree_to_segments;
55
56pub use conditional_validation::validate_with_conditions;
57pub use data_dir::DataDir;
58pub use error::MapperError;
59pub use mapper::{
60 Bo4eResult, EdifactParty, InterchangeEnvelope, InterchangeMessage, Mapper, MessageMetadata,
61 PidListEntry,
62};
63
64// Re-export key types from internal crates for mid-level access.
65pub use mig_assembly::assembler::AssembledTree;
66pub use mig_assembly::ConversionService;
67pub use mig_bo4e::engine::{DataBundle, VariantCache};
68pub use mig_bo4e::MappingEngine;
69
70// Re-export PID validation types.
71pub use mig_bo4e::pid_validation::{PidValidationError, ValidationReport};
72// Raw-EDIFACT validation types for `Mapper::validate_edifact` callers. Note the
73// AHB `ValidationReport` (automapper_validation) is a distinct type from the BO4E
74// `ValidationReport` above — it's returned by `validate_edifact` and bound by
75// inference, so only the level/severity enums need naming here.
76pub use automapper_validation::{Severity, ValidationLevel};
77
78// Re-export reverse pipeline types for BO4E → EDIFACT conversion.
79pub use edifact_primitives::EdifactDelimiters;
80pub use mig_assembly::disassembler::Disassembler;
81pub use mig_assembly::pid_filter::filter_mig_for_pid;
82pub use mig_assembly::renderer::render_edifact;
83pub use mig_bo4e::model::{DynamicInterchange, MappedMessage, MappedTransaktion};
84
85// Re-export the parser for standalone use.
86pub use edifact_parser;