UNPKG

fluoro

Version:
52 lines (51 loc) 1.7 kB
import type { Context } from './context'; import { Service } from './service'; type ModuleInstanceClass = new (ctx: any, config: ModuleConfig) => unknown; type ModuleInstanceFunction = (ctx: any, config: ModuleConfig) => void; /** Represents the structure of a module export */ export interface ModuleExport { /** The name of the module */ name?: string; /** The main function of the module */ main?: ModuleInstanceFunction; /** The main class of the module */ Main?: ModuleInstanceClass; /** The default export of the module */ default?: ModuleInstanceFunction | ModuleInstanceClass; /** The dependencies of the module */ inject?: string[]; /** The configuration of the module */ config?: ModuleConfig; } export interface ModuleConfig { } declare module './events' { interface EventsMapping { /** * Emitted when a module is ready. * * @param data - The data to pass to the event listeners */ ready_module(data: EventDataModule): void; /** * Emitted when a module is disposed. * * @param data - The data to pass to the event listeners */ dispose_module(data: EventDataModule): void; } } interface EventDataModule { instance: ModuleExport | ModuleInstanceFunction | ModuleInstanceClass; } /** * The module system. */ export declare class Modules<C extends Context = Context> { private readonly ctx; constructor(ctx: C); load(instance: EventDataModule['instance']): void; unload(instance: EventDataModule['instance']): void; service<T extends object>(name: string, instance: Service<T>): void; } export default Modules;