function schemaTree(schema, rootIndex, path) {
  const element = schema[rootIndex]
  const children = []
  let count = 1

  // Read the specified number of children
  if (element.num_children) {
    while (children.length < element.num_children) {
      const childElement = schema[rootIndex + count]
      const child = schemaTree(schema, rootIndex + count, [...path, childElement.name])
      count += child.count
      children.push(child)
    }
  }

  return { count, element, children, path }
}
Build a tree from the schema elements.

@import {SchemaElement, SchemaTree} from '../src/types.d.ts'
@param {SchemaElement[]} schema
@param {number} rootIndex index of the root element
@param {string[]} path path to the element
@returns {SchemaTree} tree of schema elements