use crate::{Context, Expand, ExpandedDocument, Loader, Options, WarningHandler, error::Error};
use rdfx::vocabulary::VocabularyMut;
use std::hash::Hash;
#[derive(Debug, thiserror::Error)]
pub enum SliceExpansionError<E> {
#[error("invalid JSON: {0}")]
Syntax(#[from] jstrict::parse::Error),
#[error(transparent)]
Expansion(Error<E>),
}
pub async fn expand_slice<N, L, W>(
bytes: &[u8],
vocabulary: &mut N,
context: Context<N::Iri, N::BlankId>,
base_url: Option<&N::Iri>,
loader: &L,
options: Options,
warnings: W,
) -> Result<ExpandedDocument<N::Iri, N::BlankId>, SliceExpansionError<L::Error>>
where
N: VocabularyMut,
N::Iri: Clone + Eq + Hash,
N::BlankId: Clone + Eq + Hash,
L: Loader,
W: WarningHandler<N>,
{
let document = jstrict::parse::parse_slice_value(bytes)?;
document
.expand_full(vocabulary, context, base_url, loader, options, warnings)
.await
.map_err(SliceExpansionError::Expansion)
}