silverbullet/common/syscalls/index.ts

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2025-01-17 17:41:02 +08:00
import type {
KvQuery,
ObjectQuery,
ObjectValue,
} from "@silverbulletmd/silverbullet/types";
import type { SysCallMapping, System } from "$lib/plugos/system.ts";
import type { LuaCollectionQuery } from "$common/space_lua/query_collection.ts";
// These are just wrappers around the system.invokeFunction calls, but they make it easier to use the index
export function indexSyscalls(system: System<any>): SysCallMapping {
return {
2025-01-18 01:31:17 +08:00
"index.indexObjects": (ctx, page: string, objects: ObjectValue<any>[]) => {
return system.syscall(ctx, "system.invokeFunction", [
"index.indexObjects",
page,
objects,
]);
2025-01-17 17:41:02 +08:00
},
"index.queryObjects": (
2025-01-18 01:31:17 +08:00
ctx,
2025-01-17 17:41:02 +08:00
tag: string,
query: ObjectQuery,
ttlSecs?: number,
) => {
2025-01-18 01:31:17 +08:00
return system.syscall(ctx, "system.invokeFunction", [
"index.queryObjects",
2025-01-17 17:41:02 +08:00
tag,
query,
ttlSecs,
]);
},
"index.queryLuaObjects": (
2025-01-18 01:31:17 +08:00
ctx,
2025-01-17 17:41:02 +08:00
tag: string,
query: LuaCollectionQuery,
scopedVariables?: Record<string, any>,
) => {
2025-01-18 01:31:17 +08:00
return system.syscall(ctx, "system.invokeFunction", [
2025-01-17 17:41:02 +08:00
"index.queryLuaObjects",
2025-01-18 01:31:17 +08:00
tag,
query,
scopedVariables,
]);
2025-01-17 17:41:02 +08:00
},
2025-01-18 01:31:17 +08:00
"index.queryDeleteObjects": (ctx, tag: string, query: ObjectQuery) => {
return system.syscall(ctx, "system.invokeFunction", [
"index.queryDeleteObjects",
tag,
query,
]);
2025-01-17 17:41:02 +08:00
},
2025-01-18 01:31:17 +08:00
"index.query": (ctx, query: KvQuery, variables?: Record<string, any>) => {
return system.syscall(ctx, "system.invokeFunction", [
"index.query",
query,
variables,
]);
2025-01-17 17:41:02 +08:00
},
2025-01-18 01:31:17 +08:00
"index.getObjectByRef": (ctx, page: string, tag: string, ref: string) => {
return system.syscall(ctx, "system.invokeFunction", [
"index.getObjectByRef",
page,
tag,
ref,
]);
2025-01-17 17:41:02 +08:00
},
};
}