UNPKG

@x5e/gink

Version:

an eventually consistent database

89 lines (88 loc) 3.7 kB
import { AbstractConnection } from "./AbstractConnection"; import { BundleListener, CallBack, BundleInfo, Muid, AsOf, KeyPair, Medallion, Meta, Bundler, Connection } from "./typedefs"; import { HasMap } from "./HasMap"; import { Store } from "./Store"; import { PromiseChainLock } from "./PromiseChainLock"; import { inspectSymbol } from "./utils"; import { Directory } from "./Directory"; /** * This is an instance of the Gink database that can be run inside a web browser or via * ts-node on a server. Because of the need to work within a browser it doesn't do any port * listening (see SimpleServer for that capability). */ export declare class Database { ready: Promise<any>; readonly connections: Map<number, AbstractConnection>; readonly connectionsByEndpoint: Map<string, AbstractConnection>; private listeners; private countConnections; private identity?; protected iHave: HasMap; private static lastCreated?; readonly store: Store; protected logger: CallBack; protected promiseChainLock: PromiseChainLock; protected medallion?: Medallion; protected keyPair?: KeyPair; protected lastLink?: BundleInfo; constructor(args?: { store?: Store; logger?: CallBack; identity?: string; }); [inspectSymbol](depth: any, opts: any): string; toString(): string; getRoot(): Directory; getLastLink(): BundleInfo | undefined; static get recent(): Database; private initialize; private completeBundle; startBundle(meta?: Meta): Promise<Bundler>; private obtainMedallion; reset(toTime?: AsOf, meta?: Meta): Promise<void>; /** * Adds a listener that will be called every time a bundle is received with the * BundleInfo (which contains chain information, timestamp, and bundle comment). * @param listener a callback to be invoked when a change occurs in the database or container * @param containerMuid the Muid of a container to subscribe to. If left out, subscribe to all containers. */ addListener(listener: BundleListener, containerMuid?: Muid, remoteOnly?: boolean): () => void; /** * Gets a list of bundle listeners per container, listening to all bundles or just remote. * @param remoteOnly true if looking for listeners only subscribed to remote bundles. * @param containerMuid optional container muid to find listeners subscribed to a specific container. */ private getListeners; /** * Closes connections to peers and closes the store. */ close(): Promise<void>; /** * @returns a truthy number that can be used to identify connections */ protected createConnectionId(): number; /** * Tries to add a bundle to the local store. If successful (i.e. it hasn't seen it before) * then it will also publish that bundle to the connected peers. * * This is called both from addPendingBundle (for locally produced bundles) and * being called by receiveMessage. * * @param bundleBytes The bytes that correspond to this transaction. * @param fromConnectionId The (truthy) connectionId if it came from a peer. * @returns */ private receiveBundle; /** * @param messageBytes Bytes received from a peer. * @param fromConnectionId Local name of the peer the data was received from. * @returns */ protected receiveMessage(messageBytes: Uint8Array, fromConnectionId: number): Promise<void>; protected onConnectionOpen(connectionId: number): void; connectTo(endpoint: string, options?: { authToken?: string; reconnectOnClose?: boolean; onError?: CallBack; }): Connection; }