mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(workflow): remove a few ts-ignore and eslint-disable (#3958)
fix(workflow): remove a few `ts-ignore` and `eslint-disable`. improve typing
This commit is contained in:
committed by
GitHub
parent
712924cbc3
commit
a73ac1d94f
@@ -1,5 +1,3 @@
|
||||
/* eslint-disable id-denylist */
|
||||
// @ts-ignore
|
||||
import * as tmpl from '@n8n_io/riot-tmpl';
|
||||
import { DateTime, Duration, Interval } from 'luxon';
|
||||
|
||||
@@ -12,20 +10,17 @@ import {
|
||||
INodeParameters,
|
||||
IRunExecutionData,
|
||||
IWorkflowDataProxyAdditionalKeys,
|
||||
IWorkflowDataProxyData,
|
||||
NodeParameterValue,
|
||||
Workflow,
|
||||
WorkflowDataProxy,
|
||||
WorkflowExecuteMode,
|
||||
} from '.';
|
||||
|
||||
// @ts-ignore
|
||||
|
||||
// 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 error get forwarded
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
tmpl.tmpl.errorHandler = (error: Error) => {
|
||||
if (error instanceof ExpressionError) {
|
||||
if (error.context.failExecution) {
|
||||
@@ -114,7 +109,6 @@ export class Expression {
|
||||
const data = dataProxy.getDataProxy();
|
||||
|
||||
// Support only a subset of process properties
|
||||
// @ts-ignore
|
||||
data.process = {
|
||||
arch: process.arch,
|
||||
env: process.env,
|
||||
@@ -130,7 +124,6 @@ export class Expression {
|
||||
* Denylist
|
||||
*/
|
||||
|
||||
// @ts-ignore
|
||||
data.document = {};
|
||||
data.global = {};
|
||||
data.window = {};
|
||||
@@ -223,11 +216,13 @@ export class Expression {
|
||||
data.Intl = typeof Intl !== 'undefined' ? Intl : {};
|
||||
|
||||
// Text
|
||||
// eslint-disable-next-line id-denylist
|
||||
data.String = String;
|
||||
data.RegExp = RegExp;
|
||||
|
||||
// Math
|
||||
data.Math = Math;
|
||||
// eslint-disable-next-line id-denylist
|
||||
data.Number = Number;
|
||||
data.BigInt = typeof BigInt !== 'undefined' ? BigInt : {};
|
||||
data.Infinity = Infinity;
|
||||
@@ -250,15 +245,28 @@ export class Expression {
|
||||
data.decodeURIComponent = decodeURIComponent;
|
||||
|
||||
// Other
|
||||
// eslint-disable-next-line id-denylist
|
||||
data.Boolean = Boolean;
|
||||
data.Symbol = Symbol;
|
||||
|
||||
// Execute the expression
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let returnValue;
|
||||
const returnValue = this.renderExpression(parameterValue, data);
|
||||
if (typeof returnValue === 'function') {
|
||||
throw new Error('Expression resolved to a function. Please add "()"');
|
||||
} else if (typeof returnValue === 'string') {
|
||||
return returnValue;
|
||||
} else if (returnValue !== null && typeof returnValue === 'object') {
|
||||
if (returnObjectAsString) {
|
||||
return this.convertObjectValueToString(returnValue);
|
||||
}
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private renderExpression(expression: string, data: IWorkflowDataProxyData): tmpl.ReturnValue {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
||||
returnValue = tmpl.tmpl(parameterValue, data);
|
||||
return tmpl.tmpl(expression, data);
|
||||
} catch (error) {
|
||||
if (error instanceof ExpressionError) {
|
||||
// Ignore all errors except if they are ExpressionErrors and they are supposed
|
||||
@@ -268,18 +276,7 @@ export class Expression {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof returnValue === 'function') {
|
||||
throw new Error('Expression resolved to a function. Please add "()"');
|
||||
} else if (returnValue !== null && typeof returnValue === 'object') {
|
||||
if (returnObjectAsString) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
return this.convertObjectValueToString(returnValue);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return returnValue;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -495,33 +492,25 @@ export class Expression {
|
||||
}
|
||||
|
||||
// The parameter value is complex so resolve depending on type
|
||||
|
||||
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 && typeof returnData === 'object') {
|
||||
return this.convertObjectValueToString(returnData);
|
||||
}
|
||||
|
||||
const returnData = parameterValue.map((item) => resolveParameterValue(item, {}));
|
||||
return returnData as NodeParameterValue[] | INodeParameters[];
|
||||
}
|
||||
|
||||
if (parameterValue === null || parameterValue === undefined) {
|
||||
return parameterValue;
|
||||
}
|
||||
|
||||
if (typeof parameterValue !== 'object') {
|
||||
return {};
|
||||
}
|
||||
|
||||
// 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,
|
||||
);
|
||||
for (const [key, value] of Object.entries(parameterValue)) {
|
||||
returnData[key] = resolveParameterValue(value, parameterValue);
|
||||
}
|
||||
|
||||
if (returnObjectAsString && typeof returnData === 'object') {
|
||||
|
||||
Reference in New Issue
Block a user