# types/algorithm.types.ts

> 111 lines of code and 17 definitions.

Tree: GovLab Context
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/context#file-context-types-algorithm-types-ts
Source text: https://banes-lab.com/source/context/types/algorithm.types.ts.txt

Listed in [types](https://banes-lab.com/api/source/context/types.md), before [types/architecture.types.ts](https://banes-lab.com/source/context/types/architecture.types.ts.md).

## Definitions

- `DomainTier` (type_alias_declaration, line 7, exported)
- `Production` (interface_declaration, line 9, exported)
- `DerivationMapEntry` (interface_declaration, line 14, exported)
- `ContractRecord` (interface_declaration, line 19, exported)
- `ContractCategory` (interface_declaration, line 43, exported)
- `Contract` (interface_declaration, line 49, exported)
- `SymbolEntry` (interface_declaration, line 54, exported)
- `SymbolFile` (interface_declaration, line 63, exported)
- `ContractSymbolView` (interface_declaration, line 67, exported)
- `AlgoGrammarOptions` (interface_declaration, line 73, exported)
- `ContractFilter` (interface_declaration, line 79, exported)
- `ClosureResult` (interface_declaration, line 86, exported)
- `Cluster` (interface_declaration, line 92, exported)
- `ConcernJoinRow` (interface_declaration, line 98, exported)
- `ConcernResolvers` (interface_declaration, line 105, exported)
- `ContractIssues` (interface_declaration, line 110, exported)
- `AlgoGrammar` (interface_declaration, line 115, exported)

## Contained in

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

## Source

```typescript
import type { DistinctDeclaration, Exemplar } from "#types/field.types";
import type { CheckFacet } from "#types/check.types";
import type { DOMAIN_TIER_VOCABULARY } from "#configuration/constants/algorithm.constants";
import type { Logger } from "#types/ontology.types";
import type { UnreadKey } from "#types/record.types";

export type DomainTier = (typeof DOMAIN_TIER_VOCABULARY)[number]["value"];

export interface Production {
    lhs: string;
    rhs: string;
}

export interface DerivationMapEntry {
    stage: string;
    record: string;
}

export interface ContractRecord {
    id: string;
    title: string;
    aliases?: string[];
    intent: string;
    invariant: string;
    flow: string[];
    productions: Production[];
    composes: string[];
    force: string[];
    grounds?: string[];
    principleRef?: string;
    meta?: boolean;
    exemplar?: Exemplar;
    stage?: string;
    axis?: string;
    mathType?: string;
    yields?: string;
    derivationMap?: DerivationMapEntry[];
    distinctFrom?: DistinctDeclaration[];
    check?: CheckFacet;
    canon?: string[];
}

export interface ContractCategory {
    category: string;
    records: ContractRecord[];
    tier: DomainTier;
}

export interface Contract extends ContractRecord {
    domain: string;
    tier: DomainTier;
}

export interface SymbolEntry {
    grammar: string;
    name: string;
    kind: "composite" | "enum";
    values?: string[];
    rhs?: string;
    definedIn: string[];
}

export interface SymbolFile {
    symbols: SymbolEntry[];
}

export interface ContractSymbolView {
    domain: string;
    id: string;
    productions: readonly { lhs: string; rhs: string }[];
}

export interface AlgoGrammarOptions {
    logger?: Logger | undefined;
    data?: ContractCategory[];
    symbols?: SymbolEntry[];
}

export interface ContractFilter {
    domain?: string;
    force?: string;
    composes?: string;
    meta?: boolean;
}

export interface ClosureResult {
    seed: string[];
    closure: Contract[];
    order: string[];
}

export interface Cluster {
    force: string;
    core: string[];
    supporting: string[];
}

export interface ConcernJoinRow {
    force: string;
    contracts: string[];
    concerns: string[];
    principles: string[];
}

export interface ConcernResolvers {
    concernsForForce?: (force: string) => string[];
    principlesForForce?: (force: string) => string[];
}

export interface ContractIssues {
    duplicateIds: string[];
    danglingComposes: { from: string; target: string }[];
}

export interface AlgoGrammar {
    attributions: () => string[];
    get: (id: string) => Contract | null;
    all: () => Contract[];
    ids: () => string[];
    symbols: () => SymbolEntry[];
    query: (filter?: ContractFilter) => Contract[];
    byForce: (force: string) => Contract[];
    resolveClosure: (ids: string[]) => ClosureResult;
    cluster: () => Cluster[];
    joinConcerns: (resolvers?: ConcernResolvers) => ConcernJoinRow[];
    unreadKeys: () => UnreadKey[];
    validateOntology: () => ContractIssues;
}
```
