UNPKG

@sentzunhat/zacatl

Version:

A modular, high-performance TypeScript microservice framework for Node.js, featuring layered architecture, dependency injection, and robust validation for building scalable APIs and distributed systems.

58 lines 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Application = void 0; const dependency_injection_1 = require("../../../dependency-injection/index.js"); const error_1 = require("../../../error/index.js"); const container_1 = require("../../../dependency-injection/container"); class Application { config; constructor(config) { this.config = config; this.register(); } register() { if (this.config.entryPoints.rest != null) { this.registerRestEntryPoints(); } } registerRestEntryPoints() { const restEntryPoints = this.config.entryPoints.rest; if (restEntryPoints == null) { return; } const { hooks: restHooks, routes: restRoutes } = restEntryPoints; if (restHooks != null && restHooks.length > 0) { for (const hook of restHooks) { if (!(0, container_1.getContainer)().isRegistered(hook)) { (0, container_1.getContainer)().registerSingleton(hook, hook); } } } if (restRoutes != null && restRoutes.length > 0) { for (const route of restRoutes) { if (!(0, container_1.getContainer)().isRegistered(route)) { (0, container_1.getContainer)().registerSingleton(route, route); } } } const hooks = restHooks != null ? (0, dependency_injection_1.resolveDependencies)(restHooks) : []; const routes = restRoutes != null ? (0, dependency_injection_1.resolveDependencies)(restRoutes) : []; if (hooks.length !== (restHooks != null ? restHooks.length : 0) || routes.length !== (restRoutes != null ? restRoutes.length : 0)) { throw new error_1.InternalServerError({ message: 'Failed to register all REST entry point dependencies', reason: 'Not all REST hooks and routes could be resolved from DI container', component: 'ApplicationLayer', operation: 'register', metadata: { expectedHooks: restHooks != null ? restHooks.length : 0, resolvedHooks: hooks.length, expectedRoutes: restRoutes != null ? restRoutes.length : 0, resolvedRoutes: routes.length, }, }); } } } exports.Application = Application; //# sourceMappingURL=application.js.map