IF Commons GitHub

logical/clock

Written to: 1 requirement: 0 proved, 0 partly, 0 failing, 1 with no test recorded. 0002-planning-core FR-003

The ids of an item and of an event are made by the hybrid clock of AnyFS's merge, reused and not made again (0037-planning FR-007): nextTime and seeTime choose the time of the next id, and makeVersionId writes it with the replica. The clock is a value that is taken and returned (FR-022): the wall time is an argument, never read here, and the last time of the replica is in the value, so that every id a replica makes is after every id it has made or seen. An id whose time is further ahead of the wall time than the limit (five minutes, as AnyFS) is refused when it is taken.

import { mintEventId, newClock } from "./clock.ts";
// const made = mintEventId(newClock(replica), Date.now()); made.kind === "ok" && made.value.id

Source: commons/planning/src/logical/clock.ts

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

logical.Entropytypeno test imports it
type Entropy = { readonly counterSeed: () => number; readonly bytes: () => Uint8Array };

Where the randomness of an id comes from: the seed of the counter of a new millisecond (0 to 2047) and the bytes of rand_b. A test gives its own; the default is the CSPRNG of the runtime, through AnyFS.

logical.SYSTEM_ENTROPYconstno test imports it
const SYSTEM_ENTROPY: Entropy

The entropy of the runtime's CSPRNG (RFC 9562 sections 6.9 and 8).

logical.Clocktypeno test imports it
type Clock = { readonly replica: ReplicaId; readonly last: IdTime | undefined; readonly maxDriftMs: number; readonly entropy: Entropy };

The clock of one replica: which replica it is (the id holds nothing of it), the time of the last id it made or saw, how far ahead of the wall time it takes an id, and its entropy.

logical.ClockProblemtypeno test imports it
type ClockProblem = { readonly kind: "future-id"; readonly id: string; readonly aheadByMs: number; readonly limitMs: number };

Why an id is not taken from another store.

logical.newClockfunctionno test imports it
function newClock(replica: ReplicaId, maxDriftMs?: number, entropy?: Entropy): Clock

The clock of a replica that has made and seen no id.

logical.mintEventIdfunctionno test imports it
function mintEventId(clock: Clock, wallMs: number): Result<{ readonly id: EventId; readonly clock: Clock; }, IdProblem>

A new event id, after every id the clock has made or seen, and the clock after it.

logical.mintItemIdfunctionno test imports it
function mintItemId(clock: Clock, wallMs: number): Result<{ readonly id: ItemId; readonly clock: Clock; }, IdProblem>

A new item id, after every id the clock has made or seen, and the clock after it.

logical.seeIdfunctionno test imports it
function seeId(clock: Clock, id: EventId | ItemId, wallMs: number): Result<Clock, ClockProblem>

The clock after an id taken from another store, so that the next id made comes after it; an id too far ahead of the wall time is refused.

Entropytypeno test imports it
type Entropy = { readonly counterSeed: () => number; readonly bytes: () => Uint8Array };

Where the randomness of an id comes from: the seed of the counter of a new millisecond (0 to 2047) and the bytes of rand_b. A test gives its own; the default is the CSPRNG of the runtime, through AnyFS.

SYSTEM_ENTROPYconstno test imports it
const SYSTEM_ENTROPY: Entropy

The entropy of the runtime's CSPRNG (RFC 9562 sections 6.9 and 8).

Clocktypeno test imports it
type Clock = { readonly replica: ReplicaId; readonly last: IdTime | undefined; readonly maxDriftMs: number; readonly entropy: Entropy };

The clock of one replica: which replica it is (the id holds nothing of it), the time of the last id it made or saw, how far ahead of the wall time it takes an id, and its entropy.

ClockProblemtypeno test imports it
type ClockProblem = { readonly kind: "future-id"; readonly id: string; readonly aheadByMs: number; readonly limitMs: number };

Why an id is not taken from another store.

newClockfunctionno test imports it
function newClock(replica: ReplicaId, maxDriftMs?: number, entropy?: Entropy): Clock

The clock of a replica that has made and seen no id.

mintEventIdfunctionno test imports it
function mintEventId(clock: Clock, wallMs: number): Result<{ readonly id: EventId; readonly clock: Clock; }, IdProblem>

A new event id, after every id the clock has made or seen, and the clock after it.

mintItemIdfunctionno test imports it
function mintItemId(clock: Clock, wallMs: number): Result<{ readonly id: ItemId; readonly clock: Clock; }, IdProblem>

A new item id, after every id the clock has made or seen, and the clock after it.

seeIdfunctionno test imports it
function seeId(clock: Clock, id: EventId | ItemId, wallMs: number): Result<Clock, ClockProblem>

The clock after an id taken from another store, so that the next id made comes after it; an id too far ahead of the wall time is refused.

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