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,6 +1,4 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import { IExecuteFunctions } from 'n8n-core';
import {
IDataObject,
@@ -8,23 +6,18 @@ import {
INodeType,
INodeTypeDescription,
JsonObject,
NodeOperationError
NodeOperationError,
} from 'n8n-workflow';
import {
nodeDescription,
} from './mongo.node.options';
import { nodeDescription } from './mongo.node.options';
import {
MongoClient,
ObjectID,
} from 'mongodb';
import { MongoClient, ObjectID } from 'mongodb';
import {
getItemCopy,
handleDateFields,
handleDateFieldsWithDotNotation,
validateAndResolveMongoCredentials
validateAndResolveMongoCredentials,
} from './mongo.node.utils';
export class MongoDb implements INodeType {
@@ -69,7 +62,7 @@ export class MongoDb implements INodeType {
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
} catch (error) {
if (this.continueOnFail()) {
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message } );
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
} else {
throw error;
}
@@ -92,7 +85,6 @@ export class MongoDb implements INodeType {
throw error;
}
}
} else if (operation === 'find') {
// ----------------------------------
// find
@@ -127,7 +119,7 @@ export class MongoDb implements INodeType {
returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]);
} catch (error) {
if (this.continueOnFail()) {
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message } );
returnItems = this.helpers.returnJsonArray({ error: (error as JsonObject).message });
} else {
throw error;
}
@@ -140,8 +132,8 @@ export class MongoDb implements INodeType {
// Prepare the data to insert and copy it to be returned
const fields = (this.getNodeParameter('fields', 0) as string)
.split(',')
.map(f => f.trim())
.filter(f => !!f);
.map((f) => f.trim())
.filter((f) => !!f);
const options = this.getNodeParameter('options', 0) as IDataObject;
const insertItems = getItemCopy(items, fields);
@@ -179,8 +171,8 @@ export class MongoDb implements INodeType {
const fields = (this.getNodeParameter('fields', 0) as string)
.split(',')
.map(f => f.trim())
.filter(f => !!f);
.map((f) => f.trim())
.filter((f) => !!f);
const options = this.getNodeParameter('options', 0) as IDataObject;
@@ -188,7 +180,8 @@ export class MongoDb implements INodeType {
updateKey = updateKey.trim();
const updateOptions = (this.getNodeParameter('upsert', 0) as boolean)
? { upsert: true } : undefined;
? { upsert: true }
: undefined;
if (!fields.includes(updateKey)) {
fields.push(updateKey);
@@ -229,9 +222,14 @@ export class MongoDb implements INodeType {
returnItems = this.helpers.returnJsonArray(updateItems as IDataObject[]);
} else {
if (this.continueOnFail()) {
returnItems = this.helpers.returnJsonArray({ json: { error: `The operation "${operation}" is not supported!` } });
returnItems = this.helpers.returnJsonArray({
json: { error: `The operation "${operation}" is not supported!` },
});
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not supported!`);
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not supported!`,
);
}
}

View File

@@ -1,7 +1,5 @@
/* eslint-disable n8n-nodes-base/node-filename-against-convention */
import {
INodeTypeDescription,
} from 'n8n-workflow';
import { INodeTypeDescription } from 'n8n-workflow';
/**
* Options to be displayed
@@ -86,9 +84,7 @@ export const nodeDescription: INodeTypeDescription = {
},
displayOptions: {
show: {
operation: [
'aggregate',
],
operation: ['aggregate'],
},
},
default: '',
@@ -110,9 +106,7 @@ export const nodeDescription: INodeTypeDescription = {
},
displayOptions: {
show: {
operation: [
'delete',
],
operation: ['delete'],
},
},
default: '{}',
@@ -146,7 +140,8 @@ export const nodeDescription: INodeTypeDescription = {
},
default: 0,
// eslint-disable-next-line n8n-nodes-base/node-param-description-wrong-for-limit
description: 'Use limit to specify the maximum number of documents or 0 for unlimited documents',
description:
'Use limit to specify the maximum number of documents or 0 for unlimited documents',
},
{
displayName: 'Skip',
@@ -177,9 +172,7 @@ export const nodeDescription: INodeTypeDescription = {
},
displayOptions: {
show: {
operation: [
'find',
],
operation: ['find'],
},
},
default: '{}',
@@ -197,9 +190,7 @@ export const nodeDescription: INodeTypeDescription = {
type: 'string',
displayOptions: {
show: {
operation: [
'insert',
],
operation: ['insert'],
},
},
default: '',
@@ -216,15 +207,14 @@ export const nodeDescription: INodeTypeDescription = {
type: 'string',
displayOptions: {
show: {
operation: [
'update',
],
operation: ['update'],
},
},
default: 'id',
required: true,
// eslint-disable-next-line n8n-nodes-base/node-param-description-miscased-id
description: 'Name of the property which decides which rows in the database should be updated. Normally that would be "id".',
description:
'Name of the property which decides which rows in the database should be updated. Normally that would be "id".',
},
{
displayName: 'Fields',
@@ -232,9 +222,7 @@ export const nodeDescription: INodeTypeDescription = {
type: 'string',
displayOptions: {
show: {
operation: [
'update',
],
operation: ['update'],
},
},
default: '',
@@ -259,10 +247,7 @@ export const nodeDescription: INodeTypeDescription = {
type: 'collection',
displayOptions: {
show: {
operation: [
'update',
'insert',
],
operation: ['update', 'insert'],
},
},
placeholder: 'Add Option',
@@ -276,7 +261,7 @@ export const nodeDescription: INodeTypeDescription = {
description: 'Comma separeted list of fields that will be parse as Mongo Date type',
},
{
displayName:'Use Dot Notation',
displayName: 'Use Dot Notation',
name: 'useDotNotation',
type: 'boolean',
default: false,

View File

@@ -34,9 +34,7 @@ export interface IMongoOverrideCredentials {
/**
* Unified credential object type (whether params are overridden with a connection string or not)
*/
export type IMongoCredentialsType =
| IMongoParametricCredentials
| IMongoOverrideCredentials;
export type IMongoCredentialsType = IMongoParametricCredentials | IMongoOverrideCredentials;
/**
* Resolve the database and connection string from input credentials

View File

@@ -18,9 +18,7 @@ import { get, set } from 'lodash';
*
* @param {ICredentialDataDecryptedObject} credentials MongoDB credentials to use, unless conn string is overridden
*/
function buildParameterizedConnString(
credentials: IMongoParametricCredentials,
): string {
function buildParameterizedConnString(credentials: IMongoParametricCredentials): string {
if (credentials.port) {
return `mongodb://${credentials.user}:${credentials.password}@${credentials.host}:${credentials.port}`;
} else {
@@ -44,16 +42,16 @@ export function buildMongoConnectionParams(
? credentials.database.trim()
: '';
if (credentials.configurationType === 'connectionString') {
if (
credentials.connectionString &&
credentials.connectionString.trim().length > 0
) {
if (credentials.connectionString && credentials.connectionString.trim().length > 0) {
return {
connectionString: credentials.connectionString.trim(),
database: sanitizedDbName,
};
} else {
throw new NodeOperationError(self.getNode(), 'Cannot override credentials: valid MongoDB connection string not provided ');
throw new NodeOperationError(
self.getNode(),
'Cannot override credentials: valid MongoDB connection string not provided ',
);
}
} else {
return {
@@ -76,10 +74,7 @@ export function validateAndResolveMongoCredentials(
if (credentials === undefined) {
throw new NodeOperationError(self.getNode(), 'No credentials got returned!');
} else {
return buildMongoConnectionParams(
self,
credentials as unknown as IMongoCredentialsType,
);
return buildMongoConnectionParams(self, credentials as unknown as IMongoCredentialsType);
}
}
@@ -91,13 +86,10 @@ export function validateAndResolveMongoCredentials(
* @param {string[]} properties The properties it should include
* @returns
*/
export function getItemCopy(
items: INodeExecutionData[],
properties: string[],
): IDataObject[] {
export function getItemCopy(items: INodeExecutionData[], properties: string[]): IDataObject[] {
// Prepare the data to insert and copy it to be returned
let newItem: IDataObject;
return items.map(item => {
return items.map((item) => {
newItem = {};
for (const property of properties) {
if (item.json[property] === undefined) {
@@ -122,7 +114,7 @@ export function handleDateFields(insertItems: IDataObject[], fields: string) {
}
export function handleDateFieldsWithDotNotation(insertItems: IDataObject[], fields: string) {
const dateFields = fields.split(',').map(field => field.trim());
const dateFields = fields.split(',').map((field) => field.trim());
for (let i = 0; i < insertItems.length; i++) {
for (const field of dateFields) {