UNPKG

@x5e/gink

Version:

an eventually consistent database

85 lines (84 loc) 4.38 kB
import { Database } from "./Database"; import { Container } from "./Container"; import { AsOf, Muid, Value } from "./typedefs"; import { Bundler } from "./Bundler"; import { ContainerBuilder } from "./builders"; /** * 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 { constructor(database: Database, address?: Muid, containerBuilder?: ContainerBuilder); /** * 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, change?: Bundler | string): Promise<Muid>; move(muidOrPosition: Muid | number, dest: number, purge?: boolean, bundlerOrComment?: Bundler | string): Promise<void>; reset(args?: { toTime?: AsOf; bundlerOrComment?: Bundler | string; skipProperties?: boolean; recurse?: boolean; seen?: Set<string>; }): Promise<void>; private findDest; /** * Removes and returns the specified entry of the list (default last), * in the provided change set or immediately if no CS is supplied. * Returns undefined when called on an empty list (and no changes are made). * @param what - position or Muid, defaults to last * @param purge - If true, removes so data cannot be recovered with "asOf" query * @param bundlerOrComment */ pop(what?: Muid | number, purge?: boolean, bundlerOrComment?: Bundler | string): Promise<Container | Value | undefined>; /** * Alias for this.pop(0, purge, bundlerOrComment) */ shift(purge?: boolean, bundlerOrComment?: Bundler | string): 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 bundlerOrComment A bundler or comment for these changes */ extend(iterable: Iterable<Value | Container>, bundlerOrComment?: Bundler | string): 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>; }