UNPKG

@constl/bohr-db

Version:

Type-safe databases for OrbitDB.

24 lines 935 B
import type { JSONSchemaType } from "ajv"; import type { KeyValueDatabase } from "@orbitdb/core"; import type { DBElements } from "./types.ts"; export type TypedKeyValue<T extends { [clef: string]: unknown; }> = Omit<KeyValueDatabase, "put" | "set" | "del" | "get" | "all"> & { put<K extends Extract<keyof T, string>>(key: K, value: T[K]): Promise<string>; set: TypedKeyValue<T>["put"]; del<K extends Extract<keyof T, string>>(key: K): Promise<string>; get<K extends Extract<keyof T, string>>(key: K): Promise<T[K] | undefined>; all: () => Promise<{ key: Extract<keyof T, string>; value: T[keyof T]; hash: string; }[]>; allAsJSON(): Promise<T>; }; export declare const typedKeyValue: <T extends { [clef: string]: DBElements; }>({ db, schema, }: { db: KeyValueDatabase; schema: JSONSchemaType<Partial<T>>; }) => TypedKeyValue<T>; //# sourceMappingURL=keyvalue.d.ts.map