import { check_type } from "../util/type_check"; import type { DocumentBody, Document, QueryListOption } from "dbtype/api"; export const MetaContentBody = { title: "string", content_type: "string", basepath: "string", filename: "string", content_hash: "string", additional: "object", tags: "string[]", }; export const isDocBody = (c: unknown): c is DocumentBody => { return check_type(c, MetaContentBody); }; export const isDoc = (c: unknown): c is Document => { if (typeof c !== "object" || c === null) return false; if ("id" in c && typeof c.id === "number") { const { id, ...rest } = c; return isDocBody(rest); } return false; }; export interface DocumentAccessor { /** * find list by option * @returns documents list */ findList: (option?: QueryListOption) => Promise; /** * @returns document if exist, otherwise undefined */ findById: (id: number, tagload?: boolean) => Promise; /** * find by base path and filename. * if you call this function with filename, its return array length is 0 or 1. */ findByPath: (basepath: string, filename?: string) => Promise; /** * find deleted content */ findDeleted: (content_type: string) => Promise; /** * search by in document */ search: (search_word: string) => Promise; /** * update document except tag. */ update: (c: Partial & { id: number }) => Promise; /** * add document */ add: (c: DocumentBody) => Promise; /** * add document list */ addList: (content_list: DocumentBody[]) => Promise; /** * delete document * @returns if it exists, return true. */ del: (id: number) => Promise; /** * @param c Valid Document * @param tagname tag name to add * @returns if success, return true */ addTag: (c: Document, tag_name: string) => Promise; /** * @returns if success, return true */ delTag: (c: Document, tag_name: string) => Promise; }