# core/stores/ontology.store.ts

> 37 lines of code and 13 definitions.

Tree: GovLab Context
Language: typescript
Layer: application
Canonical: https://banes-lab.com/anatomy/context#file-context-core-stores-ontology-store-ts
Source text: https://banes-lab.com/source/context/core/stores/ontology.store.ts.txt

Listed in [core/stores](https://banes-lab.com/api/source/context/core/stores.md), after [core/stores/lexicon.store.ts](https://banes-lab.com/source/context/core/stores/lexicon.store.ts.md).

## Definitions

- `constructor` (method_definition, line 10, exported)
- `BaseOntology` (abstract_class_declaration, line 5, exported)
- `ontology` (public_field_definition, line 6, exported)
- `matchesFilter` (public_field_definition, line 7, exported)
- `audit` (public_field_definition, line 8, exported)
- `attributions` (method_definition, line 16, exported)
- `unreadKeys` (method_definition, line 20, exported)
- `get` (method_definition, line 24, exported)
- `all` (method_definition, line 28, exported)
- `ids` (method_definition, line 32, exported)
- `index` (method_definition, line 36, exported)
- `query` (method_definition, line 40, exported)
- `validateEdges` (method_definition, line 44, exported)

## Contained in

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

## Uses

- [core/factories/ontology.factory.ts](https://banes-lab.com/source/context/core/factories/ontology.factory.ts.md)

## Linked from

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

## Source

```typescript
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<R, F extends object> {
    protected readonly ontology: Ontology<R>;
    private readonly matchesFilter: (record: R, filter: F) => boolean;
    private readonly audit: OntologyAudit;

    public constructor(records: readonly R[], config: BaseFaceConfig<R, F>) {
        this.ontology = createOntology<R>({ 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<string, R> {
        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);
    }
}
```
