2022-10-10 12:50:21 +00:00
|
|
|
import { System } from "./system.ts";
|
2022-10-12 09:47:13 +00:00
|
|
|
import { AssetJson } from "./asset_bundle/bundle.ts";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2023-08-20 05:24:17 +00:00
|
|
|
/** The generic top level of a plug manifest file.
|
|
|
|
* Defines plug metadata and functions.
|
|
|
|
*/
|
2022-03-20 08:56:28 +00:00
|
|
|
export interface Manifest<HookT> {
|
2023-08-20 05:24:17 +00:00
|
|
|
/** 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;
|
2023-08-20 05:24:17 +00:00
|
|
|
|
|
|
|
/** A list of syscall permissions required for this plug to function.
|
2023-08-27 12:13:18 +00:00
|
|
|
*
|
2023-08-20 05:24:17 +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[];
|
2023-08-20 05:24:17 +00:00
|
|
|
|
|
|
|
/** A list of files or glob patterns that should be bundled with the plug.
|
2023-08-27 12:13:18 +00:00
|
|
|
*
|
2023-08-20 05:24:17 +00:00
|
|
|
* These files will be accessible through the `asset.readAsset` function.
|
2023-08-27 12:13:18 +00:00
|
|
|
*
|
2023-08-20 05:24:17 +00:00
|
|
|
* see: plug-api/plugos-syscall/asset.ts#readAsset
|
|
|
|
*/
|
2022-10-12 09:47:13 +00:00
|
|
|
assets?: string[] | AssetJson;
|
2023-08-20 05:24:17 +00:00
|
|
|
|
|
|
|
/** 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
|
|
|
*
|
2023-08-20 05:24:17 +00:00
|
|
|
* see: common/manifest.ts#SilverBulletHooks
|
|
|
|
*/
|
2023-08-27 12:13:18 +00:00
|
|
|
functions: Record<string, FunctionDef<HookT>>;
|
2022-03-20 08:56:28 +00:00
|
|
|
}
|
|
|
|
|
2023-08-20 05:24:17 +00:00
|
|
|
/** 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> = {
|
2023-08-20 05:24:17 +00:00
|
|
|
/** A function path, in the form `${relativeFilename}:${functionName}`.
|
2023-08-27 12:13:18 +00:00
|
|
|
*
|
2023-08-20 05:24:17 +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
|
|
|
*
|
2023-08-20 05:24:17 +00:00
|
|
|
* This field and `FunctionDef.redirect` are mutually exclusive.
|
|
|
|
*/
|
2022-03-20 08:56:28 +00:00
|
|
|
path?: string;
|
2023-08-20 05:24:17 +00:00
|
|
|
|
|
|
|
/** A function from another plug, in the form `${plugName}.${functionName}` that will be attached to the given hooks. */
|
2022-10-28 14:17:40 +00:00
|
|
|
redirect?: string;
|
2023-08-20 05:24:17 +00:00
|
|
|
|
|
|
|
/** 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;
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-03-29 09:21:32 +00:00
|
|
|
export interface Hook<HookT> {
|
2022-03-23 14:41:12 +00:00
|
|
|
validateManifest(manifest: Manifest<HookT>): string[];
|
|
|
|
apply(system: System<HookT>): void;
|
2022-03-20 08:56:28 +00:00
|
|
|
}
|