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