mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(Code Tool Node): Replace vm2 with taskrunner for js (#19247)
This commit is contained in:
@@ -22,8 +22,12 @@ export class JsTaskRunnerSandbox {
|
||||
private readonly jsCode: string,
|
||||
private readonly nodeMode: CodeExecutionMode,
|
||||
private readonly workflowMode: WorkflowExecuteMode,
|
||||
private readonly executeFunctions: IExecuteFunctions,
|
||||
private readonly executeFunctions: Pick<
|
||||
IExecuteFunctions,
|
||||
'startJob' | 'continueOnFail' | 'helpers'
|
||||
>,
|
||||
private readonly chunkSize = 1000,
|
||||
private readonly additionalProperties: Record<string, unknown> = {},
|
||||
) {}
|
||||
|
||||
async runCodeAllItems(): Promise<INodeExecutionData[]> {
|
||||
@@ -36,6 +40,7 @@ export class JsTaskRunnerSandbox {
|
||||
nodeMode: this.nodeMode,
|
||||
workflowMode: this.workflowMode,
|
||||
continueOnFail: this.executeFunctions.continueOnFail(),
|
||||
additionalProperties: this.additionalProperties,
|
||||
},
|
||||
itemIndex,
|
||||
);
|
||||
@@ -51,6 +56,28 @@ export class JsTaskRunnerSandbox {
|
||||
);
|
||||
}
|
||||
|
||||
async runCodeForTool(): Promise<unknown> {
|
||||
const itemIndex = 0;
|
||||
|
||||
const executionResult = await this.executeFunctions.startJob(
|
||||
'javascript',
|
||||
{
|
||||
code: this.jsCode,
|
||||
nodeMode: this.nodeMode,
|
||||
workflowMode: this.workflowMode,
|
||||
continueOnFail: this.executeFunctions.continueOnFail(),
|
||||
additionalProperties: this.additionalProperties,
|
||||
},
|
||||
itemIndex,
|
||||
);
|
||||
|
||||
if (!executionResult.ok) {
|
||||
throwExecutionError('error' in executionResult ? executionResult.error : {});
|
||||
}
|
||||
|
||||
return executionResult.result;
|
||||
}
|
||||
|
||||
async runCodeForEachItem(numInputItems: number): Promise<INodeExecutionData[]> {
|
||||
validateNoDisallowedMethodsInRunForEach(this.jsCode, 0);
|
||||
|
||||
@@ -70,6 +97,7 @@ export class JsTaskRunnerSandbox {
|
||||
startIndex: chunk.startIdx,
|
||||
count: chunk.count,
|
||||
},
|
||||
additionalProperties: this.additionalProperties,
|
||||
},
|
||||
itemIndex,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user