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,4 +1,6 @@
|
||||
|
||||
// @ts-ignore
|
||||
import * as tmpl from 'riot-tmpl';
|
||||
// eslint-disable-next-line import/no-cycle
|
||||
import {
|
||||
INode,
|
||||
INodeExecutionData,
|
||||
@@ -9,28 +11,26 @@ import {
|
||||
Workflow,
|
||||
WorkflowDataProxy,
|
||||
WorkflowExecuteMode,
|
||||
} from './';
|
||||
} from '.';
|
||||
|
||||
// @ts-ignore
|
||||
import * as tmpl from 'riot-tmpl';
|
||||
|
||||
// Set it to use double curly brackets instead of single ones
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
tmpl.brackets.set('{{ }}');
|
||||
|
||||
// Make sure that it does not always print an error when it could not resolve
|
||||
// a variable
|
||||
tmpl.tmpl.errorHandler = () => { };
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
tmpl.tmpl.errorHandler = () => {};
|
||||
|
||||
export class Expression {
|
||||
|
||||
workflow: Workflow;
|
||||
|
||||
constructor(workflow: Workflow) {
|
||||
this.workflow = workflow;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Converts an object to a string in a way to make it clear that
|
||||
* the value comes from an object
|
||||
@@ -44,8 +44,6 @@ export class Expression {
|
||||
return `[${typeName}: ${JSON.stringify(value)}]`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resolves the paramter value. If it is an expression it will execute it and
|
||||
* return the result. For everything simply the supplied value will be returned.
|
||||
@@ -60,7 +58,19 @@ export class Expression {
|
||||
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
|
||||
* @memberof Workflow
|
||||
*/
|
||||
resolveSimpleParameterValue(parameterValue: NodeParameterValue, siblingParameters: INodeParameters, runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], mode: WorkflowExecuteMode, additionalKeys: IWorkflowDataProxyAdditionalKeys, returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
|
||||
resolveSimpleParameterValue(
|
||||
parameterValue: NodeParameterValue,
|
||||
siblingParameters: INodeParameters,
|
||||
runExecutionData: IRunExecutionData | null,
|
||||
runIndex: number,
|
||||
itemIndex: number,
|
||||
activeNodeName: string,
|
||||
connectionInputData: INodeExecutionData[],
|
||||
mode: WorkflowExecuteMode,
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
returnObjectAsString = false,
|
||||
selfData = {},
|
||||
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
|
||||
// Check if it is an expression
|
||||
if (typeof parameterValue !== 'string' || parameterValue.charAt(0) !== '=') {
|
||||
// Is no expression so return value
|
||||
@@ -70,30 +80,44 @@ export class Expression {
|
||||
// Is an expression
|
||||
|
||||
// Remove the equal sign
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
parameterValue = parameterValue.substr(1);
|
||||
|
||||
// Generate a data proxy which allows to query workflow data
|
||||
const dataProxy = new WorkflowDataProxy(this.workflow, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, siblingParameters, mode, additionalKeys, -1, selfData);
|
||||
const dataProxy = new WorkflowDataProxy(
|
||||
this.workflow,
|
||||
runExecutionData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
activeNodeName,
|
||||
connectionInputData,
|
||||
siblingParameters,
|
||||
mode,
|
||||
additionalKeys,
|
||||
-1,
|
||||
selfData,
|
||||
);
|
||||
const data = dataProxy.getDataProxy();
|
||||
|
||||
// Execute the expression
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
const returnValue = tmpl.tmpl(parameterValue, data);
|
||||
if (typeof returnValue === 'function') {
|
||||
throw new Error('Expression resolved to a function. Please add "()"');
|
||||
} else if (returnValue !== null && typeof returnValue === 'object') {
|
||||
if (returnObjectAsString === true) {
|
||||
if (returnObjectAsString) {
|
||||
return this.convertObjectValueToString(returnValue);
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return returnValue;
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-unsafe-member-access
|
||||
throw new Error(`Expression is not valid: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resolves value of parameter. But does not work for workflow-data.
|
||||
*
|
||||
@@ -103,7 +127,13 @@ export class Expression {
|
||||
* @returns {(string | undefined)}
|
||||
* @memberof Workflow
|
||||
*/
|
||||
getSimpleParameterValue(node: INode, parameterValue: string | boolean | undefined, mode: WorkflowExecuteMode, additionalKeys: IWorkflowDataProxyAdditionalKeys, defaultValue?: boolean | number | string): boolean | number | string | undefined {
|
||||
getSimpleParameterValue(
|
||||
node: INode,
|
||||
parameterValue: string | boolean | undefined,
|
||||
mode: WorkflowExecuteMode,
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
defaultValue?: boolean | number | string,
|
||||
): boolean | number | string | undefined {
|
||||
if (parameterValue === undefined) {
|
||||
// Value is not set so return the default
|
||||
return defaultValue;
|
||||
@@ -119,11 +149,18 @@ export class Expression {
|
||||
},
|
||||
};
|
||||
|
||||
return this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData, mode, additionalKeys) as boolean | number | string | undefined;
|
||||
return this.getParameterValue(
|
||||
parameterValue,
|
||||
runData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
node.name,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
) as boolean | number | string | undefined;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Resolves value of complex parameter. But does not work for workflow-data.
|
||||
*
|
||||
@@ -133,7 +170,19 @@ export class Expression {
|
||||
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined)}
|
||||
* @memberof Workflow
|
||||
*/
|
||||
getComplexParameterValue(node: INode, parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], mode: WorkflowExecuteMode, additionalKeys: IWorkflowDataProxyAdditionalKeys, defaultValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined = undefined, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined {
|
||||
getComplexParameterValue(
|
||||
node: INode,
|
||||
parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
||||
mode: WorkflowExecuteMode,
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
defaultValue:
|
||||
| NodeParameterValue
|
||||
| INodeParameters
|
||||
| NodeParameterValue[]
|
||||
| INodeParameters[]
|
||||
| undefined = undefined,
|
||||
selfData = {},
|
||||
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | undefined {
|
||||
if (parameterValue === undefined) {
|
||||
// Value is not set so return the default
|
||||
return defaultValue;
|
||||
@@ -150,14 +199,34 @@ export class Expression {
|
||||
};
|
||||
|
||||
// Resolve the "outer" main values
|
||||
const returnData = this.getParameterValue(parameterValue, runData, runIndex, itemIndex, node.name, connectionInputData, mode, additionalKeys, false, selfData);
|
||||
const returnData = this.getParameterValue(
|
||||
parameterValue,
|
||||
runData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
node.name,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
false,
|
||||
selfData,
|
||||
);
|
||||
|
||||
// Resolve the "inner" values
|
||||
return this.getParameterValue(returnData, runData, runIndex, itemIndex, node.name, connectionInputData, mode, additionalKeys, false, selfData);
|
||||
return this.getParameterValue(
|
||||
returnData,
|
||||
runData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
node.name,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
false,
|
||||
selfData,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the resolved node parameter value. If it is an expression it will execute it and
|
||||
* return the result. If the value to resolve is an array or object it will do the same
|
||||
@@ -173,24 +242,74 @@ export class Expression {
|
||||
* @returns {(NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[])}
|
||||
* @memberof Workflow
|
||||
*/
|
||||
getParameterValue(parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], runExecutionData: IRunExecutionData | null, runIndex: number, itemIndex: number, activeNodeName: string, connectionInputData: INodeExecutionData[], mode: WorkflowExecuteMode, additionalKeys: IWorkflowDataProxyAdditionalKeys, returnObjectAsString = false, selfData = {}): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
|
||||
getParameterValue(
|
||||
parameterValue: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
||||
runExecutionData: IRunExecutionData | null,
|
||||
runIndex: number,
|
||||
itemIndex: number,
|
||||
activeNodeName: string,
|
||||
connectionInputData: INodeExecutionData[],
|
||||
mode: WorkflowExecuteMode,
|
||||
additionalKeys: IWorkflowDataProxyAdditionalKeys,
|
||||
returnObjectAsString = false,
|
||||
selfData = {},
|
||||
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] {
|
||||
// Helper function which returns true when the parameter is a complex one or array
|
||||
const isComplexParameter = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[]) => {
|
||||
const isComplexParameter = (
|
||||
value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
||||
) => {
|
||||
return typeof value === 'object';
|
||||
};
|
||||
|
||||
// Helper function which resolves a parameter value depending on if it is simply or not
|
||||
const resolveParameterValue = (value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[], siblingParameters: INodeParameters) => {
|
||||
const resolveParameterValue = (
|
||||
value: NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[],
|
||||
siblingParameters: INodeParameters,
|
||||
) => {
|
||||
if (isComplexParameter(value)) {
|
||||
return this.getParameterValue(value, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, additionalKeys, returnObjectAsString, selfData);
|
||||
} else {
|
||||
return this.resolveSimpleParameterValue(value as NodeParameterValue, siblingParameters, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, additionalKeys, returnObjectAsString, selfData);
|
||||
return this.getParameterValue(
|
||||
value,
|
||||
runExecutionData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
activeNodeName,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
returnObjectAsString,
|
||||
selfData,
|
||||
);
|
||||
}
|
||||
return this.resolveSimpleParameterValue(
|
||||
value as NodeParameterValue,
|
||||
siblingParameters,
|
||||
runExecutionData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
activeNodeName,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
returnObjectAsString,
|
||||
selfData,
|
||||
);
|
||||
};
|
||||
|
||||
// Check if it value is a simple one that we can get it resolved directly
|
||||
if (!isComplexParameter(parameterValue)) {
|
||||
return this.resolveSimpleParameterValue(parameterValue as NodeParameterValue, {}, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, mode, additionalKeys, returnObjectAsString, selfData);
|
||||
return this.resolveSimpleParameterValue(
|
||||
parameterValue as NodeParameterValue,
|
||||
{},
|
||||
runExecutionData,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
activeNodeName,
|
||||
connectionInputData,
|
||||
mode,
|
||||
additionalKeys,
|
||||
returnObjectAsString,
|
||||
selfData,
|
||||
);
|
||||
}
|
||||
|
||||
// The parameter value is complex so resolve depending on type
|
||||
@@ -198,28 +317,33 @@ export class Expression {
|
||||
if (Array.isArray(parameterValue)) {
|
||||
// Data is an array
|
||||
const returnData = [];
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const item of parameterValue) {
|
||||
returnData.push(resolveParameterValue(item, {}));
|
||||
}
|
||||
|
||||
if (returnObjectAsString === true && typeof returnData === 'object') {
|
||||
if (returnObjectAsString && typeof returnData === 'object') {
|
||||
return this.convertObjectValueToString(returnData);
|
||||
}
|
||||
|
||||
return returnData as NodeParameterValue[] | INodeParameters[];
|
||||
} else if (parameterValue === null || parameterValue === undefined) {
|
||||
return parameterValue;
|
||||
} else {
|
||||
// Data is an object
|
||||
const returnData: INodeParameters = {};
|
||||
for (const key of Object.keys(parameterValue)) {
|
||||
returnData[key] = resolveParameterValue((parameterValue as INodeParameters)[key], parameterValue as INodeParameters);
|
||||
}
|
||||
|
||||
if (returnObjectAsString === true && typeof returnData === 'object') {
|
||||
return this.convertObjectValueToString(returnData);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
if (parameterValue === null || parameterValue === undefined) {
|
||||
return parameterValue;
|
||||
}
|
||||
// Data is an object
|
||||
const returnData: INodeParameters = {};
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const key of Object.keys(parameterValue)) {
|
||||
returnData[key] = resolveParameterValue(
|
||||
(parameterValue as INodeParameters)[key],
|
||||
parameterValue as INodeParameters,
|
||||
);
|
||||
}
|
||||
|
||||
if (returnObjectAsString && typeof returnData === 'object') {
|
||||
return this.convertObjectValueToString(returnData);
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user