mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-30 16:54:57 +00:00
28 lines
905 B
TypeScript
28 lines
905 B
TypeScript
import type { WorkflowNode } from '../types/level-types'
|
|
import type { WorkflowExecutionContext } from './workflow-execution-context'
|
|
import type { WorkflowState } from './workflow-state'
|
|
import { logToWorkflow } from './log-to-workflow'
|
|
|
|
/**
|
|
* Execute a transform node
|
|
*/
|
|
export async function executeTransformNode(
|
|
node: WorkflowNode,
|
|
data: any,
|
|
context: WorkflowExecutionContext,
|
|
state: WorkflowState
|
|
): Promise<{ success: boolean; output?: any; error?: string }> {
|
|
const transform = node.config.transform || 'data'
|
|
|
|
try {
|
|
const result = new Function('data', 'context', `return ${transform}`)(data, context)
|
|
logToWorkflow(state, `Transform result: ${JSON.stringify(result)}`)
|
|
return { success: true, output: result }
|
|
} catch (error) {
|
|
return {
|
|
success: false,
|
|
error: `Transform failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
}
|
|
}
|
|
}
|