refactor(core): Move execution engine code out of n8n-workflow (no-changelog) (#12147)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-12-12 13:54:44 +01:00
committed by GitHub
parent 73f0c4cca9
commit 5a055ed526
44 changed files with 1995 additions and 1795 deletions

View File

@@ -1,70 +1,16 @@
import { readFileSync } from 'fs';
import { mock } from 'jest-mock-extended';
import get from 'lodash/get';
import path from 'path';
import type {
IExecuteSingleFunctions,
IHttpRequestOptions,
IN8nHttpFullResponse,
IN8nHttpResponse,
INode,
INodeTypes,
IRunExecutionData,
} from '@/Interfaces';
import type { Workflow } from '@/Workflow';
import type { INodeTypes } from '@/Interfaces';
import { NodeTypes as NodeTypesClass } from './NodeTypes';
export function getExecuteSingleFunctions(
workflow: Workflow,
runExecutionData: IRunExecutionData,
runIndex: number,
node: INode,
itemIndex: number,
): IExecuteSingleFunctions {
return mock<IExecuteSingleFunctions>({
getItemIndex: () => itemIndex,
getNodeParameter: (parameterName: string) => {
return workflow.expression.getParameterValue(
get(node.parameters, parameterName),
runExecutionData,
runIndex,
itemIndex,
node.name,
[],
'internal',
{},
);
},
getWorkflow: () => ({
id: workflow.id,
name: workflow.name,
active: workflow.active,
}),
helpers: mock<IExecuteSingleFunctions['helpers']>({
async httpRequest(
requestOptions: IHttpRequestOptions,
): Promise<IN8nHttpFullResponse | IN8nHttpResponse> {
return {
body: {
headers: {},
statusCode: 200,
requestOptions,
},
};
},
}),
});
}
let nodeTypesInstance: NodeTypesClass | undefined;
export function NodeTypes(): INodeTypes {
if (nodeTypesInstance === undefined) {
nodeTypesInstance = new NodeTypesClass();
}
return nodeTypesInstance;
}