IF Commons GitHub

mirror/ledger

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0006-bridge-mirrored FR-006

The ledgers of a mirror, kept on its primary: one document for each replica, in a collection of typed documents below a reserved prefix, so that what each replica was last brought to is in the place that is authoritative and not in the memory of a process. A ledger is written at the version of its schema and read at any version up to it; a document that cannot be read is a problem and never an empty ledger, because an empty ledger would make every change of the replica look like a divergence of its own.

import { ledgerDoc } from "./ledger.ts";
ledgerDoc("git", { applied: new Map() }); // { replica: "git", applied: [] }

Source: commons/anyfs-bridge/src/mirror/ledger.ts

0 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.

LedgerDoctypeno test imports it
type LedgerDoc = { readonly replica: string; readonly applied: readonly (readonly [string, string])[] };

The document of a ledger: the replica it is of and, for each path, the SHA-256 in hex of the bytes the replica was last brought to.

ledgerDocfunctionno test imports it
function ledgerDoc(replica: string, ledger: Ledger): LedgerDoc

The document of a ledger, its paths in order.

ledgerOffunctionno test imports it
function ledgerOf(doc: LedgerDoc): Result<Ledger, string>

The ledger of a document, or the path that is not one.

LedgerProblemtypeno test imports it
type LedgerProblem = { readonly kind: "unreadable"; readonly replica: string; readonly detail: string } | { readonly kind: "unwritable"; readonly replica: string; readonly detail: string };

What the ledgers were asked and could not do.

LedgerBooktypeno test imports it
type LedgerBook = { /** The ledger of a replica: an empty one where there is none, and a problem where one is there an… (688 characters)
type LedgerBook = {
  /** The ledger of a replica: an empty one where there is none, and a problem where one is there and cannot be read. */
  load(replica: DocId): Promise<Result<Ledger, LedgerProblem>>;
  save(replica: DocId, ledger: Ledger): Promise<Result<void, LedgerProblem>>;
  /** Saves several ledgers: as one batch where the primary has one (one commit of a branch, not one for each), else one after the other. */
  saveMany(entries: readonly { readonly replica: DocId; readonly ledger: Ledger }[]): Promise<Result<void, LedgerProblem>>;
  /** Takes the ledger of a replica away, where it can be; what cannot be taken away is left. */
  remove(replica: DocId): Promise<void>;
};

The ledgers of a mirror.

ledgerBookfunctionno test imports it
function ledgerBook(primary: Dest, prefix: Prefix): Result<LedgerBook, string>

The ledgers below prefix of the primary.

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