//#region src/tree.types.d.ts type TreeNodeValue = Record | string | number | boolean | null; type TreeNodeValidId = string | number; interface TreeLeafNode { id: TId; parentId: TId; children: []; value?: TValue | undefined; } interface TreeParentNode { id: TId; parentId: TId | null; children: TreeNode[]; value?: TValue | undefined; } interface TreeRootNode { id: TId; parentId: null; children: TreeNode[]; value?: TValue | undefined; } type TreeNode = TreeRootNode | TreeParentNode | TreeLeafNode; //#endregion //#region src/mapper/mapper.types.d.ts type TreeMapperResult = { success: true; treeNodes: TreeNode[]; } | { success: false; message: string; issues: TreeMapperIssue[]; }; type TreeMapperIssue = { message: string; }; //#endregion //#region src/mapper/flat-tree-ws-mapper.d.ts type FlatTreeWsParams = { separator: string; }; type FlatTreeWsUniqueKey = string; type FlatTreeWsMap = Map; type FlatTreeWsRecord = Record; type FlatTreeWs = FlatTreeWsMap | FlatTreeWsRecord; declare class FlatTreeWsMapper { toTreeNodes: (data: FlatTreeWs, params: FlatTreeWsParams) => TreeMapperResult; /** * @throws Error */ toTreeNodesOrThrow: (data: FlatTreeWs, params: FlatTreeWsParams) => TreeNode[]; /** * Will convert a tree of nodes to a flat tree. */ fromTreeNodesOrThrow: (treeNodes: TreeNode[], params: { method: "breadth-first"; }) => FlatTreeWsMap; } //#endregion //#region src/search/dfs-tree-search.d.ts type TreeSearchFindParams = { includeChildren?: boolean; reverse?: boolean; }; type NativeNodeSearchKeys = [key: 'id' | 'parentId', equality: '===', value: string]; type TreeNodeOptionalChildren = TreeNode & { children?: TreeNode; }; /** * Depth-First Search (DFS) algorithm for tree structures. It uses a stack rather * than recursion in order to support deeply nested trees without call-stack overflows. * It is well suited for exploring a branch of a data structure in depth and * usually preferred when memory usage is a concern or when the data * structure has many nodes with few levels. * * @see https://hackernoon.com/a-beginners-guide-to-bfs-and-dfs-in-javascript */ declare class DfsTreeSearch { private readonly treeNodes; constructor(treeNodes: TreeNode[]); /** * Find first matching node in the tree. The `reverse` parameter can be used * to traverse the tree in reverse order. */ findOne: (idOrConditionOrFn: TKey | NativeNodeSearchKeys | ((treeNode: TreeNode) => boolean), params?: TreeSearchFindParams) => TreeNodeOptionalChildren | undefined; } //#endregion //#region src/tree.d.ts declare class Tree { protected readonly treeNodes: TreeNode[]; constructor(treeNodes: TreeNode[]); getTreeNodes: () => TreeNode[]; } //#endregion export { DfsTreeSearch, type FlatTreeWs, FlatTreeWsMapper, Tree, TreeLeafNode, TreeNode, TreeNodeValue, TreeParentNode, TreeRootNode }; //# sourceMappingURL=index.d.ts.map