IF Commons GitHub

logical/config

Written to: 2 requirements: 2 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-cli-logical FR-001, 0003-anyfs-cli-logical FR-002

The configuration of the anyfs program, written as code (commons anyfs-cli 0003-anyfs-cli-logical FR-001, FR-002): the file anyfs.config.ts exports defineConfig({ ... }), whose mounts name places (fleet is ssh://alpha.example.org/srv/fleet), whose defaults bound a transfer, and whose kinds are the openers of stores that other libraries bring (anyfs-git, anyfs-sql, a bucket): so that a new backend is a line of the configuration and no change to the program. parseConfig checks the whole of it and returns every problem it finds at once, never the first only.

import { defineConfig, parseConfig } from "./config.ts";
const parsed = parseConfig(defineConfig({ mounts: [{ name: "scratch", place: "memory:scratch" }] }));
parsed.kind === "ok" && parsed.value.mounts.length; // 1

Source: commons/anyfs-cli/src/logical/config.ts

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

MountTrustInputtypeno test imports it
type MountTrustInput = {
  readonly mode: "open" | "allowlist" | "signed";
  readonly roster?: string;
  readonly replicas?: readonly string[];
  readonly signKeys?: readonly string[];
};

Whom a store that merges takes changes from, and how it signs, as a mount says it: the mode, the file or variable (env:NAME) that holds the roster of keys, the replicas it takes from where the mode names them, and the files or variables of the keys it signs with (never the keys themselves).

MountInputtypeno test imports it
type MountInput = { readonly name: string; readonly place: string; readonly readOnly?: boolean; readonly note?: string; readonly trust?: MountTrustInput };

A mount as it is written: its name, its place as text, and whether it may only be read.

Mounttypeno test imports it
type Mount = { readonly name: MountName; readonly place: Place; readonly readOnly: boolean; readonly note: string; readonly trust: MountTrustInput | undefined };

A mount, checked.

Defaultstypeno test imports it
type Defaults = {
  /** At most this many actions at once. */
  readonly concurrency: number;
  readonly verify: VerifyMode;
  /** Files larger than this many bytes are left as they are, in a transfer; none means no limit. */
  readonly maxObjectBytes: number | undefined;
};

What a transfer is bounded by where the command line says nothing.

OpenerContexttypeno test imports it
type OpenerContext = {
  readonly env: (name: string) => string | undefined;
  /** The folder the program keeps its state in (the bases of two-way syncs, the ledgers of mirrors). */
  readonly stateDir: string;
};

What an opener of stores is told.

PlaceOpenertype
type PlaceOpener = {
  readonly kind: PlaceKind;
  /** Opens the store at the root of the place. The place of a store of a folder or a host is its root: the path inside it is the command line's. */
  readonly open: (place: Place, context: OpenerContext) => Promise<Result<AnyStore, string>>;
};

The opener of the stores of one kind of place: brought by the library of the kind and listed in the kinds of the configuration.

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

SshInputtypeno test imports it
type SshInput = { readonly knownHosts?: string; readonly userKnownHosts?: string; readonly program?: string };

How ssh is run: the files of known hosts and the program.

ConfigInputtypeno test imports it
type ConfigInput = {
  readonly mounts?: readonly MountInput[];
  readonly defaults?: Partial<Defaults>;
  readonly kinds?: readonly PlaceOpener[];
  readonly ssh?: SshInput;
};

What defineConfig takes.

Configtypeno test imports it
type Config = {
  readonly mounts: readonly Mount[];
  readonly defaults: Defaults;
  readonly kinds: readonly PlaceOpener[];
  readonly ssh: SshInput;
};

The configuration, checked.

CONFIG_FILEconstno test imports it
const CONFIG_FILE: "anyfs.config.ts"

The file the program looks for, from the working folder up.

DEFAULT_DEFAULTSconstno test imports it
const DEFAULT_DEFAULTS: Defaults

What a transfer is bounded by where nothing is said.

defineConfigfunction
function defineConfig(input: ConfigInput): ConfigInput

The configuration as it is written: a typed identity, so that the editor checks the file.

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

EMPTY_CONFIGconst
const EMPTY_CONFIG: Config

The configuration of no file: no mount, the default bounds, no opener but the program's own.

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

parseConfigfunction
function parseConfig(input: ConfigInput): Result<Config, readonly string[]>

Checks a configuration, and gives every problem found.

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

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