mirror of
https://github.com/gorules/zen.git
synced 2026-10-06 00:02:31 +00:00
fix
This commit is contained in:
@@ -261,14 +261,14 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
});
|
||||
walker.set_node_data(nid, res.output);
|
||||
}
|
||||
DecisionNodeKind::DecisionNode { content } => {
|
||||
DecisionNodeKind::DecisionNode { .. } => {
|
||||
let node_request = NodeRequest {
|
||||
node: node.clone(),
|
||||
iteration: self.iteration,
|
||||
input: walker.incoming_node_data(&self.graph, nid, true),
|
||||
};
|
||||
|
||||
let mut res = DecisionHandler::new(
|
||||
let res = DecisionHandler::new(
|
||||
self.trace,
|
||||
self.max_depth,
|
||||
self.loader.clone(),
|
||||
@@ -285,11 +285,6 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
node_request.input.dot_remove("$nodes");
|
||||
res.output.dot_remove("$nodes");
|
||||
|
||||
if content.pass_through {
|
||||
let mut base = node_request.input.clone();
|
||||
res.output = base.merge(&res.output)
|
||||
}
|
||||
|
||||
trace!({
|
||||
input: node_request.input,
|
||||
output: res.output.clone(),
|
||||
@@ -300,14 +295,14 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
});
|
||||
walker.set_node_data(nid, res.output);
|
||||
}
|
||||
DecisionNodeKind::DecisionTableNode { content } => {
|
||||
DecisionNodeKind::DecisionTableNode { .. } => {
|
||||
let node_request = NodeRequest {
|
||||
node: node.clone(),
|
||||
iteration: self.iteration,
|
||||
input: walker.incoming_node_data(&self.graph, nid, true),
|
||||
};
|
||||
|
||||
let mut res = DecisionTableHandler::new(self.trace)
|
||||
let res = DecisionTableHandler::new(self.trace)
|
||||
.handle(node_request.clone())
|
||||
.await
|
||||
.map_err(|e| NodeError {
|
||||
@@ -319,11 +314,6 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
res.output.dot_remove("$nodes");
|
||||
res.output.dot_remove("$");
|
||||
|
||||
if content.pass_through {
|
||||
let mut base = node_request.input.clone();
|
||||
res.output = base.merge(&res.output)
|
||||
}
|
||||
|
||||
trace!({
|
||||
input: node_request.input,
|
||||
output: res.output.clone(),
|
||||
@@ -334,14 +324,14 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
});
|
||||
walker.set_node_data(nid, res.output);
|
||||
}
|
||||
DecisionNodeKind::ExpressionNode { content } => {
|
||||
DecisionNodeKind::ExpressionNode { .. } => {
|
||||
let node_request = NodeRequest {
|
||||
node: node.clone(),
|
||||
iteration: self.iteration,
|
||||
input: walker.incoming_node_data(&self.graph, nid, true),
|
||||
};
|
||||
|
||||
let mut res = ExpressionHandler::new(self.trace)
|
||||
let res = ExpressionHandler::new(self.trace)
|
||||
.handle(node_request.clone())
|
||||
.await
|
||||
.map_err(|e| NodeError {
|
||||
@@ -352,11 +342,6 @@ impl<L: DecisionLoader + 'static, A: CustomNodeAdapter + 'static> DecisionGraph<
|
||||
node_request.input.dot_remove("$nodes");
|
||||
res.output.dot_remove("$nodes");
|
||||
|
||||
if content.pass_through {
|
||||
let mut base = node_request.input.clone();
|
||||
res.output = base.merge(&res.output)
|
||||
}
|
||||
|
||||
trace!({
|
||||
input: node_request.input,
|
||||
output: res.output.clone(),
|
||||
|
||||
@@ -75,8 +75,6 @@ pub struct FunctionContent {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DecisionNodeContent {
|
||||
pub key: String,
|
||||
#[serde(default)]
|
||||
pub pass_through: bool,
|
||||
#[serde(flatten)]
|
||||
pub transform_attributes: TransformAttributes,
|
||||
}
|
||||
@@ -89,8 +87,6 @@ pub struct DecisionTableContent {
|
||||
pub inputs: Vec<DecisionTableInputField>,
|
||||
pub outputs: Vec<DecisionTableOutputField>,
|
||||
pub hit_policy: DecisionTableHitPolicy,
|
||||
#[serde(default)]
|
||||
pub pass_through: bool,
|
||||
#[serde(flatten)]
|
||||
pub transform_attributes: TransformAttributes,
|
||||
}
|
||||
@@ -127,8 +123,6 @@ pub struct DecisionTableOutputField {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExpressionNodeContent {
|
||||
pub expressions: Vec<Expression>,
|
||||
#[serde(default)]
|
||||
pub pass_through: bool,
|
||||
#[serde(flatten)]
|
||||
pub transform_attributes: TransformAttributes,
|
||||
}
|
||||
@@ -178,6 +172,8 @@ pub struct TransformAttributes {
|
||||
pub output_path: Option<String>,
|
||||
#[serde(default)]
|
||||
pub execution_mode: TransformExecutionMode,
|
||||
#[serde(default)]
|
||||
pub pass_through: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)]
|
||||
|
||||
@@ -6,22 +6,39 @@ use std::future::Future;
|
||||
use zen_expression::{Isolate, Variable};
|
||||
|
||||
impl TransformAttributes {
|
||||
pub(crate) async fn run_with<F, Fut>(&self, input: Variable, evaluate: F) -> NodeResult
|
||||
pub(crate) async fn run_with<F, Fut>(&self, node_input: Variable, evaluate: F) -> NodeResult
|
||||
where
|
||||
F: Fn(Variable) -> Fut,
|
||||
Fut: Future<Output = NodeResult>,
|
||||
{
|
||||
let input = match &self.input_field {
|
||||
None => input.clone(),
|
||||
None => node_input.clone(),
|
||||
Some(input_field) => {
|
||||
let mut isolate = Isolate::new();
|
||||
isolate.set_environment(input.clone());
|
||||
isolate.set_environment(node_input.clone());
|
||||
let calculated_input = isolate.run_standard(input_field.as_str())?;
|
||||
|
||||
let new_input = isolate.run_standard(input_field.as_str())?;
|
||||
let nodes = input.dot("$nodes").unwrap_or(Variable::empty_object());
|
||||
new_input.dot_insert("$nodes", nodes);
|
||||
let nodes = node_input.dot("$nodes").unwrap_or(Variable::Null);
|
||||
match &calculated_input {
|
||||
Variable::Array(arr) => {
|
||||
let arr = arr.borrow();
|
||||
let s: Vec<_> = arr
|
||||
.iter()
|
||||
.map(|v| {
|
||||
let new_v = v.depth_clone(1);
|
||||
new_v.dot_insert("$nodes", nodes.clone());
|
||||
new_v
|
||||
})
|
||||
.collect();
|
||||
|
||||
new_input
|
||||
Variable::from_array(s)
|
||||
}
|
||||
_ => {
|
||||
let new_input = calculated_input.depth_clone(1);
|
||||
new_input.dot_insert("$nodes", nodes);
|
||||
new_input
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -33,6 +50,7 @@ impl TransformAttributes {
|
||||
trace_data.replace(td);
|
||||
}
|
||||
|
||||
response.output.dot_remove("$nodes");
|
||||
response.output
|
||||
}
|
||||
TransformExecutionMode::Loop => {
|
||||
@@ -42,12 +60,17 @@ impl TransformAttributes {
|
||||
let mut output_array = Vec::with_capacity(input_array.len());
|
||||
let mut trace_datum = Vec::with_capacity(input_array.len());
|
||||
for input in input_array.iter() {
|
||||
let response = evaluate(input.clone()).await?;
|
||||
|
||||
output_array.push(response.output);
|
||||
let mut response = evaluate(input.clone()).await?;
|
||||
if let Some(td) = response.trace_data {
|
||||
trace_datum.push(td);
|
||||
}
|
||||
|
||||
if self.pass_through {
|
||||
response.output = input.clone().merge(&response.output);
|
||||
}
|
||||
|
||||
response.output.dot_remove("$nodes");
|
||||
output_array.push(response.output);
|
||||
}
|
||||
|
||||
trace_data.replace(Value::Array(trace_datum));
|
||||
@@ -62,6 +85,11 @@ impl TransformAttributes {
|
||||
output = new_output;
|
||||
}
|
||||
|
||||
if self.pass_through {
|
||||
let mut node_input = node_input;
|
||||
output = node_input.merge(&output)
|
||||
}
|
||||
|
||||
Ok(NodeResponse { output, trace_data })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user