UNPKG

@x5e/gink

Version:

an eventually consistent database

55 lines (54 loc) 2.68 kB
import { BundleInfo, Medallion, ChainStart, Muid } from "./typedefs"; /** * A class to keep track of what data a given instance (self or peer) has for each * chain. So it's kind of like Map<[Medallion, ChainStart], SeenThrough>. * This is essentially the same data that's in the Greeting message, so I've included * functionality to convert from/to Greeting objects. */ export declare class HasMap { private readonly data; private readonly waiters; constructor({ greetingBytes, greeting }: { greetingBytes?: any; greeting?: any; }); /** * Allows you to wait until an instance has seen a particular bundle. * @param what either a muid address or a bundle info (indicates what to watch for) * @param timeoutMs how long to wait before giving up, default of undefined doesn't time out * @returns a promise that resolves when the thing has been marked as seen, or rejects at timeout */ waitTillHas({ medallion, timestamp }: BundleInfo | Muid, timeoutMs?: number): Promise<void>; /** * First, determine if the bundle is novel (represents data not previously marked), * then second, mark the data in the data structure (possibly checking that it's a sensible extension). * Note that checkValidExtension is used here as a safeguard to make sure we don't * send broken chains to the peer; the store should have its own check for receiving. * @param bundleInfo Meta about a particular bundle. * @param checkValidExtension If true then barfs if this bundle isn't a valid extension. * @returns true if the bundle represents data not seen before */ markAsHaving(bundleInfo: BundleInfo, checkValidExtension?: boolean): boolean; /** * Constructs the greeting for use during the initial handshake. Note that * the priorTimes aren't included, so recipient should not markIfNovel using * @returns */ private constructGreeting; /** * @returns bytes that can be sent during the initial handshake */ getGreetingMessageBytes(): Uint8Array; /** * Returns how far along data is seen for a particular chain. * @param key A [Medallion, ChainStart] tuple * @returns SeenThrough (a Timestamp) or undefined if not yet seen */ getBundleInfo(key: [Medallion, ChainStart]): BundleInfo | undefined; /** * Gets a list of chains seen for a particular medallion, or a list of all seen chains * @param singleMedallion The single medallion to get chains for (returns all if undefined) * @returns a list of known chains */ getChains(singleMedallion?: Medallion): Array<[Medallion, ChainStart]>; }