LockDepthtypeno test imports ittype LockDepth = "0" | "infinity";How far a lock reaches: the resource, or it and everything below.
The table of locks, in memory: exclusive write locks of a depth of 0 or infinity, with a token, an owner and a time at which each ends. Nothing is shared between servers, and a lock that ends is gone the next time anyone asks, so no timer runs. A caller holds a lock by submitting its token; a request that changes a resource a lock covers, without the token, is refused with 423.
import { newLockTable } from "./lock.ts";
const table = newLockTable(() => 0, { maxSeconds: 3600, maxLocks: 10 });
const made = table.create({ path: "/a" as never, depth: "0", owner: "<D:href>me</D:href>", seconds: 60 });
made.kind; // "ok"LockDepthtypeno test imports ittype LockDepth = "0" | "infinity";How far a lock reaches: the resource, or it and everything below.
Locktypeno test imports ittype Lock = { readonly token: string; readonly path: PosixPath; readonly depth: LockDepth; readonly owner: string; readonly expires: number; readonly seconds: number };One lock.
LockRequesttypeno test imports ittype LockRequest = { readonly path: PosixPath; readonly depth: LockDepth; readonly owner: string; readonly seconds: number };What a lock is asked for.
LockProblemtypeno test imports ittype LockProblem = { readonly kind: "locked"; readonly by: Lock } | { readonly kind: "full" } | { readonly kind: "unknown-token" };Why a lock is not made or changed.
LockTabletypeno test imports ittype LockTable = {
/** Locks the resource, unless a lock covers it or a lock below it would be covered. */
create(re… (1101 characters)type LockTable = {
/** Locks the resource, unless a lock covers it or a lock below it would be covered. */
create(request: LockRequest): Result<Lock, LockProblem>;
/** Moves the end of a lock to now plus the seconds (at most the limit). */
refresh(token: string, seconds: number): Result<Lock, LockProblem>;
/** Releases a lock held at a resource. */
release(token: string, path: PosixPath): Result<void, LockProblem>;
/** The locks that cover a resource: at it, or above it with a depth of infinity. */
covering(path: PosixPath): readonly Lock[];
/** The locks at or below a resource. */
below(path: PosixPath): readonly Lock[];
/** The first lock a change of the resource would break, given the tokens the caller submitted; with `subtree`, the locks below it count too. */
blocking(path: PosixPath, submitted: ReadonlySet<string>, subtree: boolean): Lock | undefined;
/** What a token is a lock of, if it is still one. */
find(token: string): Lock | undefined;
/** Forgets the locks at or below a resource (it was deleted or moved). */
drop(path: PosixPath): void;
};The table.
newLockTablefunctionfunction newLockTable(now: () => number, limits: { readonly maxSeconds: number; readonly maxLocks: number; }): LockTableAn empty table with a clock; the clock is read each time, so a test sets the time.