Make workflow metadata available in expresions and

node-functions
This commit is contained in:
Jan Oberhauser 2020-02-15 17:07:01 -08:00
parent b1719f1bcc
commit 70286b469e
13 changed files with 148 additions and 25 deletions

View file

@ -123,7 +123,7 @@ export class ActiveWorkflowRunner {
} }
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(webhookData.workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); const workflow = new Workflow({ id: webhookData.workflowId, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings});
// Get the node which has the webhook defined to know where to start from and to // Get the node which has the webhook defined to know where to start from and to
// get additional data // get additional data
@ -225,7 +225,7 @@ export class ActiveWorkflowRunner {
} }
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); const workflow = new Workflow({ id: workflowId, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
await this.activeWebhooks!.removeWorkflow(workflow); await this.activeWebhooks!.removeWorkflow(workflow);
@ -345,7 +345,7 @@ export class ActiveWorkflowRunner {
throw new Error(`Could not find workflow with id "${workflowId}".`); throw new Error(`Could not find workflow with id "${workflowId}".`);
} }
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
workflowInstance = new Workflow(workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); workflowInstance = new Workflow({ id: workflowId, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
const canBeActivated = workflowInstance.checkIfWorkflowCanBeActivated(['n8n-nodes-base.start']); const canBeActivated = workflowInstance.checkIfWorkflowCanBeActivated(['n8n-nodes-base.start']);
if (canBeActivated === false) { if (canBeActivated === false) {

View file

@ -508,7 +508,7 @@ class App {
const credentials = await WorkflowCredentials(workflowData.nodes); const credentials = await WorkflowCredentials(workflowData.nodes);
const additionalData = await WorkflowExecuteAdditionalData.getBase(credentials); const additionalData = await WorkflowExecuteAdditionalData.getBase(credentials);
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflowInstance = new Workflow(workflowData.id, workflowData.nodes, workflowData.connections, false, nodeTypes, undefined, workflowData.settings); const workflowInstance = new Workflow({ id: workflowData.id, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: false, nodeTypes, staticData: undefined, settings: workflowData.settings });
const needsWebhook = await this.testWebhooks.needsWebhookData(workflowData, workflowInstance, additionalData, executionMode, sessionId, destinationNode); const needsWebhook = await this.testWebhooks.needsWebhookData(workflowData, workflowInstance, additionalData, executionMode, sessionId, destinationNode);
if (needsWebhook === true) { if (needsWebhook === true) {
return { return {
@ -1088,7 +1088,7 @@ class App {
} }
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(workflowId.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); const workflow = new Workflow({ id: workflowId.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
return this.testWebhooks.cancelTestWebhook(workflowId, workflow); return this.testWebhooks.cancelTestWebhook(workflowId, workflow);
})); }));

View file

@ -67,7 +67,7 @@ export class TestWebhooks {
const workflowData = this.testWebhookData[webhookKey].workflowData; const workflowData = this.testWebhookData[webhookKey].workflowData;
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(webhookData.workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); const workflow = new Workflow({ id: webhookData.workflowId, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings});
// Get the node which has the webhook defined to know where to start from and to // Get the node which has the webhook defined to know where to start from and to
// get additional data // get additional data
@ -206,7 +206,7 @@ export class TestWebhooks {
const workflows: Workflow[] = []; const workflows: Workflow[] = [];
for (const webhookKey of Object.keys(this.testWebhookData)) { for (const webhookKey of Object.keys(this.testWebhookData)) {
workflowData = this.testWebhookData[webhookKey].workflowData; workflowData = this.testWebhookData[webhookKey].workflowData;
workflow = new Workflow(workflowData.id.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
workflows.push(); workflows.push();
} }

View file

@ -297,7 +297,8 @@ export async function executeWorkflow(workflowInfo: IExecuteWorkflowInfo, additi
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(workflowInfo.id, workflowData!.nodes, workflowData!.connections, workflowData!.active, nodeTypes, workflowData!.staticData); const workflowName = workflowData ? workflowData.name : undefined;
const workflow = new Workflow({ id: workflowInfo.id, name: workflowName, nodes: workflowData!.nodes, connections: workflowData!.connections, active: workflowData!.active, nodeTypes, staticData: workflowData!.staticData });
// Does not get used so set it simply to empty string // Does not get used so set it simply to empty string
const executionId = ''; const executionId = '';

View file

@ -90,8 +90,7 @@ export async function executeErrorWorkflow(workflowId: string, workflowErrorData
const executionMode = 'error'; const executionMode = 'error';
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflowInstance = new Workflow(workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); const workflowInstance = new Workflow({ id: workflowId, name: workflowData.name, nodeTypes, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, staticData: workflowData.staticData, settings: workflowData.settings});
let node: INode; let node: INode;
let workflowStartNode: INode | undefined; let workflowStartNode: INode | undefined;

View file

@ -119,7 +119,7 @@ export class WorkflowRunner {
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
const workflow = new Workflow(data.workflowData.id as string | undefined, data.workflowData!.nodes, data.workflowData!.connections, data.workflowData!.active, nodeTypes, data.workflowData!.staticData); const workflow = new Workflow({ id: data.workflowData.id as string | undefined, name: data.workflowData.name, nodes: data.workflowData!.nodes, connections: data.workflowData!.connections, active: data.workflowData!.active, nodeTypes, staticData: data.workflowData!.staticData });
const additionalData = await WorkflowExecuteAdditionalData.getBase(data.credentials); const additionalData = await WorkflowExecuteAdditionalData.getBase(data.credentials);
// Register the active execution // Register the active execution

View file

@ -58,7 +58,7 @@ export class WorkflowRunnerProcess {
const nodeTypes = NodeTypes(); const nodeTypes = NodeTypes();
await nodeTypes.init(nodeTypesData); await nodeTypes.init(nodeTypesData);
this.workflow = new Workflow(this.data.workflowData.id as string | undefined, this.data.workflowData!.nodes, this.data.workflowData!.connections, this.data.workflowData!.active, nodeTypes, this.data.workflowData!.staticData); this.workflow = new Workflow({ id: this.data.workflowData.id as string | undefined, name: this.data.workflowData.name, nodes: this.data.workflowData!.nodes, connections: this.data.workflowData!.connections, active: this.data.workflowData!.active, nodeTypes, staticData: this.data.workflowData!.staticData});
const additionalData = await WorkflowExecuteAdditionalData.getBase(this.data.credentials); const additionalData = await WorkflowExecuteAdditionalData.getBase(this.data.credentials);
additionalData.hooks = this.getProcessForwardHooks(); additionalData.hooks = this.getProcessForwardHooks();

View file

@ -50,7 +50,7 @@ export class LoadNodeParameterOptions {
connections: {}, connections: {},
}; };
this.workflow = new Workflow(undefined, workflowData.nodes, workflowData.connections, false, nodeTypes, undefined); this.workflow = new Workflow({ nodes: workflowData.nodes, connections: workflowData.connections, active: false, nodeTypes });
} }

View file

@ -27,6 +27,7 @@ import {
IWebhookFunctions, IWebhookFunctions,
IWorkflowDataProxyData, IWorkflowDataProxyData,
IWorkflowExecuteAdditionalData, IWorkflowExecuteAdditionalData,
IWorkflowMetadata,
NodeHelpers, NodeHelpers,
NodeParameterValue, NodeParameterValue,
Workflow, Workflow,
@ -196,6 +197,19 @@ export function getCredentials(workflow: Workflow, node: INode, type: string, ad
/**
* Returns a copy of the node
*
* @export
* @param {INode} node
* @returns {INode}
*/
export function getNode(node: INode): INode {
return JSON.parse(JSON.stringify(node));
}
/** /**
* Returns the requested resolved (all expressions replaced) node parameters. * Returns the requested resolved (all expressions replaced) node parameters.
* *
@ -312,6 +326,23 @@ export function getWebhookDescription(name: string, workflow: Workflow, node: IN
/**
* Returns the workflow metadata
*
* @export
* @param {Workflow} workflow
* @returns {IWorkflowMetadata}
*/
export function getWorkflowMetadata(workflow: Workflow): IWorkflowMetadata {
return {
id: workflow.id,
name: workflow.name,
active: workflow.active,
};
}
/** /**
* Returns the execute functions the poll nodes have access to. * Returns the execute functions the poll nodes have access to.
* *
@ -335,6 +366,9 @@ export function getExecutePollFunctions(workflow: Workflow, node: INode, additio
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
getNode: () => {
return getNode(node);
},
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
const runExecutionData: IRunExecutionData | null = null; const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;
@ -349,6 +383,9 @@ export function getExecutePollFunctions(workflow: Workflow, node: INode, additio
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
return workflow.getStaticData(type, node); return workflow.getStaticData(type, node);
}, },
@ -383,6 +420,9 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
getCredentials(type: string): ICredentialDataDecryptedObject | undefined { getCredentials(type: string): ICredentialDataDecryptedObject | undefined {
return getCredentials(workflow, node, type, additionalData); return getCredentials(workflow, node, type, additionalData);
}, },
getNode: () => {
return getNode(node);
},
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
@ -400,6 +440,9 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
return workflow.getStaticData(type, node); return workflow.getStaticData(type, node);
}, },
@ -467,12 +510,18 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
getNode: () => {
return getNode(node);
},
getRestApiUrl: (): string => { getRestApiUrl: (): string => {
return additionalData.restApiUrl; return additionalData.restApiUrl;
}, },
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => { getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => {
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData);
return dataProxy.getDataProxy(); return dataProxy.getDataProxy();
@ -544,6 +593,9 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
getNode: () => {
return getNode(node);
},
getRestApiUrl: (): string => { getRestApiUrl: (): string => {
return additionalData.restApiUrl; return additionalData.restApiUrl;
}, },
@ -553,6 +605,9 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue); return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowDataProxy: (): IWorkflowDataProxyData => { getWorkflowDataProxy: (): IWorkflowDataProxyData => {
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData); const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData);
return dataProxy.getDataProxy(); return dataProxy.getDataProxy();
@ -594,6 +649,9 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
getCurrentNodeParameters: (): INodeParameters | undefined => { getCurrentNodeParameters: (): INodeParameters | undefined => {
return JSON.parse('' + additionalData.currentNodeParameters); return JSON.parse('' + additionalData.currentNodeParameters);
}, },
getNode: () => {
return getNode(node);
},
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
const runExecutionData: IRunExecutionData | null = null; const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;
@ -637,6 +695,9 @@ export function getExecuteHookFunctions(workflow: Workflow, node: INode, additio
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
getNode: () => {
return getNode(node);
},
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
const runExecutionData: IRunExecutionData | null = null; const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;
@ -660,6 +721,9 @@ export function getExecuteHookFunctions(workflow: Workflow, node: INode, additio
getWebhookDescription(name: string): IWebhookDescription | undefined { getWebhookDescription(name: string): IWebhookDescription | undefined {
return getWebhookDescription(name, workflow, node); return getWebhookDescription(name, workflow, node);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
return workflow.getStaticData(type, node); return workflow.getStaticData(type, node);
}, },
@ -705,6 +769,9 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
getMode: (): WorkflowExecuteMode => { getMode: (): WorkflowExecuteMode => {
return mode; return mode;
}, },
getNode: () => {
return getNode(node);
},
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
const runExecutionData: IRunExecutionData | null = null; const runExecutionData: IRunExecutionData | null = null;
const itemIndex = 0; const itemIndex = 0;
@ -737,6 +804,9 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
getTimezone: (): string => { getTimezone: (): string => {
return getTimezone(workflow, additionalData); return getTimezone(workflow, additionalData);
}, },
getWorkflow: () => {
return getWorkflowMetadata(workflow);
},
getWorkflowStaticData(type: string): IDataObject { getWorkflowStaticData(type: string): IDataObject {
return workflow.getStaticData(type, node); return workflow.getStaticData(type, node);
}, },

View file

@ -192,14 +192,16 @@ export const workflowHelpers = mixins(
}; };
let workflowId = this.$store.getters.workflowId; let workflowId = this.$store.getters.workflowId;
if (workflowId !== PLACEHOLDER_EMPTY_WORKFLOW_ID) { if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
workflowId = undefined; workflowId = undefined;
} }
const workflowName = this.$store.getters.workflowName;
if (copyData === true) { if (copyData === true) {
return new Workflow(workflowId, JSON.parse(JSON.stringify(nodes)), JSON.parse(JSON.stringify(connections)), false, nodeTypes); return new Workflow({ id: workflowId, name: workflowName, nodes: JSON.parse(JSON.stringify(nodes)), connections: JSON.parse(JSON.stringify(connections)), active: false, nodeTypes});
} else { } else {
return new Workflow(workflowId, nodes, connections, false, nodeTypes); return new Workflow({ id: workflowId, name: workflowName, nodes, connections, active: false, nodeTypes});
} }
}, },

View file

@ -159,11 +159,13 @@ export interface IExecuteFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getInputData(inputIndex?: number, inputName?: string): INodeExecutionData[]; getInputData(inputIndex?: number, inputName?: string): INodeExecutionData[];
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getWorkflowDataProxy(itemIndex: number): IWorkflowDataProxyData; getWorkflowDataProxy(itemIndex: number): IWorkflowDataProxyData;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
getRestApiUrl(): string; getRestApiUrl(): string;
getTimezone(): string; getTimezone(): string;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>; prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>;
helpers: { helpers: {
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any [key: string]: (...args: any[]) => any //tslint:disable-line:no-any
@ -176,9 +178,11 @@ export interface IExecuteSingleFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getInputData(inputIndex?: number, inputName?: string): INodeExecutionData; getInputData(inputIndex?: number, inputName?: string): INodeExecutionData;
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getRestApiUrl(): string; getRestApiUrl(): string;
getTimezone(): string; getTimezone(): string;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
getWorkflowDataProxy(): IWorkflowDataProxyData; getWorkflowDataProxy(): IWorkflowDataProxyData;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
helpers: { helpers: {
@ -193,6 +197,7 @@ export interface IExecuteWorkflowInfo {
export interface ILoadOptionsFunctions { export interface ILoadOptionsFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getNode(): INode;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getCurrentNodeParameter(parameterName: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object | undefined; getCurrentNodeParameter(parameterName: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object | undefined;
getCurrentNodeParameters(): INodeParameters | undefined; getCurrentNodeParameters(): INodeParameters | undefined;
@ -206,11 +211,13 @@ export interface ILoadOptionsFunctions {
export interface IHookFunctions { export interface IHookFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeWebhookUrl: (name: string) => string | undefined; getNodeWebhookUrl: (name: string) => string | undefined;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getTimezone(): string; getTimezone(): string;
getWebhookDescription(name: string): IWebhookDescription | undefined; getWebhookDescription(name: string): IWebhookDescription | undefined;
getWebhookName(): string; getWebhookName(): string;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
helpers: { helpers: {
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any [key: string]: (...args: any[]) => any //tslint:disable-line:no-any
@ -221,9 +228,11 @@ export interface IPollFunctions {
__emit(data: INodeExecutionData[][]): void; __emit(data: INodeExecutionData[][]): void;
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getRestApiUrl(): string; getRestApiUrl(): string;
getTimezone(): string; getTimezone(): string;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
helpers: { helpers: {
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any [key: string]: (...args: any[]) => any //tslint:disable-line:no-any
@ -234,9 +243,11 @@ export interface ITriggerFunctions {
emit(data: INodeExecutionData[][]): void; emit(data: INodeExecutionData[][]): void;
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getRestApiUrl(): string; getRestApiUrl(): string;
getTimezone(): string; getTimezone(): string;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
helpers: { helpers: {
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any [key: string]: (...args: any[]) => any //tslint:disable-line:no-any
@ -248,6 +259,7 @@ export interface IWebhookFunctions {
getCredentials(type: string): ICredentialDataDecryptedObject | undefined; getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
getHeaderData(): object; getHeaderData(): object;
getMode(): WorkflowExecuteMode; getMode(): WorkflowExecuteMode;
getNode(): INode;
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
getNodeWebhookUrl: (name: string) => string | undefined; getNodeWebhookUrl: (name: string) => string | undefined;
getQueryData(): object; getQueryData(): object;
@ -256,6 +268,7 @@ export interface IWebhookFunctions {
getTimezone(): string; getTimezone(): string;
getWebhookName(): string; getWebhookName(): string;
getWorkflowStaticData(type: string): IDataObject; getWorkflowStaticData(type: string): IDataObject;
getWorkflow(workflow: Workflow): IWorkflowMetadata;
prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>; prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>;
helpers: { helpers: {
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any [key: string]: (...args: any[]) => any //tslint:disable-line:no-any
@ -519,6 +532,12 @@ export interface IWorkflowDataProxyData {
$parameter: any; // tslint:disable-line:no-any $parameter: any; // tslint:disable-line:no-any
} }
export interface IWorkflowMetadata {
id?: number | string;
name?: string;
active: boolean;
}
export type WebhookHttpMethod = 'GET' | 'POST'; export type WebhookHttpMethod = 'GET' | 'POST';
export interface IWebhookResponseData { export interface IWebhookResponseData {

View file

@ -41,6 +41,7 @@ tmpl.tmpl.errorHandler = () => { };
export class Workflow { export class Workflow {
id: string | undefined; id: string | undefined;
name: string | undefined;
nodes: INodes = {}; nodes: INodes = {};
connectionsBySourceNode: IConnections; connectionsBySourceNode: IConnections;
connectionsByDestinationNode: IConnections; connectionsByDestinationNode: IConnections;
@ -52,15 +53,17 @@ export class Workflow {
// ids of registred webhooks of nodes // ids of registred webhooks of nodes
staticData: IDataObject; staticData: IDataObject;
constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) { // constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) {
this.id = id; constructor(parameters: {id?: string, name?: string, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings}) {
this.nodeTypes = nodeTypes; this.id = parameters.id;
this.name = parameters.name;
this.nodeTypes = parameters.nodeTypes;
// Save nodes in workflow as object to be able to get the // Save nodes in workflow as object to be able to get the
// nodes easily by its name. // nodes easily by its name.
// Also directly add the default values of the node type. // Also directly add the default values of the node type.
let nodeType: INodeType | undefined; let nodeType: INodeType | undefined;
for (const node of nodes) { for (const node of parameters.nodes) {
this.nodes[node.name] = node; this.nodes[node.name] = node;
nodeType = this.nodeTypes.getByName(node.type); nodeType = this.nodeTypes.getByName(node.type);
@ -77,16 +80,16 @@ export class Workflow {
const nodeParameters = NodeHelpers.getNodeParameters(nodeType.description.properties, node.parameters, true, false); const nodeParameters = NodeHelpers.getNodeParameters(nodeType.description.properties, node.parameters, true, false);
node.parameters = nodeParameters !== null ? nodeParameters : {}; node.parameters = nodeParameters !== null ? nodeParameters : {};
} }
this.connectionsBySourceNode = connections; this.connectionsBySourceNode = parameters.connections;
// Save also the connections by the destionation nodes // Save also the connections by the destionation nodes
this.connectionsByDestinationNode = this.__getConnectionsByDestination(connections); this.connectionsByDestinationNode = this.__getConnectionsByDestination(parameters.connections);
this.active = active || false; this.active = parameters.active || false;
this.staticData = ObservableObject.create(staticData || {}, undefined, { ignoreEmptyOnFirstChild: true }); this.staticData = ObservableObject.create(parameters.staticData || {}, undefined, { ignoreEmptyOnFirstChild: true });
this.settings = settings || {}; this.settings = parameters.settings || {};
} }

View file

@ -240,6 +240,35 @@ export class WorkflowDataProxy {
/**
* Returns a proxt to query data from the workflow
*
* @private
* @returns
* @memberof WorkflowDataProxy
*/
private workflowGetter() {
const allowedValues = [
'active',
'id',
'name',
];
const that = this;
return new Proxy({}, {
get(target, name, receiver) {
if (!allowedValues.includes(name.toString())) {
throw new Error(`The key "${name.toString()}" is not supported!`);
}
// @ts-ignore
return that.workflow[name.toString()];
}
});
}
/** /**
* Returns a proxy to query data of all nodes * Returns a proxy to query data of all nodes
* *