@hemia/core 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import express, { Router } from 'express';
3
- import { METADATA_KEYS, ParamType, ApiResponse, isRedirectResponse } from '@hemia/common';
3
+ import { METADATA_KEYS, ParamType, ApiResponse, isRedirectResponse, ControllerRegistry } from '@hemia/common';
4
4
  import { TRACE_METADATA_KEY } from '@hemia/trace-manager';
5
5
  import { traceMiddleware } from '@hemia/app-context';
6
6
  import { plainToInstance } from 'class-transformer';
@@ -319,7 +319,7 @@ class HemiaFactory {
319
319
  * @param controllers Lista de Clases de Controladores a registrar.
320
320
  * @param options Opciones de configuración.
321
321
  */
322
- static async create(container, controllers, options = {}) {
322
+ static async create(container, options = {}, controllers) {
323
323
  const app = express();
324
324
  app.use(express.json(options.jsonOptions));
325
325
  app.use(express.urlencoded({ extended: true, ...options.urlencodedOptions }));
@@ -348,12 +348,15 @@ class HemiaFactory {
348
348
  if (!container.isBound(Reflector)) {
349
349
  container.bind(Reflector).toSelf().inSingletonScope();
350
350
  }
351
- controllers.forEach(controllerClass => {
351
+ const controllerList = controllers && controllers.length > 0
352
+ ? controllers
353
+ : ControllerRegistry.getAll();
354
+ controllerList.forEach(controllerClass => {
352
355
  if (!container.isBound(controllerClass)) {
353
356
  container.bind(controllerClass).toSelf();
354
357
  }
355
358
  });
356
- await registerRoutes(app, container, controllers, options.onTraceFinish || (() => { }), options.multerOptions);
359
+ await registerRoutes(app, container, controllerList, options.onTraceFinish || (() => { }), options.multerOptions);
357
360
  app.use((err, req, res, next) => {
358
361
  console.error('[Hemia] Unhandled error:', err);
359
362
  res.status(err.status || 500).json({
@@ -362,7 +365,7 @@ class HemiaFactory {
362
365
  });
363
366
  });
364
367
  if (options.logger !== false) {
365
- console.log(`[Hemia] Application initialized with ${controllers.length} controllers.`);
368
+ console.log(`[Hemia] Application initialized with ${controllerList.length} controllers.`);
366
369
  }
367
370
  return app;
368
371
  }
@@ -321,7 +321,7 @@ class HemiaFactory {
321
321
  * @param controllers Lista de Clases de Controladores a registrar.
322
322
  * @param options Opciones de configuración.
323
323
  */
324
- static async create(container, controllers, options = {}) {
324
+ static async create(container, options = {}, controllers) {
325
325
  const app = express();
326
326
  app.use(express.json(options.jsonOptions));
327
327
  app.use(express.urlencoded({ extended: true, ...options.urlencodedOptions }));
@@ -350,12 +350,15 @@ class HemiaFactory {
350
350
  if (!container.isBound(exports.Reflector)) {
351
351
  container.bind(exports.Reflector).toSelf().inSingletonScope();
352
352
  }
353
- controllers.forEach(controllerClass => {
353
+ const controllerList = controllers && controllers.length > 0
354
+ ? controllers
355
+ : common.ControllerRegistry.getAll();
356
+ controllerList.forEach(controllerClass => {
354
357
  if (!container.isBound(controllerClass)) {
355
358
  container.bind(controllerClass).toSelf();
356
359
  }
357
360
  });
358
- await registerRoutes(app, container, controllers, options.onTraceFinish || (() => { }), options.multerOptions);
361
+ await registerRoutes(app, container, controllerList, options.onTraceFinish || (() => { }), options.multerOptions);
359
362
  app.use((err, req, res, next) => {
360
363
  console.error('[Hemia] Unhandled error:', err);
361
364
  res.status(err.status || 500).json({
@@ -364,7 +367,7 @@ class HemiaFactory {
364
367
  });
365
368
  });
366
369
  if (options.logger !== false) {
367
- console.log(`[Hemia] Application initialized with ${controllers.length} controllers.`);
370
+ console.log(`[Hemia] Application initialized with ${controllerList.length} controllers.`);
368
371
  }
369
372
  return app;
370
373
  }
@@ -18,5 +18,5 @@ export declare class HemiaFactory {
18
18
  * @param controllers Lista de Clases de Controladores a registrar.
19
19
  * @param options Opciones de configuración.
20
20
  */
21
- static create(container: Container, controllers: Type<any>[], options?: HemiaFactoryOptions): Promise<Express>;
21
+ static create(container: Container, options?: HemiaFactoryOptions, controllers?: Type<any>[]): Promise<Express>;
22
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hemia/core",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Core utilities for Hemia projects",
5
5
  "main": "dist/hemia-core.js",
6
6
  "module": "dist/hemia-core.esm.js",
@@ -17,7 +17,7 @@
17
17
  "@rollup/plugin-commonjs": "^26.0.1",
18
18
  "@rollup/plugin-json": "^6.1.0",
19
19
  "@rollup/plugin-node-resolve": "^15.2.3",
20
- "@hemia/common": "^0.0.7",
20
+ "@hemia/common": "^0.0.8",
21
21
  "@hemia/app-context": "^0.0.6",
22
22
  "@hemia/trace-manager": "^0.0.9",
23
23
  "@hemia/auth-sdk": "^0.0.9",