@teleporthq/teleport-plugin-next-workflows 0.45.13 → 0.45.15

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.
@@ -141,6 +141,60 @@ function loopIterationContext(collection, index) {
141
141
  };
142
142
  }
143
143
 
144
+ // How every loop type steps, for the client executor and for each server
145
+ // route alike. next(context) hands back what one pass publishes before its
146
+ // body runs ({ key, value }, stored as context[key]), or null once the loop is
147
+ // over. A collection is walked under the loop's own id; a counted or a
148
+ // conditional loop publishes its counter under "<loopId>_iter". A while / until
149
+ // condition is tested before every pass, against the context of that pass.
150
+ var DEFAULT_LOOP_MAX_ITERATIONS = 1000;
151
+
152
+ function createLoopSteps(loopNode, config, context, collection) {
153
+ var loopType = config.loopType || 'forEach';
154
+ var iterKey = loopNode.id + '_iter';
155
+ var passes = 0;
156
+ var next;
157
+ if (loopType === 'forEach' || loopType === 'map') {
158
+ next = function() {
159
+ return passes < collection.length
160
+ ? { key: loopNode.id, value: loopIterationContext(collection, passes) }
161
+ : null;
162
+ };
163
+ } else if (loopType === 'for') {
164
+ var cursor = Number(resolveValue(config.startIndex, context)) || 0;
165
+ var end = Number(resolveValue(config.endIndex, context)) || 0;
166
+ var step = Number(resolveValue(config.step, context)) || 1;
167
+ next = function() {
168
+ if (!(step > 0 ? cursor < end : cursor > end)) return null;
169
+ var index = cursor;
170
+ cursor += step;
171
+ return { key: iterKey, value: { index: index } };
172
+ };
173
+ } else {
174
+ var maxIterations = Number(resolveValue(config.maxIterations, context)) || DEFAULT_LOOP_MAX_ITERATIONS;
175
+ var authoredCondition = loopNode.config && loopNode.config.condition;
176
+ next = function(passContext) {
177
+ if (passes >= maxIterations) return null;
178
+ var scaffold = { iteration: passes };
179
+ var testContext = Object.assign({}, passContext);
180
+ testContext[iterKey] = scaffold;
181
+ var condition = resolveValue(config.condition, testContext);
182
+ // Only the authored condition is compiled (see runExpression).
183
+ var holds = runExpression(authoredCondition, condition, ['context'], [testContext], testContext);
184
+ if (loopType === 'until' ? holds : !holds) return null;
185
+ return { key: iterKey, value: scaffold };
186
+ };
187
+ }
188
+ return {
189
+ next: function(passContext) {
190
+ var pass = next(passContext || context);
191
+ if (pass) passes++;
192
+ return pass;
193
+ },
194
+ iterations: function() { return passes; }
195
+ };
196
+ }
197
+
144
198
  function resolveCtxRef(ref, context) {
145
199
  var elem = context.triggerElement;
146
200
  if (!elem || typeof elem.getAttribute !== 'function') return undefined;
@@ -1476,35 +1530,15 @@ async function executeLoop(loopNode, config, allNodes, edges, context, nodeHandl
1476
1530
  context[loopNode.id] = loopType === 'map'
1477
1531
  ? { results: results, iterations: collection.length }
1478
1532
  : { completed: true, iterations: collection.length };
1479
- } else if (loopType === 'for') {
1480
- const start = resolveValue(config.startIndex, context) || 0;
1481
- const end = resolveValue(config.endIndex, context) || 0;
1482
- const step = resolveValue(config.step, context) || 1;
1483
- let count = 0;
1484
- for (let fi = start; step > 0 ? fi < end : fi > end; fi += step) {
1485
- const forCtx = Object.assign({}, context);
1486
- forCtx[loopNode.id + '_iter'] = { index: fi };
1487
- await executeNodes(bodyNodes, edges, forCtx, nodeHandlers, workflowConfig, callServerSegment, executionId);
1488
- Object.assign(context, forCtx);
1489
- count++;
1490
- }
1491
- context[loopNode.id] = { completed: true, iterations: count };
1492
1533
  } else {
1493
- const maxIter = resolveValue(config.maxIterations, context) || 1000;
1494
- let iter = 0;
1495
- while (iter < maxIter) {
1496
- const whileCtx = Object.assign({}, context);
1497
- whileCtx[loopNode.id + '_iter'] = { iteration: iter };
1498
- const condStr = resolveValue(config.condition, whileCtx);
1499
- // Only the authored condition is compiled (see runExpression).
1500
- const condResult = runExpression(loopNode.config && loopNode.config.condition, condStr, ['context'], [whileCtx], whileCtx);
1501
- if (loopType === 'while' && !condResult) break;
1502
- if (loopType === 'until' && condResult) break;
1503
- await executeNodes(bodyNodes, edges, whileCtx, nodeHandlers, workflowConfig, callServerSegment, executionId);
1504
- Object.assign(context, whileCtx);
1505
- iter++;
1534
+ const steps = createLoopSteps(loopNode, config, context);
1535
+ for (let pass = steps.next(context); pass; pass = steps.next(context)) {
1536
+ const passCtx = Object.assign({}, context);
1537
+ passCtx[pass.key] = pass.value;
1538
+ await executeNodes(bodyNodes, edges, passCtx, nodeHandlers, workflowConfig, callServerSegment, executionId);
1539
+ Object.assign(context, passCtx);
1506
1540
  }
1507
- context[loopNode.id] = { completed: true, iterations: iter };
1541
+ context[loopNode.id] = { completed: true, iterations: steps.iterations() };
1508
1542
  }
1509
1543
  } finally {
1510
1544
  context.__loopScopeStack.pop();
@@ -1800,6 +1834,7 @@ module.exports = {
1800
1834
  resolveRichTextContext,
1801
1835
  unwrapWorkflowCollection,
1802
1836
  loopIterationContext,
1837
+ createLoopSteps,
1803
1838
  snapshotIncomingContext,
1804
1839
  segmentReply,
1805
1840
  withoutCredentialColumns,
@@ -1 +1 @@
1
- {"version":3,"file":"executor-generator.js","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,iCAAiC,GAClC,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;AAC1F,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACpF,OAAO,EAAE,wCAAwC,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAA;AACzE,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAA;AAYpE,MAAM,gBAAgB,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,CAAA;AAE9E,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,UAAqC,EAAE,EAAU,EAAE;IAChG,OAAO;;;;;;;;;EASP,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