refactor: Format nodes-base package (A-F) (#3800)

* 🔨 prettier formated nodes - A

* 🔨 prettier formated nodes - B

*  prettier formated nodes - C

*  prettier formated nodes - D

*  prettier formated nodes - E-F

* 🎨 Adjust nodes-base formatting command (#3805)

* Format additional files in nodes A-F (#3811)

*  fixes

* 🎨 Add Mindee to ignored dirs

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Michael Kret
2022-08-01 23:47:55 +03:00
committed by GitHub
parent 2c17e6f3ca
commit 0ecbb4a19d
411 changed files with 12906 additions and 20148 deletions

View File

@@ -16,7 +16,8 @@ export class Function implements INodeType {
icon: 'fa:code',
group: ['transform'],
version: 1,
description: 'Run custom function code which gets executed once and allows you to add, remove, change and replace items',
description:
'Run custom function code which gets executed once and allows you to add, remove, change and replace items',
defaults: {
name: 'Function',
color: '#FF9922',
@@ -61,7 +62,7 @@ return items;`,
items = JSON.parse(JSON.stringify(items));
const cleanupData = (inputData: IDataObject): IDataObject => {
Object.keys(inputData).map(key => {
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
@@ -92,7 +93,7 @@ return items;`,
const mode = this.getMode();
const options = {
console: (mode === 'manual') ? 'redirect' : 'inherit',
console: mode === 'manual' ? 'redirect' : 'inherit',
sandbox,
require: {
external: false as boolean | { modules: string[] },
@@ -119,19 +120,28 @@ return items;`,
try {
// Execute the function code
items = (await vm.run(`module.exports = async function() {${functionCode}\n}()`, __dirname));
items = await vm.run(`module.exports = async function() {${functionCode}\n}()`, __dirname);
items = this.helpers.normalizeItems(items);
// Do very basic validation of the data
if (items === undefined) {
throw new NodeOperationError(this.getNode(), 'No data got returned. Always return an Array of items!');
throw new NodeOperationError(
this.getNode(),
'No data got returned. Always return an Array of items!',
);
}
if (!Array.isArray(items)) {
throw new NodeOperationError(this.getNode(), 'Always an Array of items has to be returned!');
throw new NodeOperationError(
this.getNode(),
'Always an Array of items has to be returned!',
);
}
for (const item of items) {
if (item.json === undefined) {
throw new NodeOperationError(this.getNode(), 'All returned items have to contain a property named "json"!');
throw new NodeOperationError(
this.getNode(),
'All returned items have to contain a property named "json"!',
);
}
if (typeof item.json !== 'object') {
throw new NodeOperationError(this.getNode(), 'The json-property has to be an object!');
@@ -141,13 +151,16 @@ return items;`,
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!');
throw new NodeOperationError(
this.getNode(),
'The binary-property has to be an object!',
);
}
}
}
} catch (error) {
if (this.continueOnFail()) {
items=[{json:{ error: error.message }}];
items = [{ json: { error: error.message } }];
} else {
// Try to find the line number which contains the error and attach to error message
const stackLines = error.stack.split('\n');