UNPKG

@sigiljs/sigil

Version:

TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating

84 lines (83 loc) 2.11 kB
class i { /** * Static plugin name, usually the class name. */ static name; /** * Instance plugin name, copied from the constructor. */ name; /** * Internal routes API for registering or inspecting routes. */ $routes; /** * Response template function from the framework. */ $responseTemplate; /** * Configuration object passed to this plugin. */ $pluginConfig; /** * Logger scoped to this plugin. */ logger; /** * Internal Sigil API for plugins (mount, addMiddleware, etc.). */ sigil; /** * Constructs the plugin with context injected by attachPluginContext. * @protected */ constructor() { const t = new.target; this.name = t.name; const e = new.target.prototype.__$ctx; if (!e) throw new Error("Cannot initialize plugin without context"); this.$routes = e.routes, this.$pluginConfig = e.pluginConfig, this.sigil = e.sigilApi, this.$responseTemplate = e.responseTemplate, this.logger = e.logger; } /** * Called when a new request is received. Cannot modify the request, * only for side effects such as logging or telemetry. * @param request parsed incoming request object. */ onRequestReceived(t) { } /** * Called just before a response is sent. * Can replace the actual response by returning custom SigilResponse. * @param request original HTTP incoming message. * @param response SigilResponse or Exception being sent. */ onBeforeResponseSent(t, e) { } /** * Called when the internal HTTP/S server starts listening. * @param server HTTP or HTTPS server instance, or undefined in serverless mode. */ onInternalServerStarted(t) { } /** * Called whenever the route registry is updated (e.g., mount or unmount). */ onUpdateCallback() { } /** * Called once when the plugin is first initialized. */ onInitialize() { } /** * Called before the program exits (SIGINT, etc.). * Can perform async cleanup. * @returns optional promise for async cleanup tasks. */ onBeforeExit() { } } export { i as SigilPlugin };