# tools/core/readers/report.reader.ts

> 21 lines of code and 6 definitions.

Tree: Coordination tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tools-core-readers-report-reader-ts
Source text: https://banes-lab.com/source/coordination/tools/core/readers/report.reader.ts.txt

Listed in [tools/core/readers](https://banes-lab.com/api/source/coordination/tools/core/readers.md), after [tools/core/readers/record.reader.ts](https://banes-lab.com/source/coordination/tools/core/readers/record.reader.ts.md) and before [tools/core/readers/rule.reader.ts](https://banes-lab.com/source/coordination/tools/core/readers/rule.reader.ts.md).

## Definitions

- `reportsIn` (lexical_declaration, line 17, exported)
- `reportIdOf` (lexical_declaration, line 8, exported)
- `reportEntries` (lexical_declaration, line 12, exported)
- `dir` (lexical_declaration, line 18, exported)
- `path` (lexical_declaration, line 20, exported)
- `value` (lexical_declaration, line 21, exported)

## Used by

- [tools/core/validators/governance.validator.ts](https://banes-lab.com/source/coordination/tools/core/validators/governance.validator.ts.md)

## Source

```typescript
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { GENERATED_DIR } from "../constants/path.constants.ts";
import type { ParsedReport } from "../types/report.types.ts";
import { REPORT_SUFFIX } from "../constants/report.constants.ts";
import { resolve } from "node:path";
import { tryParse } from "./json.reader.ts";

export const reportIdOf = function reportIdOf(entry: string): string {
    return entry.slice(0, entry.length - REPORT_SUFFIX.length);
};

export const reportEntries = function reportEntries(repoRoot: string): string[] {
    const dir = resolve(repoRoot, GENERATED_DIR);
    return existsSync(dir) ? readdirSync(dir).filter((entry) => entry.endsWith(REPORT_SUFFIX)) : [];
};

export const reportsIn = function reportsIn(repoRoot: string): ParsedReport[] {
    const dir = resolve(repoRoot, GENERATED_DIR);
    return reportEntries(repoRoot).flatMap((entry) => {
        const path = resolve(dir, entry);
        const value = tryParse(readFileSync(path, "utf8"))?.value;
        return typeof value === "object" && value !== null ? [{ entry, path, value }] : [];
    });
};
```
