# shared/resolvers/container.resolver.ts

> 52 lines of code and 10 definitions.

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

Listed in [shared/resolvers](https://banes-lab.com/api/source/governance/shared/resolvers.md), after [shared/resolvers/anchor.resolver.ts](https://banes-lab.com/source/governance/shared/resolvers/anchor.resolver.ts.md) and before [shared/resolvers/location.resolver.ts](https://banes-lab.com/source/governance/shared/resolvers/location.resolver.ts.md).

## Definitions

- `containerPath` (lexical_declaration, line 19, exported)
- `concernFolders` (lexical_declaration, line 39, exported)
- `containerPaths` (lexical_declaration, line 8, exported)
- `projectRelativeRoots` (lexical_declaration, line 4)
- `paths` (lexical_declaration, line 9, exported)
- `rel` (lexical_declaration, line 23, exported)
- `folder` (lexical_declaration, line 40, exported)
- `roots` (lexical_declaration, line 44, exported)
- `found` (lexical_declaration, line 45, exported)
- `trimmed` (lexical_declaration, line 47, exported)

## Uses

- [shared/manifests/taxonomy.manifest.ts](https://banes-lab.com/source/governance/shared/manifests/taxonomy.manifest.ts.md)
- [shared/strings/taxonomy.strings.ts](https://banes-lab.com/source/governance/shared/strings/taxonomy.strings.ts.md)

## Used by

- [rules/eslint/require-pool-registration.eslint.rule.ts](https://banes-lab.com/source/governance/rules/eslint/require-pool-registration.eslint.rule.ts.md)
- [shared/resolvers/anchor.resolver.ts](https://banes-lab.com/source/governance/shared/resolvers/anchor.resolver.ts.md)

## Source

```typescript
import { ambiguousContainer, rootScope, undeclaredContainerPath } from "../strings/taxonomy.strings.ts";
import { containersFor, folderFor, governedRoots } from "../manifests/taxonomy.manifest.ts";

const projectRelativeRoots = function projectRelativeRoots(): string[] {
    return governedRoots().map((root) => root.slice(root.indexOf("/") + 1));
};

export const containerPaths = function containerPaths(): string[] {
    const paths: string[] = [];
    for (const root of governedRoots()) {
        const rel = root.slice(root.indexOf("/") + 1);
        for (const container of containersFor(root)) {
            paths.push(`${rel}/${container}/`);
        }
    }
    return paths;
};

export const containerPath = function containerPath(container: string, root?: string): string {
    const roots = root === undefined ? governedRoots() : [root];
    const found: string[] = [];
    for (const each of roots) {
        const rel = each.slice(each.indexOf("/") + 1);
        for (const declared of containersFor(each)) {
            if (declared === container) {
                found.push(`${rel}/${declared}/`);
            }
        }
    }
    if (found.length === 0) {
        throw new Error(undeclaredContainerPath(container, root === undefined ? "" : rootScope(root)));
    }
    if (found.length > 1) {
        throw new Error(ambiguousContainer(container, found));
    }
    return found[0] ?? "";
};

export const concernFolders = function concernFolders(tag: string, dirs: readonly string[]): string[] {
    const folder = folderFor(tag);
    if (folder === undefined) {
        return [];
    }
    const roots = projectRelativeRoots();
    const found: string[] = [];
    for (const dir of dirs) {
        const trimmed = dir.endsWith("/") ? dir.slice(0, -1) : dir;
        if (trimmed.slice(trimmed.lastIndexOf("/") + 1) !== folder) {
            continue;
        }
        if (roots.some((rel) => trimmed.startsWith(`${rel}/`))) {
            found.push(`${trimmed}/`);
        }
    }
    return found;
};
```
