@expressots/core
Version:
Expressots - modern, fast, lightweight nodejs web framework (@core)
39 lines (38 loc) • 1.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppFactory = void 0;
exports.isWebServerConstructor = isWebServerConstructor;
const logger_provider_1 = require("../provider/logger/logger.provider");
/**
* Type guard to check if input is a constructor type of IWebServer.
* @param input - Input to check.
* @returns True if input is a constructor type of IWebServer.
*/
function isWebServerConstructor(input) {
return input && typeof input === "function";
}
/**
* AppFactory Class
*
* Responsible for creating an instance of the IWebServer implementation using a custom application type.
* @public API
*/
class AppFactory {
/**
* Create an instance of a web server.
* @param webServerType - Constructor of a class that implements IWebServer.
* @returns A promise that resolves to an instance of IWebServerBuilder.
*/
static async create(webServerType) {
if (isWebServerConstructor(webServerType)) {
const webServerInstance = new webServerType();
return webServerInstance;
}
else {
AppFactory.logger.error("Invalid web server type.", "app-factory:create");
throw new Error("Invalid web server type.");
}
}
}
exports.AppFactory = AppFactory;
AppFactory.logger = new logger_provider_1.Logger();
;