From 07744986ea2a5477d9efa45d419c7acaec2691f1 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, 10 Jul 2023 17:57:26 +0200 Subject: [PATCH] fix(core): Fix credentials lazy-loading (no-changelog) (#6615) --- packages/cli/src/CredentialTypes.ts | 17 ++++---- packages/cli/src/LoadNodesAndCredentials.ts | 44 +++++++++++---------- packages/core/bin/generate-known | 5 +++ packages/core/src/DirectoryLoader.ts | 1 + packages/workflow/src/Interfaces.ts | 5 ++- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/packages/cli/src/CredentialTypes.ts b/packages/cli/src/CredentialTypes.ts index 597ff1dfa7..6ea919cea4 100644 --- a/packages/cli/src/CredentialTypes.ts +++ b/packages/cli/src/CredentialTypes.ts @@ -26,16 +26,13 @@ export class CredentialTypes implements ICredentialTypes { * Returns all parent types of the given credential type */ getParentTypes(typeName: string): string[] { - const credentialType = this.getByName(typeName); - if (credentialType?.extends === undefined) return []; - - const types: string[] = []; - credentialType.extends.forEach((type: string) => { - types.push(type); - types.push(...this.getParentTypes(type)); - }); - - return types; + const extendsArr = this.knownCredentials[typeName]?.extends ?? []; + if (extendsArr.length) { + extendsArr.forEach((type) => { + extendsArr.push(...this.getParentTypes(type)); + }); + } + return extendsArr; } private getCredential(type: string): LoadedClass { diff --git a/packages/cli/src/LoadNodesAndCredentials.ts b/packages/cli/src/LoadNodesAndCredentials.ts index 5a6ba88aaa..4d6c3d5a5a 100644 --- a/packages/cli/src/LoadNodesAndCredentials.ts +++ b/packages/cli/src/LoadNodesAndCredentials.ts @@ -331,7 +331,7 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { for (const loader of Object.values(this.loaders)) { // list of node & credential types that will be sent to the frontend - const { types, directory } = loader; + const { known, types, directory } = loader; this.types.nodes = this.types.nodes.concat(types.nodes); this.types.credentials = this.types.credentials.concat(types.credentials); @@ -344,26 +344,30 @@ export class LoadNodesAndCredentials implements INodesAndCredentials { this.loaded.credentials[credentialTypeName] = loader.credentialTypes[credentialTypeName]; } - // Nodes and credentials that will be lazy loaded - if (loader instanceof PackageDirectoryLoader) { - const { packageName, known } = loader; + for (const type in known.nodes) { + const { className, sourcePath } = known.nodes[type]; + this.known.nodes[type] = { + className, + sourcePath: path.join(directory, sourcePath), + }; + } - for (const type in known.nodes) { - const { className, sourcePath } = known.nodes[type]; - this.known.nodes[type] = { - className, - sourcePath: path.join(directory, sourcePath), - }; - } - - for (const type in known.credentials) { - const { className, sourcePath, nodesToTestWith } = known.credentials[type]; - this.known.credentials[type] = { - className, - sourcePath: path.join(directory, sourcePath), - nodesToTestWith: nodesToTestWith?.map((nodeName) => `${packageName}.${nodeName}`), - }; - } + for (const type in known.credentials) { + const { + className, + sourcePath, + nodesToTestWith, + extends: extendsArr, + } = known.credentials[type]; + this.known.credentials[type] = { + className, + sourcePath: path.join(directory, sourcePath), + nodesToTestWith: + loader instanceof PackageDirectoryLoader + ? nodesToTestWith?.map((nodeName) => `${loader.packageName}.${nodeName}`) + : undefined, + extends: extendsArr, + }; } } } diff --git a/packages/core/bin/generate-known b/packages/core/bin/generate-known index b6dde71d4f..5cabfa9b80 100755 --- a/packages/core/bin/generate-known +++ b/packages/core/bin/generate-known @@ -38,6 +38,10 @@ const generate = async (kind) => { else obj[name] = { className, sourcePath }; } + if (kind === 'credentials' && Array.isArray(instance.extends)) { + obj[name].extends = instance.extends; + } + if (kind === 'nodes') { const { credentials } = instance.description; if (credentials && credentials.length) { @@ -53,6 +57,7 @@ const generate = async (kind) => { } return obj; }, {}); + LoggerProxy.info(`Detected ${Object.keys(data).length} ${kind}`); await writeJSON(`known/${kind}.json`, data); return data; diff --git a/packages/core/src/DirectoryLoader.ts b/packages/core/src/DirectoryLoader.ts index 6a623ab6cd..4b55f6b24d 100644 --- a/packages/core/src/DirectoryLoader.ts +++ b/packages/core/src/DirectoryLoader.ts @@ -167,6 +167,7 @@ export abstract class DirectoryLoader { this.known.credentials[tempCredential.name] = { className: credentialName, sourcePath: filePath, + extends: tempCredential.extends, }; this.credentialTypes[tempCredential.name] = { diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 3077901e90..8dd3792bee 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -1568,6 +1568,7 @@ export type LoadingDetails = { export type CredentialLoadingDetails = LoadingDetails & { nodesToTestWith?: string[]; + extends?: string[]; }; export type NodeLoadingDetails = LoadingDetails; @@ -1983,11 +1984,11 @@ export interface IExecutionsSummary { lastNodeExecuted?: string; executionError?: ExecutionError; nodeExecutionStatus?: { - [key: string]: IExceutionSummaryNodeExecutionResult; + [key: string]: IExecutionSummaryNodeExecutionResult; }; } -export interface IExceutionSummaryNodeExecutionResult { +export interface IExecutionSummaryNodeExecutionResult { executionStatus: ExecutionStatus; errors?: Array<{ name?: string;