IF Commons GitHub

mirror/events

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

What a mirror tells as it works: a closed union of events, each with the time it happened, for a tracing or an audit layer to take. A listener is called for each event in the order they happen and a listener that throws is dropped, so that no listener can stop a write or a convergence. The events can also be read as an async iterable, which ends when the mirror is closed.

import { eventHub } from "./events.ts";
const hub = eventHub();
hub.subscribe((e) => e.kind);

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

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

MirrorEventtype
type MirrorEvent = /** The primary took a change: `op` is what was done, and `path` the object it was done to (the new… (1476 characters)
type MirrorEvent =
  /** The primary took a change: `op` is what was done, and `path` the object it was done to (the new name of a rename). */
  | { readonly kind: "written"; readonly at: number; readonly op: "put" | "delete" | "rename" | "append"; readonly path: Path; readonly rev?: Revision }
  /** Changes wait for the replicas: `pending` is how many paths. */
  | { readonly kind: "queued"; readonly at: number; readonly pending: number }
  /** A replica was brought up to the primary as far as it could be: how many changes were made and how many failed. */
  | { readonly kind: "converged"; readonly at: number; readonly replica: string; readonly applied: number; readonly failed: number }
  /** A replica is behind: `reachable` is false where it could not be reached. */
  | { readonly kind: "behind"; readonly at: number; readonly replica: string; readonly pending: number; readonly reachable: boolean }
  /** A replica was changed by someone else at these paths, which the mirror leaves as they are. */
  | { readonly kind: "diverged"; readonly at: number; readonly replica: string; readonly paths: readonly Path[] }
  /** A replica became the primary. */
  | { readonly kind: "promoted"; readonly at: number; readonly from: string; readonly to: string; readonly lost: number }
  /** A read was answered by a replica because the primary could not be reached. */
  | { readonly kind: "degraded-read"; readonly at: number; readonly path: Path; readonly from: string };

What a mirror tells.

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

EventHubtypeno test imports it
type EventHub = {
  emit(event: MirrorEvent): void;
  /** Calls `listener` for each event after this; the function it gives stops it. */
  subscribe(listener: (event: MirrorEvent) => void): () => void;
  /** The events after this call, until the hub is closed. */
  stream(): AsyncIterable<MirrorEvent>;
  close(): void;
};

The listeners of a mirror and the iterables made from them.

eventHubfunctionno test imports it
function eventHub(): EventHub

An empty hub.

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