layersnamespacenamespace layersLayers: every file on one rung of a harness's ladder, and every relative import climbing it only the way the ladder allows (commons 0015-trace FR-009, FR-010). Pure functions over a ladder (rungs with their homes and the rungs each may rely on) and the contents of files; the findings are trace.ts's, judged against a baseline the same way.
A path is on the rung of the home that matches it most specifically: one path beats every glob, a glob whose last segment names files beats a folder, and among the rest the one with more literal characters wins. So src/**\/mod.ts (the guides) takes src/archon/model/mod.ts from the folder src/archon/model/, and src/archon/model/types.ts takes it from both.
import { layerFindings, type Ladder } from "./layers.ts";
const ladder: Ladder = [
{ number: 0, name: "Ontology", homes: ["ontology/"], mayRelyOn: [] },
{ number: 1, name: "Code", homes: ["src/"], mayRelyOn: [0] },
];
layerFindings(ladder, [{ path: "ontology/a.ts", text: 'import { b } from "../src/b.ts";\n' }]); // one layers/above findinglayersnamespacenamespace layerslayers.Rungtypeno test imports ittype Rung = {
readonly number: number;
readonly name: string;
readonly homes: readonly string[];
readonly mayRelyOn: readonly number[];
};A rung of a ladder: its number, its name, its homes (globs; a trailing / is everything under a folder) and the rungs it may rely on.
layers.Laddertypeno test imports ittype Ladder = readonly Rung[];A ladder: its rungs.
layers.Placementtypeno test imports ittype Placement =
| { readonly kind: "one"; readonly rung: Rung; readonly home: string }
| { readonly kind: "none" }
| { readonly kind: "tie"; readonly rungs: readonly Rung[]; readonly homes: readonly string[] };Where a path is on a ladder: one rung, none, or a tie between rungs whose homes match it equally.
layers.placeOffunctionno test imports itfunction placeOf(ladder: Ladder, path: string): PlacementThe rung a path is on (FR-009).
layers.Importtypeno test imports ittype Import = { readonly line: number; readonly specifier: string };A relative import of a file: the specifier as written and its line.
layers.importsOffunctionno test imports itfunction importsOf(text: string): readonly Import[]Every relative import of a file's text (FR-010): static, side-effect, re-export and dynamic import(), import type included.
layers.resolveImportfunctionno test imports itfunction resolveImport(from: string, specifier: string): stringA relative specifier resolved against the file that imports it, as a path from the repository with /.
layers.layerFindingsfunctionno test imports itfunction layerFindings(ladder: Ladder, files: readonly SourceFile[]): readonly Finding[]Every finding of the layers check (FR-009, FR-010): each file's placement, then each import that climbs the ladder wrongly.
Rungtypeno test imports ittype Rung = {
readonly number: number;
readonly name: string;
readonly homes: readonly string[];
readonly mayRelyOn: readonly number[];
};A rung of a ladder: its number, its name, its homes (globs; a trailing / is everything under a folder) and the rungs it may rely on.
Laddertypetype Ladder = readonly Rung[];A ladder: its rungs.
Placementtypeno test imports ittype Placement =
| { readonly kind: "one"; readonly rung: Rung; readonly home: string }
| { readonly kind: "none" }
| { readonly kind: "tie"; readonly rungs: readonly Rung[]; readonly homes: readonly string[] };Where a path is on a ladder: one rung, none, or a tie between rungs whose homes match it equally.
placeOffunctionfunction placeOf(ladder: Ladder, path: string): PlacementThe rung a path is on (FR-009).
Importtypeno test imports ittype Import = { readonly line: number; readonly specifier: string };A relative import of a file: the specifier as written and its line.
importsOffunctionfunction importsOf(text: string): readonly Import[]Every relative import of a file's text (FR-010): static, side-effect, re-export and dynamic import(), import type included.
resolveImportfunctionfunction resolveImport(from: string, specifier: string): stringA relative specifier resolved against the file that imports it, as a path from the repository with /.
layerFindingsfunctionfunction layerFindings(ladder: Ladder, files: readonly SourceFile[]): readonly Finding[]Every finding of the layers check (FR-009, FR-010): each file's placement, then each import that climbs the ladder wrongly.