#![expect(
clippy::disallowed_types,
reason = "canonical JSON / Simplified Formats operate on the wire value by definition \
(ITS-JSON; ITS-REST Simplified Formats) — serde_json::Value IS the subject matter \
(#1694)"
)]
use serde_json::{Map, Value};
use crate::flat::build;
use crate::flat::error::FlatError;
use crate::flat::flatten;
use crate::flat::sim::flat;
use crate::flat::sim::structured;
use crate::flat::webtemplate::WebTemplate;
pub fn composition_from_flat(
doc: &Map<String, Value>,
wt: &WebTemplate,
now: &str,
) -> Result<Value, FlatError> {
let tree = flat::parse_flat(doc)?;
build::build_composition(&tree, wt, now)
}
pub fn composition_to_flat(
composition: &Value,
wt: &WebTemplate,
) -> Result<Map<String, Value>, FlatError> {
let tree = flatten::flatten_composition(composition, wt)?;
Ok(flat::emit_flat(&tree))
}
pub fn composition_from_structured(
doc: &Value,
wt: &WebTemplate,
now: &str,
) -> Result<Value, FlatError> {
let tree = structured::parse_structured(doc)?;
build::build_composition(&tree, wt, now)
}
pub fn composition_to_structured(
composition: &Value,
wt: &WebTemplate,
) -> Result<Value, FlatError> {
let tree = flatten::flatten_composition(composition, wt)?;
Ok(structured::emit_structured(&tree))
}
pub fn flat_to_structured(doc: &Map<String, Value>) -> Result<Value, FlatError> {
Ok(structured::emit_structured(&flat::parse_flat(doc)?))
}
pub fn structured_to_flat(doc: &Value) -> Result<Map<String, Value>, FlatError> {
Ok(flat::emit_flat(&structured::parse_structured(doc)?))
}