# tools/core/validators/archive.validator.ts

> 73 lines of code and 12 definitions.

Tree: Coordination tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-validators-archive-validator-ts
Source text: https://banes-lab.com/assets/sources/source.f97a1616a0d9813579b5986e12c33ca23c3736a31c93cffef34ccdf52481bbed.generated.txt

## Definitions

- `shapeRefusal` (lexical_declaration, line 20)
- `textRefusal` (lexical_declaration, line 36)
- `closureRefusal` (lexical_declaration, line 43, exported)
- `extractionRefusal` (lexical_declaration, line 61, exported)
- `extractionCitationRefusal` (lexical_declaration, line 28)
- `EMPTY_EXTRACTION` (lexical_declaration, line 14, exported)
- `EXTRACTION_KIND` (lexical_declaration, line 16, exported)
- `NOT_READER` (lexical_declaration, line 18)
- `judgement` (lexical_declaration, line 21)
- `citation` (lexical_declaration, line 29)
- `cited` (lexical_declaration, line 55, exported)
- `ACKNOWLEDGED` (lexical_declaration, line 59, exported)

## Uses

- [config/surface.config.ts](https://banes-lab.com/source/coordination/config/surface.config.ts.md)
- [tools/core/resolvers/reference.resolver.ts](https://banes-lab.com/source/coordination/tools/core/resolvers/reference.resolver.ts.md)
- [tools/core/strings/archive.strings.ts](https://banes-lab.com/source/coordination/tools/core/strings/archive.strings.ts.md)

## Used by

- [tools/core/runners/archive.runner.ts](https://banes-lab.com/source/coordination/tools/core/runners/archive.runner.ts.md)

## Source

```typescript
import {
    CLOSES_NEEDS_AGENT,
    artifactNeedsRef,
    compressNeedsExtracted,
    extractedUnresolved,
    fenceMalformed,
    judgementWithRef,
    notReader,
    refKindWrong,
} from "../strings/archive.strings.ts";
import { citationRefusal, parseCitation, resolvesCitation } from "../resolvers/reference.resolver.ts";
import { projectRoot } from "../../../config/surface.config.ts";

export const EMPTY_EXTRACTION = "none:carries-nothing-durable";

export const EXTRACTION_KIND = "changelog";

const NOT_READER = "NOTREADER";

const shapeRefusal = function shapeRefusal(closes: string, ref: string | null, kind: string): string | null {
    const judgement = kind === "judgement";
    if (judgement && ref !== null) {
        return judgementWithRef(closes);
    }
    return !judgement && ref === null ? artifactNeedsRef(closes, EMPTY_EXTRACTION) : null;
};

const extractionCitationRefusal = function extractionCitationRefusal(closes: string, ref: string, carried: string): string | null {
    const citation = parseCitation(ref);
    if (citation !== null && citation.kind !== EXTRACTION_KIND) {
        return refKindWrong(closes, citation.kind, EXTRACTION_KIND, EMPTY_EXTRACTION);
    }
    return citationRefusal(ref, (cited) => resolvesCitation(projectRoot(), carried, cited));
};

const textRefusal = function textRefusal(closes: string, text: string | null): string | null {
    if (text === null) {
        return fenceMalformed(closes);
    }
    return text.startsWith(NOT_READER) ? notReader(text) : null;
};

export const closureRefusal = function closureRefusal(
    closes: string,
    ref: string | null,
    agent: string | null,
    text: string | null,
    carried: string,
    kind = "",
): string | null {
    if (agent === null) {
        return CLOSES_NEEDS_AGENT;
    }

    const cited = ref === null || ref === EMPTY_EXTRACTION ? null : extractionCitationRefusal(closes, ref, carried);
    return shapeRefusal(closes, ref, kind) ?? cited ?? textRefusal(closes, text);
};

export const ACKNOWLEDGED = "acknowledged";

export const extractionRefusal = function extractionRefusal(
    changelog: string,
    extracted: string | null,
    carried: string,
    repoRoot = projectRoot(),
): string | null {
    if (extracted === ACKNOWLEDGED) {
        return null;
    }
    if (extracted === EMPTY_EXTRACTION) {
        return null;
    }

    if (extracted !== null && parseCitation(extracted) !== null) {
        return citationRefusal(extracted, (citation) => resolvesCitation(repoRoot, carried, citation));
    }

    if (extracted === null) {
        return compressNeedsExtracted(changelog);
    }

    if (carried.includes(extracted)) {
        return null;
    }

    return extractedUnresolved(changelog, extracted);
};
```
