Stattypeno test imports ittype Stat = { readonly path: Path; readonly size: number; readonly rev: Revision; readonly modified?: string };What a store says of an object without its bytes.
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"]Stattypeno test imports ittype 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 ittype Read = { readonly bytes: Uint8Array; readonly rev: Revision; readonly modified?: string };The bytes of an object and the revision they are at.
Writtentypeno test imports ittype 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 ittype Deleted = { readonly existed: boolean };What a delete did: whether there was an object.
Listingtypeno test imports ittype 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 ittype 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 ittype BatchWritten = { readonly results: readonly ChangeResult[] };What a batch made: one result for each change, in order.
Versionstypeno test imports ittype Versions = { readonly versions: readonly { readonly rev: Revision; readonly size: number; readonly modified?: string }[] };The earlier revisions of an object, newest first.
Rangedtypeno test imports ittype Ranged = { readonly bytes: Uint8Array; readonly rev: Revision; readonly start: number };A part of an object.
Hitstypeno test imports ittype Hits = { readonly hits: readonly { readonly path: Path; readonly rev: Revision }[] };The objects a search found.
MergeActiontypeno test imports ittype 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 ittype 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.
Changetypetype 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.
ListOptionstypeno test imports ittype ListOptions = { readonly limit?: number; readonly after?: Cursor };What a list is asked: how many entries at most, and where to resume.
Optypetype 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.
OpNametypeno test imports ittype OpName = Op["op"];The name of an operation.
OP_NAMESconstconst 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.
Donetypeno test imports ittype 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 ittype Handler = (op: Op) => Promise<Result<Done, Problem>>;The one function a backend writes: an operation to what it ended with. It does not throw.
capabilityOffunctionfunction capabilityOf(op: Op): "append" | "batch" | "cas" | "delete" | "history" | "list" | "lock" | "merge" | "rangeRead" | "read" | "rename" | "search" | "stat" | "watch" | "write"The capability an operation needs.
expectsRevisionfunctionno test imports itfunction expectsRevision(op: Op): booleanWhether an operation expects a revision somewhere: it needs cas.
capabilitiesNeededfunctionfunction 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.
pathOffunctionfunction pathOf(op: Op): Path | undefinedThe path an operation is about, where it is about one.