domain/converters/catalog.converter.ts
domain/converters/catalog.converter.ts is a file in Bane's Lab Site. 183 lines of code and 11 definitions.
import {
CANON_LABEL,
GROUNDED_BY_LABEL,
INVARIANT_LABEL,
PRINCIPLE_LABEL,
} from "#configuration/strings/ontology.strings";
import {
DIMENSION_INTRO,
DIMENSION_TITLE,
FAILS_LABEL,
FIELDS_LABEL,
INVARIANT_INTRO,
INVARIANT_TITLE,
LENSES_LABEL,
MODE_INTRO,
MODE_LABEL,
MODE_TITLE,
NATURE_LABEL,
PATTERN_INTRO,
PATTERN_TITLE,
QUESTION_LABEL,
REPRESENTATION_INTRO,
REPRESENTATION_TITLE,
SUBSUMES_LABEL,
SURFACES_LABEL,
TECHNIQUES_LABEL,
TECHNIQUE_INTRO,
TECHNIQUE_TITLE,
UNIVERSAL_INTRO,
UNIVERSAL_TITLE,
} from "#configuration/strings/reason.strings";
import {
DIMENSION_SECTION_ID,
INVARIANT_SECTION_ID,
MODE_SECTION_ID,
PATTERN_SECTION_ID,
REPRESENTATION_SECTION_ID,
TECHNIQUE_SECTION_ID,
UNIVERSAL_SECTION_ID,
} from "#core/ids/ontology.ids";
import type { Section, Subsection } from "#types/document.types";
import { chips, glossary, labeled, linkList, linkRow, linked, row } from "#domain/converters/ontology.converter";
import { lensSection, mathSection, reasonRecord, surfaceSection } from "#domain/converters/reason.fragment.converter";
import type { Block } from "#types/block.types";
import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons";
import type { ReasonView } from "#types/reason.types";
import type { ResolutionView } from "#types/ontology.types";
import { failureShapeSection } from "#domain/converters/failure.converter";
import { modelSection } from "#domain/converters/loop.converter";
import { structureSections } from "#domain/converters/structure.converter";
type Recorder = (
entry: { readonly anchor: string; readonly id: string; readonly label?: string },
blocks: readonly Block[],
) => Subsection;
const catalog = function catalog(
id: string,
title: string,
intro: string,
subsections: readonly Subsection[],
): Section {
return { icon: REASON_SECTION_ICON, id, intro, subsections, title };
};
const recorderOf = function recorderOf(resolution: ResolutionView): Recorder {
return (entry, blocks) => reasonRecord(entry.anchor, entry.label ?? entry.id, blocks, resolution);
};
const dimensionSection = function dimensionSection(reason: ReasonView, record: Recorder): Section {
return catalog(
DIMENSION_SECTION_ID,
DIMENSION_TITLE,
DIMENSION_INTRO,
reason.dimensions.map((dimension) =>
record(dimension, [
chips([labeled(NATURE_LABEL, dimension.mathNature)]),
glossary([
row(QUESTION_LABEL, dimension.question),
...linkRow(FIELDS_LABEL, dimension.mathDomains),
...linkRow(SURFACES_LABEL, dimension.surfaces),
]),
]),
),
);
};
const modeSection = function modeSection(reason: ReasonView, record: Recorder): Section {
return catalog(
MODE_SECTION_ID,
MODE_TITLE,
MODE_INTRO,
reason.modes.map((mode) =>
record(mode, [
glossary([
row(MODE_LABEL, mode.practice),
...(mode.question === null ? [] : [row(QUESTION_LABEL, mode.question)]),
...linkRow(TECHNIQUES_LABEL, mode.techniques),
]),
]),
),
);
};
const universalSection = function universalSection(reason: ReasonView, record: Recorder): Section {
return catalog(
UNIVERSAL_SECTION_ID,
UNIVERSAL_TITLE,
UNIVERSAL_INTRO,
reason.universalAxes.map((axis) => {
const subsumes = row(SUBSUMES_LABEL, linkList(axis.subsumes));
return record(axis, [
glossary([row(QUESTION_LABEL, axis.question), subsumes, ...linkRow(LENSES_LABEL, axis.lenses)]),
]);
}),
);
};
const techniqueSection = function techniqueSection(reason: ReasonView, record: Recorder): Section {
return catalog(
TECHNIQUE_SECTION_ID,
TECHNIQUE_TITLE,
TECHNIQUE_INTRO,
reason.techniques.map((technique) =>
record(technique, [
chips([linked(MODE_LABEL, technique.mode)]),
glossary([
row(PRINCIPLE_LABEL, technique.principle),
...linkRow(CANON_LABEL, technique.principleRef === null ? [] : [technique.principleRef]),
row(FAILS_LABEL, technique.fails),
...linkRow(SURFACES_LABEL, technique.surfaces),
]),
]),
),
);
};
const invariantSection = function invariantSection(reason: ReasonView, resolution: ResolutionView): Section {
return catalog(
INVARIANT_SECTION_ID,
INVARIANT_TITLE,
INVARIANT_INTRO,
reason.invariants.map((invariant) =>
reasonRecord(
invariant.anchor,
invariant.name,
[
glossary([
row(INVARIANT_LABEL, invariant.statement),
...linkRow(SURFACES_LABEL, invariant.surfaces),
...linkRow(GROUNDED_BY_LABEL, invariant.groundedBy),
]),
],
resolution,
),
),
);
};
export const catalogSections = function catalogSections(
reason: ReasonView,
resolution: ResolutionView,
): readonly Section[] {
const record = recorderOf(resolution);
return [
mathSection(reason, resolution),
dimensionSection(reason, record),
lensSection(reason, resolution),
modeSection(reason, record),
catalog(
REPRESENTATION_SECTION_ID,
REPRESENTATION_TITLE,
REPRESENTATION_INTRO,
reason.representations.map((representation) =>
record(representation, [{ kind: "text", text: representation.expression }]),
),
),
catalog(
PATTERN_SECTION_ID,
PATTERN_TITLE,
PATTERN_INTRO,
reason.patternTypes.map((pattern) => record(pattern, [{ kind: "text", text: pattern.viewpoint }])),
),
modelSection(reason, resolution),
universalSection(reason, record),
surfaceSection(reason, resolution),
techniqueSection(reason, record),
invariantSection(reason, resolution),
failureShapeSection(reason, resolution),
...structureSections(reason),
];
};