From 05858c21532feb1830181f6d9f4ee7f927c5b1a2 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: Fri, 17 Jan 2025 15:17:25 +0100 Subject: [PATCH] refactor(core): Reorganize n8n-core and enforce file-name casing (no-changelog) (#12667) --- packages/core/.eslintrc.js | 1 + packages/core/bin/generate-metadata | 2 +- .../core/src/PartialExecutionUtils/index.ts | 8 - .../__tests__/credentials.test.ts} | 7 +- .../__tests__/node-execute-functions.test.ts} | 6 +- .../__tests__/file-system.manager.test.ts} | 7 +- .../__tests__/object-store.manager.test.ts} | 11 +- .../binary-data/__tests__}/utils.test.ts | 2 +- .../binary-data.service.ts} | 6 +- .../file-system.manager.ts} | 0 packages/core/src/binary-data/index.ts | 4 + .../object-store.manager.ts} | 2 +- .../__tests__/object-store.service.test.ts} | 4 +- .../object-store/object-store.service.ee.ts} | 2 +- .../object-store}/types.ts | 2 +- .../object-store}/utils.ts | 0 .../src/{BinaryData => binary-data}/types.ts | 0 .../src/{BinaryData => binary-data}/utils.ts | 0 .../core/src/{Constants.ts => constants.ts} | 32 --- .../src/{Credentials.ts => credentials.ts} | 2 +- .../encryption/__tests__/cipher.test.ts} | 6 +- .../src/{Cipher.ts => encryption/cipher.ts} | 2 +- packages/core/src/encryption/index.ts | 1 + .../errors/__tests__}/error-reporter.test.ts | 3 +- .../core/src/{ => errors}/error-reporter.ts | 4 +- packages/core/src/errors/index.ts | 2 + .../core/src/errors/invalid-mode.error.ts | 2 +- .../__tests__/active-workflows.test.ts} | 11 +- .../__tests__/routing-node.test.ts} | 6 +- .../__tests__/scheduled-task-manager.test.ts} | 5 +- .../__tests__/ssh-clients-manager.test.ts} | 2 +- .../__tests__/triggers-and-pollers.test.ts} | 2 +- .../__tests__/workflow-execute.test.ts} | 12 +- .../__tests__}/workflows/error_outputs.json | 0 .../workflows/paired_items_fix.json | 0 .../active-workflows.ts} | 11 +- packages/core/src/execution-engine/index.ts | 6 + .../__tests__/execute-context.test.ts | 0 .../__tests__/execute-single-context.test.ts | 0 .../__tests__/hook-context.test.ts | 0 .../__tests__/load-options-context.test.ts | 0 .../__tests__/node-execution-context.test.ts | 2 +- .../__tests__/poll-context.test.ts | 0 .../__tests__/shared-tests.ts | 2 +- .../__tests__/supply-data-context.test.ts | 0 .../__tests__/trigger-context.test.ts | 0 .../__tests__/webhook-context.test.ts | 0 .../base-execute-context.ts | 2 +- .../node-execution-context/execute-context.ts | 4 +- .../execute-single-context.ts | 2 +- .../node-execution-context/hook-context.ts | 2 +- .../node-execution-context/index.ts | 2 +- .../load-options-context.ts | 4 +- .../local-load-options-context.ts | 0 .../node-execution-context.ts | 14 +- .../node-execution-context/poll-context.ts | 2 +- .../supply-data-context.ts | 4 +- .../node-execution-context/trigger-context.ts | 2 +- .../__tests__/cleanup-parameter-data.test.ts} | 2 +- .../__tests__/create-node-as-tool.test.ts} | 2 +- .../utils/__tests__/ensure-type.test.ts} | 2 +- .../__tests__/execution-metadata.test.ts} | 3 +- .../__tests__/get-additional-keys.test.ts} | 4 +- .../get-input-connection-data.test.ts} | 0 .../validate-value-against-schema.test.ts} | 2 +- .../utils/cleanup-parameter-data.ts} | 0 .../utils/create-node-as-tool.ts} | 0 .../utils/ensure-type.ts} | 0 .../utils/execution-metadata.ts} | 2 +- .../utils/extract-value.ts} | 0 .../utils/get-additional-keys.ts} | 7 +- .../utils/get-input-connection-data.ts} | 6 +- .../utils/get-secrets-proxy.ts} | 0 .../utils/validate-value-against-schema.ts} | 2 +- .../node-execution-context/webhook-context.ts | 4 +- .../workflow-node-context.ts | 0 .../__tests__/clean-run-data.test.ts} | 4 +- .../__tests__/directed-graph.test.ts} | 2 +- .../__tests__/filter-disabled-nodes.test.ts} | 4 +- .../__tests__/find-start-nodes.test.ts} | 4 +- .../__tests__/find-subgraph.test.ts} | 4 +- .../__tests__/get-source-data-groups.test.ts} | 4 +- .../__tests__/handle-cycles.test.ts} | 4 +- .../__tests__/helpers.ts | 0 .../recreate-node-execution-stack.test.ts} | 9 +- .../__tests__/to-iconnections.test.ts} | 0 .../__tests__/to-itask-data.test.ts} | 0 .../clean-run-data.ts} | 2 +- .../directed-graph.ts} | 0 .../filter-disabled-nodes.ts} | 2 +- .../find-start-nodes.ts} | 4 +- .../partial-execution-utils/find-subgraph.ts} | 4 +- .../find-trigger-for-partial-execution.ts} | 0 .../get-incoming-data.ts} | 0 .../get-source-data-groups.ts} | 2 +- .../partial-execution-utils/handle-cycles.ts} | 2 +- .../partial-execution-utils/index.ts | 8 + .../recreate-node-execution-stack.ts} | 6 +- .../routing-node.ts} | 0 .../scheduled-task-manager.ts} | 2 +- .../ssh-clients-manager.ts} | 0 .../triggers-and-pollers.ts} | 0 .../workflow-execute.ts} | 11 +- packages/core/src/index.ts | 41 ++-- .../__tests__/instance-settings.test.ts} | 7 +- packages/core/src/instance-settings/index.ts | 1 + .../instance-settings-config.ts} | 0 .../instance-settings.ts} | 4 +- .../core/src/{Interfaces.ts => interfaces.ts} | 15 -- .../core/src/logging/__tests__/logger.test.ts | 2 +- packages/core/src/logging/index.ts | 1 + packages/core/src/logging/logger.ts | 6 +- ...Functions.ts => node-execute-functions.ts} | 18 +- .../helpers/binary-helpers.ts | 0 .../__tests__/directory-loader.test.ts} | 10 +- .../load-class-in-isolation.test.ts} | 4 +- packages/core/src/nodes-loader/constants.ts | 31 +++ .../nodes-loader/custom-directory-loader.ts | 31 +++ .../directory-loader.ts} | 194 +----------------- packages/core/src/nodes-loader/index.ts | 5 + .../lazy-package-directory-loader.ts | 52 +++++ .../load-class-in-isolation.ts} | 0 .../nodes-loader/package-directory-loader.ts | 107 ++++++++++ packages/core/src/nodes-loader/types.ts | 14 ++ .../__tests__/is-object-literal.test.ts} | 2 +- .../__tests__/serialized-buffer.test.ts} | 4 +- packages/core/src/utils/index.ts | 2 + .../{utils.ts => utils/is-object-literal.ts} | 0 .../serialized-buffer.ts} | 2 +- packages/core/test/helpers/index.ts | 13 +- packages/core/tsconfig.json | 3 +- .../nodes-base/test/nodes/TriggerHelpers.ts | 2 +- 132 files changed, 459 insertions(+), 441 deletions(-) delete mode 100644 packages/core/src/PartialExecutionUtils/index.ts rename packages/core/{test/Credentials.test.ts => src/__tests__/credentials.test.ts} (91%) rename packages/core/{test/NodeExecuteFunctions.test.ts => src/__tests__/node-execute-functions.test.ts} (99%) rename packages/core/{test/FileSystem.manager.test.ts => src/binary-data/__tests__/file-system.manager.test.ts} (96%) rename packages/core/{test/ObjectStore.manager.test.ts => src/binary-data/__tests__/object-store.manager.test.ts} (91%) rename packages/core/{test/BinaryData => src/binary-data/__tests__}/utils.test.ts (95%) rename packages/core/src/{BinaryData/BinaryData.service.ts => binary-data/binary-data.service.ts} (96%) rename packages/core/src/{BinaryData/FileSystem.manager.ts => binary-data/file-system.manager.ts} (100%) create mode 100644 packages/core/src/binary-data/index.ts rename packages/core/src/{BinaryData/ObjectStore.manager.ts => binary-data/object-store.manager.ts} (97%) rename packages/core/{test/ObjectStore.service.test.ts => src/binary-data/object-store/__tests__/object-store.service.test.ts} (98%) rename packages/core/src/{ObjectStore/ObjectStore.service.ee.ts => binary-data/object-store/object-store.service.ee.ts} (99%) rename packages/core/src/{ObjectStore => binary-data/object-store}/types.ts (94%) rename packages/core/src/{ObjectStore => binary-data/object-store}/utils.ts (100%) rename packages/core/src/{BinaryData => binary-data}/types.ts (100%) rename packages/core/src/{BinaryData => binary-data}/utils.ts (100%) rename packages/core/src/{Constants.ts => constants.ts} (51%) rename packages/core/src/{Credentials.ts => credentials.ts} (96%) rename packages/core/{test/Cipher.test.ts => src/encryption/__tests__/cipher.test.ts} (87%) rename packages/core/src/{Cipher.ts => encryption/cipher.ts} (96%) create mode 100644 packages/core/src/encryption/index.ts rename packages/core/{test => src/errors/__tests__}/error-reporter.test.ts (99%) rename packages/core/src/{ => errors}/error-reporter.ts (98%) rename packages/core/src/{__tests__/ActiveWorkflows.test.ts => execution-engine/__tests__/active-workflows.test.ts} (96%) rename packages/core/{test/RoutingNode.test.ts => src/execution-engine/__tests__/routing-node.test.ts} (99%) rename packages/core/{test/ScheduledTaskManager.test.ts => src/execution-engine/__tests__/scheduled-task-manager.test.ts} (94%) rename packages/core/{test/SSHClientsManager.test.ts => src/execution-engine/__tests__/ssh-clients-manager.test.ts} (97%) rename packages/core/{test/TriggersAndPollers.test.ts => src/execution-engine/__tests__/triggers-and-pollers.test.ts} (98%) rename packages/core/{test/WorkflowExecute.test.ts => src/execution-engine/__tests__/workflow-execute.test.ts} (99%) rename packages/core/{test => src/execution-engine/__tests__}/workflows/error_outputs.json (100%) rename packages/core/{test => src/execution-engine/__tests__}/workflows/paired_items_fix.json (100%) rename packages/core/src/{ActiveWorkflows.ts => execution-engine/active-workflows.ts} (95%) create mode 100644 packages/core/src/execution-engine/index.ts rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/execute-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/execute-single-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/hook-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/load-options-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/node-execution-context.test.ts (99%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/poll-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/shared-tests.ts (98%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/supply-data-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/trigger-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/__tests__/webhook-context.test.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/base-execute-context.ts (98%) rename packages/core/src/{ => execution-engine}/node-execution-context/execute-context.ts (97%) rename packages/core/src/{ => execution-engine}/node-execution-context/execute-single-context.ts (98%) rename packages/core/src/{ => execution-engine}/node-execution-context/hook-context.ts (97%) rename packages/core/src/{ => execution-engine}/node-execution-context/index.ts (90%) rename packages/core/src/{ => execution-engine}/node-execution-context/load-options-context.ts (95%) rename packages/core/src/{ => execution-engine}/node-execution-context/local-load-options-context.ts (100%) rename packages/core/src/{ => execution-engine}/node-execution-context/node-execution-context.ts (96%) rename packages/core/src/{ => execution-engine}/node-execution-context/poll-context.ts (97%) rename packages/core/src/{ => execution-engine}/node-execution-context/supply-data-context.ts (98%) rename packages/core/src/{ => execution-engine}/node-execution-context/trigger-context.ts (97%) rename packages/core/src/{node-execution-context/utils/__tests__/cleanupParameterData.test.ts => execution-engine/node-execution-context/utils/__tests__/cleanup-parameter-data.test.ts} (94%) rename packages/core/{test/CreateNodeAsTool.test.ts => src/execution-engine/node-execution-context/utils/__tests__/create-node-as-tool.test.ts} (99%) rename packages/core/src/{node-execution-context/utils/__tests__/ensureType.test.ts => execution-engine/node-execution-context/utils/__tests__/ensure-type.test.ts} (98%) rename packages/core/{test/WorkflowExecutionMetadata.test.ts => src/execution-engine/node-execution-context/utils/__tests__/execution-metadata.test.ts} (99%) rename packages/core/src/{node-execution-context/utils/__tests__/getAdditionalKeys.test.ts => execution-engine/node-execution-context/utils/__tests__/get-additional-keys.test.ts} (97%) rename packages/core/src/{node-execution-context/utils/__tests__/getInputConnectionData.test.ts => execution-engine/node-execution-context/utils/__tests__/get-input-connection-data.test.ts} (100%) rename packages/core/src/{node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts => execution-engine/node-execution-context/utils/__tests__/validate-value-against-schema.test.ts} (98%) rename packages/core/src/{node-execution-context/utils/cleanupParameterData.ts => execution-engine/node-execution-context/utils/cleanup-parameter-data.ts} (100%) rename packages/core/src/{CreateNodeAsTool.ts => execution-engine/node-execution-context/utils/create-node-as-tool.ts} (100%) rename packages/core/src/{node-execution-context/utils/ensureType.ts => execution-engine/node-execution-context/utils/ensure-type.ts} (100%) rename packages/core/src/{ExecutionMetadata.ts => execution-engine/node-execution-context/utils/execution-metadata.ts} (97%) rename packages/core/src/{ExtractValue.ts => execution-engine/node-execution-context/utils/extract-value.ts} (100%) rename packages/core/src/{node-execution-context/utils/getAdditionalKeys.ts => execution-engine/node-execution-context/utils/get-additional-keys.ts} (93%) rename packages/core/src/{node-execution-context/utils/getInputConnectionData.ts => execution-engine/node-execution-context/utils/get-input-connection-data.ts} (96%) rename packages/core/src/{Secrets.ts => execution-engine/node-execution-context/utils/get-secrets-proxy.ts} (100%) rename packages/core/src/{node-execution-context/utils/validateValueAgainstSchema.ts => execution-engine/node-execution-context/utils/validate-value-against-schema.ts} (98%) rename packages/core/src/{ => execution-engine}/node-execution-context/webhook-context.ts (97%) rename packages/core/src/{ => execution-engine}/node-execution-context/workflow-node-context.ts (100%) rename packages/core/src/{PartialExecutionUtils/__tests__/cleanRunData.test.ts => execution-engine/partial-execution-utils/__tests__/clean-run-data.test.ts} (97%) rename packages/core/src/{PartialExecutionUtils/__tests__/DirectedGraph.test.ts => execution-engine/partial-execution-utils/__tests__/directed-graph.test.ts} (99%) rename packages/core/src/{PartialExecutionUtils/__tests__/filterDisabledNodes.test.ts => execution-engine/partial-execution-utils/__tests__/filter-disabled-nodes.test.ts} (97%) rename packages/core/src/{PartialExecutionUtils/__tests__/findStartNodes.test.ts => execution-engine/partial-execution-utils/__tests__/find-start-nodes.test.ts} (99%) rename packages/core/src/{PartialExecutionUtils/__tests__/findSubgraph.test.ts => execution-engine/partial-execution-utils/__tests__/find-subgraph.test.ts} (99%) rename packages/core/src/{PartialExecutionUtils/__tests__/getSourceDataGroups.test.ts => execution-engine/partial-execution-utils/__tests__/get-source-data-groups.test.ts} (99%) rename packages/core/src/{PartialExecutionUtils/__tests__/handleCycles.test.ts => execution-engine/partial-execution-utils/__tests__/handle-cycles.test.ts} (98%) rename packages/core/src/{PartialExecutionUtils => execution-engine/partial-execution-utils}/__tests__/helpers.ts (100%) rename packages/core/src/{PartialExecutionUtils/__tests__/recreateNodeExecutionStack.test.ts => execution-engine/partial-execution-utils/__tests__/recreate-node-execution-stack.test.ts} (99%) rename packages/core/src/{PartialExecutionUtils/__tests__/toIConnections.test.ts => execution-engine/partial-execution-utils/__tests__/to-iconnections.test.ts} (100%) rename packages/core/src/{PartialExecutionUtils/__tests__/toITaskData.test.ts => execution-engine/partial-execution-utils/__tests__/to-itask-data.test.ts} (100%) rename packages/core/src/{PartialExecutionUtils/cleanRunData.ts => execution-engine/partial-execution-utils/clean-run-data.ts} (93%) rename packages/core/src/{PartialExecutionUtils/DirectedGraph.ts => execution-engine/partial-execution-utils/directed-graph.ts} (100%) rename packages/core/src/{PartialExecutionUtils/filterDisabledNodes.ts => execution-engine/partial-execution-utils/filter-disabled-nodes.ts} (88%) rename packages/core/src/{PartialExecutionUtils/findStartNodes.ts => execution-engine/partial-execution-utils/find-start-nodes.ts} (98%) rename packages/core/src/{PartialExecutionUtils/findSubgraph.ts => execution-engine/partial-execution-utils/find-subgraph.ts} (97%) rename packages/core/src/{PartialExecutionUtils/findTriggerForPartialExecution.ts => execution-engine/partial-execution-utils/find-trigger-for-partial-execution.ts} (100%) rename packages/core/src/{PartialExecutionUtils/getIncomingData.ts => execution-engine/partial-execution-utils/get-incoming-data.ts} (100%) rename packages/core/src/{PartialExecutionUtils/getSourceDataGroups.ts => execution-engine/partial-execution-utils/get-source-data-groups.ts} (98%) rename packages/core/src/{PartialExecutionUtils/handleCycles.ts => execution-engine/partial-execution-utils/handle-cycles.ts} (96%) create mode 100644 packages/core/src/execution-engine/partial-execution-utils/index.ts rename packages/core/src/{PartialExecutionUtils/recreateNodeExecutionStack.ts => execution-engine/partial-execution-utils/recreate-node-execution-stack.ts} (97%) rename packages/core/src/{RoutingNode.ts => execution-engine/routing-node.ts} (100%) rename packages/core/src/{ScheduledTaskManager.ts => execution-engine/scheduled-task-manager.ts} (95%) rename packages/core/src/{SSHClientsManager.ts => execution-engine/ssh-clients-manager.ts} (100%) rename packages/core/src/{TriggersAndPollers.ts => execution-engine/triggers-and-pollers.ts} (100%) rename packages/core/src/{WorkflowExecute.ts => execution-engine/workflow-execute.ts} (99%) rename packages/core/{test/InstanceSettings.test.ts => src/instance-settings/__tests__/instance-settings.test.ts} (98%) create mode 100644 packages/core/src/instance-settings/index.ts rename packages/core/src/{InstanceSettingsConfig.ts => instance-settings/instance-settings-config.ts} (100%) rename packages/core/src/{InstanceSettings.ts => instance-settings/instance-settings.ts} (98%) rename packages/core/src/{Interfaces.ts => interfaces.ts} (73%) create mode 100644 packages/core/src/logging/index.ts rename packages/core/src/{NodeExecuteFunctions.ts => node-execute-functions.ts} (99%) delete mode 100644 packages/core/src/node-execution-context/helpers/binary-helpers.ts rename packages/core/{test/DirectoryLoader.test.ts => src/nodes-loader/__tests__/directory-loader.test.ts} (98%) rename packages/core/{test/ClassLoader.test.ts => src/nodes-loader/__tests__/load-class-in-isolation.test.ts} (93%) create mode 100644 packages/core/src/nodes-loader/constants.ts create mode 100644 packages/core/src/nodes-loader/custom-directory-loader.ts rename packages/core/src/{DirectoryLoader.ts => nodes-loader/directory-loader.ts} (66%) create mode 100644 packages/core/src/nodes-loader/index.ts create mode 100644 packages/core/src/nodes-loader/lazy-package-directory-loader.ts rename packages/core/src/{ClassLoader.ts => nodes-loader/load-class-in-isolation.ts} (100%) create mode 100644 packages/core/src/nodes-loader/package-directory-loader.ts create mode 100644 packages/core/src/nodes-loader/types.ts rename packages/core/src/{__tests__/utils.test.ts => utils/__tests__/is-object-literal.test.ts} (95%) rename packages/core/{test/SerializedBuffer.test.ts => src/utils/__tests__/serialized-buffer.test.ts} (92%) create mode 100644 packages/core/src/utils/index.ts rename packages/core/src/{utils.ts => utils/is-object-literal.ts} (100%) rename packages/core/src/{SerializedBuffer.ts => utils/serialized-buffer.ts} (91%) diff --git a/packages/core/.eslintrc.js b/packages/core/.eslintrc.js index 9bfae8a9eb..ceb431ce40 100644 --- a/packages/core/.eslintrc.js +++ b/packages/core/.eslintrc.js @@ -16,6 +16,7 @@ module.exports = { rules: { complexity: 'error', + 'unicorn/filename-case': ['error', { case: 'kebabCase' }], // TODO: Remove this '@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': true }], diff --git a/packages/core/bin/generate-metadata b/packages/core/bin/generate-metadata index 18dbca687a..b4001ccd84 100755 --- a/packages/core/bin/generate-metadata +++ b/packages/core/bin/generate-metadata @@ -1,7 +1,7 @@ #!/usr/bin/env node const { LoggerProxy } = require('n8n-workflow'); -const { PackageDirectoryLoader } = require('../dist/DirectoryLoader'); +const { PackageDirectoryLoader } = require('../dist/nodes-loader/package-directory-loader'); const { packageDir, writeJSON } = require('./common'); LoggerProxy.init(console); diff --git a/packages/core/src/PartialExecutionUtils/index.ts b/packages/core/src/PartialExecutionUtils/index.ts deleted file mode 100644 index f85202cfa1..0000000000 --- a/packages/core/src/PartialExecutionUtils/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export { DirectedGraph } from './DirectedGraph'; -export { findTriggerForPartialExecution } from './findTriggerForPartialExecution'; -export { findStartNodes } from './findStartNodes'; -export { findSubgraph } from './findSubgraph'; -export { recreateNodeExecutionStack } from './recreateNodeExecutionStack'; -export { cleanRunData } from './cleanRunData'; -export { handleCycles } from './handleCycles'; -export { filterDisabledNodes } from './filterDisabledNodes'; diff --git a/packages/core/test/Credentials.test.ts b/packages/core/src/__tests__/credentials.test.ts similarity index 91% rename from packages/core/test/Credentials.test.ts rename to packages/core/src/__tests__/credentials.test.ts index bf6ba29ca5..366477def7 100644 --- a/packages/core/test/Credentials.test.ts +++ b/packages/core/src/__tests__/credentials.test.ts @@ -2,9 +2,10 @@ import { Container } from '@n8n/di'; import { mock } from 'jest-mock-extended'; import type { CredentialInformation } from 'n8n-workflow'; -import { Cipher } from '@/Cipher'; -import { Credentials } from '@/Credentials'; -import type { InstanceSettings } from '@/InstanceSettings'; +import { Cipher } from '@/encryption/cipher'; +import type { InstanceSettings } from '@/instance-settings'; + +import { Credentials } from '../credentials'; describe('Credentials', () => { const cipher = new Cipher(mock({ encryptionKey: 'password' })); diff --git a/packages/core/test/NodeExecuteFunctions.test.ts b/packages/core/src/__tests__/node-execute-functions.test.ts similarity index 99% rename from packages/core/test/NodeExecuteFunctions.test.ts rename to packages/core/src/__tests__/node-execute-functions.test.ts index 703e3f9bef..a1c41355e6 100644 --- a/packages/core/test/NodeExecuteFunctions.test.ts +++ b/packages/core/src/__tests__/node-execute-functions.test.ts @@ -21,8 +21,8 @@ import { join } from 'path'; import { Readable } from 'stream'; import type { SecureContextOptions } from 'tls'; -import { BinaryDataService } from '@/BinaryData/BinaryData.service'; -import { InstanceSettings } from '@/InstanceSettings'; +import { BinaryDataService } from '@/binary-data/binary-data.service'; +import { InstanceSettings } from '@/instance-settings'; import { binaryToString, copyInputItems, @@ -36,7 +36,7 @@ import { proxyRequestToAxios, removeEmptyBody, setBinaryDataBuffer, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; const temporaryDir = mkdtempSync(join(tmpdir(), 'n8n')); diff --git a/packages/core/test/FileSystem.manager.test.ts b/packages/core/src/binary-data/__tests__/file-system.manager.test.ts similarity index 96% rename from packages/core/test/FileSystem.manager.test.ts rename to packages/core/src/binary-data/__tests__/file-system.manager.test.ts index edb6bd5e77..fae24801f5 100644 --- a/packages/core/test/FileSystem.manager.test.ts +++ b/packages/core/src/binary-data/__tests__/file-system.manager.test.ts @@ -3,10 +3,9 @@ import fsp from 'node:fs/promises'; import { tmpdir } from 'node:os'; import path from 'node:path'; -import { FileSystemManager } from '@/BinaryData/FileSystem.manager'; -import { isStream } from '@/ObjectStore/utils'; - -import { toFileId, toStream } from './utils'; +import { FileSystemManager } from '@/binary-data/file-system.manager'; +import { isStream } from '@/binary-data/object-store/utils'; +import { toFileId, toStream } from '@test/utils'; jest.mock('fs'); jest.mock('fs/promises'); diff --git a/packages/core/test/ObjectStore.manager.test.ts b/packages/core/src/binary-data/__tests__/object-store.manager.test.ts similarity index 91% rename from packages/core/test/ObjectStore.manager.test.ts rename to packages/core/src/binary-data/__tests__/object-store.manager.test.ts index f01e170213..9ca99e8d7b 100644 --- a/packages/core/test/ObjectStore.manager.test.ts +++ b/packages/core/src/binary-data/__tests__/object-store.manager.test.ts @@ -1,12 +1,11 @@ import { mock } from 'jest-mock-extended'; import fs from 'node:fs/promises'; -import { ObjectStoreManager } from '@/BinaryData/ObjectStore.manager'; -import { ObjectStoreService } from '@/ObjectStore/ObjectStore.service.ee'; -import type { MetadataResponseHeaders } from '@/ObjectStore/types'; -import { isStream } from '@/ObjectStore/utils'; - -import { mockInstance, toFileId, toStream } from './utils'; +import { ObjectStoreService } from '@/binary-data/object-store/object-store.service.ee'; +import type { MetadataResponseHeaders } from '@/binary-data/object-store/types'; +import { isStream } from '@/binary-data/object-store/utils'; +import { ObjectStoreManager } from '@/binary-data/object-store.manager'; +import { mockInstance, toFileId, toStream } from '@test/utils'; jest.mock('fs/promises'); diff --git a/packages/core/test/BinaryData/utils.test.ts b/packages/core/src/binary-data/__tests__/utils.test.ts similarity index 95% rename from packages/core/test/BinaryData/utils.test.ts rename to packages/core/src/binary-data/__tests__/utils.test.ts index 50a7f165df..329345262f 100644 --- a/packages/core/test/BinaryData/utils.test.ts +++ b/packages/core/src/binary-data/__tests__/utils.test.ts @@ -1,7 +1,7 @@ import { Readable } from 'node:stream'; import { createGunzip } from 'node:zlib'; -import { binaryToBuffer } from '@/BinaryData/utils'; +import { binaryToBuffer } from '@/binary-data/utils'; describe('BinaryData/utils', () => { describe('binaryToBuffer', () => { diff --git a/packages/core/src/BinaryData/BinaryData.service.ts b/packages/core/src/binary-data/binary-data.service.ts similarity index 96% rename from packages/core/src/BinaryData/BinaryData.service.ts rename to packages/core/src/binary-data/binary-data.service.ts index 5876ae075e..742ceb500f 100644 --- a/packages/core/src/BinaryData/BinaryData.service.ts +++ b/packages/core/src/binary-data/binary-data.service.ts @@ -22,7 +22,7 @@ export class BinaryDataService { this.mode = config.mode === 'filesystem' ? 'filesystem-v2' : config.mode; if (config.availableModes.includes('filesystem')) { - const { FileSystemManager } = await import('./FileSystem.manager'); + const { FileSystemManager } = await import('./file-system.manager'); this.managers.filesystem = new FileSystemManager(config.localStoragePath); this.managers['filesystem-v2'] = this.managers.filesystem; @@ -31,8 +31,8 @@ export class BinaryDataService { } if (config.availableModes.includes('s3')) { - const { ObjectStoreManager } = await import('./ObjectStore.manager'); - const { ObjectStoreService } = await import('../ObjectStore/ObjectStore.service.ee'); + const { ObjectStoreManager } = await import('./object-store.manager'); + const { ObjectStoreService } = await import('./object-store/object-store.service.ee'); this.managers.s3 = new ObjectStoreManager(Container.get(ObjectStoreService)); diff --git a/packages/core/src/BinaryData/FileSystem.manager.ts b/packages/core/src/binary-data/file-system.manager.ts similarity index 100% rename from packages/core/src/BinaryData/FileSystem.manager.ts rename to packages/core/src/binary-data/file-system.manager.ts diff --git a/packages/core/src/binary-data/index.ts b/packages/core/src/binary-data/index.ts new file mode 100644 index 0000000000..ef82dee30f --- /dev/null +++ b/packages/core/src/binary-data/index.ts @@ -0,0 +1,4 @@ +export * from './binary-data.service'; +export * from './types'; +export { ObjectStoreService } from './object-store/object-store.service.ee'; +export { isStoredMode as isValidNonDefaultMode } from './utils'; diff --git a/packages/core/src/BinaryData/ObjectStore.manager.ts b/packages/core/src/binary-data/object-store.manager.ts similarity index 97% rename from packages/core/src/BinaryData/ObjectStore.manager.ts rename to packages/core/src/binary-data/object-store.manager.ts index 5a2ab8ef55..cc0fa564ce 100644 --- a/packages/core/src/BinaryData/ObjectStore.manager.ts +++ b/packages/core/src/binary-data/object-store.manager.ts @@ -3,9 +3,9 @@ import fs from 'node:fs/promises'; import type { Readable } from 'node:stream'; import { v4 as uuid } from 'uuid'; +import { ObjectStoreService } from './object-store/object-store.service.ee'; import type { BinaryData } from './types'; import { binaryToBuffer } from './utils'; -import { ObjectStoreService } from '../ObjectStore/ObjectStore.service.ee'; @Service() export class ObjectStoreManager implements BinaryData.Manager { diff --git a/packages/core/test/ObjectStore.service.test.ts b/packages/core/src/binary-data/object-store/__tests__/object-store.service.test.ts similarity index 98% rename from packages/core/test/ObjectStore.service.test.ts rename to packages/core/src/binary-data/object-store/__tests__/object-store.service.test.ts index 9899ad17fc..f5d2924eb5 100644 --- a/packages/core/test/ObjectStore.service.test.ts +++ b/packages/core/src/binary-data/object-store/__tests__/object-store.service.test.ts @@ -2,8 +2,8 @@ import axios from 'axios'; import { mock } from 'jest-mock-extended'; import { Readable } from 'stream'; -import { ObjectStoreService } from '@/ObjectStore/ObjectStore.service.ee'; -import { writeBlockedMessage } from '@/ObjectStore/utils'; +import { ObjectStoreService } from '@/binary-data/object-store/object-store.service.ee'; +import { writeBlockedMessage } from '@/binary-data/object-store/utils'; jest.mock('axios'); diff --git a/packages/core/src/ObjectStore/ObjectStore.service.ee.ts b/packages/core/src/binary-data/object-store/object-store.service.ee.ts similarity index 99% rename from packages/core/src/ObjectStore/ObjectStore.service.ee.ts rename to packages/core/src/binary-data/object-store/object-store.service.ee.ts index e1b98c6f50..508477d50e 100644 --- a/packages/core/src/ObjectStore/ObjectStore.service.ee.ts +++ b/packages/core/src/binary-data/object-store/object-store.service.ee.ts @@ -18,7 +18,7 @@ import type { RequestOptions, } from './types'; import { isStream, parseXml, writeBlockedMessage } from './utils'; -import type { BinaryData } from '../BinaryData/types'; +import type { BinaryData } from '../types'; @Service() export class ObjectStoreService { diff --git a/packages/core/src/ObjectStore/types.ts b/packages/core/src/binary-data/object-store/types.ts similarity index 94% rename from packages/core/src/ObjectStore/types.ts rename to packages/core/src/binary-data/object-store/types.ts index d0b7ab0713..49726f5c43 100644 --- a/packages/core/src/ObjectStore/types.ts +++ b/packages/core/src/binary-data/object-store/types.ts @@ -1,6 +1,6 @@ import type { AxiosResponseHeaders, ResponseType } from 'axios'; -import type { BinaryData } from '../BinaryData/types'; +import type { BinaryData } from '../types'; export type RawListPage = { listBucketResult: { diff --git a/packages/core/src/ObjectStore/utils.ts b/packages/core/src/binary-data/object-store/utils.ts similarity index 100% rename from packages/core/src/ObjectStore/utils.ts rename to packages/core/src/binary-data/object-store/utils.ts diff --git a/packages/core/src/BinaryData/types.ts b/packages/core/src/binary-data/types.ts similarity index 100% rename from packages/core/src/BinaryData/types.ts rename to packages/core/src/binary-data/types.ts diff --git a/packages/core/src/BinaryData/utils.ts b/packages/core/src/binary-data/utils.ts similarity index 100% rename from packages/core/src/BinaryData/utils.ts rename to packages/core/src/binary-data/utils.ts diff --git a/packages/core/src/Constants.ts b/packages/core/src/constants.ts similarity index 51% rename from packages/core/src/Constants.ts rename to packages/core/src/constants.ts index 82a39b07cd..feb630e306 100644 --- a/packages/core/src/Constants.ts +++ b/packages/core/src/constants.ts @@ -1,6 +1,3 @@ -import type { INodeProperties } from 'n8n-workflow'; -import { cronNodeOptions } from 'n8n-workflow'; - const { NODE_ENV } = process.env; export const inProduction = NODE_ENV === 'production'; export const inDevelopment = !NODE_ENV || NODE_ENV === 'development'; @@ -11,38 +8,9 @@ export const PLACEHOLDER_EMPTY_WORKFLOW_ID = '__EMPTY__'; export const HTTP_REQUEST_NODE_TYPE = 'n8n-nodes-base.httpRequest'; export const HTTP_REQUEST_TOOL_NODE_TYPE = '@n8n/n8n-nodes-langchain.toolHttpRequest'; -export const CUSTOM_NODES_CATEGORY = 'Custom Nodes'; - export const RESTRICT_FILE_ACCESS_TO = 'N8N_RESTRICT_FILE_ACCESS_TO'; export const BLOCK_FILE_ACCESS_TO_N8N_FILES = 'N8N_BLOCK_FILE_ACCESS_TO_N8N_FILES'; export const CONFIG_FILES = 'N8N_CONFIG_FILES'; export const BINARY_DATA_STORAGE_PATH = 'N8N_BINARY_DATA_STORAGE_PATH'; export const UM_EMAIL_TEMPLATES_INVITE = 'N8N_UM_EMAIL_TEMPLATES_INVITE'; export const UM_EMAIL_TEMPLATES_PWRESET = 'N8N_UM_EMAIL_TEMPLATES_PWRESET'; - -export const commonPollingParameters: INodeProperties[] = [ - { - displayName: 'Poll Times', - name: 'pollTimes', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - multipleValueButtonText: 'Add Poll Time', - }, - default: { item: [{ mode: 'everyMinute' }] }, - description: 'Time at which polling should occur', - placeholder: 'Add Poll Time', - options: cronNodeOptions, - }, -]; - -export const commonCORSParameters: INodeProperties[] = [ - { - displayName: 'Allowed Origins (CORS)', - name: 'allowedOrigins', - type: 'string', - default: '*', - description: - 'Comma-separated list of URLs allowed for cross-origin non-preflight requests. Use * (default) to allow all origins.', - }, -]; diff --git a/packages/core/src/Credentials.ts b/packages/core/src/credentials.ts similarity index 96% rename from packages/core/src/Credentials.ts rename to packages/core/src/credentials.ts index f5f8eb834f..9b5b4c1455 100644 --- a/packages/core/src/Credentials.ts +++ b/packages/core/src/credentials.ts @@ -2,7 +2,7 @@ import { Container } from '@n8n/di'; import type { ICredentialDataDecryptedObject, ICredentialsEncrypted } from 'n8n-workflow'; import { ApplicationError, ICredentials, jsonParse } from 'n8n-workflow'; -import { Cipher } from './Cipher'; +import { Cipher } from '@/encryption/cipher'; export class Credentials< T extends object = ICredentialDataDecryptedObject, diff --git a/packages/core/test/Cipher.test.ts b/packages/core/src/encryption/__tests__/cipher.test.ts similarity index 87% rename from packages/core/test/Cipher.test.ts rename to packages/core/src/encryption/__tests__/cipher.test.ts index 7f6bcdedf3..c1e14a9be0 100644 --- a/packages/core/test/Cipher.test.ts +++ b/packages/core/src/encryption/__tests__/cipher.test.ts @@ -1,9 +1,9 @@ import { Container } from '@n8n/di'; -import { Cipher } from '@/Cipher'; -import { InstanceSettings } from '@/InstanceSettings'; +import { InstanceSettings } from '@/instance-settings'; +import { mockInstance } from '@test/utils'; -import { mockInstance } from './utils'; +import { Cipher } from '../cipher'; describe('Cipher', () => { mockInstance(InstanceSettings, { encryptionKey: 'test_key' }); diff --git a/packages/core/src/Cipher.ts b/packages/core/src/encryption/cipher.ts similarity index 96% rename from packages/core/src/Cipher.ts rename to packages/core/src/encryption/cipher.ts index 812c8f452a..248ca0317b 100644 --- a/packages/core/src/Cipher.ts +++ b/packages/core/src/encryption/cipher.ts @@ -1,7 +1,7 @@ import { Service } from '@n8n/di'; import { createHash, createCipheriv, createDecipheriv, randomBytes } from 'crypto'; -import { InstanceSettings } from './InstanceSettings'; +import { InstanceSettings } from '@/instance-settings'; // Data encrypted by CryptoJS always starts with these bytes const RANDOM_BYTES = Buffer.from('53616c7465645f5f', 'hex'); diff --git a/packages/core/src/encryption/index.ts b/packages/core/src/encryption/index.ts new file mode 100644 index 0000000000..b2ab9e782e --- /dev/null +++ b/packages/core/src/encryption/index.ts @@ -0,0 +1 @@ +export { Cipher } from './cipher'; diff --git a/packages/core/test/error-reporter.test.ts b/packages/core/src/errors/__tests__/error-reporter.test.ts similarity index 99% rename from packages/core/test/error-reporter.test.ts rename to packages/core/src/errors/__tests__/error-reporter.test.ts index e5b51d3356..ff260ea1f7 100644 --- a/packages/core/test/error-reporter.test.ts +++ b/packages/core/src/errors/__tests__/error-reporter.test.ts @@ -4,9 +4,10 @@ import { AxiosError } from 'axios'; import { mock } from 'jest-mock-extended'; import { ApplicationError } from 'n8n-workflow'; -import { ErrorReporter } from '@/error-reporter'; import type { Logger } from '@/logging/logger'; +import { ErrorReporter } from '../error-reporter'; + jest.mock('@sentry/node', () => ({ init: jest.fn(), setTag: jest.fn(), diff --git a/packages/core/src/error-reporter.ts b/packages/core/src/errors/error-reporter.ts similarity index 98% rename from packages/core/src/error-reporter.ts rename to packages/core/src/errors/error-reporter.ts index 5444b0d410..3c0bffcd4b 100644 --- a/packages/core/src/error-reporter.ts +++ b/packages/core/src/errors/error-reporter.ts @@ -6,8 +6,8 @@ import { AxiosError } from 'axios'; import { ApplicationError, ExecutionCancelledError, type ReportingOptions } from 'n8n-workflow'; import { createHash } from 'node:crypto'; -import type { InstanceType } from './InstanceSettings'; -import { Logger } from './logging/logger'; +import type { InstanceType } from '@/instance-settings'; +import { Logger } from '@/logging/logger'; type ErrorReporterInitOptions = { serverType: InstanceType | 'task_runner'; diff --git a/packages/core/src/errors/index.ts b/packages/core/src/errors/index.ts index 38cd481c25..b6571dd336 100644 --- a/packages/core/src/errors/index.ts +++ b/packages/core/src/errors/index.ts @@ -5,3 +5,5 @@ export { InvalidManagerError } from './invalid-manager.error'; export { InvalidExecutionMetadataError } from './invalid-execution-metadata.error'; export { UnrecognizedCredentialTypeError } from './unrecognized-credential-type.error'; export { UnrecognizedNodeTypeError } from './unrecognized-node-type.error'; + +export { ErrorReporter } from './error-reporter'; diff --git a/packages/core/src/errors/invalid-mode.error.ts b/packages/core/src/errors/invalid-mode.error.ts index 179582911a..1e3a4f3594 100644 --- a/packages/core/src/errors/invalid-mode.error.ts +++ b/packages/core/src/errors/invalid-mode.error.ts @@ -1,6 +1,6 @@ import { ApplicationError } from 'n8n-workflow'; -import { CONFIG_MODES } from '../BinaryData/utils'; +import { CONFIG_MODES } from '../binary-data/utils'; export class InvalidModeError extends ApplicationError { constructor() { diff --git a/packages/core/src/__tests__/ActiveWorkflows.test.ts b/packages/core/src/execution-engine/__tests__/active-workflows.test.ts similarity index 96% rename from packages/core/src/__tests__/ActiveWorkflows.test.ts rename to packages/core/src/execution-engine/__tests__/active-workflows.test.ts index 410b4779ba..2d96a36488 100644 --- a/packages/core/src/__tests__/ActiveWorkflows.test.ts +++ b/packages/core/src/execution-engine/__tests__/active-workflows.test.ts @@ -12,11 +12,12 @@ import type { } from 'n8n-workflow'; import { LoggerProxy, TriggerCloseError, WorkflowActivationError } from 'n8n-workflow'; -import { ActiveWorkflows } from '@/ActiveWorkflows'; -import type { ErrorReporter } from '@/error-reporter'; -import type { PollContext } from '@/node-execution-context'; -import type { ScheduledTaskManager } from '@/ScheduledTaskManager'; -import type { TriggersAndPollers } from '@/TriggersAndPollers'; +import type { ErrorReporter } from '@/errors/error-reporter'; + +import { ActiveWorkflows } from '../active-workflows'; +import type { PollContext } from '../node-execution-context'; +import type { ScheduledTaskManager } from '../scheduled-task-manager'; +import type { TriggersAndPollers } from '../triggers-and-pollers'; describe('ActiveWorkflows', () => { const workflowId = 'test-workflow-id'; diff --git a/packages/core/test/RoutingNode.test.ts b/packages/core/src/execution-engine/__tests__/routing-node.test.ts similarity index 99% rename from packages/core/test/RoutingNode.test.ts rename to packages/core/src/execution-engine/__tests__/routing-node.test.ts index 45ef937803..5203cff3da 100644 --- a/packages/core/test/RoutingNode.test.ts +++ b/packages/core/src/execution-engine/__tests__/routing-node.test.ts @@ -21,10 +21,10 @@ import type { } from 'n8n-workflow'; import { NodeHelpers, Workflow } from 'n8n-workflow'; -import * as executionContexts from '@/node-execution-context'; -import { RoutingNode } from '@/RoutingNode'; +import * as executionContexts from '@/execution-engine/node-execution-context'; +import { NodeTypes } from '@test/helpers'; -import { NodeTypes } from './helpers'; +import { RoutingNode } from '../routing-node'; const postReceiveFunction1 = async function ( this: IExecuteSingleFunctions, diff --git a/packages/core/test/ScheduledTaskManager.test.ts b/packages/core/src/execution-engine/__tests__/scheduled-task-manager.test.ts similarity index 94% rename from packages/core/test/ScheduledTaskManager.test.ts rename to packages/core/src/execution-engine/__tests__/scheduled-task-manager.test.ts index 5166240856..4c39d3afbc 100644 --- a/packages/core/test/ScheduledTaskManager.test.ts +++ b/packages/core/src/execution-engine/__tests__/scheduled-task-manager.test.ts @@ -1,8 +1,9 @@ import { mock } from 'jest-mock-extended'; import type { Workflow } from 'n8n-workflow'; -import type { InstanceSettings } from '@/InstanceSettings'; -import { ScheduledTaskManager } from '@/ScheduledTaskManager'; +import type { InstanceSettings } from '@/instance-settings'; + +import { ScheduledTaskManager } from '../scheduled-task-manager'; describe('ScheduledTaskManager', () => { const instanceSettings = mock({ isLeader: true }); diff --git a/packages/core/test/SSHClientsManager.test.ts b/packages/core/src/execution-engine/__tests__/ssh-clients-manager.test.ts similarity index 97% rename from packages/core/test/SSHClientsManager.test.ts rename to packages/core/src/execution-engine/__tests__/ssh-clients-manager.test.ts index 132a54baef..d58fe22802 100644 --- a/packages/core/test/SSHClientsManager.test.ts +++ b/packages/core/src/execution-engine/__tests__/ssh-clients-manager.test.ts @@ -1,7 +1,7 @@ import type { SSHCredentials } from 'n8n-workflow'; import { Client } from 'ssh2'; -import { SSHClientsManager } from '@/SSHClientsManager'; +import { SSHClientsManager } from '../ssh-clients-manager'; describe('SSHClientsManager', () => { const credentials: SSHCredentials = { diff --git a/packages/core/test/TriggersAndPollers.test.ts b/packages/core/src/execution-engine/__tests__/triggers-and-pollers.test.ts similarity index 98% rename from packages/core/test/TriggersAndPollers.test.ts rename to packages/core/src/execution-engine/__tests__/triggers-and-pollers.test.ts index 27cc8b47d9..0b7b9cd4a4 100644 --- a/packages/core/test/TriggersAndPollers.test.ts +++ b/packages/core/src/execution-engine/__tests__/triggers-and-pollers.test.ts @@ -13,7 +13,7 @@ import type { IRun, } from 'n8n-workflow'; -import { TriggersAndPollers } from '@/TriggersAndPollers'; +import { TriggersAndPollers } from '../triggers-and-pollers'; describe('TriggersAndPollers', () => { const node = mock(); diff --git a/packages/core/test/WorkflowExecute.test.ts b/packages/core/src/execution-engine/__tests__/workflow-execute.test.ts similarity index 99% rename from packages/core/test/WorkflowExecute.test.ts rename to packages/core/src/execution-engine/__tests__/workflow-execute.test.ts index 6ab3afdaeb..3bdc4b5c78 100644 --- a/packages/core/test/WorkflowExecute.test.ts +++ b/packages/core/src/execution-engine/__tests__/workflow-execute.test.ts @@ -37,13 +37,13 @@ import { Workflow, } from 'n8n-workflow'; -import { DirectedGraph } from '@/PartialExecutionUtils'; -import * as partialExecutionUtils from '@/PartialExecutionUtils'; -import { createNodeData, toITaskData } from '@/PartialExecutionUtils/__tests__/helpers'; -import { WorkflowExecute } from '@/WorkflowExecute'; +import * as Helpers from '@test/helpers'; +import { legacyWorkflowExecuteTests, v1WorkflowExecuteTests } from '@test/helpers/constants'; -import * as Helpers from './helpers'; -import { legacyWorkflowExecuteTests, v1WorkflowExecuteTests } from './helpers/constants'; +import { DirectedGraph } from '../partial-execution-utils'; +import * as partialExecutionUtils from '../partial-execution-utils'; +import { createNodeData, toITaskData } from '../partial-execution-utils/__tests__/helpers'; +import { WorkflowExecute } from '../workflow-execute'; const nodeTypes = Helpers.NodeTypes(); diff --git a/packages/core/test/workflows/error_outputs.json b/packages/core/src/execution-engine/__tests__/workflows/error_outputs.json similarity index 100% rename from packages/core/test/workflows/error_outputs.json rename to packages/core/src/execution-engine/__tests__/workflows/error_outputs.json diff --git a/packages/core/test/workflows/paired_items_fix.json b/packages/core/src/execution-engine/__tests__/workflows/paired_items_fix.json similarity index 100% rename from packages/core/test/workflows/paired_items_fix.json rename to packages/core/src/execution-engine/__tests__/workflows/paired_items_fix.json diff --git a/packages/core/src/ActiveWorkflows.ts b/packages/core/src/execution-engine/active-workflows.ts similarity index 95% rename from packages/core/src/ActiveWorkflows.ts rename to packages/core/src/execution-engine/active-workflows.ts index abd544956a..50aa3853be 100644 --- a/packages/core/src/ActiveWorkflows.ts +++ b/packages/core/src/execution-engine/active-workflows.ts @@ -18,11 +18,12 @@ import { WorkflowDeactivationError, } from 'n8n-workflow'; -import { ErrorReporter } from './error-reporter'; -import type { IWorkflowData } from './Interfaces'; -import { Logger } from './logging/logger'; -import { ScheduledTaskManager } from './ScheduledTaskManager'; -import { TriggersAndPollers } from './TriggersAndPollers'; +import { ErrorReporter } from '@/errors/error-reporter'; +import type { IWorkflowData } from '@/interfaces'; +import { Logger } from '@/logging/logger'; + +import { ScheduledTaskManager } from './scheduled-task-manager'; +import { TriggersAndPollers } from './triggers-and-pollers'; @Service() export class ActiveWorkflows { diff --git a/packages/core/src/execution-engine/index.ts b/packages/core/src/execution-engine/index.ts new file mode 100644 index 0000000000..1523e93a11 --- /dev/null +++ b/packages/core/src/execution-engine/index.ts @@ -0,0 +1,6 @@ +export * from './active-workflows'; +export * from './routing-node'; +export * from './node-execution-context'; +export * from './partial-execution-utils'; +export * from './node-execution-context/utils/execution-metadata'; +export * from './workflow-execute'; diff --git a/packages/core/src/node-execution-context/__tests__/execute-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/execute-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/execute-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/execute-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/execute-single-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/execute-single-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/execute-single-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/execute-single-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/hook-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/hook-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/hook-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/hook-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/load-options-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/load-options-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/load-options-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/load-options-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/node-execution-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/node-execution-context.test.ts similarity index 99% rename from packages/core/src/node-execution-context/__tests__/node-execution-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/node-execution-context.test.ts index a0a368df4c..6a10c2bba5 100644 --- a/packages/core/src/node-execution-context/__tests__/node-execution-context.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/__tests__/node-execution-context.test.ts @@ -12,7 +12,7 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; -import { InstanceSettings } from '@/InstanceSettings'; +import { InstanceSettings } from '@/instance-settings'; import { NodeExecutionContext } from '../node-execution-context'; diff --git a/packages/core/src/node-execution-context/__tests__/poll-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/poll-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/poll-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/poll-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/shared-tests.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/shared-tests.ts similarity index 98% rename from packages/core/src/node-execution-context/__tests__/shared-tests.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/shared-tests.ts index 8b1d23930b..601b49fe4c 100644 --- a/packages/core/src/node-execution-context/__tests__/shared-tests.ts +++ b/packages/core/src/execution-engine/node-execution-context/__tests__/shared-tests.ts @@ -17,7 +17,7 @@ import type { } from 'n8n-workflow'; import { ApplicationError, NodeHelpers, WAIT_INDEFINITELY } from 'n8n-workflow'; -import { BinaryDataService } from '@/BinaryData/BinaryData.service'; +import { BinaryDataService } from '@/binary-data/binary-data.service'; import type { BaseExecuteContext } from '../base-execute-context'; diff --git a/packages/core/src/node-execution-context/__tests__/supply-data-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/supply-data-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/supply-data-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/supply-data-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/trigger-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/trigger-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/trigger-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/trigger-context.test.ts diff --git a/packages/core/src/node-execution-context/__tests__/webhook-context.test.ts b/packages/core/src/execution-engine/node-execution-context/__tests__/webhook-context.test.ts similarity index 100% rename from packages/core/src/node-execution-context/__tests__/webhook-context.test.ts rename to packages/core/src/execution-engine/node-execution-context/__tests__/webhook-context.test.ts diff --git a/packages/core/src/node-execution-context/base-execute-context.ts b/packages/core/src/execution-engine/node-execution-context/base-execute-context.ts similarity index 98% rename from packages/core/src/node-execution-context/base-execute-context.ts rename to packages/core/src/execution-engine/node-execution-context/base-execute-context.ts index 0416870344..1c4bba34e3 100644 --- a/packages/core/src/node-execution-context/base-execute-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/base-execute-context.ts @@ -29,7 +29,7 @@ import { WorkflowDataProxy, } from 'n8n-workflow'; -import { BinaryDataService } from '@/BinaryData/BinaryData.service'; +import { BinaryDataService } from '@/binary-data/binary-data.service'; import { NodeExecutionContext } from './node-execution-context'; diff --git a/packages/core/src/node-execution-context/execute-context.ts b/packages/core/src/execution-engine/node-execution-context/execute-context.ts similarity index 97% rename from packages/core/src/node-execution-context/execute-context.ts rename to packages/core/src/execution-engine/node-execution-context/execute-context.ts index 089c3f500a..7b3ec16bf5 100644 --- a/packages/core/src/node-execution-context/execute-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/execute-context.ts @@ -37,10 +37,10 @@ import { getFileSystemHelperFunctions, getCheckProcessedHelperFunctions, detectBinaryEncoding, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { BaseExecuteContext } from './base-execute-context'; -import { getInputConnectionData } from './utils/getInputConnectionData'; +import { getInputConnectionData } from './utils/get-input-connection-data'; export class ExecuteContext extends BaseExecuteContext implements IExecuteFunctions { readonly helpers: IExecuteFunctions['helpers']; diff --git a/packages/core/src/node-execution-context/execute-single-context.ts b/packages/core/src/execution-engine/node-execution-context/execute-single-context.ts similarity index 98% rename from packages/core/src/node-execution-context/execute-single-context.ts rename to packages/core/src/execution-engine/node-execution-context/execute-single-context.ts index af837a12c5..2ba450b593 100644 --- a/packages/core/src/node-execution-context/execute-single-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/execute-single-context.ts @@ -21,7 +21,7 @@ import { getBinaryHelperFunctions, getRequestHelperFunctions, returnJsonArray, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { BaseExecuteContext } from './base-execute-context'; diff --git a/packages/core/src/node-execution-context/hook-context.ts b/packages/core/src/execution-engine/node-execution-context/hook-context.ts similarity index 97% rename from packages/core/src/node-execution-context/hook-context.ts rename to packages/core/src/execution-engine/node-execution-context/hook-context.ts index 102be563a1..28dbac802c 100644 --- a/packages/core/src/node-execution-context/hook-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/hook-context.ts @@ -16,7 +16,7 @@ import { getNodeWebhookUrl, getRequestHelperFunctions, getWebhookDescription, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { NodeExecutionContext } from './node-execution-context'; diff --git a/packages/core/src/node-execution-context/index.ts b/packages/core/src/execution-engine/node-execution-context/index.ts similarity index 90% rename from packages/core/src/node-execution-context/index.ts rename to packages/core/src/execution-engine/node-execution-context/index.ts index c3bcebbd44..4c96322211 100644 --- a/packages/core/src/node-execution-context/index.ts +++ b/packages/core/src/execution-engine/node-execution-context/index.ts @@ -10,4 +10,4 @@ export { SupplyDataContext } from './supply-data-context'; export { TriggerContext } from './trigger-context'; export { WebhookContext } from './webhook-context'; -export { getAdditionalKeys } from './utils/getAdditionalKeys'; +export { getAdditionalKeys } from './utils/get-additional-keys'; diff --git a/packages/core/src/node-execution-context/load-options-context.ts b/packages/core/src/execution-engine/node-execution-context/load-options-context.ts similarity index 95% rename from packages/core/src/node-execution-context/load-options-context.ts rename to packages/core/src/execution-engine/node-execution-context/load-options-context.ts index c961b56c06..30c31eacce 100644 --- a/packages/core/src/node-execution-context/load-options-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/load-options-context.ts @@ -9,11 +9,11 @@ import type { Workflow, } from 'n8n-workflow'; -import { extractValue } from '@/ExtractValue'; // eslint-disable-next-line import/no-cycle -import { getRequestHelperFunctions, getSSHTunnelFunctions } from '@/NodeExecuteFunctions'; +import { getRequestHelperFunctions, getSSHTunnelFunctions } from '@/node-execute-functions'; import { NodeExecutionContext } from './node-execution-context'; +import { extractValue } from './utils/extract-value'; export class LoadOptionsContext extends NodeExecutionContext implements ILoadOptionsFunctions { readonly helpers: ILoadOptionsFunctions['helpers']; diff --git a/packages/core/src/node-execution-context/local-load-options-context.ts b/packages/core/src/execution-engine/node-execution-context/local-load-options-context.ts similarity index 100% rename from packages/core/src/node-execution-context/local-load-options-context.ts rename to packages/core/src/execution-engine/node-execution-context/local-load-options-context.ts diff --git a/packages/core/src/node-execution-context/node-execution-context.ts b/packages/core/src/execution-engine/node-execution-context/node-execution-context.ts similarity index 96% rename from packages/core/src/node-execution-context/node-execution-context.ts rename to packages/core/src/execution-engine/node-execution-context/node-execution-context.ts index 45a205637c..f5f3730244 100644 --- a/packages/core/src/node-execution-context/node-execution-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/node-execution-context.ts @@ -28,16 +28,16 @@ import { NodeOperationError, } from 'n8n-workflow'; -import { HTTP_REQUEST_NODE_TYPE, HTTP_REQUEST_TOOL_NODE_TYPE } from '@/Constants'; +import { HTTP_REQUEST_NODE_TYPE, HTTP_REQUEST_TOOL_NODE_TYPE } from '@/constants'; import { Memoized } from '@/decorators'; -import { extractValue } from '@/ExtractValue'; -import { InstanceSettings } from '@/InstanceSettings'; +import { InstanceSettings } from '@/instance-settings'; import { Logger } from '@/logging/logger'; -import { cleanupParameterData } from './utils/cleanupParameterData'; -import { ensureType } from './utils/ensureType'; -import { getAdditionalKeys } from './utils/getAdditionalKeys'; -import { validateValueAgainstSchema } from './utils/validateValueAgainstSchema'; +import { cleanupParameterData } from './utils/cleanup-parameter-data'; +import { ensureType } from './utils/ensure-type'; +import { extractValue } from './utils/extract-value'; +import { getAdditionalKeys } from './utils/get-additional-keys'; +import { validateValueAgainstSchema } from './utils/validate-value-against-schema'; export abstract class NodeExecutionContext implements Omit { protected readonly instanceSettings = Container.get(InstanceSettings); diff --git a/packages/core/src/node-execution-context/poll-context.ts b/packages/core/src/execution-engine/node-execution-context/poll-context.ts similarity index 97% rename from packages/core/src/node-execution-context/poll-context.ts rename to packages/core/src/execution-engine/node-execution-context/poll-context.ts index ca90a243f4..8ee2c2a692 100644 --- a/packages/core/src/node-execution-context/poll-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/poll-context.ts @@ -15,7 +15,7 @@ import { getRequestHelperFunctions, getSchedulingFunctions, returnJsonArray, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { NodeExecutionContext } from './node-execution-context'; diff --git a/packages/core/src/node-execution-context/supply-data-context.ts b/packages/core/src/execution-engine/node-execution-context/supply-data-context.ts similarity index 98% rename from packages/core/src/node-execution-context/supply-data-context.ts rename to packages/core/src/execution-engine/node-execution-context/supply-data-context.ts index be1f63b56c..dc2ac37a91 100644 --- a/packages/core/src/node-execution-context/supply-data-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/supply-data-context.ts @@ -33,10 +33,10 @@ import { getSSHTunnelFunctions, normalizeItems, returnJsonArray, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { BaseExecuteContext } from './base-execute-context'; -import { getInputConnectionData } from './utils/getInputConnectionData'; +import { getInputConnectionData } from './utils/get-input-connection-data'; export class SupplyDataContext extends BaseExecuteContext implements ISupplyDataFunctions { readonly helpers: ISupplyDataFunctions['helpers']; diff --git a/packages/core/src/node-execution-context/trigger-context.ts b/packages/core/src/execution-engine/node-execution-context/trigger-context.ts similarity index 97% rename from packages/core/src/node-execution-context/trigger-context.ts rename to packages/core/src/execution-engine/node-execution-context/trigger-context.ts index 88c8d91432..845bad61f5 100644 --- a/packages/core/src/node-execution-context/trigger-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/trigger-context.ts @@ -16,7 +16,7 @@ import { getSchedulingFunctions, getSSHTunnelFunctions, returnJsonArray, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { NodeExecutionContext } from './node-execution-context'; diff --git a/packages/core/src/node-execution-context/utils/__tests__/cleanupParameterData.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/cleanup-parameter-data.test.ts similarity index 94% rename from packages/core/src/node-execution-context/utils/__tests__/cleanupParameterData.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/cleanup-parameter-data.test.ts index 47913669b6..a3b22fcdd2 100644 --- a/packages/core/src/node-execution-context/utils/__tests__/cleanupParameterData.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/cleanup-parameter-data.test.ts @@ -2,7 +2,7 @@ import toPlainObject from 'lodash/toPlainObject'; import { DateTime } from 'luxon'; import type { NodeParameterValue } from 'n8n-workflow'; -import { cleanupParameterData } from '../cleanupParameterData'; +import { cleanupParameterData } from '../cleanup-parameter-data'; describe('cleanupParameterData', () => { it('should stringify Luxon dates in-place', () => { diff --git a/packages/core/test/CreateNodeAsTool.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/create-node-as-tool.test.ts similarity index 99% rename from packages/core/test/CreateNodeAsTool.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/create-node-as-tool.test.ts index fdc14269e1..450ec99247 100644 --- a/packages/core/test/CreateNodeAsTool.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/create-node-as-tool.test.ts @@ -2,7 +2,7 @@ import { mock } from 'jest-mock-extended'; import type { INodeType, ISupplyDataFunctions, INode } from 'n8n-workflow'; import { z } from 'zod'; -import { createNodeAsTool } from '@/CreateNodeAsTool'; +import { createNodeAsTool } from '../create-node-as-tool'; jest.mock('@langchain/core/tools', () => ({ DynamicStructuredTool: jest.fn().mockImplementation((config) => ({ diff --git a/packages/core/src/node-execution-context/utils/__tests__/ensureType.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/ensure-type.test.ts similarity index 98% rename from packages/core/src/node-execution-context/utils/__tests__/ensureType.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/ensure-type.test.ts index 1637d988c9..374b3d43bc 100644 --- a/packages/core/src/node-execution-context/utils/__tests__/ensureType.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/ensure-type.test.ts @@ -1,6 +1,6 @@ import { ExpressionError } from 'n8n-workflow'; -import { ensureType } from '../ensureType'; +import { ensureType } from '../ensure-type'; describe('ensureType', () => { it('throws error for null value', () => { diff --git a/packages/core/test/WorkflowExecutionMetadata.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/execution-metadata.test.ts similarity index 99% rename from packages/core/test/WorkflowExecutionMetadata.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/execution-metadata.test.ts index 63d0892e6a..c673a2fcfe 100644 --- a/packages/core/test/WorkflowExecutionMetadata.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/execution-metadata.test.ts @@ -1,13 +1,14 @@ import type { IRunExecutionData } from 'n8n-workflow'; import { InvalidExecutionMetadataError } from '@/errors/invalid-execution-metadata.error'; + import { setWorkflowExecutionMetadata, setAllWorkflowExecutionMetadata, KV_LIMIT, getWorkflowExecutionMetadata, getAllWorkflowExecutionMetadata, -} from '@/ExecutionMetadata'; +} from '../execution-metadata'; describe('Execution Metadata functions', () => { test('setWorkflowExecutionMetadata will set a value', () => { diff --git a/packages/core/src/node-execution-context/utils/__tests__/getAdditionalKeys.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/get-additional-keys.test.ts similarity index 97% rename from packages/core/src/node-execution-context/utils/__tests__/getAdditionalKeys.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/get-additional-keys.test.ts index 6ac1fbdc07..b78de39a6d 100644 --- a/packages/core/src/node-execution-context/utils/__tests__/getAdditionalKeys.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/get-additional-keys.test.ts @@ -7,9 +7,9 @@ import type { SecretsHelpersBase, } from 'n8n-workflow'; -import { PLACEHOLDER_EMPTY_EXECUTION_ID } from '@/Constants'; +import { PLACEHOLDER_EMPTY_EXECUTION_ID } from '@/constants'; -import { getAdditionalKeys } from '../getAdditionalKeys'; +import { getAdditionalKeys } from '../get-additional-keys'; describe('getAdditionalKeys', () => { const secretsHelpers = mock(); diff --git a/packages/core/src/node-execution-context/utils/__tests__/getInputConnectionData.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/get-input-connection-data.test.ts similarity index 100% rename from packages/core/src/node-execution-context/utils/__tests__/getInputConnectionData.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/get-input-connection-data.test.ts diff --git a/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/validate-value-against-schema.test.ts similarity index 98% rename from packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts rename to packages/core/src/execution-engine/node-execution-context/utils/__tests__/validate-value-against-schema.test.ts index d4b96fa41d..4f389856ad 100644 --- a/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/__tests__/validate-value-against-schema.test.ts @@ -1,6 +1,6 @@ import type { IDataObject, INode, INodeType } from 'n8n-workflow'; -import { validateValueAgainstSchema } from '../validateValueAgainstSchema'; +import { validateValueAgainstSchema } from '../validate-value-against-schema'; describe('validateValueAgainstSchema', () => { test('should validate fixedCollection values parameter', () => { diff --git a/packages/core/src/node-execution-context/utils/cleanupParameterData.ts b/packages/core/src/execution-engine/node-execution-context/utils/cleanup-parameter-data.ts similarity index 100% rename from packages/core/src/node-execution-context/utils/cleanupParameterData.ts rename to packages/core/src/execution-engine/node-execution-context/utils/cleanup-parameter-data.ts diff --git a/packages/core/src/CreateNodeAsTool.ts b/packages/core/src/execution-engine/node-execution-context/utils/create-node-as-tool.ts similarity index 100% rename from packages/core/src/CreateNodeAsTool.ts rename to packages/core/src/execution-engine/node-execution-context/utils/create-node-as-tool.ts diff --git a/packages/core/src/node-execution-context/utils/ensureType.ts b/packages/core/src/execution-engine/node-execution-context/utils/ensure-type.ts similarity index 100% rename from packages/core/src/node-execution-context/utils/ensureType.ts rename to packages/core/src/execution-engine/node-execution-context/utils/ensure-type.ts diff --git a/packages/core/src/ExecutionMetadata.ts b/packages/core/src/execution-engine/node-execution-context/utils/execution-metadata.ts similarity index 97% rename from packages/core/src/ExecutionMetadata.ts rename to packages/core/src/execution-engine/node-execution-context/utils/execution-metadata.ts index 8466933e05..5e7c4954d6 100644 --- a/packages/core/src/ExecutionMetadata.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/execution-metadata.ts @@ -1,7 +1,7 @@ import type { IRunExecutionData } from 'n8n-workflow'; import { LoggerProxy as Logger } from 'n8n-workflow'; -import { InvalidExecutionMetadataError } from './errors/invalid-execution-metadata.error'; +import { InvalidExecutionMetadataError } from '@/errors/invalid-execution-metadata.error'; export const KV_LIMIT = 10; diff --git a/packages/core/src/ExtractValue.ts b/packages/core/src/execution-engine/node-execution-context/utils/extract-value.ts similarity index 100% rename from packages/core/src/ExtractValue.ts rename to packages/core/src/execution-engine/node-execution-context/utils/extract-value.ts diff --git a/packages/core/src/node-execution-context/utils/getAdditionalKeys.ts b/packages/core/src/execution-engine/node-execution-context/utils/get-additional-keys.ts similarity index 93% rename from packages/core/src/node-execution-context/utils/getAdditionalKeys.ts rename to packages/core/src/execution-engine/node-execution-context/utils/get-additional-keys.ts index 28bf3b89f6..7e18d0f2d1 100644 --- a/packages/core/src/node-execution-context/utils/getAdditionalKeys.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/get-additional-keys.ts @@ -6,14 +6,15 @@ import type { } from 'n8n-workflow'; import { LoggerProxy } from 'n8n-workflow'; -import { PLACEHOLDER_EMPTY_EXECUTION_ID } from '@/Constants'; +import { PLACEHOLDER_EMPTY_EXECUTION_ID } from '@/constants'; + import { setWorkflowExecutionMetadata, setAllWorkflowExecutionMetadata, getWorkflowExecutionMetadata, getAllWorkflowExecutionMetadata, -} from '@/ExecutionMetadata'; -import { getSecretsProxy } from '@/Secrets'; +} from './execution-metadata'; +import { getSecretsProxy } from './get-secrets-proxy'; /** Returns the additional keys for Expressions and Function-Nodes */ export function getAdditionalKeys( diff --git a/packages/core/src/node-execution-context/utils/getInputConnectionData.ts b/packages/core/src/execution-engine/node-execution-context/utils/get-input-connection-data.ts similarity index 96% rename from packages/core/src/node-execution-context/utils/getInputConnectionData.ts rename to packages/core/src/execution-engine/node-execution-context/utils/get-input-connection-data.ts index 231f672d65..9f76d0e106 100644 --- a/packages/core/src/node-execution-context/utils/getInputConnectionData.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/get-input-connection-data.ts @@ -19,10 +19,10 @@ import { ApplicationError, } from 'n8n-workflow'; -import { createNodeAsTool } from '@/CreateNodeAsTool'; +import { createNodeAsTool } from './create-node-as-tool'; // eslint-disable-next-line import/no-cycle -import { SupplyDataContext } from '@/node-execution-context'; -import type { ExecuteContext, WebhookContext } from '@/node-execution-context'; +import { SupplyDataContext } from '../../node-execution-context'; +import type { ExecuteContext, WebhookContext } from '../../node-execution-context'; export async function getInputConnectionData( this: ExecuteContext | WebhookContext | SupplyDataContext, diff --git a/packages/core/src/Secrets.ts b/packages/core/src/execution-engine/node-execution-context/utils/get-secrets-proxy.ts similarity index 100% rename from packages/core/src/Secrets.ts rename to packages/core/src/execution-engine/node-execution-context/utils/get-secrets-proxy.ts diff --git a/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts b/packages/core/src/execution-engine/node-execution-context/utils/validate-value-against-schema.ts similarity index 98% rename from packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts rename to packages/core/src/execution-engine/node-execution-context/utils/validate-value-against-schema.ts index a4c1b211e7..58744adf03 100644 --- a/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts +++ b/packages/core/src/execution-engine/node-execution-context/utils/validate-value-against-schema.ts @@ -14,7 +14,7 @@ import { validateFieldType, } from 'n8n-workflow'; -import type { ExtendedValidationResult } from '@/Interfaces'; +import type { ExtendedValidationResult } from '@/interfaces'; const validateResourceMapperValue = ( parameterName: string, diff --git a/packages/core/src/node-execution-context/webhook-context.ts b/packages/core/src/execution-engine/node-execution-context/webhook-context.ts similarity index 97% rename from packages/core/src/node-execution-context/webhook-context.ts rename to packages/core/src/execution-engine/node-execution-context/webhook-context.ts index 9d131a4103..d5b55cffb6 100644 --- a/packages/core/src/node-execution-context/webhook-context.ts +++ b/packages/core/src/execution-engine/node-execution-context/webhook-context.ts @@ -25,10 +25,10 @@ import { getNodeWebhookUrl, getRequestHelperFunctions, returnJsonArray, -} from '@/NodeExecuteFunctions'; +} from '@/node-execute-functions'; import { NodeExecutionContext } from './node-execution-context'; -import { getInputConnectionData } from './utils/getInputConnectionData'; +import { getInputConnectionData } from './utils/get-input-connection-data'; export class WebhookContext extends NodeExecutionContext implements IWebhookFunctions { readonly helpers: IWebhookFunctions['helpers']; diff --git a/packages/core/src/node-execution-context/workflow-node-context.ts b/packages/core/src/execution-engine/node-execution-context/workflow-node-context.ts similarity index 100% rename from packages/core/src/node-execution-context/workflow-node-context.ts rename to packages/core/src/execution-engine/node-execution-context/workflow-node-context.ts diff --git a/packages/core/src/PartialExecutionUtils/__tests__/cleanRunData.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/clean-run-data.test.ts similarity index 97% rename from packages/core/src/PartialExecutionUtils/__tests__/cleanRunData.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/clean-run-data.test.ts index 959ab78845..7de648e6fd 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/cleanRunData.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/clean-run-data.test.ts @@ -1,8 +1,8 @@ import type { IRunData } from 'n8n-workflow'; import { createNodeData, toITaskData } from './helpers'; -import { cleanRunData } from '../cleanRunData'; -import { DirectedGraph } from '../DirectedGraph'; +import { cleanRunData } from '../clean-run-data'; +import { DirectedGraph } from '../directed-graph'; describe('cleanRunData', () => { // ┌─────┐ ┌─────┐ ┌─────┐ diff --git a/packages/core/src/PartialExecutionUtils/__tests__/DirectedGraph.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/directed-graph.test.ts similarity index 99% rename from packages/core/src/PartialExecutionUtils/__tests__/DirectedGraph.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/directed-graph.test.ts index 5d769004a5..a825c144a9 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/DirectedGraph.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/directed-graph.test.ts @@ -13,7 +13,7 @@ import type { INode } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import { createNodeData, defaultWorkflowParameter } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; +import { DirectedGraph } from '../directed-graph'; describe('DirectedGraph', () => { // ┌─────┐ ┌─────┐ ┌─────┐ diff --git a/packages/core/src/PartialExecutionUtils/__tests__/filterDisabledNodes.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/filter-disabled-nodes.test.ts similarity index 97% rename from packages/core/src/PartialExecutionUtils/__tests__/filterDisabledNodes.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/filter-disabled-nodes.test.ts index 7e60e009a8..69348720f7 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/filterDisabledNodes.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/filter-disabled-nodes.test.ts @@ -12,8 +12,8 @@ import { NodeConnectionType } from 'n8n-workflow'; import { createNodeData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { filterDisabledNodes } from '../filterDisabledNodes'; +import { DirectedGraph } from '../directed-graph'; +import { filterDisabledNodes } from '../filter-disabled-nodes'; describe('filterDisabledNodes', () => { // XX diff --git a/packages/core/src/PartialExecutionUtils/__tests__/findStartNodes.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/find-start-nodes.test.ts similarity index 99% rename from packages/core/src/PartialExecutionUtils/__tests__/findStartNodes.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/find-start-nodes.test.ts index f2a99fdb92..a0c86515c2 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/findStartNodes.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/find-start-nodes.test.ts @@ -12,8 +12,8 @@ import { type IPinData, type IRunData } from 'n8n-workflow'; import { createNodeData, toITaskData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { findStartNodes, isDirty } from '../findStartNodes'; +import { DirectedGraph } from '../directed-graph'; +import { findStartNodes, isDirty } from '../find-start-nodes'; describe('isDirty', () => { test("if the node has pinned data it's not dirty", () => { diff --git a/packages/core/src/PartialExecutionUtils/__tests__/findSubgraph.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/find-subgraph.test.ts similarity index 99% rename from packages/core/src/PartialExecutionUtils/__tests__/findSubgraph.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/find-subgraph.test.ts index e479214e10..1a6382017a 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/findSubgraph.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/find-subgraph.test.ts @@ -12,8 +12,8 @@ import { NodeConnectionType } from 'n8n-workflow'; import { createNodeData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { findSubgraph } from '../findSubgraph'; +import { DirectedGraph } from '../directed-graph'; +import { findSubgraph } from '../find-subgraph'; describe('findSubgraph', () => { // ►► diff --git a/packages/core/src/PartialExecutionUtils/__tests__/getSourceDataGroups.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/get-source-data-groups.test.ts similarity index 99% rename from packages/core/src/PartialExecutionUtils/__tests__/getSourceDataGroups.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/get-source-data-groups.test.ts index d8c3485d65..872a452aa7 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/getSourceDataGroups.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/get-source-data-groups.test.ts @@ -11,8 +11,8 @@ import type { IPinData } from 'n8n-workflow'; import { NodeConnectionType, type IRunData } from 'n8n-workflow'; import { createNodeData, toITaskData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { getSourceDataGroups } from '../getSourceDataGroups'; +import { DirectedGraph } from '../directed-graph'; +import { getSourceDataGroups } from '../get-source-data-groups'; describe('getSourceDataGroups', () => { //┌───────┐1 diff --git a/packages/core/src/PartialExecutionUtils/__tests__/handleCycles.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/handle-cycles.test.ts similarity index 98% rename from packages/core/src/PartialExecutionUtils/__tests__/handleCycles.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/handle-cycles.test.ts index def9fed0ff..06ed5daf47 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/handleCycles.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/handle-cycles.test.ts @@ -10,8 +10,8 @@ // PD denotes that the node has pinned data import { createNodeData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { handleCycles } from '../handleCycles'; +import { DirectedGraph } from '../directed-graph'; +import { handleCycles } from '../handle-cycles'; describe('handleCycles', () => { // ┌────┐ ┌─────────┐ diff --git a/packages/core/src/PartialExecutionUtils/__tests__/helpers.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/helpers.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/__tests__/helpers.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/helpers.ts diff --git a/packages/core/src/PartialExecutionUtils/__tests__/recreateNodeExecutionStack.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/recreate-node-execution-stack.test.ts similarity index 99% rename from packages/core/src/PartialExecutionUtils/__tests__/recreateNodeExecutionStack.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/recreate-node-execution-stack.test.ts index b78b9df135..0f20896e21 100644 --- a/packages/core/src/PartialExecutionUtils/__tests__/recreateNodeExecutionStack.test.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/__tests__/recreate-node-execution-stack.test.ts @@ -18,15 +18,14 @@ import type { } from 'n8n-workflow'; import { NodeConnectionType, type IPinData, type IRunData } from 'n8n-workflow'; +import { createNodeData, toITaskData } from './helpers'; +import { DirectedGraph } from '../directed-graph'; +import { findSubgraph } from '../find-subgraph'; import { addWaitingExecution, addWaitingExecutionSource, recreateNodeExecutionStack, -} from '@/PartialExecutionUtils/recreateNodeExecutionStack'; - -import { createNodeData, toITaskData } from './helpers'; -import { DirectedGraph } from '../DirectedGraph'; -import { findSubgraph } from '../findSubgraph'; +} from '../recreate-node-execution-stack'; describe('recreateNodeExecutionStack', () => { // ►► diff --git a/packages/core/src/PartialExecutionUtils/__tests__/toIConnections.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/to-iconnections.test.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/__tests__/toIConnections.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/to-iconnections.test.ts diff --git a/packages/core/src/PartialExecutionUtils/__tests__/toITaskData.test.ts b/packages/core/src/execution-engine/partial-execution-utils/__tests__/to-itask-data.test.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/__tests__/toITaskData.test.ts rename to packages/core/src/execution-engine/partial-execution-utils/__tests__/to-itask-data.test.ts diff --git a/packages/core/src/PartialExecutionUtils/cleanRunData.ts b/packages/core/src/execution-engine/partial-execution-utils/clean-run-data.ts similarity index 93% rename from packages/core/src/PartialExecutionUtils/cleanRunData.ts rename to packages/core/src/execution-engine/partial-execution-utils/clean-run-data.ts index 6ed5db6100..78d08acd9b 100644 --- a/packages/core/src/PartialExecutionUtils/cleanRunData.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/clean-run-data.ts @@ -1,6 +1,6 @@ import type { INode, IRunData } from 'n8n-workflow'; -import type { DirectedGraph } from './DirectedGraph'; +import type { DirectedGraph } from './directed-graph'; /** * Returns new run data that does not contain data for any node that is a child diff --git a/packages/core/src/PartialExecutionUtils/DirectedGraph.ts b/packages/core/src/execution-engine/partial-execution-utils/directed-graph.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/DirectedGraph.ts rename to packages/core/src/execution-engine/partial-execution-utils/directed-graph.ts diff --git a/packages/core/src/PartialExecutionUtils/filterDisabledNodes.ts b/packages/core/src/execution-engine/partial-execution-utils/filter-disabled-nodes.ts similarity index 88% rename from packages/core/src/PartialExecutionUtils/filterDisabledNodes.ts rename to packages/core/src/execution-engine/partial-execution-utils/filter-disabled-nodes.ts index c381f70759..af9ffb3512 100644 --- a/packages/core/src/PartialExecutionUtils/filterDisabledNodes.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/filter-disabled-nodes.ts @@ -1,6 +1,6 @@ import { NodeConnectionType } from 'n8n-workflow'; -import type { DirectedGraph } from './DirectedGraph'; +import type { DirectedGraph } from './directed-graph'; export function filterDisabledNodes(graph: DirectedGraph): DirectedGraph { const filteredGraph = graph.clone(); diff --git a/packages/core/src/PartialExecutionUtils/findStartNodes.ts b/packages/core/src/execution-engine/partial-execution-utils/find-start-nodes.ts similarity index 98% rename from packages/core/src/PartialExecutionUtils/findStartNodes.ts rename to packages/core/src/execution-engine/partial-execution-utils/find-start-nodes.ts index 1c1c0b9fc7..d7b3fb522d 100644 --- a/packages/core/src/PartialExecutionUtils/findStartNodes.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/find-start-nodes.ts @@ -1,7 +1,7 @@ import { NodeConnectionType, type INode, type IPinData, type IRunData } from 'n8n-workflow'; -import type { DirectedGraph } from './DirectedGraph'; -import { getIncomingData, getIncomingDataFromAnyRun } from './getIncomingData'; +import type { DirectedGraph } from './directed-graph'; +import { getIncomingData, getIncomingDataFromAnyRun } from './get-incoming-data'; /** * A node is dirty if either of the following is true: diff --git a/packages/core/src/PartialExecutionUtils/findSubgraph.ts b/packages/core/src/execution-engine/partial-execution-utils/find-subgraph.ts similarity index 97% rename from packages/core/src/PartialExecutionUtils/findSubgraph.ts rename to packages/core/src/execution-engine/partial-execution-utils/find-subgraph.ts index 039124c1ad..f333f4764e 100644 --- a/packages/core/src/PartialExecutionUtils/findSubgraph.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/find-subgraph.ts @@ -1,7 +1,7 @@ import { NodeConnectionType, type INode } from 'n8n-workflow'; -import type { GraphConnection } from './DirectedGraph'; -import { DirectedGraph } from './DirectedGraph'; +import type { GraphConnection } from './directed-graph'; +import { DirectedGraph } from './directed-graph'; function findSubgraphRecursive( graph: DirectedGraph, diff --git a/packages/core/src/PartialExecutionUtils/findTriggerForPartialExecution.ts b/packages/core/src/execution-engine/partial-execution-utils/find-trigger-for-partial-execution.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/findTriggerForPartialExecution.ts rename to packages/core/src/execution-engine/partial-execution-utils/find-trigger-for-partial-execution.ts diff --git a/packages/core/src/PartialExecutionUtils/getIncomingData.ts b/packages/core/src/execution-engine/partial-execution-utils/get-incoming-data.ts similarity index 100% rename from packages/core/src/PartialExecutionUtils/getIncomingData.ts rename to packages/core/src/execution-engine/partial-execution-utils/get-incoming-data.ts diff --git a/packages/core/src/PartialExecutionUtils/getSourceDataGroups.ts b/packages/core/src/execution-engine/partial-execution-utils/get-source-data-groups.ts similarity index 98% rename from packages/core/src/PartialExecutionUtils/getSourceDataGroups.ts rename to packages/core/src/execution-engine/partial-execution-utils/get-source-data-groups.ts index d9a9940816..d96aba3062 100644 --- a/packages/core/src/PartialExecutionUtils/getSourceDataGroups.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/get-source-data-groups.ts @@ -1,6 +1,6 @@ import { type INode, type IPinData, type IRunData } from 'n8n-workflow'; -import type { GraphConnection, DirectedGraph } from './DirectedGraph'; +import type { GraphConnection, DirectedGraph } from './directed-graph'; function sortByInputIndexThenByName( connection1: GraphConnection, diff --git a/packages/core/src/PartialExecutionUtils/handleCycles.ts b/packages/core/src/execution-engine/partial-execution-utils/handle-cycles.ts similarity index 96% rename from packages/core/src/PartialExecutionUtils/handleCycles.ts rename to packages/core/src/execution-engine/partial-execution-utils/handle-cycles.ts index 94a8ae8cbc..1e52b491ed 100644 --- a/packages/core/src/PartialExecutionUtils/handleCycles.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/handle-cycles.ts @@ -1,7 +1,7 @@ import type { INode } from 'n8n-workflow'; import * as a from 'node:assert/strict'; -import type { DirectedGraph } from './DirectedGraph'; +import type { DirectedGraph } from './directed-graph'; /** * Returns a new set of start nodes. diff --git a/packages/core/src/execution-engine/partial-execution-utils/index.ts b/packages/core/src/execution-engine/partial-execution-utils/index.ts new file mode 100644 index 0000000000..d363f52302 --- /dev/null +++ b/packages/core/src/execution-engine/partial-execution-utils/index.ts @@ -0,0 +1,8 @@ +export { DirectedGraph } from './directed-graph'; +export { findTriggerForPartialExecution } from './find-trigger-for-partial-execution'; +export { findStartNodes } from './find-start-nodes'; +export { findSubgraph } from './find-subgraph'; +export { recreateNodeExecutionStack } from './recreate-node-execution-stack'; +export { cleanRunData } from './clean-run-data'; +export { handleCycles } from './handle-cycles'; +export { filterDisabledNodes } from './filter-disabled-nodes'; diff --git a/packages/core/src/PartialExecutionUtils/recreateNodeExecutionStack.ts b/packages/core/src/execution-engine/partial-execution-utils/recreate-node-execution-stack.ts similarity index 97% rename from packages/core/src/PartialExecutionUtils/recreateNodeExecutionStack.ts rename to packages/core/src/execution-engine/partial-execution-utils/recreate-node-execution-stack.ts index 542d4b8fbd..95aced2515 100644 --- a/packages/core/src/PartialExecutionUtils/recreateNodeExecutionStack.ts +++ b/packages/core/src/execution-engine/partial-execution-utils/recreate-node-execution-stack.ts @@ -12,9 +12,9 @@ import { type IWaitingForExecutionSource, } from 'n8n-workflow'; -import type { DirectedGraph } from './DirectedGraph'; -import { getIncomingDataFromAnyRun } from './getIncomingData'; -import { getSourceDataGroups } from './getSourceDataGroups'; +import type { DirectedGraph } from './directed-graph'; +import { getIncomingDataFromAnyRun } from './get-incoming-data'; +import { getSourceDataGroups } from './get-source-data-groups'; export function addWaitingExecution( waitingExecution: IWaitingForExecution, diff --git a/packages/core/src/RoutingNode.ts b/packages/core/src/execution-engine/routing-node.ts similarity index 100% rename from packages/core/src/RoutingNode.ts rename to packages/core/src/execution-engine/routing-node.ts diff --git a/packages/core/src/ScheduledTaskManager.ts b/packages/core/src/execution-engine/scheduled-task-manager.ts similarity index 95% rename from packages/core/src/ScheduledTaskManager.ts rename to packages/core/src/execution-engine/scheduled-task-manager.ts index 0c33f9872c..1a20700b00 100644 --- a/packages/core/src/ScheduledTaskManager.ts +++ b/packages/core/src/execution-engine/scheduled-task-manager.ts @@ -2,7 +2,7 @@ import { Service } from '@n8n/di'; import { CronJob } from 'cron'; import type { CronExpression, Workflow } from 'n8n-workflow'; -import { InstanceSettings } from './InstanceSettings'; +import { InstanceSettings } from '@/instance-settings'; @Service() export class ScheduledTaskManager { diff --git a/packages/core/src/SSHClientsManager.ts b/packages/core/src/execution-engine/ssh-clients-manager.ts similarity index 100% rename from packages/core/src/SSHClientsManager.ts rename to packages/core/src/execution-engine/ssh-clients-manager.ts diff --git a/packages/core/src/TriggersAndPollers.ts b/packages/core/src/execution-engine/triggers-and-pollers.ts similarity index 100% rename from packages/core/src/TriggersAndPollers.ts rename to packages/core/src/execution-engine/triggers-and-pollers.ts diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/execution-engine/workflow-execute.ts similarity index 99% rename from packages/core/src/WorkflowExecute.ts rename to packages/core/src/execution-engine/workflow-execute.ts index ffd3b57f50..2eb7a9e7fe 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/execution-engine/workflow-execute.ts @@ -55,9 +55,10 @@ import { } from 'n8n-workflow'; import PCancelable from 'p-cancelable'; -import { ErrorReporter } from './error-reporter'; +import { ErrorReporter } from '@/errors/error-reporter'; +import * as NodeExecuteFunctions from '@/node-execute-functions'; + import { ExecuteContext, PollContext } from './node-execution-context'; -import * as NodeExecuteFunctions from './NodeExecuteFunctions'; import { DirectedGraph, findStartNodes, @@ -67,9 +68,9 @@ import { recreateNodeExecutionStack, handleCycles, filterDisabledNodes, -} from './PartialExecutionUtils'; -import { RoutingNode } from './RoutingNode'; -import { TriggersAndPollers } from './TriggersAndPollers'; +} from './partial-execution-utils'; +import { RoutingNode } from './routing-node'; +import { TriggersAndPollers } from './triggers-and-pollers'; export class WorkflowExecute { private status: ExecutionStatus = 'new'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7abbd9ad9a..12aa968fcc 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,29 +1,18 @@ -import * as NodeExecuteFunctions from './NodeExecuteFunctions'; +import * as NodeExecuteFunctions from './node-execute-functions'; -export * from './decorators'; -export * from './errors'; -export * from './ActiveWorkflows'; -export * from './BinaryData/BinaryData.service'; -export * from './BinaryData/types'; -export { Cipher } from './Cipher'; -export * from './Constants'; -export * from './Credentials'; -export * from './DirectoryLoader'; -export * from './Interfaces'; -export { InstanceSettings, InstanceType } from './InstanceSettings'; -export { Logger } from './logging/logger'; -export * from './NodeExecuteFunctions'; -export * from './RoutingNode'; -export * from './WorkflowExecute'; -export { NodeExecuteFunctions }; +export * from './binary-data'; +export * from './constants'; +export * from './credentials'; export * from './data-deduplication-service'; +export * from './decorators'; +export * from './encryption'; export * from './errors'; -export { ObjectStoreService } from './ObjectStore/ObjectStore.service.ee'; -export { BinaryData } from './BinaryData/types'; -export { isStoredMode as isValidNonDefaultMode } from './BinaryData/utils'; -export * from './ExecutionMetadata'; -export * from './node-execution-context'; -export * from './PartialExecutionUtils'; -export { ErrorReporter } from './error-reporter'; -export * from './SerializedBuffer'; -export { isObjectLiteral } from './utils'; +export * from './execution-engine'; +export * from './instance-settings'; +export * from './logging'; +export * from './nodes-loader'; +export * from './utils'; + +export * from './interfaces'; +export * from './node-execute-functions'; +export { NodeExecuteFunctions }; diff --git a/packages/core/test/InstanceSettings.test.ts b/packages/core/src/instance-settings/__tests__/instance-settings.test.ts similarity index 98% rename from packages/core/test/InstanceSettings.test.ts rename to packages/core/src/instance-settings/__tests__/instance-settings.test.ts index 203a77a94b..b57ed99f09 100644 --- a/packages/core/test/InstanceSettings.test.ts +++ b/packages/core/src/instance-settings/__tests__/instance-settings.test.ts @@ -2,11 +2,10 @@ import { mock } from 'jest-mock-extended'; jest.mock('node:fs', () => mock()); import * as fs from 'node:fs'; -import { InstanceSettings } from '@/InstanceSettings'; -import { InstanceSettingsConfig } from '@/InstanceSettingsConfig'; +import { InstanceSettings } from '@/instance-settings'; +import { InstanceSettingsConfig } from '@/instance-settings/instance-settings-config'; import { Logger } from '@/logging/logger'; - -import { mockInstance } from './utils'; +import { mockInstance } from '@test/utils'; describe('InstanceSettings', () => { const userFolder = '/test'; diff --git a/packages/core/src/instance-settings/index.ts b/packages/core/src/instance-settings/index.ts new file mode 100644 index 0000000000..74b05f5d98 --- /dev/null +++ b/packages/core/src/instance-settings/index.ts @@ -0,0 +1 @@ +export { InstanceSettings, InstanceType } from './instance-settings'; diff --git a/packages/core/src/InstanceSettingsConfig.ts b/packages/core/src/instance-settings/instance-settings-config.ts similarity index 100% rename from packages/core/src/InstanceSettingsConfig.ts rename to packages/core/src/instance-settings/instance-settings-config.ts diff --git a/packages/core/src/InstanceSettings.ts b/packages/core/src/instance-settings/instance-settings.ts similarity index 98% rename from packages/core/src/InstanceSettings.ts rename to packages/core/src/instance-settings/instance-settings.ts index 53d9f72d6d..5f8a68596b 100644 --- a/packages/core/src/InstanceSettings.ts +++ b/packages/core/src/instance-settings/instance-settings.ts @@ -5,10 +5,10 @@ import { customAlphabet } from 'nanoid'; import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'; import path from 'path'; +import { Memoized } from '@/decorators'; import { Logger } from '@/logging/logger'; -import { Memoized } from './decorators'; -import { InstanceSettingsConfig } from './InstanceSettingsConfig'; +import { InstanceSettingsConfig } from './instance-settings-config'; const nanoid = customAlphabet(ALPHABET, 16); diff --git a/packages/core/src/Interfaces.ts b/packages/core/src/interfaces.ts similarity index 73% rename from packages/core/src/Interfaces.ts rename to packages/core/src/interfaces.ts index 2963e46185..a00176eee9 100644 --- a/packages/core/src/Interfaces.ts +++ b/packages/core/src/interfaces.ts @@ -20,19 +20,4 @@ export interface IWorkflowData { triggerResponses?: ITriggerResponse[]; } -export namespace n8n { - export interface PackageJson { - name: string; - version: string; - n8n?: { - credentials?: string[]; - nodes?: string[]; - }; - author?: { - name?: string; - email?: string; - }; - } -} - export type ExtendedValidationResult = ValidationResult & { fieldName?: string }; diff --git a/packages/core/src/logging/__tests__/logger.test.ts b/packages/core/src/logging/__tests__/logger.test.ts index d34eaf250a..1a9ee8e7ef 100644 --- a/packages/core/src/logging/__tests__/logger.test.ts +++ b/packages/core/src/logging/__tests__/logger.test.ts @@ -7,7 +7,7 @@ import type { GlobalConfig } from '@n8n/config'; import { mock } from 'jest-mock-extended'; import { LoggerProxy } from 'n8n-workflow'; -import type { InstanceSettingsConfig } from '@/InstanceSettingsConfig'; +import type { InstanceSettingsConfig } from '@/instance-settings/instance-settings-config'; import { Logger } from '../logger'; diff --git a/packages/core/src/logging/index.ts b/packages/core/src/logging/index.ts new file mode 100644 index 0000000000..a1332e91c6 --- /dev/null +++ b/packages/core/src/logging/index.ts @@ -0,0 +1 @@ +export { Logger } from './logger'; diff --git a/packages/core/src/logging/logger.ts b/packages/core/src/logging/logger.ts index 8115f93c86..82a47649ff 100644 --- a/packages/core/src/logging/logger.ts +++ b/packages/core/src/logging/logger.ts @@ -14,9 +14,9 @@ import path, { basename } from 'node:path'; import pc from 'picocolors'; import winston from 'winston'; -import { inDevelopment, inProduction } from '@/Constants'; -import { InstanceSettingsConfig } from '@/InstanceSettingsConfig'; -import { isObjectLiteral } from '@/utils'; +import { inDevelopment, inProduction } from '@/constants'; +import { InstanceSettingsConfig } from '@/instance-settings/instance-settings-config'; +import { isObjectLiteral } from '@/utils/is-object-literal'; const noOp = () => {}; diff --git a/packages/core/src/NodeExecuteFunctions.ts b/packages/core/src/node-execute-functions.ts similarity index 99% rename from packages/core/src/NodeExecuteFunctions.ts rename to packages/core/src/node-execute-functions.ts index 9504ad1c78..fc94dc3434 100644 --- a/packages/core/src/NodeExecuteFunctions.ts +++ b/packages/core/src/node-execute-functions.ts @@ -98,9 +98,9 @@ import url, { URL, URLSearchParams } from 'url'; import { Logger } from '@/logging/logger'; -import { BinaryDataService } from './BinaryData/BinaryData.service'; -import type { BinaryData } from './BinaryData/types'; -import { binaryToBuffer } from './BinaryData/utils'; +import { BinaryDataService } from './binary-data/binary-data.service'; +import type { BinaryData } from './binary-data/types'; +import { binaryToBuffer } from './binary-data/utils'; import { BINARY_DATA_STORAGE_PATH, BLOCK_FILE_ACCESS_TO_N8N_FILES, @@ -109,14 +109,14 @@ import { RESTRICT_FILE_ACCESS_TO, UM_EMAIL_TEMPLATES_INVITE, UM_EMAIL_TEMPLATES_PWRESET, -} from './Constants'; +} from './constants'; import { DataDeduplicationService } from './data-deduplication-service'; -import { InstanceSettings } from './InstanceSettings'; -import type { IResponseError } from './Interfaces'; // eslint-disable-next-line import/no-cycle -import { PollContext, TriggerContext } from './node-execution-context'; -import { ScheduledTaskManager } from './ScheduledTaskManager'; -import { SSHClientsManager } from './SSHClientsManager'; +import { PollContext, TriggerContext } from './execution-engine/node-execution-context'; +import { ScheduledTaskManager } from './execution-engine/scheduled-task-manager'; +import { SSHClientsManager } from './execution-engine/ssh-clients-manager'; +import { InstanceSettings } from './instance-settings'; +import type { IResponseError } from './interfaces'; axios.defaults.timeout = 300000; // Prevent axios from adding x-form-www-urlencoded headers by default diff --git a/packages/core/src/node-execution-context/helpers/binary-helpers.ts b/packages/core/src/node-execution-context/helpers/binary-helpers.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/core/test/DirectoryLoader.test.ts b/packages/core/src/nodes-loader/__tests__/directory-loader.test.ts similarity index 98% rename from packages/core/test/DirectoryLoader.test.ts rename to packages/core/src/nodes-loader/__tests__/directory-loader.test.ts index 226b5a6fee..cb66300257 100644 --- a/packages/core/test/DirectoryLoader.test.ts +++ b/packages/core/src/nodes-loader/__tests__/directory-loader.test.ts @@ -22,12 +22,10 @@ jest.mock('fast-glob', () => async (pattern: string) => { : ['dist/Credential1.js']; }); -import * as classLoader from '@/ClassLoader'; -import { - CustomDirectoryLoader, - PackageDirectoryLoader, - LazyPackageDirectoryLoader, -} from '@/DirectoryLoader'; +import { CustomDirectoryLoader } from '../custom-directory-loader'; +import { LazyPackageDirectoryLoader } from '../lazy-package-directory-loader'; +import * as classLoader from '../load-class-in-isolation'; +import { PackageDirectoryLoader } from '../package-directory-loader'; describe('DirectoryLoader', () => { const directory = '/not/a/real/path'; diff --git a/packages/core/test/ClassLoader.test.ts b/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts similarity index 93% rename from packages/core/test/ClassLoader.test.ts rename to packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts index 9527572662..656830fa87 100644 --- a/packages/core/test/ClassLoader.test.ts +++ b/packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts @@ -1,8 +1,8 @@ import vm from 'vm'; -import { loadClassInIsolation } from '@/ClassLoader'; +import { loadClassInIsolation } from '../load-class-in-isolation'; -describe('ClassLoader', () => { +describe('loadClassInIsolation', () => { const filePath = '/path/to/TestClass.js'; const className = 'TestClass'; diff --git a/packages/core/src/nodes-loader/constants.ts b/packages/core/src/nodes-loader/constants.ts new file mode 100644 index 0000000000..171be0352b --- /dev/null +++ b/packages/core/src/nodes-loader/constants.ts @@ -0,0 +1,31 @@ +import type { INodeProperties } from 'n8n-workflow'; +import { cronNodeOptions } from 'n8n-workflow'; + +export const CUSTOM_NODES_CATEGORY = 'Custom Nodes'; + +export const commonPollingParameters: INodeProperties[] = [ + { + displayName: 'Poll Times', + name: 'pollTimes', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + multipleValueButtonText: 'Add Poll Time', + }, + default: { item: [{ mode: 'everyMinute' }] }, + description: 'Time at which polling should occur', + placeholder: 'Add Poll Time', + options: cronNodeOptions, + }, +]; + +export const commonCORSParameters: INodeProperties[] = [ + { + displayName: 'Allowed Origins (CORS)', + name: 'allowedOrigins', + type: 'string', + default: '*', + description: + 'Comma-separated list of URLs allowed for cross-origin non-preflight requests. Use * (default) to allow all origins.', + }, +]; diff --git a/packages/core/src/nodes-loader/custom-directory-loader.ts b/packages/core/src/nodes-loader/custom-directory-loader.ts new file mode 100644 index 0000000000..8e84440608 --- /dev/null +++ b/packages/core/src/nodes-loader/custom-directory-loader.ts @@ -0,0 +1,31 @@ +import glob from 'fast-glob'; + +import { DirectoryLoader } from './directory-loader'; + +/** + * Loader for source files of nodes and credentials located in a custom dir, + * e.g. `~/.n8n/custom` + */ +export class CustomDirectoryLoader extends DirectoryLoader { + packageName = 'CUSTOM'; + + override async loadAll() { + const nodes = await glob('**/*.node.js', { + cwd: this.directory, + absolute: true, + }); + + for (const nodePath of nodes) { + this.loadNodeFromFile(nodePath); + } + + const credentials = await glob('**/*.credentials.js', { + cwd: this.directory, + absolute: true, + }); + + for (const credentialPath of credentials) { + this.loadCredentialFromFile(credentialPath); + } + } +} diff --git a/packages/core/src/DirectoryLoader.ts b/packages/core/src/nodes-loader/directory-loader.ts similarity index 66% rename from packages/core/src/DirectoryLoader.ts rename to packages/core/src/nodes-loader/directory-loader.ts index 559c0c5531..094aa8d1e0 100644 --- a/packages/core/src/DirectoryLoader.ts +++ b/packages/core/src/nodes-loader/directory-loader.ts @@ -1,5 +1,4 @@ import { Container } from '@n8n/di'; -import glob from 'fast-glob'; import uniqBy from 'lodash/uniqBy'; import type { CodexData, @@ -16,18 +15,15 @@ import type { IVersionedNodeType, KnownNodesAndCredentials, } from 'n8n-workflow'; -import { ApplicationError, applyDeclarativeNodeOptionParameters, jsonParse } from 'n8n-workflow'; -import { readFileSync } from 'node:fs'; -import { readFile } from 'node:fs/promises'; +import { ApplicationError, applyDeclarativeNodeOptionParameters } from 'n8n-workflow'; import * as path from 'path'; +import { UnrecognizedCredentialTypeError } from '@/errors/unrecognized-credential-type.error'; +import { UnrecognizedNodeTypeError } from '@/errors/unrecognized-node-type.error'; import { Logger } from '@/logging/logger'; -import { loadClassInIsolation } from './ClassLoader'; -import { commonCORSParameters, commonPollingParameters, CUSTOM_NODES_CATEGORY } from './Constants'; -import { UnrecognizedCredentialTypeError } from './errors/unrecognized-credential-type.error'; -import { UnrecognizedNodeTypeError } from './errors/unrecognized-node-type.error'; -import type { n8n } from './Interfaces'; +import { commonCORSParameters, commonPollingParameters, CUSTOM_NODES_CATEGORY } from './constants'; +import { loadClassInIsolation } from './load-class-in-isolation'; function toJSON(this: ICredentialType) { return { @@ -395,183 +391,3 @@ export abstract class DirectoryLoader { } } } - -/** - * Loader for source files of nodes and credentials located in a custom dir, - * e.g. `~/.n8n/custom` - */ -export class CustomDirectoryLoader extends DirectoryLoader { - packageName = 'CUSTOM'; - - override async loadAll() { - const nodes = await glob('**/*.node.js', { - cwd: this.directory, - absolute: true, - }); - - for (const nodePath of nodes) { - this.loadNodeFromFile(nodePath); - } - - const credentials = await glob('**/*.credentials.js', { - cwd: this.directory, - absolute: true, - }); - - for (const credentialPath of credentials) { - this.loadCredentialFromFile(credentialPath); - } - } -} - -/** - * Loader for source files of nodes and credentials located in a package dir, - * e.g. /nodes-base or community packages. - */ -export class PackageDirectoryLoader extends DirectoryLoader { - packageJson: n8n.PackageJson; - - packageName: string; - - constructor(directory: string, excludeNodes: string[] = [], includeNodes: string[] = []) { - super(directory, excludeNodes, includeNodes); - - this.packageJson = this.readJSONSync('package.json'); - this.packageName = this.packageJson.name; - this.excludeNodes = this.extractNodeTypes(excludeNodes); - this.includeNodes = this.extractNodeTypes(includeNodes); - } - - private extractNodeTypes(fullNodeTypes: string[]) { - return fullNodeTypes - .map((fullNodeType) => fullNodeType.split('.')) - .filter(([packageName]) => packageName === this.packageName) - .map(([_, nodeType]) => nodeType); - } - - override async loadAll() { - const { n8n } = this.packageJson; - if (!n8n) return; - - const { nodes, credentials } = n8n; - - if (Array.isArray(nodes)) { - for (const nodePath of nodes) { - this.loadNodeFromFile(nodePath); - } - } - - if (Array.isArray(credentials)) { - for (const credentialPath of credentials) { - this.loadCredentialFromFile(credentialPath); - } - } - - this.inferSupportedNodes(); - - this.logger.debug(`Loaded all credentials and nodes from ${this.packageName}`, { - credentials: credentials?.length ?? 0, - nodes: nodes?.length ?? 0, - }); - } - - private inferSupportedNodes() { - const knownCredentials = this.known.credentials; - for (const { type: credentialType } of Object.values(this.credentialTypes)) { - const supportedNodes = knownCredentials[credentialType.name].supportedNodes ?? []; - if (supportedNodes.length > 0 && credentialType.httpRequestNode) { - credentialType.httpRequestNode.hidden = true; - } - - credentialType.supportedNodes = supportedNodes; - - if (!credentialType.iconUrl && !credentialType.icon) { - for (const supportedNode of supportedNodes) { - const nodeDescription = this.nodeTypes[supportedNode]?.type.description; - - if (!nodeDescription) continue; - if (nodeDescription.icon) { - credentialType.icon = nodeDescription.icon; - credentialType.iconColor = nodeDescription.iconColor; - break; - } - if (nodeDescription.iconUrl) { - credentialType.iconUrl = nodeDescription.iconUrl; - break; - } - } - } - } - } - - private parseJSON(fileString: string, filePath: string): T { - try { - return jsonParse(fileString); - } catch (error) { - throw new ApplicationError('Failed to parse JSON', { extra: { filePath } }); - } - } - - protected readJSONSync(file: string): T { - const filePath = this.resolvePath(file); - const fileString = readFileSync(filePath, 'utf8'); - return this.parseJSON(fileString, filePath); - } - - protected async readJSON(file: string): Promise { - const filePath = this.resolvePath(file); - const fileString = await readFile(filePath, 'utf8'); - return this.parseJSON(fileString, filePath); - } -} - -/** - * This loader extends PackageDirectoryLoader to load node and credentials lazily, if possible - */ -export class LazyPackageDirectoryLoader extends PackageDirectoryLoader { - override async loadAll() { - try { - this.known.nodes = await this.readJSON('dist/known/nodes.json'); - this.known.credentials = await this.readJSON('dist/known/credentials.json'); - - this.types.nodes = await this.readJSON('dist/types/nodes.json'); - this.types.credentials = await this.readJSON('dist/types/credentials.json'); - - if (this.includeNodes.length) { - const allowedNodes: typeof this.known.nodes = {}; - for (const nodeType of this.includeNodes) { - if (nodeType in this.known.nodes) { - allowedNodes[nodeType] = this.known.nodes[nodeType]; - } - } - this.known.nodes = allowedNodes; - - this.types.nodes = this.types.nodes.filter((nodeType) => - this.includeNodes.includes(nodeType.name), - ); - } - - if (this.excludeNodes.length) { - for (const nodeType of this.excludeNodes) { - delete this.known.nodes[nodeType]; - } - - this.types.nodes = this.types.nodes.filter( - (nodeType) => !this.excludeNodes.includes(nodeType.name), - ); - } - - this.logger.debug(`Lazy-loading nodes and credentials from ${this.packageJson.name}`, { - nodes: this.types.nodes?.length ?? 0, - credentials: this.types.credentials?.length ?? 0, - }); - - this.isLazyLoaded = true; - - return; // We can load nodes and credentials lazily now - } catch { - this.logger.debug("Can't enable lazy-loading"); - await super.loadAll(); - } - } -} diff --git a/packages/core/src/nodes-loader/index.ts b/packages/core/src/nodes-loader/index.ts new file mode 100644 index 0000000000..f8fedca5be --- /dev/null +++ b/packages/core/src/nodes-loader/index.ts @@ -0,0 +1,5 @@ +export { DirectoryLoader, type Types } from './directory-loader'; +export { CustomDirectoryLoader } from './custom-directory-loader'; +export { PackageDirectoryLoader } from './package-directory-loader'; +export { LazyPackageDirectoryLoader } from './lazy-package-directory-loader'; +export type { n8n } from './types'; diff --git a/packages/core/src/nodes-loader/lazy-package-directory-loader.ts b/packages/core/src/nodes-loader/lazy-package-directory-loader.ts new file mode 100644 index 0000000000..5da6084e1a --- /dev/null +++ b/packages/core/src/nodes-loader/lazy-package-directory-loader.ts @@ -0,0 +1,52 @@ +import { PackageDirectoryLoader } from './package-directory-loader'; + +/** + * This loader extends PackageDirectoryLoader to load node and credentials lazily, if possible + */ +export class LazyPackageDirectoryLoader extends PackageDirectoryLoader { + override async loadAll() { + try { + this.known.nodes = await this.readJSON('dist/known/nodes.json'); + this.known.credentials = await this.readJSON('dist/known/credentials.json'); + + this.types.nodes = await this.readJSON('dist/types/nodes.json'); + this.types.credentials = await this.readJSON('dist/types/credentials.json'); + + if (this.includeNodes.length) { + const allowedNodes: typeof this.known.nodes = {}; + for (const nodeType of this.includeNodes) { + if (nodeType in this.known.nodes) { + allowedNodes[nodeType] = this.known.nodes[nodeType]; + } + } + this.known.nodes = allowedNodes; + + this.types.nodes = this.types.nodes.filter((nodeType) => + this.includeNodes.includes(nodeType.name), + ); + } + + if (this.excludeNodes.length) { + for (const nodeType of this.excludeNodes) { + delete this.known.nodes[nodeType]; + } + + this.types.nodes = this.types.nodes.filter( + (nodeType) => !this.excludeNodes.includes(nodeType.name), + ); + } + + this.logger.debug(`Lazy-loading nodes and credentials from ${this.packageJson.name}`, { + nodes: this.types.nodes?.length ?? 0, + credentials: this.types.credentials?.length ?? 0, + }); + + this.isLazyLoaded = true; + + return; // We can load nodes and credentials lazily now + } catch { + this.logger.debug("Can't enable lazy-loading"); + await super.loadAll(); + } + } +} diff --git a/packages/core/src/ClassLoader.ts b/packages/core/src/nodes-loader/load-class-in-isolation.ts similarity index 100% rename from packages/core/src/ClassLoader.ts rename to packages/core/src/nodes-loader/load-class-in-isolation.ts diff --git a/packages/core/src/nodes-loader/package-directory-loader.ts b/packages/core/src/nodes-loader/package-directory-loader.ts new file mode 100644 index 0000000000..4c46a684ec --- /dev/null +++ b/packages/core/src/nodes-loader/package-directory-loader.ts @@ -0,0 +1,107 @@ +import { ApplicationError, jsonParse } from 'n8n-workflow'; +import { readFileSync } from 'node:fs'; +import { readFile } from 'node:fs/promises'; + +import { DirectoryLoader } from './directory-loader'; +import type { n8n } from './types'; + +/** + * Loader for source files of nodes and credentials located in a package dir, + * e.g. /nodes-base or community packages. + */ +export class PackageDirectoryLoader extends DirectoryLoader { + packageJson: n8n.PackageJson; + + packageName: string; + + constructor(directory: string, excludeNodes: string[] = [], includeNodes: string[] = []) { + super(directory, excludeNodes, includeNodes); + + this.packageJson = this.readJSONSync('package.json'); + this.packageName = this.packageJson.name; + this.excludeNodes = this.extractNodeTypes(excludeNodes); + this.includeNodes = this.extractNodeTypes(includeNodes); + } + + private extractNodeTypes(fullNodeTypes: string[]) { + return fullNodeTypes + .map((fullNodeType) => fullNodeType.split('.')) + .filter(([packageName]) => packageName === this.packageName) + .map(([_, nodeType]) => nodeType); + } + + override async loadAll() { + const { n8n } = this.packageJson; + if (!n8n) return; + + const { nodes, credentials } = n8n; + + if (Array.isArray(nodes)) { + for (const nodePath of nodes) { + this.loadNodeFromFile(nodePath); + } + } + + if (Array.isArray(credentials)) { + for (const credentialPath of credentials) { + this.loadCredentialFromFile(credentialPath); + } + } + + this.inferSupportedNodes(); + + this.logger.debug(`Loaded all credentials and nodes from ${this.packageName}`, { + credentials: credentials?.length ?? 0, + nodes: nodes?.length ?? 0, + }); + } + + private inferSupportedNodes() { + const knownCredentials = this.known.credentials; + for (const { type: credentialType } of Object.values(this.credentialTypes)) { + const supportedNodes = knownCredentials[credentialType.name].supportedNodes ?? []; + if (supportedNodes.length > 0 && credentialType.httpRequestNode) { + credentialType.httpRequestNode.hidden = true; + } + + credentialType.supportedNodes = supportedNodes; + + if (!credentialType.iconUrl && !credentialType.icon) { + for (const supportedNode of supportedNodes) { + const nodeDescription = this.nodeTypes[supportedNode]?.type.description; + + if (!nodeDescription) continue; + if (nodeDescription.icon) { + credentialType.icon = nodeDescription.icon; + credentialType.iconColor = nodeDescription.iconColor; + break; + } + if (nodeDescription.iconUrl) { + credentialType.iconUrl = nodeDescription.iconUrl; + break; + } + } + } + } + } + + private parseJSON(fileString: string, filePath: string): T { + try { + return jsonParse(fileString); + } catch (error) { + throw new ApplicationError('Failed to parse JSON', { extra: { filePath } }); + } + } + + protected readJSONSync(file: string): T { + const filePath = this.resolvePath(file); + const fileString = readFileSync(filePath, 'utf8'); + return this.parseJSON(fileString, filePath); + } + + protected async readJSON(file: string): Promise { + const filePath = this.resolvePath(file); + const fileString = await readFile(filePath, 'utf8'); + return this.parseJSON(fileString, filePath); + } +} diff --git a/packages/core/src/nodes-loader/types.ts b/packages/core/src/nodes-loader/types.ts new file mode 100644 index 0000000000..e898c44b2d --- /dev/null +++ b/packages/core/src/nodes-loader/types.ts @@ -0,0 +1,14 @@ +export namespace n8n { + export interface PackageJson { + name: string; + version: string; + n8n?: { + credentials?: string[]; + nodes?: string[]; + }; + author?: { + name?: string; + email?: string; + }; + } +} diff --git a/packages/core/src/__tests__/utils.test.ts b/packages/core/src/utils/__tests__/is-object-literal.test.ts similarity index 95% rename from packages/core/src/__tests__/utils.test.ts rename to packages/core/src/utils/__tests__/is-object-literal.test.ts index a8532ed589..f6c3cfddd0 100644 --- a/packages/core/src/__tests__/utils.test.ts +++ b/packages/core/src/utils/__tests__/is-object-literal.test.ts @@ -1,4 +1,4 @@ -import { isObjectLiteral } from '@/utils'; +import { isObjectLiteral } from '../is-object-literal'; describe('isObjectLiteral', () => { test.each([ diff --git a/packages/core/test/SerializedBuffer.test.ts b/packages/core/src/utils/__tests__/serialized-buffer.test.ts similarity index 92% rename from packages/core/test/SerializedBuffer.test.ts rename to packages/core/src/utils/__tests__/serialized-buffer.test.ts index 95d7213401..19b7df496d 100644 --- a/packages/core/test/SerializedBuffer.test.ts +++ b/packages/core/src/utils/__tests__/serialized-buffer.test.ts @@ -1,5 +1,5 @@ -import type { SerializedBuffer } from '@/SerializedBuffer'; -import { toBuffer, isSerializedBuffer } from '@/SerializedBuffer'; +import type { SerializedBuffer } from '../serialized-buffer'; +import { toBuffer, isSerializedBuffer } from '../serialized-buffer'; // Mock data for tests const validSerializedBuffer: SerializedBuffer = { diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts new file mode 100644 index 0000000000..4973c13417 --- /dev/null +++ b/packages/core/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from './serialized-buffer'; +export { isObjectLiteral } from './is-object-literal'; diff --git a/packages/core/src/utils.ts b/packages/core/src/utils/is-object-literal.ts similarity index 100% rename from packages/core/src/utils.ts rename to packages/core/src/utils/is-object-literal.ts diff --git a/packages/core/src/SerializedBuffer.ts b/packages/core/src/utils/serialized-buffer.ts similarity index 91% rename from packages/core/src/SerializedBuffer.ts rename to packages/core/src/utils/serialized-buffer.ts index d6ea874c7a..e98e1a0883 100644 --- a/packages/core/src/SerializedBuffer.ts +++ b/packages/core/src/utils/serialized-buffer.ts @@ -1,4 +1,4 @@ -import { isObjectLiteral } from '@/utils'; +import { isObjectLiteral } from './is-object-literal'; /** A nodejs Buffer gone through JSON.stringify */ export type SerializedBuffer = { diff --git a/packages/core/test/helpers/index.ts b/packages/core/test/helpers/index.ts index 14f19789b0..28cec2dff2 100644 --- a/packages/core/test/helpers/index.ts +++ b/packages/core/test/helpers/index.ts @@ -85,8 +85,7 @@ const preparePinData = (pinData: IDataObject) => { return returnData; }; -const readJsonFileSync = (filePath: string) => - JSON.parse(readFileSync(path.join(BASE_DIR, filePath), 'utf-8')) as T; +const readJsonFileSync = (filePath: string) => JSON.parse(readFileSync(filePath, 'utf-8')) as T; export function getNodeTypes(testData: WorkflowTestData[] | WorkflowTestData) { if (!Array.isArray(testData)) { @@ -100,7 +99,7 @@ export function getNodeTypes(testData: WorkflowTestData[] | WorkflowTestData) { const nodeNames = nodes.map((n) => n.type); const knownNodes = readJsonFileSync>( - 'nodes-base/dist/known/nodes.json', + path.join(BASE_DIR, 'nodes-base/dist/known/nodes.json'), ); for (const nodeName of nodeNames) { @@ -120,14 +119,14 @@ export function getNodeTypes(testData: WorkflowTestData[] | WorkflowTestData) { return nodeTypes; } -const getWorkflowFilenames = (dirname: string, testFolder = 'workflows') => { +const getWorkflowFilepaths = (dirname: string, testFolder = 'workflows') => { const workflows: string[] = []; const filenames: string[] = readdirSync(`${dirname}${path.sep}${testFolder}`); filenames.forEach((file) => { if (file.endsWith('.json')) { - workflows.push(path.join('core', 'test', testFolder, file)); + workflows.push(path.join(dirname, testFolder, file)); } }); @@ -135,11 +134,11 @@ const getWorkflowFilenames = (dirname: string, testFolder = 'workflows') => { }; export const workflowToTests = (dirname: string, testFolder = 'workflows') => { - const workflowFiles: string[] = getWorkflowFilenames(dirname, testFolder); + const workflowFilepaths: string[] = getWorkflowFilepaths(dirname, testFolder); const testCases: WorkflowTestData[] = []; - for (const filePath of workflowFiles) { + for (const filePath of workflowFilepaths) { const description = filePath.replace('.json', ''); const workflowData = readJsonFileSync(filePath); if (workflowData.pinData === undefined) { diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 111dd828dd..0fbcc8b81a 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -4,7 +4,8 @@ "rootDir": ".", "baseUrl": "src", "paths": { - "@/*": ["./*"] + "@/*": ["./*"], + "@test/*": ["../test/*"] }, "tsBuildInfoFile": "dist/typecheck.tsbuildinfo", "emitDecoratorMetadata": true, diff --git a/packages/nodes-base/test/nodes/TriggerHelpers.ts b/packages/nodes-base/test/nodes/TriggerHelpers.ts index 7e04dcaa86..5348cab08c 100644 --- a/packages/nodes-base/test/nodes/TriggerHelpers.ts +++ b/packages/nodes-base/test/nodes/TriggerHelpers.ts @@ -4,7 +4,7 @@ import get from 'lodash/get'; import merge from 'lodash/merge'; import set from 'lodash/set'; import { PollContext, returnJsonArray, type InstanceSettings } from 'n8n-core'; -import { ScheduledTaskManager } from 'n8n-core/dist/ScheduledTaskManager'; +import { ScheduledTaskManager } from 'n8n-core/dist/execution-engine/scheduled-task-manager'; import type { IBinaryData, ICredentialDataDecryptedObject,