@sigiljs/sigil
Version:
TypeScript-first Node.js HTTP framework offering schema-driven routing, modifier-based middleware, plugin extensibility, and flexible response templating
44 lines (43 loc) • 1 kB
JavaScript
class l {
/** Unique identifier for this middleware instance. */
#e;
/** The middleware callback function. */
#t;
/** Cleanup function to remove this middleware. */
#i;
/**
* Constructs a new SigilMiddleware.
*
* @param executor middleware callback to execute on each request.
* @param onRemove callback to invoke when this middleware is removed.
* @param id unique ID assigned to this middleware.
*/
constructor(e, t, i) {
this.#e = i, this.#t = e, this.#i = t;
}
/**
* Returns the string representation of this middleware (its ID).
*
* @returns middleware ID.
*/
toString() {
return this.#e;
}
/**
* Removes this middleware by invoking its removal callback.
*/
removeMiddleware() {
this.#i();
}
/**
* Retrieves the original middleware callback function.
*
* @returns SigilMiddlewareCallback assigned to this instance.
*/
getMiddlewareCallback() {
return this.#t;
}
}
export {
l as SigilMiddleware
};