Skip to content

Commit

Permalink
feat(core): Add support for pairedItem (beta) (n8n-io#3012)
Browse files Browse the repository at this point in the history
* ✨ Add pairedItem support

* 👕 Fix lint issue

* 🐛 Fix resolution in frontend

* 🐛 Fix resolution issue

* 🐛 Fix resolution in frontend

* 🐛 Fix another resolution issue in frontend

* ⚡ Try to automatically add pairedItem data if possible

* ⚡ Cleanup

* ⚡ Display expression errors in editor UI

* 🐛 Fix issue that it did not display errors in production

* 🐛 Fix auto-fix of missing pairedItem data

* 🐛 Fix frontend resolution for not executed nodes

* ⚡ Fail execution on pairedItem resolve issue and display information
about itemIndex and runIndex

* ⚡ Allow that pairedItem is only set to number if runIndex is 0

* ✨ Improve Expression Errors

* ⚡ Remove no longer needed code

* ⚡ Make errors more helpful

* ⚡ Add additional errors

* 👕 Fix lint issue

* ⚡ Add pairedItem support to core nodes

* ⚡ Improve support in Merge-Node

* ⚡ Fix issue with not correctly converted incoming pairedItem data

* 🐛 Fix frontend resolve issue

* 🐛 Fix frontend parameter name display issue

* ⚡ Improve errors

* 👕 Fix lint issue

* ⚡ Improve errors

* ⚡ Make it possible to display parameter name in error messages

* ⚡ Improve error messages

* ⚡ Fix error message

* ⚡ Improve error messages

* ⚡ Add another error message

* ⚡ Simplify
  • Loading branch information
janober authored and simshaun committed Jun 4, 2022
1 parent 404f36a commit e1c7c97
Show file tree
Hide file tree
Showing 52 changed files with 1,317 additions and 152 deletions.
2 changes: 2 additions & 0 deletions packages/cli/src/ActiveWorkflowRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ export class ActiveWorkflowRunner {
data: {
main: data,
},
source: null,
},
];

Expand All @@ -603,6 +604,7 @@ export class ActiveWorkflowRunner {
contextData: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
},
};

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/CredentialsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class CredentialsHelper extends ICredentialsHelper {
'internal',
defaultTimezone,
additionalKeys,
undefined,
'',
);

Expand Down Expand Up @@ -366,6 +367,7 @@ export class CredentialsHelper extends ICredentialsHelper {
mode,
timezone,
{},
undefined,
false,
decryptedData,
) as ICredentialDataDecryptedObject;
Expand Down Expand Up @@ -398,6 +400,7 @@ export class CredentialsHelper extends ICredentialsHelper {
defaultTimezone,
{},
undefined,
undefined,
decryptedData,
) as ICredentialDataDecryptedObject;
}
Expand Down Expand Up @@ -642,6 +645,7 @@ export class CredentialsHelper extends ICredentialsHelper {
inputData,
runIndex,
nodeTypeCopy,
{ node, data: {}, source: null },
NodeExecuteFunctions,
credentialsDecrypted,
);
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/WebhookHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export async function executeWebhook(
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
'onReceived',
);
const responseCode = workflow.expression.getSimpleParameterValue(
Expand All @@ -206,6 +207,7 @@ export async function executeWebhook(
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
200,
) as number;

Expand All @@ -215,6 +217,7 @@ export async function executeWebhook(
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
'firstEntryJson',
);

Expand Down Expand Up @@ -288,6 +291,7 @@ export async function executeWebhook(
additionalData.timezone,
additionalKeys,
undefined,
undefined,
) as {
entries?:
| Array<{
Expand Down Expand Up @@ -373,6 +377,7 @@ export async function executeWebhook(
data: {
main: webhookResultData.workflowData,
},
source: null,
});

runExecutionData =
Expand Down Expand Up @@ -546,6 +551,7 @@ export async function executeWebhook(
additionalData.timezone,
additionalKeys,
undefined,
undefined,
);

if (responsePropertyName !== undefined) {
Expand All @@ -559,6 +565,7 @@ export async function executeWebhook(
additionalData.timezone,
additionalKeys,
undefined,
undefined,
);

if (responseContentType !== undefined) {
Expand Down Expand Up @@ -603,6 +610,7 @@ export async function executeWebhook(
executionMode,
additionalData.timezone,
additionalKeys,
undefined,
'data',
);

Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx
contextData: {},
nodeExecutionStack: [],
waitingExecution: {},
waitingExecutionSource: {},
},
};
}
Expand Down Expand Up @@ -752,6 +753,7 @@ export async function getRunData(
data: {
main: [inputData],
},
source: null,
});

const runExecutionData: IRunExecutionData = {
Expand All @@ -763,6 +765,7 @@ export async function getRunData(
contextData: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/WorkflowHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export async function executeErrorWorkflow(
],
],
},
source: null,
});

