Files
plainleaf/plug-api/syscalls/system.ts
T

122 lines
3.0 KiB
TypeScript

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<any> {
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<any> {
return syscall("system.invokeCommand", name, args);
}
/**
* Lists all commands available
* @returns a map of all available commands
*/
export function listCommands(): Promise<Record<string, CommandDef>> {
return syscall("system.listCommands");
}
/**
* Lists all syscalls available
* @returns a list of all available syscalls
*/
export function listSyscalls(): Promise<SyscallMeta[]> {
return syscall("system.listSyscalls");
}
/**
* Trigger a reload of all plugs
* @returns
*/
export function reloadPlugs(): Promise<void> {
return syscall("system.reloadPlugs");
}
/**
* Make edited-on-disk state live and wait until the client is ready again.
*/
export function reboot(): Promise<void> {
return syscall("system.reboot");
}
/**
* Load (or reload) a single plug from a space file path.
*/
export function loadPlug(path: string): Promise<void> {
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<boolean> {
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<string> {
return syscall("system.getURLPrefix");
}
/**
* Returns the base URI for this SilverBullet isntance
*/
export function getBaseURI(): Promise<string> {
return syscall("system.getBaseURI");
}
/**
* Returns the SilverBullet version
*/
export function getVersion(): Promise<string> {
return syscall("system.getVersion");
}
export function getConfig<T = any>(
key: string,
defaultValue: any = undefined,
): Promise<T> {
return syscall("system.getConfig", key, defaultValue);
}
export function wipeClient(logout = false): Promise<void> {
return syscall("system.wipeClient", logout);
}
/**
* DEPRECATED
* Deletes all IndexedDB databases that are not connected to client (e.g. legacy databases)
*/
export function cleanDatabases(): Promise<boolean> {
return syscall("system.cleanDatabases");
}