IF Commons GitHub

merge/state

Written to: 4 requirements: 4 proved, 0 partly, 0 failing, 0 with no test recorded. 0008-anyfs-merge-logical FR-001, 0008-anyfs-merge-logical FR-002, 0008-anyfs-merge-logical FR-008, 0008-anyfs-merge-logical FR-009

The state of a replica: a set of version rows and a set of blobs, and nothing derived is part of it. What a path holds is a view of the rows: the heads of a path are its versions that no other version replaced, the winner is the head with the greatest id, and the other heads are its siblings; a winner that is a tombstone means the path is not there. The union of two states is their rows and blobs together, which is the same in any order, however grouped and however often, and the view is a function of the rows alone, so replicas that hold the same rows hold the same files.

import { newState } from "./state.ts";

Source: commons/anyfs/src/merge/state.ts

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

MergeConfigtypeno test imports it
type MergeConfig = { readonly maxDrift: number; readonly limits: Limits; readonly trust: Trust };

What a replica is told that is not data: how far ahead of its wall time it takes an id, its limits and whom it takes changes from.

defaultConfigfunction
function defaultConfig(replica: ReplicaId): MergeConfig

A configuration of a replica that takes changes from itself alone, with the default limits and drift.

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

MergeStatetype
type MergeState = { readonly replica: ReplicaId; readonly config: MergeConfig; /** The rows, by `id|sum`: the prim… (822 characters)
type MergeState = {
  readonly replica: ReplicaId;
  readonly config: MergeConfig;
  /** The rows, by `id|sum`: the primary key of the row. */
  readonly versions: ReadonlyMap<string, Version>;
  /** The blobs, by the SHA-256 of their bytes. */
  readonly blobs: ReadonlyMap<string, Uint8Array>;
  readonly last: IdTime | undefined;
  readonly pending: readonly Delta[];
  /** The rows of each path: an index of the rows, made again from them. */
  readonly byPath: ReadonlyMap<string, readonly Version[]>;
  /** The ids some row replaced: what makes a version no longer a head. */
  readonly replaced: ReadonlySet<VersionId>;
  /** The numbers held of each replica's rows. */
  readonly seqs: ReadonlyMap<string, ReadonlySet<number>>;
  /** The highest number of the rows of this replica. */
  readonly ownSeq: number;
};

A replica: its rows and blobs, who it is, the last id time it made or took, and the deltas it holds back until what they wait for arrives.

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

newStatefunction
function newState(replica: ReplicaId, config?: MergeConfig): MergeState

A replica that holds nothing.

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

withVersionfunction
function withVersion(state: MergeState, v: Version): MergeState

The state with a row added (the same row twice is one row) and the index and the clock kept in step with it.

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

withBlobfunction
function withBlob(state: MergeState, sha: string, bytes: Uint8Array<ArrayBufferLike>): MergeState

The state with a blob added.

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

headsOffunction
function headsOf(state: MergeState, path: string): readonly Version[]

The heads of a path: its versions that no other version replaced, the greatest first.

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

PathViewtypeno test imports it
type PathView = { readonly path: string; readonly winner: Version | undefined; readonly present: boolean; readonly siblings: readonly Version[] };

What a path holds now: the winner (the greatest head), whether it is there, and the siblings (the other heads).

viewOffunction
function viewOf(state: MergeState, path: string): PathView

The view of a path: a function of the rows alone.

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

presentPathsfunction
function presentPaths(state: MergeState): readonly string[]

The paths that are there, in the order of their texts.

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

vectorOffunction
function vectorOf(state: MergeState): VersionVector

What a replica holds: for each replica, the number of its last row held with none missing before it.

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

stateTextfunction
function stateText(state: MergeState): string

The state as one text: its rows and its blobs, each in order. Two replicas hold the same state exactly where their texts are equal.

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

viewTextfunction
function viewText(state: MergeState): string

The files as one text: for each path, the winner, whether it is there and its siblings. A function of the rows, so equal states have equal views.

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

PathOptypeno test imports it
type PathOp = { readonly kind: "put"; readonly path: string; readonly blob: string } | { readonly kind: "remove"; readonly path: string };

A change of a replica: put a path with a blob, or remove it.

Madetypeno test imports it
type Made = { readonly state: MergeState; readonly delta: Delta | undefined };

What a transaction made: the state after it and the delta that carries it, none where it changed nothing.

transactfunction
function transact(state: MergeState, ops: readonly PathOp[], blobs: ReadonlyMap<string, Uint8Array<ArrayBufferLike>>, wall: number): Promise<Result<Made, string>>

The changes of one transaction made to a replica, as one delta: every change is a new row with its own id, after the last, that replaces the heads of its path that the replica sees. The bytes of the blobs named are given.

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

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