# core/loaders/inventory.loader.ts

> 34 lines of code and 9 definitions.

Tree: Build tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/build#file-build-core-loaders-inventory-loader-ts
Source text: https://banes-lab.com/assets/sources/source.837c529343f2a2d4a271249c3b42794f4baa55be5f07fea1f2cb630f45f10842.generated.txt

## Definitions

- `inventorySourcePaths` (lexical_declaration, line 18, exported)
- `boundaryDocsPresent` (lexical_declaration, line 13)
- `inventoryTarget` (lexical_declaration, line 30, exported)
- `isInventory` (lexical_declaration, line 34)
- `readInventorySources` (lexical_declaration, line 26, exported)
- `readInventory` (lexical_declaration, line 38, exported)
- `readSource` (lexical_declaration, line 9)
- `config` (lexical_declaration, line 14)
- `parsed` (lexical_declaration, line 39, exported)

## Used by

- [runtime/entrypoints/leak.entrypoint.ts](https://banes-lab.com/source/build/runtime/entrypoints/leak.entrypoint.ts.md)

## Source

```typescript
import { AVOIDANCE_REFERENCE, SURFACE_POLICY, UTF8 } from "#configuration/constants/source.constants";
import type { Inventory, SourceText } from "#types/inventory.types";
import { absolutePath, relativePath } from "@ssot/paths";
import { docsConfig, loadGovlabConfig } from "@govlab/quality/config";
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { readJsonOrNull } from "#core/persistence/report.persistence";

const readSource = function readSource(path: string): SourceText {
    return { path, text: readFileSync(join(process.cwd(), path), UTF8) };
};

const boundaryDocsPresent = async function boundaryDocsPresent(): Promise<string[]> {
    const config = await loadGovlabConfig(process.cwd());
    return docsConfig(config).boundaryDocs.filter((name) => existsSync(join(process.cwd(), name)));
};

export const inventorySourcePaths = async function inventorySourcePaths(): Promise<string[]> {
    return [
        ...(await boundaryDocsPresent()),
        relativePath("collaboration.behaviour", SURFACE_POLICY),
        relativePath("docArch.references", AVOIDANCE_REFERENCE),
    ];
};

export const readInventorySources = async function readInventorySources(): Promise<SourceText[]> {
    return (await inventorySourcePaths()).map(readSource);
};

export const inventoryTarget = function inventoryTarget(): string {
    return absolutePath("govlabHost.reports.content.inventory");
};

const isInventory = function isInventory(value: unknown): value is Inventory {
    return typeof value === "object" && value !== null && Array.isArray(Reflect.get(value, "records"));
};

export const readInventory = function readInventory(): Inventory | null {
    const parsed = readJsonOrNull(inventoryTarget());
    return isInventory(parsed) ? parsed : null;
};
```
