"use strict"; const lastItem = require("last-item"); const createNamedTreeBuilder = require("./named-tree-builder"); const specialUseAttributes = new Set([ '\\All', '\\Archive', '\\Drafts', '\\Flagged', '\\Important', '\\Junk', '\\Sent', '\\Trash' ]); // TODO: Eventually make this progressively updateable so that the results of multiple LIST commands can be combined over time? module.exports = function createBoxTreeBuilder() { let treeBuilder = createNamedTreeBuilder({ childrenKey: "children", parentKey: "parent", treatRootAsParent: false }); return { add: function (item) { let { flags, delimiter } = item; let path = (delimiter != null) ? item.name.split(delimiter) : [ item.name ]; treeBuilder.add(path, { name: lastItem(path), path: path, attributes: flags, delimiter: delimiter, specialUseAttribute: flags.find((attribute) => specialUseAttributes.has(attribute)), children: null, parent: null }); }, done: function () { return treeBuilder.done().children; } }; };