@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
@@ -144,6 +144,81 @@ 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
+
201
+ // The nodes of the branch an if-statement did NOT take: everything reachable
202
+ // from that branch's edge, never walking back through the if itself nor past
203
+ // stopAtId (the loop a body belongs to, whose loop-back edge leads out of it).
204
+ function nonTakenBranchNodeIds(edges, ifNodeId, conditionHeld, stopAtId) {
205
+ var skipHandle = conditionHeld ? 'false' : 'true';
206
+ var all = edges || [];
207
+ var skipEdge = all.find(function(e) { return e.source === ifNodeId && e.sourceHandle === skipHandle; });
208
+ var skipIds = {};
209
+ if (!skipEdge) return skipIds;
210
+ var queue = [skipEdge.target];
211
+ while (queue.length > 0) {
212
+ var id = queue.shift();
213
+ if (skipIds[id] || id === ifNodeId || id === stopAtId) continue;
214
+ skipIds[id] = true;
215
+ all.forEach(function(e) {
216
+ if (e.source === id && !skipIds[e.target]) queue.push(e.target);
217
+ });
218
+ }
219
+ return skipIds;
220
+ }
221
+
147
222
  function resolveCtxRef(ref, context) {
148
223
  var elem = context.triggerElement;
149
224
  if (!elem || typeof elem.getAttribute !== 'function') return undefined;
@@ -1479,35 +1554,15 @@ async function executeLoop(loopNode, config, allNodes, edges, context, nodeHandl
1479
1554
  context[loopNode.id] = loopType === 'map'
1480
1555
  ? { results: results, iterations: collection.length }
1481
1556
  : { 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
1557
  } 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++;
1558
+ const steps = createLoopSteps(loopNode, config, context);
1559
+ for (let pass = steps.next(context); pass; pass = steps.next(context)) {
1560
+ const passCtx = Object.assign({}, context);
1561
+ passCtx[pass.key] = pass.value;
1562
+ await executeNodes(bodyNodes, edges, passCtx, nodeHandlers, workflowConfig, callServerSegment, executionId);
1563
+ Object.assign(context, passCtx);
1509
1564
  }
1510
- context[loopNode.id] = { completed: true, iterations: iter };
1565
+ context[loopNode.id] = { completed: true, iterations: steps.iterations() };
1511
1566
  }
1512
1567
  } finally {
1513
1568
  context.__loopScopeStack.pop();
@@ -1803,6 +1858,8 @@ module.exports = {
1803
1858
  resolveRichTextContext,
1804
1859
  unwrapWorkflowCollection,
1805
1860
  loopIterationContext,
1861
+ createLoopSteps,
1862
+ nonTakenBranchNodeIds,
1806
1863
  snapshotIncomingContext,
1807
1864
  segmentReply,
1808
1865
  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;I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;;;;;;;;;;;;;;;;;;;;;CAwpBR,CAAA;AACD,CAAC,CAAA;AA1pBY,QAAA,yBAAyB,6BA0pBrC"}
@@ -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"}
@@ -857,7 +857,74 @@ function handOffPendingNodePromises(context) {
857
857
  return Promise.resolve();
858
858
  }
859
859
 
860
+ // One loop of a server route, a loop inside its body included: every route
861
+ // kind runs its loops through here and differs only in runBodyNode(node,
862
+ // resolvedConfig), which runs one ordinary body node and stores its result.
863
+ // The body is walked in step order, once per pass of the loop type (see
864
+ // createLoopSteps). An if-statement skips the branch it does not take for
865
+ // that pass only; a loop found in the body runs all of its own passes on
866
+ // every pass of this one, and its body nodes belong to it alone.
867
+ // Returns every node id between the loop and its loop-back edge (the bodies
868
+ // of inner loops included), which the route must not run again.
869
+ async function runServerLoop(loopNode, config, sortedNodes, edges, context, runBodyNode) {
870
+ var bodyNodeIds = {};
871
+ utils.getLoopBodyNodeIds(loopNode.id, edges).forEach(function(id) { bodyNodeIds[id] = true; });
872
+ var innerLoopBodyIds = {};
873
+ sortedNodes.forEach(function(n) {
874
+ if (!bodyNodeIds[n.id] || n.type !== 'general-loop') return;
875
+ utils.getLoopBodyNodeIds(n.id, edges).forEach(function(id) { innerLoopBodyIds[id] = true; });
876
+ });
877
+ var bodyNodes = sortedNodes.filter(function(n) { return bodyNodeIds[n.id] && !innerLoopBodyIds[n.id]; });
878
+ // A map loop publishes the output of its last body node per pass, as
879
+ // Array.prototype.map does (general-loop in node-context-schemas.json).
880
+ var isMap = (config.loopType || 'forEach') === 'map';
881
+ var lastBodyNode = bodyNodes[bodyNodes.length - 1];
882
+ // A helper node's envelope ({ result }, { records }, { matches }) is
883
+ // unwrapped to the one array it holds.
884
+ var collection = utils.unwrapWorkflowCollection(config.collection);
885
+ var results = [];
886
+
887
+ // The scope stack lets custom JavaScript tell the nodes before the outermost
888
+ // loop (params) from those inside a loop at each depth (innerParams); the
889
+ // registry keeps a finished inner loop recognisable as scaffolding.
890
+ if (!context.__loopScopeStack) context.__loopScopeStack = [];
891
+ context.__loopScopeStack.push({ loopNodeId: loopNode.id, bodyNodeIds: bodyNodeIds });
892
+ if (!context.__loopNodeIds) context.__loopNodeIds = {};
893
+ context.__loopNodeIds[loopNode.id] = true;
894
+
895
+ var steps = utils.createLoopSteps(loopNode, config, context, collection);
896
+ for (var pass = steps.next(context); pass; pass = steps.next(context)) {
897
+ context[pass.key] = pass.value;
898
+ var skippedThisPass = {};
899
+ for (var i = 0; i < bodyNodes.length; i++) {
900
+ var bodyNode = bodyNodes[i];
901
+ if (skippedThisPass[bodyNode.id]) continue;
902
+ var resolved = utils.resolveNodeConfig(bodyNode, context);
903
+ resolved.__nodeId = bodyNode.id;
904
+ if (bodyNode.type === 'general-if-statement') {
905
+ var held = utils.evaluateCondition(resolved, context, bodyNode.config);
906
+ context[bodyNode.id] = { result: held };
907
+ Object.assign(skippedThisPass, utils.nonTakenBranchNodeIds(edges, bodyNode.id, held, loopNode.id));
908
+ continue;
909
+ }
910
+ if (bodyNode.type === 'general-loop') {
911
+ await runServerLoop(bodyNode, resolved, sortedNodes, edges, context, runBodyNode);
912
+ continue;
913
+ }
914
+ await runBodyNode(bodyNode, resolved);
915
+ }
916
+ if (isMap) {
917
+ results.push(lastBodyNode ? context[lastBodyNode.id] : context[loopNode.id]);
918
+ }
919
+ }
920
+
921
+ context.__loopScopeStack.pop();
922
+ context[loopNode.id] = { completed: true, iterations: steps.iterations(), results: results };
923
+ return bodyNodeIds;
924
+ }
925
+
860
926
  module.exports = Object.assign({}, utils, {
927
+ runServerLoop: runServerLoop,
861
928
  handOffPendingNodePromises: handOffPendingNodePromises,
862
929
  claimSegmentContext: claimSegmentContext,
863
930
  segmentReply: segmentReply,
@@ -1 +1 @@
1
- {"version":3,"file":"server-runtime-code.js","sourceRoot":"","sources":["../../src/server-runtime-code.ts"],"names":[],"mappings":";;;AAAA,uEAA8E;AAC9E,uEAAoF;AACpF,uEAA8D;AAC9D,iFAAkE;AAClE,yDAAsE;AAEtE,wEAAwE;AAC3D,QAAA,wBAAwB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;AAEtD,kFAAkF;AACrE,QAAA,2BAA2B,GAAG,EAAE,GAAG,IAAI,CAAA;AAEpD,8EAA8E;AACjE,QAAA,oBAAoB,GAAG,yCAAyC,CAAA;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACI,MAAM,yBAAyB,GAAG,CACvC,UAA+C,EAAE,EACzC,EAAE,CAAC;;;;EAIX,IAAA,oDAAiC,GAAE;;;;;;;;;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