# shared/loaders/document.loader.ts

> 23 lines of code and 7 definitions.

Tree: Governance tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/governance#file-governance-shared-loaders-document-loader-ts
Source text: https://banes-lab.com/source/governance/shared/loaders/document.loader.ts.txt

Listed in [shared/loaders](https://banes-lab.com/api/source/governance/shared/loaders.md), after [shared/loaders/barrel.loader.ts](https://banes-lab.com/source/governance/shared/loaders/barrel.loader.ts.md) and before [shared/loaders/graph.loader.ts](https://banes-lab.com/source/governance/shared/loaders/graph.loader.ts.md).

## Definitions

- `relativeLabel` (lexical_declaration, line 10)
- `governedDocumentTexts` (lexical_declaration, line 20, exported)
- `governedManifests` (lexical_declaration, line 14, exported)
- `DOC_MANIFEST` (lexical_declaration, line 8)
- `policy` (lexical_declaration, line 21, exported)
- `manifests` (lexical_declaration, line 22, exported)
- `parsed` (lexical_declaration, line 23, exported)

## Uses

- [shared/loaders/manifest.loader.ts](https://banes-lab.com/source/governance/shared/loaders/manifest.loader.ts.md)
- [shared/selectors/document.selector.ts](https://banes-lab.com/source/governance/shared/selectors/document.selector.ts.md)

## Source

```typescript
import { WORKSPACE_POSIX, memberDirs } from "./manifest.loader.ts";
import { existsSync, readFileSync } from "node:fs";
import { jsonTexts, markdownTexts } from "../selectors/document.selector.ts";
import type { DocumentText } from "../../types/writing.types.ts";
import { absolutePath } from "@ssot/paths";
import path from "node:path";

const DOC_MANIFEST = "_manifest.json";

const relativeLabel = function relativeLabel(file: string): string {
    return path.relative(WORKSPACE_POSIX, file).split(path.sep).join(path.posix.sep);
};

export const governedManifests = function governedManifests(): readonly string[] {
    return [WORKSPACE_POSIX, ...memberDirs()]
        .map((dir) => path.join(dir, DOC_MANIFEST))
        .filter((file) => existsSync(file));
};

export const governedDocumentTexts = function governedDocumentTexts(): DocumentText[] {
    const policy = absolutePath("claudePolicy");
    const manifests = governedManifests().flatMap((file) => {
        const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
        return jsonTexts(relativeLabel(file), parsed);
    });
    return [...markdownTexts(relativeLabel(policy), readFileSync(policy, "utf8")), ...manifests];
};
```
