@x5e/gink
Version:
an eventually consistent database
92 lines (91 loc) • 4.21 kB
TypeScript
import { Database } from "./Database";
import { Container } from "./Container";
import { ScalarKey, Muid, AsOf } from "./typedefs";
import { Bundler } from "./Bundler";
import { ContainerBuilder } from "./builders";
export declare class KeySet extends Container {
constructor(database: Database, address: Muid, containerBuilder?: ContainerBuilder);
/**
* 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, change?: Bundler | string): 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>, change?: Bundler | string): Promise<Bundler>;
/**
* 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, change?: Bundler | string): 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>;
/**
*
* @param args Optional arguments, including:
* @argument toTime Optional time to reset to. If absent, the container will be cleared.
* @argument bundlerOrComment Optional bundler or comment to add this change to
* @argument skipProperties If true, do not reset properties of this container. By default,
* all properties associated with this container will be reset to the time specified in toTime.
* @argument recurse NOTE: THIS FLAG IS IGNORED. Recursive reset for Inclusion-based containers
* is not yet implemented, but this arg needs to be accepted for other containers recursively
* resetting this one.
* @argument seen NOTE: THIS FLAG IS IGNORED. Recursive reset for Inclusion-based containers
* is not yet implemented, but this arg needs to be accepted for other containers recursively
* resetting this one.
*/
reset(args?: {
toTime?: AsOf;
bundlerOrComment?: Bundler | string;
skipProperties?: boolean;
recurse?: boolean;
seen?: Set<string>;
}): 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>;
}