Skip to main content

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::{GroupEntrySegmentError, MapperError};
59pub use mapper::{
60    Bo4eResult, EdifactParty, EnvelopeOptions, InterchangeEnvelope, InterchangeMessage, Mapper,
61    MessageMetadata, 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// AHB validation types for `Mapper::validate_edifact` / `Mapper::validate_bo4e`
73// callers. The AHB report is a distinct type from the BO4E `ValidationReport`
74// above, so it is re-exported under a non-clashing name.
75pub use automapper_validation::{
76    IssueKind, Severity, UnresolvedConditions, ValidationCategory, ValidationIssue,
77    ValidationLevel, ValidationReport as AhbValidationReport,
78};
79// The display layer: narrating a `ValidationIssue`'s `kind` into words, for
80// callers that want the legacy `message`/`code`/`category` shape (a display
81// boundary — see `automapper_validation::display`). `IssueKind` and
82// `ValidationCategory` are re-exported above so a consumer can implement
83// `IssueView`/`IssueNarrator` for a world of their own — `StructureDiagnosticKind`
84// below completes that, since `IssueKind::StructureDiagnostic`'s `kind` field
85// is that type.
86pub use automapper_validation::display;
87// Assembly diagnostics for `Mapper::from_edifact_with_diagnostics` callers.
88pub use mig_assembly::{StructureDiagnostic, StructureDiagnosticKind};
89
90// Re-export reverse pipeline types for BO4E → EDIFACT conversion.
91pub use edifact_primitives::EdifactDelimiters;
92pub use mig_assembly::disassembler::Disassembler;
93pub use mig_assembly::pid_filter::filter_mig_for_pid;
94pub use mig_assembly::renderer::render_edifact;
95pub use mig_bo4e::model::{DynamicInterchange, MappedMessage, MappedTransaktion};
96
97// Re-export the parser for standalone use.
98pub use edifact_parser;