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

@@ -1,10 +1,8 @@
import {
INodeProperties,
INodePropertyCollection,
INodePropertyOptions,
} from 'n8n-workflow';
import { INodeProperties, INodePropertyCollection, INodePropertyOptions } from 'n8n-workflow';
export const rabbitDefaultOptions: Array<INodePropertyOptions | INodeProperties | INodePropertyCollection> = [
export const rabbitDefaultOptions: Array<
INodePropertyOptions | INodeProperties | INodePropertyCollection
> = [
{
displayName: 'Arguments',
name: 'arguments',

View File

@@ -1,8 +1,4 @@
import {
IDataObject,
IExecuteFunctions,
ITriggerFunctions,
} from 'n8n-workflow';
import { IDataObject, IExecuteFunctions, ITriggerFunctions } from 'n8n-workflow';
import * as amqplib from 'amqplib';
@@ -12,19 +8,16 @@ declare module 'amqplib' {
}
}
export async function rabbitmqConnect(this: IExecuteFunctions | ITriggerFunctions, options: IDataObject): Promise<amqplib.Channel> {
export async function rabbitmqConnect(
this: IExecuteFunctions | ITriggerFunctions,
options: IDataObject,
): Promise<amqplib.Channel> {
const credentials = await this.getCredentials('rabbitmq');
const credentialKeys = [
'hostname',
'port',
'username',
'password',
'vhost',
];
const credentialKeys = ['hostname', 'port', 'username', 'password', 'vhost'];
const credentialData: IDataObject = {};
credentialKeys.forEach(key => {
credentialKeys.forEach((key) => {
credentialData[key] = credentials[key] === '' ? undefined : credentials[key];
});
@@ -41,7 +34,6 @@ export async function rabbitmqConnect(this: IExecuteFunctions | ITriggerFunction
}
}
return new Promise(async (resolve, reject) => {
try {
const connection = await amqplib.connect(credentialData, optsData);
@@ -50,13 +42,18 @@ export async function rabbitmqConnect(this: IExecuteFunctions | ITriggerFunction
reject(error);
});
const channel = await connection.createChannel().catch(console.warn) as amqplib.Channel;
const channel = (await connection.createChannel().catch(console.warn)) as amqplib.Channel;
if (options.arguments && ((options.arguments as IDataObject).argument! as IDataObject[]).length) {
if (
options.arguments &&
((options.arguments as IDataObject).argument! as IDataObject[]).length
) {
const additionalArguments: IDataObject = {};
((options.arguments as IDataObject).argument as IDataObject[]).forEach((argument: IDataObject) => {
additionalArguments[argument.key as string] = argument.value;
});
((options.arguments as IDataObject).argument as IDataObject[]).forEach(
(argument: IDataObject) => {
additionalArguments[argument.key as string] = argument.value;
},
);
options.arguments = additionalArguments;
}
@@ -67,7 +64,11 @@ export async function rabbitmqConnect(this: IExecuteFunctions | ITriggerFunction
});
}
export async function rabbitmqConnectQueue(this: IExecuteFunctions | ITriggerFunctions, queue: string, options: IDataObject): Promise<amqplib.Channel> {
export async function rabbitmqConnectQueue(
this: IExecuteFunctions | ITriggerFunctions,
queue: string,
options: IDataObject,
): Promise<amqplib.Channel> {
const channel = await rabbitmqConnect.call(this, options);
return new Promise(async (resolve, reject) => {
@@ -80,7 +81,12 @@ export async function rabbitmqConnectQueue(this: IExecuteFunctions | ITriggerFun
});
}
export async function rabbitmqConnectExchange(this: IExecuteFunctions | ITriggerFunctions, exchange: string, type: string, options: IDataObject): Promise<amqplib.Channel> {
export async function rabbitmqConnectExchange(
this: IExecuteFunctions | ITriggerFunctions,
exchange: string,
type: string,
options: IDataObject,
): Promise<amqplib.Channel> {
const channel = await rabbitmqConnect.call(this, options);
return new Promise(async (resolve, reject) => {
@@ -106,7 +112,7 @@ export class MessageTracker {
return;
}
const index = this.messages.findIndex(value => value !== message.fields.deliveryTag);
const index = this.messages.findIndex((value) => value !== message.fields.deliveryTag);
this.messages.splice(index);
}

View File

@@ -1,7 +1,5 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
@@ -13,10 +11,7 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
rabbitmqConnectExchange,
rabbitmqConnectQueue,
} from './GenericFunctions';
import { rabbitmqConnectExchange, rabbitmqConnectQueue } from './GenericFunctions';
export class RabbitMQ implements INodeType {
description: INodeTypeDescription = {
@@ -68,9 +63,7 @@ export class RabbitMQ implements INodeType {
type: 'string',
displayOptions: {
show: {
mode: [
'queue',
],
mode: ['queue'],
},
},
default: '',
@@ -88,9 +81,7 @@ export class RabbitMQ implements INodeType {
type: 'string',
displayOptions: {
show: {
mode: [
'exchange',
],
mode: ['exchange'],
},
},
default: '',
@@ -103,9 +94,7 @@ export class RabbitMQ implements INodeType {
type: 'options',
displayOptions: {
show: {
mode: [
'exchange',
],
mode: ['exchange'],
},
},
options: [
@@ -139,9 +128,7 @@ export class RabbitMQ implements INodeType {
type: 'string',
displayOptions: {
show: {
mode: [
'exchange',
],
mode: ['exchange'],
},
},
default: '',
@@ -166,9 +153,7 @@ export class RabbitMQ implements INodeType {
type: 'string',
displayOptions: {
show: {
sendInputData: [
false,
],
sendInputData: [false],
},
},
default: '',
@@ -187,13 +172,12 @@ export class RabbitMQ implements INodeType {
type: 'string',
displayOptions: {
show: {
'/mode': [
'exchange',
],
'/mode': ['exchange'],
},
},
default: '',
description: 'An exchange to send messages to if this exchange cant route them to any queues',
description:
'An exchange to send messages to if this exchange cant route them to any queues',
},
{
displayName: 'Arguments',
@@ -231,7 +215,8 @@ export class RabbitMQ implements INodeType {
name: 'autoDelete',
type: 'boolean',
default: false,
description: 'Whether the queue will be deleted when the number of consumers drops to zero',
description:
'Whether the queue will be deleted when the number of consumers drops to zero',
},
{
displayName: 'Durable',
@@ -246,9 +231,7 @@ export class RabbitMQ implements INodeType {
type: 'boolean',
displayOptions: {
show: {
'/mode': [
'queue',
],
'/mode': ['queue'],
},
},
default: false,
@@ -318,12 +301,17 @@ export class RabbitMQ implements INodeType {
}
let headers: IDataObject = {};
if (options.headers && ((options.headers as IDataObject).header! as IDataObject[]).length) {
if (
options.headers &&
((options.headers as IDataObject).header! as IDataObject[]).length
) {
const itemOptions = this.getNodeParameter('options', i, {}) as IDataObject;
const additionalHeaders: IDataObject = {};
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach((header: IDataObject) => {
additionalHeaders[header.key as string] = header.value;
});
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach(
(header: IDataObject) => {
additionalHeaders[header.key as string] = header.value;
},
);
headers = additionalHeaders;
}
@@ -336,18 +324,15 @@ export class RabbitMQ implements INodeType {
// @ts-ignore
promisesResponses.forEach((response: JsonObject) => {
if (response!.status !== 'fulfilled') {
if (this.continueOnFail() !== true) {
throw new NodeApiError(this.getNode(), response);
} else {
// Return the actual reason as error
returnItems.push(
{
json: {
error: response.reason,
},
returnItems.push({
json: {
error: response.reason,
},
);
});
return;
}
}
@@ -361,8 +346,7 @@ export class RabbitMQ implements INodeType {
await channel.close();
await channel.connection.close();
}
else if (mode === 'exchange') {
} else if (mode === 'exchange') {
const exchange = this.getNodeParameter('exchange', 0) as string;
const type = this.getNodeParameter('exchangeType', 0) as string;
const routingKey = this.getNodeParameter('routingKey', 0) as string;
@@ -384,16 +368,23 @@ export class RabbitMQ implements INodeType {
}
let headers: IDataObject = {};
if (options.headers && ((options.headers as IDataObject).header! as IDataObject[]).length) {
if (
options.headers &&
((options.headers as IDataObject).header! as IDataObject[]).length
) {
const itemOptions = this.getNodeParameter('options', i, {}) as IDataObject;
const additionalHeaders: IDataObject = {};
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach((header: IDataObject) => {
additionalHeaders[header.key as string] = header.value;
});
((itemOptions.headers as IDataObject).header as IDataObject[]).forEach(
(header: IDataObject) => {
additionalHeaders[header.key as string] = header.value;
},
);
headers = additionalHeaders;
}
exchangePromises.push(channel.publish(exchange, routingKey, Buffer.from(message), { headers }));
exchangePromises.push(
channel.publish(exchange, routingKey, Buffer.from(message), { headers }),
);
}
// @ts-ignore
@@ -402,18 +393,15 @@ export class RabbitMQ implements INodeType {
// @ts-ignore
promisesResponses.forEach((response: JsonObject) => {
if (response!.status !== 'fulfilled') {
if (this.continueOnFail() !== true) {
throw new NodeApiError(this.getNode(), response);
} else {
// Return the actual reason as error
returnItems.push(
{
json: {
error: response.reason,
},
returnItems.push({
json: {
error: response.reason,
},
);
});
return;
}
}
@@ -432,8 +420,7 @@ export class RabbitMQ implements INodeType {
}
return this.prepareOutputData(returnItems);
}
catch (error) {
} catch (error) {
if (channel) {
await channel.close();
await channel.connection.close();

View File

@@ -13,14 +13,9 @@ import {
NodeOperationError,
} from 'n8n-workflow';
import {
rabbitDefaultOptions,
} from './DefaultOptions';
import { rabbitDefaultOptions } from './DefaultOptions';
import {
MessageTracker,
rabbitmqConnectQueue,
} from './GenericFunctions';
import { MessageTracker, rabbitmqConnectQueue } from './GenericFunctions';
import * as amqplib from 'amqplib';
@@ -76,7 +71,8 @@ export class RabbitMQTrigger implements INodeType {
{
name: 'Execution Finishes',
value: 'executionFinishes',
description: 'After the workflow execution finished. No matter if the execution was successful or not.',
description:
'After the workflow execution finished. No matter if the execution was successful or not.',
},
{
name: 'Execution Finishes Successfully',
@@ -98,9 +94,7 @@ export class RabbitMQTrigger implements INodeType {
type: 'boolean',
displayOptions: {
hide: {
contentIsBinary: [
true,
],
contentIsBinary: [true],
},
},
default: false,
@@ -112,9 +106,7 @@ export class RabbitMQTrigger implements INodeType {
type: 'boolean',
displayOptions: {
hide: {
contentIsBinary: [
true,
],
contentIsBinary: [true],
},
},
default: false,
@@ -128,24 +120,31 @@ export class RabbitMQTrigger implements INodeType {
default: -1,
displayOptions: {
hide: {
acknowledge: [
'immediately',
],
acknowledge: ['immediately'],
},
},
description: 'Max number of executions at a time. Use -1 for no limit.',
},
...rabbitDefaultOptions,
].sort((a, b) => {
if ((a as INodeProperties).displayName.toLowerCase() < (b as INodeProperties).displayName.toLowerCase()) { return -1; }
if ((a as INodeProperties).displayName.toLowerCase() > (b as INodeProperties).displayName.toLowerCase()) { return 1; }
if (
(a as INodeProperties).displayName.toLowerCase() <
(b as INodeProperties).displayName.toLowerCase()
) {
return -1;
}
if (
(a as INodeProperties).displayName.toLowerCase() >
(b as INodeProperties).displayName.toLowerCase()
) {
return 1;
}
return 0;
}) as INodeProperties[],
},
],
};
async trigger(this: ITriggerFunctions): Promise<ITriggerResponse> {
const queue = this.getNodeParameter('queue') as string;
const options = this.getNodeParameter('options', {}) as IDataObject;
@@ -154,10 +153,16 @@ export class RabbitMQTrigger implements INodeType {
const self = this;
let parallelMessages = (options.parallelMessages !== undefined && options.parallelMessages !== -1) ? parseInt(options.parallelMessages as string, 10) : -1;
let parallelMessages =
options.parallelMessages !== undefined && options.parallelMessages !== -1
? parseInt(options.parallelMessages as string, 10)
: -1;
if (parallelMessages === 0 || parallelMessages < -1) {
throw new NodeOperationError(this.getNode(), 'Parallel message processing limit must be greater than zero (or -1 for no limit)');
throw new NodeOperationError(
this.getNode(),
'Parallel message processing limit must be greater than zero (or -1 for no limit)',
);
}
if (this.getMode() === 'manual') {
@@ -184,7 +189,6 @@ export class RabbitMQTrigger implements INodeType {
const consumerInfo = await channel.consume(queue, async (message) => {
if (message !== null) {
try {
if (acknowledgeMode !== 'immediately') {
messageTracker.received(message);
@@ -220,17 +224,11 @@ export class RabbitMQTrigger implements INodeType {
responsePromise = await createDeferredPromise<IRun>();
}
self.emit([
[
item,
],
], undefined, responsePromise);
self.emit([[item]], undefined, responsePromise);
if (responsePromise) {
// Acknowledge message after the execution finished
await responsePromise
.promise()
.then(async (data: IRun) => {
await responsePromise.promise().then(async (data: IRun) => {
if (data.data.resultData.error) {
// The execution did fail
if (acknowledgeMode === 'executionFinishesSuccessfully') {
@@ -247,7 +245,6 @@ export class RabbitMQTrigger implements INodeType {
// Acknowledge message directly
channel.ack(message);
}
} catch (error) {
const workflow = this.getWorkflow();
const node = this.getNode();
@@ -255,7 +252,8 @@ export class RabbitMQTrigger implements INodeType {
messageTracker.answered(message);
}
Logger.error(`There was a problem with the RabbitMQ Trigger node "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
Logger.error(
`There was a problem with the RabbitMQ Trigger node "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
{
node: node.name,
workflowId: workflow.id,
@@ -272,13 +270,13 @@ export class RabbitMQTrigger implements INodeType {
// The "closeFunction" function gets called by n8n whenever
// the workflow gets deactivated and can so clean up.
async function closeFunction() {
try {
return messageTracker.closeChannel(channel, consumerTag);
} catch(error) {
} catch (error) {
const workflow = self.getWorkflow();
const node = self.getNode();
Logger.error(`There was a problem closing the RabbitMQ Trigger node connection "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
Logger.error(
`There was a problem closing the RabbitMQ Trigger node connection "${node.name}" in workflow "${workflow.id}": "${error.message}"`,
{
node: node.name,
workflowId: workflow.id,
@@ -291,5 +289,4 @@ export class RabbitMQTrigger implements INodeType {
closeFunction,
};
}
}