UNPKG

@x5e/gink

Version:

an eventually consistent database

74 lines (73 loc) 4.03 kB
import { IDBPTransaction } from "idb"; import { AsOf, BroadcastFunc, Bytes, ChainStart, ClaimedChain, Entry, IndexedDbStoreSchema, ScalarKey, Medallion, Muid, MuidTuple, Removal, Timestamp, BundleView, KeyPair, Value, Placement } from "./typedefs"; import { ChainTracker } from "./ChainTracker"; import { Store } from "./Store"; type Transaction = IDBPTransaction<IndexedDbStoreSchema, ("trxns" | "chainInfos" | "activeChains" | "containers" | "removals" | "clearances" | "entries" | "identities" | "verifyKeys" | "secretKeys" | "symmetricKeys")[], "readwrite" | "readonly">; /** * Uses an indexedDb to implement the Store interface. On the server side, this will * be done using a shim that is only an in-memory implementation of the IndexedDb API, * so the LogBackedStore should be used on the server for persistence. Most of the time * uses of Gink should not need to call methods on the store directly, instead just * pass it into the Database (or SimpleServer, etc.). */ export declare class IndexedDbStore implements Store { private keepingHistory; ready: Promise<void>; private wrapped; private transaction; private countTrxns; private initialized; private processingLock; private lastCaller; private foundBundleCallBacks; private pending; private static readonly YEAR_2020; constructor(indexedDbName: string, reset?: boolean, keepingHistory?: boolean); private initialize; getVerifyKey(chainInfo: [Medallion, ChainStart]): Promise<Bytes>; saveKeyPair(keyPair: KeyPair): Promise<void>; pullKeyPair(publicKey: Bytes): Promise<KeyPair>; saveSymmetricKey(symmetricKey: Bytes): Promise<number>; getSymmetricKey(keyId: number, trxn?: Transaction): Promise<Bytes>; private clearTransaction; private getTransaction; getTransactionCount(): number; dropHistory(container?: Muid, before?: AsOf): Promise<void>; stopHistory(): Promise<void>; startHistory(): void; close(): Promise<void>; getLocation(entry: Muid, asOf?: AsOf): Promise<Placement | undefined>; private asOfToTimestamp; getClaimedChains(): Promise<Map<Medallion, ClaimedChain>>; getChainIdentity(chainInfo: [Medallion, ChainStart]): Promise<string>; private claimChain; getChainTracker(): Promise<ChainTracker>; private getChainInfos; addBundle(bundleView: BundleView, claimChain?: boolean): Promise<boolean>; private addBundleHelper; getContainerBytes(address: Muid): Promise<Bytes | undefined>; getEntryByKey(container?: Muid, key?: ScalarKey | Muid | [Muid, Muid], asOf?: AsOf): Promise<Entry | undefined>; getClearanceTime(trxn: Transaction, muidTuple: MuidTuple, asOfTs: Timestamp): Promise<Timestamp>; getKeyedEntries(container: Muid, asOf?: AsOf): Promise<Map<string, Entry>>; getEntriesBySourceOrTarget(vertex: Muid, source: boolean, asOf?: AsOf): Promise<Entry[]>; /** * Returns entry data for a List. Does it in a single pass rather than using an async generator * because if a user tried to await on something else between entries it would cause the IndexedDb * transaction to auto-close. * @param container to get entries for * @param through number to get, negative for starting from end * @param asOf show results as of a time in the past * @returns a promise of a list of ChangePairs */ getOrderedEntries(container: Muid, through?: number, asOf?: AsOf): Promise<Map<string, Entry>>; getEntryById(entryMuid: Muid, asOf?: AsOf): Promise<Entry | undefined>; getContainersByName(name: string, asOf?: AsOf): Promise<Muid[]>; getContainerProperties(containerMuid: Muid, asOf?: AsOf): Promise<Map<string, Value>>; getAllContainerTuples(): Promise<MuidTuple[]>; getAllEntryKeys(): Promise<MuidTuple[]>; getAllEntries(): Promise<Entry[]>; getAllRemovals(): Promise<Removal[]>; getBundles(callBack: (bundle: BundleView) => void): Promise<void>; addFoundBundleCallBack(callback: BroadcastFunc): void; } export {};