2022-10-10 12:50:21 +00:00
|
|
|
import { SysCallMapping } from "../system.ts";
|
2023-05-23 18:53:53 +00:00
|
|
|
import { DexieKVStore } from "../lib/kv_store.dexie.ts";
|
|
|
|
import { KV } from "../lib/kv_store.ts";
|
2022-03-25 11:03:06 +00:00
|
|
|
|
|
|
|
export function storeSyscalls(
|
2023-05-23 18:53:53 +00:00
|
|
|
db: DexieKVStore,
|
2022-03-25 11:03:06 +00:00
|
|
|
): SysCallMapping {
|
|
|
|
return {
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.delete": (_ctx, key: string) => {
|
|
|
|
return db.del(key);
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.deletePrefix": (_ctx, prefix: string) => {
|
|
|
|
return db.deletePrefix(prefix);
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.deleteAll": () => {
|
|
|
|
return db.deleteAll();
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +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
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.get": (_ctx, key: string): Promise<any | null> => {
|
|
|
|
return db.get(key);
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.has": (_ctx, key: string): Promise<boolean> => {
|
|
|
|
return db.has(key);
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
|
2023-05-23 18:53:53 +00:00
|
|
|
"store.queryPrefix": (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
|
|
|
keyPrefix: string,
|
2022-04-03 16:42:12 +00:00
|
|
|
): Promise<{ key: string; value: any }[]> => {
|
2023-05-23 18:53:53 +00:00
|
|
|
return db.queryPrefix(keyPrefix);
|
2022-03-25 11:03:06 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|