feat(core): Automatically convert Luxon Dates to string (#3266)

This commit is contained in:
Jan Oberhauser 2022-05-14 00:06:12 +02:00 committed by GitHub
parent 8a8feb11c8
commit 3fcee14bf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;