UNPKG

@fireproof/database

Version:
33 lines (32 loc) 1.01 kB
import { WriteQueue } from './write-queue'; import { CRDT } from './crdt'; import type { DocUpdate, ClockHead, Doc, FireproofOptions } from './types'; export declare class Database { static databases: Map<string, Database>; name: string; opts: FireproofOptions; _listeners: Set<ListenerFn>; _crdt: CRDT; _writeQueue: WriteQueue; constructor(name: string, opts?: FireproofOptions); get(id: string): Promise<Doc>; put(doc: Doc): Promise<DbResponse>; del(id: string): Promise<DbResponse>; changes(since?: ClockHead): Promise<ChangesResponse>; subscribe(listener: ListenerFn): () => void; _notify(updates: DocUpdate[]): Promise<void>; } type ChangesResponse = { clock: ClockHead; rows: { key: string; value: Doc; }[]; }; type DbResponse = { id: string; clock: ClockHead; }; type ListenerFn = (docs: Doc[]) => Promise<void> | void; export declare function database(name: string, opts?: FireproofOptions): Database; export {};