UNPKG

@constl/bohr-db

Version:

Type-safe databases for orbit-db.

24 lines (23 loc) 848 B
import type { JSONSchemaType } from "ajv"; import type { KeyValueDatabase } from "@orbitdb/core"; import type { DBElements } from "./types.js"; export type TypedKeyValue<T extends { [clef: string]: unknown; }> = Omit<KeyValueDatabase, "put" | "set" | "del" | "get" | "all"> & { put<K extends keyof T>(key: K, value: T[K]): Promise<string>; set: TypedKeyValue<T>["put"]; del<K extends keyof T>(key: K): Promise<string>; get<K extends keyof T>(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>;