UNPKG

@sourcebot/mcp

Version:

[![Sourcebot](https://img.shields.io/badge/Website-sourcebot.dev-blue)](https://sourcebot.dev) [![GitHub](https://img.shields.io/badge/GitHub-sourcebot--dev%2Fsourcebot-green?logo=github)](https://github.com/sourcebot-dev/sourcebot) [![Docs](https://img.s

54 lines 1.7 kB
export const isServiceError = (data) => { return typeof data === 'object' && data !== null && 'statusCode' in data && 'errorCode' in data && 'message' in data; }; export class ServiceErrorException extends Error { serviceError; constructor(serviceError) { super(JSON.stringify(serviceError)); this.serviceError = serviceError; } } export const normalizeTreePath = (path) => { const withoutLeading = path.replace(/^\/+/, ''); return withoutLeading.replace(/\/+$/, ''); }; export const joinTreePath = (parentPath, name) => { if (!parentPath) { return name; } return `${parentPath}/${name}`; }; export const buildTreeNodeIndex = (root) => { const nodeIndex = new Map(); const visit = (node, currentPath) => { nodeIndex.set(currentPath, node); for (const child of node.children) { visit(child, joinTreePath(currentPath, child.name)); } }; visit(root, ''); return nodeIndex; }; export const sortTreeEntries = (entries) => { const collator = new Intl.Collator(undefined, { sensitivity: 'base' }); return [...entries].sort((a, b) => { const parentCompare = collator.compare(a.parentPath, b.parentPath); if (parentCompare !== 0) { return parentCompare; } if (a.type !== b.type) { // sort directories above files return a.type === 'tree' ? -1 : 1; } const nameCompare = collator.compare(a.name, b.name); if (nameCompare !== 0) { return nameCompare; } return collator.compare(a.path, b.path); }); }; //# sourceMappingURL=utils.js.map