1
0
silverbullet/plugos/types.ts

55 lines
2.0 KiB
TypeScript
Raw Normal View History

import { System } from "./system.ts";
2022-10-12 09:47:13 +00:00
import { AssetJson } from "./asset_bundle/bundle.ts";
/** The generic top level of a plug manifest file.
* Defines plug metadata and functions.
*/
export interface Manifest<HookT> {
/** The plug's name. Typically this is the name of the manifest file, without the file extension. */
2022-04-26 17:04:36 +00:00
name: string;
/** A list of syscall permissions required for this plug to function.
2023-08-27 12:13:18 +00:00
*
* Possible values:
* - `fetch`: enables `fetch` function. (see: plug-api/plugos-syscall/fetch.ts, and plug-api/lib/fetch.ts)
* - `shell`: enables the `shell.run` syscall. (see: plug-api/plugos-syscall/shell.ts)
*/
2022-03-25 11:03:06 +00:00
requiredPermissions?: string[];
/** A list of files or glob patterns that should be bundled with the plug.
2023-08-27 12:13:18 +00:00
*
* These files will be accessible through the `asset.readAsset` function.
2023-08-27 12:13:18 +00:00
*
* see: plug-api/plugos-syscall/asset.ts#readAsset
*/
2022-10-12 09:47:13 +00:00
assets?: string[] | AssetJson;
/** A map of function names to definitions. Declared functions are public, and may be associated with various hooks
2023-08-27 12:13:18 +00:00
*
* see: common/manifest.ts#SilverBulletHooks
*/
2023-08-27 12:13:18 +00:00
functions: Record<string, FunctionDef<HookT>>;
}
/** Associates hooks with a function. This is the generic base structure, that identifies the function. Hooks are defined by the type parameter. */
2022-03-27 09:26:13 +00:00
export type FunctionDef<HookT> = {
/** A function path, in the form `${relativeFilename}:${functionName}`.
2023-08-27 12:13:18 +00:00
*
* During compilation (see `../build_plugs.ts`) the function is read from the file and inlined into the plug bundle.
2023-08-27 12:13:18 +00:00
*
* This field and `FunctionDef.redirect` are mutually exclusive.
*/
path?: string;
/** A function from another plug, in the form `${plugName}.${functionName}` that will be attached to the given hooks. */
redirect?: string;
/** Environments where this plug is allowed to run, current may be one of "cli", "server", or "client". */
2023-08-04 16:56:55 +00:00
env?: string;
2022-03-27 09:26:13 +00:00
} & HookT;
export interface Hook<HookT> {
2022-03-23 14:41:12 +00:00
validateManifest(manifest: Manifest<HookT>): string[];
apply(system: System<HookT>): void;
}