OpCapabilitytypetype OpCapability = Exclude<Capability, "watch" | "lock">;The capabilities that have an operation: every one but watch and lock.
The store: one interface to a place, whose capabilities are in its type. Store<C> has the methods of the capabilities C and no other, and a function that needs a capability takes a Store that has it, so that a store without it is a compile error and not a surprise at run time. A store is made by makeStore from one handler of operations: the store is a facade, so that every layer and every attenuation is a function of operations and none can be bypassed.
The one cast of the library is in makeStore: it builds the object from the capabilities it is given and gives it the type those capabilities say. A test holds it: a store has a method exactly where its capabilities name one. watch and lock are capabilities with no operation, so makeStore makes no store of them yet.
import { makeStore } from "./store.ts";
// a store of `read` alone: store.write does not exist, and a function that needs `write` refuses itOpCapabilitytypetype OpCapability = Exclude<Capability, "watch" | "lock">;The capabilities that have an operation: every one but watch and lock.
Changedtypeno test imports ittype Changed = { readonly path: Path; readonly kind: "put" | "delete" };The change of an object a watcher is told of.
Subscriptiontypeno test imports ittype Subscription = { stop(): void };A watch: stop it with stop.
Locktypeno test imports ittype Lock = { release(): Promise<void> };A held object: give it back with release.
StoreBasetypeno test imports ittype StoreBase = {
/** What the store is called in a finding. */
readonly id: string;
/** Where it is. */
readon… (478 characters)type StoreBase = {
/** What the store is called in a finding. */
readonly id: string;
/** Where it is. */
readonly place: Place;
readonly consistency: Consistency;
readonly traits: Traits;
/** The capabilities it has, as a set a program can read; the type says the same at compile time. */
readonly capabilities: ReadonlySet<Capability>;
/** Every operation goes through here, after the check that the store has what it needs. */
readonly handle: Handler;
};What every store has, whatever its capabilities.
Storetypetype Store<C extends Capability> = StoreBase & UnionToIntersection<{ [K in C]: Group<K, C> }[C]> & { readonly "@anyfs/capabilities"?: (capability: C) => void };A store with the capabilities C: it has their methods and no other. The optional marker is a function of C and never present at run time: it lets the compiler read C back from a store (so that readOnly(store) of a store in memory is a store of the capabilities of memory) and keeps a store of more capabilities assignable to a store of fewer.
AnyStoretypeno test imports ittype AnyStore = StoreBase;Any store, whatever its capabilities: what a function that only handles operations takes.
StoreSpectypeno test imports ittype StoreSpec<C extends OpCapability> = {
readonly id: string;
readonly place: Place;
readonly consistency: Consistency;
readonly traits: Traits;
readonly capabilities: readonly C[];
readonly handle: Handler;
};What a store is made from.
hasOperationconstno test imports itconst hasOperation: (c: "append" | "batch" | "cas" | "delete" | "history" | "list" | "lock" | "merge" | "rangeRead" | "read" | "rename" | "search" | "stat" | "watch" | "write") => c is OpCapabilityWhether a capability has an operation.
opCapabilitiesOfconstno test imports itconst opCapabilitiesOf: (store: StoreBase) => readonly OpCapability[]The capabilities of a store that have an operation.
capabilitiesWithoutfunctionno test imports itfunction capabilitiesWithout<C extends Capability, D extends Capability>(store: Store<C>, dropped: readonly D[]): readonly Exclude<C, "lock" | "watch" | D>[]The capabilities of a store of C that are carried and are not in dropped, typed as the type says: the same fact as the set of the store, with some taken away.
Carriedtypeno test imports ittype Carried<C extends Capability> = Exclude<C, "watch" | "lock">;What a layer or an attenuation keeps of a store of C: every capability but watch and lock, which have no operation to carry.
carriedCapabilitiesfunctionno test imports itfunction carriedCapabilities<C extends Capability>(store: Store<C>): readonly Exclude<C, "lock" | "watch">[]The capabilities of a store of C that are carried, typed as the type says. The type of a store is its set, so the cast is the same fact.
makeStorefunctionfunction makeStore<C extends OpCapability>(spec: StoreSpec<C>): Store<C>The store of its capabilities, made from a handler: it has exactly their methods, checks before each operation that it has what the operation needs, and never throws.
supportsfunctionfunction supports<C extends Capability, D extends Capability>(store: Store<C>, ...needed: readonly D[]): store is StoreBase & UnionToIntersection<{ [K in C]: Group<K, C>; }[C]> & { readonly "@anyfs/capabilities"?: ((capability: C) => void) | undefined; } & UnionToIntersection<{ [K in D]: Group<K, D>; }[D]> & { readonly "@anyfs/capabilities"?: ((capability: D) => void) | undefined; }Narrows a store to more capabilities where its set has them: the compiler then lets the caller use their methods.