All files / src/framework registry.ts

100% Statements 38/38
100% Branches 15/15
100% Functions 10/10
100% Lines 38/38

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x                 1x 17x   17x 23x 23x   1x 1x 22x 23x   17x 4x 4x 2x 4x   17x 2x 2x   17x 6x 6x   17x 4x 4x   17x 2x 2x   17x 2x 2x   17x 2x 2x   17x 4x 4x 17x     1x  
/**
 * Check registry — central registration and discovery.
 */
 
import type { Check } from './check-types.js';
import { NotFoundError } from '../lib/errors.js';
 
export type { Check };
 
export class CheckRegistry {
  private readonly checks = new Map<string, Check>();
 
  register(check: Check): void {
    const slug = check.config.slug;
    if (this.checks.has(slug)) {
      // Silently skip duplicate — same check imported multiple times
      return;
    }
    this.checks.set(slug, check);
  }
 
  get(slug: string): Check {
    const check = this.checks.get(slug);
    if (!check) throw new NotFoundError(`Check not found: ${slug}`);
    return check;
  }
 
  has(slug: string): boolean {
    return this.checks.has(slug);
  }
 
  list(): Check[] {
    return [...this.checks.values()];
  }
 
  listEnabled(): Check[] {
    return this.list().filter(c => !c.config.disabled);
  }
 
  byCategory(category: string): Check[] {
    return this.listEnabled().filter(c => c.config.category === category);
  }
 
  getBySlug(slug: string): Check | undefined {
    return this.checks.get(slug);
  }
 
  listSlugs(): string[] {
    return [...this.checks.keys()];
  }
 
  get size(): number {
    return this.checks.size;
  }
}
 
/** Default global registry — checks auto-register here on import */
export const defaultRegistry = new CheckRegistry();