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 element_scopes;
52pub mod error;
53pub mod evaluator_factory;
54pub mod mapper;
55mod transaction_view;
56mod tree_to_segments;
57
58pub use conditional_validation::{validate_with_conditions, validate_with_conditions_in_scopes};
59pub use data_dir::DataDir;
60pub use error::{GroupEntrySegmentError, MapperError};
61pub use mapper::{
62 Bo4eResult, CodeForm, EdifactParty, EnvelopeOptions, FromEdifactOptions, InterchangeEnvelope,
63 InterchangeMessage, Mapper, MessageMetadata, PidListEntry,
64};
65pub use transaction_view::TransactionView;
66
67// Re-export key types from internal crates for mid-level access.
68pub use mig_assembly::assembler::AssembledTree;
69pub use mig_assembly::ConversionService;
70pub use mig_bo4e::engine::{DataBundle, VariantCache};
71pub use mig_bo4e::MappingEngine;
72
73// Re-export PID validation types.
74pub use mig_bo4e::pid_validation::{PidValidationError, ValidationReport};
75// AHB validation types for `Mapper::validate_edifact` / `Mapper::validate_bo4e`
76// callers. The AHB report is a distinct type from the BO4E `ValidationReport`
77// above, so it is re-exported under a non-clashing name.
78pub use automapper_validation::{
79 IssueKind, Severity, UnresolvedConditions, ValidationCategory, ValidationIssue,
80 ValidationLevel, ValidationReport as AhbValidationReport,
81};
82// The display layer: narrating a `ValidationIssue`'s `kind` into words, for
83// callers that want the legacy `message`/`code`/`category` shape (a display
84// boundary — see `automapper_validation::display`). `IssueKind` and
85// `ValidationCategory` are re-exported above so a consumer can implement
86// `IssueView`/`IssueNarrator` for a world of their own — `StructureDiagnosticKind`
87// below completes that, since `IssueKind::StructureDiagnostic`'s `kind` field
88// is that type.
89pub use automapper_validation::display;
90// Assembly diagnostics for `Mapper::from_edifact_with_diagnostics` callers.
91pub use mig_assembly::{StructureDiagnostic, StructureDiagnosticKind};
92
93// Re-export reverse pipeline types for BO4E → EDIFACT conversion.
94pub use edifact_primitives::charset;
95pub use edifact_primitives::EdifactDelimiters;
96pub use mig_assembly::disassembler::Disassembler;
97pub use mig_assembly::pid_filter::filter_mig_for_pid;
98pub use mig_assembly::renderer::render_edifact;
99pub use mig_bo4e::model::{DynamicInterchange, MappedMessage, MappedTransaktion};
100
101// Re-export the parser for standalone use.
102pub use edifact_parser;