import { syscall } from "../syscall.ts"; import type { CommandDef } from "../types/manifest.ts"; import type { SyscallMeta } from "@silverbulletmd/silverbullet/type/index"; /** * System level syscalls * @module */ /** * Invoke a plug function * @param name a string representing the name of the function to invoke ("plug.functionName") * @param args arguments to pass to the function * @returns */ export function invokeFunction(name: string, ...args: any[]): Promise { return syscall("system.invokeFunction", name, ...args); } /** * Invoke a client command by name * Note: only available on the client * @param name name of the command * @param args arguments to pass to the command */ export function invokeCommand(name: string, args?: string[]): Promise { return syscall("system.invokeCommand", name, args); } /** * Lists all commands available * @returns a map of all available commands */ export function listCommands(): Promise> { return syscall("system.listCommands"); } /** * Lists all syscalls available * @returns a list of all available syscalls */ export function listSyscalls(): Promise { return syscall("system.listSyscalls"); } /** * Trigger a reload of all plugs * @returns */ export function reloadPlugs(): Promise { return syscall("system.reloadPlugs"); } /** * Make edited-on-disk state live and wait until the client is ready again. */ export function reboot(): Promise { return syscall("system.reboot"); } /** * Load (or reload) a single plug from a space file path. */ export function loadPlug(path: string): Promise { return syscall("system.loadPlug", path); } /** * Unload a plug previously loaded from the given space file path. * Returns true if a plug was unloaded. */ export function unloadPlug(path: string): Promise { return syscall("system.unloadPlug", path); } /** * Returns the current mode of the system, either "ro" (read-only) or "rw" (read-write) */ export function getMode(): Promise<"ro" | "rw"> { return syscall("system.getMode"); } /** * Returns the prefix set by SB_URL_PREFIX or "/" if the variable isn't set */ export function getURLPrefix(): Promise { return syscall("system.getURLPrefix"); } /** * Returns the base URI for this SilverBullet isntance */ export function getBaseURI(): Promise { return syscall("system.getBaseURI"); } /** * Returns the SilverBullet version */ export function getVersion(): Promise { return syscall("system.getVersion"); } export function getConfig( key: string, defaultValue: any = undefined, ): Promise { return syscall("system.getConfig", key, defaultValue); } export function wipeClient(logout = false): Promise { return syscall("system.wipeClient", logout); } /** * DEPRECATED * Deletes all IndexedDB databases that are not connected to client (e.g. legacy databases) */ export function cleanDatabases(): Promise { return syscall("system.cleanDatabases"); }