IF Commons GitHub

layers

Layers: 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 finding

Source: commons/mizan/src/layers.ts

5 of 16 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

layersnamespace
namespace layers
layers.Rungtypeno test imports it
type 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 it
type Ladder = readonly Rung[];

A ladder: its rungs.

layers.Placementtypeno test imports it
type 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 it
function placeOf(ladder: Ladder, path: string): Placement

The rung a path is on (FR-009).

layers.Importtypeno test imports it
type Import = { readonly line: number; readonly specifier: string };

A relative import of a file: the specifier as written and its line.

layers.importsOffunctionno test imports it
function 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 it
function resolveImport(from: string, specifier: string): string

A relative specifier resolved against the file that imports it, as a path from the repository with /.

layers.layerFindingsfunctionno test imports it
function 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 it
type 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.

Laddertype
type Ladder = readonly Rung[];

A ladder: its rungs.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Placementtypeno test imports it
type 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.

placeOffunction
function placeOf(ladder: Ladder, path: string): Placement

The rung a path is on (FR-009).

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Importtypeno test imports it
type Import = { readonly line: number; readonly specifier: string };

A relative import of a file: the specifier as written and its line.

importsOffunction
function 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.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

resolveImportfunction
function resolveImport(from: string, specifier: string): string

A relative specifier resolved against the file that imports it, as a path from the repository with /.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

layerFindingsfunction
function 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.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.