function curateStructuredFields(typeAllowsChildren, fields, maxDepth) {
  const /** @type StructuredFieldSpecification */
    structuredFields = {
      children: {},
      root: true,
    };

  for (let i = 1; i <= maxDepth; i++) {
    if (!has(fields, i)) {
      throw assertionError.get("missing_nested_spec");
    }

    fields[i].forEach((field) => {
      const parent = getParent(structuredFields, field.path),
        childKey = field.path[field.path.length - 1];

      if (!parent.root && typeAllowsChildren.indexOf(parent.type) === -1) {
        throw assertionError.get("unexpected_children", parent.type);
      }

      if (!has(parent, "children")) {
        parent.children = {};
      }

      parent.children[childKey] = field;
    });
  }

  return structuredFields;
}
@param {string[]} typeAllowsChildren
@param {StructuredFieldSpecification[][]} fields
@param {number} maxDepth : depth of the fields; counting starts at 1
@throws PreconditionError