@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
45 lines (44 loc) • 1.9 kB
TypeScript
import { SigilPlugin, SigilPluginConstructor } from './misc';
import { SigilMiddleware, SigilMiddlewareCallback } from './misc/sigil-middleware';
import { default as SigilCore } from './sigil-core';
import { MaybePromise, SigilOptions } from './types';
/**
* Plugin system extension of the Sigil core.
* Manages plugin retrieval and middleware registration.
*
* @template T type of Sigil runtime options.
*/
export default class SigilPluginSystem<T extends Partial<SigilOptions>> extends SigilCore<T> {
/**
* Constructs the SigilPluginSystem with optional configuration.
*
* @param options partial SigilOptions for core initialization.
*/
constructor(options?: T);
/**
* Retrieves a registered plugin instance by its constructor.
* Logs an error if the plugin has not been loaded.
*
* @param plugin plugin constructor to retrieve.
* @returns plugin instance, or undefined if not loaded.
*/
plugin<P extends SigilPlugin>(plugin: SigilPluginConstructor<P>): P;
/**
* Executes a callback with the plugin instance if it exists.
* Returns null if the plugin is not registered.
*
* @param plugin plugin constructor to use.
* @param callback function to execute with the plugin.
* @returns result of the callback or null.
*/
withPlugin<P extends SigilPlugin, R = any>(plugin: SigilPluginConstructor<P>, callback: (plugin: P) => R): MaybePromise<R>;
/**
* Adds a global middleware to the Sigil framework.
* Generates a unique ID for the middleware and logs its registration.
* Returns a SigilMiddleware instance that can be used to unregister.
*
* @param callback the middleware function to register.
* @returns SigilMiddleware object for managing the middleware lifecycle.
*/
addMiddleware(callback: SigilMiddlewareCallback): SigilMiddleware;
}