@x5e/gink
Version:
an eventually consistent database
72 lines (71 loc) • 3.13 kB
TypeScript
import { Database } from "./Database";
import { Container } from "./Container";
import { ScalarKey, Muid, AsOf, Meta } from "./typedefs";
export declare class KeySet extends Container {
private constructor();
static get(database?: Database, muid?: Muid): KeySet;
static create(database?: Database, meta?: Meta): Promise<KeySet>;
/**
* Adds a key to the keyset.
* If a bundler is supplied, the function will add the entry to that bundler
* and return immediately (presumably you know what to do with a CS if you passed it in).
* If the caller does not supply a bundler, then one is created on the fly, and
* then this method will await on the CS being added to the database instance.
* This is to allow simple console usage like:
* await myKeySet.add("foo");
* @param key
* @param change an optional bundler to put this in.
* @returns a promise that resolves to the address of the newly created entry
*/
add(key: ScalarKey, meta?: Meta): Promise<Muid>;
/**
* Similar to add method, but for multiple entries.
* @param keys an iterable of keys to add to the key set
* @param change an optional bundler to put this in.
* @returns a promise that resolves to a Bundler object for the created entries.
*/
update(keys: Iterable<ScalarKey>, meta?: Meta): Promise<void>;
/**
* 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: ScalarKey, meta?: Meta): Promise<Muid>;
/**
* Function to iterate over the contents of the key set.
* @param asOf
* @returns an async iterator across everything in the key set, with values returned as pairs of Key, Key
*/
entries(asOf?: AsOf): AsyncGenerator<[ScalarKey, ScalarKey], void, unknown>;
/**
* Returns whether the key set has a key or not.
* @param key
* @param asOf
* @returns true if the key set has the key, false if not.
*/
has(key: ScalarKey, asOf?: AsOf): Promise<boolean>;
reset(toTime?: AsOf, recurse?: any, meta?: Meta): Promise<void>;
/**
* Returns the contents of the key set as a set.
* @param asOf
* @returns a promise that resolves to a set with KeyTypes.
*/
toSet(asOf?: AsOf): Promise<Set<ScalarKey>>;
/**
* How many entries are in the key set.
* @param asOf
* @returns a promise that resolves to a number.
*/
size(asOf?: AsOf): Promise<number>;
/**
* Generates a JSON representation of the data in the key set.
* 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>;
}