From 308a94311fe6e20617dde62e9ac87e9e547c7c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Mon, 24 Apr 2023 11:17:08 +0000 Subject: [PATCH] refactor: Async functions don't need to explicitly return promises (no-changelog) (#6041) --- packages/cli/src/CredentialsHelper.ts | 4 +- packages/cli/src/InternalHooks.ts | 6 +- packages/cli/src/Ldap/LdapService.ee.ts | 2 +- packages/cli/src/posthog/index.ts | 2 +- packages/cli/src/sso/saml/saml.service.ee.ts | 3 +- packages/cli/src/telemetry/index.ts | 2 +- .../test/integration/ldap/ldap.api.test.ts | 28 ++---- packages/cli/test/integration/shared/utils.ts | 4 +- .../cli/test/unit/ActiveExecutions.test.ts | 2 +- .../test/unit/ActiveWorkflowRunner.test.ts | 9 +- .../WorkflowExecuteAdditionalData.test.ts | 2 +- .../core/src/BinaryDataManager/FileSystem.ts | 98 +++++++++---------- packages/core/src/BinaryDataManager/index.ts | 20 ++-- packages/core/src/WorkflowExecute.ts | 12 +-- .../src/components/ExecutionsList.vue | 15 ++- .../layouts/ResourcesListLayout.vue | 2 +- .../editor-ui/src/mixins/workflowHelpers.ts | 12 +-- packages/editor-ui/src/plugins/i18n/index.ts | 8 +- packages/editor-ui/src/stores/settings.ts | 30 +++--- packages/editor-ui/src/views/NodeView.vue | 21 ++-- packages/nodes-base/nodes/Code/Code.node.ts | 4 +- .../nodes/Function/Function.node.ts | 2 +- .../nodes/FunctionItem/FunctionItem.node.ts | 4 +- .../nodes/Google/Ads/CampaignDescription.ts | 18 ++-- .../test/v2/node/executeQuery.test.ts | 9 +- .../test/v2/node/insert.autoMapMode.test.ts | 9 +- .../test/v2/node/insert.manualMode.test.ts | 11 +-- .../nodes/MySql/test/v2/operations.test.ts | 6 +- .../nodes/MySql/test/v2/runQueries.test.ts | 4 +- .../nodes/Postgres/test/v2/operations.test.ts | 2 +- packages/workflow/src/Workflow.ts | 8 +- 31 files changed, 149 insertions(+), 210 deletions(-) diff --git a/packages/cli/src/CredentialsHelper.ts b/packages/cli/src/CredentialsHelper.ts index 2851638360576..cfc86bfd263af 100644 --- a/packages/cli/src/CredentialsHelper.ts +++ b/packages/cli/src/CredentialsHelper.ts @@ -542,10 +542,10 @@ export class CredentialsHelper extends ICredentialsHelper { ): Promise { const credentialTestFunction = this.getCredentialTestFunction(credentialType); if (credentialTestFunction === undefined) { - return Promise.resolve({ + return { status: 'Error', message: 'No testing function found for this credential.', - }); + }; } if (credentialsDecrypted.data) { diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index 6a1ab61b64715..965f84642b6fa 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -271,12 +271,12 @@ export class InternalHooks implements IInternalHooksClass { runData?: IRun, userId?: string, ): Promise { - const promises = [Promise.resolve()]; - if (!workflow.id) { - return Promise.resolve(); + return; } + const promises = []; + const properties: IExecutionTrackProperties = { workflow_id: workflow.id, is_manual: false, diff --git a/packages/cli/src/Ldap/LdapService.ee.ts b/packages/cli/src/Ldap/LdapService.ee.ts index bc5432cbea6ef..63394a4145fe4 100644 --- a/packages/cli/src/Ldap/LdapService.ee.ts +++ b/packages/cli/src/Ldap/LdapService.ee.ts @@ -82,7 +82,7 @@ export class LdapService { await this.client.unbind(); return searchEntries; } - return Promise.resolve([]); + return []; } /** diff --git a/packages/cli/src/posthog/index.ts b/packages/cli/src/posthog/index.ts index e513e366366cf..df390c53b39a8 100644 --- a/packages/cli/src/posthog/index.ts +++ b/packages/cli/src/posthog/index.ts @@ -44,7 +44,7 @@ export class PostHogClient { } async getFeatureFlags(user: Pick): Promise { - if (!this.postHog) return Promise.resolve({}); + if (!this.postHog) return {}; const fullId = [this.instanceId, user.id].join('#'); diff --git a/packages/cli/src/sso/saml/saml.service.ee.ts b/packages/cli/src/sso/saml/saml.service.ee.ts index b1a764c724094..b16d14600e1d8 100644 --- a/packages/cli/src/sso/saml/saml.service.ee.ts +++ b/packages/cli/src/sso/saml/saml.service.ee.ts @@ -73,9 +73,8 @@ export class SamlService { validate: async (response: string) => { const valid = await validateResponse(response); if (!valid) { - return Promise.reject(new Error('Invalid SAML response')); + throw new Error('Invalid SAML response'); } - return Promise.resolve(); }, }); } diff --git a/packages/cli/src/telemetry/index.ts b/packages/cli/src/telemetry/index.ts index cdc7b96f8be74..7edb6f6172f41 100644 --- a/packages/cli/src/telemetry/index.ts +++ b/packages/cli/src/telemetry/index.ts @@ -76,7 +76,7 @@ export class Telemetry { private async pulse(): Promise { if (!this.rudderStack) { - return Promise.resolve(); + return; } const allPromises = Object.keys(this.executionCountsBuffer).map(async (workflowId) => { diff --git a/packages/cli/test/integration/ldap/ldap.api.test.ts b/packages/cli/test/integration/ldap/ldap.api.test.ts index 2bb766be937b9..eaffa15494f23 100644 --- a/packages/cli/test/integration/ldap/ldap.api.test.ts +++ b/packages/cli/test/integration/ldap/ldap.api.test.ts @@ -205,9 +205,7 @@ test('GET /ldap/config route should retrieve current configuration', async () => describe('POST /ldap/test-connection', () => { test('route should success', async () => { - jest - .spyOn(LdapService.prototype, 'testConnection') - .mockImplementation(async () => Promise.resolve()); + jest.spyOn(LdapService.prototype, 'testConnection').mockResolvedValue(); const response = await authAgent(owner).post('/ldap/test-connection'); expect(response.statusCode).toBe(200); @@ -216,9 +214,7 @@ describe('POST /ldap/test-connection', () => { test('route should fail', async () => { const errorMessage = 'Invalid connection'; - jest - .spyOn(LdapService.prototype, 'testConnection') - .mockImplementation(async () => Promise.reject(new Error(errorMessage))); + jest.spyOn(LdapService.prototype, 'testConnection').mockRejectedValue(new Error(errorMessage)); const response = await authAgent(owner).post('/ldap/test-connection'); expect(response.statusCode).toBe(400); @@ -240,9 +236,7 @@ describe('POST /ldap/sync', () => { describe('dry mode', () => { const runTest = async (ldapUsers: LdapUser[]) => { - jest - .spyOn(LdapService.prototype, 'searchWithAdminBinding') - .mockImplementation(async () => Promise.resolve(ldapUsers)); + jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers); const response = await authAgent(owner).post('/ldap/sync').send({ type: 'dry' }); @@ -337,9 +331,7 @@ describe('POST /ldap/sync', () => { describe('live mode', () => { const runTest = async (ldapUsers: LdapUser[]) => { - jest - .spyOn(LdapService.prototype, 'searchWithAdminBinding') - .mockImplementation(async () => Promise.resolve(ldapUsers)); + jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue(ldapUsers); const response = await authAgent(owner).post('/ldap/sync').send({ type: 'live' }); @@ -467,9 +459,7 @@ describe('POST /ldap/sync', () => { test('should remove user instance access once the user is disabled during synchronization', async () => { const member = await testDb.createLdapUser({ globalRole: globalMemberRole }, uniqueId()); - jest - .spyOn(LdapService.prototype, 'searchWithAdminBinding') - .mockImplementation(async () => Promise.resolve([])); + jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([]); await authAgent(owner).post('/ldap/sync').send({ type: 'live' }); @@ -508,13 +498,9 @@ describe('POST /login', () => { const authlessAgent = utils.createAgent(app); - jest - .spyOn(LdapService.prototype, 'searchWithAdminBinding') - .mockImplementation(async () => Promise.resolve([ldapUser])); + jest.spyOn(LdapService.prototype, 'searchWithAdminBinding').mockResolvedValue([ldapUser]); - jest - .spyOn(LdapService.prototype, 'validUser') - .mockImplementation(async () => Promise.resolve()); + jest.spyOn(LdapService.prototype, 'validUser').mockResolvedValue(); const response = await authlessAgent .post('/login') diff --git a/packages/cli/test/integration/shared/utils.ts b/packages/cli/test/integration/shared/utils.ts index 3625caf661a84..9e8e4aa2b1ab8 100644 --- a/packages/cli/test/integration/shared/utils.ts +++ b/packages/cli/test/integration/shared/utils.ts @@ -799,11 +799,11 @@ export function installedNodePayload(packageName: string): InstalledNodePayload }; } -export const emptyPackage = () => { +export const emptyPackage = async () => { const installedPackage = new InstalledPackages(); installedPackage.installedNodes = []; - return Promise.resolve(installedPackage); + return installedPackage; }; // ---------------------------------- diff --git a/packages/cli/test/unit/ActiveExecutions.test.ts b/packages/cli/test/unit/ActiveExecutions.test.ts index 19c1d316e6a5b..3f27677052db8 100644 --- a/packages/cli/test/unit/ActiveExecutions.test.ts +++ b/packages/cli/test/unit/ActiveExecutions.test.ts @@ -18,7 +18,7 @@ jest.mock('@/Db', () => { return { collections: { Execution: { - save: jest.fn(async () => Promise.resolve({ id: FAKE_EXECUTION_ID })), + save: jest.fn(async () => ({ id: FAKE_EXECUTION_ID })), update: jest.fn(), }, }, diff --git a/packages/cli/test/unit/ActiveWorkflowRunner.test.ts b/packages/cli/test/unit/ActiveWorkflowRunner.test.ts index efe6fe22960c8..ab1232cde6e62 100644 --- a/packages/cli/test/unit/ActiveWorkflowRunner.test.ts +++ b/packages/cli/test/unit/ActiveWorkflowRunner.test.ts @@ -99,12 +99,11 @@ jest.mock('@/Db', () => { return { collections: { Workflow: { - find: jest.fn(async () => Promise.resolve(generateWorkflows(databaseActiveWorkflowsCount))), + find: jest.fn(async () => generateWorkflows(databaseActiveWorkflowsCount)), findOne: jest.fn(async (searchParams) => { - const foundWorkflow = databaseActiveWorkflowsList.find( + return databaseActiveWorkflowsList.find( (workflow) => workflow.id.toString() === searchParams.where.id.toString(), ); - return Promise.resolve(foundWorkflow); }), update: jest.fn(), createQueryBuilder: jest.fn(() => { @@ -112,7 +111,7 @@ jest.mock('@/Db', () => { update: () => fakeQueryBuilder, set: () => fakeQueryBuilder, where: () => fakeQueryBuilder, - execute: () => Promise.resolve(), + execute: async () => {}, }; return fakeQueryBuilder; }), @@ -246,7 +245,7 @@ describe('ActiveWorkflowRunner', () => { const workflow = generateWorkflows(1); const additionalData = await WorkflowExecuteAdditionalData.getBase('fake-user-id'); - workflowRunnerRun.mockImplementationOnce(() => Promise.resolve('invalid-execution-id')); + workflowRunnerRun.mockResolvedValueOnce('invalid-execution-id'); await activeWorkflowRunner.runWorkflow( workflow[0], diff --git a/packages/cli/test/unit/WorkflowExecuteAdditionalData.test.ts b/packages/cli/test/unit/WorkflowExecuteAdditionalData.test.ts index 9d364bd788939..6007c0dd74b81 100644 --- a/packages/cli/test/unit/WorkflowExecuteAdditionalData.test.ts +++ b/packages/cli/test/unit/WorkflowExecuteAdditionalData.test.ts @@ -6,7 +6,7 @@ jest.mock('@/Db', () => { return { collections: { ExecutionMetadata: { - save: jest.fn(async () => Promise.resolve([])), + save: jest.fn(async () => []), }, }, }; diff --git a/packages/core/src/BinaryDataManager/FileSystem.ts b/packages/core/src/BinaryDataManager/FileSystem.ts index df033569752f1..011a5cd5eedae 100644 --- a/packages/core/src/BinaryDataManager/FileSystem.ts +++ b/packages/core/src/BinaryDataManager/FileSystem.ts @@ -134,63 +134,58 @@ export class BinaryDataFileSystem implements IBinaryDataManager { const execsAdded: { [key: string]: number } = {}; - const proms = metaFileNames.reduce( - (prev, curr) => { - const [prefix, executionId, ts] = curr.split('_'); + const promises = metaFileNames.reduce>>((prev, curr) => { + const [prefix, executionId, ts] = curr.split('_'); - if (prefix !== filePrefix) { + if (prefix !== filePrefix) { + return prev; + } + + const execTimestamp = parseInt(ts, 10); + + if (execTimestamp < currentTimeValue) { + if (execsAdded[executionId]) { + // do not delete data, only meta file + prev.push(this.deleteMetaFileByPath(path.join(metaPath, curr))); return prev; } - const execTimestamp = parseInt(ts, 10); - - if (execTimestamp < currentTimeValue) { - if (execsAdded[executionId]) { - // do not delete data, only meta file - prev.push(this.deleteMetaFileByPath(path.join(metaPath, curr))); - return prev; - } - - execsAdded[executionId] = 1; - prev.push( - this.deleteBinaryDataByExecutionId(executionId).then(async () => - this.deleteMetaFileByPath(path.join(metaPath, curr)), - ), - ); - } + execsAdded[executionId] = 1; + prev.push( + this.deleteBinaryDataByExecutionId(executionId).then(async () => + this.deleteMetaFileByPath(path.join(metaPath, curr)), + ), + ); + } - return prev; - }, - [Promise.resolve()], - ); + return prev; + }, []); - return Promise.all(proms).then(() => {}); + await Promise.all(promises); } async duplicateBinaryDataByIdentifier(binaryDataId: string, prefix: string): Promise { const newBinaryDataId = this.generateFileName(prefix); - return fs - .copyFile(this.resolveStoragePath(binaryDataId), this.resolveStoragePath(newBinaryDataId)) - .then(() => newBinaryDataId); + await fs.copyFile( + this.resolveStoragePath(binaryDataId), + this.resolveStoragePath(newBinaryDataId), + ); + return newBinaryDataId; } async deleteBinaryDataByExecutionId(executionId: string): Promise { const regex = new RegExp(`${executionId}_*`); const filenames = await fs.readdir(this.storagePath); - const proms = filenames.reduce( - (allProms, filename) => { - if (regex.test(filename)) { - allProms.push(fs.rm(this.resolveStoragePath(filename))); - } - - return allProms; - }, - [Promise.resolve()], - ); + const promises = filenames.reduce>>((allProms, filename) => { + if (regex.test(filename)) { + allProms.push(fs.rm(this.resolveStoragePath(filename))); + } + return allProms; + }, []); - return Promise.all(proms).then(async () => Promise.resolve()); + await Promise.all(promises); } async deleteBinaryDataByIdentifier(identifier: string): Promise { @@ -198,20 +193,17 @@ export class BinaryDataFileSystem implements IBinaryDataManager { } async persistBinaryDataForExecutionId(executionId: string): Promise { - return fs.readdir(this.getBinaryDataPersistMetaPath()).then(async (metafiles) => { - const proms = metafiles.reduce( - (prev, curr) => { - if (curr.startsWith(`${PREFIX_PERSISTED_METAFILE}_${executionId}_`)) { - prev.push(fs.rm(path.join(this.getBinaryDataPersistMetaPath(), curr))); - return prev; - } - + return fs.readdir(this.getBinaryDataPersistMetaPath()).then(async (metaFiles) => { + const promises = metaFiles.reduce>>((prev, curr) => { + if (curr.startsWith(`${PREFIX_PERSISTED_METAFILE}_${executionId}_`)) { + prev.push(fs.rm(path.join(this.getBinaryDataPersistMetaPath(), curr))); return prev; - }, - [Promise.resolve()], - ); + } + + return prev; + }, []); - return Promise.all(proms).then(() => {}); + await Promise.all(promises); }); } @@ -227,8 +219,8 @@ export class BinaryDataFileSystem implements IBinaryDataManager { return path.join(this.storagePath, 'persistMeta'); } - private async deleteMetaFileByPath(metafilePath: string): Promise { - return fs.rm(metafilePath); + private async deleteMetaFileByPath(metaFilePath: string): Promise { + return fs.rm(metaFilePath); } private async deleteFromLocalStorage(identifier: string) { diff --git a/packages/core/src/BinaryDataManager/index.ts b/packages/core/src/BinaryDataManager/index.ts index b3ddb8738d6c6..d1c85f5b797ed 100644 --- a/packages/core/src/BinaryDataManager/index.ts +++ b/packages/core/src/BinaryDataManager/index.ts @@ -158,38 +158,30 @@ export class BinaryDataManager { async markDataForDeletionByExecutionId(executionId: string): Promise { if (this.managers[this.binaryDataMode]) { - return this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId); + await this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(executionId); } - - return Promise.resolve(); } async markDataForDeletionByExecutionIds(executionIds: string[]): Promise { if (this.managers[this.binaryDataMode]) { - return Promise.all( + await Promise.all( executionIds.map(async (id) => this.managers[this.binaryDataMode].markDataForDeletionByExecutionId(id), ), - ).then(() => {}); + ); } - - return Promise.resolve(); } async persistBinaryDataForExecutionId(executionId: string): Promise { if (this.managers[this.binaryDataMode]) { - return this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId); + await this.managers[this.binaryDataMode].persistBinaryDataForExecutionId(executionId); } - - return Promise.resolve(); } async deleteBinaryDataByExecutionId(executionId: string): Promise { if (this.managers[this.binaryDataMode]) { - return this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId); + await this.managers[this.binaryDataMode].deleteBinaryDataByExecutionId(executionId); } - - return Promise.resolve(); } async duplicateBinaryData( @@ -218,7 +210,7 @@ export class BinaryDataManager { return Promise.all(returnInputData); } - return Promise.resolve(inputData as INodeExecutionData[][]); + return inputData as INodeExecutionData[][]; } private generateBinaryId(filename: string) { diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 480a2b2f80e0c..00e7a3f84f01c 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -792,7 +792,7 @@ export class WorkflowExecute { } if (gotCancel) { - return Promise.resolve(); + return; } nodeSuccessData = null; @@ -919,7 +919,7 @@ export class WorkflowExecute { for (let tryIndex = 0; tryIndex < maxTries; tryIndex++) { if (gotCancel) { - return Promise.resolve(); + return; } try { if (tryIndex !== 0) { @@ -1175,10 +1175,8 @@ export class WorkflowExecute { outputIndex ]) { if (!workflow.nodes.hasOwnProperty(connectionData.node)) { - return Promise.reject( - new Error( - `The node "${executionNode.name}" connects to not found node "${connectionData.node}"`, - ), + throw new Error( + `The node "${executionNode.name}" connects to not found node "${connectionData.node}"`, ); } @@ -1212,7 +1210,7 @@ export class WorkflowExecute { ]); } - return Promise.resolve(); + return; })() .then(async () => { if (gotCancel && executionError === undefined) { diff --git a/packages/editor-ui/src/components/ExecutionsList.vue b/packages/editor-ui/src/components/ExecutionsList.vue index b5db196fb6b3f..a26d349a40cb8 100644 --- a/packages/editor-ui/src/components/ExecutionsList.vue +++ b/packages/editor-ui/src/components/ExecutionsList.vue @@ -527,15 +527,12 @@ export default mixins(externalHooks, genericHelpers, executionHelpers, showMessa // Suppose 504 finishes before 500, 501, 502 and 503. // iF you use firstId, filtering id >= 504 you won't // ever get ids 500, 501, 502 and 503 when they finish - const pastExecutionsPromise: Promise = - this.workflowsStore.getPastExecutions(filter, this.requestItemsPerRequest); - const currentExecutionsPromise: Promise = isEmpty( - filter.metadata, - ) - ? this.workflowsStore.getCurrentExecutions({}) - : Promise.resolve([]); - - const results = await Promise.all([pastExecutionsPromise, currentExecutionsPromise]); + const promises = [this.workflowsStore.getPastExecutions(filter, this.requestItemsPerRequest)]; + if (isEmpty(filter.metadata)) { + promises.push(this.workflowsStore.getCurrentExecutions({})); + } + + const results = await Promise.all(promises); for (const activeExecution of results[1]) { if ( diff --git a/packages/editor-ui/src/components/layouts/ResourcesListLayout.vue b/packages/editor-ui/src/components/layouts/ResourcesListLayout.vue index 8cc4512b4cbcd..9ac79df859a43 100644 --- a/packages/editor-ui/src/components/layouts/ResourcesListLayout.vue +++ b/packages/editor-ui/src/components/layouts/ResourcesListLayout.vue @@ -250,7 +250,7 @@ export default mixins(showMessage, debounceHelper).extend({ }, initialize: { type: Function as PropType<() => Promise>, - default: () => () => Promise.resolve(), + default: () => async () => {}, }, filters: { type: Object, diff --git a/packages/editor-ui/src/mixins/workflowHelpers.ts b/packages/editor-ui/src/mixins/workflowHelpers.ts index 7f9a00b6148cd..6550a39a384f5 100644 --- a/packages/editor-ui/src/mixins/workflowHelpers.ts +++ b/packages/editor-ui/src/mixins/workflowHelpers.ts @@ -460,7 +460,7 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e }, // Returns the currently loaded workflow as JSON. - getWorkflowDataToSave(): Promise { + async getWorkflowDataToSave(): Promise { const workflowNodes = this.workflowsStore.allNodes; const workflowConnections = this.workflowsStore.allConnections; @@ -468,12 +468,8 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e const nodes = []; for (let nodeIndex = 0; nodeIndex < workflowNodes.length; nodeIndex++) { - try { - // @ts-ignore - nodeData = this.getNodeDataToSave(workflowNodes[nodeIndex]); - } catch (e) { - return Promise.reject(e); - } + // @ts-ignore + nodeData = this.getNodeDataToSave(workflowNodes[nodeIndex]); nodes.push(nodeData); } @@ -494,7 +490,7 @@ export const workflowHelpers = mixins(externalHooks, nodeHelpers, showMessage).e data.id = workflowId; } - return Promise.resolve(data); + return data; }, // Returns all node-types diff --git a/packages/editor-ui/src/plugins/i18n/index.ts b/packages/editor-ui/src/plugins/i18n/index.ts index 61e8c62be4586..579f66d91837e 100644 --- a/packages/editor-ui/src/plugins/i18n/index.ts +++ b/packages/editor-ui/src/plugins/i18n/index.ts @@ -535,14 +535,16 @@ function setLanguage(language: string) { } export async function loadLanguage(language?: string) { - if (!language) return Promise.resolve(); + if (!language) return; if (i18nInstance.locale === language) { - return Promise.resolve(setLanguage(language)); + setLanguage(language); + return; } if (loadedLanguages.includes(language)) { - return Promise.resolve(setLanguage(language)); + setLanguage(language); + return; } const { numberFormats, ...rest } = (await import(`./locales/${language}.json`)).default; diff --git a/packages/editor-ui/src/stores/settings.ts b/packages/editor-ui/src/stores/settings.ts index 04769f8edcea0..12e7edcc901a2 100644 --- a/packages/editor-ui/src/stores/settings.ts +++ b/packages/editor-ui/src/stores/settings.ts @@ -243,27 +243,23 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, { }, async fetchPromptsData(): Promise { if (!this.isTelemetryEnabled) { - Promise.resolve(); + return; } - try { - const uiStore = useUIStore(); - const usersStore = useUsersStore(); - const promptsData: IN8nPrompts = await getPromptsData( - this.settings.instanceId, - usersStore.currentUserId || '', - ); - if (promptsData && promptsData.showContactPrompt) { - uiStore.openModal(CONTACT_PROMPT_MODAL_KEY); - } else if (promptsData && promptsData.showValueSurvey) { - uiStore.openModal(VALUE_SURVEY_MODAL_KEY); - } + const uiStore = useUIStore(); + const usersStore = useUsersStore(); + const promptsData: IN8nPrompts = await getPromptsData( + this.settings.instanceId, + usersStore.currentUserId || '', + ); - this.setPromptsData(promptsData); - Promise.resolve(); - } catch (error) { - Promise.reject(error); + if (promptsData && promptsData.showContactPrompt) { + uiStore.openModal(CONTACT_PROMPT_MODAL_KEY); + } else if (promptsData && promptsData.showValueSurvey) { + uiStore.openModal(VALUE_SURVEY_MODAL_KEY); } + + this.setPromptsData(promptsData); }, async submitContactInfo(email: string): Promise { try { diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index d838c5812ed66..323b1e922ad8f 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -445,7 +445,7 @@ export default mixins( } } else if (confirmModal === MODAL_CANCEL) { this.workflowsStore.setWorkflowId(PLACEHOLDER_EMPTY_WORKFLOW_ID); - await this.resetWorkspace(); + this.resetWorkspace(); this.uiStore.stateIsDirty = false; next(); } @@ -2529,7 +2529,7 @@ export default mixins( }, async newWorkflow(): Promise { this.startLoading(); - await this.resetWorkspace(); + this.resetWorkspace(); this.workflowData = await this.workflowsStore.getNewWorkflowData(); this.workflowsStore.currentWorkflowExecutions = []; this.workflowsStore.activeWorkflowExecution = null; @@ -2551,7 +2551,7 @@ export default mixins( // In case the workflow got saved we do not have to run init // as only the route changed but all the needed data is already loaded this.uiStore.stateIsDirty = false; - return Promise.resolve(); + return; } if (this.blankRedirect) { this.blankRedirect = false; @@ -2573,7 +2573,7 @@ export default mixins( const saved = await this.saveCurrentWorkflow(); if (saved) await this.settingsStore.fetchPromptsData(); } else if (confirmModal === MODAL_CLOSE) { - return Promise.resolve(); + return; } } // Load a workflow @@ -3473,7 +3473,7 @@ export default mixins( connections: tempWorkflow.connectionsBySourceNode, }; }, - getSelectedNodesToSave(): Promise { + async getSelectedNodesToSave(): Promise { const data: IWorkflowData = { nodes: [], connections: {}, @@ -3484,12 +3484,8 @@ export default mixins( const exportNodeNames: string[] = []; for (const node of this.uiStore.getSelectedNodes) { - try { - nodeData = this.getNodeDataToSave(node); - exportNodeNames.push(node.name); - } catch (e) { - return Promise.reject(e); - } + nodeData = this.getNodeDataToSave(node); + exportNodeNames.push(node.name); data.nodes.push(nodeData); } @@ -3539,7 +3535,7 @@ export default mixins( } }); - return Promise.resolve(data); + return data; }, resetWorkspace() { this.workflowsStore.resetWorkflow(); @@ -3581,7 +3577,6 @@ export default mixins( this.uiStore.nodeViewOffsetPosition = [0, 0]; this.credentialsUpdated = false; - return Promise.resolve(); }, async loadActiveWorkflows(): Promise { await this.workflowsStore.fetchActiveWorkflows(); diff --git a/packages/nodes-base/nodes/Code/Code.node.ts b/packages/nodes-base/nodes/Code/Code.node.ts index ac64931d25fc7..a14b6ec73a862 100644 --- a/packages/nodes-base/nodes/Code/Code.node.ts +++ b/packages/nodes-base/nodes/Code/Code.node.ts @@ -88,7 +88,7 @@ export class Code implements INodeType { try { result = await sandbox.runCodeAllItems(); } catch (error) { - if (!this.continueOnFail()) return Promise.reject(error); + if (!this.continueOnFail()) throw error; result = [{ json: { error: error.message } }]; } @@ -122,7 +122,7 @@ export class Code implements INodeType { try { result = await sandbox.runCodeEachItem(index); } catch (error) { - if (!this.continueOnFail()) return Promise.reject(error); + if (!this.continueOnFail()) throw error; returnData.push({ json: { error: error.message } }); } diff --git a/packages/nodes-base/nodes/Function/Function.node.ts b/packages/nodes-base/nodes/Function/Function.node.ts index cdf1a110edd42..f681676fe7900 100644 --- a/packages/nodes-base/nodes/Function/Function.node.ts +++ b/packages/nodes-base/nodes/Function/Function.node.ts @@ -233,7 +233,7 @@ return items;`, } } - return Promise.reject(error); + throw error; } } diff --git a/packages/nodes-base/nodes/FunctionItem/FunctionItem.node.ts b/packages/nodes-base/nodes/FunctionItem/FunctionItem.node.ts index a81948fcb9987..e0971f339ed20 100644 --- a/packages/nodes-base/nodes/FunctionItem/FunctionItem.node.ts +++ b/packages/nodes-base/nodes/FunctionItem/FunctionItem.node.ts @@ -208,14 +208,14 @@ return item;`, const lineNumber = lineParts.splice(-2, 1); if (!isNaN(lineNumber as number)) { error.message = `${error.message} [Line ${lineNumber} | Item Index: ${itemIndex}]`; - return Promise.reject(error); + throw error; } } } error.message = `${error.message} [Item Index: ${itemIndex}]`; - return Promise.reject(error); + throw error; } } diff --git a/packages/nodes-base/nodes/Google/Ads/CampaignDescription.ts b/packages/nodes-base/nodes/Google/Ads/CampaignDescription.ts index b5ce28439ac99..3e86ce50d2f2a 100644 --- a/packages/nodes-base/nodes/Google/Ads/CampaignDescription.ts +++ b/packages/nodes-base/nodes/Google/Ads/CampaignDescription.ts @@ -13,17 +13,13 @@ async function processCampaignSearchResponse( ): Promise { const results = (responseData.body as IDataObject).results as GoogleAdsCampaignElement; - return Promise.resolve( - results.map((result) => { - return { - json: { - ...result.campaign, - ...result.metrics, - ...result.campaignBudget, - }, - }; - }), - ); + return results.map((result) => ({ + json: { + ...result.campaign, + ...result.metrics, + ...result.campaignBudget, + }, + })); } export const campaignOperations: INodeProperties[] = [ diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts index 7991f36da60e5..e424ba7a11cf8 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/executeQuery.test.ts @@ -14,21 +14,20 @@ jest.mock('../../../v2/transport', () => { ...originalModule, googleApiRequest: jest.fn(async (method: string, resource: string) => { if (resource === '/v2/projects/test-project/jobs' && method === 'POST') { - return Promise.resolve({ + return { jobReference: { jobId: 'job_123', }, status: { state: 'DONE', }, - }); + }; } if (resource === '/v2/projects/test-project/queries/job_123' && method === 'GET') { - return Promise.resolve({}); + return {}; } - return Promise.resolve(); }), - // googleApiRequestAllItems: jest.fn(async () => Promise.resolve()), + // googleApiRequestAllItems: jest.fn(async () => {}), }; }); diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts index 14d5771f1b792..c79556283223d 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.autoMapMode.test.ts @@ -17,25 +17,24 @@ jest.mock('../../../v2/transport', () => { '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text' && method === 'GET' ) { - return Promise.resolve({ + return { schema: { fields: [ { name: 'id', type: 'INT' }, { name: 'test', type: 'STRING' }, ], }, - }); + }; } if ( resource === '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/num_text/insertAll' && method === 'POST' ) { - return Promise.resolve({ kind: 'bigquery#tableDataInsertAllResponse' }); + return { kind: 'bigquery#tableDataInsertAllResponse' }; } - return Promise.resolve(); }), - googleApiRequestAllItems: jest.fn(async () => Promise.resolve()), + googleApiRequestAllItems: jest.fn(async () => {}), }; }); diff --git a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts index c4181e9495452..52005cb834e88 100644 --- a/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts +++ b/packages/nodes-base/nodes/Google/BigQuery/test/v2/node/insert.manualMode.test.ts @@ -17,7 +17,7 @@ jest.mock('../../../v2/transport', () => { '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json' && method === 'GET' ) { - return Promise.resolve({ + return { schema: { fields: [ { name: 'json', type: 'JSON' }, @@ -25,22 +25,21 @@ jest.mock('../../../v2/transport', () => { { name: 'active', type: 'BOOLEAN' }, ], }, - }); + }; } if ( resource === '/v2/projects/test-project/datasets/bigquery_node_dev_test_dataset/tables/test_json/insertAll' && method === 'POST' ) { - return Promise.resolve({ kind: 'bigquery#tableDataInsertAllResponse' }); + return { kind: 'bigquery#tableDataInsertAllResponse' }; } - return Promise.resolve(); }), - googleApiRequestAllItems: jest.fn(async () => Promise.resolve()), + googleApiRequestAllItems: jest.fn(async () => {}), }; }); -describe('Test Google BigQuery V2, insert define manualy', () => { +describe('Test Google BigQuery V2, insert define manually', () => { const workflows = ['nodes/Google/BigQuery/test/v2/node/insert.manualMode.workflow.json']; const tests = workflowToTests(workflows); diff --git a/packages/nodes-base/nodes/MySql/test/v2/operations.test.ts b/packages/nodes-base/nodes/MySql/test/v2/operations.test.ts index 8f24baf49815e..a131e929be103 100644 --- a/packages/nodes-base/nodes/MySql/test/v2/operations.test.ts +++ b/packages/nodes-base/nodes/MySql/test/v2/operations.test.ts @@ -29,7 +29,7 @@ const fakeConnection = { format(query: string, values: any[]) { return mysql2.format(query, values); }, - query: jest.fn(async (_query = ''): Promise => Promise.resolve([{}])), + query: jest.fn(async (_query = '') => [{}]), release: jest.fn(), beginTransaction: jest.fn(), commit: jest.fn(), @@ -41,7 +41,7 @@ const createFakePool = (connection: IDataObject) => { getConnection() { return connection; }, - query: jest.fn(async () => Promise.resolve([{}])), + query: jest.fn(async () => [{}]), } as unknown as Mysql2Pool; }; @@ -214,7 +214,7 @@ describe('Test MySql V2, operations', () => { } else { result.push({}); } - return Promise.resolve(result); + return result; }); const pool = createFakePool(fakeConnectionCopy); diff --git a/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts b/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts index 73a0eb3418ac5..3fd5ffce4eecb 100644 --- a/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts +++ b/packages/nodes-base/nodes/MySql/test/v2/runQueries.test.ts @@ -23,7 +23,7 @@ const fakeConnection = { format(query: string, values: any[]) { return mysql2.format(query, values); }, - query: jest.fn(async () => Promise.resolve([{}])), + query: jest.fn(async () => [{}]), release: jest.fn(), beginTransaction: jest.fn(), commit: jest.fn(), @@ -35,7 +35,7 @@ const createFakePool = (connection: IDataObject) => { getConnection() { return connection; }, - query: jest.fn(async () => Promise.resolve([{}])), + query: jest.fn(async () => [{}]), } as unknown as Mysql2Pool; }; diff --git a/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts b/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts index 4de24f6b4cf96..4d0e30fa59fef 100644 --- a/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts +++ b/packages/nodes-base/nodes/Postgres/test/v2/operations.test.ts @@ -52,7 +52,7 @@ const createMockDb = (columnInfo: ColumnInfo[]) => { } as unknown as PgpDatabase; }; -// if node parameters copied from canvas all default parameters has to be added manualy as JSON would not have them +// if node parameters copied from canvas all default parameters has to be added manually as JSON would not have them describe('Test PostgresV2, deleteTable operation', () => { afterEach(() => { jest.clearAllMocks(); diff --git a/packages/workflow/src/Workflow.ts b/packages/workflow/src/Workflow.ts index feb9c699d88fd..a3befc4580b46 100644 --- a/packages/workflow/src/Workflow.ts +++ b/packages/workflow/src/Workflow.ts @@ -1236,13 +1236,7 @@ export class Workflow { return { data: null }; } - let promiseResults; - try { - promiseResults = await Promise.all(returnPromises); - } catch (error) { - return Promise.reject(error); - } - + const promiseResults = await Promise.all(returnPromises); if (promiseResults) { return { data: [promiseResults] }; }