n8n-nodes-while-loop 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,15 +37,15 @@ class WhileLoop {
37
37
  typeOptions: { minValue: 1, maxValue: 100000 },
38
38
  description: "Safety cap to prevent infinite loops",
39
39
  },
40
- {
41
- displayName: "Condition Expression",
42
- name: "conditionExpression",
43
- type: "string",
44
- typeOptions: { rows: 2 },
45
- default: "={{$json.counter < 5}}",
46
- description: "n8n expression that must evaluate to true to continue looping. You can use {{$loop.iteration}}.",
47
- displayOptions: { show: { mode: ["expression"] } },
48
- },
40
+ {
41
+ displayName: "Condition Expression",
42
+ name: "conditionExpression",
43
+ type: "string",
44
+ typeOptions: { rows: 2 },
45
+ default: "={{$json.loopIteration < 5}}",
46
+ description: "n8n expression that must be true to continue. Available: $json.loopIteration, $json.loopFirst, $json.loopMax.",
47
+ displayOptions: { show: { mode: ["expression"] } },
48
+ },
49
49
  {
50
50
  displayName: "Add Loop Metadata",
51
51
  name: "addMeta",
@@ -78,18 +78,21 @@ class WhileLoop {
78
78
  }
79
79
  else {
80
80
  try {
81
- const originalLoop = items[i].json?.$loop;
82
- items[i].json = items[i].json || {};
83
- items[i].json.$loop = { iteration };
84
- const exprResult = this.evaluateExpression(conditionExpression, i, items);
81
+ const injected = {
82
+ loopIteration: iteration,
83
+ loopFirst: iteration === 0,
84
+ loopMax: maxIterations,
85
+ };
86
+ const originalJson = items[i].json || {};
87
+ const tempItem = {
88
+ ...items[i],
89
+ json: {
90
+ ...originalJson,
91
+ ...injected,
92
+ },
93
+ };
94
+ const exprResult = this.evaluateExpression(conditionExpression, i, undefined, undefined, tempItem);
85
95
  shouldContinue = Boolean(exprResult) && iteration < maxIterations;
86
- // restore
87
- if (originalLoop === undefined) {
88
- delete items[i].json.$loop;
89
- }
90
- else {
91
- items[i].json.$loop = originalLoop;
92
- }
93
96
  }
94
97
  catch (error) {
95
98
  throw new NodeApiError(this.getNode(), error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-while-loop",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Simple while-loop control node for n8n with counter or expression conditions",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",