@storm-stack/plugin-system
Version:
A library used to create and manage a plugin-styled architecture in a TypeScript application.
62 lines (61 loc) • 2.72 kB
TypeScript
import { StormDateTime } from "@storm-stack/date-time";
import type { IStormLog } from "@storm-stack/logging";
import { type IPluginLoader, type IPluginModule, type PluginDefinition, type PluginInstance, type PluginManagerOptions } from "../types";
/**
* Discovers and instantiates plugins.
*/
export declare class PluginManager<TContext = any, TPluginModule extends IPluginModule = any> {
private _options;
private _hasDiscovered;
private _registry;
private _store;
private _hooks;
private _logger;
private _loaders;
private _loaderResolver;
static create: <TContext_1 = any, TPluginModule_1 extends IPluginModule<TContext_1> = any>(logger: IStormLog, options: Omit<Partial<PluginManagerOptions>, "defaultLoader"> & Pick<PluginManagerOptions, "defaultLoader">) => Promise<PluginManager<TContext_1, TPluginModule_1>>;
/**
* Creates a new plugin manager object.
*
* @param config - The base storm workspace configuration.
* @param options - The plugin configuration options.
*/
private constructor();
discover: () => Promise<Map<string, PluginDefinition>>;
getInstance: (provider: string, options?: Record<string, any>) => PluginInstance<TContext, TPluginModule> | undefined;
instantiate: (provider: string, options?: Record<string, any>) => Promise<PluginInstance<TContext, TPluginModule>>;
execute: (provider: string, context: TContext, options?: Record<string, any>, executionDateTime?: StormDateTime) => Promise<Record<string, Error | null>>;
invokeHook: (name: string, context: TContext, handler?: (context: TContext) => Promise<TContext> | TContext) => Promise<TContext>;
register: (provider: string) => Promise<PluginDefinition>;
getRegistry(): Map<string, PluginDefinition>;
getLoaders(): Map<string, IPluginLoader<TContext, TPluginModule>>;
getStore(): Map<string, PluginInstance<TContext, TPluginModule>>;
/**
* Generates a cache ID for the plugin and the config.
*
* @param provider - The plugin provider.
* @param options - The options for the plugin.
* @returns The cache ID.
*/
private _getCacheId;
/**
* Builds the globbing expression based on the configuration options.
*
* @returns The globbing expression.
*/
private _globExpression;
/**
* Gets the loader module.
*
* @param loader - The loader module to retrieve.
* @returns The loader module.
*/
private _getLoader;
/**
* Gets the plugin definition from the plugin configuration file.
*
* @param _configPath - The path to the plugin configuration file.
* @returns The plugin definition.
*/
private _getDefinition;
}