IF Commons GitHub

governance/path

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

The keys of a store: a path and a prefix, each a branded text made only by its parser, and the reasons another file system could not hold a path. A path is a relative key of segments joined by /, never an operating system's path: it has no . or .., no backslash, no control character, and it is in Unicode normalization form C, so that two spellings of one name are one path. Paths are case sensitive; a store that cannot tell two paths apart by case says so in its traits, and portabilityFindings names what a path could not be in a case-folding or Windows file system.

import { parsePath, parsePrefix, isUnder } from "./path.ts";
const p = parsePath("fleet/olympia/asset.json");
const prefix = parsePrefix("fleet");
p.kind === "ok" && prefix.kind === "ok" && isUnder(prefix.value, p.value); // true

Source: commons/anyfs/src/governance/path.ts

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

Pathtype
type Path = Brand<string, "anyfs path">;

A key of a store: one or more segments joined by /, in normalization form C. Made only by parsePath.

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

Prefixtype
type Prefix = Brand<string, "anyfs prefix">;

The root or a path: what a list is asked below. Made only by parsePrefix.

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

MAX_SEGMENT_BYTESconstno test imports it
const MAX_SEGMENT_BYTES: 255

The longest segment of a path, in UTF-8 bytes.

MAX_PATH_BYTESconstno test imports it
const MAX_PATH_BYTES: 1024

The longest path, in UTF-8 bytes.

parsePathfunction
function parsePath(text: string): Result<Path, string>

A path from text, or the reason it is not one. The text is returned in normalization form C.

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

ROOTconst
const ROOT: Prefix

The root of a store: the prefix of every path.

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

parsePrefixfunction
function parsePrefix(text: string): Result<Prefix, string>

A prefix from text: the empty text is the root, and any other text is a path.

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

isUnderfunction
function isUnder(prefix: Prefix, path: Path): boolean

Whether a path is below a prefix: every path is below the root, and a prefix is not below itself.

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

relativeTofunction
function relativeTo(prefix: Prefix, path: Path): Path | undefined

The path below a prefix, or nothing where the path is not below it.

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

relativePrefixfunctionno test imports it
function relativePrefix(base: Prefix, prefix: Prefix): Prefix | undefined

The prefix below a base: the root where they are the same, and nothing where the prefix is not below the base.

belowfunctionno test imports it
function below(prefix: Prefix, path: Path): Result<Path, string>

A path below a prefix: the prefix, a / and the path, or why it is too long.

nameOffunctionno test imports it
function nameOf(path: Path): string

The last segment of a path.

parentOffunctionno test imports it
function parentOf(path: Path): Prefix

The prefix that holds a path: the root for a path of one segment.

comparePathsfunction
function comparePaths(a: string, b: string): number

The order of paths in a list: by their code points, which no locale changes and which is the order of their UTF-8 bytes.

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

portabilityFindingsfunction
function portabilityFindings(path: Path): readonly string[]

What another file system could not hold in a path: one sentence for each reason, none where the path is portable.

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

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