mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-23 11:44:06 -08:00
✨ Make workflow metadata available in expresions and
node-functions
This commit is contained in:
parent
b1719f1bcc
commit
70286b469e
|
@ -123,7 +123,7 @@ export class ActiveWorkflowRunner {
|
|||
}
|
||||
|
||||
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 additional data
|
||||
|
@ -225,7 +225,7 @@ export class ActiveWorkflowRunner {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -345,7 +345,7 @@ export class ActiveWorkflowRunner {
|
|||
throw new Error(`Could not find workflow with id "${workflowId}".`);
|
||||
}
|
||||
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']);
|
||||
if (canBeActivated === false) {
|
||||
|
|
|
@ -508,7 +508,7 @@ class App {
|
|||
const credentials = await WorkflowCredentials(workflowData.nodes);
|
||||
const additionalData = await WorkflowExecuteAdditionalData.getBase(credentials);
|
||||
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);
|
||||
if (needsWebhook === true) {
|
||||
return {
|
||||
|
@ -1088,7 +1088,7 @@ class App {
|
|||
}
|
||||
|
||||
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);
|
||||
}));
|
||||
|
|
|
@ -67,7 +67,7 @@ export class TestWebhooks {
|
|||
const workflowData = this.testWebhookData[webhookKey].workflowData;
|
||||
|
||||
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 additional data
|
||||
|
@ -206,7 +206,7 @@ export class TestWebhooks {
|
|||
const workflows: Workflow[] = [];
|
||||
for (const webhookKey of Object.keys(this.testWebhookData)) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -297,7 +297,8 @@ export async function executeWorkflow(workflowInfo: IExecuteWorkflowInfo, additi
|
|||
|
||||
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
|
||||
const executionId = '';
|
||||
|
|
|
@ -90,8 +90,7 @@ export async function executeErrorWorkflow(workflowId: string, workflowErrorData
|
|||
const executionMode = 'error';
|
||||
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 workflowStartNode: INode | undefined;
|
||||
|
|
|
@ -119,7 +119,7 @@ export class WorkflowRunner {
|
|||
|
||||
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);
|
||||
|
||||
// Register the active execution
|
||||
|
|
|
@ -58,7 +58,7 @@ export class WorkflowRunnerProcess {
|
|||
const nodeTypes = NodeTypes();
|
||||
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);
|
||||
additionalData.hooks = this.getProcessForwardHooks();
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ export class LoadNodeParameterOptions {
|
|||
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 });
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
IWebhookFunctions,
|
||||
IWorkflowDataProxyData,
|
||||
IWorkflowExecuteAdditionalData,
|
||||
IWorkflowMetadata,
|
||||
NodeHelpers,
|
||||
NodeParameterValue,
|
||||
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.
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -335,6 +366,9 @@ export function getExecutePollFunctions(workflow: Workflow, node: INode, additio
|
|||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
|
||||
const runExecutionData: IRunExecutionData | null = null;
|
||||
const itemIndex = 0;
|
||||
|
@ -349,6 +383,9 @@ export function getExecutePollFunctions(workflow: Workflow, node: INode, additio
|
|||
getTimezone: (): string => {
|
||||
return getTimezone(workflow, additionalData);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowStaticData(type: string): IDataObject {
|
||||
return workflow.getStaticData(type, node);
|
||||
},
|
||||
|
@ -383,6 +420,9 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
|
|||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined {
|
||||
return getCredentials(workflow, node, type, additionalData);
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
|
@ -400,6 +440,9 @@ export function getExecuteTriggerFunctions(workflow: Workflow, node: INode, addi
|
|||
getTimezone: (): string => {
|
||||
return getTimezone(workflow, additionalData);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowStaticData(type: string): IDataObject {
|
||||
return workflow.getStaticData(type, node);
|
||||
},
|
||||
|
@ -467,12 +510,18 @@ export function getExecuteFunctions(workflow: Workflow, runExecutionData: IRunEx
|
|||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getRestApiUrl: (): string => {
|
||||
return additionalData.restApiUrl;
|
||||
},
|
||||
getTimezone: (): string => {
|
||||
return getTimezone(workflow, additionalData);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowDataProxy: (itemIndex: number): IWorkflowDataProxyData => {
|
||||
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData);
|
||||
return dataProxy.getDataProxy();
|
||||
|
@ -544,6 +593,9 @@ export function getExecuteSingleFunctions(workflow: Workflow, runExecutionData:
|
|||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getRestApiUrl: (): string => {
|
||||
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
|
||||
return getNodeParameter(workflow, runExecutionData, runIndex, connectionInputData, node, parameterName, itemIndex, fallbackValue);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowDataProxy: (): IWorkflowDataProxyData => {
|
||||
const dataProxy = new WorkflowDataProxy(workflow, runExecutionData, runIndex, itemIndex, node.name, connectionInputData);
|
||||
return dataProxy.getDataProxy();
|
||||
|
@ -594,6 +649,9 @@ export function getLoadOptionsFunctions(workflow: Workflow, node: INode, additio
|
|||
getCurrentNodeParameters: (): INodeParameters | undefined => {
|
||||
return JSON.parse('' + additionalData.currentNodeParameters);
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
|
||||
const runExecutionData: IRunExecutionData | null = null;
|
||||
const itemIndex = 0;
|
||||
|
@ -637,6 +695,9 @@ export function getExecuteHookFunctions(workflow: Workflow, node: INode, additio
|
|||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
|
||||
const runExecutionData: IRunExecutionData | null = null;
|
||||
const itemIndex = 0;
|
||||
|
@ -660,6 +721,9 @@ export function getExecuteHookFunctions(workflow: Workflow, node: INode, additio
|
|||
getWebhookDescription(name: string): IWebhookDescription | undefined {
|
||||
return getWebhookDescription(name, workflow, node);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowStaticData(type: string): IDataObject {
|
||||
return workflow.getStaticData(type, node);
|
||||
},
|
||||
|
@ -705,6 +769,9 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
|
|||
getMode: (): WorkflowExecuteMode => {
|
||||
return mode;
|
||||
},
|
||||
getNode: () => {
|
||||
return getNode(node);
|
||||
},
|
||||
getNodeParameter: (parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object => { //tslint:disable-line:no-any
|
||||
const runExecutionData: IRunExecutionData | null = null;
|
||||
const itemIndex = 0;
|
||||
|
@ -737,6 +804,9 @@ export function getExecuteWebhookFunctions(workflow: Workflow, node: INode, addi
|
|||
getTimezone: (): string => {
|
||||
return getTimezone(workflow, additionalData);
|
||||
},
|
||||
getWorkflow: () => {
|
||||
return getWorkflowMetadata(workflow);
|
||||
},
|
||||
getWorkflowStaticData(type: string): IDataObject {
|
||||
return workflow.getStaticData(type, node);
|
||||
},
|
||||
|
|
|
@ -192,14 +192,16 @@ export const workflowHelpers = mixins(
|
|||
};
|
||||
|
||||
let workflowId = this.$store.getters.workflowId;
|
||||
if (workflowId !== PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
||||
if (workflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
||||
workflowId = undefined;
|
||||
}
|
||||
|
||||
const workflowName = this.$store.getters.workflowName;
|
||||
|
||||
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 {
|
||||
return new Workflow(workflowId, nodes, connections, false, nodeTypes);
|
||||
return new Workflow({ id: workflowId, name: workflowName, nodes, connections, active: false, nodeTypes});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -159,11 +159,13 @@ export interface IExecuteFunctions {
|
|||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getInputData(inputIndex?: number, inputName?: string): INodeExecutionData[];
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, itemIndex: number, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getWorkflowDataProxy(itemIndex: number): IWorkflowDataProxyData;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
getRestApiUrl(): string;
|
||||
getTimezone(): string;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>;
|
||||
helpers: {
|
||||
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any
|
||||
|
@ -176,9 +178,11 @@ export interface IExecuteSingleFunctions {
|
|||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getInputData(inputIndex?: number, inputName?: string): INodeExecutionData;
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getRestApiUrl(): string;
|
||||
getTimezone(): string;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
getWorkflowDataProxy(): IWorkflowDataProxyData;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
helpers: {
|
||||
|
@ -193,6 +197,7 @@ export interface IExecuteWorkflowInfo {
|
|||
|
||||
export interface ILoadOptionsFunctions {
|
||||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getCurrentNodeParameter(parameterName: string): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object | undefined;
|
||||
getCurrentNodeParameters(): INodeParameters | undefined;
|
||||
|
@ -206,11 +211,13 @@ export interface ILoadOptionsFunctions {
|
|||
export interface IHookFunctions {
|
||||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeWebhookUrl: (name: string) => string | undefined;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getTimezone(): string;
|
||||
getWebhookDescription(name: string): IWebhookDescription | undefined;
|
||||
getWebhookName(): string;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
helpers: {
|
||||
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any
|
||||
|
@ -221,9 +228,11 @@ export interface IPollFunctions {
|
|||
__emit(data: INodeExecutionData[][]): void;
|
||||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getRestApiUrl(): string;
|
||||
getTimezone(): string;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
helpers: {
|
||||
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any
|
||||
|
@ -234,9 +243,11 @@ export interface ITriggerFunctions {
|
|||
emit(data: INodeExecutionData[][]): void;
|
||||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getRestApiUrl(): string;
|
||||
getTimezone(): string;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
helpers: {
|
||||
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any
|
||||
|
@ -248,6 +259,7 @@ export interface IWebhookFunctions {
|
|||
getCredentials(type: string): ICredentialDataDecryptedObject | undefined;
|
||||
getHeaderData(): object;
|
||||
getMode(): WorkflowExecuteMode;
|
||||
getNode(): INode;
|
||||
getNodeParameter(parameterName: string, fallbackValue?: any): NodeParameterValue | INodeParameters | NodeParameterValue[] | INodeParameters[] | object; //tslint:disable-line:no-any
|
||||
getNodeWebhookUrl: (name: string) => string | undefined;
|
||||
getQueryData(): object;
|
||||
|
@ -256,6 +268,7 @@ export interface IWebhookFunctions {
|
|||
getTimezone(): string;
|
||||
getWebhookName(): string;
|
||||
getWorkflowStaticData(type: string): IDataObject;
|
||||
getWorkflow(workflow: Workflow): IWorkflowMetadata;
|
||||
prepareOutputData(outputData: INodeExecutionData[], outputIndex?: number): Promise<INodeExecutionData[][]>;
|
||||
helpers: {
|
||||
[key: string]: (...args: any[]) => any //tslint:disable-line:no-any
|
||||
|
@ -519,6 +532,12 @@ export interface IWorkflowDataProxyData {
|
|||
$parameter: any; // tslint:disable-line:no-any
|
||||
}
|
||||
|
||||
export interface IWorkflowMetadata {
|
||||
id?: number | string;
|
||||
name?: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export type WebhookHttpMethod = 'GET' | 'POST';
|
||||
|
||||
export interface IWebhookResponseData {
|
||||
|
|
|
@ -41,6 +41,7 @@ tmpl.tmpl.errorHandler = () => { };
|
|||
|
||||
export class Workflow {
|
||||
id: string | undefined;
|
||||
name: string | undefined;
|
||||
nodes: INodes = {};
|
||||
connectionsBySourceNode: IConnections;
|
||||
connectionsByDestinationNode: IConnections;
|
||||
|
@ -52,15 +53,17 @@ export class Workflow {
|
|||
// ids of registred webhooks of nodes
|
||||
staticData: IDataObject;
|
||||
|
||||
constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) {
|
||||
this.id = id;
|
||||
this.nodeTypes = nodeTypes;
|
||||
// constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) {
|
||||
constructor(parameters: {id?: string, name?: string, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings}) {
|
||||
this.id = parameters.id;
|
||||
this.name = parameters.name;
|
||||
this.nodeTypes = parameters.nodeTypes;
|
||||
|
||||
// Save nodes in workflow as object to be able to get the
|
||||
// nodes easily by its name.
|
||||
// Also directly add the default values of the node type.
|
||||
let nodeType: INodeType | undefined;
|
||||
for (const node of nodes) {
|
||||
for (const node of parameters.nodes) {
|
||||
this.nodes[node.name] = node;
|
||||
nodeType = this.nodeTypes.getByName(node.type);
|
||||
|
||||
|
@ -77,16 +80,16 @@ export class Workflow {
|
|||
const nodeParameters = NodeHelpers.getNodeParameters(nodeType.description.properties, node.parameters, true, false);
|
||||
node.parameters = nodeParameters !== null ? nodeParameters : {};
|
||||
}
|
||||
this.connectionsBySourceNode = connections;
|
||||
this.connectionsBySourceNode = parameters.connections;
|
||||
|
||||
// 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 || {};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue