refactor(core): Remove NodeExecutionOutput. Add execution hints directly to the context (#13111)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2025-02-10 16:51:01 +01:00
committed by GitHub
parent 5dddf772cf
commit dbb9475b7b
17 changed files with 103 additions and 171 deletions

View File

@@ -165,7 +165,8 @@ export class Code implements INodeType {
standardizeOutput(item.json);
}
return addPostExecutionWarning(items, inputDataItems?.length);
addPostExecutionWarning(this, items, inputDataItems?.length);
return [items];
}
// ----------------------------------
@@ -201,6 +202,7 @@ export class Code implements INodeType {
}
}
return addPostExecutionWarning(returnData, inputDataItems?.length);
addPostExecutionWarning(this, returnData, inputDataItems?.length);
return [returnData];
}
}

View File

@@ -1,49 +1,46 @@
import type { INodeExecutionData } from 'n8n-workflow';
import { NodeExecutionOutput } from 'n8n-workflow';
import { mock } from 'jest-mock-extended';
import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { addPostExecutionWarning } from '../utils';
describe('addPostExecutionWarning', () => {
const context = mock<IExecuteFunctions>();
const inputItemsLength = 2;
it('should return a NodeExecutionOutput warning when returnData length differs from inputItemsLength', () => {
beforeEach(() => jest.resetAllMocks());
it('should add execution hints when returnData length differs from inputItemsLength', () => {
const returnData: INodeExecutionData[] = [{ json: {}, pairedItem: 0 }];
const result = addPostExecutionWarning(returnData, inputItemsLength);
addPostExecutionWarning(context, returnData, inputItemsLength);
expect(result).toBeInstanceOf(NodeExecutionOutput);
expect((result as NodeExecutionOutput)?.getHints()).toEqual([
{
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
},
]);
expect(context.addExecutionHints).toHaveBeenCalledWith({
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
});
});
it('should return a NodeExecutionOutput warning when any item has undefined pairedItem', () => {
it('should add execution hints when any item has undefined pairedItem', () => {
const returnData: INodeExecutionData[] = [{ json: {}, pairedItem: 0 }, { json: {} }];
const result = addPostExecutionWarning(returnData, inputItemsLength);
addPostExecutionWarning(context, returnData, inputItemsLength);
expect(result).toBeInstanceOf(NodeExecutionOutput);
expect((result as NodeExecutionOutput)?.getHints()).toEqual([
{
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
},
]);
expect(context.addExecutionHints).toHaveBeenCalledWith({
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
});
});
it('should return returnData array when all items match inputItemsLength and have defined pairedItem', () => {
it('should not add execution hints when all items match inputItemsLength and have defined pairedItem', () => {
const returnData: INodeExecutionData[] = [
{ json: {}, pairedItem: 0 },
{ json: {}, pairedItem: 1 },
];
const result = addPostExecutionWarning(returnData, inputItemsLength);
addPostExecutionWarning(context, returnData, inputItemsLength);
expect(result).toEqual([returnData]);
expect(context.addExecutionHints).not.toHaveBeenCalled();
});
});

View File

@@ -1,5 +1,4 @@
import type { INodeExecutionData, IDataObject } from 'n8n-workflow';
import { NodeExecutionOutput } from 'n8n-workflow';
import type { INodeExecutionData, IDataObject, IExecuteFunctions } from 'n8n-workflow';
export function isObject(maybe: unknown): maybe is { [key: string]: unknown } {
return (
@@ -39,24 +38,18 @@ export function standardizeOutput(output: IDataObject) {
}
export const addPostExecutionWarning = (
context: IExecuteFunctions,
returnData: INodeExecutionData[],
inputItemsLength: number,
) => {
): void => {
if (
returnData.length !== inputItemsLength ||
returnData.some((item) => item.pairedItem === undefined)
) {
return new NodeExecutionOutput(
[returnData],
[
{
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
},
],
);
context.addExecutionHints({
message:
'To make sure expressions after this node work, return the input items that produced each output item. <a target="_blank" href="https://docs.n8n.io/data/data-mapping/data-item-linking/item-linking-code-node/">More info</a>',
location: 'outputPane',
});
}
return [returnData];
};