/
foult080
/
terminal-db
Обзор
Документация
Войти
/
foult080
/
terminal-db
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/commands/CommandRegistry.ts
45 строк
1 KB
foult080
feat(): migrate to bun and openTUI
14 июл 2026, 08:30
14 июл 2026, 08:30
97759c7
Код
Авторство
О чём код?
import { AppError } from "../core/errors/AppError.js" import type { Command } from "../core/types/commands.js" import { searchCommands } from "./Command.js" export class CommandRegistry { private commands = new Map<string, Command>() register(command: Command): void { if (this.commands.has(command.id)) { throw AppError.validation(`Command "${command.id}" is already registered`) } this.commands.set(command.id, command) } unregister(id: string): void { if (!this.commands.has(id)) { throw AppError.notFound("Command", id) } this.commands.delete(id) } get(id: string): Command { const command = this.commands.get(id) if (!command) { throw AppError.notFound("Command", id) } return command } has(id: string): boolean { return this.commands.has(id) } list(): Command[] { return [...this.commands.values()] } search(query: string): Command[] { return searchCommands(this.list(), query).map((result) => result.command) } clear(): void { this.commands.clear() } }