UNPKG

@x5e/gink

Version:

an eventually consistent database

49 lines (48 loc) 2.24 kB
import { Database } from "./Database"; import { Container } from "./Container"; import { Value, Muid, AsOf, Meta } from "./typedefs"; export declare class Box extends Container { private constructor(); static get(database?: Database, muid?: Muid): Box; static create(database?: Database, meta?: Meta): Promise<Box>; /** * 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, meta?: Meta): 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(toTime?: AsOf, recurse?: any, meta?: Meta): 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>; }