1
0
silverbullet/plugos/syscalls/store.ts

55 lines
1.2 KiB
TypeScript
Raw Normal View History

import { SysCallMapping } from "../system.ts";
2023-08-04 16:56:55 +00:00
import { KV, KVStore } from "../lib/kv_store.ts";
2022-03-25 11:03:06 +00:00
export function storeSyscalls(
2023-08-04 16:56:55 +00:00
db: KVStore,
2022-03-25 11:03:06 +00:00
): SysCallMapping {
return {
"store.delete": (_ctx, key: string) => {
return db.del(key);
2022-03-25 11:03:06 +00:00
},
"store.deletePrefix": (_ctx, prefix: string) => {
return db.deletePrefix(prefix);
2022-03-25 11:03:06 +00:00
},
"store.deleteAll": () => {
return db.deleteAll();
2022-03-25 11:03:06 +00:00
},
"store.set": (_ctx, key: string, value: any) => {
return db.set(key, value);
},
"store.batchSet": (_ctx, kvs: KV[]) => {
return db.batchSet(kvs);
},
"store.batchDelete": (_ctx, keys: string[]) => {
return db.batchDelete(keys);
},
"store.batchGet": (
_ctx,
keys: string[],
): Promise<(any | undefined)[]> => {
return db.batchGet(keys);
2022-03-25 11:03:06 +00:00
},
"store.get": (_ctx, key: string): Promise<any | null> => {
return db.get(key);
2022-03-25 11:03:06 +00:00
},
"store.has": (_ctx, key: string): Promise<boolean> => {
return db.has(key);
2022-03-25 11:03:06 +00:00
},
"store.queryPrefix": (
_ctx,
keyPrefix: string,
): Promise<{ key: string; value: any }[]> => {
return db.queryPrefix(keyPrefix);
2022-03-25 11:03:06 +00:00
},
};
}