22
33const { cloneDeep } = require ( 'lodash' ) ;
44const authNode = require ( './compute/authnode' ) ;
5- // const complexNode = require('./compute/complexnode');
65const assertNode = require ( './compute/assertnode' ) ;
76const requestNode = require ( './compute/requestNode' ) ;
87const setVarNode = require ( './compute/setvarnode' ) ;
@@ -12,27 +11,25 @@ const readFile = require('../../flowtest-electron/src/utils/filemanager/readfile
1211const { serialize } = require ( '../../flowtest-electron/src/utils/flowparser/parser' ) ;
1312const Node = require ( './compute/node' ) ;
1413
15- class complexNode extends Node {
16- constructor ( nodes , edges , startTime , timeout , initialEnvVars , initialLogs ) {
17- super ( 'complexNode ' ) ;
14+ class nestedFlowNode extends Node {
15+ constructor ( nodes , edges , startTime , timeout , initialEnvVars ) {
16+ super ( 'flowNode ' ) ;
1817 try {
19- this . internalGraph = new Graph ( nodes , edges , startTime , timeout , initialEnvVars , initialLogs ) ;
18+ this . internalGraph = new Graph ( nodes , edges , startTime , timeout , initialEnvVars ) ;
2019 } catch ( error ) {
2120 console . log ( error ) ;
2221 }
2322 }
2423
2524 async evaluate ( ) {
26- //console.log('Evaluating a complex node (nested graph):');
2725 return this . internalGraph . run ( ) ;
2826 }
2927}
3028
3129class Graph {
32- constructor ( nodes , edges , startTime , timeout , initialEnvVars , initialLogs ) {
30+ constructor ( nodes , edges , startTime , timeout , initialEnvVars ) {
3331 this . nodes = nodes ;
3432 this . edges = edges ;
35- this . logs = initialLogs ;
3633 this . timeout = timeout ;
3734 this . startTime = startTime ;
3835 this . graphRunNodeOutput = { } ;
@@ -83,11 +80,7 @@ class Graph {
8380 const prevNodeOutputData = this . #computeDataFromPreviousNodes( node ) ;
8481
8582 try {
86- //console.debug('Executing node: ', node);
87-
8883 if ( node . type === 'outputNode' ) {
89- //this.logs.push(`Output: ${JSON.stringify(prevNodeOutputData)}`);
90- //useCanvasStore.getState().setOutputNode(node.id, prevNodeOutputData);
9184 console . log ( 'Output Node' ) ;
9285 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( `${ JSON . stringify ( prevNodeOutputData ) } ` ) ) ;
9386 result = {
@@ -105,15 +98,13 @@ class Graph {
10598 this . logs ,
10699 ) ;
107100 if ( eNode . evaluate ( ) ) {
108- //this.logs.push('Result: true');
109101 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( 'True' ) ) ;
110102 result = {
111103 status : 'Success' ,
112104 data : prevNodeOutputData ,
113105 output : true ,
114106 } ;
115107 } else {
116- //this.logs.push('Result: false');
117108 console . log ( chalk . red ( ` ✕ ` ) + chalk . dim ( 'False' ) ) ;
118109 result = {
119110 status : 'Success' ,
@@ -130,7 +121,6 @@ class Graph {
130121 } ;
131122 console . log ( 'Delay Node: ' + chalk . green ( `....waiting for: ${ delay } ms` ) ) ;
132123 await wait ( delay ) ;
133- //this.logs.push(`Wait for: ${delay} ms`);
134124 result = {
135125 status : 'Success' ,
136126 } ;
@@ -147,7 +137,7 @@ class Graph {
147137
148138 if ( node . type === 'requestNode' ) {
149139 console . log ( 'Request Node' ) ;
150- const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth , this . logs ) ;
140+ const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth ) ;
151141 result = await rNode . evaluate ( ) ;
152142 // add post response variables if any
153143 if ( result . postRespVars ) {
@@ -158,18 +148,17 @@ class Graph {
158148 }
159149 }
160150
161- if ( node . type === 'complexNode ' ) {
162- console . log ( 'Complex Node (Nested graph)' ) ;
151+ if ( node . type === 'flowNode ' ) {
152+ console . log ( 'Flow Node (Nested graph)' ) ;
163153 const content = readFile ( path . join ( process . cwd ( ) , node . data . relativePath ) ) ;
164154 const flowData = serialize ( JSON . parse ( content ) ) ;
165155 if ( flowData ) {
166- const cNode = new complexNode (
156+ const cNode = new nestedFlowNode (
167157 cloneDeep ( flowData . nodes ) ,
168158 cloneDeep ( flowData . edges ) ,
169159 this . startTime ,
170160 this . timeout ,
171161 this . envVariables ,
172- this . logs ,
173162 ) ;
174163 result = await cNode . evaluate ( ) ;
175164 this . envVariables = result . envVars ;
@@ -185,7 +174,6 @@ class Graph {
185174 const sNode = new setVarNode ( node . data , prevNodeOutputData , this . envVariables ) ;
186175 const newVariable = sNode . evaluate ( ) ;
187176 if ( newVariable != undefined ) {
188- //this.logs.push(`Evaluate variable: ${JSON.stringify(newVariable)}`);
189177 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( `Evaluate variable: ${ JSON . stringify ( newVariable ) } ` ) ) ;
190178 this . envVariables = {
191179 ...this . envVariables ,
@@ -198,18 +186,17 @@ class Graph {
198186 }
199187
200188 if ( this . #checkTimeout( ) ) {
201- console . log ( chalk . red ( `Timeout of ${ this . timeout } ms exceeded, stopping graph run` ) ) ;
202189 throw `Timeout of ${ this . timeout } ms exceeded, stopping graph run` ;
203190 }
204191 } catch ( err ) {
205- this . logs . push ( `Flow failed at: ${ JSON . stringify ( node ) } due to ${ err } ` ) ;
192+ console . log ( chalk . red ( `Flow failed at: ${ JSON . stringify ( node ) } due to ${ err } ` ) ) ;
206193 return {
207194 status : 'Failed' ,
208195 } ;
209196 }
210197
211198 if ( result === undefined ) {
212- this . logs . push ( `Flow failed at : ${ JSON . stringify ( node ) } ` ) ;
199+ console . log ( chalk . red ( `Flow failed due to failure to evaluate result at node : ${ node . data } ` ) ) ;
213200 return {
214201 status : 'Failed' ,
215202 } ;
@@ -219,7 +206,7 @@ class Graph {
219206 if ( connectingEdge != undefined ) {
220207 const nextNode = this . nodes . find (
221208 ( node ) =>
222- [ 'requestNode' , 'outputNode' , 'assertNode' , 'delayNode' , 'authNode' , 'complexNode ' , 'setVarNode' ] . includes (
209+ [ 'requestNode' , 'outputNode' , 'assertNode' , 'delayNode' , 'authNode' , 'flowNode ' , 'setVarNode' ] . includes (
223210 node . type ,
224211 ) && node . id === connectingEdge . target ,
225212 ) ;
@@ -232,25 +219,15 @@ class Graph {
232219 }
233220
234221 async run ( ) {
235- // reset every output node for a fresh run
236- // this.nodes.forEach((node) => {
237- // if (node.type === 'outputNode') {
238- // useCanvasStore.getState().unSetOutputNode(node.id);
239- // }
240- // });
241222 this . graphRunNodeOutput = { } ;
242223
243- //this.logs.push('Start Flowtest');
244224 console . log ( chalk . green ( 'Start Flowtest' ) ) ;
245225 const startNode = this . nodes . find ( ( node ) => node . type === 'startNode' ) ;
246226 if ( startNode == undefined ) {
247- //this.logs.push('No start node found');
248- //this.logs.push('End Flowtest');
249227 console . log ( chalk . red ( `✕ ` ) + chalk . red ( 'No start node found' ) ) ;
250228 console . log ( chalk . red ( 'End Flowtest' ) ) ;
251229 return {
252230 status : 'Success' ,
253- logs : this . logs ,
254231 envVars : this . envVariables ,
255232 } ;
256233 }
@@ -265,18 +242,14 @@ class Graph {
265242 } else {
266243 console . log ( chalk . green ( 'End Flowtest' ) ) ;
267244 }
268- //this.logs.push('End Flowtest');
269245 return {
270246 status : result . status ,
271- logs : this . logs ,
272247 envVars : this . envVariables ,
273248 } ;
274249 } else {
275- //this.logs.push('End Flowtest');
276250 console . log ( chalk . green ( 'End Flowtest' ) ) ;
277251 return {
278252 status : 'Success' ,
279- logs : this . logs ,
280253 envVars : this . envVariables ,
281254 } ;
282255 }
0 commit comments