@zanobijs/core 1.0.2-beta.0 → 1.1.0-beta.0
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/CHANGELOG.md +1 -1
- package/exceptions/constant.message.js +1 -1
- package/exceptions/index.d.ts +2 -2
- package/exceptions/invalid.module.exception.d.ts +1 -1
- package/exceptions/invalid.module.exception.js +1 -1
- package/exceptions/resolution.exception.d.ts +1 -1
- package/factory.d.ts +13 -18
- package/factory.js +31 -40
- package/index.d.ts +2 -2
- package/injector/index.d.ts +2 -2
- package/injector/injector.d.ts +11 -6
- package/injector/injector.js +14 -11
- package/injector/module.d.ts +4 -3
- package/injector/module.js +13 -14
- package/interfaces/globals.interface.d.ts +4 -0
- package/interfaces/globals.interface.js +2 -0
- package/interfaces/index.d.ts +2 -1
- package/interfaces/index.js +1 -0
- package/metadata.d.ts +27 -25
- package/metadata.js +19 -18
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [1.1.0-beta.0](https://github.com/devdroide/ZanobiJS/compare/v1.0.2...v1.1.0-beta.0) (2025-05-02)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @zanobijs/core
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CONTAINER_RESOLUTION_ENTITY_ERROR = exports.CONTAINER_RESOLUTION_ERROR = exports.MODULE_INVALID_ANNOTATION_ERROR = void 0;
|
|
4
|
-
const MODULE_INVALID_ANNOTATION_ERROR = () =>
|
|
4
|
+
const MODULE_INVALID_ANNOTATION_ERROR = () => 'The class must have an annotation @Module()';
|
|
5
5
|
exports.MODULE_INVALID_ANNOTATION_ERROR = MODULE_INVALID_ANNOTATION_ERROR;
|
|
6
6
|
const CONTAINER_RESOLUTION_ERROR = (entity, resolutionError) => `${resolutionError} please review '${entity}' and its dependencies.`;
|
|
7
7
|
exports.CONTAINER_RESOLUTION_ERROR = CONTAINER_RESOLUTION_ERROR;
|
package/exceptions/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './constant.message';
|
|
2
|
+
export * from './invalid.module.exception';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuntimeException } from
|
|
1
|
+
import { RuntimeException } from '@zanobijs/common/exceptions/runtime.exception';
|
|
2
2
|
/**
|
|
3
3
|
* Excepción lanzada cuando una clase Modulo no tiene el decorador `@Module`
|
|
4
4
|
* de @zanobijs/common
|
|
@@ -12,7 +12,7 @@ const constant_message_1 = require("./constant.message");
|
|
|
12
12
|
* para proporcionar detalles adicionales específicos a esquemas de módulos inválidos.
|
|
13
13
|
*/
|
|
14
14
|
class InvalidModuleAnnotationException extends runtime_exception_1.RuntimeException {
|
|
15
|
-
constructor(detail =
|
|
15
|
+
constructor(detail = '') {
|
|
16
16
|
super((0, constant_message_1.MODULE_INVALID_ANNOTATION_ERROR)(), detail);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuntimeException } from
|
|
1
|
+
import { RuntimeException } from '@zanobijs/common/exceptions/runtime.exception';
|
|
2
2
|
/**
|
|
3
3
|
* Excepción lanzada cuando se intenta obtener una dependencia
|
|
4
4
|
* de un controlador o servicio y esta no fue registrada
|
package/factory.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IFactoryOptions } from
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { IFactoryOptions } from './interfaces';
|
|
3
|
+
import { TClass } from './interfaces/globals.interface';
|
|
3
4
|
/**
|
|
4
5
|
* Factory es una clase que facilita la creación y configuración de
|
|
5
6
|
* contenedores de inyección de dependencias utilizando metadatos y
|
|
6
|
-
* la librería `awilix` para registrar y resolver
|
|
7
|
-
* servicios.
|
|
7
|
+
* la librería `awilix` para registrar y resolver entidades como:
|
|
8
|
+
* controladores y servicios.
|
|
8
9
|
*/
|
|
9
10
|
export declare class Factory {
|
|
10
11
|
private moduleHandler;
|
|
@@ -12,30 +13,24 @@ export declare class Factory {
|
|
|
12
13
|
private container;
|
|
13
14
|
private logger;
|
|
14
15
|
private options;
|
|
15
|
-
constructor(appModule:
|
|
16
|
-
/**
|
|
17
|
-
* Este método registra clases desde el módulo proporcionado
|
|
18
|
-
* y recorre sus importaciones de forma recursiva para registrar
|
|
19
|
-
* las clases necesarias de importación.
|
|
20
|
-
* @private
|
|
21
|
-
*/
|
|
22
|
-
private registerClassesFromModule;
|
|
16
|
+
constructor(appModule: TClass, options?: IFactoryOptions);
|
|
23
17
|
/**
|
|
24
18
|
* Registra clases desde un módulo específico.
|
|
25
|
-
* @param {
|
|
19
|
+
* @param {TClass} module - Módulo desde el que se registrarán las clases.
|
|
26
20
|
* @private
|
|
27
21
|
*/
|
|
28
|
-
private
|
|
22
|
+
private processModule;
|
|
29
23
|
/**
|
|
30
24
|
* Crea el contenedor de inyección de dependencias y registra las clases.
|
|
31
25
|
* @returns {Factory} - Instancia actual de la fábrica.
|
|
32
26
|
*/
|
|
33
27
|
create(): Factory;
|
|
34
28
|
/**
|
|
35
|
-
* Resuelve y devuelve una instancia del contenedor
|
|
36
|
-
*
|
|
37
|
-
* @
|
|
29
|
+
* Resuelve y devuelve una instancia del contenedor
|
|
30
|
+
* teniendo en cuenta el nombre de la entidad proporcionada.
|
|
31
|
+
* @param {string} className - Nombre de la entidad a resolver.
|
|
32
|
+
* @returns {T} - Instancia resuelta.
|
|
38
33
|
*/
|
|
39
|
-
get<T>(
|
|
34
|
+
get<T>(className: string): T;
|
|
40
35
|
private evaluateOptions;
|
|
41
36
|
}
|
package/factory.js
CHANGED
|
@@ -9,8 +9,8 @@ const utils_1 = require("@zanobijs/common/utils");
|
|
|
9
9
|
/**
|
|
10
10
|
* Factory es una clase que facilita la creación y configuración de
|
|
11
11
|
* contenedores de inyección de dependencias utilizando metadatos y
|
|
12
|
-
* la librería `awilix` para registrar y resolver
|
|
13
|
-
* servicios.
|
|
12
|
+
* la librería `awilix` para registrar y resolver entidades como:
|
|
13
|
+
* controladores y servicios.
|
|
14
14
|
*/
|
|
15
15
|
class Factory {
|
|
16
16
|
moduleHandler;
|
|
@@ -19,43 +19,33 @@ class Factory {
|
|
|
19
19
|
logger;
|
|
20
20
|
options;
|
|
21
21
|
constructor(appModule, options = {}) {
|
|
22
|
-
process.env.ZANOBIJS_LOGGER =
|
|
23
|
-
process.env.ZANOBIJS_LOGGER_USER =
|
|
22
|
+
process.env.ZANOBIJS_LOGGER = 'false';
|
|
23
|
+
process.env.ZANOBIJS_LOGGER_USER = 'false';
|
|
24
24
|
this.options = options;
|
|
25
25
|
this.evaluateOptions();
|
|
26
26
|
this.logger = (0, utils_1.Logger)();
|
|
27
27
|
this.moduleHandler = new module_1.Module();
|
|
28
|
-
this.
|
|
28
|
+
this.processModule(appModule);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* las clases necesarias de importación.
|
|
31
|
+
* Registra clases desde un módulo específico.
|
|
32
|
+
* @param {TClass} module - Módulo desde el que se registrarán las clases.
|
|
34
33
|
* @private
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
|
-
this.logger.debug(
|
|
38
|
-
this.
|
|
35
|
+
processModule(module) {
|
|
36
|
+
this.logger.debug('Factory - Process - Create module setup:', module.name);
|
|
37
|
+
this.moduleHandler.setup(module);
|
|
38
|
+
this.logger.debug('Factory - Process - Module initialize:', module.name);
|
|
39
|
+
this.moduleHandler.initialize();
|
|
40
|
+
Object.assign(this.registeredClasses, this.moduleHandler.getRegisterClass());
|
|
41
|
+
this.logger.success('Factory - Process - Completion of module ', module.name);
|
|
39
42
|
const importedModules = this.moduleHandler.getImports();
|
|
40
43
|
if (importedModules && importedModules.length) {
|
|
41
44
|
importedModules.forEach((moduleImport) => {
|
|
42
|
-
this.
|
|
45
|
+
this.processModule(moduleImport);
|
|
43
46
|
});
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Registra clases desde un módulo específico.
|
|
48
|
-
* @param {any} module - Módulo desde el que se registrarán las clases.
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
registerFromModule(module) {
|
|
52
|
-
this.logger.debug("Factory - Setup:", module.name);
|
|
53
|
-
this.moduleHandler.setup(module);
|
|
54
|
-
this.logger.debug("Factory - Initialize:", module.name);
|
|
55
|
-
this.moduleHandler.initialize();
|
|
56
|
-
Object.assign(this.registeredClasses, this.moduleHandler.getRegisterClass());
|
|
57
|
-
this.logger.success("Factory - Completion of module ", module.name);
|
|
58
|
-
this.logger.debug("===================================================");
|
|
48
|
+
this.logger.debug('===================================================');
|
|
59
49
|
}
|
|
60
50
|
/**
|
|
61
51
|
* Crea el contenedor de inyección de dependencias y registra las clases.
|
|
@@ -64,33 +54,34 @@ class Factory {
|
|
|
64
54
|
create() {
|
|
65
55
|
this.container = (0, awilix_1.createContainer)({ injectionMode: awilix_1.InjectionMode.CLASSIC });
|
|
66
56
|
this.container.register(this.registeredClasses);
|
|
67
|
-
this.logger.info(
|
|
57
|
+
this.logger.info('Factory - classes and providers registered in the container', Object.keys(this.registeredClasses));
|
|
68
58
|
return this;
|
|
69
59
|
}
|
|
70
60
|
/**
|
|
71
|
-
* Resuelve y devuelve una instancia del contenedor
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
61
|
+
* Resuelve y devuelve una instancia del contenedor
|
|
62
|
+
* teniendo en cuenta el nombre de la entidad proporcionada.
|
|
63
|
+
* @param {string} className - Nombre de la entidad a resolver.
|
|
64
|
+
* @returns {T} - Instancia resuelta.
|
|
74
65
|
*/
|
|
75
|
-
get(
|
|
66
|
+
get(className) {
|
|
76
67
|
try {
|
|
77
|
-
return this.container.resolve(
|
|
68
|
+
return this.container.resolve(className);
|
|
78
69
|
}
|
|
79
70
|
catch (error) {
|
|
80
|
-
this.logger.info(
|
|
81
|
-
const resolutionError = error.message.split(
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
throw new resolution_exception_1.ContainerResolutionEntityException(
|
|
71
|
+
this.logger.info('Error resolving entity: ', error.message + '\n');
|
|
72
|
+
const resolutionError = error.message.split('\n');
|
|
73
|
+
const classNameFound = resolutionError[0].match(/'([^']+)'/);
|
|
74
|
+
if (classNameFound[1] === className) {
|
|
75
|
+
throw new resolution_exception_1.ContainerResolutionEntityException(className, error.message);
|
|
85
76
|
}
|
|
86
|
-
throw new resolution_exception_1.ContainerResolutionException(
|
|
77
|
+
throw new resolution_exception_1.ContainerResolutionException(className, resolutionError[0], error.message);
|
|
87
78
|
}
|
|
88
79
|
}
|
|
89
80
|
evaluateOptions() {
|
|
90
81
|
if (this.options.activeLoggerSystem)
|
|
91
|
-
process.env.ZANOBIJS_LOGGER =
|
|
82
|
+
process.env.ZANOBIJS_LOGGER = 'true';
|
|
92
83
|
if (this.options.activeLoggerUser)
|
|
93
|
-
process.env.ZANOBIJS_LOGGER_USER =
|
|
84
|
+
process.env.ZANOBIJS_LOGGER_USER = 'true';
|
|
94
85
|
}
|
|
95
86
|
}
|
|
96
87
|
exports.Factory = Factory;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Factory } from './factory';
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
2
|
+
export * from './injector';
|
|
3
|
+
export * from './interfaces';
|
package/injector/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './module';
|
|
2
|
+
export * from './injector';
|
package/injector/injector.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TClass } from '../interfaces';
|
|
1
2
|
export type Constructor<T> = {
|
|
2
3
|
new (...args: any[]): T;
|
|
3
4
|
};
|
|
@@ -17,7 +18,7 @@ export declare class Injector {
|
|
|
17
18
|
* @param {Module} module - El módulo debe tener el decorador `@Module`
|
|
18
19
|
* para poderlo procesar.
|
|
19
20
|
*/
|
|
20
|
-
constructor(module:
|
|
21
|
+
constructor(module: TClass, listProviders: Map<string, any>);
|
|
21
22
|
/**
|
|
22
23
|
* Este método privado recorre el array de los servicios del modulo para
|
|
23
24
|
* buscar los proveedores tipo objeto a injectar y los almacena en una
|
|
@@ -26,15 +27,19 @@ export declare class Injector {
|
|
|
26
27
|
*/
|
|
27
28
|
private scanProviders;
|
|
28
29
|
/**
|
|
29
|
-
* Método para obtener un objeto con los parámetros y valores
|
|
30
|
-
* que se inyectarán en la clase (target).
|
|
30
|
+
* Método para obtener un objeto con los parámetros(key) y valores(useValue)
|
|
31
|
+
* que se inyectarán en la clase (target) mediante asClass().inject().
|
|
31
32
|
*
|
|
32
|
-
* @param {
|
|
33
|
+
* @param { TClass} target - La clase objetivo.
|
|
33
34
|
* @returns {object} - Objeto con datos a inyectar.
|
|
34
35
|
*/
|
|
35
|
-
getInjectData(target:
|
|
36
|
+
getInjectData(target: TClass): object;
|
|
36
37
|
/**
|
|
37
|
-
* Método para obtener el injector apropiado para la clase objetivo
|
|
38
|
+
* Método para obtener el injector apropiado para la clase objetivo
|
|
39
|
+
* e inyectar los parametros del constructor encontrados en getInjectData
|
|
40
|
+
*
|
|
41
|
+
* Al hacer asClass().inject() evita que los busque en el contenedor ya que
|
|
42
|
+
* se registran de forma local en la clase objetivo
|
|
38
43
|
*
|
|
39
44
|
* @param {any} target - La clase objetivo.
|
|
40
45
|
* @returns - El injector configurado.
|
package/injector/injector.js
CHANGED
|
@@ -14,7 +14,7 @@ class Injector {
|
|
|
14
14
|
listProviders;
|
|
15
15
|
metadata;
|
|
16
16
|
logger;
|
|
17
|
-
moduleName =
|
|
17
|
+
moduleName = '';
|
|
18
18
|
/**
|
|
19
19
|
* En Constructor de la clase Injector obtenermos las instancias
|
|
20
20
|
* de Metadata y Logger e inciamos el escaneo de proveedores.
|
|
@@ -36,19 +36,19 @@ class Injector {
|
|
|
36
36
|
* @private
|
|
37
37
|
*/
|
|
38
38
|
scanProviders() {
|
|
39
|
-
this.logger.debug(
|
|
39
|
+
this.logger.debug('Injector - Scan provider to module:', this.moduleName);
|
|
40
40
|
const { services } = this.metadata.getMetadataModule(this.module);
|
|
41
41
|
services.forEach((service) => {
|
|
42
|
-
if (typeof service ===
|
|
42
|
+
if (typeof service === 'object')
|
|
43
43
|
this.listProviders.set(service.provider, service.useValue);
|
|
44
44
|
});
|
|
45
|
-
this.logger.debug(
|
|
45
|
+
this.logger.debug('Injector - list provider', this.listProviders);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* Método para obtener un objeto con los parámetros y valores
|
|
49
|
-
* que se inyectarán en la clase (target).
|
|
48
|
+
* Método para obtener un objeto con los parámetros(key) y valores(useValue)
|
|
49
|
+
* que se inyectarán en la clase (target) mediante asClass().inject().
|
|
50
50
|
*
|
|
51
|
-
* @param {
|
|
51
|
+
* @param { TClass} target - La clase objetivo.
|
|
52
52
|
* @returns {object} - Objeto con datos a inyectar.
|
|
53
53
|
*/
|
|
54
54
|
getInjectData(target) {
|
|
@@ -62,15 +62,18 @@ class Injector {
|
|
|
62
62
|
injectData[paramName] = useValue;
|
|
63
63
|
}
|
|
64
64
|
else {
|
|
65
|
-
this.logger.important(`
|
|
66
|
-
// throw new ContainerInjectResolutionException(key, target.name);
|
|
65
|
+
this.logger.important(`You are trying to inject @INJECT('${key}') into '${target.name}'`, `but the provider '${key}' and its value are not registered in '${this.moduleName}' or any other previously loaded modules`);
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
return injectData;
|
|
71
70
|
}
|
|
72
71
|
/**
|
|
73
|
-
* Método para obtener el injector apropiado para la clase objetivo
|
|
72
|
+
* Método para obtener el injector apropiado para la clase objetivo
|
|
73
|
+
* e inyectar los parametros del constructor encontrados en getInjectData
|
|
74
|
+
*
|
|
75
|
+
* Al hacer asClass().inject() evita que los busque en el contenedor ya que
|
|
76
|
+
* se registran de forma local en la clase objetivo
|
|
74
77
|
*
|
|
75
78
|
* @param {any} target - La clase objetivo.
|
|
76
79
|
* @returns - El injector configurado.
|
|
@@ -91,7 +94,7 @@ class Injector {
|
|
|
91
94
|
return this.listProviders;
|
|
92
95
|
}
|
|
93
96
|
getInjectProvider(provider) {
|
|
94
|
-
return typeof provider.value ===
|
|
97
|
+
return typeof provider.value === 'function'
|
|
95
98
|
? (0, awilix_1.asFunction)(provider.value).scoped()
|
|
96
99
|
: (0, awilix_1.asValue)(provider.value);
|
|
97
100
|
}
|
package/injector/module.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { TClass } from '../interfaces';
|
|
2
3
|
/**
|
|
3
4
|
* Módulo para gestionar la configuración y el registro de controladores, servicios y dependencias.
|
|
4
5
|
*/
|
|
@@ -67,9 +68,9 @@ export declare class Module {
|
|
|
67
68
|
private registerAllProviders;
|
|
68
69
|
/**
|
|
69
70
|
* Devuelve las importaciones del módulo.
|
|
70
|
-
* @returns {
|
|
71
|
+
* @returns {TClass[] | undefined} - Importaciones del módulo.
|
|
71
72
|
*/
|
|
72
|
-
getImports():
|
|
73
|
+
getImports(): TClass[] | undefined;
|
|
73
74
|
/**
|
|
74
75
|
* Devuelve las clases registradas en el módulo.
|
|
75
76
|
* @returns {any} - Clases registradas.
|
package/injector/module.js
CHANGED
|
@@ -19,7 +19,7 @@ class Module {
|
|
|
19
19
|
registerClass = {};
|
|
20
20
|
dependenciesClass = [];
|
|
21
21
|
metadata;
|
|
22
|
-
types = [
|
|
22
|
+
types = ['controller', 'service'];
|
|
23
23
|
listProviders = new Map();
|
|
24
24
|
/**
|
|
25
25
|
* Constructor del módulo.
|
|
@@ -35,7 +35,7 @@ class Module {
|
|
|
35
35
|
setup(module) {
|
|
36
36
|
if (this.metadata.isTypeModule(module)) {
|
|
37
37
|
this.module = module;
|
|
38
|
-
this.logger.debug(
|
|
38
|
+
this.logger.debug('Module - Setup - Create Injector to module:', module.name);
|
|
39
39
|
this.injector = new injector_1.Injector(module, this.listProviders);
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
@@ -46,7 +46,7 @@ class Module {
|
|
|
46
46
|
* Inicializa el módulo extrayendo metadatos y registrando las entidades.
|
|
47
47
|
*/
|
|
48
48
|
initialize() {
|
|
49
|
-
this.logger.debug(
|
|
49
|
+
this.logger.debug('Module - Initialize:', this.module.name);
|
|
50
50
|
this.registerAllProviders();
|
|
51
51
|
this.getMetadataModule();
|
|
52
52
|
this.registerDependencies();
|
|
@@ -64,8 +64,8 @@ class Module {
|
|
|
64
64
|
* @private
|
|
65
65
|
*/
|
|
66
66
|
registerDependencies() {
|
|
67
|
-
this.registerEntities(
|
|
68
|
-
this.registerEntities(
|
|
67
|
+
this.registerEntities('controllers');
|
|
68
|
+
this.registerEntities('services');
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Registra entidades de configuración (controladores o servicios) del módulo.
|
|
@@ -74,7 +74,7 @@ class Module {
|
|
|
74
74
|
*/
|
|
75
75
|
registerEntities(entityType) {
|
|
76
76
|
const entities = this.config[entityType];
|
|
77
|
-
this.logger.debug(
|
|
77
|
+
this.logger.debug('Module - ..... searching for entities type ', entityType);
|
|
78
78
|
if (entities && entities.length > 0) {
|
|
79
79
|
const registeredEntities = entities
|
|
80
80
|
.filter((target) => {
|
|
@@ -82,7 +82,7 @@ class Module {
|
|
|
82
82
|
this.types.includes(this.metadata.determineType(target)));
|
|
83
83
|
})
|
|
84
84
|
.map((target) => {
|
|
85
|
-
this.logger.debug(
|
|
85
|
+
this.logger.debug('Module - Entity', `<<< ${target.name} >>>`);
|
|
86
86
|
this.groupDependenciesForAlias(target);
|
|
87
87
|
const targetName = (0, shared_utils_1.unCapitalize)(target.name);
|
|
88
88
|
return {
|
|
@@ -93,7 +93,7 @@ class Module {
|
|
|
93
93
|
Object.assign(this.registerClass, ...registeredEntities);
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
|
-
this.logger.debug(
|
|
96
|
+
this.logger.debug('Module - Does not have entities of that type', entityType);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
@@ -110,7 +110,7 @@ class Module {
|
|
|
110
110
|
*/
|
|
111
111
|
groupDependenciesForAlias(target) {
|
|
112
112
|
const dependencies = this.metadata.getClassDependencies(target);
|
|
113
|
-
this.logger.debug(`Module - List dependecies
|
|
113
|
+
this.logger.debug(`Module - List dependecies to group by${target.name}`, dependencies);
|
|
114
114
|
if (dependencies && !(0, shared_utils_1.isEmpty)(dependencies)) {
|
|
115
115
|
this.dependenciesClass = [...this.dependenciesClass, ...dependencies];
|
|
116
116
|
}
|
|
@@ -125,7 +125,7 @@ class Module {
|
|
|
125
125
|
* contructor(private sA: ServiceA) // parametro con nombre diferente
|
|
126
126
|
*/
|
|
127
127
|
registerDependenciesToAlias() {
|
|
128
|
-
this.logger.debug(
|
|
128
|
+
this.logger.debug('Module - dependencies to register as candidates ', this.dependenciesClass);
|
|
129
129
|
this.dependenciesClass.forEach((dependency) => {
|
|
130
130
|
if (!this.registerClass[dependency.nameParameter]) {
|
|
131
131
|
this.registerClass[dependency.nameParameter] = (0, awilix_1.aliasTo)(dependency.nameClassContainer);
|
|
@@ -133,7 +133,7 @@ class Module {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
registerAllProviders() {
|
|
136
|
-
this.logger.debug(
|
|
136
|
+
this.logger.debug('Module - Register list provider:', this.module.name);
|
|
137
137
|
const listProviders = this.injector.getAllProvider();
|
|
138
138
|
listProviders.forEach((value, key) => {
|
|
139
139
|
const providerInject = this.injector.getInjectProvider({
|
|
@@ -141,12 +141,11 @@ class Module {
|
|
|
141
141
|
value,
|
|
142
142
|
});
|
|
143
143
|
this.registerClass[key] = providerInject;
|
|
144
|
-
// this.registerClass[snakeToCamel(key)] = aliasTo(key);
|
|
145
144
|
});
|
|
146
145
|
}
|
|
147
146
|
/**
|
|
148
147
|
* Devuelve las importaciones del módulo.
|
|
149
|
-
* @returns {
|
|
148
|
+
* @returns {TClass[] | undefined} - Importaciones del módulo.
|
|
150
149
|
*/
|
|
151
150
|
getImports() {
|
|
152
151
|
return this.config.imports;
|
|
@@ -156,7 +155,7 @@ class Module {
|
|
|
156
155
|
* @returns {any} - Clases registradas.
|
|
157
156
|
*/
|
|
158
157
|
getRegisterClass() {
|
|
159
|
-
this.logger.debug(
|
|
158
|
+
this.logger.debug('Module - List of candidate classes to register in container.', this.registerClass);
|
|
160
159
|
return this.registerClass;
|
|
161
160
|
}
|
|
162
161
|
}
|
package/interfaces/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './factory.interface';
|
|
2
|
+
export * from './globals.interface';
|
package/interfaces/index.js
CHANGED
package/metadata.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IModuleConfig } from
|
|
1
|
+
import { IModuleConfig } from '@zanobijs/common';
|
|
2
|
+
import { TClass } from './interfaces';
|
|
2
3
|
/**
|
|
3
4
|
* La clase `Metadata` proporciona métodos para acceder y manipular
|
|
4
5
|
* metadatos relacionados con diversos componentes y módulos.
|
|
@@ -16,17 +17,18 @@ export declare class Metadata {
|
|
|
16
17
|
/**
|
|
17
18
|
* Obtiene los metadatos de un módulo específico.
|
|
18
19
|
*
|
|
19
|
-
* @param module - El módulo del cual obtener los metadatos.
|
|
20
|
-
* @returns Un objeto con los metadatos del módulo
|
|
20
|
+
* @param { IModuleConfig } module - El módulo del cual obtener los metadatos.
|
|
21
|
+
* @returns Un objeto con los metadatos del módulo
|
|
22
|
+
* {imports, controllers ,services, exports }.
|
|
21
23
|
*/
|
|
22
|
-
getMetadataModule(module:
|
|
24
|
+
getMetadataModule(module: TClass): IModuleConfig;
|
|
23
25
|
/**
|
|
24
26
|
* Obtiene todas las dependencias asociadas con una clase.
|
|
25
27
|
*
|
|
26
|
-
* @param target - La función/clase objetivo.
|
|
28
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
27
29
|
* @returns Un objeto con las dependencias del target.
|
|
28
30
|
*/
|
|
29
|
-
getAllDependencies(target:
|
|
31
|
+
getAllDependencies(target: TClass): {
|
|
30
32
|
dClass: any;
|
|
31
33
|
dParam: any;
|
|
32
34
|
dInject: Map<string, string>;
|
|
@@ -34,73 +36,73 @@ export declare class Metadata {
|
|
|
34
36
|
/**
|
|
35
37
|
* Obtiene las dependencias de clase asociadas con una clase.
|
|
36
38
|
*
|
|
37
|
-
* @param target - La función/clase objetivo.
|
|
39
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
38
40
|
* @returns Las dependencias de clase de la clase.
|
|
39
41
|
*/
|
|
40
|
-
getClassDependencies(target:
|
|
42
|
+
getClassDependencies(target: TClass): any;
|
|
41
43
|
/**
|
|
42
44
|
* Obtiene las dependencias de parámetro asociadas con una clase.
|
|
43
45
|
*
|
|
44
|
-
* @param target - La función/clase objetivo.
|
|
46
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
45
47
|
* @returns Las dependencias de parámetro de la clase.
|
|
46
48
|
*/
|
|
47
|
-
getParameterDependencies(target:
|
|
49
|
+
getParameterDependencies(target: TClass): any;
|
|
48
50
|
/**
|
|
49
51
|
* Obtiene las dependencias a inyectar asociadas con una clase.
|
|
50
52
|
*
|
|
51
|
-
* @param target - La función/clase objetivo.
|
|
53
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
52
54
|
* @returns Un Map con las dependencias a inyectar de la clase.
|
|
53
55
|
*/
|
|
54
|
-
getInjectionDependencies(target:
|
|
56
|
+
getInjectionDependencies(target: TClass): Map<string, string>;
|
|
55
57
|
/**
|
|
56
58
|
* Determina el tipo de una clase basado en sus metadatos.
|
|
57
59
|
*
|
|
58
|
-
* @param target - La función/clase objetivo.
|
|
60
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
59
61
|
* @returns Una cadena de texto que indica el tipo del clase segun el mapa de metadata.
|
|
60
62
|
* @throws {Error} Lanza un error si el tipo de la clase es desconocido.
|
|
61
63
|
*/
|
|
62
|
-
determineType(target:
|
|
64
|
+
determineType(target: TClass): string;
|
|
63
65
|
/**
|
|
64
66
|
* Verifica si una clase tiene un metadato específico.
|
|
65
67
|
*
|
|
66
68
|
* @param metadataKey - La llave del metadato a verificar.
|
|
67
|
-
* @param target - La función/clase objetivo.
|
|
69
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
68
70
|
* @returns Verdadero si el target tiene el metadato, falso en caso contrario.
|
|
69
71
|
*/
|
|
70
72
|
private hasMetadata;
|
|
71
73
|
/**
|
|
72
74
|
* Verifica si una clase es de tipo "module".
|
|
73
75
|
*
|
|
74
|
-
* @param target - La función/clase objetivo.
|
|
76
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
75
77
|
* @returns Verdadero si el target es de tipo "module", falso en caso contrario.
|
|
76
78
|
*/
|
|
77
|
-
isTypeModule(target:
|
|
79
|
+
isTypeModule(target: TClass): boolean;
|
|
78
80
|
/**
|
|
79
81
|
* Verifica si una clase es de tipo "import".
|
|
80
82
|
*
|
|
81
|
-
* @param target - La función/clase objetivo.
|
|
83
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
82
84
|
* @returns Verdadero si el target es de tipo "import", falso en caso contrario.
|
|
83
85
|
*/
|
|
84
|
-
isTypeImport(target:
|
|
86
|
+
isTypeImport(target: TClass): boolean;
|
|
85
87
|
/**
|
|
86
88
|
* Verifica si una clase es de tipo "controller".
|
|
87
89
|
*
|
|
88
|
-
* @param target - La función/clase objetivo.
|
|
90
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
89
91
|
* @returns Verdadero si el target es de tipo "controller", falso en caso contrario.
|
|
90
92
|
*/
|
|
91
|
-
isTypeController(target:
|
|
93
|
+
isTypeController(target: TClass): boolean;
|
|
92
94
|
/**
|
|
93
95
|
* Verifica si una clase es de tipo "service".
|
|
94
96
|
*
|
|
95
|
-
* @param target - La función/clase objetivo.
|
|
97
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
96
98
|
* @returns Verdadero si el target es de tipo "service", falso en caso contrario.
|
|
97
99
|
*/
|
|
98
|
-
isTypeService(target:
|
|
100
|
+
isTypeService(target: TClass): boolean;
|
|
99
101
|
/**
|
|
100
102
|
* Verifica si una clase es de tipo "export".
|
|
101
103
|
*
|
|
102
|
-
* @param target - La función/clase objetivo.
|
|
104
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
103
105
|
* @returns Verdadero si el target es de tipo "export", falso en caso contrario.
|
|
104
106
|
*/
|
|
105
|
-
isTypeExports(target:
|
|
107
|
+
isTypeExports(target: TClass): boolean;
|
|
106
108
|
}
|
package/metadata.js
CHANGED
|
@@ -9,11 +9,11 @@ const constants_1 = require("@zanobijs/common/utils/constants");
|
|
|
9
9
|
class Metadata {
|
|
10
10
|
static instance;
|
|
11
11
|
metadataMap = {
|
|
12
|
-
[constants_1.IS_MODULE]:
|
|
13
|
-
[constants_1.IS_IMPORTS]:
|
|
14
|
-
[constants_1.IS_CONTROLLER]:
|
|
15
|
-
[constants_1.IS_SERVICE]:
|
|
16
|
-
[constants_1.IS_EXPORT]:
|
|
12
|
+
[constants_1.IS_MODULE]: 'module',
|
|
13
|
+
[constants_1.IS_IMPORTS]: 'import',
|
|
14
|
+
[constants_1.IS_CONTROLLER]: 'controller',
|
|
15
|
+
[constants_1.IS_SERVICE]: 'service',
|
|
16
|
+
[constants_1.IS_EXPORT]: 'export',
|
|
17
17
|
};
|
|
18
18
|
constructor() { }
|
|
19
19
|
/**
|
|
@@ -30,8 +30,9 @@ class Metadata {
|
|
|
30
30
|
/**
|
|
31
31
|
* Obtiene los metadatos de un módulo específico.
|
|
32
32
|
*
|
|
33
|
-
* @param module - El módulo del cual obtener los metadatos.
|
|
34
|
-
* @returns Un objeto con los metadatos del módulo
|
|
33
|
+
* @param { IModuleConfig } module - El módulo del cual obtener los metadatos.
|
|
34
|
+
* @returns Un objeto con los metadatos del módulo
|
|
35
|
+
* {imports, controllers ,services, exports }.
|
|
35
36
|
*/
|
|
36
37
|
getMetadataModule(module) {
|
|
37
38
|
return {
|
|
@@ -44,7 +45,7 @@ class Metadata {
|
|
|
44
45
|
/**
|
|
45
46
|
* Obtiene todas las dependencias asociadas con una clase.
|
|
46
47
|
*
|
|
47
|
-
* @param target - La función/clase objetivo.
|
|
48
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
48
49
|
* @returns Un objeto con las dependencias del target.
|
|
49
50
|
*/
|
|
50
51
|
getAllDependencies(target) {
|
|
@@ -57,7 +58,7 @@ class Metadata {
|
|
|
57
58
|
/**
|
|
58
59
|
* Obtiene las dependencias de clase asociadas con una clase.
|
|
59
60
|
*
|
|
60
|
-
* @param target - La función/clase objetivo.
|
|
61
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
61
62
|
* @returns Las dependencias de clase de la clase.
|
|
62
63
|
*/
|
|
63
64
|
getClassDependencies(target) {
|
|
@@ -66,7 +67,7 @@ class Metadata {
|
|
|
66
67
|
/**
|
|
67
68
|
* Obtiene las dependencias de parámetro asociadas con una clase.
|
|
68
69
|
*
|
|
69
|
-
* @param target - La función/clase objetivo.
|
|
70
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
70
71
|
* @returns Las dependencias de parámetro de la clase.
|
|
71
72
|
*/
|
|
72
73
|
getParameterDependencies(target) {
|
|
@@ -75,7 +76,7 @@ class Metadata {
|
|
|
75
76
|
/**
|
|
76
77
|
* Obtiene las dependencias a inyectar asociadas con una clase.
|
|
77
78
|
*
|
|
78
|
-
* @param target - La función/clase objetivo.
|
|
79
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
79
80
|
* @returns Un Map con las dependencias a inyectar de la clase.
|
|
80
81
|
*/
|
|
81
82
|
getInjectionDependencies(target) {
|
|
@@ -84,7 +85,7 @@ class Metadata {
|
|
|
84
85
|
/**
|
|
85
86
|
* Determina el tipo de una clase basado en sus metadatos.
|
|
86
87
|
*
|
|
87
|
-
* @param target - La función/clase objetivo.
|
|
88
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
88
89
|
* @returns Una cadena de texto que indica el tipo del clase segun el mapa de metadata.
|
|
89
90
|
* @throws {Error} Lanza un error si el tipo de la clase es desconocido.
|
|
90
91
|
*/
|
|
@@ -100,7 +101,7 @@ class Metadata {
|
|
|
100
101
|
* Verifica si una clase tiene un metadato específico.
|
|
101
102
|
*
|
|
102
103
|
* @param metadataKey - La llave del metadato a verificar.
|
|
103
|
-
* @param target - La función/clase objetivo.
|
|
104
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
104
105
|
* @returns Verdadero si el target tiene el metadato, falso en caso contrario.
|
|
105
106
|
*/
|
|
106
107
|
hasMetadata(metadataKey, target) {
|
|
@@ -109,7 +110,7 @@ class Metadata {
|
|
|
109
110
|
/**
|
|
110
111
|
* Verifica si una clase es de tipo "module".
|
|
111
112
|
*
|
|
112
|
-
* @param target - La función/clase objetivo.
|
|
113
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
113
114
|
* @returns Verdadero si el target es de tipo "module", falso en caso contrario.
|
|
114
115
|
*/
|
|
115
116
|
isTypeModule(target) {
|
|
@@ -118,7 +119,7 @@ class Metadata {
|
|
|
118
119
|
/**
|
|
119
120
|
* Verifica si una clase es de tipo "import".
|
|
120
121
|
*
|
|
121
|
-
* @param target - La función/clase objetivo.
|
|
122
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
122
123
|
* @returns Verdadero si el target es de tipo "import", falso en caso contrario.
|
|
123
124
|
*/
|
|
124
125
|
isTypeImport(target) {
|
|
@@ -127,7 +128,7 @@ class Metadata {
|
|
|
127
128
|
/**
|
|
128
129
|
* Verifica si una clase es de tipo "controller".
|
|
129
130
|
*
|
|
130
|
-
* @param target - La función/clase objetivo.
|
|
131
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
131
132
|
* @returns Verdadero si el target es de tipo "controller", falso en caso contrario.
|
|
132
133
|
*/
|
|
133
134
|
isTypeController(target) {
|
|
@@ -136,7 +137,7 @@ class Metadata {
|
|
|
136
137
|
/**
|
|
137
138
|
* Verifica si una clase es de tipo "service".
|
|
138
139
|
*
|
|
139
|
-
* @param target - La función/clase objetivo.
|
|
140
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
140
141
|
* @returns Verdadero si el target es de tipo "service", falso en caso contrario.
|
|
141
142
|
*/
|
|
142
143
|
isTypeService(target) {
|
|
@@ -145,7 +146,7 @@ class Metadata {
|
|
|
145
146
|
/**
|
|
146
147
|
* Verifica si una clase es de tipo "export".
|
|
147
148
|
*
|
|
148
|
-
* @param target - La función/clase objetivo.
|
|
149
|
+
* @param { TClass } target - La función/clase objetivo.
|
|
149
150
|
* @returns Verdadero si el target es de tipo "export", falso en caso contrario.
|
|
150
151
|
*/
|
|
151
152
|
isTypeExports(target) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zanobijs/core",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-beta.0",
|
|
4
4
|
"description": "Zanobi - modern, small, powerful node.js lambda framework (@core)",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "John Edison Cortes Rivera [Devdroide] <johne.aplicativos@gmail.com>",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@zanobijs/common": "*"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "4ad8ac9c4b576e84a3cbd94bb4bd8f7c3151375c"
|
|
33
33
|
}
|