import type { BaseFaceConfig, Edge, Ontology, OntologyAudit, OntologyIssues } from "#types/ontology.types"; import type { UnreadKey } from "#types/record.types"; import { createOntology } from "#core/factories/ontology.factory"; export abstract class BaseOntology { protected readonly ontology: Ontology; private readonly matchesFilter: (record: R, filter: F) => boolean; private readonly audit: OntologyAudit; public constructor(records: readonly R[], config: BaseFaceConfig) { this.ontology = createOntology({ idOf: config.idOf, label: config.label, logger: config.logger, records }); this.matchesFilter = config.matches; this.audit = config.audit; } public attributions(): string[] { return this.audit.attributions(); } public unreadKeys(): UnreadKey[] { return this.audit.unread(); } public get(id: string): R | null { return this.ontology.get(id); } public all(): R[] { return this.ontology.all(); } public ids(): string[] { return this.ontology.ids(); } public index(): ReadonlyMap { return this.ontology.index(); } public query(filter?: F): R[] { return this.ontology.query((record) => !filter || this.matchesFilter(record, filter)); } protected validateEdges(edgesOf: (record: R) => Edge[], resolveId?: (target: string) => string): OntologyIssues { return this.ontology.validateOntology(edgesOf, resolveId); } }