/** * File Info Enricher Interface * * SPI for plugins that enrich FileInfo responses with additional data. * Enrichers are called when specific query parameters are present. */ import { FileInfo } from '@hamak/shared-utils'; import { Request } from 'express'; /** * Context provided to enrichers during file info enrichment */ export interface EnricherContext { /** * The workspace identifier */ workspace: string; /** * The path segments of the file/directory */ pathSegments: string[]; /** * The full resolved path on the filesystem */ resolvedPath: string; /** * The Express request object (for accessing query params, headers, etc.) */ request: Request; /** * The operation type */ operation: 'list' | 'read' | 'get' | 'mkdir' | 'write' | 'delete'; } /** * Interface for file info enrichers * * Enrichers add extension data to FileInfo objects based on query parameters. * For example, a git enricher might add git status when `?extensions=git` is present. * * @example * ```typescript * class GitEnricher implements IFileInfoEnricher { * extensionKey = 'git'; * * shouldEnrich(context: EnricherContext): boolean { * const extensions = context.request.query.extensions; * return extensions?.includes('git') ?? false; * } * * async enrich(fileInfo: FileInfo, context: EnricherContext): Promise { * const gitStatus = await getGitStatus(context.resolvedPath); * return { * ...fileInfo, * extensions: { * ...fileInfo.extensions, * [this.extensionKey]: gitStatus * } * }; * } * } * ``` */ export interface IFileInfoEnricher { /** * Unique key for this enricher (e.g., 'git', 'permissions') * Used as the key in FileInfo.extensions */ readonly extensionKey: string; /** * Priority for enricher execution order (lower = earlier) * Default should be 100. */ readonly priority?: number; /** * Determine if this enricher should process the request * * @param context The enricher context * @returns true if this enricher should enrich the response */ shouldEnrich(context: EnricherContext): boolean; /** * Enrich a single FileInfo with extension data * * @param fileInfo The FileInfo to enrich * @param context The enricher context * @returns The enriched FileInfo */ enrich(fileInfo: FileInfo, context: EnricherContext): Promise; /** * Enrich multiple FileInfo objects (for list operations) * Default implementation calls enrich() for each item. * * @param fileInfos The FileInfo array to enrich * @param context The enricher context * @returns The enriched FileInfo array */ enrichMany?(fileInfos: FileInfo[], context: EnricherContext): Promise; } /** * Registry for file info enrichers */ export interface IFileInfoEnricherRegistry { /** * Register an enricher */ register(enricher: IFileInfoEnricher): void; /** * Unregister an enricher by its extension key */ unregister(extensionKey: string): void; /** * Get all registered enrichers sorted by priority */ getEnrichers(): IFileInfoEnricher[]; /** * Apply all applicable enrichers to a FileInfo */ applyEnrichers(fileInfo: FileInfo, context: EnricherContext): Promise; /** * Apply all applicable enrichers to multiple FileInfo objects */ applyEnrichersMany(fileInfos: FileInfo[], context: EnricherContext): Promise; } //# sourceMappingURL=IFileInfoEnricher.d.ts.map