IF Commons GitHub

exchange/cursor

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0007-bridge-exchange FR-004

What a replica keeps of its exchange, on its own side: the number of its last row that it has published, and the delta files it has taken from the medium (applied, or put aside as not to be taken). It is never written to the medium. A cursor that is lost costs time and nothing else, because a delta applied twice has the effect of once and a file published again is the same file.

import { memoryCursor } from "./cursor.ts";
const cursor = memoryCursor();

Source: commons/anyfs-bridge/src/exchange/cursor.ts

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

CursorStatetypeno test imports it
type CursorState = {
  /** The number of the last of the replica's own rows that it has published, 0 where it has published none. */
  readonly published: number;
  /** The paths of the delta files taken. */
  readonly applied: readonly string[];
  /** The paths of the delta files put aside, which are not tried again. */
  readonly quarantined: readonly string[];
};

What a cursor holds.

EMPTY_CURSORconstno test imports it
const EMPTY_CURSOR: CursorState

A cursor with nothing in it.

Cursortypeno test imports it
type Cursor = {
  load(): Promise<Result<CursorState, string>>;
  save(state: CursorState): Promise<Result<void, string>>;
};

Where the state of an exchange is kept.

memoryCursorfunction
function memoryCursor(initial?: CursorState): Cursor

A cursor that lives as long as the program does.

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

encodeCursorfunctionno test imports it
function encodeCursor(state: CursorState): string

The text a cursor is kept as: JSON, with its lists sorted.

decodeCursorfunctionno test imports it
function decodeCursor(text: string): Result<CursorState, string>

A cursor from its text, or why it is not one.

storeCursorfunctionno test imports it
function storeCursor(store: Store<"read" | "write">, path: Path): Cursor

A cursor kept as one file of a store of this replica's own (never the medium).

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