From b1719f1bccd1aa2d4db6b0f5b41ab4262c33b3d0 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 15 Feb 2020 16:01:00 -0800 Subject: [PATCH] :zap: Make node "json" data available in expression via "json" key --- docs/node-basics.md | 2 +- docs/nodes.md | 6 +++--- packages/editor-ui/src/components/VariableSelector.vue | 2 +- packages/workflow/src/WorkflowDataProxy.ts | 10 ++++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/node-basics.md b/docs/node-basics.md index 15bd8e2c75..ff319fd4d7 100644 --- a/docs/node-basics.md +++ b/docs/node-basics.md @@ -31,7 +31,7 @@ With the help of expressions, it is possible to set node parameters dynamically An expression could look like this: -My name is: `{{$node["Webhook"].data["query"]["name"]}}` +My name is: `{{$node["Webhook"].json["query"]["name"]}}` This one would return "My name is: " and then attach the value that the node with the name "Webhook" outputs and there select the property "query" and its key "name". So if the node would output this data: diff --git a/docs/nodes.md b/docs/nodes.md index cf2484c6c7..03620ab01e 100644 --- a/docs/nodes.md +++ b/docs/nodes.md @@ -75,9 +75,9 @@ Example: ```typescript // Returns the value of the JSON data property "myNumber" of Node "Set" (first item) -const myNumber = $item(0).$node["Set"].data["myNumber"]; +const myNumber = $item(0).$node["Set"].json["myNumber"]; // Like above but data of the 6th item -const myNumber = $item(5).$node["Set"].data["myNumber"]; +const myNumber = $item(5).$node["Set"].json["myNumber"]; // Returns the value of the parameter "channel" of Node "Slack". // If it contains an expression the value will be resolved with the @@ -93,7 +93,7 @@ const channel = $item(9).$node["Slack"].parameter["channel"]; Works exactly like `$item` with the difference that it will always return the data of the first item. ```typescript -const myNumber = $node["Set"].data['myNumber']; +const myNumber = $node["Set"].json['myNumber']; const channel = $node["Slack"].parameter["channel"]; ``` diff --git a/packages/editor-ui/src/components/VariableSelector.vue b/packages/editor-ui/src/components/VariableSelector.vue index 22075d5d0c..1975f332ac 100644 --- a/packages/editor-ui/src/components/VariableSelector.vue +++ b/packages/editor-ui/src/components/VariableSelector.vue @@ -293,7 +293,7 @@ export default mixins( if (outputData.hasOwnProperty('json')) { const jsonDataOptions: IVariableSelectorOption[] = []; for (const propertyName of Object.keys(outputData.json)) { - jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].data`, propertyName, filterText)); + jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].json`, propertyName, filterText)); } if (jsonDataOptions.length) { diff --git a/packages/workflow/src/WorkflowDataProxy.ts b/packages/workflow/src/WorkflowDataProxy.ts index fc0754bacc..d713758e23 100644 --- a/packages/workflow/src/WorkflowDataProxy.ts +++ b/packages/workflow/src/WorkflowDataProxy.ts @@ -127,7 +127,7 @@ export class WorkflowDataProxy { get(target, name, receiver) { name = name.toString(); - if (['binary', 'data'].includes(name)) { + if (['binary', 'data', 'json'].includes(name)) { let executionData: INodeExecutionData[]; if (shortSyntax === false) { // Long syntax got used to return data from node in path @@ -180,7 +180,7 @@ export class WorkflowDataProxy { throw new Error(`No data found for item-index: "${that.itemIndex}"`); } - if (name === 'data') { + if (['data', 'json'].includes(name as string)) { // JSON-Data return executionData[that.itemIndex].json; } else if (name === 'binary') { @@ -275,15 +275,17 @@ export class WorkflowDataProxy { const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData); return dataProxy.getDataProxy(); }, + $json: {}, // Placeholder $node: this.nodeGetter(), $parameter: this.nodeParameterGetter(this.activeNodeName), + $workflow: this.workflowGetter(), }; return new Proxy(base, { get(target, name, receiver) { - if (name === '$data') { + if (['$data', '$json'].includes(name as string)) { // @ts-ignore - return that.nodeDataGetter(that.activeNodeName, true).data; + return that.nodeDataGetter(that.activeNodeName, true).json; } else if (name === '$binary') { // @ts-ignore return that.nodeDataGetter(that.activeNodeName, true).binary;