use async_trait::async_trait;
use eyre::Result;
use crate::types::SharedState;
pub trait BaseNode: Send + Sync + 'static {
fn prep(&self, shared: &SharedState) -> Result<serde_json::Value>;
fn exec(&self, prep_res: &serde_json::Value) -> Result<serde_json::Value>;
fn post(
&self,
shared: &SharedState,
prep_res: &serde_json::Value,
exec_res: &serde_json::Value,
) -> Result<String>;
fn run(&self, shared: &SharedState) -> Result<String> {
let prep_res = self.prep(shared)?;
let exec_res = self.exec(&prep_res)?;
self.post(shared, &prep_res, &exec_res)
}
}
#[async_trait]
pub trait AsyncBaseNode: Send + Sync + 'static {
async fn prep_async(&self, shared: &SharedState) -> Result<serde_json::Value>;
async fn exec_async(&self, prep_res: &serde_json::Value) -> Result<serde_json::Value>;
async fn post_async(
&self,
shared: &SharedState,
prep_res: &serde_json::Value,
exec_res: &serde_json::Value,
) -> Result<String>;
async fn run_async(&self, shared: &SharedState) -> Result<String> {
let prep_res = self.prep_async(shared).await?;
let exec_res = self.exec_async(&prep_res).await?;
self.post_async(shared, &prep_res, &exec_res).await
}
}