IF Commons GitHub

logical/href

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-serve-logical FR-003

The address of a resource and the path it stands for, in both directions. An address is read one segment at a time, so that an encoded slash is never a separator, and a segment that is empty after decoding, is . or .., holds a control character, a NUL or a backslash is refused: nothing is resolved, so nothing climbs out of the root. A name that is not in the normal form of Unicode is turned into it, or refused, as the program says.

import { pathOfUrl, hrefOf } from "./href.ts";
const r = pathOfUrl(new URL("http://127.0.0.1/fleet/olympia%20one.json"), "/", "nfc");
hrefOf(r.kind === "ok" ? r.value.path : undefined, false, "/"); // "/fleet/olympia%20one.json"

Source: commons/anyfs-serve/src/logical/href.ts

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

Addressedtypeno test imports it
type Addressed = { readonly path: PosixPath; readonly collection: boolean };

What an address is: the path and whether the address ended in a slash.

AddressProblemtypeno test imports it
type AddressProblem = { readonly kind: "outside"; readonly message: string } | { readonly kind: "malformed"; readonly message: string } | { readonly kind: "unicode"; readonly message: string };

Why an address is not a path of the store.

normalBasefunctionno test imports it
function normalBase(base: string): string

The base of an address: / or a path with no trailing slash, which the server answers below.

pathOfUrlfunction
function pathOfUrl(url: URL, base: string, unicode: Unicode): Result<Addressed, AddressProblem>

The path an address names, below a base.

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

hrefOffunction
function hrefOf(path: PosixPath | undefined, collection: boolean, base: string): string

The address of a path below a base; a collection ends in a slash. The root of the store is the base itself.

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

pathOfDestinationfunction
function pathOfDestination(value: string, hostOfRequest: string, base: string, unicode: Unicode): Result<Addressed, { readonly kind: "other-host"; readonly message: string; } | AddressProblem>

The path a Destination names: an absolute address on the same host, or an absolute path, below the base.

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

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