fix: Set '@typescript-eslint/return-await' rule to 'always' for node code (no-changelog) (#8363)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Tomi Turtiainen
2024-01-17 17:08:50 +02:00
committed by GitHub
parent 2eb829a6b4
commit 9a1cc56806
369 changed files with 1041 additions and 928 deletions

View File

@@ -209,8 +209,8 @@ export class ActiveWorkflows {
const w = this.activeWorkflows[workflowId];
w.triggerResponses?.forEach(async (r) => this.close(r, workflowId, 'trigger'));
w.pollResponses?.forEach(async (r) => this.close(r, workflowId, 'poller'));
w.triggerResponses?.forEach(async (r) => await this.close(r, workflowId, 'trigger'));
w.pollResponses?.forEach(async (r) => await this.close(r, workflowId, 'poller'));
delete this.activeWorkflows[workflowId];
@@ -221,8 +221,8 @@ export class ActiveWorkflows {
for (const workflowId of Object.keys(this.activeWorkflows)) {
const w = this.activeWorkflows[workflowId];
w.triggerResponses?.forEach(async (r) => this.close(r, workflowId, 'trigger'));
w.pollResponses?.forEach(async (r) => this.close(r, workflowId, 'poller'));
w.triggerResponses?.forEach(async (r) => await this.close(r, workflowId, 'trigger'));
w.pollResponses?.forEach(async (r) => await this.close(r, workflowId, 'poller'));
}
}

View File

@@ -111,20 +111,20 @@ export class BinaryDataService {
}
async toBuffer(bufferOrStream: Buffer | Readable) {
return toBuffer(bufferOrStream);
return await toBuffer(bufferOrStream);
}
async getAsStream(binaryDataId: string, chunkSize?: number) {
const [mode, fileId] = binaryDataId.split(':');
return this.getManager(mode).getAsStream(fileId, chunkSize);
return await this.getManager(mode).getAsStream(fileId, chunkSize);
}
async getAsBuffer(binaryData: IBinaryData) {
if (binaryData.id) {
const [mode, fileId] = binaryData.id.split(':');
return this.getManager(mode).getAsBuffer(fileId);
return await this.getManager(mode).getAsBuffer(fileId);
}
return Buffer.from(binaryData.data, BINARY_ENCODING);
@@ -139,7 +139,7 @@ export class BinaryDataService {
async getMetadata(binaryDataId: string) {
const [mode, fileId] = binaryDataId.split(':');
return this.getManager(mode).getMetadata(fileId);
return await this.getManager(mode).getMetadata(fileId);
}
async deleteMany(ids: BinaryData.IdsForDeletion) {
@@ -159,10 +159,14 @@ export class BinaryDataService {
const returnInputData = (inputData as INodeExecutionData[][]).map(
async (executionDataArray) => {
if (executionDataArray) {
return Promise.all(
return await Promise.all(
executionDataArray.map(async (executionData) => {
if (executionData.binary) {
return this.duplicateBinaryDataInExecData(workflowId, executionId, executionData);
return await this.duplicateBinaryDataInExecData(
workflowId,
executionId,
executionData,
);
}
return executionData;
@@ -174,7 +178,7 @@ export class BinaryDataService {
},
);
return Promise.all(returnInputData);
return await Promise.all(returnInputData);
}
return inputData as INodeExecutionData[][];
@@ -217,13 +221,13 @@ export class BinaryDataService {
const [_mode, fileId] = binaryDataId.split(':');
return manager?.copyByFileId(workflowId, executionId, fileId).then((newFileId) => ({
return await manager?.copyByFileId(workflowId, executionId, fileId).then((newFileId) => ({
newId: this.createBinaryDataId(newFileId),
key,
}));
});
return Promise.all(bdPromises).then((b) => {
return await Promise.all(bdPromises).then((b) => {
return b.reduce((acc, curr) => {
if (acc.binary && curr) {
acc.binary[curr.key].id = curr.newId;

View File

@@ -61,13 +61,13 @@ export class FileSystemManager implements BinaryData.Manager {
throw new FileNotFoundError(filePath);
}
return fs.readFile(filePath);
return await fs.readFile(filePath);
}
async getMetadata(fileId: string): Promise<BinaryData.Metadata> {
const filePath = this.resolvePath(`${fileId}.metadata`);
return jsonParse(await fs.readFile(filePath, { encoding: 'utf-8' }));
return await jsonParse(await fs.readFile(filePath, { encoding: 'utf-8' }));
}
async deleteMany(ids: BinaryData.IdsForDeletion) {

View File

@@ -34,11 +34,11 @@ export class ObjectStoreManager implements BinaryData.Manager {
}
async getAsBuffer(fileId: string) {
return this.objectStoreService.get(fileId, { mode: 'buffer' });
return await this.objectStoreService.get(fileId, { mode: 'buffer' });
}
async getAsStream(fileId: string) {
return this.objectStoreService.get(fileId, { mode: 'stream' });
return await this.objectStoreService.get(fileId, { mode: 'stream' });
}
async getMetadata(fileId: string): Promise<BinaryData.Metadata> {
@@ -102,6 +102,6 @@ export class ObjectStoreManager implements BinaryData.Manager {
}
private async toBuffer(bufferOrStream: Buffer | Readable) {
return toBuffer(bufferOrStream);
return await toBuffer(bufferOrStream);
}
}

View File

@@ -34,7 +34,7 @@ export async function doesNotExist(dir: string) {
export async function toBuffer(body: Buffer | Readable) {
if (Buffer.isBuffer(body)) return body;
return new Promise<Buffer>((resolve, reject) => {
return await new Promise<Buffer>((resolve, reject) => {
body
.once('error', (cause) => {
if ('code' in cause && cause.code === 'Z_DATA_ERROR')

View File

@@ -754,7 +754,7 @@ export async function proxyRequestToAxios(
}
};
} else {
requestFn = async () => axios(axiosConfig);
requestFn = async () => await axios(axiosConfig);
}
try {
@@ -969,14 +969,14 @@ export function getBinaryPath(binaryDataId: string): string {
* Returns binary file metadata
*/
export async function getBinaryMetadata(binaryDataId: string): Promise<BinaryData.Metadata> {
return Container.get(BinaryDataService).getMetadata(binaryDataId);
return await Container.get(BinaryDataService).getMetadata(binaryDataId);
}
/**
* Returns binary file stream for piping
*/
export async function getBinaryStream(binaryDataId: string, chunkSize?: number): Promise<Readable> {
return Container.get(BinaryDataService).getAsStream(binaryDataId, chunkSize);
return await Container.get(BinaryDataService).getAsStream(binaryDataId, chunkSize);
}
export function assertBinaryData(
@@ -1024,7 +1024,7 @@ export async function getBinaryDataBuffer(
inputIndex: number,
): Promise<Buffer> {
const binaryData = inputData.main[inputIndex]![itemIndex]!.binary![propertyName]!;
return Container.get(BinaryDataService).getAsBuffer(binaryData);
return await Container.get(BinaryDataService).getAsBuffer(binaryData);
}
/**
@@ -1041,7 +1041,7 @@ export async function setBinaryDataBuffer(
workflowId: string,
executionId: string,
): Promise<IBinaryData> {
return Container.get(BinaryDataService).store(
return await Container.get(BinaryDataService).store(
workflowId,
executionId,
bufferOrStream,
@@ -1100,7 +1100,7 @@ export async function copyBinaryFile(
returnData.fileName = path.parse(filePath).base;
}
return Container.get(BinaryDataService).copyBinaryFile(
return await Container.get(BinaryDataService).copyBinaryFile(
workflowId,
executionId,
returnData,
@@ -1197,7 +1197,7 @@ async function prepareBinaryData(
}
}
return setBinaryDataBuffer(returnData, binaryData, workflowId, executionId);
return await setBinaryDataBuffer(returnData, binaryData, workflowId, executionId);
}
/**
@@ -1289,7 +1289,7 @@ export async function requestOAuth2(
});
}
if (isN8nRequest) {
return this.helpers.httpRequest(newRequestOptions).catch(async (error: AxiosError) => {
return await this.helpers.httpRequest(newRequestOptions).catch(async (error: AxiosError) => {
if (error.response?.status === 401) {
Logger.debug(
`OAuth2 token for "${credentialsType}" used by node "${node.name}" expired. Should revalidate.`,
@@ -1346,7 +1346,7 @@ export async function requestOAuth2(
});
}
return this.helpers.httpRequest(refreshedRequestOption);
return await this.helpers.httpRequest(refreshedRequestOption);
}
throw error;
});
@@ -1356,7 +1356,7 @@ export async function requestOAuth2(
? 401
: oAuth2Options?.tokenExpiredStatusCode;
return this.helpers
return await this.helpers
.request(newRequestOptions)
.then((response) => {
const requestOptions = newRequestOptions as any;
@@ -1433,7 +1433,7 @@ export async function requestOAuth2(
});
}
return this.helpers.request(newRequestOptions);
return await this.helpers.request(newRequestOptions);
}
// Unknown error so simply throw it
@@ -1506,10 +1506,10 @@ export async function requestOAuth1(
oauth.authorize(requestOptions as unknown as clientOAuth1.RequestOptions, token),
);
if (isN8nRequest) {
return this.helpers.httpRequest(requestOptions as IHttpRequestOptions);
return await this.helpers.httpRequest(requestOptions as IHttpRequestOptions);
}
return this.helpers.request(requestOptions).catch(async (error: IResponseError) => {
return await this.helpers.request(requestOptions).catch(async (error: IResponseError) => {
// Unknown error so simply throw it
throw error;
});
@@ -2984,7 +2984,7 @@ const getRequestHelperFunctions = (
requestOptions,
additionalCredentialOptions,
): Promise<any> {
return httpRequestWithAuthentication.call(
return await httpRequestWithAuthentication.call(
this,
credentialsType,
requestOptions,
@@ -2996,7 +2996,7 @@ const getRequestHelperFunctions = (
},
request: async (uriOrObject, options) =>
proxyRequestToAxios(workflow, additionalData, node, uriOrObject, options),
await proxyRequestToAxios(workflow, additionalData, node, uriOrObject, options),
async requestWithAuthentication(
this,
@@ -3004,7 +3004,7 @@ const getRequestHelperFunctions = (
requestOptions,
additionalCredentialOptions,
): Promise<any> {
return requestWithAuthentication.call(
return await requestWithAuthentication.call(
this,
credentialsType,
requestOptions,
@@ -3020,7 +3020,7 @@ const getRequestHelperFunctions = (
credentialsType: string,
requestOptions: OptionsWithUrl | RequestPromiseOptions,
): Promise<any> {
return requestOAuth1.call(this, credentialsType, requestOptions);
return await requestOAuth1.call(this, credentialsType, requestOptions);
},
async requestOAuth2(
@@ -3029,7 +3029,7 @@ const getRequestHelperFunctions = (
requestOptions: OptionsWithUri | RequestPromiseOptions,
oAuth2Options?: IOAuth2Options,
): Promise<any> {
return requestOAuth2.call(
return await requestOAuth2.call(
this,
credentialsType,
requestOptions,
@@ -3139,7 +3139,7 @@ const getFileSystemHelperFunctions = (node: INode): FileSystemHelperFunctions =>
level: 'warning',
});
}
return fsWriteFile(filePath, content, { encoding: 'binary', flag });
return await fsWriteFile(filePath, content, { encoding: 'binary', flag });
},
});
@@ -3148,7 +3148,7 @@ const getNodeHelperFunctions = (
workflowId: string,
): NodeHelperFunctions => ({
copyBinaryFile: async (filePath, fileName, mimeType) =>
copyBinaryFile(workflowId, executionId!, filePath, fileName, mimeType),
await copyBinaryFile(workflowId, executionId!, filePath, fileName, mimeType),
});
const getBinaryHelperFunctions = (
@@ -3159,11 +3159,11 @@ const getBinaryHelperFunctions = (
getBinaryStream,
getBinaryMetadata,
binaryToBuffer: async (body: Buffer | Readable) =>
Container.get(BinaryDataService).toBuffer(body),
await Container.get(BinaryDataService).toBuffer(body),
prepareBinaryData: async (binaryData, filePath, mimeType) =>
prepareBinaryData(binaryData, executionId!, workflowId, filePath, mimeType),
await prepareBinaryData(binaryData, executionId!, workflowId, filePath, mimeType),
setBinaryDataBuffer: async (data, binaryData) =>
setBinaryDataBuffer(data, binaryData, workflowId, executionId!),
await setBinaryDataBuffer(data, binaryData, workflowId, executionId!),
copyBinaryFile: async () => {
throw new ApplicationError('`copyBinaryFile` has been removed. Please upgrade this node.');
},
@@ -3213,7 +3213,8 @@ export function getExecutePollFunctions(
},
getMode: () => mode,
getActivationMode: () => activation,
getCredentials: async (type) => getCredentials(workflow, node, type, additionalData, mode),
getCredentials: async (type) =>
await getCredentials(workflow, node, type, additionalData, mode),
getNodeParameter: (
parameterName: string,
fallbackValue?: any,
@@ -3275,7 +3276,8 @@ export function getExecuteTriggerFunctions(
},
getMode: () => mode,
getActivationMode: () => activation,
getCredentials: async (type) => getCredentials(workflow, node, type, additionalData, mode),
getCredentials: async (type) =>
await getCredentials(workflow, node, type, additionalData, mode),
getNodeParameter: (
parameterName: string,
fallbackValue?: any,
@@ -3333,7 +3335,7 @@ export function getExecuteFunctions(
...executionCancellationFunctions(abortSignal),
getMode: () => mode,
getCredentials: async (type, itemIndex) =>
getCredentials(
await getCredentials(
workflow,
node,
type,
@@ -3365,19 +3367,20 @@ export function getExecuteFunctions(
workflowInfo: IExecuteWorkflowInfo,
inputData?: INodeExecutionData[],
): Promise<any> {
return additionalData
return await additionalData
.executeWorkflow(workflowInfo, additionalData, {
parentWorkflowId: workflow.id?.toString(),
inputData,
parentWorkflowSettings: workflow.settings,
node,
})
.then(async (result) =>
Container.get(BinaryDataService).duplicateBinaryData(
workflow.id,
additionalData.executionId!,
result,
),
.then(
async (result) =>
await Container.get(BinaryDataService).duplicateBinaryData(
workflow.id,
additionalData.executionId!,
result,
),
);
},
getContext(type: ContextType): IContextObject {
@@ -3390,7 +3393,7 @@ export function getExecuteFunctions(
// TODO: Not implemented yet, and maybe also not needed
inputIndex?: number,
): Promise<unknown> {
return getInputConnectionData.call(
return await getInputConnectionData.call(
this,
workflow,
runExecutionData,
@@ -3482,7 +3485,7 @@ export function getExecuteFunctions(
return dataProxy.getDataProxy();
},
binaryToBuffer: async (body: Buffer | Readable) =>
Container.get(BinaryDataService).toBuffer(body),
await Container.get(BinaryDataService).toBuffer(body),
async putExecutionToWait(waitTill: Date): Promise<void> {
runExecutionData.waitTill = toUtcDate(waitTill, getTimezone(workflow));
if (additionalData.setExecutionStatus) {
@@ -3581,7 +3584,7 @@ export function getExecuteFunctions(
assertBinaryData: (itemIndex, propertyName) =>
assertBinaryData(inputData, node, itemIndex, propertyName, 0),
getBinaryDataBuffer: async (itemIndex, propertyName) =>
getBinaryDataBuffer(inputData, itemIndex, propertyName, 0),
await getBinaryDataBuffer(inputData, itemIndex, propertyName, 0),
returnJsonArray,
normalizeItems,
@@ -3632,7 +3635,7 @@ export function getExecuteSingleFunctions(
return NodeHelpers.getContext(runExecutionData, type, node);
},
getCredentials: async (type) =>
getCredentials(
await getCredentials(
workflow,
node,
type,
@@ -3726,7 +3729,7 @@ export function getExecuteSingleFunctions(
assertBinaryData: (propertyName, inputIndex = 0) =>
assertBinaryData(inputData, node, itemIndex, propertyName, inputIndex),
getBinaryDataBuffer: async (propertyName, inputIndex = 0) =>
getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex),
await getBinaryDataBuffer(inputData, itemIndex, propertyName, inputIndex),
},
};
})(workflow, runExecutionData, connectionInputData, inputData, node, itemIndex);
@@ -3736,7 +3739,7 @@ export function getCredentialTestFunctions(): ICredentialTestFunctions {
return {
helpers: {
request: async (uriOrObject: string | object, options?: object) => {
return proxyRequestToAxios(undefined, undefined, undefined, uriOrObject, options);
return await proxyRequestToAxios(undefined, undefined, undefined, uriOrObject, options);
},
},
};
@@ -3755,7 +3758,7 @@ export function getLoadOptionsFunctions(
return {
...getCommonWorkflowFunctions(workflow, node, additionalData),
getCredentials: async (type) =>
getCredentials(workflow, node, type, additionalData, 'internal'),
await getCredentials(workflow, node, type, additionalData, 'internal'),
getCurrentNodeParameter: (
parameterPath: string,
options?: IGetNodeParameterOptions,
@@ -3832,7 +3835,8 @@ export function getExecuteHookFunctions(
return ((workflow: Workflow, node: INode) => {
return {
...getCommonWorkflowFunctions(workflow, node, additionalData),
getCredentials: async (type) => getCredentials(workflow, node, type, additionalData, mode),
getCredentials: async (type) =>
await getCredentials(workflow, node, type, additionalData, mode),
getMode: () => mode,
getActivationMode: () => activation,
getNodeParameter: (
@@ -3904,7 +3908,8 @@ export function getExecuteWebhookFunctions(
}
return additionalData.httpRequest.body;
},
getCredentials: async (type) => getCredentials(workflow, node, type, additionalData, mode),
getCredentials: async (type) =>
await getCredentials(workflow, node, type, additionalData, mode),
getHeaderData(): IncomingHttpHeaders {
if (additionalData.httpRequest === undefined) {
throw new ApplicationError('Request is missing');
@@ -3937,7 +3942,7 @@ export function getExecuteWebhookFunctions(
};
const runIndex = 0;
return getInputConnectionData.call(
return await getInputConnectionData.call(
this,
workflow,
runExecutionData,

View File

@@ -65,7 +65,7 @@ export class ObjectStoreService {
async checkConnection() {
if (this.isReady) return;
return this.request('HEAD', this.host, this.bucket.name);
return await this.request('HEAD', this.host, this.bucket.name);
}
/**
@@ -74,7 +74,7 @@ export class ObjectStoreService {
* @doc https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html
*/
async put(filename: string, buffer: Buffer, metadata: BinaryData.PreWriteMetadata = {}) {
if (this.isReadOnly) return this.blockWrite(filename);
if (this.isReadOnly) return await this.blockWrite(filename);
const headers: Record<string, string | number> = {
'Content-Length': buffer.length,
@@ -86,7 +86,7 @@ export class ObjectStoreService {
const path = `/${this.bucket.name}/${filename}`;
return this.request('PUT', this.host, path, { headers, body: buffer });
return await this.request('PUT', this.host, path, { headers, body: buffer });
}
/**
@@ -131,7 +131,7 @@ export class ObjectStoreService {
async deleteOne(fileId: string) {
const path = `${this.bucket.name}/${fileId}`;
return this.request('DELETE', this.host, path);
return await this.request('DELETE', this.host, path);
}
/**
@@ -156,7 +156,7 @@ export class ObjectStoreService {
const path = `${this.bucket.name}/?delete`;
return this.request('POST', this.host, path, { headers, body });
return await this.request('POST', this.host, path, { headers, body });
}
/**

View File

@@ -7,12 +7,12 @@ export function isStream(maybeStream: unknown): maybeStream is Stream {
}
export async function parseXml<T>(xml: string): Promise<T> {
return parseStringPromise(xml, {
return await (parseStringPromise(xml, {
explicitArray: false,
ignoreAttrs: true,
tagNameProcessors: [firstCharLowerCase],
valueProcessors: [parseNumbers, parseBooleans],
}) as Promise<T>;
}) as Promise<T>);
}
export function writeBlockedMessage(filename: string) {

View File

@@ -308,7 +308,7 @@ export class WorkflowExecute {
return;
}
return this.additionalData.hooks.executeHookFunctions(hookName, parameters);
return await this.additionalData.hooks.executeHookFunctions(hookName, parameters);
}
moveNodeMetadata(): void {
@@ -1657,14 +1657,19 @@ export class WorkflowExecute {
})()
.then(async () => {
if (this.status === 'canceled' && executionError === undefined) {
return this.processSuccessExecution(
return await this.processSuccessExecution(
startedAt,
workflow,
new WorkflowOperationError('Workflow has been canceled or timed out!'),
closeFunction,
);
}
return this.processSuccessExecution(startedAt, workflow, executionError, closeFunction);
return await this.processSuccessExecution(
startedAt,
workflow,
executionError,
closeFunction,
);
})
.catch(async (error) => {
const fullRunData = this.getFullRunData(startedAt);
@@ -1708,7 +1713,7 @@ export class WorkflowExecute {
return fullRunData;
});
return returnPromise.then(resolve);
return await returnPromise.then(resolve);
});
}