n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -9,7 +9,6 @@ import {
NodeParameterValue,
} from 'n8n-workflow';
export class If implements INodeType {
description: INodeTypeDescription = {
displayName: 'IF',
@@ -177,10 +176,7 @@ export class If implements INodeType {
type: 'number',
displayOptions: {
hide: {
operation: [
'isEmpty',
'isNotEmpty',
],
operation: ['isEmpty', 'isNotEmpty'],
},
},
default: 0,
@@ -264,12 +260,7 @@ export class If implements INodeType {
type: 'string',
displayOptions: {
hide: {
operation: [
'isEmpty',
'isNotEmpty',
'regex',
'notRegex',
],
operation: ['isEmpty', 'isNotEmpty', 'regex', 'notRegex'],
},
},
default: '',
@@ -281,10 +272,7 @@ export class If implements INodeType {
type: 'string',
displayOptions: {
show: {
operation: [
'regex',
'notRegex',
],
operation: ['regex', 'notRegex'],
},
},
default: '',
@@ -312,12 +300,12 @@ export class If implements INodeType {
},
],
default: 'all',
description: 'If multiple rules got set this settings decides if it is true as soon as ANY condition matches or only if ALL get meet',
description:
'If multiple rules got set this settings decides if it is true as soon as ANY condition matches or only if ALL get meet',
},
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const returnDataTrue: INodeExecutionData[] = [];
const returnDataFalse: INodeExecutionData[] = [];
@@ -331,22 +319,44 @@ export class If implements INodeType {
const compareOperationFunctions: {
[key: string]: (value1: NodeParameterValue, value2: NodeParameterValue) => boolean;
} = {
after: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) > (value2 || 0),
before: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) < (value2 || 0),
contains: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || '').toString().includes((value2 || '').toString()),
notContains: (value1: NodeParameterValue, value2: NodeParameterValue) => !(value1 || '').toString().includes((value2 || '').toString()),
endsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).endsWith(value2 as string),
notEndsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => !(value1 as string).endsWith(value2 as string),
after: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) > (value2 || 0),
before: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) < (value2 || 0),
contains: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || '').toString().includes((value2 || '').toString()),
notContains: (value1: NodeParameterValue, value2: NodeParameterValue) =>
!(value1 || '').toString().includes((value2 || '').toString()),
endsWith: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 as string).endsWith(value2 as string),
notEndsWith: (value1: NodeParameterValue, value2: NodeParameterValue) =>
!(value1 as string).endsWith(value2 as string),
equal: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 === value2,
notEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => value1 !== value2,
larger: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) > (value2 || 0),
largerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) >= (value2 || 0),
smaller: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) < (value2 || 0),
smallerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 || 0) <= (value2 || 0),
startsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => (value1 as string).startsWith(value2 as string),
notStartsWith: (value1: NodeParameterValue, value2: NodeParameterValue) => !(value1 as string).startsWith(value2 as string),
isEmpty: (value1: NodeParameterValue) => (([undefined, null, ''].includes(value1 as string)) || ((typeof value1 === 'object' && value1 !== null) ? (Object.entries(value1 as string).length === 0) : false)),
isNotEmpty: (value1: NodeParameterValue) => !(([undefined, null, ''].includes(value1 as string)) || ((typeof value1 === 'object' && value1 !== null) ? (Object.entries(value1 as string).length === 0) : false)),
larger: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) > (value2 || 0),
largerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) >= (value2 || 0),
smaller: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) < (value2 || 0),
smallerEqual: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 || 0) <= (value2 || 0),
startsWith: (value1: NodeParameterValue, value2: NodeParameterValue) =>
(value1 as string).startsWith(value2 as string),
notStartsWith: (value1: NodeParameterValue, value2: NodeParameterValue) =>
!(value1 as string).startsWith(value2 as string),
isEmpty: (value1: NodeParameterValue) =>
[undefined, null, ''].includes(value1 as string) ||
(typeof value1 === 'object' && value1 !== null
? Object.entries(value1 as string).length === 0
: false),
isNotEmpty: (value1: NodeParameterValue) =>
!(
[undefined, null, ''].includes(value1 as string) ||
(typeof value1 === 'object' && value1 !== null
? Object.entries(value1 as string).length === 0
: false)
),
regex: (value1: NodeParameterValue, value2: NodeParameterValue) => {
const regexMatch = (value2 || '').toString().match(new RegExp('^/(.*?)/([gimusy]*)$'));
@@ -384,34 +394,33 @@ export class If implements INodeType {
returnValue = new Date(value).getTime();
} else if (typeof value === 'number') {
returnValue = value;
} if (moment.isMoment(value)) {
}
if (moment.isMoment(value)) {
returnValue = value.unix();
} if ((value as unknown as object) instanceof Date) {
}
if ((value as unknown as object) instanceof Date) {
returnValue = (value as unknown as Date).getTime();
}
if (returnValue === undefined || isNaN(returnValue)) {
throw new NodeOperationError(this.getNode(), `The value "${value}" is not a valid DateTime.`);
throw new NodeOperationError(
this.getNode(),
`The value "${value}" is not a valid DateTime.`,
);
}
return returnValue;
};
// The different dataTypes to check the values in
const dataTypes = [
'boolean',
'dateTime',
'number',
'string',
];
const dataTypes = ['boolean', 'dateTime', 'number', 'string'];
// Itterate over all items to check which ones should be output as via output "true" and
// which ones via output "false"
let dataType: string;
let compareOperationResult: boolean;
let value1: NodeParameterValue, value2: NodeParameterValue;
itemLoop:
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
itemLoop: for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
item = items[itemIndex];
let compareData: INodeParameters;
@@ -421,7 +430,11 @@ export class If implements INodeType {
// Check all the values of the different dataTypes
for (dataType of dataTypes) {
// Check all the values of the current dataType
for (compareData of this.getNodeParameter(`conditions.${dataType}`, itemIndex, []) as INodeParameters[]) {
for (compareData of this.getNodeParameter(
`conditions.${dataType}`,
itemIndex,
[],
) as INodeParameters[]) {
// Check if the values passes
value1 = compareData.value1 as NodeParameterValue;
@@ -432,7 +445,10 @@ export class If implements INodeType {
value2 = convertDateTime(value2);
}
compareOperationResult = compareOperationFunctions[compareData.operation as string](value1, value2);
compareOperationResult = compareOperationFunctions[compareData.operation as string](
value1,
value2,
);
if (compareOperationResult === true && combineOperation === 'any') {
// If it passes and the operation is "any" we do not have to check any