1
0
silverbullet/plugs/index/plug_api.ts
Zef Hemel a2dbf7b3db
PlugOS refactor and other tweaks (#631)
* Prep for in-process plug loading (e.g. for CF workers, Deno Deploy)
* Prototype of fixed in-process loading plugs
* Fix: buttons not to scroll with content
* Better positioning of modal especially on mobile
* Move query caching outside query
* Fix annoying mouse behavior when filter box appears
* Page navigator search tweaks
2024-01-15 16:43:12 +01:00

41 lines
1020 B
TypeScript

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