flowcraft 1.0.0-beta.8 → 1.0.0

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 (134) hide show
  1. package/README.md +68 -200
  2. package/dist/builder/graph/graph.d.ts +57 -0
  3. package/dist/builder/graph/graph.js +21 -0
  4. package/dist/builder/graph/graph.js.map +1 -0
  5. package/dist/builder/graph/index.d.ts +8 -0
  6. package/dist/builder/graph/index.js +23 -0
  7. package/dist/builder/graph/index.js.map +1 -0
  8. package/dist/builder/graph/internal-nodes.d.ts +59 -0
  9. package/dist/builder/graph/internal-nodes.js +20 -0
  10. package/dist/builder/graph/internal-nodes.js.map +1 -0
  11. package/dist/builder/graph/runner.d.ts +51 -0
  12. package/dist/builder/graph/runner.js +21 -0
  13. package/dist/builder/graph/runner.js.map +1 -0
  14. package/dist/builder/graph/types.d.ts +3 -0
  15. package/dist/builder/graph/types.js +3 -0
  16. package/dist/builder/graph/types.js.map +1 -0
  17. package/dist/builder/index.d.ts +8 -0
  18. package/dist/builder/index.js +24 -0
  19. package/dist/builder/index.js.map +1 -0
  20. package/dist/builder/patterns.d.ts +136 -0
  21. package/dist/builder/patterns.js +19 -0
  22. package/dist/builder/patterns.js.map +1 -0
  23. package/dist/chunk-3YMBNZ77.js +441 -0
  24. package/dist/chunk-3YMBNZ77.js.map +1 -0
  25. package/dist/chunk-64DNBF5W.js +36 -0
  26. package/dist/chunk-64DNBF5W.js.map +1 -0
  27. package/dist/chunk-6QCXIRLA.js +18 -0
  28. package/dist/chunk-6QCXIRLA.js.map +1 -0
  29. package/dist/chunk-7XUN3OQT.js +3 -0
  30. package/dist/chunk-7XUN3OQT.js.map +1 -0
  31. package/dist/chunk-AOHBHYF6.js +7 -0
  32. package/dist/chunk-AOHBHYF6.js.map +1 -0
  33. package/dist/chunk-BRFMFLR6.js +85 -0
  34. package/dist/chunk-BRFMFLR6.js.map +1 -0
  35. package/dist/chunk-ELEHMJPM.js +13 -0
  36. package/dist/chunk-ELEHMJPM.js.map +1 -0
  37. package/dist/chunk-F2RSES6P.js +3 -0
  38. package/dist/chunk-F2RSES6P.js.map +1 -0
  39. package/dist/chunk-F6C6J7HK.js +3 -0
  40. package/dist/chunk-F6C6J7HK.js.map +1 -0
  41. package/dist/chunk-GMKJ34T2.js +3 -0
  42. package/dist/chunk-GMKJ34T2.js.map +1 -0
  43. package/dist/chunk-HEO3XL4Z.js +328 -0
  44. package/dist/chunk-HEO3XL4Z.js.map +1 -0
  45. package/dist/chunk-IIKTTIW5.js +56 -0
  46. package/dist/chunk-IIKTTIW5.js.map +1 -0
  47. package/dist/chunk-KOBEU2EM.js +3 -0
  48. package/dist/chunk-KOBEU2EM.js.map +1 -0
  49. package/dist/chunk-L5PK5VL2.js +178 -0
  50. package/dist/chunk-L5PK5VL2.js.map +1 -0
  51. package/dist/chunk-P3RPDZHO.js +36 -0
  52. package/dist/chunk-P3RPDZHO.js.map +1 -0
  53. package/dist/chunk-PNWOW52F.js +19 -0
  54. package/dist/chunk-PNWOW52F.js.map +1 -0
  55. package/dist/chunk-R27FIYR5.js +62 -0
  56. package/dist/chunk-R27FIYR5.js.map +1 -0
  57. package/dist/chunk-S4WFNGQG.js +17 -0
  58. package/dist/chunk-S4WFNGQG.js.map +1 -0
  59. package/dist/chunk-TS3M7MWA.js +3 -0
  60. package/dist/chunk-TS3M7MWA.js.map +1 -0
  61. package/dist/chunk-UY4PNPBX.js +156 -0
  62. package/dist/chunk-UY4PNPBX.js.map +1 -0
  63. package/dist/chunk-VMH2LRM6.js +114 -0
  64. package/dist/chunk-VMH2LRM6.js.map +1 -0
  65. package/dist/chunk-VZDHIOCH.js +76 -0
  66. package/dist/chunk-VZDHIOCH.js.map +1 -0
  67. package/dist/chunk-WGVHM7DU.js +66 -0
  68. package/dist/chunk-WGVHM7DU.js.map +1 -0
  69. package/dist/chunk-WR5PDOPP.js +91 -0
  70. package/dist/chunk-WR5PDOPP.js.map +1 -0
  71. package/dist/chunk-YR433ZDA.js +20 -0
  72. package/dist/chunk-YR433ZDA.js.map +1 -0
  73. package/dist/context.d.ts +113 -0
  74. package/dist/context.js +3 -0
  75. package/dist/context.js.map +1 -0
  76. package/dist/errors.d.ts +35 -0
  77. package/dist/errors.js +3 -0
  78. package/dist/errors.js.map +1 -0
  79. package/dist/executors/in-memory.d.ts +39 -0
  80. package/dist/executors/in-memory.js +6 -0
  81. package/dist/executors/in-memory.js.map +1 -0
  82. package/dist/executors/types.d.ts +3 -0
  83. package/dist/executors/types.js +3 -0
  84. package/dist/executors/types.js.map +1 -0
  85. package/dist/functions.d.ts +88 -0
  86. package/dist/functions.js +21 -0
  87. package/dist/functions.js.map +1 -0
  88. package/dist/index.d.ts +16 -1056
  89. package/dist/index.js +26 -5
  90. package/dist/index.js.map +1 -1
  91. package/dist/logger.d.ts +43 -0
  92. package/dist/logger.js +3 -0
  93. package/dist/logger.js.map +1 -0
  94. package/dist/types-U76Ukj96.d.ts +609 -0
  95. package/dist/types.d.ts +3 -0
  96. package/dist/types.js +3 -0
  97. package/dist/types.js.map +1 -0
  98. package/dist/utils/analysis.d.ts +75 -0
  99. package/dist/utils/analysis.js +3 -0
  100. package/dist/utils/analysis.js.map +1 -0
  101. package/dist/utils/index.d.ts +8 -0
  102. package/dist/utils/index.js +10 -0
  103. package/dist/utils/index.js.map +1 -0
  104. package/dist/utils/mermaid.d.ts +46 -0
  105. package/dist/utils/mermaid.js +4 -0
  106. package/dist/utils/mermaid.js.map +1 -0
  107. package/dist/utils/middleware.d.ts +11 -0
  108. package/dist/utils/middleware.js +3 -0
  109. package/dist/utils/middleware.js.map +1 -0
  110. package/dist/utils/sanitize.d.ts +19 -0
  111. package/dist/utils/sanitize.js +3 -0
  112. package/dist/utils/sanitize.js.map +1 -0
  113. package/dist/utils/sleep.d.ts +9 -0
  114. package/dist/utils/sleep.js +4 -0
  115. package/dist/utils/sleep.js.map +1 -0
  116. package/dist/workflow/AbstractNode.d.ts +3 -0
  117. package/dist/workflow/AbstractNode.js +4 -0
  118. package/dist/workflow/AbstractNode.js.map +1 -0
  119. package/dist/workflow/Flow.d.ts +3 -0
  120. package/dist/workflow/Flow.js +16 -0
  121. package/dist/workflow/Flow.js.map +1 -0
  122. package/dist/workflow/Node.d.ts +3 -0
  123. package/dist/workflow/Node.js +15 -0
  124. package/dist/workflow/Node.js.map +1 -0
  125. package/dist/workflow/index.d.ts +4 -0
  126. package/dist/workflow/index.js +18 -0
  127. package/dist/workflow/index.js.map +1 -0
  128. package/dist/workflow/node-patterns.d.ts +55 -0
  129. package/dist/workflow/node-patterns.js +16 -0
  130. package/dist/workflow/node-patterns.js.map +1 -0
  131. package/dist/workflow/registry.d.ts +17 -0
  132. package/dist/workflow/registry.js +3 -0
  133. package/dist/workflow/registry.js.map +1 -0
  134. package/package.json +30 -11
