@x5e/gink
Version:
an eventually consistent database
55 lines (54 loc) • 2.4 kB
TypeScript
import { Database } from "./Database";
import { Container } from "./Container";
import { Value, Muid, AsOf } from "./typedefs";
import { Bundler } from "./Bundler";
import { ContainerBuilder } from "./builders";
export declare class Box extends Container {
constructor(database: Database, address: Muid, containerBuilder?: ContainerBuilder);
/**
* Puts a value or a reference to another container in this box.
* 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 myBox.put("some value");
* @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(value: Value | Container, change?: Bundler | string): Promise<Muid>;
/**
* Returns a promise that resolves to the most recent value put in the box, or undefined.
* @returns undefined, a basic value, or a container
*/
get(asOf?: AsOf): Promise<Container | Value | undefined>;
/**
* checks to see how many things are in the box (will be either 0 or 1)
* @param asOf Historical time to look
* @returns 0 or 1 depending on whether there's something in the box.
*/
size(asOf?: AsOf): Promise<number>;
reset(args?: {
toTime?: AsOf;
bundlerOrComment?: Bundler | string;
skipProperties?: boolean;
recurse?: boolean;
seen?: Set<string>;
}): Promise<void>;
/**
* checks to see if something is in the box
* @param asOf
* @returns true if no value or container is in the box
*/
isEmpty(asOf?: AsOf): Promise<boolean>;
/**
* Generates a JSON representation of the data in the box (the box itself is transparent).
* Mostly intended for demo/debug purposes.
* @param indent true to pretty print
* @param asOf effective time
* @param seen (internal use only! Prevent cycles from breaking things)
* @returns a JSON string
*/
toJson(indent?: number | boolean, asOf?: AsOf, seen?: Set<string>): Promise<string>;
}