mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
rename workflow mappings inputs to local resource mappings
This commit is contained in:
parent
46b662fa03
commit
5efdde1f6d
|
@ -93,17 +93,15 @@ export class DynamicNodeParametersController {
|
|||
);
|
||||
}
|
||||
|
||||
@Post('/workflow-input-mapping-fields')
|
||||
async getWorkflowInputMappingFields(
|
||||
req: DynamicNodeParametersRequest.WorkflowInputMappingFields,
|
||||
) {
|
||||
@Post('/local-resource-mapper-fields')
|
||||
async getLocalResourceMappingFields(req: DynamicNodeParametersRequest.ResourceMapperFields) {
|
||||
const { path, methodName, credentials, currentNodeParameters, nodeTypeAndVersion } = req.body;
|
||||
|
||||
if (!methodName) throw new BadRequestError('Missing `methodName` in request body');
|
||||
|
||||
const additionalData = await getBase(req.user.id, currentNodeParameters);
|
||||
|
||||
return await this.service.getWorkflowInputMappingFields(
|
||||
return await this.service.getLocalResourceMappingFields(
|
||||
methodName,
|
||||
path,
|
||||
additionalData,
|
||||
|
|
|
@ -385,11 +385,6 @@ export declare namespace DynamicNodeParametersRequest {
|
|||
methodName: string;
|
||||
}>;
|
||||
|
||||
/** POST dynamic-node-parameters/workflow-input-mapping-fields */
|
||||
type WorkflowInputMappingFields = BaseRequest<{
|
||||
methodName: string;
|
||||
}>;
|
||||
|
||||
/** POST /dynamic-node-parameters/action-result */
|
||||
type ActionResult = BaseRequest<{
|
||||
handler: string;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { LoadOptionsContext, NodeExecuteFunctions, WorkflowInputsContext } from 'n8n-core';
|
||||
import { LoadOptionsContext, NodeExecuteFunctions, LocalLoadOptionsContext } from 'n8n-core';
|
||||
import type {
|
||||
ILoadOptions,
|
||||
ILoadOptionsFunctions,
|
||||
|
@ -17,15 +17,15 @@ import type {
|
|||
INodeTypeNameVersion,
|
||||
NodeParameterValueType,
|
||||
IDataObject,
|
||||
IWorkflowInputsLoadOptionsFunctions,
|
||||
ILocalLoadOptionsFunctions,
|
||||
} from 'n8n-workflow';
|
||||
import { Workflow, RoutingNode, ApplicationError } from 'n8n-workflow';
|
||||
import { Service } from 'typedi';
|
||||
|
||||
import { NodeTypes } from '@/node-types';
|
||||
|
||||
type WorkflowInputsMappingMethod = (
|
||||
this: IWorkflowInputsLoadOptionsFunctions,
|
||||
type LocalResourceMappingMethod = (
|
||||
this: ILocalLoadOptionsFunctions,
|
||||
) => Promise<ResourceMapperFields>;
|
||||
type ListSearchMethod = (
|
||||
this: ILoadOptionsFunctions,
|
||||
|
@ -40,7 +40,7 @@ type ActionHandlerMethod = (
|
|||
type ResourceMappingMethod = (this: ILoadOptionsFunctions) => Promise<ResourceMapperFields>;
|
||||
|
||||
type NodeMethod =
|
||||
| WorkflowInputsMappingMethod
|
||||
| LocalResourceMappingMethod
|
||||
| ListSearchMethod
|
||||
| LoadOptionsMethod
|
||||
| ActionHandlerMethod
|
||||
|
@ -183,7 +183,7 @@ export class DynamicNodeParametersService {
|
|||
}
|
||||
|
||||
/** Returns the available workflow input mapping fields for the ResourceMapper component */
|
||||
async getWorkflowInputMappingFields(
|
||||
async getLocalResourceMappingFields(
|
||||
methodName: string,
|
||||
path: string,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
|
@ -192,9 +192,9 @@ export class DynamicNodeParametersService {
|
|||
credentials?: INodeCredentials,
|
||||
): Promise<ResourceMapperFields> {
|
||||
const nodeType = this.getNodeType(nodeTypeAndVersion);
|
||||
const method = this.getMethod('workflowInputsMapping', methodName, nodeType);
|
||||
const method = this.getMethod('localResourceMapping', methodName, nodeType);
|
||||
const workflow = this.getWorkflow(nodeTypeAndVersion, currentNodeParameters, credentials);
|
||||
const thisArgs = this.getWorkflowInputsContext(path, additionalData, workflow);
|
||||
const thisArgs = this.getLocalLoadOptionsContext(path, additionalData, workflow);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return method.call(thisArgs);
|
||||
}
|
||||
|
@ -223,10 +223,10 @@ export class DynamicNodeParametersService {
|
|||
nodeType: INodeType,
|
||||
): ResourceMappingMethod;
|
||||
private getMethod(
|
||||
type: 'workflowInputsMapping',
|
||||
type: 'localResourceMapping',
|
||||
methodName: string,
|
||||
nodeType: INodeType,
|
||||
): WorkflowInputsMappingMethod;
|
||||
): LocalResourceMappingMethod;
|
||||
private getMethod(type: 'listSearch', methodName: string, nodeType: INodeType): ListSearchMethod;
|
||||
private getMethod(
|
||||
type: 'loadOptions',
|
||||
|
@ -241,7 +241,7 @@ export class DynamicNodeParametersService {
|
|||
private getMethod(
|
||||
type:
|
||||
| 'resourceMapping'
|
||||
| 'workflowInputsMapping'
|
||||
| 'localResourceMapping'
|
||||
| 'listSearch'
|
||||
| 'loadOptions'
|
||||
| 'actionHandler',
|
||||
|
@ -297,12 +297,12 @@ export class DynamicNodeParametersService {
|
|||
return new LoadOptionsContext(workflow, node, additionalData, path);
|
||||
}
|
||||
|
||||
private getWorkflowInputsContext(
|
||||
private getLocalLoadOptionsContext(
|
||||
path: string,
|
||||
additionalData: IWorkflowExecuteAdditionalData,
|
||||
workflow: Workflow,
|
||||
) {
|
||||
const node = workflow.nodes['Temp-Node'];
|
||||
return new WorkflowInputsContext(workflow, node, additionalData, path);
|
||||
return new LocalLoadOptionsContext(workflow, node, additionalData, path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ export { ExecuteContext } from './execute-context';
|
|||
export { ExecuteSingleContext } from './execute-single-context';
|
||||
export { HookContext } from './hook-context';
|
||||
export { LoadOptionsContext } from './load-options-context';
|
||||
export { WorkflowInputsContext } from './workflow-inputs-context';
|
||||
export { LocalLoadOptionsContext } from './local-load-options-context';
|
||||
export { PollContext } from './poll-context';
|
||||
export { SupplyDataContext } from './supply-data-context';
|
||||
export { TriggerContext } from './trigger-context';
|
||||
|
|
|
@ -7,17 +7,17 @@ import type {
|
|||
IWorkflowExecuteAdditionalData,
|
||||
NodeParameterValueType,
|
||||
Workflow,
|
||||
IWorkflowInputsLoadOptionsFunctions,
|
||||
FieldType,
|
||||
ILocalLoadOptionsFunctions,
|
||||
FieldValueOption,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { extractValue } from '@/ExtractValue';
|
||||
|
||||
import { NodeExecutionContext } from './node-execution-context';
|
||||
|
||||
export class WorkflowInputsContext
|
||||
export class LocalLoadOptionsContext
|
||||
extends NodeExecutionContext
|
||||
implements IWorkflowInputsLoadOptionsFunctions
|
||||
implements ILocalLoadOptionsFunctions
|
||||
{
|
||||
constructor(
|
||||
workflow: Workflow,
|
||||
|
@ -28,12 +28,12 @@ export class WorkflowInputsContext
|
|||
super(workflow, node, additionalData, 'internal');
|
||||
}
|
||||
|
||||
getWorkflowInputValues(): Array<{ name: string; type: FieldType }> {
|
||||
getWorkflowInputValues(): FieldValueOption[] {
|
||||
const { value } = this.getCurrentNodeParameter('workflowId') as INodeParameterResourceLocator;
|
||||
|
||||
const workflowId = value as string;
|
||||
if (!workflowId) {
|
||||
throw new ApplicationError('No workflowId defined on node!');
|
||||
throw new ApplicationError('No workflowId parameter defined on node!');
|
||||
}
|
||||
|
||||
// TODO: load the inputs from the workflow
|
||||
|
@ -41,6 +41,7 @@ export class WorkflowInputsContext
|
|||
{ name: 'field1', type: 'string' as const },
|
||||
{ name: 'field2', type: 'number' as const },
|
||||
{ name: 'field3', type: 'boolean' as const },
|
||||
{ name: 'field4', type: 'any' as const },
|
||||
];
|
||||
|
||||
return dummyFields;
|
|
@ -1275,10 +1275,6 @@ export declare namespace DynamicNodeParameters {
|
|||
methodName: string;
|
||||
}
|
||||
|
||||
interface WorkflowInputMappingFieldsRequest extends BaseRequest {
|
||||
methodName: string;
|
||||
}
|
||||
|
||||
interface ActionResultRequest extends BaseRequest {
|
||||
handler: string;
|
||||
payload: IDataObject | string | undefined;
|
||||
|
|
|
@ -59,14 +59,14 @@ export async function getResourceMapperFields(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getWorkflowInputFields(
|
||||
export async function getLocalResourceMapperFields(
|
||||
context: IRestApiContext,
|
||||
sendData: DynamicNodeParameters.WorkflowInputMappingFieldsRequest,
|
||||
sendData: DynamicNodeParameters.ResourceMapperFieldsRequest,
|
||||
): Promise<ResourceMapperFields> {
|
||||
return await makeRestApiRequest(
|
||||
context,
|
||||
'POST',
|
||||
'/dynamic-node-parameters/workflow-input-mapping-fields',
|
||||
'/dynamic-node-parameters/local-resource-mapper-fields',
|
||||
sendData,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -245,8 +245,8 @@ async function loadFieldsToMap(): Promise<void> {
|
|||
}
|
||||
|
||||
const resourceMapperMethod = props.parameter.typeOptions?.resourceMapper?.resourceMapperMethod;
|
||||
const workflowInputsMappingMethod =
|
||||
props.parameter.typeOptions?.resourceMapper?.workflowInputsMappingMethod;
|
||||
const localResourceMapperMethod =
|
||||
props.parameter.typeOptions?.resourceMapper?.localResourceMapperMethod;
|
||||
|
||||
let fetchedFields = null;
|
||||
|
||||
|
@ -266,8 +266,8 @@ async function loadFieldsToMap(): Promise<void> {
|
|||
};
|
||||
fetchedFields = await nodeTypesStore.getResourceMapperFields(requestParams);
|
||||
} else {
|
||||
if (typeof workflowInputsMappingMethod === 'string') {
|
||||
const requestParams: DynamicNodeParameters.WorkflowInputMappingFieldsRequest = {
|
||||
if (typeof localResourceMapperMethod === 'string') {
|
||||
const requestParams: DynamicNodeParameters.ResourceMapperFieldsRequest = {
|
||||
nodeTypeAndVersion: {
|
||||
name: props.node?.type,
|
||||
version: props.node.typeVersion,
|
||||
|
@ -277,9 +277,9 @@ async function loadFieldsToMap(): Promise<void> {
|
|||
props.node.parameters,
|
||||
) as INodeParameters,
|
||||
path: props.path,
|
||||
methodName: workflowInputsMappingMethod,
|
||||
methodName: localResourceMapperMethod,
|
||||
};
|
||||
fetchedFields = await nodeTypesStore.getWorkflowInputFields(requestParams);
|
||||
fetchedFields = await nodeTypesStore.getLocalResourceMapperFields(requestParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -302,11 +302,11 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, () => {
|
|||
}
|
||||
};
|
||||
|
||||
const getWorkflowInputFields = async (
|
||||
sendData: DynamicNodeParameters.WorkflowInputMappingFieldsRequest,
|
||||
const getLocalResourceMapperFields = async (
|
||||
sendData: DynamicNodeParameters.ResourceMapperFieldsRequest,
|
||||
) => {
|
||||
try {
|
||||
return await nodeTypesApi.getWorkflowInputFields(rootStore.restApiContext, sendData);
|
||||
return await nodeTypesApi.getLocalResourceMapperFields(rootStore.restApiContext, sendData);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, () => {
|
|||
visibleNodeTypesByInputConnectionTypeNames,
|
||||
isConfigurableNode,
|
||||
getResourceMapperFields,
|
||||
getWorkflowInputFields,
|
||||
getLocalResourceMapperFields,
|
||||
getNodeParameterActionResult,
|
||||
getResourceLocatorResults,
|
||||
getNodeParameterOptions,
|
||||
|
|
|
@ -201,7 +201,7 @@ export class ExecuteWorkflow implements INodeType {
|
|||
typeOptions: {
|
||||
loadOptionsDependsOn: ['workflowId.value'],
|
||||
resourceMapper: {
|
||||
workflowInputsMappingMethod: 'getWorkflowInputs',
|
||||
localResourceMapperMethod: 'getWorkflowInputs',
|
||||
valuesLabel: 'Workflow Inputs',
|
||||
mode: 'add',
|
||||
fieldWords: {
|
||||
|
@ -265,7 +265,7 @@ export class ExecuteWorkflow implements INodeType {
|
|||
};
|
||||
|
||||
methods = {
|
||||
workflowInputsMapping: {
|
||||
localResourceMapping: {
|
||||
getWorkflowInputs,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,24 +1,30 @@
|
|||
import type {
|
||||
FieldType,
|
||||
IWorkflowInputsLoadOptionsFunctions,
|
||||
FieldValueOption,
|
||||
ILocalLoadOptionsFunctions,
|
||||
ResourceMapperField,
|
||||
ResourceMapperFields,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function getWorkflowInputs(
|
||||
this: IWorkflowInputsLoadOptionsFunctions,
|
||||
this: ILocalLoadOptionsFunctions,
|
||||
): Promise<ResourceMapperFields> {
|
||||
const workflowInputs = this.getWorkflowInputValues() as Array<{ name: string; type: FieldType }>;
|
||||
const workflowInputFields = this.getWorkflowInputValues() as FieldValueOption[];
|
||||
|
||||
const fields: ResourceMapperField[] = workflowInputs.map((currentWorkflowInput) => ({
|
||||
id: currentWorkflowInput.name,
|
||||
displayName: currentWorkflowInput.name,
|
||||
required: false,
|
||||
defaultMatch: true,
|
||||
display: true,
|
||||
type: currentWorkflowInput.type,
|
||||
canBeUsedToMatch: true,
|
||||
}));
|
||||
const fields: ResourceMapperField[] = workflowInputFields.map((currentWorkflowInput) => {
|
||||
const field: ResourceMapperField = {
|
||||
id: currentWorkflowInput.name,
|
||||
displayName: currentWorkflowInput.name,
|
||||
required: false,
|
||||
defaultMatch: true,
|
||||
display: true,
|
||||
canBeUsedToMatch: true,
|
||||
};
|
||||
|
||||
if (currentWorkflowInput.type !== 'any') {
|
||||
field.type = currentWorkflowInput.type;
|
||||
}
|
||||
|
||||
return field;
|
||||
});
|
||||
return { fields };
|
||||
}
|
||||
|
|
|
@ -1072,7 +1072,7 @@ export interface ILoadOptionsFunctions extends FunctionsBase {
|
|||
|
||||
export type FieldValueOption = { name: string; type: FieldType | 'any' };
|
||||
|
||||
export interface IWorkflowInputsLoadOptionsFunctions {
|
||||
export interface ILocalLoadOptionsFunctions {
|
||||
getWorkflowInputValues(): FieldValueOption[];
|
||||
}
|
||||
|
||||
|
@ -1374,14 +1374,14 @@ export interface ResourceMapperTypeOptionsBase {
|
|||
};
|
||||
}
|
||||
|
||||
// Enforce at least one of resourceMapperMethod or workflowInputsMappingMethod
|
||||
// Enforce at least one of resourceMapperMethod or localResourceMapperMethod
|
||||
export type ResourceMapperTypeOptions =
|
||||
| (ResourceMapperTypeOptionsBase & {
|
||||
resourceMapperMethod: string;
|
||||
workflowInputsMappingMethod?: never;
|
||||
localResourceMapperMethod?: never;
|
||||
})
|
||||
| (ResourceMapperTypeOptionsBase & {
|
||||
workflowInputsMappingMethod: string;
|
||||
localResourceMapperMethod: string;
|
||||
resourceMapperMethod?: never;
|
||||
});
|
||||
|
||||
|
@ -1647,10 +1647,8 @@ export interface INodeType {
|
|||
resourceMapping?: {
|
||||
[functionName: string]: (this: ILoadOptionsFunctions) => Promise<ResourceMapperFields>;
|
||||
};
|
||||
workflowInputsMapping?: {
|
||||
[functionName: string]: (
|
||||
this: IWorkflowInputsLoadOptionsFunctions,
|
||||
) => Promise<ResourceMapperFields>;
|
||||
localResourceMapping?: {
|
||||
[functionName: string]: (this: ILocalLoadOptionsFunctions) => Promise<ResourceMapperFields>;
|
||||
};
|
||||
actionHandler?: {
|
||||
[functionName: string]: (
|
||||
|
|
Loading…
Reference in a new issue