mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Always stringify data of Function-Nodes (#2606)
* ⚡ Always stringify data of Function-Nodes * ⚡ Fix lint issue and fix data
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
@@ -58,6 +59,21 @@ return items;`,
|
||||
// Copy the items as they may get changed in the functions
|
||||
items = JSON.parse(JSON.stringify(items));
|
||||
|
||||
const cleanupData = (inputData: IDataObject): IDataObject => {
|
||||
Object.keys(inputData).map(key => {
|
||||
if (inputData[key] !== null && typeof inputData[key] === 'object') {
|
||||
if (inputData[key]!.constructor.name === 'Object') {
|
||||
// Is regular node.js object so check its data
|
||||
inputData[key] = cleanupData(inputData[key] as IDataObject);
|
||||
} else {
|
||||
// Is some special object like a Date so stringify
|
||||
inputData[key] = JSON.parse(JSON.stringify(inputData[key]));
|
||||
}
|
||||
}
|
||||
});
|
||||
return inputData;
|
||||
};
|
||||
|
||||
// Define the global objects for the custom function
|
||||
const sandbox = {
|
||||
getNodeParameter: this.getNodeParameter,
|
||||
@@ -117,6 +133,9 @@ return items;`,
|
||||
if (typeof item.json !== 'object') {
|
||||
throw new NodeOperationError(this.getNode(), 'The json-property has to be an object!');
|
||||
}
|
||||
|
||||
item.json = cleanupData(item.json);
|
||||
|
||||
if (item.binary !== undefined) {
|
||||
if (Array.isArray(item.binary) || typeof item.binary !== 'object') {
|
||||
throw new NodeOperationError(this.getNode(), 'The binary-property has to be an object!');
|
||||
@@ -143,9 +162,6 @@ return items;`,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return this.prepareOutputData(items);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user