( blocks: Record<string, T> | T[], options: ResolveStartOptions )
| 171 | } |
| 172 | |
| 173 | export function resolveStartCandidates<T extends MinimalBlock>( |
| 174 | blocks: Record<string, T> | T[], |
| 175 | options: ResolveStartOptions |
| 176 | ): StartBlockCandidate<T>[] { |
| 177 | const entries = toEntries(blocks) |
| 178 | if (entries.length === 0) return [] |
| 179 | |
| 180 | const priorities = options.isChildWorkflow |
| 181 | ? CHILD_PRIORITIES |
| 182 | : EXECUTION_PRIORITIES[options.execution] |
| 183 | |
| 184 | const candidates: StartBlockCandidate<T>[] = [] |
| 185 | |
| 186 | for (const [blockId, block] of entries) { |
| 187 | // Skip disabled blocks - they cannot be used as triggers |
| 188 | if ('enabled' in block && block.enabled === false) { |
| 189 | continue |
| 190 | } |
| 191 | |
| 192 | const path = classifyStartBlock(block) |
| 193 | if (!path) continue |
| 194 | |
| 195 | if (options.isChildWorkflow) { |
| 196 | if (!CHILD_PRIORITIES.includes(path)) { |
| 197 | continue |
| 198 | } |
| 199 | } else if (!supportsExecution(path, options.execution)) { |
| 200 | continue |
| 201 | } |
| 202 | |
| 203 | if (path === StartBlockPath.LEGACY_STARTER && options.allowLegacyStarter === false) { |
| 204 | continue |
| 205 | } |
| 206 | |
| 207 | candidates.push({ blockId, block, path }) |
| 208 | } |
| 209 | |
| 210 | candidates.sort((a, b) => { |
| 211 | const order = options.isChildWorkflow ? CHILD_PRIORITIES : priorities |
| 212 | const aIdx = order.indexOf(a.path) |
| 213 | const bIdx = order.indexOf(b.path) |
| 214 | if (aIdx === -1 && bIdx === -1) return 0 |
| 215 | if (aIdx === -1) return 1 |
| 216 | if (bIdx === -1) return -1 |
| 217 | return aIdx - bIdx |
| 218 | }) |
| 219 | |
| 220 | return candidates |
| 221 | } |
| 222 | |
| 223 | type SubBlockWithValue = { value?: unknown } |
| 224 |
no test coverage detected