( blocks: SerializedBlock[], options: ResolveExecutorStartOptions )
| 42 | } |
| 43 | |
| 44 | export function resolveExecutorStartBlock( |
| 45 | blocks: SerializedBlock[], |
| 46 | options: ResolveExecutorStartOptions |
| 47 | ): ExecutorStartResolution | null { |
| 48 | if (blocks.length === 0) { |
| 49 | return null |
| 50 | } |
| 51 | |
| 52 | const blockMap = blocks.reduce<Record<string, StartCandidateWrapper>>((acc, block) => { |
| 53 | const type = block.metadata?.id |
| 54 | if (!type) { |
| 55 | return acc |
| 56 | } |
| 57 | |
| 58 | acc[block.id] = { |
| 59 | type, |
| 60 | subBlocks: extractSubBlocks(block), |
| 61 | original: block, |
| 62 | } |
| 63 | |
| 64 | return acc |
| 65 | }, {}) |
| 66 | |
| 67 | const candidates = resolveStartCandidates(blockMap, { |
| 68 | execution: options.execution, |
| 69 | isChildWorkflow: options.isChildWorkflow, |
| 70 | }) |
| 71 | |
| 72 | if (candidates.length === 0) { |
| 73 | return null |
| 74 | } |
| 75 | |
| 76 | if (options.isChildWorkflow && candidates.length > 1) { |
| 77 | throw new Error('Child workflow has multiple trigger blocks. Keep only one Start block.') |
| 78 | } |
| 79 | |
| 80 | const [primary] = candidates |
| 81 | return { |
| 82 | blockId: primary.blockId, |
| 83 | block: primary.block.original, |
| 84 | path: primary.path, |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | export function buildResolutionFromBlock(block: SerializedBlock): ExecutorStartResolution | null { |
| 89 | const type = block.metadata?.id |
no test coverage detected