IF Commons GitHub

logical/ifheader

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

The If header: lists of conditions, each a lock token or an entity tag that may be negated, optionally for a named resource. A list holds when all of its conditions do, the header holds for a resource when any list that names it, or names none, holds. The tokens a header submits are the ones a lock check needs. The reader takes the grammar of RFC 4918 and nothing else; text it cannot read is refused whole.

import { parseIf, submittedTokens } from "./ifheader.ts";
const h = parseIf('(<opaquelocktoken:abc> ["etag"])');
submittedTokens(h.kind === "ok" ? h.value : []); // Set { "opaquelocktoken:abc" }

Source: commons/anyfs-serve/src/logical/ifheader.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.

Conditiontypeno test imports it
type Condition = { readonly not: boolean; readonly kind: "token" | "etag"; readonly value: string };

One condition: a lock token or an entity tag, possibly negated.

IfListtypeno test imports it
type IfList = { readonly resource?: string; readonly conditions: readonly Condition[] };

One list of conditions, for a resource it names or for the one the request is about.

parseIffunction
function parseIf(header: string): Result<readonly IfList[], string>

The lists of an If header, or why it is not read.

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

submittedTokensfunction
function submittedTokens(lists: readonly IfList[]): ReadonlySet<string>

The lock tokens a header submits: those that are not negated.

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

IfFactstypeno test imports it
type IfFacts = { readonly etag: string | undefined; readonly tokens: ReadonlySet<string>; readonly names: (resource: string) => boolean };

What the server knows of the resource a header is evaluated for.

ifHoldsfunction
function ifHolds(lists: readonly IfList[], facts: IfFacts): boolean

Whether the header holds for the resource: any list that applies to it holds, and a header with no list that applies does not constrain it.

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

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