UNPKG

@directus/api

Version:

Directus is a real-time API and App dashboard for managing SQL database content

31 lines (30 loc) 1.4 kB
import type { AbstractServiceOptions, Folder } from '@directus/types'; import { ItemsService } from './items.js'; export declare class FoldersService extends ItemsService<Folder> { constructor(options: AbstractServiceOptions); /** * Builds a full folder tree starting from a given root folder. * * This method returns a map of folder IDs to their corresponding paths * relative to the root. It resolves all nested child folders and ensures * that folder names are deduplicated within the same parent. * * Access control is applied automatically when non-admin, only folders the user has `read` * access to are included. * * @param {string} root - The ID of the root folder to start building the tree from. * @returns {Promise<Map<string, string>>} A `Map` where: * - Key: folder ID * - Value: folder path relative to the root (e.g., "Documents/Photos") * * @example * const foldersService = new FoldersService({ schema, accountability }); * const tree = await foldersService.buildTree('root-folder-id'); * console.log(tree.get('folder1')); // e.g., "RootFolder/SubFolder1" * * @remarks * - The returned `Map` includes the root folder itself. * - If a folder has no name, its ID will be used as a fallback. */ buildTree(root: string): Promise<Map<string, string>>; }