Change evaluateExpression -> $evaluateExpression

This commit is contained in:
Jan Oberhauser 2020-04-13 16:51:04 +02:00
parent 399397fbb7
commit 4ad009214e
6 changed files with 24 additions and 13 deletions

View file

@ -163,7 +163,7 @@ const workflowName = $workflow.name;
``` ```
#### Method: evaluateExpression(expression: string, itemIndex: number) #### Method: $evaluateExpression(expression: string, itemIndex: number)
Evaluates a given string as expression. Evaluates a given string as expression.
If no `itemIndex` is provided it uses by default in the Function-Node the data of item 0 and If no `itemIndex` is provided it uses by default in the Function-Node the data of item 0 and
@ -172,8 +172,8 @@ in the Function Item-Node the data of the current item.
Example: Example:
```javascript ```javascript
items[0].json.variable1 = evaluateExpression('{{1+2}}'); items[0].json.variable1 = $evaluateExpression('{{1+2}}');
items[0].json.variable2 = evaluateExpression($node["Set"].json["myExpression"], 1); items[0].json.variable2 = $evaluateExpression($node["Set"].json["myExpression"], 1);
return items; return items;
``` ```

View file

@ -2,6 +2,23 @@
This list shows all the versions which include breaking changes and how to upgrade This list shows all the versions which include breaking changes and how to upgrade
## 0.62.0
### What changed?
The function "evaluateExpression(...)" got renamed to "$evaluateExpression()"
in Function and FunctionItem Nodes to simplify code and to normalize function
names.
### When is action necessary?
If "evaluateExpression(...)" gets used in any Function or FunctionItem Node.
### How to upgrade:
Simply replace the "evaluateExpression(...)" with "$evaluateExpression(...)".
## 0.52.0 ## 0.52.0
### What changed? ### What changed?

View file

@ -47,9 +47,6 @@ export class Function implements INodeType {
// Define the global objects for the custom function // Define the global objects for the custom function
const sandbox = { const sandbox = {
evaluateExpression: (expression: string, itemIndex = 0) => {
return this.evaluateExpression(expression, itemIndex);
},
getNodeParameter: this.getNodeParameter, getNodeParameter: this.getNodeParameter,
getWorkflowStaticData: this.getWorkflowStaticData, getWorkflowStaticData: this.getWorkflowStaticData,
helpers: this.helpers, helpers: this.helpers,

View file

@ -48,9 +48,6 @@ export class FunctionItem implements INodeType {
// Define the global objects for the custom function // Define the global objects for the custom function
const sandbox = { const sandbox = {
evaluateExpression: (expression: string, itemIndex: number | undefined) => {
return this.evaluateExpression(expression, itemIndex);
},
getBinaryData: (): IBinaryKeyData | undefined => { getBinaryData: (): IBinaryKeyData | undefined => {
return item.binary; return item.binary;
}, },

View file

@ -899,9 +899,6 @@ export class Workflow {
// Generate a data proxy which allows to query workflow data // Generate a data proxy which allows to query workflow data
const dataProxy = new WorkflowDataProxy(this, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData); const dataProxy = new WorkflowDataProxy(this, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData);
const data = dataProxy.getDataProxy(); const data = dataProxy.getDataProxy();
data.$evaluateExpression = (expression: string) => {
return this.resolveSimpleParameterValue('=' + expression, runExecutionData, runIndex, itemIndex, activeNodeName, connectionInputData, returnObjectAsString);
};
// Execute the expression // Execute the expression
try { try {

View file

@ -335,7 +335,10 @@ export class WorkflowDataProxy {
$binary: {}, // Placeholder $binary: {}, // Placeholder
$data: {}, // Placeholder $data: {}, // Placeholder
$env: this.envGetter(), $env: this.envGetter(),
$evaluateExpression: (expression: string) => { }, // Placeholder $evaluateExpression: (expression: string, itemIndex?: number) => {
itemIndex = itemIndex || that.itemIndex;
return that.workflow.getParameterValue('=' + expression, that.runExecutionData, that.runIndex, itemIndex, that.activeNodeName, that.connectionInputData);
},
$item: (itemIndex: number, runIndex?: number) => { $item: (itemIndex: number, runIndex?: number) => {
const defaultReturnRunIndex = runIndex === undefined ? -1 : runIndex; const defaultReturnRunIndex = runIndex === undefined ? -1 : runIndex;
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData, defaultReturnRunIndex); const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData, defaultReturnRunIndex);