UNPKG

@memory-bank/mcp

Version:

Memory-enabled Co-Pilot (MCP) server for managing project documentation and context

78 lines 3.21 kB
import { BranchInfo } from "../../../domain/entities/BranchInfo.js"; import { DocumentPath } from "../../../domain/entities/DocumentPath.js"; import { ApplicationError, ApplicationErrorCodes } from "../../../shared/errors/ApplicationError.js"; import { DomainError, DomainErrorCodes } from "../../../shared/errors/DomainError.js"; /** * Use case for updating JSON document indexes */ export class UpdateJsonIndexUseCase { jsonRepository; indexService; globalRepository; /** * Constructor * @param jsonRepository JSON document repository * @param indexService Index service for updating indexes * @param globalRepository Global JSON document repository (optional) */ constructor(jsonRepository, indexService, globalRepository) { this.jsonRepository = jsonRepository; this.indexService = indexService; this.globalRepository = globalRepository; } /** * Execute the use case * @param input Input data * @returns Promise resolving to output data */ async execute(input) { try { const isGlobal = !input.branchName; const repository = isGlobal ? this.globalRepository || this.jsonRepository : this.jsonRepository; const location = isGlobal ? 'global' : input.branchName; const fullRebuild = input.fullRebuild ?? false; const branchInfo = isGlobal ? BranchInfo.create('feature/global') : BranchInfo.create(input.branchName); if (!isGlobal) { const dummyPath = DocumentPath.create('index.json'); const branchExists = await this.jsonRepository.exists(branchInfo, dummyPath); if (!branchExists) { throw new DomainError(DomainErrorCodes.BRANCH_NOT_FOUND, `Branch "${input.branchName}" not found`); } } const documents = await repository.listAll(branchInfo); if (fullRebuild) { await this.indexService.buildIndex(branchInfo, documents); } else { for (const document of documents) { await this.indexService.addToIndex(branchInfo, document); } } const uniqueTags = new Set(); documents.forEach((doc) => { doc.tags.forEach((tag) => uniqueTags.add(tag.value)); }); const tags = Array.from(uniqueTags); return { tags, documentCount: documents.length, updateInfo: { updateLocation: location, fullRebuild, timestamp: new Date().toISOString(), }, }; } catch (error) { if (error instanceof DomainError || error instanceof ApplicationError) { throw error; } throw new ApplicationError(ApplicationErrorCodes.USE_CASE_EXECUTION_FAILED, `Failed to update JSON index: ${error.message}`, { originalError: error }); } } } //# sourceMappingURL=UpdateJsonIndexUseCase.js.map