UNPKG

@x5e/gink

Version:

an eventually consistent database

71 lines (70 loc) 3.69 kB
import { Database } from "./Database"; import { Container } from "./Container"; import { AsOf, Muid, Value, Meta } from "./typedefs"; /** * Kind of like the Gink version of a Javascript Array; supports push, pop, shift. * Doesn't support unshift because order is defined by insertion order. */ export declare class Sequence extends Container { private constructor(); static get(database?: Database, muid?: Muid): Sequence; static create(database?: Database, meta?: Meta): Promise<Sequence>; /** * Adds an element to the end of the list. * @param value * @param change change set to apply the change to or comment to put in * @returns */ push(value: Value | Container, meta?: Meta): Promise<Muid>; move(what: number | Muid, dest: number, purge?: boolean, meta?: Meta): Promise<void>; reset(toTime?: AsOf, recurse?: any, meta?: Meta): Promise<void>; private findDest; pop(what?: Muid | number, purge?: boolean, meta?: Meta): Promise<Container | Value | undefined>; /** * Alias for this.pop with position of 0 */ shift(purge?: boolean, meta?: Meta): Promise<Container | Value | undefined>; /** * Adds multiple entries into this sequence. * NOTE: If you pass a bundler, all changes will share the same timestamp. This means you will * not be able to move new entries in between these (you may move these entries between one another). * Without a bundler, each item from the iterable will be committed separately, which will be costly, * but there won't be the same restrictions on moving. * @param iterable An iterable of stuff to add to the sequence. * @param meta optional place to pass in a comment or bundler */ extend(iterable: Iterable<Value | Container>, meta?: Meta): Promise<void>; private getEntryAt; /** * * @param position Index to look for the thing, negative counts from end, or muid of entry * @param asOf * @returns value at the position of the list, or undefined if list is too small */ at(position: number, asOf?: AsOf): Promise<Container | Value | undefined>; /** * Dumps the contents of this list to a javascript array. * useful for debugging and could also be used to export data by walking the tree * @param through how many elements to get, positive starting from beginning, negative starting from end * @param asOf effective time to get the dump for: leave undefined to get data as of the present * @returns an array containing Values (e.g. numbers, strings) and Containers (e.g. other Lists, Boxes, Directories) */ toArray(through?: number, asOf?: AsOf): Promise<(Container | Value)[]>; size(asOf?: AsOf): Promise<number>; /** * Function to iterate over the contents of the List, showing the address of each entry (which can be used in pop). * @param through count of many things to iterate through, positive starting from front, negative for end * @param asOf effective time to get the contents for * @returns an async iterator across everything in the list, with values returned being pairs of Muid, (Value|Container), */ entries(through?: number, asOf?: AsOf): AsyncGenerator<[Muid, Value | Container], void, unknown>; /** * Generates a JSON representation of the data in the list. * 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>; }