UNPKG

@memory-bank/mcp

Version:

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

78 lines 2.36 kB
import { DomainError, DomainErrorCodes } from "../../shared/errors/DomainError.js"; import { toSafeBranchName } from "../../shared/utils/branchNameUtils.js"; /** * Value object representing branch information */ export class BranchInfo { _name; _displayName; _type; constructor(_name, _displayName, _type) { this._name = _name; this._displayName = _displayName; this._type = _type; } /** * Factory method to create a new BranchInfo * @param branchName Raw branch name * @returns BranchInfo instance * @throws DomainError if branch name is invalid */ static create(branchName) { if (!branchName) { throw new DomainError(DomainErrorCodes.INVALID_BRANCH_NAME, 'Branch name cannot be empty'); } if (!branchName.includes('/')) { throw new DomainError(DomainErrorCodes.INVALID_BRANCH_NAME, 'Branch name must include a namespace prefix with slash (e.g. "feature/my-branch")'); } const namespacePrefix = branchName.split('/')[0]; const type = namespacePrefix === 'feature' ? 'feature' : namespacePrefix === 'fix' ? 'fix' : 'feature'; const displayName = branchName.substring(branchName.indexOf('/') + 1); if (!displayName) { throw new DomainError(DomainErrorCodes.INVALID_BRANCH_NAME, 'Branch name must have a name after the prefix'); } return new BranchInfo(branchName, displayName, type); } /** * Get the raw branch name */ get name() { return this._name; } /** * Get the display name (without prefix) */ get displayName() { return this._displayName; } /** * Get the branch type */ get type() { return this._type; } /** * Get a safe branch name for filesystem usage */ get safeName() { return toSafeBranchName(this._name); } /** * Checks if two BranchInfo instances are equal * @param other Another BranchInfo instance * @returns boolean indicating equality */ equals(other) { return this._name === other._name; } /** * Convert to string * @returns Raw branch name */ toString() { return this._name; } } //# sourceMappingURL=BranchInfo.js.map