MUTATING_CAPABILITIESconstno test imports itconst MUTATING_CAPABILITIES: readonly ["write", "delete", "batch", "rename", "append", "lock", "merge"]The capabilities that change something.
Attenuation: a store given to a program is made smaller before it is given. readOnly takes away every capability that changes anything, sub shows only what is below a prefix, and only keeps the capabilities named. Each makes a store of a type that has no more than its argument, and each can only narrow: there is no function here that gives a store a capability it did not have. A program that holds a store has no other way to the place, because a store has no ambient file system behind it.
import { readOnly, sub } from "./attenuate.ts";
// const fleet = readOnly(sub(root, prefix)): reads below `prefix` and nothing elseMUTATING_CAPABILITIESconstno test imports itconst MUTATING_CAPABILITIES: readonly ["write", "delete", "batch", "rename", "append", "lock", "merge"]The capabilities that change something.
MutatingCapabilitytypeno test imports ittype MutatingCapability = (typeof MUTATING_CAPABILITIES)[number];One capability that changes something.
readOnlyfunctionfunction readOnly<C extends Capability>(store: Store<C>): Store<Exclude<C, "append" | "batch" | "delete" | "lock" | "merge" | "rename" | "watch" | "write">>A store with none of the capabilities of its argument that change anything.
onlyfunctionfunction only<C extends Capability, K extends C & OpCapability>(store: Store<C>, capabilities: readonly K[]): Store<K>A store with only the capabilities named, which the argument has: the compiler refuses a capability it lacks.
viewfunctionno test imports itfunction view<D extends OpCapability>(store: StoreBase, capabilities: readonly D[]): Result<Store<D>, string>A store of the capabilities named, from a store whose type does not say them (one a function was given as any store): the store has them, or the answer says which it lacks.
subfunctionfunction sub<C extends Capability>(store: Store<C>, prefix: Prefix): Store<Exclude<Carried<C>, "merge">>A store of only what is below a prefix of its argument: every path is below the prefix and none can name the way out of it. It has the capabilities of its argument that have an operation.