(
blocks: Record<string, BlockState>,
edges: Edge[],
loops?: Record<string, Loop>,
parallels?: Record<string, Parallel>,
validateRequired = false
)
| 146 | |
| 147 | export class Serializer { |
| 148 | serializeWorkflow( |
| 149 | blocks: Record<string, BlockState>, |
| 150 | edges: Edge[], |
| 151 | loops?: Record<string, Loop>, |
| 152 | parallels?: Record<string, Parallel>, |
| 153 | validateRequired = false |
| 154 | ): SerializedWorkflow { |
| 155 | const canonicalLoops = generateLoopBlocks(blocks) |
| 156 | const canonicalParallels = generateParallelBlocks(blocks) |
| 157 | const safeLoops = Object.keys(canonicalLoops).length > 0 ? canonicalLoops : loops || {} |
| 158 | const safeParallels = |
| 159 | Object.keys(canonicalParallels).length > 0 ? canonicalParallels : parallels || {} |
| 160 | if (validateRequired) { |
| 161 | this.validateSubflowsBeforeExecution(blocks, safeLoops, safeParallels) |
| 162 | } |
| 163 | |
| 164 | return { |
| 165 | version: '1.0', |
| 166 | blocks: Object.values(blocks).map((block) => |
| 167 | this.serializeBlock(block, { |
| 168 | validateRequired, |
| 169 | allBlocks: blocks, |
| 170 | }) |
| 171 | ), |
| 172 | connections: edges.map((edge) => ({ |
| 173 | source: edge.source, |
| 174 | target: edge.target, |
| 175 | sourceHandle: edge.sourceHandle || undefined, |
| 176 | targetHandle: edge.targetHandle || undefined, |
| 177 | })), |
| 178 | loops: safeLoops, |
| 179 | parallels: safeParallels, |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Validate loop and parallel subflows for required inputs when running in "each/collection" modes |
no test coverage detected