UNPKG

@braindb/core

Version:

markdown-graph-content-layer-database

97 lines (96 loc) 2.85 kB
import { WildcardHandler } from "mitt"; import { Document } from "./Document.js"; import { Link } from "./Link.js"; import { DocumentsOtions, SortDirection } from "./query.js"; import { Task } from "./Task.js"; type Events = { update: { document: Document; }; delete: { document: Document; }; create: { document: Document; }; ready: void; }; export { Document, DocumentsOtions, SortDirection, Task, Link }; export type Frontmatter = Record<string, unknown>; export type BrainDBOptionsIn = { /** * If `dbPath` is present, than DB would be persited to the disc and used as cache on the next run */ dbPath?: string; /** * Even if `dbPath` is absent, and DB stored in memory it can be long runing process and cache can be used */ cache?: boolean; /** * function to generate path (URL) a the document */ url?: (filePath: string, frontmatter: Frontmatter) => string; /** * function to generate slug for a document */ slug?: (filePath: string, frontmatter: Frontmatter) => string; /** * root of the project */ root: string; /** * source files */ source?: string; /** * if `true` will use git date for `updated_at` field. * It will search for git repo in `root` or any parent directory */ git?: boolean; /** * if you never use Document's `markdown` and `text` * you can set this to `false` in order to save some memory */ storeMarkdown?: boolean; }; export type BrainDBOptionsOut = { linkType?: "PML" | "web"; /** * If output use PML, sometimes it may be required to adjust them to the new root */ transformPath?: (path: string) => string; transformFrontmatter?: (doc: Document) => Frontmatter; /** * experimental * @param path string * @param node mdast node * @returns undefined | mdast node */ transformUnresolvedLink?: (path: string, node: any) => any; }; export declare class BrainDB { private cfg; private emitter; private db; private watcher; private initializing; private initQueue; constructor(cfg: BrainDBOptionsIn); start(silent?: boolean): this; stop(): Promise<this>; on(type: "*", handler: WildcardHandler<Events>): this; off(type: "*", handler: WildcardHandler<Events>): this; ready(): Promise<unknown>; documentsSync(options?: DocumentsOtions): Document[]; documents(options?: DocumentsOtions): Promise<Document[]>; findDocumentSync(path: string): Document; findDocument(path: string): Promise<Document>; linksSync(): Link[]; links(): Promise<Link[]>; /** * TODO: filter by checked true/false */ tasksSync(): Task[]; tasks(): Promise<Task[]>; __rawQuery(query: string): unknown[]; }