const runExecutionData: IRunExecutionData = {
Expand All @@ -200,6 +201,7 @@ export async function executeErrorWorkflow(
contextData: {},
nodeExecutionStack,
waitingExecution: {},
waitingExecutionSource: {},
},
};

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/LoadNodeParameterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export class LoadNodeParameterOptions {
inputData,
runIndex,
tempNode,
{ node: node!, source: null, data: {} },
NodeExecuteFunctions,
);

Expand Down
26 changes: 25 additions & 1 deletion packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
WorkflowDataProxy,
WorkflowExecuteMode,
LoggerProxy as Logger,
IExecuteData,
} from 'n8n-workflow';

import { Agent } from 'https';
Expand Down Expand Up @@ -1447,6 +1448,7 @@ export function getNodeParameter(
mode: WorkflowExecuteMode,
timezone: string,
additionalKeys: IWorkflowDataProxyAdditionalKeys,
executeData?: IExecuteData,
fallbackValue?: any,
): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object {
const nodeType = workflow.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
Expand All @@ -1472,11 +1474,13 @@ export function getNodeParameter(
mode,
timezone,
additionalKeys,
executeData,
);

returnData = cleanupParameterData(returnData);
} catch (e) {
e.message += ` [Error in parameter: "${parameterName}"]`;
if (e.context) e.context.parameter = parameterName;
e.cause = value;
throw e;
}

Expand Down Expand Up @@ -1543,6 +1547,7 @@ export function getNodeWebhookUrl(
mode,
timezone,
additionalKeys,
undefined,
false,
) as boolean;
return NodeHelpers.getNodeWebhookUrl(baseUrl, workflow.id!, node, path.toString(), isFullPath);
Expand Down Expand Up @@ -1673,6 +1678,7 @@ export function getExecutePollFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
undefined,
fallbackValue,
);
},
Expand Down Expand Up @@ -1827,6 +1833,7 @@ export function getExecuteTriggerFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
undefined,
fallbackValue,
);
},
Expand Down Expand Up @@ -1940,6 +1947,7 @@ export function getExecuteFunctions(
inputData: ITaskDataConnections,
node: INode,
additionalData: IWorkflowExecuteAdditionalData,
executeData: IExecuteData,
mode: WorkflowExecuteMode,
): IExecuteFunctions {
return ((workflow, runExecutionData, connectionInputData, inputData, node) => {
Expand All @@ -1959,6 +1967,7 @@ export function getExecuteFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
);
},
async executeWorkflow(
Expand Down Expand Up @@ -2035,6 +2044,7 @@ export function getExecuteFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
fallbackValue,
);
},
Expand All @@ -2050,6 +2060,9 @@ export function getExecuteFunctions(
getTimezone: (): string => {
return getTimezone(workflow, additionalData);
},
getExecuteData: (): IExecuteData => {
return executeData;
},
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
Expand All @@ -2065,6 +2078,7 @@ export function getExecuteFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
);
return dataProxy.getDataProxy();
},
Expand Down Expand Up @@ -2199,6 +2213,7 @@ export function getExecuteSingleFunctions(
node: INode,
itemIndex: number,
additionalData: IWorkflowExecuteAdditionalData,
executeData: IExecuteData,
mode: WorkflowExecuteMode,
): IExecuteSingleFunctions {
return ((workflow, runExecutionData, connectionInputData, inputData, node, itemIndex) => {
Expand All @@ -2219,6 +2234,7 @@ export function getExecuteSingleFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
);
},
getContext(type: string): IContextObject {
Expand Down Expand Up @@ -2276,6 +2292,9 @@ export function getExecuteSingleFunctions(
getTimezone: (): string => {
return getTimezone(workflow, additionalData);
},
getExecuteData: (): IExecuteData => {
return executeData;
},
getNodeParameter: (
parameterName: string,
fallbackValue?: any,
Expand All @@ -2296,6 +2315,7 @@ export function getExecuteSingleFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
fallbackValue,
);
},
Expand All @@ -2314,6 +2334,7 @@ export function getExecuteSingleFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
executeData,
);
return dataProxy.getDataProxy();
},
Expand Down Expand Up @@ -2471,6 +2492,7 @@ export function getLoadOptionsFunctions(
'internal' as WorkflowExecuteMode,
additionalData.timezone,
getAdditionalKeys(additionalData),
undefined,
fallbackValue,
);
},
Expand Down Expand Up @@ -2601,6 +2623,7 @@ export function getExecuteHookFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
undefined,
fallbackValue,
);
},
Expand Down Expand Up @@ -2763,6 +2786,7 @@ export function getExecuteWebhookFunctions(
mode,
additionalData.timezone,
getAdditionalKeys(additionalData),
undefined,
fallbackValue,
);
},
Expand Down
Loading

0 comments on commit e1c7c97

Please sign in to comment.