UNPKG

@x5e/gink

Version:

an eventually consistent database

61 lines (60 loc) 2.92 kB
import { Container } from "./Container"; import { Value, Muid, ScalarKey, AsOf, StorageKey } from "./typedefs"; import { Bundler } from "./Bundler"; import { Addressable } from "./Addressable"; export declare class Keyed<GenericType extends ScalarKey | Addressable | [Addressable, Addressable]> extends Container { /** * Sets a key/value association in a directory. * If a bundler is supplied, the function will add the entry to that bundler * and return immediately (you'll need to addBundler manually in that case). * If the caller does not supply a bundler, then one is created on the fly, and * then this method will await on the bundler being added to the database instance. * This is to allow simple console usage like: * await myDirectory.set("foo", "bar"); * @param key * @param value * @param change an optional bundler to put this in. * @returns a promise that resolves to the address of the newly created entry */ set(key: GenericType, value: Value | Container, change?: Bundler | string): Promise<Muid>; /** * Adds a deletion marker (tombstone) for a particular key in the directory. * The corresponding value will be seen to be unset in the data model. * @param key * @param change an optional bundler to put this in. * @returns a promise that resolves to the address of the newly created deletion entry */ delete(key: GenericType, change?: Bundler | string): Promise<Muid>; /** * Returns a promise that resolves to the most recent value set for the given key, or undefined. * @param key * @param asOf * @returns undefined, a basic value, or a container */ get(key: GenericType, asOf?: AsOf): Promise<Container | Value | undefined>; size(asOf?: AsOf): Promise<number>; has(key: GenericType, asOf?: AsOf): Promise<boolean>; reset(args?: { toTime?: AsOf; bundlerOrComment?: Bundler | string; skipProperties?: boolean; recurse?: boolean; seen?: Set<string>; }): Promise<void>; /** * Dumps the contents of this directory into a javascript Map; mostly useful for * debugging though also could be used to create a backup of a database. * @param asOf effective time to get the dump for, or undefined for the present * @returns a javascript map from keys (numbers or strings) to values or containers */ toMap(asOf?: AsOf): Promise<Map<StorageKey, Value | Container>>; /** * Generates a JSON representation of the data in this container. * Mostly intended for demo/debug purposes. * @param indent true to pretty print * @param asOf effective time * @param seen (internal use only! This prevents cycles from breaking things) * @returns a JSON string */ toJson(indent?: number | boolean, asOf?: AsOf, seen?: Set<string>): Promise<string>; }