mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 03:12:15 +00:00
✨ Make workflow metadata available in expresions and
node-functions
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user