mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🎨 Set up linting and formatting (#2120)
* ⬆️ Upgrade TS to 4.3.5 * 👕 Add ESLint configs * 🎨 Add Prettier config * 📦 Add deps and commands * ⚡ Adjust global .editorconfig to new ruleset * 🔥 Remove unneeded local .editorconfig * 📦 Update deps in editor-ui * 🔨 Limit Prettier to only TS files * ⚡ Add recommended VSCode extensions * 👕 Fix build * 🔥 Remove Vue setting from global config * ⚡ Disable prefer-default-export per feedback * ✏️ Add forgotten divider * 👕 Disable no-plusplus * 👕 Disable class-methods-use-this * ✏️ Alphabetize overrides * 👕 Add one-var consecutive override * ⏪ Revert one-var consecutive override This reverts commit b9252cf935659ba6d76727ad484a1d3c00008fcc. * 🎨 👕 Lint and format workflow package (#2121) * 🎨 Format /workflow package * 👕 Lint /workflow package * 🎨 Re-format /workflow package * 👕 Re-lint /workflow package * ✏️ Fix typo * ⚡ Consolidate if-checks * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format node-dev package (#2122) * 🎨 Format /node-dev package * ⚡ Exclude templates from ESLint config This keeps the templates consistent with the codebase while preventing lint exceptions from being made part of the templates. * 👕 Lint /node-dev package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🎨 👕 Lint and format core package (#2123) * 🎨 Format /core package * 👕 Lint /core package * 🎨 Re-format /core package * 👕 Re-lint /core package * 🔥 Remove prefer-default-export exceptions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 🎨 👕 Lint and format cli package (#2124) * 🎨 Format /cli package * 👕 Exclude migrations from linting * 👕 Lint /cli package * 🎨 Re-format /cli package * 👕 Re-lint /cli package * 👕 Fix build * 🔥 Remove prefer-default-export exceptions * ⚡ Update exceptions in ActiveExecutions * 🔥 Remove no-plusplus exceptions * 🔥 Remove class-methods-use-this exceptions * 👕 fix lint issues * 🔧 use package specific linter, remove tslint command * 🔨 resolve build issue, sync dependencies * 🔧 change lint command Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com>
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable @typescript-eslint/no-this-alias */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable no-prototype-builtins */
|
||||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import {
|
||||
IDataObject,
|
||||
INodeExecutionData,
|
||||
@@ -9,26 +18,44 @@ import {
|
||||
NodeParameterValue,
|
||||
Workflow,
|
||||
WorkflowExecuteMode,
|
||||
} from './';
|
||||
|
||||
|
||||
} from '.';
|
||||
|
||||
export class WorkflowDataProxy {
|
||||
private workflow: Workflow;
|
||||
|
||||
private runExecutionData: IRunExecutionData | null;
|
||||
|
||||
private defaultReturnRunIndex: number;
|
||||
|
||||
private runIndex: number;
|
||||
|
||||
private itemIndex: number;
|
||||
|
||||
private activeNodeName: string;
|
||||
|
||||
private connectionInputData: INodeExecutionData[];
|
||||
|
||||
private siblingParameters: INodeParameters;
|
||||
|
||||
private mode: WorkflowExecuteMode;
|
||||
|
||||
private selfData: IDataObject;
|
||||
|
||||
private additionalKeys: IWorkflowDataProxyAdditionalKeys;
|
||||
|
||||
|
||||
|
||||
constructor(workflow: Workflow, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], siblingParameters: INodeParameters, mode: WorkflowExecuteMode, additionalKeys: IWorkflowDataProxyAdditionalKeys, defaultReturnRunIndex = -1, selfData = {}) {
|
||||
constructor(
|
||||
workflow: Workflow,
|
||||
runExecutionData: IRunExecutionData | null,
|
||||
runIndex: number,
|
||||
itemIndex: number,
|
||||
activeNodeName: string,
|
||||
connectionInputData: INodeExecutionData[],
|
||||
siblingParameters: INodeParameters,
|
||||
mode: WorkflowExecuteMode,
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
defaultReturnRunIndex = -1,
|
||||
selfData = {},
|
||||
) {
|
||||
this.workflow = workflow;
|
||||
this.runExecutionData = runExecutionData;
|
||||
this.defaultReturnRunIndex = defaultReturnRunIndex;
|
||||
@@ -42,8 +69,6 @@ export class WorkflowDataProxy {
|
||||
this.additionalKeys = additionalKeys;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxy which allows to query context data of a given node
|
||||
*
|
||||
@@ -56,46 +81,51 @@ export class WorkflowDataProxy {
|
||||
const that = this;
|
||||
const node = this.workflow.nodes[nodeName];
|
||||
|
||||
return new Proxy({}, {
|
||||
ownKeys(target) {
|
||||
if (Reflect.ownKeys(target).length === 0) {
|
||||
// Target object did not get set yet
|
||||
Object.assign(target, NodeHelpers.getContext(that.runExecutionData!, 'node', node));
|
||||
}
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
ownKeys(target) {
|
||||
if (Reflect.ownKeys(target).length === 0) {
|
||||
// Target object did not get set yet
|
||||
Object.assign(target, NodeHelpers.getContext(that.runExecutionData!, 'node', node));
|
||||
}
|
||||
|
||||
return Reflect.ownKeys(target);
|
||||
return Reflect.ownKeys(target);
|
||||
},
|
||||
get(target, name, receiver) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
name = name.toString();
|
||||
const contextData = NodeHelpers.getContext(that.runExecutionData!, 'node', node);
|
||||
|
||||
if (!contextData.hasOwnProperty(name)) {
|
||||
// Parameter does not exist on node
|
||||
throw new Error(`Could not find parameter "${name}" on context of node "${nodeName}"`);
|
||||
}
|
||||
|
||||
return contextData[name];
|
||||
},
|
||||
},
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
const contextData = NodeHelpers.getContext(that.runExecutionData!, 'node', node);
|
||||
|
||||
if (!contextData.hasOwnProperty(name)) {
|
||||
// Parameter does not exist on node
|
||||
throw new Error(`Could not find parameter "${name}" on context of node "${nodeName}"`);
|
||||
}
|
||||
|
||||
return contextData[name];
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private selfGetter() {
|
||||
const that = this;
|
||||
|
||||
return new Proxy({}, {
|
||||
ownKeys(target) {
|
||||
return Reflect.ownKeys(target);
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
ownKeys(target) {
|
||||
return Reflect.ownKeys(target);
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
return that.selfData[name];
|
||||
},
|
||||
},
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
return that.selfData[name];
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxy which allows to query parameter data of a given node
|
||||
*
|
||||
@@ -115,12 +145,15 @@ export class WorkflowDataProxy {
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
|
||||
let returnValue: INodeParameters | NodeParameterValue | NodeParameterValue[] | INodeParameters[];
|
||||
let returnValue:
|
||||
| INodeParameters
|
||||
| NodeParameterValue
|
||||
| NodeParameterValue[]
|
||||
| INodeParameters[];
|
||||
if (name[0] === '&') {
|
||||
const key = name.slice(1);
|
||||
if (!that.siblingParameters.hasOwnProperty(key)) {
|
||||
throw new Error(`Could not find sibling parameter "${key}" on node "${nodeName}"`);
|
||||
|
||||
}
|
||||
returnValue = that.siblingParameters[key];
|
||||
} else {
|
||||
@@ -134,7 +167,16 @@ export class WorkflowDataProxy {
|
||||
|
||||
if (typeof returnValue === 'string' && returnValue.charAt(0) === '=') {
|
||||
// The found value is an expression so resolve it
|
||||
return that.workflow.expression.getParameterValue(returnValue, that.runExecutionData, that.runIndex, that.itemIndex, that.activeNodeName, that.connectionInputData, that.mode, that.additionalKeys);
|
||||
return that.workflow.expression.getParameterValue(
|
||||
returnValue,
|
||||
that.runExecutionData,
|
||||
that.runIndex,
|
||||
that.itemIndex,
|
||||
that.activeNodeName,
|
||||
that.connectionInputData,
|
||||
that.mode,
|
||||
that.additionalKeys,
|
||||
);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
@@ -142,7 +184,6 @@ export class WorkflowDataProxy {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the node ExecutionData
|
||||
*
|
||||
@@ -154,11 +195,16 @@ export class WorkflowDataProxy {
|
||||
* @returns {INodeExecutionData[]}
|
||||
* @memberof WorkflowDataProxy
|
||||
*/
|
||||
private getNodeExecutionData(nodeName: string, shortSyntax = false, outputIndex?: number, runIndex?: number): INodeExecutionData[] {
|
||||
private getNodeExecutionData(
|
||||
nodeName: string,
|
||||
shortSyntax = false,
|
||||
outputIndex?: number,
|
||||
runIndex?: number,
|
||||
): INodeExecutionData[] {
|
||||
const that = this;
|
||||
|
||||
let executionData: INodeExecutionData[];
|
||||
if (shortSyntax === false) {
|
||||
if (!shortSyntax) {
|
||||
// Long syntax got used to return data from node in path
|
||||
|
||||
if (that.runExecutionData === null) {
|
||||
@@ -170,7 +216,8 @@ export class WorkflowDataProxy {
|
||||
}
|
||||
|
||||
runIndex = runIndex === undefined ? that.defaultReturnRunIndex : runIndex;
|
||||
runIndex = runIndex === -1 ? (that.runExecutionData.resultData.runData[nodeName].length -1) : runIndex;
|
||||
runIndex =
|
||||
runIndex === -1 ? that.runExecutionData.resultData.runData[nodeName].length - 1 : runIndex;
|
||||
|
||||
if (that.runExecutionData.resultData.runData[nodeName].length < runIndex) {
|
||||
throw new Error(`No execution data found for run "${runIndex}" of node "${nodeName}"`);
|
||||
@@ -187,10 +234,17 @@ export class WorkflowDataProxy {
|
||||
// Depends on how the nodes are connected.
|
||||
// (example "IF" node. If node is connected to "true" or to "false" output)
|
||||
if (outputIndex === undefined) {
|
||||
const outputIndex = that.workflow.getNodeConnectionOutputIndex(that.activeNodeName, nodeName, 'main');
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
const outputIndex = that.workflow.getNodeConnectionOutputIndex(
|
||||
that.activeNodeName,
|
||||
nodeName,
|
||||
'main',
|
||||
);
|
||||
|
||||
if (outputIndex === undefined) {
|
||||
throw new Error(`The node "${that.activeNodeName}" is not connected with node "${nodeName}" so no data can get returned from it.`);
|
||||
throw new Error(
|
||||
`The node "${that.activeNodeName}" is not connected with node "${nodeName}" so no data can get returned from it.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +253,9 @@ export class WorkflowDataProxy {
|
||||
}
|
||||
|
||||
if (taskData.main.length < outputIndex) {
|
||||
throw new Error(`No data found from "main" input with index "${outputIndex}" via which node is connected with.`);
|
||||
throw new Error(
|
||||
`No data found from "main" input with index "${outputIndex}" via which node is connected with.`,
|
||||
);
|
||||
}
|
||||
|
||||
executionData = taskData.main[outputIndex] as INodeExecutionData[];
|
||||
@@ -217,7 +273,6 @@ export class WorkflowDataProxy {
|
||||
return executionData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxy which allows to query data of a given node
|
||||
*
|
||||
@@ -228,7 +283,6 @@ export class WorkflowDataProxy {
|
||||
* @memberof WorkflowDataGetter
|
||||
*/
|
||||
private nodeDataGetter(nodeName: string, shortSyntax = false) {
|
||||
|
||||
const that = this;
|
||||
const node = this.workflow.nodes[nodeName];
|
||||
|
||||
@@ -236,65 +290,69 @@ export class WorkflowDataProxy {
|
||||
throw new Error(`The node "${nodeName}" does not exist!`);
|
||||
}
|
||||
|
||||
return new Proxy({}, {
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, name, receiver) {
|
||||
name = name.toString();
|
||||
|
||||
if (['binary', 'data', 'json'].includes(name)) {
|
||||
const executionData = that.getNodeExecutionData(nodeName, shortSyntax, undefined);
|
||||
if (['binary', 'data', 'json'].includes(name)) {
|
||||
const executionData = that.getNodeExecutionData(nodeName, shortSyntax, undefined);
|
||||
|
||||
if (executionData.length <= that.itemIndex) {
|
||||
throw new Error(`No data found for item-index: "${that.itemIndex}"`);
|
||||
}
|
||||
if (executionData.length <= that.itemIndex) {
|
||||
throw new Error(`No data found for item-index: "${that.itemIndex}"`);
|
||||
}
|
||||
|
||||
if (['data', 'json'].includes(name as string)) {
|
||||
// JSON-Data
|
||||
return executionData[that.itemIndex].json;
|
||||
} else if (name === 'binary') {
|
||||
// Binary-Data
|
||||
const returnData: IDataObject = {};
|
||||
if (['data', 'json'].includes(name)) {
|
||||
// JSON-Data
|
||||
return executionData[that.itemIndex].json;
|
||||
}
|
||||
if (name === 'binary') {
|
||||
// Binary-Data
|
||||
const returnData: IDataObject = {};
|
||||
|
||||
if (!executionData[that.itemIndex].binary) {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
const binaryKeyData = executionData[that.itemIndex].binary!;
|
||||
for (const keyName of Object.keys(binaryKeyData)) {
|
||||
returnData[keyName] = {};
|
||||
|
||||
const binaryData = binaryKeyData[keyName];
|
||||
for (const propertyName in binaryData) {
|
||||
if (propertyName === 'data') {
|
||||
// Skip the data property
|
||||
// eslint-disable-next-line no-continue
|
||||
continue;
|
||||
}
|
||||
(returnData[keyName] as IDataObject)[propertyName] = binaryData[propertyName];
|
||||
}
|
||||
}
|
||||
|
||||
if (!executionData[that.itemIndex].binary) {
|
||||
return returnData;
|
||||
}
|
||||
|
||||
const binaryKeyData = executionData[that.itemIndex].binary!;
|
||||
for (const keyName of Object.keys(binaryKeyData)) {
|
||||
|
||||
returnData[keyName] = {};
|
||||
|
||||
const binaryData = binaryKeyData[keyName];
|
||||
for (const propertyName in binaryData) {
|
||||
if (propertyName === 'data') {
|
||||
// Skip the data property
|
||||
continue;
|
||||
}
|
||||
(returnData[keyName] as IDataObject)[propertyName] = binaryData[propertyName];
|
||||
}
|
||||
} else if (name === 'context') {
|
||||
return that.nodeContextGetter(nodeName);
|
||||
} else if (name === 'parameter') {
|
||||
// Get node parameter data
|
||||
return that.nodeParameterGetter(nodeName);
|
||||
} else if (name === 'runIndex') {
|
||||
if (
|
||||
that.runExecutionData === null ||
|
||||
!that.runExecutionData.resultData.runData[nodeName]
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return returnData;
|
||||
return that.runExecutionData.resultData.runData[nodeName].length - 1;
|
||||
}
|
||||
|
||||
} else if (name === 'context') {
|
||||
return that.nodeContextGetter(nodeName);
|
||||
} else if (name === 'parameter') {
|
||||
// Get node parameter data
|
||||
return that.nodeParameterGetter(nodeName);
|
||||
} else if (name === 'runIndex') {
|
||||
if (that.runExecutionData === null || !that.runExecutionData.resultData.runData[nodeName]) {
|
||||
return -1;
|
||||
}
|
||||
return that.runExecutionData.resultData.runData[nodeName].length - 1;
|
||||
}
|
||||
|
||||
return Reflect.get(target, name, receiver);
|
||||
return Reflect.get(target, name, receiver);
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxy to query data from the environment
|
||||
*
|
||||
@@ -303,15 +361,16 @@ export class WorkflowDataProxy {
|
||||
* @memberof WorkflowDataGetter
|
||||
*/
|
||||
private envGetter() {
|
||||
return new Proxy({}, {
|
||||
get(target, name, receiver) {
|
||||
return process.env[name.toString()];
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, name, receiver) {
|
||||
return process.env[name.toString()];
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxt to query data from the workflow
|
||||
*
|
||||
@@ -320,27 +379,24 @@ export class WorkflowDataProxy {
|
||||
* @memberof WorkflowDataProxy
|
||||
*/
|
||||
private workflowGetter() {
|
||||
const allowedValues = [
|
||||
'active',
|
||||
'id',
|
||||
'name',
|
||||
];
|
||||
const allowedValues = ['active', 'id', 'name'];
|
||||
const that = this;
|
||||
|
||||
return new Proxy({}, {
|
||||
get(target, name, receiver) {
|
||||
if (!allowedValues.includes(name.toString())) {
|
||||
throw new Error(`The key "${name.toString()}" is not supported!`);
|
||||
}
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, name, receiver) {
|
||||
if (!allowedValues.includes(name.toString())) {
|
||||
throw new Error(`The key "${name.toString()}" is not supported!`);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
return that.workflow[name.toString()];
|
||||
// @ts-ignore
|
||||
return that.workflow[name.toString()];
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a proxy to query data of all nodes
|
||||
*
|
||||
@@ -350,15 +406,16 @@ export class WorkflowDataProxy {
|
||||
*/
|
||||
private nodeGetter() {
|
||||
const that = this;
|
||||
return new Proxy({}, {
|
||||
get(target, name, receiver) {
|
||||
return that.nodeDataGetter(name.toString());
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, name, receiver) {
|
||||
return that.nodeDataGetter(name.toString());
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the data proxy object which allows to query data from current run
|
||||
*
|
||||
@@ -374,11 +431,31 @@ export class WorkflowDataProxy {
|
||||
$env: this.envGetter(),
|
||||
$evaluateExpression: (expression: string, itemIndex?: number) => {
|
||||
itemIndex = itemIndex || that.itemIndex;
|
||||
return that.workflow.expression.getParameterValue('=' + expression, that.runExecutionData, that.runIndex, itemIndex, that.activeNodeName, that.connectionInputData, that.mode, that.additionalKeys);
|
||||
return that.workflow.expression.getParameterValue(
|
||||
`=${expression}`,
|
||||
that.runExecutionData,
|
||||
that.runIndex,
|
||||
itemIndex,
|
||||
that.activeNodeName,
|
||||
that.connectionInputData,
|
||||
that.mode,
|
||||
that.additionalKeys,
|
||||
);
|
||||
},
|
||||
$item: (itemIndex: number, runIndex?: number) => {
|
||||
const defaultReturnRunIndex = runIndex === undefined ? -1 : runIndex;
|
||||
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData, that.siblingParameters, that.mode, that.additionalKeys, defaultReturnRunIndex);
|
||||
const dataProxy = new WorkflowDataProxy(
|
||||
this.workflow,
|
||||
this.runExecutionData,
|
||||
this.runIndex,
|
||||
itemIndex,
|
||||
this.activeNodeName,
|
||||
this.connectionInputData,
|
||||
that.siblingParameters,
|
||||
that.mode,
|
||||
that.additionalKeys,
|
||||
defaultReturnRunIndex,
|
||||
);
|
||||
return dataProxy.getDataProxy();
|
||||
},
|
||||
$items: (nodeName?: string, outputIndex?: number, runIndex?: number) => {
|
||||
@@ -410,7 +487,8 @@ export class WorkflowDataProxy {
|
||||
if (['$data', '$json'].includes(name as string)) {
|
||||
// @ts-ignore
|
||||
return that.nodeDataGetter(that.activeNodeName, true).json;
|
||||
} else if (name === '$binary') {
|
||||
}
|
||||
if (name === '$binary') {
|
||||
// @ts-ignore
|
||||
return that.nodeDataGetter(that.activeNodeName, true).binary;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user