import { EventSourceBase, EventEmitter } from '@govflanders/vl-widget-event'; import { VersionAware } from '@govflanders/vl-widget-module'; import { PluginContext } from './context'; import { PluginHost } from './host'; import { PluginEvent } from './event'; import { PluginState } from './state'; import { PluginRuntime, PluginRuntimeAware } from './runtime'; /** * Interface which describes a plugin function hook. * * @todo Check whether we need to resolve this T to a specific type. */ export interface PluginHookFunction { (...args: any[]): Promise; } /** * Interface which describes a plugin. */ export interface Plugin extends EventEmitter, PluginRuntimeAware, VersionAware { /** * Initialize the plugin. * * @return {Promise} * A promise to initialize the plugin. */ initialize(): Promise; /** * Get the current plugin state. * * @return {PluginState} * Value which represents the current plugin state. */ getPluginState(): PluginState; /** * Get the plugin host. * * @return {PluginHost} * An object which represents the plugin host. */ getPluginHost(): PluginHostType; /** * Get the plugin context. * * @return {PluginContext} * An object which contains the plugin context. */ getPluginContext(): PluginContextType; /** * Get the plugin type identifier. * * @return {string} * */ getPluginTypeId(): string; /** * Get the plugin identifier. * * @return {string} */ getPluginId(): string; } /** * Base implementation for a plugin. */ export declare abstract class PluginBase extends EventSourceBase implements Plugin { /** * Holds the initialize promise. * * @var {PluginState} */ protected pluginState: PluginState; /** * Holds a reference to the plugin host. * * @var {PluginHost} */ protected pluginHost: PluginHostType; /** * Holds the plugin context. * * @var {PluginContext} */ protected pluginContext: PluginContextType; /** * Holds the plugin initialization promise. * * @var {Promise} */ protected pluginInitPromise: Promise | undefined; /** * Create a PluginBase object. * * @param {PluginHost} pluginHost * An object which represents the plugin host. * @param {PluginContext} pluginContext * An object which represents the widget context. * * @throws {Error} * Indicates a widget context error. */ constructor(pluginHost: PluginHostType, pluginContext: PluginContextType); /** * Handle task before initialization starts. * * @return {Promise} * A promise to perform the task. */ protected onBeforeInitialize(): Promise; /** * Handle task to initialize the plugin. * * @return {Promise} * A promise to perform the task. */ protected onInitialize(): Promise; /** * Handle task when plugin is about to transition to ready. * * @return {Promise} * A promise to perform the task. */ protected onBeforeReady(): Promise; /** * Handle task when plugin transitioned to ready. * * @return {Promise} * A promise to perform the task. */ protected onReady(): Promise; /** * Handle task when plugin transitioned to failure. * * @return {Promise} * A promise to perform the task. */ protected onFailed(): Promise; /** * Handle tasks when plugin triggers an error. * * @param {Error} error * Error which was triggered. * * @return {Promise} * A promise to perform the task. */ protected onError(error: Error): Promise; /** * Create an event for given plugin hook. * * @param {string} hook * Name of the hook. * @param {...any} args * Additional hook arguments. * * @return {PluginEvent} * An object which represents a plugin hook event. */ protected createHookEvent(hook: string, ...args: any[]): PluginEvent; /** * Invoke specified hook for this plugin. * * @param {string} hook * Name of the hook. * @param {...any} args * Optional. Additional hook arguments. * * @return {Promise} * A promise to invoke a hook. */ protected invokeHook(hook: string, ...args: any[]): Promise; /** * Validate the plugin context. * * @param {PluginContext} pluginContext * An object which represents the plugin context. * * @return {PluginContext} * An object which represents the plugin context. * * @throws {Error} * Indicates a context error. */ protected validatePluginContext(pluginContext: PluginContextType): void; /** * {@inheritdoc} */ initialize(): Promise; /** * {@inheritdoc} */ getPluginState(): PluginState; /** * {@inheritdoc} */ getPluginHost(): PluginHostType; /** * {@inheritdoc} */ getPluginContext(): PluginContextType; /** * {@inheritdoc} */ getPluginTypeId(): string; /** * {@inheritdoc} */ abstract getPluginId(): string; /** * {@inheritdoc} */ abstract getRuntime(): PluginRuntimeType; /** * {@inheritdoc} */ abstract getVersion(): string; /** * {@inheritdoc} */ toString(): string; }