IF Commons GitHub

governance/registry

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-grc-layers FR-009

The registry of typed ports (0001-grc-layers FR-009): the one shape every extension point of GRC takes. An entry has a stable id (lower-case words joined by - or .), a second entry of one id is refused as an error value, and a registry says nothing of what its entries are: the port that owns it does.

import { createRegistry } from "./registry.ts";
const r = createRegistry<{ readonly id: string }>("runner");
r.register({ id: "sql" }); // { kind: "ok", ... }
r.register({ id: "sql" }); // { kind: "err", error: { kind: "duplicate", ... } }

Source: commons/grc/src/governance/registry.ts

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

governance.Entrytypeno test imports it
type Entry = { readonly id: string };

What every entry of a registry has.

governance.RegistryProblemtypeno test imports it
type RegistryProblem =
  | { readonly kind: "unstable-id"; readonly registry: string; readonly id: string }
  | { readonly kind: "duplicate"; readonly registry: string; readonly id: string };

Why an entry was refused.

governance.STABLE_IDconstno test imports it
const STABLE_ID: RegExp

A stable id: lower-case words (letters and digits, beginning with a letter) joined by - or ..

governance.Registrytypeno test imports it
type Registry<T extends Entry> = {
  readonly label: string;
  register(entry: T): Result<T, RegistryProblem>;
  get(id: string): T | undefined;
  has(id: string): boolean;
  /** The entries in the order of their ids. */
  list(): readonly T[];
};

A registry of the entries of one port.

governance.createRegistryfunctionno test imports it
function createRegistry<T extends Entry>(label: string): Registry<T>

A registry of its own, empty; label names the port in a problem.

governance.describeRegistryProblemfunctionno test imports it
function describeRegistryProblem(p: RegistryProblem): string

One sentence for a problem.

Entrytypeno test imports it
type Entry = { readonly id: string };

What every entry of a registry has.

RegistryProblemtypeno test imports it
type RegistryProblem =
  | { readonly kind: "unstable-id"; readonly registry: string; readonly id: string }
  | { readonly kind: "duplicate"; readonly registry: string; readonly id: string };

Why an entry was refused.

STABLE_IDconstno test imports it
const STABLE_ID: RegExp

A stable id: lower-case words (letters and digits, beginning with a letter) joined by - or ..

Registrytypeno test imports it
type Registry<T extends Entry> = {
  readonly label: string;
  register(entry: T): Result<T, RegistryProblem>;
  get(id: string): T | undefined;
  has(id: string): boolean;
  /** The entries in the order of their ids. */
  list(): readonly T[];
};

A registry of the entries of one port.

createRegistryfunction
function createRegistry<T extends Entry>(label: string): Registry<T>

A registry of its own, empty; label names the port in a problem.

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

describeRegistryProblemfunctionno test imports it
function describeRegistryProblem(p: RegistryProblem): string

One sentence for a problem.

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