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:
@@ -7,29 +7,17 @@ import {
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
} from 'n8n-workflow';
|
||||
import {
|
||||
collectionFields,
|
||||
collectionOperations,
|
||||
} from './CollectionDescription';
|
||||
import { collectionFields, collectionOperations } from './CollectionDescription';
|
||||
import {
|
||||
createCollectionEntry,
|
||||
getAllCollectionEntries,
|
||||
getAllCollectionNames,
|
||||
} from './CollectionFunctions';
|
||||
import {
|
||||
formFields,
|
||||
formOperations
|
||||
} from './FormDescription';
|
||||
import { formFields, formOperations } from './FormDescription';
|
||||
import { submitForm } from './FormFunctions';
|
||||
import { createDataFromParameters } from './GenericFunctions';
|
||||
import {
|
||||
singletonFields,
|
||||
singletonOperations,
|
||||
} from './SingletonDescription';
|
||||
import {
|
||||
getAllSingletonNames,
|
||||
getSingleton,
|
||||
} from './SingletonFunctions';
|
||||
import { singletonFields, singletonOperations } from './SingletonDescription';
|
||||
import { getAllSingletonNames, getSingleton } from './SingletonFunctions';
|
||||
|
||||
export class Cockpit implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -89,7 +77,7 @@ export class Cockpit implements INodeType {
|
||||
async getCollections(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const collections = await getAllCollectionNames.call(this);
|
||||
|
||||
return collections.map(itemName => {
|
||||
return collections.map((itemName) => {
|
||||
return {
|
||||
name: itemName,
|
||||
value: itemName,
|
||||
@@ -100,7 +88,7 @@ export class Cockpit implements INodeType {
|
||||
async getSingletons(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const singletons = await getAllSingletonNames.call(this);
|
||||
|
||||
return singletons.map(itemName => {
|
||||
return singletons.map((itemName) => {
|
||||
return {
|
||||
name: itemName,
|
||||
value: itemName,
|
||||
|
||||
@@ -8,9 +8,7 @@ export const collectionOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -49,13 +47,12 @@ export const collectionFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Name of the collection to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'Name of the collection to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
|
||||
// Collection:entry:getAll
|
||||
@@ -65,12 +62,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
type: 'boolean',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['collection'],
|
||||
},
|
||||
},
|
||||
default: false,
|
||||
@@ -82,15 +75,9 @@ export const collectionFields: INodeProperties[] = [
|
||||
type: 'number',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
returnAll: [
|
||||
false,
|
||||
],
|
||||
operation: ['getAll'],
|
||||
resource: ['collection'],
|
||||
returnAll: [false],
|
||||
},
|
||||
},
|
||||
typeOptions: {
|
||||
@@ -108,12 +95,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'getAll',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['getAll'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -137,7 +120,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
alwaysOpenEditWindow: true,
|
||||
},
|
||||
placeholder: '{"name": "Jim"}',
|
||||
description: 'Filter query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
description:
|
||||
'Filter query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
},
|
||||
{
|
||||
displayName: 'Language',
|
||||
@@ -173,7 +157,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
type: 'json',
|
||||
default: '',
|
||||
placeholder: '{"price": -1}',
|
||||
description: 'Sort query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
description:
|
||||
'Sort query in <a href="https://jeroen.github.io/mongolite/query-data.html">Mongolite format</a>',
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -187,12 +172,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['update'],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -206,13 +187,8 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
'update',
|
||||
],
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Whether new entry fields should be set via the value-key pair UI or JSON',
|
||||
@@ -227,16 +203,9 @@ export const collectionFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [
|
||||
true,
|
||||
],
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
'update',
|
||||
],
|
||||
jsonDataFields: [true],
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
description: 'Entry data to send as JSON',
|
||||
@@ -251,16 +220,9 @@ export const collectionFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [
|
||||
false,
|
||||
],
|
||||
resource: [
|
||||
'collection',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
'update',
|
||||
],
|
||||
jsonDataFields: [false],
|
||||
resource: ['collection'],
|
||||
operation: ['create', 'update'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
import { ICollection } from './CollectionInterface';
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function createCollectionEntry(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string, data: IDataObject, id?: string): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function createCollectionEntry(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
data: IDataObject,
|
||||
id?: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const body: ICollection = {
|
||||
data,
|
||||
};
|
||||
@@ -22,12 +24,16 @@ export async function createCollectionEntry(this: IExecuteFunctions | IExecuteSi
|
||||
return cockpitApiRequest.call(this, 'post', `/collections/save/${resourceName}`, body);
|
||||
}
|
||||
|
||||
|
||||
export async function getAllCollectionEntries(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string, options: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function getAllCollectionEntries(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
options: IDataObject,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const body: ICollection = {};
|
||||
|
||||
if (options.fields) {
|
||||
const fields = (options.fields as string).split(',').map(field => field.trim() );
|
||||
const fields = (options.fields as string).split(',').map((field) => field.trim());
|
||||
|
||||
const bodyFields = {
|
||||
_id: false,
|
||||
@@ -71,7 +77,8 @@ export async function getAllCollectionEntries(this: IExecuteFunctions | IExecute
|
||||
return cockpitApiRequest.call(this, 'post', `/collections/get/${resourceName}`, body);
|
||||
}
|
||||
|
||||
|
||||
export async function getAllCollectionNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> {
|
||||
export async function getAllCollectionNames(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
): Promise<string[]> {
|
||||
return cockpitApiRequest.call(this, 'GET', `/collections/listCollections`, {});
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ export const formOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'form',
|
||||
],
|
||||
resource: ['form'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -20,7 +18,6 @@ export const formOperations: INodeProperties[] = [
|
||||
description: 'Store data from a form submission',
|
||||
action: 'Submit a form',
|
||||
},
|
||||
|
||||
],
|
||||
default: 'submit',
|
||||
},
|
||||
@@ -33,9 +30,7 @@ export const formFields: INodeProperties[] = [
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'form',
|
||||
],
|
||||
resource: ['form'],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
@@ -51,12 +46,8 @@ export const formFields: INodeProperties[] = [
|
||||
default: false,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'form',
|
||||
],
|
||||
operation: [
|
||||
'submit',
|
||||
],
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
description: 'Whether form fields should be set via the value-key pair UI or JSON',
|
||||
@@ -71,15 +62,9 @@ export const formFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [
|
||||
true,
|
||||
],
|
||||
resource: [
|
||||
'form',
|
||||
],
|
||||
operation: [
|
||||
'submit',
|
||||
],
|
||||
jsonDataFields: [true],
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
description: 'Form data to send as JSON',
|
||||
@@ -94,15 +79,9 @@ export const formFields: INodeProperties[] = [
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
jsonDataFields: [
|
||||
false,
|
||||
],
|
||||
resource: [
|
||||
'form',
|
||||
],
|
||||
operation: [
|
||||
'submit',
|
||||
],
|
||||
jsonDataFields: [false],
|
||||
resource: ['form'],
|
||||
operation: ['submit'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
import { IForm } from './FormInterface';
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function submitForm(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string, form: IDataObject) {
|
||||
export async function submitForm(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
form: IDataObject,
|
||||
) {
|
||||
const body: IForm = {
|
||||
form,
|
||||
};
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
import { IDataObject, NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
export async function cockpitApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function cockpitApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
body: any = {},
|
||||
uri?: string,
|
||||
option: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const credentials = await this.getCredentials('cockpitApi');
|
||||
let options: OptionsWithUri = {
|
||||
headers: {
|
||||
@@ -35,7 +40,10 @@ export async function cockpitApiRequest(this: IExecuteFunctions | IExecuteSingle
|
||||
}
|
||||
}
|
||||
|
||||
export function createDataFromParameters(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, itemIndex: number): IDataObject {
|
||||
export function createDataFromParameters(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
itemIndex: number,
|
||||
): IDataObject {
|
||||
const dataFieldsAreJson = this.getNodeParameter('jsonDataFields', itemIndex) as boolean;
|
||||
|
||||
if (dataFieldsAreJson) {
|
||||
|
||||
@@ -8,9 +8,7 @@ export const singletonOperations: INodeProperties[] = [
|
||||
noDataExpression: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'singleton',
|
||||
],
|
||||
resource: ['singleton'],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
@@ -36,12 +34,11 @@ export const singletonFields: INodeProperties[] = [
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'singleton',
|
||||
],
|
||||
resource: ['singleton'],
|
||||
},
|
||||
},
|
||||
required: true,
|
||||
description: 'Name of the singleton to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
description:
|
||||
'Name of the singleton to operate on. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
ILoadOptionsFunctions
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
||||
import { cockpitApiRequest } from './GenericFunctions';
|
||||
|
||||
export async function getSingleton(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, resourceName: string): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function getSingleton(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
resourceName: string,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
return cockpitApiRequest.call(this, 'get', `/singletons/get/${resourceName}`);
|
||||
}
|
||||
|
||||
export async function getAllSingletonNames(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions): Promise<string[]> {
|
||||
export async function getAllSingletonNames(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
): Promise<string[]> {
|
||||
return cockpitApiRequest.call(this, 'GET', `/singletons/listSingletons`, {});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user