UNPKG

@constl/bohr-db

Version:

Type-safe databases for OrbitDB.

25 lines 1.17 kB
import type { JSONSchemaType } from "ajv"; import type { OrderedKeyValueDatabaseType } from "@orbitdb/ordered-keyvalue-db"; import type { DBElements } from "./types.ts"; import type { DagCborEncodable } from "@orbitdb/core"; export type TypedOrderedKeyValue<T extends { [clef: string]: DagCborEncodable; }> = Omit<OrderedKeyValueDatabaseType, "put" | "set" | "del" | "move" | "get" | "all"> & { put: <K extends Extract<keyof T, string>>(key: K, value: T[K], position?: number) => Promise<string>; set: TypedOrderedKeyValue<T>["put"]; del: <K extends keyof T>(key: K) => Promise<string>; move: <K extends Extract<keyof T, string>>(key: K, position: number) => Promise<void>; 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; }[]>; }; export declare const typedOrderedKeyValue: <T extends { [clef: string]: DBElements; }>({ db, schema, }: { db: OrderedKeyValueDatabaseType; schema: JSONSchemaType<Partial<T>>; }) => TypedOrderedKeyValue<T>; //# sourceMappingURL=ordered-keyvalue.d.ts.map