IF Commons GitHub

logical/ops

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-anyfs-logical FR-001

The operations of a store as data, and what each ends with. A store is a facade over one handler of operations (store.ts), so that a layer, an attenuation or a mount is a function of operations and can neither be bypassed nor forget one. An operation names the capability it needs, and an expectation of a revision needs cas as well.

import { capabilitiesNeeded } from "./ops.ts";
import { parsePath, expectAny } from "@intellectual-frontiers/anyfs/governance";
const p = parsePath("a");
p.kind === "ok" && capabilitiesNeeded({ op: "write", path: p.value, bytes: new Uint8Array(), expect: expectAny }); // ["write"]

Source: commons/anyfs/src/logical/ops.ts

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

Stattypeno test imports it
type Stat = { readonly path: Path; readonly size: number; readonly rev: Revision; readonly modified?: string };

What a store says of an object without its bytes.

Readtypeno test imports it
type Read = { readonly bytes: Uint8Array; readonly rev: Revision; readonly modified?: string };

The bytes of an object and the revision they are at.

Writtentypeno test imports it
type Written = { readonly rev: Revision; readonly created: boolean };

What a write made: the revision of the object and whether it did not exist.

Deletedtypeno test imports it
type Deleted = { readonly existed: boolean };

What a delete did: whether there was an object.

Listingtypeno test imports it
type Listing = { readonly entries: readonly Stat[]; readonly next?: Cursor };

One page of a list: the entries in the order of their paths, and where the next page begins where there is one.

ChangeResulttypeno test imports it
type ChangeResult = { readonly kind: "put"; readonly path: Path; readonly rev: Revision; readonly created: boolean } | { readonly kind: "delete"; readonly path: Path; readonly existed: boolean };

What one change of a batch made.

BatchWrittentypeno test imports it
type BatchWritten = { readonly results: readonly ChangeResult[] };

What a batch made: one result for each change, in order.

Versionstypeno test imports it
type Versions = { readonly versions: readonly { readonly rev: Revision; readonly size: number; readonly modified?: string }[] };

The earlier revisions of an object, newest first.

Rangedtypeno test imports it
type Ranged = { readonly bytes: Uint8Array; readonly rev: Revision; readonly start: number };

A part of an object.

Hitstypeno test imports it
type Hits = { readonly hits: readonly { readonly path: Path; readonly rev: Revision }[] };

The objects a search found.

MergeActiontypeno test imports it
type MergeAction = { readonly kind: "vector" } | { readonly kind: "since"; readonly since: VersionVector } | { readonly kind: "apply"; readonly delta: Delta };

What a merge is asked: what the replica has seen, the delta of what it has that a replica which has seen a vector has not, or to take a delta.

MergeAnswertypeno test imports it
type MergeAnswer = { readonly kind: "vector"; readonly vector: VersionVector } | { readonly kind: "delta"; readonly delta: Delta } | { readonly kind: "outcome"; readonly outcome: MergeOutcome };

What a merge answered: a vector, a delta, or what taking a delta ended with.

Changetype
type Change<E extends Expect = Expect> =
  | { readonly kind: "put"; readonly path: Path; readonly bytes: Uint8Array; readonly expect: E }
  | { readonly kind: "delete"; readonly path: Path; readonly expect: E };

One change of a batch.

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

ListOptionstypeno test imports it
type ListOptions = { readonly limit?: number; readonly after?: Cursor };

What a list is asked: how many entries at most, and where to resume.

Optype
type Op = | { readonly op: "read"; readonly path: Path } | { readonly op: "write"; readonly path: Path; readonly byt… (997 characters)
type Op =
  | { readonly op: "read"; readonly path: Path }
  | { readonly op: "write"; readonly path: Path; readonly bytes: Uint8Array; readonly expect: Expect }
  | { readonly op: "stat"; readonly path: Path }
  | { readonly op: "list"; readonly prefix: Prefix; readonly limit?: number; readonly after?: Cursor }
  | { readonly op: "delete"; readonly path: Path; readonly expect: Expect }
  | { readonly op: "batch"; readonly changes: readonly Change[] }
  | { readonly op: "rename"; readonly from: Path; readonly to: Path; readonly expect: Expect }
  | { readonly op: "history"; readonly path: Path; readonly limit?: number }
  | { readonly op: "rangeRead"; readonly path: Path; readonly start: number; readonly length: number }
  | { readonly op: "append"; readonly path: Path; readonly bytes: Uint8Array; readonly expect: Expect }
  | { readonly op: "search"; readonly prefix: Prefix; readonly text: string; readonly limit?: number }
  | { readonly op: "merge"; readonly action: MergeAction };

An operation of a store, as data: a closed union.

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

OpNametypeno test imports it
type OpName = Op["op"];

The name of an operation.

OP_NAMESconst
const OP_NAMES: readonly ("append" | "batch" | "delete" | "history" | "list" | "merge" | "rangeRead" | "read" | "rename" | "search" | "stat" | "write")[]

The names of the operations, in the order of the capabilities.

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

Donetypeno test imports it
type Done = | { readonly op: "read"; readonly value: Read } | { readonly op: "write"; readonly value: Written } | … (667 characters)
type Done =
  | { readonly op: "read"; readonly value: Read }
  | { readonly op: "write"; readonly value: Written }
  | { readonly op: "stat"; readonly value: Stat }
  | { readonly op: "list"; readonly value: Listing }
  | { readonly op: "delete"; readonly value: Deleted }
  | { readonly op: "batch"; readonly value: BatchWritten }
  | { readonly op: "rename"; readonly value: Written }
  | { readonly op: "history"; readonly value: Versions }
  | { readonly op: "rangeRead"; readonly value: Ranged }
  | { readonly op: "append"; readonly value: Written }
  | { readonly op: "search"; readonly value: Hits }
  | { readonly op: "merge"; readonly value: MergeAnswer };

What an operation ended with: a closed union, tagged by the operation it answers.

Handlertypeno test imports it
type Handler = (op: Op) => Promise<Result<Done, Problem>>;

The one function a backend writes: an operation to what it ended with. It does not throw.

capabilityOffunction
function capabilityOf(op: Op): "append" | "batch" | "cas" | "delete" | "history" | "list" | "lock" | "merge" | "rangeRead" | "read" | "rename" | "search" | "stat" | "watch" | "write"

The capability an operation needs.

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

expectsRevisionfunctionno test imports it
function expectsRevision(op: Op): boolean

Whether an operation expects a revision somewhere: it needs cas.

capabilitiesNeededfunction
function capabilitiesNeeded(op: Op): readonly ("append" | "batch" | "cas" | "delete" | "history" | "list" | "lock" | "merge" | "rangeRead" | "read" | "rename" | "search" | "stat" | "watch" | "write")[]

Every capability an operation needs: its own, and cas where it expects a revision.

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

pathOffunction
function pathOf(op: Op): Path | undefined

The path an operation is about, where it is about one.

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

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