refactor(core): clear @ts-ignore from workflow and core packages (#4467)

* 📘 Clear all `@ts-ignore` comments from workflow package

* 👕 Default to error with package-level overrides

* refactor(core): clear all `@ts-ignore` comments from core package (#4473)

👕 Clear all `@ts-ignore` comments from core package

* ✏️ Update comment
This commit is contained in:
Iván Ovejero 2022-10-31 12:45:34 +01:00 committed by GitHub
parent 46905fd2cb
commit ec5ef0c50d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 87 additions and 62 deletions

View file

@ -137,7 +137,7 @@ const config = (module.exports = {
/** /**
* https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md
*/ */
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }], '@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }],
/** /**
* https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md

View file

@ -12,5 +12,6 @@ module.exports = {
rules: { rules: {
// TODO: Remove this // TODO: Remove this
'import/order': 'off', 'import/order': 'off',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
}, },
}; };

View file

@ -6,5 +6,6 @@ module.exports = {
rules: { rules: {
// TODO: Remove this // TODO: Remove this
'import/order': 'off', 'import/order': 'off',
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }],
}, },
}; };

View file

@ -4,7 +4,7 @@ import { IBinaryDataConfig, IBinaryDataManager } from '../Interfaces';
import { BinaryDataFileSystem } from './FileSystem'; import { BinaryDataFileSystem } from './FileSystem';
export class BinaryDataManager { export class BinaryDataManager {
private static instance: BinaryDataManager; static instance: BinaryDataManager | undefined;
private managers: { private managers: {
[key: string]: IBinaryDataManager; [key: string]: IBinaryDataManager;

View file

@ -77,8 +77,8 @@ import { get } from 'lodash';
import type { Request, Response } from 'express'; import type { Request, Response } from 'express';
import FormData from 'form-data'; import FormData from 'form-data';
import path from 'path'; import path from 'path';
import { OptionsWithUri, OptionsWithUrl } from 'request'; import { OptionsWithUri, OptionsWithUrl, RequestCallback, RequiredUriUrl } from 'request';
import requestPromise from 'request-promise-native'; import requestPromise, { RequestPromiseOptions } from 'request-promise-native';
import { fromBuffer } from 'file-type'; import { fromBuffer } from 'file-type';
import { lookup } from 'mime-types'; import { lookup } from 'mime-types';
@ -123,18 +123,16 @@ const requestPromiseWithDefaults = requestPromise.defaults({
const pushFormDataValue = (form: FormData, key: string, value: any) => { const pushFormDataValue = (form: FormData, key: string, value: any) => {
if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) { if (value?.hasOwnProperty('value') && value.hasOwnProperty('options')) {
// @ts-ignore
form.append(key, value.value, value.options); form.append(key, value.value, value.options);
} else { } else {
form.append(key, value); form.append(key, value);
} }
}; };
const createFormDataObject = (data: object) => { const createFormDataObject = (data: Record<string, unknown>) => {
const formData = new FormData(); const formData = new FormData();
const keys = Object.keys(data); const keys = Object.keys(data);
keys.forEach((key) => { keys.forEach((key) => {
// @ts-ignore
const formField = data[key]; const formField = data[key];
if (formField instanceof Array) { if (formField instanceof Array) {
@ -231,7 +229,7 @@ async function parseRequestObject(requestObject: IDataObject) {
if (requestObject.formData !== undefined && requestObject.formData instanceof FormData) { if (requestObject.formData !== undefined && requestObject.formData instanceof FormData) {
axiosConfig.data = requestObject.formData; axiosConfig.data = requestObject.formData;
} else { } else {
const allData = { const allData: Partial<FormData> = {
...(requestObject.body as object | undefined), ...(requestObject.body as object | undefined),
...(requestObject.formData as object | undefined), ...(requestObject.formData as object | undefined),
}; };
@ -240,7 +238,6 @@ async function parseRequestObject(requestObject: IDataObject) {
} }
// replace the existing header with a new one that // replace the existing header with a new one that
// contains the boundary property. // contains the boundary property.
// @ts-ignore
delete axiosConfig.headers[contentTypeHeaderKeyName]; delete axiosConfig.headers[contentTypeHeaderKeyName];
const headers = axiosConfig.data.getHeaders(); const headers = axiosConfig.data.getHeaders();
axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers); axiosConfig.headers = Object.assign(axiosConfig.headers || {}, headers);
@ -276,7 +273,7 @@ async function parseRequestObject(requestObject: IDataObject) {
if (requestObject.formData instanceof FormData) { if (requestObject.formData instanceof FormData) {
axiosConfig.data = requestObject.formData; axiosConfig.data = requestObject.formData;
} else { } else {
axiosConfig.data = createFormDataObject(requestObject.formData as object); axiosConfig.data = createFormDataObject(requestObject.formData as Record<string, unknown>);
} }
// Mix in headers as FormData creates the boundary. // Mix in headers as FormData creates the boundary.
const headers = axiosConfig.data.getHeaders(); const headers = axiosConfig.data.getHeaders();
@ -284,9 +281,8 @@ async function parseRequestObject(requestObject: IDataObject) {
await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers); await generateContentLengthHeader(axiosConfig.data, axiosConfig.headers);
} else if (requestObject.body !== undefined) { } else if (requestObject.body !== undefined) {
// If we have body and possibly form // If we have body and possibly form
if (requestObject.form !== undefined) { if (requestObject.form !== undefined && requestObject.body) {
// merge both objects when exist. // merge both objects when exist.
// @ts-ignore
requestObject.body = Object.assign(requestObject.body, requestObject.form); requestObject.body = Object.assign(requestObject.body, requestObject.form);
} }
axiosConfig.data = requestObject.body as FormData | GenericValue | GenericValue[]; axiosConfig.data = requestObject.body as FormData | GenericValue | GenericValue[];
@ -313,10 +309,25 @@ async function parseRequestObject(requestObject: IDataObject) {
axiosConfig.params = requestObject.qs as IDataObject; axiosConfig.params = requestObject.qs as IDataObject;
} }
function hasArrayFormatOptions(
arg: IDataObject,
): arg is IDataObject & { qsStringifyOptions: { arrayFormat: 'repeat' | 'brackets' } } {
if (
typeof arg.qsStringifyOptions === 'object' &&
arg.qsStringifyOptions !== null &&
!Array.isArray(arg.qsStringifyOptions) &&
'arrayFormat' in arg.qsStringifyOptions
) {
return true;
}
return false;
}
if ( if (
requestObject.useQuerystring === true || requestObject.useQuerystring === true ||
// @ts-ignore (hasArrayFormatOptions(requestObject) &&
requestObject.qsStringifyOptions?.arrayFormat === 'repeat' requestObject.qsStringifyOptions.arrayFormat === 'repeat')
) { ) {
axiosConfig.paramsSerializer = (params) => { axiosConfig.paramsSerializer = (params) => {
return stringify(params, { arrayFormat: 'repeat' }); return stringify(params, { arrayFormat: 'repeat' });
@ -327,8 +338,10 @@ async function parseRequestObject(requestObject: IDataObject) {
}; };
} }
// @ts-ignore if (
if (requestObject.qsStringifyOptions?.arrayFormat === 'brackets') { hasArrayFormatOptions(requestObject) &&
requestObject.qsStringifyOptions.arrayFormat === 'brackets'
) {
axiosConfig.paramsSerializer = (params) => { axiosConfig.paramsSerializer = (params) => {
return stringify(params, { arrayFormat: 'brackets' }); return stringify(params, { arrayFormat: 'brackets' });
}; };
@ -552,8 +565,11 @@ async function proxyRequestToAxios(
): Promise<any> { ): Promise<any> {
// Check if there's a better way of getting this config here // Check if there's a better way of getting this config here
if (process.env.N8N_USE_DEPRECATED_REQUEST_LIB) { if (process.env.N8N_USE_DEPRECATED_REQUEST_LIB) {
// @ts-ignore return requestPromiseWithDefaults.call(
return requestPromiseWithDefaults.call(null, uriOrObject, options); null,
uriOrObject as unknown as RequiredUriUrl & RequestPromiseOptions,
options as unknown as RequestCallback,
);
} }
let axiosConfig: AxiosRequestConfig = { let axiosConfig: AxiosRequestConfig = {
@ -970,10 +986,8 @@ export async function requestOAuth2(
const newRequestOptions = token.sign(requestOptions as clientOAuth2.RequestObject); const newRequestOptions = token.sign(requestOptions as clientOAuth2.RequestObject);
const newRequestHeaders = (newRequestOptions.headers = newRequestOptions.headers ?? {}); const newRequestHeaders = (newRequestOptions.headers = newRequestOptions.headers ?? {});
// If keep bearer is false remove the it from the authorization header // If keep bearer is false remove the it from the authorization header
if (oAuth2Options?.keepBearer === false) { if (oAuth2Options?.keepBearer === false && typeof newRequestHeaders.Authorization === 'string') {
newRequestHeaders.Authorization = newRequestHeaders.Authorization = newRequestHeaders.Authorization.split(' ')[1];
// @ts-ignore
newRequestHeaders.Authorization.split(' ')[1];
} }
if (oAuth2Options?.keyToIncludeInAccessTokenHeader) { if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
@ -1110,10 +1124,8 @@ export async function requestOAuth2(
const newRequestOptions = newToken.sign(requestOptions as clientOAuth2.RequestObject); const newRequestOptions = newToken.sign(requestOptions as clientOAuth2.RequestObject);
newRequestOptions.headers = newRequestOptions.headers ?? {}; newRequestOptions.headers = newRequestOptions.headers ?? {};
// @ts-ignore
if (oAuth2Options?.keyToIncludeInAccessTokenHeader) { if (oAuth2Options?.keyToIncludeInAccessTokenHeader) {
Object.assign(newRequestOptions.headers, { Object.assign(newRequestOptions.headers, {
// @ts-ignore
[oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken, [oAuth2Options.keyToIncludeInAccessTokenHeader]: token.accessToken,
}); });
} }
@ -1126,9 +1138,8 @@ export async function requestOAuth2(
}); });
} }
/* Makes a request using OAuth1 data for authentication /**
* * Makes a request using OAuth1 data for authentication
* @param {(OptionsWithUrl | requestPromise.RequestPromiseOptions)} requestOptions
*/ */
export async function requestOAuth1( export async function requestOAuth1(
this: IAllExecuteFunctions, this: IAllExecuteFunctions,
@ -1169,20 +1180,21 @@ export async function requestOAuth1(
secret: oauthTokenData.oauth_token_secret as string, secret: oauthTokenData.oauth_token_secret as string,
}; };
// @ts-ignore // @ts-expect-error @TECH_DEBT: Remove request library
requestOptions.data = { ...requestOptions.qs, ...requestOptions.form }; requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
// Fixes issue that OAuth1 library only works with "url" property and not with "uri" // Fixes issue that OAuth1 library only works with "url" property and not with "uri"
// @ts-ignore // @ts-expect-error @TECH_DEBT: Remove request library
if (requestOptions.uri && !requestOptions.url) { if (requestOptions.uri && !requestOptions.url) {
// @ts-ignore // @ts-expect-error @TECH_DEBT: Remove request library
requestOptions.url = requestOptions.uri; requestOptions.url = requestOptions.uri;
// @ts-ignore // @ts-expect-error @TECH_DEBT: Remove request library
delete requestOptions.uri; delete requestOptions.uri;
} }
// @ts-ignore requestOptions.headers = oauth.toHeader(
requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token)); oauth.authorize(requestOptions as unknown as clientOAuth1.RequestOptions, token),
);
if (isN8nRequest) { if (isN8nRequest) {
return this.helpers.httpRequest(requestOptions as IHttpRequestOptions); return this.helpers.httpRequest(requestOptions as IHttpRequestOptions);
} }

