@hemia/core 0.0.6 → 0.0.8
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.
package/dist/hemia-core.esm.js
CHANGED
|
@@ -312,17 +312,23 @@ Reflector = __decorate([
|
|
|
312
312
|
injectable()
|
|
313
313
|
], Reflector);
|
|
314
314
|
|
|
315
|
-
class
|
|
315
|
+
class AppFactory {
|
|
316
316
|
/**
|
|
317
317
|
* Inicializa la aplicación Hemia conectando Express con Inversify.
|
|
318
318
|
* @param container El contenedor de Inversify con tus servicios ya bindeados.
|
|
319
|
-
* @param controllers Lista de Clases de Controladores a registrar.
|
|
320
319
|
* @param options Opciones de configuración.
|
|
321
320
|
*/
|
|
322
|
-
static async create(container, options = {},
|
|
321
|
+
static async create(container, options = {}, plugins = []) {
|
|
323
322
|
const app = express();
|
|
324
323
|
app.use(express.json(options.jsonOptions));
|
|
325
324
|
app.use(express.urlencoded({ extended: true, ...options.urlencodedOptions }));
|
|
325
|
+
if (plugins && Array.isArray(plugins) && plugins.length > 0) {
|
|
326
|
+
for (const plugin of plugins) {
|
|
327
|
+
if (plugin && typeof plugin === 'function') {
|
|
328
|
+
await plugin(container);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
326
332
|
if (options.middlewares && Array.isArray(options.middlewares)) {
|
|
327
333
|
options.middlewares.forEach(middleware => {
|
|
328
334
|
app.use(middleware);
|
|
@@ -348,15 +354,27 @@ class HemiaFactory {
|
|
|
348
354
|
if (!container.isBound(Reflector)) {
|
|
349
355
|
container.bind(Reflector).toSelf().inSingletonScope();
|
|
350
356
|
}
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
357
|
+
const autoControllerList = ControllerRegistry.getAll();
|
|
358
|
+
const validAutoControllers = autoControllerList.filter(controllerClass => {
|
|
359
|
+
if (container.isBound(controllerClass)) {
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
const isManual = Reflect.getMetadata(METADATA_KEYS.MANUAL_REGISTER, controllerClass);
|
|
363
|
+
if (isManual) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
return true;
|
|
367
|
+
});
|
|
368
|
+
const controllers = Array.from(new Set([
|
|
369
|
+
...(options.controllers || []),
|
|
370
|
+
...validAutoControllers,
|
|
371
|
+
]));
|
|
372
|
+
controllers.forEach(controllerClass => {
|
|
355
373
|
if (!container.isBound(controllerClass)) {
|
|
356
374
|
container.bind(controllerClass).toSelf();
|
|
357
375
|
}
|
|
358
376
|
});
|
|
359
|
-
await registerRoutes(app, container,
|
|
377
|
+
await registerRoutes(app, container, controllers, options.onTraceFinish || (() => { }), options.multerOptions);
|
|
360
378
|
app.use((err, req, res, next) => {
|
|
361
379
|
console.error('[Hemia] Unhandled error:', err);
|
|
362
380
|
res.status(err.status || 500).json({
|
|
@@ -365,7 +383,7 @@ class HemiaFactory {
|
|
|
365
383
|
});
|
|
366
384
|
});
|
|
367
385
|
if (options.logger !== false) {
|
|
368
|
-
console.log(`[Hemia] Application initialized with ${
|
|
386
|
+
console.log(`[Hemia] Application initialized with ${controllers.length} controllers.`);
|
|
369
387
|
}
|
|
370
388
|
return app;
|
|
371
389
|
}
|
|
@@ -478,4 +496,4 @@ JWTGuard = __decorate([
|
|
|
478
496
|
__metadata("design:paramtypes", [AuthService])
|
|
479
497
|
], JWTGuard);
|
|
480
498
|
|
|
481
|
-
export { ApiKeyGuard, AuthGuard, GuardsConsumer, HemiaExecutionContext,
|
|
499
|
+
export { ApiKeyGuard, AppFactory, AuthGuard, GuardsConsumer, HemiaExecutionContext, JWTGuard, Reflector, ResponseSerializer, registerRoutes };
|
package/dist/hemia-core.js
CHANGED
|
@@ -314,17 +314,23 @@ exports.Reflector = __decorate([
|
|
|
314
314
|
inversify.injectable()
|
|
315
315
|
], exports.Reflector);
|
|
316
316
|
|
|
317
|
-
class
|
|
317
|
+
class AppFactory {
|
|
318
318
|
/**
|
|
319
319
|
* Inicializa la aplicación Hemia conectando Express con Inversify.
|
|
320
320
|
* @param container El contenedor de Inversify con tus servicios ya bindeados.
|
|
321
|
-
* @param controllers Lista de Clases de Controladores a registrar.
|
|
322
321
|
* @param options Opciones de configuración.
|
|
323
322
|
*/
|
|
324
|
-
static async create(container, options = {},
|
|
323
|
+
static async create(container, options = {}, plugins = []) {
|
|
325
324
|
const app = express();
|
|
326
325
|
app.use(express.json(options.jsonOptions));
|
|
327
326
|
app.use(express.urlencoded({ extended: true, ...options.urlencodedOptions }));
|
|
327
|
+
if (plugins && Array.isArray(plugins) && plugins.length > 0) {
|
|
328
|
+
for (const plugin of plugins) {
|
|
329
|
+
if (plugin && typeof plugin === 'function') {
|
|
330
|
+
await plugin(container);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
328
334
|
if (options.middlewares && Array.isArray(options.middlewares)) {
|
|
329
335
|
options.middlewares.forEach(middleware => {
|
|
330
336
|
app.use(middleware);
|
|
@@ -350,15 +356,27 @@ class HemiaFactory {
|
|
|
350
356
|
if (!container.isBound(exports.Reflector)) {
|
|
351
357
|
container.bind(exports.Reflector).toSelf().inSingletonScope();
|
|
352
358
|
}
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
359
|
+
const autoControllerList = common.ControllerRegistry.getAll();
|
|
360
|
+
const validAutoControllers = autoControllerList.filter(controllerClass => {
|
|
361
|
+
if (container.isBound(controllerClass)) {
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
const isManual = Reflect.getMetadata(common.METADATA_KEYS.MANUAL_REGISTER, controllerClass);
|
|
365
|
+
if (isManual) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
return true;
|
|
369
|
+
});
|
|
370
|
+
const controllers = Array.from(new Set([
|
|
371
|
+
...(options.controllers || []),
|
|
372
|
+
...validAutoControllers,
|
|
373
|
+
]));
|
|
374
|
+
controllers.forEach(controllerClass => {
|
|
357
375
|
if (!container.isBound(controllerClass)) {
|
|
358
376
|
container.bind(controllerClass).toSelf();
|
|
359
377
|
}
|
|
360
378
|
});
|
|
361
|
-
await registerRoutes(app, container,
|
|
379
|
+
await registerRoutes(app, container, controllers, options.onTraceFinish || (() => { }), options.multerOptions);
|
|
362
380
|
app.use((err, req, res, next) => {
|
|
363
381
|
console.error('[Hemia] Unhandled error:', err);
|
|
364
382
|
res.status(err.status || 500).json({
|
|
@@ -367,7 +385,7 @@ class HemiaFactory {
|
|
|
367
385
|
});
|
|
368
386
|
});
|
|
369
387
|
if (options.logger !== false) {
|
|
370
|
-
console.log(`[Hemia] Application initialized with ${
|
|
388
|
+
console.log(`[Hemia] Application initialized with ${controllers.length} controllers.`);
|
|
371
389
|
}
|
|
372
390
|
return app;
|
|
373
391
|
}
|
|
@@ -480,8 +498,8 @@ exports.JWTGuard = __decorate([
|
|
|
480
498
|
__metadata("design:paramtypes", [authSdk.AuthService])
|
|
481
499
|
], exports.JWTGuard);
|
|
482
500
|
|
|
501
|
+
exports.AppFactory = AppFactory;
|
|
483
502
|
exports.GuardsConsumer = GuardsConsumer;
|
|
484
503
|
exports.HemiaExecutionContext = HemiaExecutionContext;
|
|
485
|
-
exports.HemiaFactory = HemiaFactory;
|
|
486
504
|
exports.ResponseSerializer = ResponseSerializer;
|
|
487
505
|
exports.registerRoutes = registerRoutes;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Container } from "inversify";
|
|
2
2
|
import { TraceFinishCallback } from "./router";
|
|
3
|
-
import { Type } from "@hemia/common";
|
|
3
|
+
import { Plugin, Type } from "@hemia/common";
|
|
4
4
|
import { Express } from "express";
|
|
5
|
-
export interface
|
|
5
|
+
export interface AppFactoryOptions {
|
|
6
6
|
onTraceFinish?: TraceFinishCallback;
|
|
7
7
|
logger?: boolean;
|
|
8
8
|
corsHeaders?: Record<string, string>;
|
|
@@ -10,13 +10,13 @@ export interface HemiaFactoryOptions {
|
|
|
10
10
|
multerOptions?: any;
|
|
11
11
|
jsonOptions?: any;
|
|
12
12
|
urlencodedOptions?: any;
|
|
13
|
+
controllers?: Type<any>[];
|
|
13
14
|
}
|
|
14
|
-
export declare class
|
|
15
|
+
export declare class AppFactory {
|
|
15
16
|
/**
|
|
16
17
|
* Inicializa la aplicación Hemia conectando Express con Inversify.
|
|
17
18
|
* @param container El contenedor de Inversify con tus servicios ya bindeados.
|
|
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, options?:
|
|
21
|
+
static create(container: Container, options?: AppFactoryOptions, plugins?: Plugin[]): Promise<Express>;
|
|
22
22
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './app-factory';
|
|
3
3
|
export * from "./services";
|
|
4
4
|
export * from "./context";
|
|
5
5
|
export * from "./router";
|
|
6
6
|
export * from "./guards";
|
|
7
|
-
export * from "./
|
|
7
|
+
export * from "./app-factory";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hemia/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "Core utilities for Hemia projects",
|
|
5
5
|
"main": "dist/hemia-core.js",
|
|
6
6
|
"module": "dist/hemia-core.esm.js",
|
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
"build": "npm run clean && npm run tscBuild",
|
|
12
12
|
"test": "jest --detectOpenHandles",
|
|
13
13
|
"test:coverage": "jest --coverage",
|
|
14
|
-
"test:watch": "jest --watch"
|
|
14
|
+
"test:watch": "jest --watch",
|
|
15
|
+
"prepublish": "npm run build"
|
|
15
16
|
},
|
|
16
17
|
"devDependencies": {
|
|
17
18
|
"@rollup/plugin-commonjs": "^26.0.1",
|
|
18
19
|
"@rollup/plugin-json": "^6.1.0",
|
|
19
20
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
20
|
-
"@hemia/common": "^0.0.
|
|
21
|
+
"@hemia/common": "^0.0.12",
|
|
21
22
|
"@hemia/app-context": "^0.0.6",
|
|
22
23
|
"@hemia/trace-manager": "^0.0.9",
|
|
23
|
-
"@hemia/auth-sdk": "^0.0.
|
|
24
|
+
"@hemia/auth-sdk": "^0.0.11",
|
|
24
25
|
"@types/express": "^5.0.5",
|
|
25
26
|
"express": "^5.1.0",
|
|
26
27
|
"inversify": "^7.10.4",
|