# core/registries/section.registry.ts

> 27 lines of code and 7 definitions.

Tree: GovLab Quality
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/quality#file-quality-core-registries-section-registry-ts
Source text: https://banes-lab.com/source/quality/core/registries/section.registry.ts.txt

Listed in [core/registries](https://banes-lab.com/api/source/quality/core/registries.md), after [core/registries/producer.registry.ts](https://banes-lab.com/source/quality/core/registries/producer.registry.ts.md) and before [core/registries/step.registry.ts](https://banes-lab.com/source/quality/core/registries/step.registry.ts.md).

## Definitions

- `defineConfigSection` (lexical_declaration, line 7, exported)
- `EXTENDS_KEY` (lexical_declaration, line 3)
- `sections` (lexical_declaration, line 5)
- `registeredSections` (lexical_declaration, line 12, exported)
- `validateConfig` (lexical_declaration, line 16, exported)
- `errors` (lexical_declaration, line 17, exported)
- `known` (lexical_declaration, line 18, exported)

## Contained in

- [core/registries](https://banes-lab.com/anatomy/quality/folder-quality-core-registries.md)

## Used by

- [core/schemas/tool.schema.ts](https://banes-lab.com/source/quality/core/schemas/tool.schema.ts.md)

## Linked from

- [core/schemas](https://banes-lab.com/anatomy/quality/folder-quality-core-schemas.md)

## Source

```typescript
import type { ConfigSection } from "#types/config.types";

const EXTENDS_KEY = "extends";

const sections = new Map<string, ConfigSection>();

export const defineConfigSection = function defineConfigSection(section: ConfigSection): ConfigSection {
    sections.set(section.key, section);
    return section;
};

export const registeredSections = function registeredSections(): ConfigSection[] {
    return [...sections.values()];
};

export const validateConfig = function validateConfig(config: Record<string, unknown>): string[] {
    const errors: string[] = [];
    const known = new Set<string>([EXTENDS_KEY, ...sections.keys()]);
    for (const key of Object.keys(config)) {
        if (!known.has(key)) {
            errors.push(`unknown config section "${key}"`);
        }
    }
    for (const section of sections.values()) {
        if (Object.hasOwn(config, section.key)) {
            for (const error of section.validate(config[section.key])) {
                errors.push(`${section.key}: ${error}`);
            }
        }
    }
    return errors;
};
```
