@teleporthq/teleport-plugin-next-workflows 0.45.14 → 0.45.16

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.
Files changed (31) hide show
  1. package/__tests__/cron-route-loop-templateparams.test.ts +5 -4
  2. package/__tests__/custom-js-loop-scope.test.ts +10 -5
  3. package/__tests__/loop-collection-unwrap.test.ts +6 -1
  4. package/__tests__/server-loop-body-branches.test.ts +188 -0
  5. package/__tests__/server-loop-types.test.ts +371 -0
  6. package/__tests__/server-nested-loops.test.ts +392 -0
  7. package/__tests__/streaming-route-if-branch.test.ts +107 -0
  8. package/dist/cjs/api-route-generator.d.ts.map +1 -1
  9. package/dist/cjs/api-route-generator.js +57 -248
  10. package/dist/cjs/api-route-generator.js.map +1 -1
  11. package/dist/cjs/executor-generator.d.ts.map +1 -1
  12. package/dist/cjs/executor-generator.js +84 -27
  13. package/dist/cjs/executor-generator.js.map +1 -1
  14. package/dist/cjs/server-runtime-code.d.ts.map +1 -1
  15. package/dist/cjs/server-runtime-code.js +67 -0
  16. package/dist/cjs/server-runtime-code.js.map +1 -1
  17. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  18. package/dist/esm/api-route-generator.d.ts.map +1 -1
  19. package/dist/esm/api-route-generator.js +57 -248
  20. package/dist/esm/api-route-generator.js.map +1 -1
  21. package/dist/esm/executor-generator.d.ts.map +1 -1
  22. package/dist/esm/executor-generator.js +84 -27
  23. package/dist/esm/executor-generator.js.map +1 -1
  24. package/dist/esm/server-runtime-code.d.ts.map +1 -1
  25. package/dist/esm/server-runtime-code.js +67 -0
  26. package/dist/esm/server-runtime-code.js.map +1 -1
  27. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +2 -2
  29. package/src/api-route-generator.ts +57 -248
  30. package/src/executor-generator.ts +84 -27
  31. package/src/server-runtime-code.ts +67 -0
