From 00fc6e598025022edca6b9461e1d5c9caaf85060 Mon Sep 17 00:00:00 2001 From: Chris Lonardo Date: Mon, 6 Apr 2020 14:04:59 -0400 Subject: [PATCH] enhance .editorconfig and apply formatting cleanup to last commit --- .editorconfig | 7 + package.json | 40 ++--- .../nodes-base/nodes/MongoDb/MongoDb.node.ts | 64 +++---- .../nodes/MongoDb/mongo.node.options.ts | 156 +++++++++--------- .../nodes/MongoDb/mongo.node.utils.ts | 6 +- 5 files changed, 140 insertions(+), 133 deletions(-) diff --git a/.editorconfig b/.editorconfig index bec7553240..5d02a5688b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,3 +6,10 @@ indent_style = tab end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true + +[package.json] +indent_style = space +indent_size = 2 + +[*.ts] +quote_type = single \ No newline at end of file diff --git a/package.json b/package.json index e14010e7a8..0c7d8dac15 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,22 @@ { - "name": "n8n", - "private": true, - "homepage": "https://n8n.io", - "scripts": { - "bootstrap": "lerna bootstrap --hoist --no-ci", - "build": "lerna exec npm run build", - "dev": "lerna exec npm run dev --parallel", - "clean:dist": "lerna exec -- rimraf ./dist", - "start": "run-script-os", - "start:default": "cd packages/cli/bin && ./n8n", - "start:windows": "cd packages/cli/bin && n8n", - "test": "lerna run test", - "watch": "lerna run --parallel watch" - }, - "devDependencies": { - "lerna": "^3.13.1", - "rimraf": "^3.0.2", - "run-script-os": "^1.0.7" - }, - "postcss": {} + "name": "n8n", + "private": true, + "homepage": "https://n8n.io", + "scripts": { + "bootstrap": "lerna bootstrap --hoist --no-ci", + "build": "lerna exec npm run build", + "dev": "lerna exec npm run dev --parallel", + "clean:dist": "lerna exec -- rimraf ./dist", + "start": "run-script-os", + "start:default": "cd packages/cli/bin && ./n8n", + "start:windows": "cd packages/cli/bin && n8n", + "test": "lerna run test", + "watch": "lerna run --parallel watch" + }, + "devDependencies": { + "lerna": "^3.13.1", + "rimraf": "^3.0.2", + "run-script-os": "^1.0.7" + }, + "postcss": {} } diff --git a/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts b/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts index d15fd0112e..7dc8daa957 100644 --- a/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts +++ b/packages/nodes-base/nodes/MongoDb/MongoDb.node.ts @@ -1,41 +1,41 @@ -import { IExecuteFunctions } from "n8n-core"; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, INodeExecutionData, INodeType, - INodeTypeDescription, -} from "n8n-workflow"; -import { nodeDescription } from "./mongo.node.options"; -import { MongoClient } from "mongodb"; -import { getItemCopy, buildParameterizedConnString } from "./mongo.node.utils"; + INodeTypeDescription +} from 'n8n-workflow'; +import { nodeDescription } from './mongo.node.options'; +import { MongoClient } from 'mongodb'; +import { getItemCopy, buildParameterizedConnString } from './mongo.node.utils'; export class MongoDb implements INodeType { description: INodeTypeDescription = nodeDescription; async execute(this: IExecuteFunctions): Promise { - const credentials = this.getCredentials("mongoDb"); + const credentials = this.getCredentials('mongoDb'); // user can optionally override connection string const useOverriddenConnString = this.getNodeParameter( - "shouldOverrideConnString", + 'shouldOverrideConnString', 0 ) as boolean; if (credentials === undefined) { - throw new Error("No credentials got returned!"); + throw new Error('No credentials got returned!'); } - let connectionUri = ""; + let connectionUri = ''; if (useOverriddenConnString === true) { const connStringInput = this.getNodeParameter( - "connStringOverrideVal", + 'connStringOverrideVal', 0 ) as string; if (connStringInput && connStringInput.length > 0) { connectionUri = connStringInput; } else { throw new Error( - "Cannot override credentials: valid MongoDB connection string not provided " + 'Cannot override credentials: valid MongoDB connection string not provided ' ); } } else { @@ -44,7 +44,7 @@ export class MongoDb implements INodeType { const client: MongoClient = await MongoClient.connect(connectionUri, { useNewUrlParser: true, - useUnifiedTopology: true, + useUnifiedTopology: true }); const mdb = client.db(credentials.database as string); @@ -52,34 +52,34 @@ export class MongoDb implements INodeType { let returnItems = []; const items = this.getInputData(); - const operation = this.getNodeParameter("operation", 0) as string; + const operation = this.getNodeParameter('operation', 0) as string; - if (operation === "find") { + if (operation === 'find') { // ---------------------------------- // find // ---------------------------------- const queryResult = await mdb - .collection(this.getNodeParameter("collection", 0) as string) - .find(JSON.parse(this.getNodeParameter("query", 0) as string)) + .collection(this.getNodeParameter('collection', 0) as string) + .find(JSON.parse(this.getNodeParameter('query', 0) as string)) .toArray(); returnItems = this.helpers.returnJsonArray(queryResult as IDataObject[]); - } else if (operation === "insert") { + } else if (operation === 'insert') { // ---------------------------------- // insert // ---------------------------------- // 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); + const fields = (this.getNodeParameter('fields', 0) as string) + .split(',') + .map(f => f.trim()) + .filter(f => !!f); const insertItems = getItemCopy(items, fields); const { insertedIds } = await mdb - .collection(this.getNodeParameter("collection", 0) as string) + .collection(this.getNodeParameter('collection', 0) as string) .insertMany(insertItems); // Add the id to the data @@ -87,21 +87,21 @@ export class MongoDb implements INodeType { returnItems.push({ json: { ...insertItems[parseInt(i, 10)], - id: insertedIds[parseInt(i, 10)] as string, - }, + id: insertedIds[parseInt(i, 10)] as string + } }); } - } else if (operation === "update") { + } else if (operation === 'update') { // ---------------------------------- // update // ---------------------------------- - const fields = (this.getNodeParameter("fields", 0) as string) - .split(",") - .map((f) => f.trim()) - .filter((f) => !!f); + const fields = (this.getNodeParameter('fields', 0) as string) + .split(',') + .map(f => f.trim()) + .filter(f => !!f); - let updateKey = this.getNodeParameter("updateKey", 0) as string; + let updateKey = this.getNodeParameter('updateKey', 0) as string; updateKey = updateKey.trim(); if (!fields.includes(updateKey)) { @@ -120,7 +120,7 @@ export class MongoDb implements INodeType { filter[updateKey] = item[updateKey] as string; await mdb - .collection(this.getNodeParameter("collection", 0) as string) + .collection(this.getNodeParameter('collection', 0) as string) .updateOne(filter, { $set: item }); } diff --git a/packages/nodes-base/nodes/MongoDb/mongo.node.options.ts b/packages/nodes-base/nodes/MongoDb/mongo.node.options.ts index 19f18f4ab7..4a98eeabd5 100644 --- a/packages/nodes-base/nodes/MongoDb/mongo.node.options.ts +++ b/packages/nodes-base/nodes/MongoDb/mongo.node.options.ts @@ -1,156 +1,156 @@ -import { INodeTypeDescription } from "n8n-workflow"; +import { INodeTypeDescription } from 'n8n-workflow'; /** * Options to be displayed */ export const nodeDescription: INodeTypeDescription = { - displayName: "MongoDB", - name: "mongoDb", - icon: "file:mongoDb.png", - group: ["input"], + displayName: 'MongoDB', + name: 'mongoDb', + icon: 'file:mongoDb.png', + group: ['input'], version: 1, - description: "Find, insert and update documents in MongoDB.", + description: 'Find, insert and update documents in MongoDB.', defaults: { - name: "MongoDB", - color: "#13AA52", + name: 'MongoDB', + color: '#13AA52' }, - inputs: ["main"], - outputs: ["main"], + inputs: ['main'], + outputs: ['main'], credentials: [ { - name: "mongoDb", - required: true, - }, + name: 'mongoDb', + required: true + } ], properties: [ { - displayName: "Override conn string", - name: "shouldOverrideConnString", - type: "boolean", + displayName: 'Override conn string', + name: 'shouldOverrideConnString', + type: 'boolean', default: false, description: - "Whether to override the generated connection string. Credentials will also be ignored in this case.", + 'Whether to override the generated connection string. Credentials will also be ignored in this case.' }, { - displayName: "Conn string", - name: "connStringOverrideVal", - type: "string", + displayName: 'Conn string', + name: 'connStringOverrideVal', + type: 'string', typeOptions: { - rows: 1, + rows: 1 }, displayOptions: { show: { - shouldOverrideConnString: [true], - }, + shouldOverrideConnString: [true] + } }, - default: "", + default: '', placeholder: `mongodb://USERNAMEHERE:PASSWORDHERE@localhost:27017/?authSource=admin&readPreference=primary&appname=n8n&ssl=false`, required: false, - description: `If "Override conn string" is checked, the value here will be used as a MongoDB connection string, and the MongoDB credentials will be ignored`, + description: `If "Override conn string" is checked, the value here will be used as a MongoDB connection string, and the MongoDB credentials will be ignored` }, { - displayName: "Operation", - name: "operation", - type: "options", + displayName: 'Operation', + name: 'operation', + type: 'options', options: [ { - name: "Find", - value: "find", - description: "Find documents.", + name: 'Find', + value: 'find', + description: 'Find documents.' }, { - name: "Insert", - value: "insert", - description: "Insert documents.", + name: 'Insert', + value: 'insert', + description: 'Insert documents.' }, { - name: "Update", - value: "update", - description: "Updates documents.", - }, + name: 'Update', + value: 'update', + description: 'Updates documents.' + } ], - default: "find", - description: "The operation to perform.", + default: 'find', + description: 'The operation to perform.' }, { - displayName: "Collection", - name: "collection", - type: "string", + displayName: 'Collection', + name: 'collection', + type: 'string', required: true, - default: "", - description: "MongoDB Collection", + default: '', + description: 'MongoDB Collection' }, // ---------------------------------- // find // ---------------------------------- { - displayName: "Query (JSON format)", - name: "query", - type: "string", + displayName: 'Query (JSON format)', + name: 'query', + type: 'string', typeOptions: { - rows: 5, + rows: 5 }, displayOptions: { show: { - operation: ["find"], - }, + operation: ['find'] + } }, - default: "{}", + default: '{}', placeholder: `{ "birth": { "$gt": "1950-01-01" } }`, required: true, - description: "MongoDB Find query.", + description: 'MongoDB Find query.' }, // ---------------------------------- // insert // ---------------------------------- { - displayName: "Fields", - name: "fields", - type: "string", + displayName: 'Fields', + name: 'fields', + type: 'string', displayOptions: { show: { - operation: ["insert"], - }, + operation: ['insert'] + } }, - default: "", - placeholder: "name,description", + default: '', + placeholder: 'name,description', description: - "Comma separated list of the fields to be included into the new document.", + 'Comma separated list of the fields to be included into the new document.' }, // ---------------------------------- // update // ---------------------------------- { - displayName: "Update Key", - name: "updateKey", - type: "string", + displayName: 'Update Key', + name: 'updateKey', + type: 'string', displayOptions: { show: { - operation: ["update"], - }, + operation: ['update'] + } }, - default: "id", + default: 'id', required: true, description: - 'Name of the property which decides which rows in the database should be updated. Normally that would be "id".', + 'Name of the property which decides which rows in the database should be updated. Normally that would be "id".' }, { - displayName: "Fields", - name: "fields", - type: "string", + displayName: 'Fields', + name: 'fields', + type: 'string', displayOptions: { show: { - operation: ["update"], - }, + operation: ['update'] + } }, - default: "", - placeholder: "name,description", + default: '', + placeholder: 'name,description', description: - "Comma separated list of the fields to be included into the new document.", - }, - ], + 'Comma separated list of the fields to be included into the new document.' + } + ] }; diff --git a/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts b/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts index 7de725f08a..54cae7d53c 100644 --- a/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts +++ b/packages/nodes-base/nodes/MongoDb/mongo.node.utils.ts @@ -1,8 +1,8 @@ import { IDataObject, INodeExecutionData, - ICredentialDataDecryptedObject, -} from "n8n-workflow"; + ICredentialDataDecryptedObject +} from 'n8n-workflow'; /** * Standard way of building the MongoDB connection string, unless overridden with a provided string @@ -33,7 +33,7 @@ export function getItemCopy( ): 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) {