# domain/converters/check.converter.ts

> 70 lines of code and 10 definitions.

Tree: Site tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/tree#file-domain-converters-check-converter-ts
Source text: https://banes-lab.com/source/tree/domain/converters/check.converter.ts.txt

Listed in [domain/converters](https://banes-lab.com/api/source/tree/domain/converters.md), after [domain/converters/chapter.converter.ts](https://banes-lab.com/source/tree/domain/converters/chapter.converter.ts.md) and before [domain/converters/contract.converter.ts](https://banes-lab.com/source/tree/domain/converters/contract.converter.ts.md).

## Definitions

- `checkBlocks` (lexical_declaration, line 61, exported)
- `answerRow` (lexical_declaration, line 28)
- `canonOf` (lexical_declaration, line 47, exported)
- `listRow` (lexical_declaration, line 24)
- `checkRowsOf` (lexical_declaration, line 32, exported)
- `{ answers }` (lexical_declaration, line 33, exported)
- `recordCheckOf` (lexical_declaration, line 53, exported)
- `entry` (lexical_declaration, line 54, exported)
- `answers` (lexical_declaration, line 55, exported)
- `check` (lexical_declaration, line 62, exported)

## Uses

- [configuration/strings/reference.strings.ts](https://banes-lab.com/source/tree/configuration/strings/reference.strings.ts.md)
- [domain/converters/ontology.converter.ts](https://banes-lab.com/source/tree/domain/converters/ontology.converter.ts.md)

## Used by

- [domain/converters/contract.converter.ts](https://banes-lab.com/source/tree/domain/converters/contract.converter.ts.md)
- [domain/converters/failure.converter.ts](https://banes-lab.com/source/tree/domain/converters/failure.converter.ts.md)
- [domain/converters/grammar.section.converter.ts](https://banes-lab.com/source/tree/domain/converters/grammar.section.converter.ts.md)
- [domain/converters/lexicon.converter.ts](https://banes-lab.com/source/tree/domain/converters/lexicon.converter.ts.md)
- [domain/converters/loop.converter.ts](https://banes-lab.com/source/tree/domain/converters/loop.converter.ts.md)
- [domain/converters/principle.converter.ts](https://banes-lab.com/source/tree/domain/converters/principle.converter.ts.md)
- [domain/converters/reason.fragment.converter.ts](https://banes-lab.com/source/tree/domain/converters/reason.fragment.converter.ts.md)
- [presentation/components/reference.component.ts](https://banes-lab.com/source/tree/presentation/components/reference.component.ts.md)

## Source

```typescript
import {
    CHECK_AUTHORITY_LABEL,
    CHECK_BY_LABEL,
    CHECK_DEPENDS_ON_LABEL,
    CHECK_EVIDENCE_LABEL,
    CHECK_FRESHNESS_LABEL,
    CHECK_HEADING,
    CHECK_OBSERVATION_LABEL,
    CHECK_POPULATION_LABEL,
    CHECK_REFUSAL_LABEL,
    CHECK_SHAPE_LABEL,
    DECLARED_ABSENCE_MARK,
    NOT_ANSWERED,
    checkAnswerOf,
    evidenceAnswerOf,
} from "#configuration/strings/reference.strings";
import type { CheckRow, CheckView, RecordCheckView } from "#types/reference.types";
import type { RecordCheckEntryView, ResolutionView } from "#types/ontology.types";
import { glossary, linkOf, row, text } from "#domain/converters/ontology.converter";
import type { Block } from "#types/block.types";
import type { EdgeRef } from "#types/link.types";
import { LIST_SEPARATOR } from "#configuration/strings/ontology.strings";

const listRow = function listRow(label: string, edges: readonly EdgeRef[]): CheckRow {
    return { edges: edges.length === 0 ? null : edges, label, text: NOT_ANSWERED };
};

const answerRow = function answerRow(label: string, answer: string | null): CheckRow {
    return { edges: null, label, text: checkAnswerOf(answer) };
};

export const checkRowsOf = function checkRowsOf(check: RecordCheckView): readonly CheckRow[] {
    const { answers } = check;
    return [
        listRow(CHECK_BY_LABEL, check.by),
        answerRow(CHECK_POPULATION_LABEL, answers.population),
        answerRow(CHECK_FRESHNESS_LABEL, answers.freshness),
        answerRow(CHECK_REFUSAL_LABEL, answers.refusal),
        answerRow(CHECK_OBSERVATION_LABEL, answers.observation),
        { edges: null, label: CHECK_EVIDENCE_LABEL, text: evidenceAnswerOf(answers.evidence) },
        answerRow(CHECK_AUTHORITY_LABEL, answers.authority),
        listRow(CHECK_DEPENDS_ON_LABEL, check.dependsOn),
        listRow(CHECK_SHAPE_LABEL, check.shape),
    ];
};

export const canonOf = function canonOf(canon: readonly string[]): string {
    return canon
        .map((entry) => (entry.startsWith(DECLARED_ABSENCE_MARK) ? checkAnswerOf(entry) : entry))
        .join(LIST_SEPARATOR);
};

export const recordCheckOf = function recordCheckOf(resolution: ResolutionView, ref: string): RecordCheckView | null {
    const entry: RecordCheckEntryView | undefined = resolution.byRecord[ref];
    const answers: CheckView | undefined = entry === undefined ? undefined : resolution.answers[entry.answers];
    return entry === undefined || answers === undefined
        ? null
        : { answers, by: entry.by, dependsOn: entry.dependsOn, shape: entry.shape };
};

export const checkBlocks = function checkBlocks(resolution: ResolutionView, ref: string): readonly Block[] {
    const check = recordCheckOf(resolution, ref);
    if (check === null) {
        throw new Error(
            `ontology: the resolution carries no check for ${ref}, so its record section cannot show how it is checked`,
        );
    }
    return [
        text(CHECK_HEADING),
        glossary(
            checkRowsOf(check).map((line) =>
                row(line.label, line.edges === null ? line.text : line.edges.map(linkOf).join(LIST_SEPARATOR)),
            ),
        ),
    ];
};
```