View file

@ -156,7 +156,6 @@ export class WorkflowExecute {
startNodes: string[], startNodes: string[],
destinationNode: string, destinationNode: string,
pinData?: IPinData, pinData?: IPinData,
// @ts-ignore
): PCancelable<IRun> { ): PCancelable<IRun> {
let incomingNodeConnections: INodeConnections | undefined; let incomingNodeConnections: INodeConnections | undefined;
let connection: IConnection; let connection: IConnection;
@ -783,7 +782,6 @@ export class WorkflowExecute {
gotCancel = true; gotCancel = true;
} }
// @ts-ignore
if (gotCancel) { if (gotCancel) {
return Promise.resolve(); return Promise.resolve();
} }
@ -911,7 +909,6 @@ export class WorkflowExecute {
} }
for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) { for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) {
// @ts-ignore
if (gotCancel) { if (gotCancel) {
return Promise.resolve(); return Promise.resolve();
} }

View file

@ -11,7 +11,6 @@ describe('NodeExecuteFunctions', () => {
describe(`test binary data helper methods`, () => { describe(`test binary data helper methods`, () => {
// Reset BinaryDataManager for each run. This is a dirty operation, as individual managers are not cleaned. // Reset BinaryDataManager for each run. This is a dirty operation, as individual managers are not cleaned.
beforeEach(() => { beforeEach(() => {
//@ts-ignore
BinaryDataManager.instance = undefined; BinaryDataManager.instance = undefined;
}); });

View file

@ -23,5 +23,6 @@ module.exports = {
'@typescript-eslint/prefer-nullish-coalescing': 'off', '@typescript-eslint/prefer-nullish-coalescing': 'off',
'@typescript-eslint/prefer-optional-chain': 'off', '@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
} }
}; };

View file

@ -49,5 +49,6 @@ module.exports = {
'@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/return-await': 'off', '@typescript-eslint/return-await': 'off',
'@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
}, },
}; };

View file

@ -8,5 +8,6 @@ module.exports = {
], ],
rules: { rules: {
'import/order': 'off', // TODO: remove this 'import/order': 'off', // TODO: remove this
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
}, },
}; };

