silverbullet/plugs/index/plug_api.ts

46 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2024-07-30 23:24:17 +08:00
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<T>(
page: string,
objects: ObjectValue<T>[],
): Promise<void> {
return system.invokeFunction("index.indexObjects", page, objects);
}
2023-10-03 21:24:07 +08:00
export function batchSet(page: string, kvs: KV[]): Promise<void> {
return system.invokeFunction("index.batchSet", page, kvs);
2023-10-03 21:24:07 +08:00
}
export function query(
query: KvQuery,
): Promise<KV[]> {
return system.invokeFunction("index.query", query);
2023-10-03 21:24:07 +08:00
}
export function queryObjects<T>(
tag: string,
query: ObjectQuery,
ttlSecs?: number,
): Promise<ObjectValue<T>[]> {
return ttlCache(
query,
() => system.invokeFunction("index.queryObjects", tag, query),
ttlSecs, // no-op when undefined
);
}
export function getObjectByRef<T>(
page: string,
tag: string,
ref: string,
2023-11-06 16:14:16 +08:00
): Promise<T | undefined> {
return system.invokeFunction("index.getObjectByRef", page, tag, ref);
}