@@ -141,6 +141,81 @@ 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
+
198
+ // The nodes of the branch an if-statement did NOT take: everything reachable
199
+ // from that branch's edge, never walking back through the if itself nor past
200
+ // stopAtId (the loop a body belongs to, whose loop-back edge leads out of it).
201
+ function nonTakenBranchNodeIds(edges, ifNodeId, conditionHeld, stopAtId) {
202
+ var skipHandle = conditionHeld ? 'false' : 'true';
203
+ var all = edges || [];
204
+ var skipEdge = all.find(function(e) { return e.source === ifNodeId && e.sourceHandle === skipHandle; });
205
+ var skipIds = {};
206
+ if (!skipEdge) return skipIds;
207
+ var queue = [skipEdge.target];
208
+ while (queue.length > 0) {
209
+ var id = queue.shift();
210
+ if (skipIds[id] || id === ifNodeId || id === stopAtId) continue;
211
+ skipIds[id] = true;
212
+ all.forEach(function(e) {
213
+ if (e.source === id && !skipIds[e.target]) queue.push(e.target);
214
+ });
215
+ }
216
+ return skipIds;
217
+ }
218
+
144
219
  function resolveCtxRef(ref, context) {
145
220
  var elem = context.triggerElement;
146
221
  if (!elem || typeof elem.getAttribute !== 'function') return undefined;
@@ -1476,35 +1551,15 @@ async function executeLoop(loopNode, config, allNodes, edges, context, nodeHandl
1476
1551
  context[loopNode.id] = loopType === 'map'
1477
1552
  ? { results: results, iterations: collection.length }
1478
1553
  : { 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
1554
  } 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++;
1555
+ const steps = createLoopSteps(loopNode, config, context);
1556
+ for (let pass = steps.next(context); pass; pass = steps.next(context)) {
1557
+ const passCtx = Object.assign({}, context);
1558
+ passCtx[pass.key] = pass.value;
1559
+ await executeNodes(bodyNodes, edges, passCtx, nodeHandlers, workflowConfig, callServerSegment, executionId);
1560
+ Object.assign(context, passCtx);
1506
1561
  }
1507
- context[loopNode.id] = { completed: true, iterations: iter };
1562
+ context[loopNode.id] = { completed: true, iterations: steps.iterations() };
1508
1563
  }
1509
1564
  } finally {
1510
1565
  context.__loopScopeStack.pop();
@@ -1800,6 +1855,8 @@ module.exports = {
1800
1855
  resolveRichTextContext,
1801
1856
  unwrapWorkflowCollection,
1802
1857
  loopIterationContext,
1858
+ createLoopSteps,
1859
+ nonTakenBranchNodeIds,
1803
1860
  snapshotIncomingContext,
1804
1861
  segmentReply,
1805
1862
  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,MAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwpBR,CAAA;AACD,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"server-runtime-code.d.ts","sourceRoot":"","sources":["../../src/server-runtime-code.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,QAAiB,CAAA;AAEtD,kFAAkF;AAClF,eAAO,MAAM,2BAA2B,QAAY,CAAA;AAEpD,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,4CAA4C,CAAA;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,yBAAyB,aAC3B;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,KAC3C,MA6xBF,CAAA"}
1
+ {"version":3,"file":"server-runtime-code.d.ts","sourceRoot":"","sources":["../../src/server-runtime-code.ts"],"names":[],"mappings":"AAMA,wEAAwE;AACxE,eAAO,MAAM,wBAAwB,QAAiB,CAAA;AAEtD,kFAAkF;AAClF,eAAO,MAAM,2BAA2B,QAAY,CAAA;AAEpD,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,4CAA4C,CAAA;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,eAAO,MAAM,yBAAyB,aAC3B;IAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAAE,KAC3C,MAg2BF,CAAA"}
@@ -854,7 +854,74 @@ function handOffPendingNodePromises(context) {
854
854
  return Promise.resolve();
855
855
  }
856
856
 
857
+ // One loop of a server route, a loop inside its body included: every route
858
+ // kind runs its loops through here and differs only in runBodyNode(node,
859
+ // resolvedConfig), which runs one ordinary body node and stores its result.
860
+ // The body is walked in step order, once per pass of the loop type (see
861
+ // createLoopSteps). An if-statement skips the branch it does not take for
862
+ // that pass only; a loop found in the body runs all of its own passes on
863
+ // every pass of this one, and its body nodes belong to it alone.
864
+ // Returns every node id between the loop and its loop-back edge (the bodies
865
+ // of inner loops included), which the route must not run again.
866
+ async function runServerLoop(loopNode, config, sortedNodes, edges, context, runBodyNode) {
867
+ var bodyNodeIds = {};
868
+ utils.getLoopBodyNodeIds(loopNode.id, edges).forEach(function(id) { bodyNodeIds[id] = true; });
869
+ var innerLoopBodyIds = {};
870
+ sortedNodes.forEach(function(n) {
871
+ if (!bodyNodeIds[n.id] || n.type !== 'general-loop') return;
872
+ utils.getLoopBodyNodeIds(n.id, edges).forEach(function(id) { innerLoopBodyIds[id] = true; });
873
+ });
874
+ var bodyNodes = sortedNodes.filter(function(n) { return bodyNodeIds[n.id] && !innerLoopBodyIds[n.id]; });
875
+ // A map loop publishes the output of its last body node per pass, as
876
+ // Array.prototype.map does (general-loop in node-context-schemas.json).
877
+ var isMap = (config.loopType || 'forEach') === 'map';
878
+ var lastBodyNode = bodyNodes[bodyNodes.length - 1];
879
+ // A helper node's envelope ({ result }, { records }, { matches }) is
880
+ // unwrapped to the one array it holds.
881
+ var collection = utils.unwrapWorkflowCollection(config.collection);
882
+ var results = [];
883
+
884
+ // The scope stack lets custom JavaScript tell the nodes before the outermost
885
+ // loop (params) from those inside a loop at each depth (innerParams); the
886
+ // registry keeps a finished inner loop recognisable as scaffolding.
887
+ if (!context.__loopScopeStack) context.__loopScopeStack = [];
888
+ context.__loopScopeStack.push({ loopNodeId: loopNode.id, bodyNodeIds: bodyNodeIds });
889
+ if (!context.__loopNodeIds) context.__loopNodeIds = {};
890
+ context.__loopNodeIds[loopNode.id] = true;
891
+
892
+ var steps = utils.createLoopSteps(loopNode, config, context, collection);
893
+ for (var pass = steps.next(context); pass; pass = steps.next(context)) {
894
+ context[pass.key] = pass.value;
895
+ var skippedThisPass = {};
896
+ for (var i = 0; i < bodyNodes.length; i++) {
897
+ var bodyNode = bodyNodes[i];
898
+ if (skippedThisPass[bodyNode.id]) continue;
899
+ var resolved = utils.resolveNodeConfig(bodyNode, context);
900
+ resolved.__nodeId = bodyNode.id;
901
+ if (bodyNode.type === 'general-if-statement') {
902
+ var held = utils.evaluateCondition(resolved, context, bodyNode.config);
903
+ context[bodyNode.id] = { result: held };
904
+ Object.assign(skippedThisPass, utils.nonTakenBranchNodeIds(edges, bodyNode.id, held, loopNode.id));
905
+ continue;
906
+ }
907
+ if (bodyNode.type === 'general-loop') {
908
+ await runServerLoop(bodyNode, resolved, sortedNodes, edges, context, runBodyNode);
909
+ continue;
910
+ }
911
+ await runBodyNode(bodyNode, resolved);
912
+ }
913
+ if (isMap) {
914
+ results.push(lastBodyNode ? context[lastBodyNode.id] : context[loopNode.id]);
915
+ }
916
+ }
917
+
918
+ context.__loopScopeStack.pop();
919
+ context[loopNode.id] = { completed: true, iterations: steps.iterations(), results: results };
920
+ return bodyNodeIds;
921
+ }
922
+
857
923
  module.exports = Object.assign({}, utils, {
924
+ runServerLoop: runServerLoop,
858
925
  handOffPendingNodePromises: handOffPendingNodePromises,
859
926
  claimSegmentContext: claimSegmentContext,
860
927
  segmentReply: segmentReply,
@@ -1 +1 @@
1
- {"version":3,"file":"server-runtime-code.js","sourceRoot":"","sources":["../../src/server-runtime-code.ts"],"names":[],"m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