View file

@ -59,6 +59,7 @@ module.exports = {
'@typescript-eslint/restrict-template-expressions': 'off', '@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/return-await': 'off', '@typescript-eslint/return-await': 'off',
'@typescript-eslint/unbound-method': 'off', '@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }],
}, },
overrides: [ overrides: [

View file

@ -157,7 +157,6 @@ export class Expression {
data.Reflect = {}; data.Reflect = {};
data.Proxy = {}; data.Proxy = {};
// @ts-ignore
data.constructor = {}; data.constructor = {};
// Deprecated // Deprecated

View file

@ -1400,6 +1400,7 @@ export interface IWorkflowDataProxyData {
$thisItemIndex: number; $thisItemIndex: number;
$now: any; $now: any;
$today: any; $today: any;
constructor: any;
} }
export type IWorkflowDataProxyAdditionalKeys = IDataObject; export type IWorkflowDataProxyAdditionalKeys = IDataObject;

View file

@ -16,6 +16,7 @@ import {
IN8nRequestOperations, IN8nRequestOperations,
INodeCredentialDescription, INodeCredentialDescription,
IExecuteData, IExecuteData,
INodeTypeDescription,
} from '../src'; } from '../src';
import * as Helpers from './Helpers'; import * as Helpers from './Helpers';
@ -1689,8 +1690,7 @@ describe('RoutingNode', () => {
connections: {}, connections: {},
}; };
// @ts-ignore nodeType.description = { ...testData.input.nodeType } as INodeTypeDescription;
nodeType.description = { ...testData.input.nodeType };
const workflow = new Workflow({ const workflow = new Workflow({
nodes: workflowData.nodes, nodes: workflowData.nodes,
@ -1714,8 +1714,7 @@ describe('RoutingNode', () => {
source: null, source: null,
} as IExecuteData; } as IExecuteData;
// @ts-ignore const nodeExecuteFunctions: Partial<INodeExecuteFunctions> = {
const nodeExecuteFunctions: INodeExecuteFunctions = {
getExecuteFunctions: () => { getExecuteFunctions: () => {
return Helpers.getExecuteFunctions( return Helpers.getExecuteFunctions(
workflow, workflow,
@ -1751,7 +1750,7 @@ describe('RoutingNode', () => {
runIndex, runIndex,
nodeType, nodeType,
executeData, executeData,
nodeExecuteFunctions, nodeExecuteFunctions as INodeExecuteFunctions,
); );
expect(result).toEqual(testData.output); expect(result).toEqual(testData.output);
@ -1763,12 +1762,7 @@ describe('RoutingNode', () => {
const tests: Array<{ const tests: Array<{
description: string; description: string;
input: { input: {
nodeType: { nodeType: Partial<INodeTypeDescription>;
properties?: INodeProperties[];
credentials?: INodeCredentialDescription[];
requestDefaults?: IHttpRequestOptions;
requestOperations?: IN8nRequestOperations;
};
node: { node: {
parameters: INodeParameters; parameters: INodeParameters;
}; };
@ -1868,8 +1862,7 @@ describe('RoutingNode', () => {
connections: {}, connections: {},
}; };
// @ts-ignore nodeType.description = { ...testData.input.nodeType } as INodeTypeDescription;
nodeType.description = { ...testData.input.nodeType };
const workflow = new Workflow({ const workflow = new Workflow({
nodes: workflowData.nodes, nodes: workflowData.nodes,
@ -1895,8 +1888,7 @@ describe('RoutingNode', () => {
let currentItemIndex = 0; let currentItemIndex = 0;
for (let iteration = 0; iteration < inputData.main[0]!.length; iteration++) { for (let iteration = 0; iteration < inputData.main[0]!.length; iteration++) {
// @ts-ignore const nodeExecuteFunctions: Partial<INodeExecuteFunctions> = {
const nodeExecuteFunctions: INodeExecuteFunctions = {
getExecuteFunctions: () => { getExecuteFunctions: () => {
return Helpers.getExecuteFunctions( return Helpers.getExecuteFunctions(
workflow, workflow,
@ -1927,6 +1919,10 @@ describe('RoutingNode', () => {
}, },
}; };
if (!nodeExecuteFunctions.getExecuteSingleFunctions) {
fail('Expected nodeExecuteFunctions to contain getExecuteSingleFunctions');
}
const routingNodeExecutionContext = nodeExecuteFunctions.getExecuteSingleFunctions( const routingNodeExecutionContext = nodeExecuteFunctions.getExecuteSingleFunctions(
routingNode.workflow, routingNode.workflow,
routingNode.runExecutionData, routingNode.runExecutionData,

View file

@ -1,9 +1,12 @@
import { import {
IBinaryKeyData,
IConnections, IConnections,
IDataObject,
INode, INode,
INodeExecutionData, INodeExecutionData,
INodeParameters, INodeParameters,
IRunExecutionData, IRunExecutionData,
NodeParameterValueType,
Workflow, Workflow,
} from '../src'; } from '../src';
@ -696,7 +699,17 @@ describe('Workflow', () => {
}); });
describe('getParameterValue', () => { describe('getParameterValue', () => {
const tests = [ const tests: {
description: string;
input: {
[nodeName: string]: {
parameters: Record<string, NodeParameterValueType>;
outputJson?: IDataObject;
outputBinary?: IBinaryKeyData;
};
};
output: Record<string, unknown>;
}[] = [
{ {
description: 'read simple not expression value', description: 'read simple not expression value',
input: { input: {
@ -881,6 +894,7 @@ describe('Workflow', () => {
binaryKey: { binaryKey: {
data: '', data: '',
type: '', type: '',
mimeType: 'test',
fileName: 'test-file1.jpg', fileName: 'test-file1.jpg',
}, },
}, },
@ -908,6 +922,7 @@ describe('Workflow', () => {
binaryKey: { binaryKey: {
data: '', data: '',
type: '', type: '',
mimeType: 'test',
fileName: 'test-file1.jpg', fileName: 'test-file1.jpg',
}, },
}, },
@ -1134,8 +1149,7 @@ describe('Workflow', () => {
{ {
name: 'Node3', name: 'Node3',
parameters: testData.input.hasOwnProperty('Node3') parameters: testData.input.hasOwnProperty('Node3')
? // @ts-ignore ? testData.input.Node3?.parameters
testData.input.Node3.parameters
: {}, : {},
type: 'test.set', type: 'test.set',
typeVersion: 1, typeVersion: 1,
@ -1145,8 +1159,7 @@ describe('Workflow', () => {
{ {
name: 'Node 4 with spaces', name: 'Node 4 with spaces',
parameters: testData.input.hasOwnProperty('Node4') parameters: testData.input.hasOwnProperty('Node4')
? // @ts-ignore ? testData.input.Node4.parameters
testData.input.Node4.parameters
: {}, : {},
type: 'test.set', type: 'test.set',
typeVersion: 1, typeVersion: 1,
@ -1187,6 +1200,11 @@ describe('Workflow', () => {
runData: { runData: {
Node1: [ Node1: [
{ {
source: [
{
previousNode: 'test',
},
],
startTime: 1, startTime: 1,
executionTime: 1, executionTime: 1,
data: { data: {
@ -1194,7 +1212,6 @@ describe('Workflow', () => {
[ [
{ {
json: testData.input.Node1.outputJson || testData.input.Node1.parameters, json: testData.input.Node1.outputJson || testData.input.Node1.parameters,
// @ts-ignore
binary: testData.input.Node1.outputBinary, binary: testData.input.Node1.outputBinary,
}, },
], ],
@ -1226,7 +1243,6 @@ describe('Workflow', () => {
timezone, timezone,
{}, {},
); );
// @ts-ignore
expect(result).toEqual(testData.output[parameterName]); expect(result).toEqual(testData.output[parameterName]);
} }
}); });
@ -1278,7 +1294,6 @@ describe('Workflow', () => {
// const workflow = new Workflow({ nodes, connections, active: false, nodeTypes }); // const workflow = new Workflow({ nodes, connections, active: false, nodeTypes });
// const activeNodeName = 'Node2'; // const activeNodeName = 'Node2';
// // @ts-ignore
// const parameterValue = nodes.find((node) => node.name === activeNodeName).parameters.name; // const parameterValue = nodes.find((node) => node.name === activeNodeName).parameters.name;
// // const parameterValue = '=[data.propertyName]'; // TODO: Make this dynamic from node-data via "activeNodeName"! // // const parameterValue = '=[data.propertyName]'; // TODO: Make this dynamic from node-data via "activeNodeName"!
// const runData: RunData = { // const runData: RunData = {