core/factories/evidence.factory.ts

core/factories/evidence.factory.ts is a file in Bane's Lab Site. 47 lines of code and 9 definitions.

import type { AbsenceReason, DeclaredAbsence, Evidence, EvidenceNode, EvidenceSubject } from "#types/evidence.types";
import { FACE_SEPARATOR } from "@govlab/constants";

export const recordSubject = function recordSubject(face: string, id: string): EvidenceSubject {
    return { kind: "record", ref: face + FACE_SEPARATOR + id };
};

export const chapterSubject = function chapterSubject(page: string, tab: string, section: string): EvidenceSubject {
    return { kind: "chapter", page, section, tab };
};

export const definitionNode = function definitionNode(name: string, file: string | null = null): EvidenceNode {
    return { file, kind: "definition", name };
};

export const fileNode = function fileNode(name: string): EvidenceNode {
    return { kind: "file", name };
};

export const folderNode = function folderNode(...words: readonly string[]): EvidenceNode {
    return { kind: "folder", words };
};

export const groundedBy = function groundedBy(
    nodes: readonly EvidenceNode[],
    face: string,
    ids: readonly string[],
): readonly Evidence[] {
    return ids.map((id) => ({ nodes, subject: recordSubject(face, id) }));
};

export const groundedChapters = function groundedChapters(
    nodes: readonly EvidenceNode[],
    page: string,
    tab: string,
    sections: readonly string[],
): readonly Evidence[] {
    return sections.map((section) => ({ nodes, subject: chapterSubject(page, tab, section) }));
};

export const absentChapters = function absentChapters(
    reason: AbsenceReason,
    page: string,
    tab: string,
    sections: readonly string[],
): readonly DeclaredAbsence[] {
    return sections.map((section) => ({ reason, subject: chapterSubject(page, tab, section) }));
};

export const absentRecords = function absentRecords(
    reason: AbsenceReason,
    face: string,
    ids: readonly string[],
): readonly DeclaredAbsence[] {
    return ids.map((id) => ({ reason, subject: recordSubject(face, id) }));
};