build-output-list.ts

Overview

The build-output-list.ts file contains a utility function designed to transform a complex nested object of outputs into a simplified array of output descriptors. Specifically, it takes an input object where each key corresponds to an output name and its associated metadata, and returns an array of objects with a concise structure containing only the output title and its type. This transformation facilitates easier consumption and rendering of output data, especially within UI components that require a list format.


Detailed Explanation

Function: buildOutputList

export function buildOutputList(outputs: Record<string, Record<string, any>>): OutputType[]

Purpose

Transforms an object containing output metadata into an array of simplified output descriptor objects.

Parameters

Return Value

Usage Example

import { buildOutputList } from './build-output-list';

const outputs = {
  result: { type: 'boolean', description: 'Success flag' },
  data: { type: 'object', fields: ['id', 'value'] },
};

const outputList = buildOutputList(outputs);
/*
outputList will be:
[
  { title: 'result', type: 'boolean' },
  { title: 'data', type: 'object' }
]
*/

Implementation Details


Important Implementation Notes


Interaction with Other Parts of the System


Visual Diagram

flowchart TD
    A[buildOutputList(outputs)] --> B[Object.entries(outputs)]
    B --> C[Array of [key, value] pairs]
    C --> D[Reduce over entries]
    D --> E[For each entry]
    E --> F[Extract key as title]
    E --> G[Extract value.type as type]
    F & G --> H[Push {title, type} into accumulator array]
    H --> I[Return OutputType[] array]

Summary

This file is a small but crucial helper in transforming backend or processing outputs into a front-end consumable format, enabling consistent output presentation across the application.