# core/converters/dependency.converter.ts

> 50 lines of code and 11 definitions.

Tree: GovLab Docs
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-converters-dependency-converter-ts
Source text: https://banes-lab.com/source/docs/core/converters/dependency.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/docs/core/converters.md), after [core/converters/catalog.converter.ts](https://banes-lab.com/source/docs/core/converters/catalog.converter.ts.md) and before [core/converters/diagram.converter.ts](https://banes-lab.com/source/docs/core/converters/diagram.converter.ts.md).

## Definitions

- `scopedDepNames` (lexical_declaration, line 15, exported)
- `rowOf` (lexical_declaration, line 19)
- `workspaceMapDoc` (lexical_declaration, line 38, exported)
- `LINE_BREAK` (lexical_declaration, line 13)
- `{ maturity }` (lexical_declaration, line 20)
- `{ name }` (lexical_declaration, line 21)
- `workspaceRows` (lexical_declaration, line 30, exported)
- `moduleDepsOf` (lexical_declaration, line 34, exported)
- `rows` (lexical_declaration, line 39, exported)
- `graph` (lexical_declaration, line 40, exported)
- `table` (lexical_declaration, line 41, exported)

## Contained in

- [core/converters](https://banes-lab.com/anatomy/docs/folder-docs-core-converters.md)

## Uses

- [configuration/strings/package.strings.ts](https://banes-lab.com/source/docs/configuration/strings/package.strings.ts.md)
- [core/predicates/record.predicate.ts](https://banes-lab.com/source/docs/core/predicates/record.predicate.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/docs/folder-docs-configuration-strings.md)
- [core/converters](https://banes-lab.com/anatomy/docs/folder-docs-core-converters.md)
- [core/predicates](https://banes-lab.com/anatomy/docs/folder-docs-core-predicates.md)

## Source

```typescript
import { WORKSPACE_MAP, inventoryRow, mermaidFence } from "#configuration/strings/package.strings";
import type { DocumentDecl } from "#types/document.types";
import { MISSING_MATURITY } from "#configuration/constants/figure.constants";
import type { ManifestModule } from "#types/manifest.types";
import type { ModuleDep } from "#types/diagram.types";
import { PACKAGE_SCOPE } from "#configuration/constants/manifest.constants";
import { WORKSPACE_MAP_DOC } from "#configuration/constants/document.constants";
import type { WorkspaceRow } from "#types/figure.types";
import { depGraphOf } from "#core/converters/graph.converter";
import { emitGraph } from "#core/formatters/diagram.formatter";
import { isPlainRecord } from "#core/predicates/record.predicate";

const LINE_BREAK = "\n";

export const scopedDepNames = function scopedDepNames(value: unknown): string[] {
    return Object.keys(isPlainRecord(value) ? value : {}).filter((dep) => dep.startsWith(PACKAGE_SCOPE));
};

const rowOf = function rowOf(module: ManifestModule): WorkspaceRow {
    const { maturity } = module.manifest;
    const { name } = module.pkg;
    return {
        deps: scopedDepNames(module.pkg["dependencies"]),
        group: module.group,
        maturity: typeof maturity === "string" ? maturity : MISSING_MATURITY,
        name: typeof name === "string" ? name : module.slug,
    };
};

export const workspaceRows = function workspaceRows(modules: readonly ManifestModule[]): WorkspaceRow[] {
    return modules.map(rowOf).toSorted((left, right) => left.name.localeCompare(right.name));
};

export const moduleDepsOf = function moduleDepsOf(rows: readonly WorkspaceRow[]): ModuleDep[] {
    return rows.map((row) => ({ deps: row.deps, name: row.name }));
};

export const workspaceMapDoc = function workspaceMapDoc(modules: readonly ManifestModule[]): DocumentDecl {
    const rows = workspaceRows(modules);
    const graph = emitGraph(depGraphOf(moduleDepsOf(rows)));
    const table = [
        ...WORKSPACE_MAP.tableHead,
        ...rows.map((row) => inventoryRow(row.name, row.group, row.maturity, row.deps.length)),
    ].join(LINE_BREAK);
    return {
        ...WORKSPACE_MAP_DOC,
        body: [
            { content: mermaidFence(graph), heading: WORKSPACE_MAP.graphHeading },
            { content: table, heading: WORKSPACE_MAP.inventoryHeading },
        ],
        generated: true,
        lead: WORKSPACE_MAP.lead,
        summary: WORKSPACE_MAP.summary,
        title: WORKSPACE_MAP.title,
    };
};
```
