pub struct EdgePostExecutionArguments {
definition: crate::wit::EdgeDefinition,
edges: Vec<(String, Vec<String>)>,
metadata: String,
}
impl EdgePostExecutionArguments {
pub(crate) fn new(
definition: crate::wit::EdgeDefinition,
edges: Vec<(String, Vec<String>)>,
metadata: String,
) -> Self {
Self {
definition,
edges,
metadata,
}
}
pub fn parent_type_name(&self) -> &str {
&self.definition.parent_type_name
}
pub fn field_name(&self) -> &str {
&self.definition.field_name
}
pub fn edges<'a, T, K>(&'a self) -> Result<Vec<(T, Vec<K>)>, serde_json::Error>
where
T: serde::Deserialize<'a>,
K: serde::Deserialize<'a>,
{
self.edges
.iter()
.map(|(parent, nodes)| {
let parent: T = serde_json::from_str(parent)?;
let nodes: Vec<K> = nodes
.iter()
.map(|node| serde_json::from_str(node))
.collect::<Result<_, _>>()?;
Ok((parent, nodes))
})
.collect()
}
pub fn metadata<'a, T>(&'a self) -> Result<T, serde_json::Error>
where
T: serde::Deserialize<'a>,
{
serde_json::from_str(&self.metadata)
}
}