core/loaders/inventory.loader.ts
core/loaders/inventory.loader.ts is a file in Bane's Lab Content. 34 lines of code and 9 definitions.
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("app.coordination", 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;
};