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};
62
63// Re-export key types from internal crates for mid-level access.
64pub use mig_assembly::assembler::AssembledTree;
65pub use mig_assembly::ConversionService;
66pub use mig_bo4e::engine::{DataBundle, VariantCache};
67pub use mig_bo4e::MappingEngine;
68
69// Re-export PID validation types.
70pub use mig_bo4e::pid_validation::{PidValidationError, ValidationReport};
71
72// Re-export reverse pipeline types for BO4E → EDIFACT conversion.
73pub use edifact_primitives::EdifactDelimiters;
74pub use mig_assembly::disassembler::Disassembler;
75pub use mig_assembly::pid_filter::filter_mig_for_pid;
76pub use mig_assembly::renderer::render_edifact;
77pub use mig_bo4e::model::{MappedMessage, MappedTransaktion};
78
79// Re-export the parser for standalone use.
80pub use edifact_parser;