( nodeId: string, textValue: string, inputData: any, config?: unknown, )
| 3057 | } |
| 3058 | |
| 3059 | async function executeAppendTextNode( |
| 3060 | nodeId: string, |
| 3061 | textValue: string, |
| 3062 | inputData: any, |
| 3063 | config?: unknown, |
| 3064 | ): Promise<NodeExecutionResult> { |
| 3065 | console.log(`AppendText Node ${nodeId}: Processing with config "${textValue}" and input:`, inputData); |
| 3066 | |
| 3067 | if (!inputData) { |
| 3068 | return { success: false, error: "Invalid input: No input data provided" }; |
| 3069 | } |
| 3070 | |
| 3071 | // Parse configuration |
| 3072 | let beforeText = ""; |
| 3073 | let afterText = ""; |
| 3074 | let groupedTextSelection: "Text" | "Text Lines" = "Text"; |
| 3075 | |
| 3076 | const parsedConfig = getNodeConfig<{ |
| 3077 | beforeText?: string; |
| 3078 | afterText?: string; |
| 3079 | groupedTextSelection?: "Text" | "Text Lines"; |
| 3080 | }>(config, textValue); |
| 3081 | if (parsedConfig) { |
| 3082 | beforeText = parsedConfig.beforeText || ""; |
| 3083 | afterText = parsedConfig.afterText || ""; |
| 3084 | groupedTextSelection = parsedConfig.groupedTextSelection || "Text"; |
| 3085 | } else { |
| 3086 | // If not JSON, treat as empty configuration |
| 3087 | beforeText = ""; |
| 3088 | afterText = ""; |
| 3089 | } |
| 3090 | |
| 3091 | // Process escape sequences |
| 3092 | beforeText = beforeText.replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/\\r/g, "\r"); |
| 3093 | afterText = afterText.replace(/\\n/g, "\n").replace(/\\t/g, "\t").replace(/\\r/g, "\r"); |
| 3094 | |
| 3095 | let outputText: any; |
| 3096 | let outputTextLines: any; |
| 3097 | let outputType = inputData.type || "Text"; |
| 3098 | |
| 3099 | // Handle GroupedText input - preserve structure |
| 3100 | if (inputData.type === "GroupedText") { |
| 3101 | // Default: keep both unchanged |
| 3102 | outputText = inputData.text; |
| 3103 | outputTextLines = inputData.textLines; |
| 3104 | |
| 3105 | // Only modify the selected field |
| 3106 | if (groupedTextSelection === "Text") { |
| 3107 | // Modify text array (keys) only |
| 3108 | if (inputData.text && Array.isArray(inputData.text)) { |
| 3109 | outputText = inputData.text.map((key: string) => `${beforeText}${key}${afterText}`); |
| 3110 | } |
| 3111 | } else { |
| 3112 | // Modify textLines array (values) only |
| 3113 | if (inputData.textLines && Array.isArray(inputData.textLines)) { |
| 3114 | // TextLines is array of arrays - append to each value within each array |
| 3115 | outputTextLines = inputData.textLines.map((valueArray: string[]) => |
| 3116 | valueArray.map((value: string) => `${beforeText}${value}${afterText}`), |
no test coverage detected