(
blockName: string,
pathParts: string[],
context: BlockReferenceContext,
options: {
allowLargeValueRefs?: boolean
executionContext?: ResolutionContext['executionContext']
} = {}
)
| 207 | } |
| 208 | |
| 209 | export function resolveBlockReference( |
| 210 | blockName: string, |
| 211 | pathParts: string[], |
| 212 | context: BlockReferenceContext, |
| 213 | options: { |
| 214 | allowLargeValueRefs?: boolean |
| 215 | executionContext?: ResolutionContext['executionContext'] |
| 216 | } = {} |
| 217 | ): BlockReferenceResult | undefined { |
| 218 | const normalizedName = normalizeName(blockName) |
| 219 | const blockId = context.blockNameMapping[normalizedName] |
| 220 | |
| 221 | if (!blockId) { |
| 222 | return undefined |
| 223 | } |
| 224 | |
| 225 | const blockOutput = context.blockData[blockId] |
| 226 | |
| 227 | // When the block has not produced any output (e.g. it lives on a branched |
| 228 | // path that wasn't taken), resolve the reference to undefined without |
| 229 | // validating against the declared schema. Callers map this to an empty |
| 230 | // value so that references to skipped blocks don't fail the workflow. |
| 231 | if (blockOutput === undefined) { |
| 232 | return { value: undefined, blockId } |
| 233 | } |
| 234 | |
| 235 | if (pathParts.length === 0) { |
| 236 | return { value: blockOutput, blockId } |
| 237 | } |
| 238 | |
| 239 | const value = navigatePath(blockOutput, pathParts, options) |
| 240 | |
| 241 | const schema = context.blockOutputSchemas?.[blockId] |
| 242 | if (value === undefined && schema) { |
| 243 | if (!isPathInSchema(schema, pathParts)) { |
| 244 | throw new InvalidFieldError(blockName, pathParts.join('.'), getSchemaFieldNames(schema)) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return { value, blockId } |
| 249 | } |
| 250 | |
| 251 | export async function resolveBlockReferenceAsync( |
| 252 | blockName: string, |
no test coverage detected