import { type TreeNode, type TreeNodeWithoutChildren } from './tree'; import { type Maybe } from '../value/maybe.type'; /** * Configuration for an ExpandTreeFunction, defining how to retrieve child values for a given value. * * @template T The type of the value being processed at each node in the tree. */ export interface ExpandTree { /** * Returns child values from the input value, if they exist. * These child values will be recursively processed to form child nodes. * * @param value The current value of type T to retrieve children for. * @param depth The depth of the current node. * @returns An array of child values of type T, or undefined/null if no children exist. */ getChildren(value: T, depth: number): Maybe; } /** * Extended ExpandTree configuration that includes a custom node builder. * This allows for creating tree nodes of a specific type N, potentially with additional properties beyond the basic TreeNode structure. * * @template T The type of the value being processed at each node. * @template N The specific type of TreeNode to be created. Must extend TreeNode. */ export interface ExpandTreeWithNodeBuilder> extends ExpandTree { /** * Creates a tree node of type N (omitting the 'children' property, which is attached later). * This function is called for each value being converted into a node in the tree. * * @param node A TreeNodeWithoutChildren object containing the core properties (value, depth, parent). * @returns An object of type Omit, representing the custom-built node without its children. */ makeNode: (node: TreeNodeWithoutChildren) => Omit; } /** * A function that expands an input value of type T into a TreeNode of type N. * * @template T The type of the input value to expand. * @template N The type of the TreeNode to be created. Defaults to TreeNode. * @param value The input value of type T to expand into a tree node. * @returns A tree node of type N representing the expanded value and its descendants. */ export type ExpandTreeFunction = TreeNode> = (value: T) => N; /** * Creates an ExpandTreeFunction using a basic ExpandTree configuration. * The resulting nodes will be of type TreeNode. * * @template T The type of the value being processed at each node. * @param config An ExpandTree configuration object. * @returns An ExpandTreeFunction>. */ export declare function expandTreeFunction(config: ExpandTree): ExpandTreeFunction>; /** * Creates an ExpandTreeFunction using an ExpandTreeWithNodeBuilder configuration. * This allows for the creation of custom tree nodes of type N. * * @template T The type of the value being processed at each node. * @template N The specific type of TreeNode to be created. * @param config An ExpandTreeWithNodeBuilder configuration object. * @returns An ExpandTreeFunction. */ export declare function expandTreeFunction>(config: ExpandTreeWithNodeBuilder): ExpandTreeFunction; /** * Convenience function for expanding multiple root values into an array of trees. * Each value in the input array is treated as a root for a new tree. * * @template T The type of the input values. * @template N The type of the TreeNode in the resulting trees. Must extend TreeNode. * @param values An array of root values of type T to expand. * @param expandFn An ExpandTreeFunction used to expand each value into a tree. * @returns An array of N, where each N is the root node of an expanded tree. */ export declare function expandTrees>(values: T[], expandFn: ExpandTreeFunction): N[];