import type { KV, KvQuery, ObjectQuery, ObjectValue, } from "../../plug-api/types.ts"; import { ttlCache } from "$lib/memory_cache.ts"; import { system } from "@silverbulletmd/silverbullet/syscalls"; export function indexObjects( page: string, objects: ObjectValue[], ): Promise { return system.invokeFunction("index.indexObjects", page, objects); } export function batchSet(page: string, kvs: KV[]): Promise { return system.invokeFunction("index.batchSet", page, kvs); } export function query( query: KvQuery, ): Promise { return system.invokeFunction("index.query", query); } export function queryObjects( tag: string, query: ObjectQuery, ttlSecs?: number, ): Promise[]> { return ttlCache( query, () => system.invokeFunction("index.queryObjects", tag, query), ttlSecs, // no-op when undefined ); } export function getObjectByRef( page: string, tag: string, ref: string, ): Promise { return system.invokeFunction("index.getObjectByRef", page, tag, ref); }