flexbiz-server
Version:
Flexible Server
5 lines (4 loc) • 1.56 kB
JavaScript
const {evalute}=require("../../libs/utils"),moment=require("moment"),numeral=require("numeral"),_=require("lodash");
async function functionHandler($flowState_nodeInstanceId$$,$node_sandbox$$,$payload$$,$abortSignal$$){$flowState_nodeInstanceId$$=`${$flowState_nodeInstanceId$$.instanceId}-${$node_sandbox$$.id}`;const $userCode$$=$node_sandbox$$.data?.code;if(typeof $userCode$$!=="string"||$userCode$$.trim()==="")return Logger.warn(`[${$flowState_nodeInstanceId$$}] Function node has no code to execute.`),$payload$$;if($abortSignal$$.aborted)throw Logger.info(`[${$flowState_nodeInstanceId$$}] Function node aborted before execution.`),
new DOMException("Function node aborted before execution","AbortError");$node_sandbox$$={payload:$payload$$,node:{id:$node_sandbox$$.id,type:$node_sandbox$$.type,data:{...$node_sandbox$$.data}},console,moment,numeral,_};Logger.info(`[${$flowState_nodeInstanceId$$}] Executing function node code...`);try{const $result$$=evalute($userCode$$,$node_sandbox$$,5E3);if($abortSignal$$.aborted)throw Logger.info(`[${$flowState_nodeInstanceId$$}] Function node aborted immediately after execution (code might have finished).`),
new DOMException("Function node aborted after execution","AbortError");Logger.info(`[${$flowState_nodeInstanceId$$}] Function node execution finished.`);return $result$$}catch($executionError$$){throw Logger.error(`[${$flowState_nodeInstanceId$$}] Error executing function node code:`,$executionError$$),Error(`Function node error: ${$executionError$$.message}`);}}module.exports=functionHandler;