( blockName: string, pathParts: string[], context: BlockReferenceContext, resolutionContext: ResolutionContext, navigatePathAsync: AsyncPathNavigator )
| 249 | } |
| 250 | |
| 251 | export async function resolveBlockReferenceAsync( |
| 252 | blockName: string, |
| 253 | pathParts: string[], |
| 254 | context: BlockReferenceContext, |
| 255 | resolutionContext: ResolutionContext, |
| 256 | navigatePathAsync: AsyncPathNavigator |
| 257 | ): Promise<BlockReferenceResult | undefined> { |
| 258 | const normalizedName = normalizeName(blockName) |
| 259 | const blockId = context.blockNameMapping[normalizedName] |
| 260 | |
| 261 | if (!blockId) { |
| 262 | return undefined |
| 263 | } |
| 264 | |
| 265 | const blockOutput = context.blockData[blockId] |
| 266 | if (blockOutput === undefined) { |
| 267 | return { value: undefined, blockId } |
| 268 | } |
| 269 | |
| 270 | if (pathParts.length === 0) { |
| 271 | return { value: blockOutput, blockId } |
| 272 | } |
| 273 | |
| 274 | const value = await navigatePathAsync(blockOutput, pathParts, resolutionContext) |
| 275 | |
| 276 | const schema = context.blockOutputSchemas?.[blockId] |
| 277 | if (value === undefined && schema) { |
| 278 | if (!isPathInSchema(schema, pathParts)) { |
| 279 | throw new InvalidFieldError(blockName, pathParts.join('.'), getSchemaFieldNames(schema)) |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return { value, blockId } |
| 284 | } |
no test coverage detected