@vortex-js/core
Version:
A simple and powerful role-based access control (RBAC) middleware for Express.js, designed to be easy to use and integrate with your existing applications. It provides a flexible way to manage user permissions and roles, making it ideal for building secur
46 lines (45 loc) • 1.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Routes_1 = __importDefault(require("./Routes"));
class Module {
/**
* Module class to encapsulate routes and bootstrap functionality
* @param config - Configuration object for the module
*/
constructor(config) {
if (!config.routes) {
throw new Error("Module name and version are required");
}
/**
* All the required fields must be given
* throw an error if not
*/
if (!config.name) {
throw new Error("Module name is required");
}
if (!config.routes) {
throw new Error("Module routes are required");
}
if (!(config.routes instanceof Routes_1.default)) {
throw new Error("Module routes must be an instance of Routes");
}
if (config.bootstrap &&
(typeof config.bootstrap !== "function" ||
config.bootstrap instanceof Promise)) {
throw new Error("Module bootstrap must be a function");
}
this.name = config.name;
this.bootstrap = config.bootstrap;
this.i18n = config.i18n ? config.i18n : {};
// Ensure routes have a module reference
this.addModuleToAllRoutes(config.routes);
this.routes = config.routes;
}
addModuleToAllRoutes(routes) {
routes.registerModule(this);
}
}
exports.default = Module;