From 3fcee14bf5c61ec11fc1d4f30256f5ceba09e7f4 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 14 May 2022 00:06:12 +0200 Subject: [PATCH] feat(core): Automatically convert Luxon Dates to string (#3266) --- packages/core/src/NodeExecuteFunctions.ts | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/NodeExecuteFunctions.ts index e8038b7572..fc33761a96 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/NodeExecuteFunctions.ts @@ -1386,6 +1386,36 @@ export function getNode(node: INode): INode { return JSON.parse(JSON.stringify(node)); } +/** + * Clean up parameter data to make sure that only valid data gets returned + * INFO: Currently only converts Luxon Dates as we know for sure it will not be breaking + */ +function cleanupParameterData( + inputData: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], +): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] { + if (inputData === null || inputData === undefined) { + return inputData; + } + + if (Array.isArray(inputData)) { + inputData.forEach((value) => cleanupParameterData(value)); + return inputData; + } + + if (inputData.constructor.name === 'DateTime') { + // Is a special luxon date so convert to string + return inputData.toString(); + } + + if (typeof inputData === 'object') { + Object.keys(inputData).forEach((key) => { + inputData[key] = cleanupParameterData(inputData[key]); + }); + } + + return inputData; +} + /** * Returns the requested resolved (all expressions replaced) node parameters. * @@ -1437,6 +1467,8 @@ export function getNodeParameter( timezone, additionalKeys, ); + + returnData = cleanupParameterData(returnData); } catch (e) { e.message += ` [Error in parameter: "${parameterName}"]`; throw e;