Skip to content

Commit

Permalink
fix: Set '@typescript-eslint/return-await' rule to 'always' for node …
Browse files Browse the repository at this point in the history
…code (no-changelog) (#8363)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <[email protected]>
  • Loading branch information
tomi and netroy authored Jan 17, 2024
1 parent 2eb829a commit 9a1cc56
Show file tree
Hide file tree
Showing 369 changed files with 1,041 additions and 928 deletions.
10 changes: 5 additions & 5 deletions packages/@n8n/nodes-langchain/nodes/agents/Agent/Agent.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ export class Agent implements INodeType {
const agentType = this.getNodeParameter('agent', 0, '') as string;

if (agentType === 'conversationalAgent') {
return conversationalAgentExecute.call(this);
return await conversationalAgentExecute.call(this);
} else if (agentType === 'openAiFunctionsAgent') {
return openAiFunctionsAgentExecute.call(this);
return await openAiFunctionsAgentExecute.call(this);
} else if (agentType === 'reActAgent') {
return reActAgentAgentExecute.call(this);
return await reActAgentAgentExecute.call(this);
} else if (agentType === 'sqlAgent') {
return sqlAgentAgentExecute.call(this);
return await sqlAgentAgentExecute.call(this);
} else if (agentType === 'planAndExecuteAgent') {
return planAndExecuteAgentExecute.call(this);
return await planAndExecuteAgentExecute.call(this);
}

throw new NodeOperationError(this.getNode(), `The agent type "${agentType}" is not supported`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ export async function conversationalAgentExecute(
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ export async function openAiFunctionsAgentExecute(
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ export async function planAndExecuteAgentExecute(
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ export async function reActAgentAgentExecute(
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ export async function sqlAgentAgentExecute(
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,6 @@ export class OpenAiAssistant implements INodeType {
returnData.push({ json: response });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function getChain(

// If there are no output parsers, create a simple LLM chain and execute the query
if (!outputParsers.length) {
return createSimpleLLMChain(context, llm, query, chatTemplate);
return await createSimpleLLMChain(context, llm, query, chatTemplate);
}

// If there's only one output parser, use it; otherwise, create a combined output parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ export class ChainRetrievalQa implements INodeType {
const response = await chain.call({ query });
returnData.push({ json: { response } });
}
return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ export class ChainSummarizationV1 implements INodeType {
returnData.push({ json: { response } });
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,6 @@ export class ChainSummarizationV2 implements INodeType {
}
}

return this.prepareOutputData(returnData);
return await this.prepareOutputData(returnData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MemoryChatRetriever implements INodeType {
const messages = await memory?.chatHistory.getMessages();

if (simplifyOutput && messages) {
return this.prepareOutputData(simplifyMessages(messages));
return await this.prepareOutputData(simplifyMessages(messages));
}

const serializedMessages =
Expand All @@ -107,6 +107,6 @@ export class MemoryChatRetriever implements INodeType {
return { json: serializedMessage as unknown as IDataObject };
}) ?? [];

return this.prepareOutputData(serializedMessages);
return await this.prepareOutputData(serializedMessages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,6 @@ export class MemoryManager implements INodeType {
result.push(...executionData);
}

return this.prepareOutputData(result);
return await this.prepareOutputData(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class ToolCode implements INodeType {

const runFunction = async (query: string): Promise<string> => {
const sandbox = getSandbox(query, itemIndex);
return sandbox.runCode() as Promise<string>;
return await (sandbox.runCode() as Promise<string>);
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const VectorStoreInMemory = createVectorStoreNode({
const memoryKey = context.getNodeParameter('memoryKey', itemIndex) as string;
const vectorStoreSingleton = MemoryVectorStoreManager.getInstance(embeddings);

return vectorStoreSingleton.getVectorStore(`${workflowId}__${memoryKey}`);
return await vectorStoreSingleton.getVectorStore(`${workflowId}__${memoryKey}`);
},
async populateVectorStore(context, embeddings, documents, itemIndex) {
const memoryKey = context.getNodeParameter('memoryKey', itemIndex) as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ export class VectorStoreInMemoryInsert implements INodeType {
clearStore,
);

return this.prepareOutputData(serializedDocuments);
return await this.prepareOutputData(serializedDocuments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const VectorStorePinecone = createVectorStoreNode({
filter,
};

return PineconeStore.fromExistingIndex(embeddings, config);
return await PineconeStore.fromExistingIndex(embeddings, config);
},
async populateVectorStore(context, embeddings, documents, itemIndex) {
const index = context.getNodeParameter('pineconeIndex', itemIndex, '', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ export class VectorStorePineconeInsert implements INodeType {
pineconeIndex,
});

return this.prepareOutputData(serializedDocuments);
return await this.prepareOutputData(serializedDocuments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const VectorStoreQdrant = createVectorStoreNode({
collectionName: collection,
};

return QdrantVectorStore.fromExistingCollection(embeddings, config);
return await QdrantVectorStore.fromExistingCollection(embeddings, config);
},
async populateVectorStore(context, embeddings, documents, itemIndex) {
const collectionName = context.getNodeParameter('qdrantCollection', itemIndex, '', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const VectorStoreSupabase = createVectorStoreNode({
const credentials = await context.getCredentials('supabaseApi');
const client = createClient(credentials.host as string, credentials.serviceRole as string);

return SupabaseVectorStore.fromExistingIndex(embeddings, {
return await SupabaseVectorStore.fromExistingIndex(embeddings, {
client,
tableName,
queryName: options.queryName ?? 'match_documents',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ export class VectorStoreSupabaseInsert implements INodeType {
queryName,
});

return this.prepareOutputData(serializedDocuments);
return await this.prepareOutputData(serializedDocuments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ export class VectorStoreZepInsert implements INodeType {

await ZepVectorStore.fromDocuments(processedDocuments, embeddings, zepConfig);

return this.prepareOutputData(serializedDocuments);
return await this.prepareOutputData(serializedDocuments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
resultData.push(...serializedDocs);
}

return this.prepareOutputData(resultData);
return await this.prepareOutputData(resultData);
}

if (mode === 'insert') {
Expand Down Expand Up @@ -267,7 +267,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
}
}

return this.prepareOutputData(resultData);
return await this.prepareOutputData(resultData);
}

throw new NodeOperationError(
Expand Down
7 changes: 7 additions & 0 deletions packages/@n8n_io/eslint-config/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ module.exports = {
es6: true,
node: true,
},

rules: {
/**
* https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/return-await.md
*/
'@typescript-eslint/return-await': ['error', 'always'],
},
};
2 changes: 1 addition & 1 deletion packages/cli/src/AbstractServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export abstract class AbstractServer {
// TODO UM: check if this needs validation with user management.
this.app.delete(
`/${this.restEndpoint}/test-webhook/:id`,
send(async (req) => testWebhooks.cancelWebhook(req.params.id)),
send(async (req) => await testWebhooks.cancelWebhook(req.params.id)),
);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/ActiveExecutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class ActiveExecutions {
this.activeExecutions[executionId].workflowExecution!.cancel();
}

return this.getPostExecutePromise(executionId);
return await this.getPostExecutePromise(executionId);
}

/**
Expand All @@ -197,7 +197,7 @@ export class ActiveExecutions {

this.activeExecutions[executionId].postExecutePromises.push(waitPromise);

return waitPromise.promise();
return await waitPromise.promise();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/ActiveWebhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ActiveWebhooks implements IWebhookManager {
) {}

async getWebhookMethods(path: string) {
return this.webhookService.getWebhookMethods(path);
return await this.webhookService.getWebhookMethods(path);
}

async findAccessControlOptions(path: string, httpMethod: IHttpRequestMethods) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export class ActiveWebhooks implements IWebhookManager {
throw new NotFoundError('Could not find node to process webhook.');
}

return new Promise((resolve, reject) => {
return await new Promise((resolve, reject) => {
const executionMode = 'webhook';
void WebhookHelpers.executeWebhook(
workflow,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ActiveWorkflowRunner {
}

async getAllWorkflowActivationErrors() {
return this.activationErrorsService.getAll();
return await this.activationErrorsService.getAll();
}

/**
Expand Down Expand Up @@ -305,7 +305,7 @@ export class ActiveWorkflowRunner {
};

const workflowRunner = new WorkflowRunner();
return workflowRunner.run(runData, true, undefined, undefined, responsePromise);
return await workflowRunner.run(runData, true, undefined, undefined, responsePromise);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ export class CredentialsHelper extends ICredentialsHelper {
if (typeof credentialType.authenticate === 'function') {
// Special authentication function is defined

return credentialType.authenticate(credentials, requestOptions as IHttpRequestOptions);
return await credentialType.authenticate(
credentials,
requestOptions as IHttpRequestOptions,
);
}

if (typeof credentialType.authenticate === 'object') {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (!inTest) {
}

export async function transaction<T>(fn: (entityManager: EntityManager) => Promise<T>): Promise<T> {
return connection.transaction(fn);
return await connection.transaction(fn);
}

export function getConnectionOptions(dbType: DatabaseType): ConnectionOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ExternalSecretsController {
@Get('/providers')
@RequireGlobalScope('externalSecretsProvider:list')
async getProviders() {
return this.secretsService.getProviders();
return await this.secretsService.getProviders();
}

@Get('/providers/:provider')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ExternalSecretsService {
}
const { settings } = providerAndSettings;
const newData = this.unredact(data, settings.settings);
return Container.get(ExternalSecretsManager).testProviderSettings(providerName, newData);
return await Container.get(ExternalSecretsManager).testProviderSettings(providerName, newData);
}

async updateProvider(providerName: string) {
Expand All @@ -143,6 +143,6 @@ export class ExternalSecretsService {
if (!providerAndSettings) {
throw new ExternalSecretsProviderNotFoundError(providerName);
}
return Container.get(ExternalSecretsManager).updateProvider(providerName);
return await Container.get(ExternalSecretsManager).updateProvider(providerName);
}
}
11 changes: 7 additions & 4 deletions packages/cli/src/ExternalSecrets/ExternalSecretsManager.ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ export class ExternalSecretsManager {
this.initialized = true;
resolve();
this.initializingPromise = undefined;
this.updateInterval = setInterval(async () => this.updateSecrets(), updateIntervalTime());
this.updateInterval = setInterval(
async () => await this.updateSecrets(),
updateIntervalTime(),
);
});
}
return this.initializingPromise;
return await this.initializingPromise;
}
}

Expand Down Expand Up @@ -107,8 +110,8 @@ export class ExternalSecretsManager {
}
const providers: Array<SecretsProvider | null> = (
await Promise.allSettled(
Object.entries(settings).map(async ([name, providerSettings]) =>
this.initProvider(name, providerSettings),
Object.entries(settings).map(
async ([name, providerSettings]) => await this.initProvider(name, providerSettings),
),
)
).map((i) => (i.status === 'rejected' ? null : i.value));
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/ExternalSecrets/providers/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class VaultProvider extends SecretsProvider {
await Promise.allSettled(
listResp.data.data.keys.map(async (key): Promise<[string, IDataObject] | null> => {
if (key.endsWith('/')) {
return this.getKVSecrets(mountPath, kvVersion, path + key);
return await this.getKVSecrets(mountPath, kvVersion, path + key);
}
let secretPath = mountPath;
if (kvVersion === '2') {
Expand Down
Loading

0 comments on commit 9a1cc56

Please sign in to comment.