@@ -10,12 +10,13 @@ const path = require('path');
1010const readFile = require ( '../../flowtest-electron/src/utils/filemanager/readfile' ) ;
1111const { serialize } = require ( '../../flowtest-electron/src/utils/flowparser/parser' ) ;
1212const Node = require ( './compute/node' ) ;
13+ const { LogLevel } = require ( './GraphLogger' ) ;
1314
1415class nestedFlowNode extends Node {
15- constructor ( nodes , edges , startTime , timeout , initialEnvVars ) {
16+ constructor ( nodes , edges , startTime , timeout , initialEnvVars , logger ) {
1617 super ( 'flowNode' ) ;
1718 try {
18- this . internalGraph = new Graph ( nodes , edges , startTime , timeout , initialEnvVars ) ;
19+ this . internalGraph = new Graph ( nodes , edges , startTime , timeout , initialEnvVars , logger ) ;
1920 } catch ( error ) {
2021 console . log ( error ) ;
2122 }
@@ -27,14 +28,15 @@ class nestedFlowNode extends Node {
2728}
2829
2930class Graph {
30- constructor ( nodes , edges , startTime , timeout , initialEnvVars ) {
31+ constructor ( nodes , edges , startTime , timeout , initialEnvVars , logger ) {
3132 this . nodes = nodes ;
3233 this . edges = edges ;
3334 this . timeout = timeout ;
3435 this . startTime = startTime ;
3536 this . graphRunNodeOutput = { } ;
3637 this . auth = undefined ;
3738 this . envVariables = initialEnvVars ;
39+ this . logger = logger ;
3840 }
3941
4042 #checkTimeout( ) {
@@ -83,6 +85,7 @@ class Graph {
8385 if ( node . type === 'outputNode' ) {
8486 console . log ( 'Output Node' ) ;
8587 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( `${ JSON . stringify ( prevNodeOutputData ) } ` ) ) ;
88+ this . logger . add ( LogLevel . INFO , '' , { type : 'outputNode' , data : { output : prevNodeOutputData } } ) ;
8689 result = {
8790 status : 'Success' ,
8891 data : prevNodeOutputData ,
@@ -95,7 +98,7 @@ class Graph {
9598 node . data . variables ,
9699 prevNodeOutputData ,
97100 this . envVariables ,
98- this . logs ,
101+ this . logger ,
99102 ) ;
100103 if ( eNode . evaluate ( ) ) {
101104 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( 'True' ) ) ;
@@ -121,6 +124,7 @@ class Graph {
121124 } ;
122125 console . log ( 'Delay Node: ' + chalk . green ( `....waiting for: ${ delay } ms` ) ) ;
123126 await wait ( delay ) ;
127+ this . logger . add ( LogLevel . INFO , '' , { type : 'delayNode' , data : { delay } } ) ;
124128 result = {
125129 status : 'Success' ,
126130 } ;
@@ -137,7 +141,7 @@ class Graph {
137141
138142 if ( node . type === 'requestNode' ) {
139143 console . log ( 'Request Node' ) ;
140- const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth ) ;
144+ const rNode = new requestNode ( node . data , prevNodeOutputData , this . envVariables , this . auth , this . logger ) ;
141145 result = await rNode . evaluate ( ) ;
142146 // add post response variables if any
143147 if ( result . postRespVars ) {
@@ -159,6 +163,7 @@ class Graph {
159163 this . startTime ,
160164 this . timeout ,
161165 this . envVariables ,
166+ this . logger ,
162167 ) ;
163168 result = await cNode . evaluate ( ) ;
164169 this . envVariables = result . envVars ;
@@ -175,6 +180,13 @@ class Graph {
175180 const newVariable = sNode . evaluate ( ) ;
176181 if ( newVariable != undefined ) {
177182 console . log ( chalk . green ( ` ✓ ` ) + chalk . dim ( `Set variable: ${ JSON . stringify ( newVariable ) } ` ) ) ;
183+ this . logger . add ( LogLevel . INFO , '' , {
184+ type : 'setVarNode' ,
185+ data : {
186+ name : Object . keys ( newVariable ) [ 0 ] ,
187+ value : newVariable [ Object . keys ( newVariable ) [ 0 ] ] ,
188+ } ,
189+ } ) ;
178190 this . envVariables = {
179191 ...this . envVariables ,
180192 ...newVariable ,
@@ -186,17 +198,19 @@ class Graph {
186198 }
187199
188200 if ( this . #checkTimeout( ) ) {
189- throw `Timeout of ${ this . timeout } ms exceeded, stopping graph run` ;
201+ throw Error ( `Timeout of ${ this . timeout } ms exceeded, stopping graph run` ) ;
190202 }
191203 } catch ( err ) {
192204 console . log ( chalk . red ( `Flow failed at: ${ JSON . stringify ( node . data ) } due to ${ err } ` ) ) ;
205+ this . logger . add ( LogLevel . ERROR , `Flow failed due to ${ err } ` , node ) ;
193206 return {
194207 status : 'Failed' ,
195208 } ;
196209 }
197210
198211 if ( result === undefined ) {
199212 console . log ( chalk . red ( `Flow failed due to failure to evaluate result at node: ${ node . data } ` ) ) ;
213+ this . logger . add ( LogLevel . ERROR , 'Flow failed due to failure to evaluate result' , node ) ;
200214 return {
201215 status : 'Failed' ,
202216 } ;
@@ -222,10 +236,14 @@ class Graph {
222236 this . graphRunNodeOutput = { } ;
223237
224238 console . log ( chalk . green ( 'Start Flowtest' ) ) ;
239+ this . logger . add ( LogLevel . INFO , 'Start Flowtest' ) ;
240+
225241 const startNode = this . nodes . find ( ( node ) => node . type === 'startNode' ) ;
226242 if ( startNode == undefined ) {
227243 console . log ( chalk . red ( `✕ ` ) + chalk . red ( 'No start node found' ) ) ;
228244 console . log ( chalk . red ( 'End Flowtest' ) ) ;
245+ this . logger . add ( LogLevel . INFO , 'No start node found' ) ;
246+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
229247 return {
230248 status : 'Success' ,
231249 envVars : this . envVariables ,
@@ -242,12 +260,14 @@ class Graph {
242260 } else {
243261 console . log ( chalk . green ( 'End Flowtest' ) ) ;
244262 }
263+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
245264 return {
246265 status : result . status ,
247266 envVars : this . envVariables ,
248267 } ;
249268 } else {
250269 console . log ( chalk . green ( 'End Flowtest' ) ) ;
270+ this . logger . add ( LogLevel . INFO , 'End Flowtest' ) ;
251271 return {
252272 status : 'Success' ,
253273 envVars : this . envVariables ,
0 commit comments