@@ -0,0 +1,66 @@
1
+ import { ParallelFlow } from './chunk-L5PK5VL2.js';
2
+ import { Node } from './chunk-HEO3XL4Z.js';
3
+
4
+ // src/builder/graph/internal-nodes.ts
5
+ var InputMappingNode = class extends Node {
6
+ mappings;
7
+ constructor(options) {
8
+ super();
9
+ const { nodeId, originalId, isSubWorkflow, ...mappings } = options.data;
10
+ this.mappings = mappings;
11
+ }
12
+ async prep({ ctx, logger }) {
13
+ for (const [subKey, parentKey] of Object.entries(this.mappings)) {
14
+ if (await ctx.has(parentKey)) {
15
+ ctx.set(subKey, await ctx.get(parentKey));
16
+ } else {
17
+ logger.warn(`[InputMapper] Input mapping failed. Key '${parentKey}' not found in context.`);
18
+ }
19
+ }
20
+ }
21
+ };
22
+ var OutputMappingNode = class extends Node {
23
+ mappings;
24
+ constructor(options) {
25
+ super();
26
+ const { nodeId, originalId, isSubWorkflow, ...mappings } = options.data;
27
+ this.mappings = mappings;
28
+ }
29
+ async prep({ ctx, logger }) {
30
+ for (const [parentKey, subKey] of Object.entries(this.mappings)) {
31
+ if (await ctx.has(subKey)) {
32
+ ctx.set(parentKey, await ctx.get(subKey));
33
+ } else {
34
+ logger.warn(`[OutputMapper] Output mapping failed. Key '${subKey}' not found in context.`);
35
+ }
36
+ }
37
+ }
38
+ };
39
+ var SubWorkflowContainerNode = class extends Node {
40
+ constructor() {
41
+ super();
42
+ this.isPassthrough = true;
43
+ }
44
+ async exec() {
45
+ }
46
+ };
47
+ var ParallelBranchContainer = class extends ParallelFlow {
48
+ /** A tag to reliably identify this node type in the visualizer. */
49
+ isParallelContainer = true;
50
+ // This is now a public, mutable property for the executor to populate.
51
+ nodesToRun = [];
52
+ constructor() {
53
+ super();
54
+ this.isPassthrough = true;
55
+ }
56
+ };
57
+ var ConditionalJoinNode = class extends Node {
58
+ constructor() {
59
+ super();
60
+ this.isPassthrough = true;
61
+ }
62
+ };
63
+
64
+ export { ConditionalJoinNode, InputMappingNode, OutputMappingNode, ParallelBranchContainer, SubWorkflowContainerNode };
65
+ //# sourceMappingURL=chunk-WGVHM7DU.js.map
66
+ //# sourceMappingURL=chunk-WGVHM7DU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/builder/graph/internal-nodes.ts"],"names":[],"mappings":";;;;AAYO,IAAM,gBAAA,GAAN,cAAmE,IAAA,CAAqC;AAAA,EACtG,QAAA;AAAA,EACR,YAAY,OAAA,EAA2C;AACtD,IAAA,KAAA,EAAM;AAEN,IAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAY,eAAe,GAAG,QAAA,KAAa,OAAA,CAAQ,IAAA;AACnE,IAAA,IAAA,CAAK,QAAA,GAAW,QAAA;AAAA,EACjB;AAAA,EAEA,MAAM,IAAA,CAAK,EAAE,GAAA,EAAK,QAAO,EAAwC;AAChE,IAAA,KAAA,MAAW,CAAC,QAAQ,SAAS,CAAA,IAAK,OAAO,OAAA,CAAQ,IAAA,CAAK,QAAQ,CAAA,EAAG;AAChE,MAAA,IAAI,MAAM,GAAA,CAAI,GAAA,CAAI,SAAS,CAAA,EAAG;AAC7B,QAAA,GAAA,CAAI,IAAI,MAAA,EAAQ,MAAM,GAAA,CAAI,GAAA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A,EAErC,WAAA,GAAc;AACb,IAAA,KAAA,EAAM;AAEN,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAA;AAAA,EACtB;AACD;AAQO,IAAM,mBAAA,GAAN,cAAsE,IAAA,CAAqC;AAAA,EACjH,WAAA,GAAc;AACb,IAAA,KAAA,EAAM;AACN,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAA;AAAA,EACtB;AACD","file":"chunk-WGVHM7DU.js","sourcesContent":["import type { Context } from '../../context'\nimport type { NodeArgs } from '../../types'\nimport type { AbstractNode } from '../../workflow/index'\nimport { Node } from '../../workflow/index'\nimport { ParallelFlow } from '../patterns'\n\n/**\n * An internal node used by the GraphBuilder to handle the `inputs` mapping\n * of an inlined sub-workflow. It copies data from the parent context scope\n * to the sub-workflow's context scope.\n * @internal\n */\nexport class InputMappingNode<TContext extends Context = Context> extends Node<void, void, any, any, TContext> {\n\tprivate mappings: Record<string, string>\n\tconstructor(options: { data: Record<string, string> }) {\n\t\tsuper()\n\t\t// Exclude the injected nodeId from the mappings\n\t\tconst { nodeId, originalId, isSubWorkflow, ...mappings } = options.data\n\t\tthis.mappings = mappings\n\t}\n\n\tasync prep({ ctx, logger }: NodeArgs<void, void, any, TContext>) {\n\t\tfor (const [subKey, parentKey] of Object.entries(this.mappings)) {\n\t\t\tif (await ctx.has(parentKey)) {\n\t\t\t\tctx.set(subKey, await ctx.get(parentKey))\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlogger.warn(`[InputMapper] Input mapping failed. Key '${parentKey}' not found in context.`)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * An internal node used by the GraphBuilder to handle the `outputs` mapping\n * of an inlined sub-workflow. It copies data from the sub-workflow's\n * context scope back to the parent's context scope.\n * @internal\n */\nexport class OutputMappingNode<TContext extends Context = Context> extends Node<void, void, any, any, TContext> {\n\tprivate mappings: Record<string, string>\n\tconstructor(options: { data: Record<string, string> }) {\n\t\tsuper()\n\t\t// Exclude the injected nodeId from the mappings\n\t\tconst { nodeId, originalId, isSubWorkflow, ...mappings } = options.data\n\t\tthis.mappings = mappings\n\t}\n\n\tasync prep({ ctx, logger }: NodeArgs<void, void, any, TContext>) {\n\t\tfor (const [parentKey, subKey] of Object.entries(this.mappings)) {\n\t\t\tif (await ctx.has(subKey)) {\n\t\t\t\tctx.set(parentKey, await ctx.get(subKey))\n\t\t\t}\n\t\t\telse {\n\t\t\t\tlogger.warn(`[OutputMapper] Output mapping failed. Key '${subKey}' not found in context.`)\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * A private class used by the builder to represent the sub-workflow container itself.\n * It's a structural node that preserves the original node ID in the flattened graph.\n * @internal\n */\nexport class SubWorkflowContainerNode<TContext extends Context = Context> extends Node<void, void, any, any, TContext> {\n\tconstructor() {\n\t\tsuper()\n\t\tthis.isPassthrough = true\n\t}\n\n\tasync exec() {\n\t\t// This node performs no work; it just acts as a stable entry point.\n\t\t// The graph wiring ensures the InputMappingNode is executed next.\n\t}\n}\n\n/** A private class used by the builder to represent parallel execution blocks. */\nexport class ParallelBranchContainer<TContext extends Context = Context> extends ParallelFlow<TContext> {\n\t/** A tag to reliably identify this node type in the visualizer. */\n\tpublic readonly isParallelContainer = true\n\t// This is now a public, mutable property for the executor to populate.\n\tpublic nodesToRun: AbstractNode[] = []\n\n\tconstructor() {\n\t\tsuper() // Call the parent constructor, which can handle an empty/no-arg state.\n\t\t// semantic flag for distributed executors.\n\t\tthis.isPassthrough = true\n\t}\n}\n\n/**\n * A private class used by the builder to unify conditional branches\n * before they connect to a common successor. This ensures the successor\n * only has one predecessor, preventing false fan-in detection.\n * @internal\n */\nexport class ConditionalJoinNode<TContext extends Context = Context> extends Node<void, void, any, any, TContext> {\n\tconstructor() {\n\t\tsuper()\n\t\tthis.isPassthrough = true // It performs no logic, just structural\n\t}\n}\n"]}
@@ -0,0 +1,91 @@
1
+ // src/utils/analysis.ts
2
+ function isNodeType(type) {
3
+ return (node) => {
4
+ return node.type === type;
5
+ };
6
+ }
7
+ function analyzeGraph(graph) {
8
+ const typedGraph = graph;
9
+ const analysis = {
10
+ nodes: /* @__PURE__ */ new Map(),
11
+ allNodeIds: [],
12
+ startNodeIds: [],
13
+ cycles: []
14
+ };
15
+ if (!typedGraph || !typedGraph.nodes || !typedGraph.nodes.length)
16
+ return analysis;
17
+ const allNodeIds = typedGraph.nodes.map((node) => node.id);
18
+ analysis.allNodeIds = allNodeIds;
19
+ const adj = /* @__PURE__ */ new Map();
20
+ typedGraph.nodes.forEach((node) => {
21
+ analysis.nodes.set(node.id, { ...node, inDegree: 0, outDegree: 0 });
22
+ adj.set(node.id, []);
23
+ });
24
+ typedGraph.edges.forEach((edge) => {
25
+ const source = analysis.nodes.get(edge.source);
26
+ const target = analysis.nodes.get(edge.target);
27
+ if (source)
28
+ source.outDegree++;
29
+ if (target)
30
+ target.inDegree++;
31
+ if (adj.has(edge.source))
32
+ adj.get(edge.source).push(edge.target);
33
+ });
34
+ analysis.startNodeIds = allNodeIds.filter((id) => analysis.nodes.get(id).inDegree === 0);
35
+ const visited = /* @__PURE__ */ new Set();
36
+ const recursionStack = /* @__PURE__ */ new Set();
37
+ function detectCycleUtil(nodeId, path) {
38
+ visited.add(nodeId);
39
+ recursionStack.add(nodeId);
40
+ path.push(nodeId);
41
+ const neighbors = adj.get(nodeId) || [];
42
+ for (const neighbor of neighbors) {
43
+ if (recursionStack.has(neighbor)) {
44
+ const cycleStartIndex = path.indexOf(neighbor);
45
+ const cycle = path.slice(cycleStartIndex);
46
+ analysis.cycles.push([...cycle, neighbor]);
47
+ } else if (!visited.has(neighbor)) {
48
+ detectCycleUtil(neighbor, path);
49
+ }
50
+ }
51
+ recursionStack.delete(nodeId);
52
+ path.pop();
53
+ }
54
+ for (const nodeId of allNodeIds) {
55
+ if (!visited.has(nodeId))
56
+ detectCycleUtil(nodeId, []);
57
+ }
58
+ return analysis;
59
+ }
60
+ function createNodeRule(filter, check) {
61
+ return (analysis, _graph) => {
62
+ const errors = [];
63
+ for (const node of analysis.nodes.values()) {
64
+ if (filter(node)) {
65
+ const result = check(node);
66
+ if (result) {
67
+ if (Array.isArray(result))
68
+ errors.push(...result);
69
+ else
70
+ errors.push(result);
71
+ }
72
+ }
73
+ }
74
+ return errors;
75
+ };
76
+ }
77
+ var checkForCycles = (analysis) => {
78
+ const uniqueCycles = new Set(analysis.cycles.map((c) => c.slice(0, -1).sort().join(",")));
79
+ return Array.from(uniqueCycles).map((cycleKey) => {
80
+ const representativeCycle = analysis.cycles.find((c) => c.slice(0, -1).sort().join(",") === cycleKey);
81
+ return {
82
+ nodeId: representativeCycle[0],
83
+ type: "CycleDetected",
84
+ message: `Cycle detected involving nodes: ${representativeCycle.join(" -> ")}`
85
+ };
86
+ });
87
+ };
88
+
89
+ export { analyzeGraph, checkForCycles, createNodeRule, isNodeType };
90
+ //# sourceMappingURL=chunk-WR5PDOPP.js.map
91
+ //# sourceMappingURL=chunk-WR5PDOPP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/analysis.ts"],"names":[],"mappings":";AAyCO,SAAS,WAAqD,IAAA,EAAS;AAC7E,EAAA,OAAO,CAAC,IAAA,KAAqE;AAC5E,IAAA,OAAO,KAAK,IAAA,KAAS,IAAA;AAAA,EACtB,CAAA;AACD;AAcO,SAAS,aAAoC,KAAA,EAAgE;AACnH,EAAA,MAAM,UAAA,GAAa,KAAA;AACnB,EAAA,MAAM,QAAA,GAA6B;AAAA,IAClC,KAAA,sBAAW,GAAA,EAAI;AAAA,IACf,YAAY,EAAC;AAAA,IACb,cAAc,EAAC;AAAA,IACf,QAAQ;AAAC,GACV;AAEA,EAAA,IAAI,CAAC,UAAA,IAAc,CAAC,WAAW,KAAA,IAAS,CAAC,WAAW,KAAA,CAAM,MAAA;AACzD,IAAA,OAAO,QAAA;AAER,EAAA,MAAM,aAAa,UAAA,CAAW,KAAA,CAAM,GAAA,CAAI,CAAA,IAAA,KAAQ,KAAK,EAAE,CAAA;AACvD,EAAA,QAAA,CAAS,UAAA,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,IAAI,MAAA,EAAQ;AACX,UAAA,IAAI,KAAA,CAAM,QAAQ,MAAM,CAAA;AACvB,YAAA,MAAA,CAAO,IAAA,CAAK,GAAG,MAAM,CAAA;AAAA;AAErB,YAAA,MAAA,CAAO,KAAK,MAAM,CAAA;AAAA,QACpB;AAAA,MACD;AAAA,IACD;AACA,IAAA,OAAO,MAAA;AAAA,EACR,CAAA;AACD;AAKO,IAAM,cAAA,GAA4B,CAAC,QAAA,KAAa;AACtD,EAAA,MAAM,eAAe,IAAI,GAAA,CAAI,QAAA,CAAS,MAAA,CAAO,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,CAAE,IAAA,GAAO,IAAA,CAAK,GAAG,CAAC,CAAC,CAAA;AACtF,EAAA,OAAO,MAAM,IAAA,CAAK,YAAY,CAAA,CAAE,GAAA,CAAI,CAAC,QAAA,KAAa;AACjD,IAAA,MAAM,mBAAA,GAAsB,QAAA,CAAS,MAAA,CAAO,IAAA,CAAK,OAAK,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,EAAE,IAAA,EAAK,CAAE,IAAA,CAAK,GAAG,MAAM,QAAQ,CAAA;AAClG,IAAA,OAAO;AAAA,MACN,MAAA,EAAQ,oBAAoB,CAAC,CAAA;AAAA,MAC7B,IAAA,EAAM,eAAA;AAAA,MACN,OAAA,EAAS,CAAA,gCAAA,EAAmC,mBAAA,CAAoB,IAAA,CAAK,MAAM,CAAC,CAAA;AAAA,KAC7E;AAAA,EACD,CAAC,CAAA;AACF","file":"chunk-WR5PDOPP.js","sourcesContent":["import type { GraphNode, NodeTypeMap, TypedGraphNode, TypedWorkflowGraph, WorkflowGraph } from '../builder/graph/types'\n\n/** The rich metadata object returned by the analyzeGraph function. */\nexport interface GraphAnalysis<T extends NodeTypeMap = any> {\n\t/** A map of all nodes, keyed by ID, augmented with their connection degrees. */\n\tnodes: Map<string, TypedGraphNode<T> & { inDegree: number, outDegree: number }>\n\t/** An array of all node IDs in the graph. */\n\tallNodeIds: string[]\n\t/** An array of node IDs that have no incoming edges. */\n\tstartNodeIds: string[]\n\t/** A list of cycles found in the graph. Each cycle is an array of node IDs. */\n\tcycles: string[][]\n}\n\n/** A standard structure for reporting a single validation error. */\nexport interface ValidationError {\n\t/** The ID of the node where the error occurred, if applicable. */\n\tnodeId?: string\n\t/** A category for the error, e.g., 'CycleDetected', 'ConnectionRuleViolation'. */\n\ttype: string\n\t/** A human-readable message explaining the validation failure. */\n\tmessage: string\n}\n\n/**\n * A function that takes a graph analysis and the original graph,\n * and returns an array of validation errors.\n */\nexport type Validator<T extends NodeTypeMap = any> = (\n\tanalysis: GraphAnalysis<T>,\n\tgraph: TypedWorkflowGraph<T>\n) => ValidationError[]\n\n/**\n * A helper function that creates a type guard for filtering nodes by their type.\n * This simplifies writing type-safe validation rules by removing the need for\n * verbose, explicit type guard syntax.\n *\n * @param type The literal string of the node type to check for.\n * @returns A type guard function that narrows the node to its specific type.\n */\nexport function isNodeType<T extends NodeTypeMap, K extends keyof T>(type: K) {\n\treturn (node: TypedGraphNode<T>): node is TypedGraphNode<T> & { type: K } => {\n\t\treturn node.type === type\n\t}\n}\n\n/**\n * Analyzes a declarative workflow graph definition to extract structural metadata.\n * This is a lightweight, static utility that does not instantiate any nodes.\n *\n * @param graph The WorkflowGraph object containing nodes and edges.\n * @returns A GraphAnalysis object containing nodes with degree counts, start nodes, and any cycles.\n */\n// (Typesafe Overload) Analyzes a declarative workflow graph, preserving strong types.\nexport function analyzeGraph<T extends NodeTypeMap>(graph: TypedWorkflowGraph<T>): GraphAnalysis<T>\n// (Untyped Overload) Analyzes a declarative workflow graph with basic types.\nexport function analyzeGraph(graph: WorkflowGraph): GraphAnalysis\n// (Implementation) Analyzes a declarative workflow graph to extract structural metadata.\nexport function analyzeGraph<T extends NodeTypeMap>(graph: TypedWorkflowGraph<T> | WorkflowGraph): GraphAnalysis<T> {\n\tconst typedGraph = graph as TypedWorkflowGraph<T> // Cast for internal consistency\n\tconst analysis: GraphAnalysis<T> = {\n\t\tnodes: new Map(),\n\t\tallNodeIds: [],\n\t\tstartNodeIds: [],\n\t\tcycles: [],\n\t}\n\n\tif (!typedGraph || !typedGraph.nodes || !typedGraph.nodes.length)\n\t\treturn analysis\n\n\tconst allNodeIds = typedGraph.nodes.map(node => node.id)\n\tanalysis.allNodeIds = allNodeIds\n\n\tconst adj: Map<string, string[]> = new Map()\n\ttypedGraph.nodes.forEach((node) => {\n\t\tanalysis.nodes.set(node.id, { ...node, inDegree: 0, outDegree: 0 })\n\t\tadj.set(node.id, [])\n\t})\n\n\ttypedGraph.edges.forEach((edge) => {\n\t\tconst source = analysis.nodes.get(edge.source)\n\t\tconst target = analysis.nodes.get(edge.target)\n\t\tif (source)\n\t\t\tsource.outDegree++\n\t\tif (target)\n\t\t\ttarget.inDegree++\n\t\tif (adj.has(edge.source))\n\t\t\tadj.get(edge.source)!.push(edge.target)\n\t})\n\n\tanalysis.startNodeIds = allNodeIds.filter(id => analysis.nodes.get(id)!.inDegree === 0)\n\n\tconst visited = new Set<string>()\n\tconst recursionStack = new Set<string>()\n\tfunction detectCycleUtil(nodeId: string, path: string[]) {\n\t\tvisited.add(nodeId)\n\t\trecursionStack.add(nodeId)\n\t\tpath.push(nodeId)\n\n\t\tconst neighbors = adj.get(nodeId) || []\n\t\tfor (const neighbor of neighbors) {\n\t\t\tif (recursionStack.has(neighbor)) {\n\t\t\t\tconst cycleStartIndex = path.indexOf(neighbor)\n\t\t\t\tconst cycle = path.slice(cycleStartIndex)\n\t\t\t\tanalysis.cycles.push([...cycle, neighbor])\n\t\t\t}\n\t\t\telse if (!visited.has(neighbor)) {\n\t\t\t\tdetectCycleUtil(neighbor, path)\n\t\t\t}\n\t\t}\n\n\t\trecursionStack.delete(nodeId)\n\t\tpath.pop()\n\t}\n\n\tfor (const nodeId of allNodeIds) {\n\t\tif (!visited.has(nodeId))\n\t\t\tdetectCycleUtil(nodeId, [])\n\t}\n\n\treturn analysis\n}\n\n/**\n * Factory for creating a generic, reusable validator that checks node properties.\n * A single rule can now return multiple errors for a single node.\n *\n * @param filter A predicate to select which nodes this rule applies to.\n * @param check A function that validates a selected node. It can return a single\n * ValidationError, an array of them, or null if the node is valid.\n * @returns A Validator function.\n */\n// (Type-Safe Overload) Creates a validator with strong types based on a NodeTypeMap.\nexport function createNodeRule<T extends NodeTypeMap>(\n\tfilter: (node: TypedGraphNode<T>) => boolean,\n\tcheck: (\n\t\tnode: TypedGraphNode<T> & { inDegree: number, outDegree: number },\n\t) => ValidationError | ValidationError[] | null | undefined,\n): Validator<T>\n// (Untyped Overload) Creates a validator with basic types.\nexport function createNodeRule(\n\tfilter: (node: GraphNode) => boolean,\n\tcheck: (\n\t\tnode: GraphNode & { inDegree: number, outDegree: number },\n\t) => ValidationError | ValidationError[] | null | undefined,\n): Validator\n// (Implementation) Factory for creating a generic, reusable validator.\nexport function createNodeRule(\n\tfilter: (node: any) => boolean,\n\tcheck: (\n\t\tnode: any,\n\t) => ValidationError | ValidationError[] | null | undefined,\n): Validator {\n\treturn (analysis: GraphAnalysis, _graph: WorkflowGraph): ValidationError[] => {\n\t\tconst errors: ValidationError[] = []\n\t\tfor (const node of analysis.nodes.values()) {\n\t\t\tif (filter(node)) {\n\t\t\t\tconst result = check(node)\n\t\t\t\tif (result) {\n\t\t\t\t\tif (Array.isArray(result))\n\t\t\t\t\t\terrors.push(...result)\n\t\t\t\t\telse\n\t\t\t\t\t\terrors.push(result)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn errors\n\t}\n}\n\n/**\n * A built-in validator that reports any cycles found in the graph.\n */\nexport const checkForCycles: Validator = (analysis) => {\n\tconst uniqueCycles = new Set(analysis.cycles.map(c => c.slice(0, -1).sort().join(',')))\n\treturn Array.from(uniqueCycles).map((cycleKey) => {\n\t\tconst representativeCycle = analysis.cycles.find(c => c.slice(0, -1).sort().join(',') === cycleKey)!\n\t\treturn {\n\t\t\tnodeId: representativeCycle[0],\n\t\t\ttype: 'CycleDetected',\n\t\t\tmessage: `Cycle detected involving nodes: ${representativeCycle.join(' -> ')}`,\n\t\t}\n\t})\n}\n"]}
@@ -0,0 +1,20 @@
1
+ // src/utils/sanitize.ts
2
+ function sanitizeGraph(rawGraph) {
3
+ const nodes = rawGraph.nodes.map(({ id, type, data, config }) => ({
4
+ id,
5
+ type,
6
+ data,
7
+ ...config && { config }
8
+ }));
9
+ const edges = rawGraph.edges.map(({ id, source, target, action }) => ({
10
+ id,
11
+ source,
12
+ target,
13
+ ...action && { action }
14
+ }));
15
+ return { nodes, edges };
16
+ }
17
+
18
+ export { sanitizeGraph };
19
+ //# sourceMappingURL=chunk-YR433ZDA.js.map
20
+ //# sourceMappingURL=chunk-YR433ZDA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/sanitize.ts"],"names":[],"mappings":";AAWO,SAAS,cAAc,QAAA,EAAyD;AACtF,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,KAAA,CAAM,GAAA,CAAI,CAAC,EAAE,EAAA,EAAI,IAAA,EAAM,IAAA,EAAM,MAAA,EAAO,MAAO;AAAA,IACjE,EAAA;AAAA,IACA,IAAA;AAAA,IACA,IAAA;AAAA,IACA,GAAI,MAAA,IAAU,EAAE,MAAA;AAAO,GACxB,CAAE,CAAA;AAEF,EAAA,MAAM,KAAA,GAAQ,QAAA,CAAS,KAAA,CAAM,GAAA,CAAI,CAAC,EAAE,EAAA,EAAI,MAAA,EAAQ,MAAA,EAAQ,MAAA,EAAO,MAAO;AAAA,IACrE,EAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAI,MAAA,IAAU,EAAE,MAAA;AAAO,GACxB,CAAE,CAAA;AAEF,EAAA,OAAO,EAAE,OAAO,KAAA,EAAM;AACvB","file":"chunk-YR433ZDA.js","sourcesContent":["import type { WorkflowGraph } from '../builder/graph/types'\n\n/**\n * Sanitizes a raw workflow graph object by removing properties that are not\n * relevant to the execution engine, such as UI-specific data.\n *\n * @param rawGraph - The raw graph object, potentially containing extraneous properties.\n * @param rawGraph.nodes - An array of node objects.\n * @param rawGraph.edges - An array of edge objects.\n * @returns A clean, execution-focused `WorkflowGraph` object.\n */\nexport function sanitizeGraph(rawGraph: { nodes: any[], edges: any[] }): WorkflowGraph {\n\tconst nodes = rawGraph.nodes.map(({ id, type, data, config }) => ({\n\t\tid,\n\t\ttype,\n\t\tdata,\n\t\t...(config && { config }),\n\t}))\n\n\tconst edges = rawGraph.edges.map(({ id, source, target, action }) => ({\n\t\tid,\n\t\tsource,\n\t\ttarget,\n\t\t...(action && { action }),\n\t}))\n\n\treturn { nodes, edges }\n}\n"]}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * A type-safe, opaque key for storing and retrieving values from the Context.
3
+ * Using a `ContextKey` provides compile-time safety for your workflow's state.
4
+ * @template T The type of the value this key refers to.
5
+ */
6
+ type ContextKey<T> = symbol & {
7
+ __type: T;
8
+ };
9
+ /**
10
+ * Creates a new, unique `ContextKey` for type-safe access to the `Context`.
11
+ * @template T The type of the value this key will hold.
12
+ * @param description An optional description for debugging purposes (e.g., in logs or test snapshots).
13
+ * @returns A unique `ContextKey<T>`.
14
+ */
15
+ declare const contextKey: <T>(description?: string) => ContextKey<T>;
16
+ /**
17
+ * Defines the interface for the shared context object passed through the workflow.
18
+ * This interface is "async-aware", allowing for both synchronous (Map-based)
19
+ * and asynchronous (e.g., Redis-backed) implementations.
20
+ */
21
+ interface Context {
22
+ /**
23
+ * Asynchronously retrieves a value from the context.
24
+ * Callers should ALWAYS `await` the result of this method.
25
+ */
26
+ get: (<T>(key: ContextKey<T>) => Promise<T | undefined>) & (<T = any>(key: string) => Promise<T | undefined>);
27
+ /** Asynchronously stores a value in the context. */
28
+ set: (<T>(key: ContextKey<T>, value: T) => Promise<this>) & ((key: string, value: any) => Promise<this>);
29
+ /** Asynchronously checks if a key exists in the context. */
30
+ has: ((key: ContextKey<any>) => Promise<boolean>) & ((key: string) => Promise<boolean>);
31
+ /** Asynchronously deletes a key from the context. */
32
+ delete: ((key: ContextKey<any>) => Promise<boolean>) & ((key: string) => Promise<boolean>);
33
+ /**
34
+ * Returns an iterator of all [key, value] pairs in the context.
35
+ * NOTE: This may not be supported or may be inefficient in some async implementations.
36
+ */
37
+ entries: () => IterableIterator<[any, any]>;
38
+ /**
39
+ * Returns an iterator of all keys in the context.
40
+ * NOTE: This may not be supported or may be inefficient in some async implementations.
41
+ */
42
+ keys: () => IterableIterator<any>;
43
+ /**
44
+ * Returns an iterator of all values in the context.
45
+ * NOTE: This may not be supported or may be inefficient in some async implementations.
46
+ */
47
+ values: () => IterableIterator<any>;
48
+ }
49
+ /**
50
+ * The default, `Map`-based implementation of the `Context` interface.
51
+ * Its methods are async to satisfy the `Context` interface, but they wrap
52
+ * synchronous operations.
53
+ */
54
+ declare class TypedContext implements Context {
55
+ private data;
56
+ /**
57
+ * @param initialData An optional iterable (like an array of `[key, value]` pairs)
58
+ * to initialize the context with.
59
+ */
60
+ constructor(initialData?: Iterable<readonly [ContextKey<any> | string, any]> | null);
61
+ get(key: ContextKey<any> | string): Promise<any>;
62
+ set(key: ContextKey<any> | string, value: any): Promise<this>;
63
+ has(key: ContextKey<any> | string): Promise<boolean>;
64
+ delete(key: ContextKey<any> | string): Promise<boolean>;
65
+ entries(): IterableIterator<[any, any]>;
66
+ keys(): IterableIterator<any>;
67
+ values(): IterableIterator<any>;
68
+ }
69
+ /** A function that takes a `Context` and returns a (potentially new) `Context`. */
70
+ type ContextTransform = (ctx: Context) => Context | Promise<Context>;
71
+ /**
72
+ * A "lens" provides a way to "focus" on a single key in the `Context`,
73
+ * creating reusable, type-safe async functions to get, set, or update its value.
74
+ * @template T The type of the value the lens focuses on.
75
+ */
76
+ interface ContextLens<T> {
77
+ /** Asynchronously retrieves the value for the key from the context. */
78
+ get: (ctx: Context) => Promise<T | undefined>;
79
+ /** Returns an asynchronous `ContextTransform` function that will set the key to the provided value. */
80
+ set: (value: T) => ContextTransform;
81
+ /** Returns an asynchronous `ContextTransform` function that updates the key's value based on its current value. */
82
+ update: (fn: (current: T | undefined) => T) => ContextTransform;
83
+ }
84
+ /**
85
+ * Creates a `ContextLens` object for a specific `ContextKey`.
86
+ * This is the entry point for functional context manipulation.
87
+ * All operations that read from the context are now async.
88
+ *
89
+ * @example
90
+ * const NAME = contextKey<string>('name')
91
+ * const nameLens = lens(NAME)
92
+ *
93
+ * // Usage in an async function:
94
+ * async function exampleUsage(ctx: Context) {
95
+ * const currentName = await nameLens.get(ctx);
96
+ * const setNameTransform = nameLens.set('Alice');
97
+ * await setNameTransform(ctx);
98
+ * }
99
+ *
100
+ * @param key The `ContextKey` to focus on.
101
+ * @returns A `ContextLens<T>` object with async-aware methods.
102
+ */
103
+ declare function lens<T>(key: ContextKey<T>): ContextLens<T>;
104
+ /**
105
+ * Composes multiple `ContextTransform` functions into a single `ContextTransform` function.
106
+ * The transformations are applied in the order they are provided.
107
+ *
108
+ * @param transforms A sequence of `ContextTransform` functions.
109
+ * @returns A single function that applies all transformations.
110
+ */
111
+ declare function composeContext(...transforms: ContextTransform[]): ContextTransform;
112
+
113
+ export { type Context, type ContextKey, type ContextLens, type ContextTransform, TypedContext, composeContext, contextKey, lens };
@@ -0,0 +1,3 @@
1
+ export { TypedContext, composeContext, contextKey, lens } from './chunk-R27FIYR5.js';
2
+ //# sourceMappingURL=context.js.map
3
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"context.js"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Error thrown when a workflow is gracefully aborted via an `AbortSignal`.
3
+ * This error is caught by the execution engine to halt the flow.
4
+ */
5
+ declare class AbortError extends Error {
6
+ constructor(message?: string);
7
+ }
8
+ /**
9
+ * A custom error class for failures within a workflow, providing additional
10
+ * context about where and when the error occurred.
11
+ */
12
+ declare class WorkflowError extends Error {
13
+ readonly nodeName: string;
14
+ readonly phase: 'prep' | 'exec' | 'post';
15
+ readonly originalError?: Error;
16
+ /**
17
+ * @param message The error message.
18
+ * @param nodeName The name of the `Node` class where the error occurred.
19
+ * @param phase The lifecycle phase (`'prep'`, `'exec'`, or `'post'`) where the error was thrown.
20
+ * @param originalError The underlying error that was caught and wrapped.
21
+ */
22
+ constructor(message: string, nodeName: string, phase: 'prep' | 'exec' | 'post', originalError?: Error);
23
+ }
24
+ /**
25
+ * An error thrown by a node to indicate a non-recoverable failure.
26
+ *
27
+ * When an executor catches this error, it should immediately terminate the
28
+ * entire workflow run, bypassing any remaining retries, fallbacks, or
29
+ * subsequent nodes in the graph.
30
+ */
31
+ declare class FatalWorkflowError extends WorkflowError {
32
+ constructor(message: string, nodeName: string, phase: 'prep' | 'exec' | 'post', originalError?: Error);
33
+ }
34
+
35
+ export { AbortError, FatalWorkflowError, WorkflowError };
package/dist/errors.js ADDED
@@ -0,0 +1,3 @@
1
+ export { AbortError, FatalWorkflowError, WorkflowError } from './chunk-64DNBF5W.js';
2
+ //# sourceMappingURL=errors.js.map
3
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"errors.js"}
@@ -0,0 +1,39 @@
1
+ import { Context } from '../context.js';
2
+ import { I as IExecutor, A as AbstractNode, e as Middleware, p as InternalRunOptions, F as Flow, R as RunOptions } from '../types-U76Ukj96.js';
3
+ import '../logger.js';
4
+
5
+ /**
6
+ * The default executor that runs a workflow within a single, in-memory process.
7
+ * This class contains the core logic for traversing a workflow graph, applying middleware,
8
+ * and handling node execution.
9
+ */
10
+ declare class InMemoryExecutor implements IExecutor {
11
+ /**
12
+ * A stateless, reusable method that orchestrates the traversal of a graph.
13
+ * It is called by `run()` for top-level flows and by `Flow.exec()` for sub-flows.
14
+ * @param startNode The node where the graph traversal begins.
15
+ * @param flowMiddleware The middleware array from the containing flow.
16
+ * @param context The shared workflow context.
17
+ * @param options The internal, normalized run options.
18
+ * @returns The final action from the last executed node in the graph.
19
+ * @internal
20
+ */
21
+ _orch<T = any>(startNode: AbstractNode, flowMiddleware: Middleware[], context: Context, options: InternalRunOptions): Promise<T>;
22
+ /**
23
+ * Executes a given flow with a specific context and options.
24
+ * This is the main entry point for the in-memory execution engine.
25
+ * @param flow The Flow instance to execute.
26
+ * @param context The shared context for the workflow.
27
+ * @param options Runtime options, including a logger, abort controller, or initial params.
28
+ * @returns A promise that resolves with the final action of the workflow.
29
+ */
30
+ run<T>(flow: Flow<any, T>, context: Context, options?: RunOptions): Promise<T>;
31
+ run(flow: Flow, context: Context, options?: RunOptions): Promise<any>;
32
+ /**
33
+ * Determines the next node to execute based on the action returned by the current node.
34
+ * @internal
35
+ */
36
+ getNextNode(curr: AbstractNode, action: any): AbstractNode | undefined;
37
+ }
38
+
39
+ export { InMemoryExecutor };
@@ -0,0 +1,6 @@
1
+ export { InMemoryExecutor } from '../chunk-BRFMFLR6.js';
2
+ import '../chunk-PNWOW52F.js';
3
+ import '../chunk-64DNBF5W.js';
4
+ import '../chunk-IIKTTIW5.js';
5
+ //# sourceMappingURL=in-memory.js.map
6
+ //# sourceMappingURL=in-memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"in-memory.js"}
@@ -0,0 +1,3 @@
1
+ import '../context.js';
2
+ import '../logger.js';
3
+ export { I as IExecutor, p as InternalRunOptions } from '../types-U76Ukj96.js';
@@ -0,0 +1,3 @@
1
+ import '../chunk-TS3M7MWA.js';
2
+ //# sourceMappingURL=types.js.map
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"types.js"}
@@ -0,0 +1,88 @@
1
+ import { Context, ContextTransform } from './context.js';
2
+ import { P as Params, N as Node, F as Flow } from './types-U76Ukj96.js';
3
+ import './logger.js';
4
+
5
+ /**
6
+ * A type for a pure function that can be executed within a `Node`,
7
+ * typically taking the node's `params` as input.
8
+ * @template TIn The input type, corresponding to `params`.
9
+ * @template TOut The output type, which becomes the node's `execRes`.
10
+ */
11
+ type NodeFunction<TIn = any, TOut = any> = (input: TIn) => TOut | Promise<TOut>;
12
+ /**
13
+ * A type for a function that operates on the shared `Context` in addition
14
+ * to the node's `params`.
15
+ * @template TIn The input type, corresponding to `params`.
16
+ * @template TOut The output type, which becomes the node's `execRes`.
17
+ */
18
+ type ContextFunction<TIn = any, TOut = any, TContext extends Context = Context> = (ctx: TContext, input: TIn) => TOut | Promise<TOut>;
19
+ /**
20
+ * Creates a `Node` from a simple, pure function that transforms an input to an output.
21
+ * The node's `params` object is passed as the input to the function.
22
+ *
23
+ * @example
24
+ * const add = (n: number) => mapNode<{ value: number }, number>(params => params.value + n)
25
+ * const add5Node = add(5) // A reusable node that adds 5 to its input parameter.
26
+ *
27
+ * @param fn A function that takes an input object and returns a result.
28
+ * @returns A new `Node` instance that wraps the function.
29
+ */
30
+ declare function mapNode<TIn extends Params, TOut, TContext extends Context = Context>(fn: NodeFunction<TIn, TOut>): Node<void, TOut, any, TIn, TContext>;
31
+ /**
32
+ * Creates a `Node` from a function that requires access to the shared `Context`.
33
+ * Both the `Context` and the node's `params` are passed as arguments to the function.
34
+ *
35
+ * @example
36
+ * const greeter = contextNode(async (ctx, params: { name: string }) => {
37
+ * const language = await ctx.get(LANGUAGE_KEY) || 'en'
38
+ * return language === 'en' ? `Hello, ${params.name}` : `Hola, ${params.name}`
39
+ * })
40
+ *
41
+ * @param fn A function that takes the context and an input object, and returns a result.
42
+ * @returns A new `Node` instance that wraps the function.
43
+ */
44
+ declare function contextNode<TIn extends Params, TOut, TContext extends Context = Context>(fn: ContextFunction<TIn, TOut, TContext>): Node<void, TOut, any, TIn, TContext>;
45
+ /**
46
+ * Creates a `Node` that declaratively applies a series of transformations to the `Context`.
47
+ * This is a "side-effect" node used purely for state management; its logic runs in the `prep` phase,
48
+ * and it does not produce an `exec` output.
49
+ *
50
+ * @example
51
+ * const USER_ID = contextKey<string>('user_id')
52
+ * const userLens = lens(USER_ID)
53
+ * const setupUserContext = (userId: string) => transformNode(userLens.set(userId))
54
+ *
55
+ * @param transforms A sequence of `ContextTransform` functions (e.g., from a lens) to apply.
56
+ * @returns A new `Node` instance that will mutate the context when executed.
57
+ */
58
+ declare function transformNode<TContext extends Context = Context>(...transforms: ContextTransform[]): Node<void, void, any, Params, TContext>;
59
+ /**
60
+ * A functional-style alias for `SequenceFlow`. It constructs a linear workflow
61
+ * where each node executes in the order it is provided.
62
+ *
63
+ * @example
64
+ * const mathPipeline = pipeline(addNode(5), multiplyNode(2))
65
+ *
66
+ * @param nodes A sequence of `Node` instances to chain together.
67
+ * @returns A `Flow` instance representing the linear sequence.
68
+ */
69
+ declare function pipeline<TContext extends Context = Context>(...nodes: Node<any, any, any, any, TContext>[]): Flow<any, any, Params, TContext>;
70
+ /**
71
+ * A classic functional composition utility. It takes two functions, `f` and `g`,
72
+ * and returns a new function that computes `f(g(x))`.
73
+ *
74
+ * This is a general-purpose helper, not a `Node` builder itself, but it can be
75
+ * used to create more complex `NodeFunction`s to pass to `mapNode`.
76
+ *
77
+ * @example
78
+ * const add5 = (x: number) => x + 5
79
+ * const multiply2 = (x: number) => x * 2
80
+ * const add5ThenMultiply2 = compose(multiply2, add5) // equivalent to: x => (x + 5) * 2
81
+ *
82
+ * @param f The outer function, which receives the result of `g`.
83
+ * @param g The inner function, which receives the initial input.
84
+ * @returns A new `NodeFunction` that combines both operations.
85
+ */
86
+ declare function compose<A, B, C>(f: NodeFunction<B, C>, g: NodeFunction<A, B>): NodeFunction<A, C>;
87
+
88
+ export { type ContextFunction, type NodeFunction, compose, contextNode, mapNode, pipeline, transformNode };
@@ -0,0 +1,21 @@
1
+ export { compose, contextNode, mapNode, pipeline, transformNode } from './chunk-P3RPDZHO.js';
2
+ import './chunk-R27FIYR5.js';
3
+ import './chunk-L5PK5VL2.js';
4
+ import './chunk-F6C6J7HK.js';
5
+ import './chunk-UY4PNPBX.js';
6
+ import './chunk-ELEHMJPM.js';
7
+ import './chunk-HEO3XL4Z.js';
8
+ import './chunk-7XUN3OQT.js';
9
+ import './chunk-WR5PDOPP.js';
10
+ import './chunk-VMH2LRM6.js';
11
+ import './chunk-YR433ZDA.js';
12
+ import './chunk-6QCXIRLA.js';
13
+ import './chunk-BRFMFLR6.js';
14
+ import './chunk-PNWOW52F.js';
15
+ import './chunk-VZDHIOCH.js';
16
+ import './chunk-S4WFNGQG.js';
17
+ import './chunk-64DNBF5W.js';
18
+ import './chunk-IIKTTIW5.js';
19
+ import './chunk-AOHBHYF6.js';
20
+ //# sourceMappingURL=functions.js.map
21
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"functions.js"}