use crate::{
JsonLdBacktraceBuilder, JsonLdDocument, JsonLdExpandedDocument, JsonLdIndexedObject,
JsonLdLocatedError, JsonLdObject, JsonLdSourceFileRef, algorithms::AsyncJsonLdEnvironment,
context::RawJsonLdProcessedContext,
};
mod array;
mod document;
mod element;
mod environment;
mod expanded;
mod literal;
mod node;
mod options;
mod value;
use element::*;
use environment::*;
use expanded::*;
use literal::*;
use node::node_id_of_term;
pub use options::*;
pub trait JsonLdExpand {
#[allow(async_fn_in_trait)]
async fn expand(
&self,
env: impl AsyncJsonLdEnvironment,
) -> Result<JsonLdExpandedDocument, JsonLdLocatedError>;
#[allow(async_fn_in_trait)]
async fn expand_with(
&self,
env: impl AsyncJsonLdEnvironment,
active_context: &RawJsonLdProcessedContext,
options: JsonLdExpansionOptions,
) -> Result<JsonLdExpandedDocument, JsonLdLocatedError>;
}
impl JsonLdExpand for JsonLdDocument {
async fn expand(
&self,
env: impl AsyncJsonLdEnvironment,
) -> Result<JsonLdExpandedDocument, JsonLdLocatedError> {
let active_context = RawJsonLdProcessedContext::new(self.url().map(ToOwned::to_owned));
self.expand_with(env, &active_context, JsonLdExpansionOptions::default())
.await
}
async fn expand_with(
&self,
env: impl AsyncJsonLdEnvironment,
active_context: &RawJsonLdProcessedContext,
options: JsonLdExpansionOptions,
) -> Result<JsonLdExpandedDocument, JsonLdLocatedError> {
let loc = JsonLdBacktraceBuilder::new().file(JsonLdSourceFileRef::original(self.url()));
Expander {
base_url: self.url(),
options,
active_context,
active_property: None,
}
.expand_document(&env, self.document(), loc)
.await
}
}
fn filter_top_level_item(item: &JsonLdIndexedObject) -> bool {
!matches!(item.inner(), JsonLdObject::Value(_))
}