Conditiontypeno test imports ittype Condition = { readonly not: boolean; readonly kind: "token" | "etag"; readonly value: string };One condition: a lock token or an entity tag, possibly negated.
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" }Conditiontypeno test imports ittype 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 ittype 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.
parseIffunctionfunction parseIf(header: string): Result<readonly IfList[], string>The lists of an If header, or why it is not read.
submittedTokensfunctionfunction submittedTokens(lists: readonly IfList[]): ReadonlySet<string>The lock tokens a header submits: those that are not negated.
IfFactstypeno test imports ittype 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.
ifHoldsfunctionfunction ifHolds(lists: readonly IfList[], facts: IfFacts): booleanWhether 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.