# core/normalizers/architecture.normalizer.ts

> 52 lines of code and 10 definitions.

Tree: GovLab Context
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/context#file-context-core-normalizers-architecture-normalizer-ts
Source text: https://banes-lab.com/source/context/core/normalizers/architecture.normalizer.ts.txt

Listed in [core/normalizers](https://banes-lab.com/api/source/context/core/normalizers.md), after [core/normalizers/algorithm.normalizer.ts](https://banes-lab.com/source/context/core/normalizers/algorithm.normalizer.ts.md) and before [core/normalizers/field.normalizer.ts](https://banes-lab.com/source/context/core/normalizers/field.normalizer.ts.md).

## Definitions

- `normalizePrinciple` (lexical_declaration, line 11, exported)
- `name` (lexical_declaration, line 17, exported)
- `exemplar` (lexical_declaration, line 18, exported)
- `mandatoryFor` (lexical_declaration, line 19, exported)
- `check` (lexical_declaration, line 20, exported)
- `canon` (lexical_declaration, line 21, exported)
- `distinctFrom` (lexical_declaration, line 22, exported)
- `expressedBy` (lexical_declaration, line 23, exported)
- `formedBy` (lexical_declaration, line 24, exported)
- `violatedBy` (lexical_declaration, line 25, exported)

## Contained in

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

## Uses

- [configuration/strings/architecture.strings.ts](https://banes-lab.com/source/context/configuration/strings/architecture.strings.ts.md)
- [core/converters/identifier.converter.ts](https://banes-lab.com/source/context/core/converters/identifier.converter.ts.md)
- [core/normalizers/field.normalizer.ts](https://banes-lab.com/source/context/core/normalizers/field.normalizer.ts.md)
- [core/validators/field.validator.ts](https://banes-lab.com/source/context/core/validators/field.validator.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/context/folder-context-configuration-strings.md)
- [core/converters](https://banes-lab.com/anatomy/context/folder-context-core-converters.md)
- [core/normalizers](https://banes-lab.com/anatomy/context/folder-context-core-normalizers.md)
- [core/validators](https://banes-lab.com/anatomy/context/folder-context-core-validators.md)

## Source

```typescript
import { ARCH_SCHEMA, PRINCIPLE_KIND } from "#configuration/schemas/architecture.schema";
import { ARCH_SUBJECT, SEVERITY_LEVEL_VALUES } from "#configuration/constants/architecture.constants";
import { asCheck, mergeCheck } from "#core/converters/check.converter";
import { asClosed, asDistinctFrom, asExemplar, asString, asStringArray } from "#core/normalizers/field.normalizer";
import type { CheckFacet } from "#types/check.types";
import type { Principle } from "#types/architecture.types";
import { refuseRecord } from "#core/validators/field.validator";
import { severityOf } from "#configuration/strings/architecture.strings";
import { slugify } from "#core/converters/identifier.converter";

export const normalizePrinciple = function normalizePrinciple(
    raw: Record<string, unknown>,
    category: string,
    declared: CheckFacet | null,
): Principle {
    refuseRecord(ARCH_SUBJECT, PRINCIPLE_KIND, ARCH_SCHEMA, raw);
    const name = asString(raw["name"]);
    const exemplar = asExemplar(raw["exemplar"]);
    const mandatoryFor = asString(raw["mandatoryFor"]);
    const check = mergeCheck(declared, asCheck(raw["check"]));
    const canon = asStringArray(raw["canon"]);
    const distinctFrom = asDistinctFrom(raw["distinctFrom"]);
    const expressedBy = asStringArray(raw["expressedBy"]);
    const formedBy = asString(raw["formed_by"]);
    const violatedBy = asStringArray(raw["violated_by"]);
    return {
        aliases: asStringArray(raw["aliases"]),
        category,
        conflicts_with: asStringArray(raw["conflicts_with"]),
        definition: asString(raw["definition"]),
        detected_by: asStringArray(raw["detected_by"]),
        enables: asStringArray(raw["enables"]),
        enforced_by: asStringArray(raw["enforced_by"]),
        id: asString(raw["id"]) || slugify(name),
        measured_by: asStringArray(raw["measured_by"]),
        name,
        refactored_by: asStringArray(raw["refactored_by"]),
        reinforces: asStringArray(raw["reinforces"]),
        requires: asStringArray(raw["requires"]),
        scope: asStringArray(raw["scope"]),
        severity: asClosed(SEVERITY_LEVEL_VALUES, raw["severity"], severityOf(name)),
        tensions_with: asStringArray(raw["tensions_with"]),
        type: asString(raw["type"]),
        ...(violatedBy.length > 0 ? { violated_by: violatedBy } : {}),
        ...(formedBy ? { formed_by: formedBy } : {}),
        ...(canon.length > 0 ? { canon } : {}),
        ...(check ? { check } : {}),
        ...(distinctFrom.length > 0 ? { distinctFrom } : {}),
        ...(exemplar ? { exemplar } : {}),
        ...(expressedBy.length > 0 ? { expressedBy } : {}),
        ...(mandatoryFor ? { mandatoryFor } : {}),
    };
};
```
