2022-10-10 12:50:21 +00:00
|
|
|
import type { Query } from "../plugos-syscall/store.ts";
|
|
|
|
import { syscall } from "./syscall.ts";
|
2022-04-01 15:07:08 +00:00
|
|
|
|
|
|
|
export type KV = {
|
|
|
|
key: string;
|
|
|
|
value: any;
|
|
|
|
};
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function set(
|
2022-04-01 15:07:08 +00:00
|
|
|
page: string,
|
|
|
|
key: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
value: any,
|
2022-04-01 15:07:08 +00:00
|
|
|
): Promise<void> {
|
|
|
|
return syscall("index.set", page, key, value);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function batchSet(page: string, kvs: KV[]): Promise<void> {
|
2022-04-01 15:07:08 +00:00
|
|
|
return syscall("index.batchSet", page, kvs);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function get(page: string, key: string): Promise<any> {
|
2022-04-01 15:07:08 +00:00
|
|
|
return syscall("index.get", page, key);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function del(page: string, key: string): Promise<void> {
|
2022-04-01 15:07:08 +00:00
|
|
|
return syscall("index.delete", page, key);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function queryPrefix(
|
|
|
|
prefix: string,
|
2022-04-01 15:07:08 +00:00
|
|
|
): Promise<{ key: string; page: string; value: any }[]> {
|
2022-05-17 13:54:55 +00:00
|
|
|
return syscall("index.queryPrefix", prefix);
|
2022-04-01 15:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function query(
|
|
|
|
query: Query,
|
2022-04-01 15:07:08 +00:00
|
|
|
): Promise<{ key: string; page: string; value: any }[]> {
|
2022-05-17 13:54:55 +00:00
|
|
|
return syscall("index.query", query);
|
2022-04-01 15:07:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function clearPageIndexForPage(page: string): Promise<void> {
|
2022-04-01 15:07:08 +00:00
|
|
|
return syscall("index.clearPageIndexForPage", page);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function deletePrefixForPage(
|
2022-04-01 15:07:08 +00:00
|
|
|
page: string,
|
2022-10-10 12:50:21 +00:00
|
|
|
prefix: string,
|
2022-04-01 15:07:08 +00:00
|
|
|
): Promise<void> {
|
|
|
|
return syscall("index.deletePrefixForPage", page, prefix);
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
export function clearPageIndex(): Promise<void> {
|
2022-04-01 15:07:08 +00:00
|
|
|
return syscall("index.clearPageIndex");
|
|
|
|
}
|