edifact-mapper 0.8.0

EDIFACT to BO4E bidirectional conversion for the German energy market
Documentation
//! # edifact-mapper
//!
//! EDIFACT to BO4E bidirectional conversion for the German energy market.
//!
//! This crate provides a high-level [`Mapper`] API that loads precompiled
//! [`DataBundle`] files and exposes [`ConversionService`] and [`MappingEngine`]
//! instances for specific format versions, message variants, and PIDs.
//!
//! # Quick Start — Outbound (BO4E → EDIFACT)
//!
//! ```ignore
//! use edifact_mapper::{DataDir, Mapper};
//!
//! let mapper = Mapper::from_data_dir(DataDir::auto())?;
//!
//! let edifact = mapper.to_edifact(
//!     &msg_stammdaten, &tx_stammdaten,
//!     "FV2504", "UTILMD_Strom", "55001",
//! )?;
//! ```
//!
//! # Quick Start — Inbound (EDIFACT → BO4E)
//!
//! For inbound messages where the PID is not known upfront, use
//! [`Mapper::detect_pid`] to extract it from the EDIFACT content:
//!
//! ```ignore
//! use edifact_mapper::{DataDir, Mapper};
//!
//! let mapper = Mapper::from_data_dir(DataDir::auto())?;
//!
//! // Step 1: Detect PID from raw EDIFACT (reads RFF+Z13 or BGM+STS)
//! let pid = mapper.detect_pid(edifact_str)?;
//!
//! // Step 2: Convert to typed BO4E interchange
//! let interchange: DynamicInterchange =
//!     mapper.from_edifact(edifact_str, "FV2504", "UTILMD_Strom", &pid)?;
//! ```
//!
//! # Mid-level Access
//!
//! For advanced use cases, key types from internal crates are re-exported:
//!
//! - [`ConversionService`] — tokenize EDIFACT input and assemble MIG trees
//! - [`MappingEngine`] — convert between MIG trees and BO4E JSON
//! - [`DataBundle`] / [`VariantCache`] — precompiled mapping data
//! - [`edifact_parser`] — standalone EDIFACT parser (no BO4E dependency)

mod conditional_validation;
pub mod data_dir;
pub mod error;
pub mod evaluator_factory;
pub mod mapper;
mod tree_to_segments;

pub use conditional_validation::validate_with_conditions;
pub use data_dir::DataDir;
pub use error::{GroupEntrySegmentError, MapperError};
pub use mapper::{
    Bo4eResult, EdifactParty, EnvelopeOptions, InterchangeEnvelope, InterchangeMessage, Mapper,
    MessageMetadata, PidListEntry,
};

// Re-export key types from internal crates for mid-level access.
pub use mig_assembly::assembler::AssembledTree;
pub use mig_assembly::ConversionService;
pub use mig_bo4e::engine::{DataBundle, VariantCache};
pub use mig_bo4e::MappingEngine;

// Re-export PID validation types.
pub use mig_bo4e::pid_validation::{PidValidationError, ValidationReport};
// AHB validation types for `Mapper::validate_edifact` / `Mapper::validate_bo4e`
// callers. The AHB report is a distinct type from the BO4E `ValidationReport`
// above, so it is re-exported under a non-clashing name.
pub use automapper_validation::{
    IssueKind, Severity, UnresolvedConditions, ValidationCategory, ValidationIssue,
    ValidationLevel, ValidationReport as AhbValidationReport,
};
// The display layer: narrating a `ValidationIssue`'s `kind` into words, for
// callers that want the legacy `message`/`code`/`category` shape (a display
// boundary — see `automapper_validation::display`). `IssueKind` and
// `ValidationCategory` are re-exported above so a consumer can implement
// `IssueView`/`IssueNarrator` for a world of their own — `StructureDiagnosticKind`
// below completes that, since `IssueKind::StructureDiagnostic`'s `kind` field
// is that type.
pub use automapper_validation::display;
// Assembly diagnostics for `Mapper::from_edifact_with_diagnostics` callers.
pub use mig_assembly::{StructureDiagnostic, StructureDiagnosticKind};

// Re-export reverse pipeline types for BO4E → EDIFACT conversion.
pub use edifact_primitives::EdifactDelimiters;
pub use mig_assembly::disassembler::Disassembler;
pub use mig_assembly::pid_filter::filter_mig_for_pid;
pub use mig_assembly::renderer::render_edifact;
pub use mig_bo4e::model::{DynamicInterchange, MappedMessage, MappedTransaktion};

// Re-export the parser for standalone use.
pub use edifact_parser;