@fireproof/database
Version:
Live database for the web
57 lines (56 loc) • 2.04 kB
TypeScript
import type { Block, Link } from 'multiformats';
import { ProllyNode as BaseNode } from 'prolly-trees/base';
import { AnyLink, DocUpdate, MapFn, DocFragment, BlockFetcher, IndexKey, IndexUpdate, QueryOpts, IndexRow } from './types';
import { Transaction } from './transaction';
import { CRDT } from './crdt';
export declare class IndexTree {
cid: AnyLink | null;
root: ProllyNode | null;
}
export declare const byKeyOpts: StaticProllyOptions;
export declare const byIdOpts: StaticProllyOptions;
export declare function indexEntriesForChanges(changes: DocUpdate[], mapFn: MapFn): {
key: [string, string];
value: DocFragment;
}[];
export declare function bulkIndex(tblocks: Transaction, inIndex: IndexTree, indexEntries: IndexUpdate[], opts: StaticProllyOptions): Promise<IndexTree>;
export declare function loadIndex(tblocks: BlockFetcher, cid: AnyLink, opts: StaticProllyOptions): Promise<ProllyNode>;
export declare function applyQuery(crdt: CRDT, resp: {
result: IndexRow[];
}, query: QueryOpts): Promise<{
rows: IndexRow[];
}>;
export declare function encodeRange(range: [DocFragment, DocFragment]): [IndexKey, IndexKey];
export declare function encodeKey(key: string): string;
export interface ProllyNode extends BaseNode {
getAllEntries(): PromiseLike<{
[x: string]: any;
result: IndexRow[];
}>;
getMany(removeIds: string[]): Promise<{
[x: string]: any;
result: IndexKey[];
}>;
range(a: IndexKey, b: IndexKey): Promise<{
result: IndexRow[];
}>;
get(key: string): Promise<{
result: IndexRow[];
}>;
bulk(bulk: IndexUpdate[]): PromiseLike<{
root: ProllyNode | null;
blocks: Block[];
}>;
address: Promise<Link>;
distance: number;
compare: (a: any, b: any) => number;
cache: any;
block: Promise<Block>;
}
export interface StaticProllyOptions {
cache: any;
chunker: (entry: any, distance: number) => boolean;
codec: any;
hasher: any;
compare: (a: any, b: any) => number;
}