@zanobijs/core 1.0.0-beta.4 → 1.0.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 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
- # [1.0.0-beta.4](https://github.com/devdroide/ZanobiJS/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2024-04-12)
6
+ # [1.0.0](https://github.com/devdroide/ZanobiJS/compare/v1.0.0-beta.5...v1.0.0) (2024-05-31)
7
7
 
8
8
  **Note:** Version bump only for package @zanobijs/core
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <H1 align="center">Welcome to ZanobiJS</H1>
6
6
 
7
7
  [![npm](https://img.shields.io/badge/npm-v1.0.0-darkorange.svg)](https://www.npmjs.com/package/@zanobijs/cli)
8
- [![coverage](https://img.shields.io/badge/coverage-98-green.svg)](https://mochajs.org/)
8
+ [![coverage](https://img.shields.io/badge/coverage-100-green.svg)](https://mochajs.org/)
9
9
  [![test](https://img.shields.io/badge/test-mocha-CC0000.svg)](https://mochajs.org/)
10
10
  [![nodejs](https://img.shields.io/badge/nodejs->=16.0.0-darkgreen.svg)](https://nodejs.org)
11
11
  [![typescrit](https://img.shields.io/badge/TS->=5.2.2-darkblue.svg)](https://www.typescriptlang.org/)
@@ -1,2 +1,3 @@
1
1
  export declare const MODULE_INVALID_ANNOTATION_ERROR: () => string;
2
- export declare const CONTAINER_RESOLUTION_ERROR: (entity: string) => string;
2
+ export declare const CONTAINER_RESOLUTION_ERROR: (entity: string, resolutionError: string) => string;
3
+ export declare const CONTAINER_RESOLUTION_ENTITY_ERROR: (entity: string) => string;
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONTAINER_RESOLUTION_ERROR = exports.MODULE_INVALID_ANNOTATION_ERROR = void 0;
3
+ exports.CONTAINER_RESOLUTION_ENTITY_ERROR = exports.CONTAINER_RESOLUTION_ERROR = exports.MODULE_INVALID_ANNOTATION_ERROR = void 0;
4
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
- const CONTAINER_RESOLUTION_ERROR = (entity) => `'${entity}' is not registered in any @module.`;
6
+ const CONTAINER_RESOLUTION_ERROR = (entity, resolutionError) => `${resolutionError} please review '${entity}' and its dependencies.`;
7
7
  exports.CONTAINER_RESOLUTION_ERROR = CONTAINER_RESOLUTION_ERROR;
8
- // export const CONTAINER_RESOLUTION_INJECT_ERROR = (
9
- // entity: string,
10
- // targetName: any,
11
- // ) =>
12
- // `'@Inject(${entity})' was not found in any loaded @module. Check the "${targetName}" file`;
8
+ const CONTAINER_RESOLUTION_ENTITY_ERROR = (entity) => `Please check that the entity '${entity}' exists and is registered in @modulo`;
9
+ exports.CONTAINER_RESOLUTION_ENTITY_ERROR = CONTAINER_RESOLUTION_ENTITY_ERROR;
@@ -1,4 +1,20 @@
1
1
  import { RuntimeException } from "@zanobijs/common/exceptions/runtime.exception";
2
+ /**
3
+ * Excepción lanzada cuando se intenta obtener una dependencia
4
+ * de un controlador o servicio y esta no fue registrada
5
+ * en un modulo
6
+ *
7
+ * @remarks
8
+ * Esta clase extiende la base `RuntimeException`de @zanobijs/core
9
+ * para proporcionar detalles adicionales del error.
10
+ *
11
+ * @example
12
+ * private service1: Service1
13
+ * @Module{... services:["otherService"]}
14
+ */
15
+ export declare class ContainerResolutionException extends RuntimeException {
16
+ constructor(entity: string, resolutionError: string, detail: any);
17
+ }
2
18
  /**
3
19
  * Excepción lanzada cuando se intenta obtener una entidad
4
20
  * (importar, controlador, servicio o exportar) que no fue
@@ -8,6 +24,6 @@ import { RuntimeException } from "@zanobijs/common/exceptions/runtime.exception"
8
24
  * Esta clase extiende la base `RuntimeException`de @zanobijs/core
9
25
  * para proporcionar detalles adicionales del error.
10
26
  */
11
- export declare class ContainerResolutionException extends RuntimeException {
27
+ export declare class ContainerResolutionEntityException extends RuntimeException {
12
28
  constructor(entity: string, detail: any);
13
29
  }
@@ -1,8 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContainerResolutionException = void 0;
3
+ exports.ContainerResolutionEntityException = exports.ContainerResolutionException = void 0;
4
4
  const runtime_exception_1 = require("@zanobijs/common/exceptions/runtime.exception");
5
5
  const constant_message_1 = require("./constant.message");
6
+ /**
7
+ * Excepción lanzada cuando se intenta obtener una dependencia
8
+ * de un controlador o servicio y esta no fue registrada
9
+ * en un modulo
10
+ *
11
+ * @remarks
12
+ * Esta clase extiende la base `RuntimeException`de @zanobijs/core
13
+ * para proporcionar detalles adicionales del error.
14
+ *
15
+ * @example
16
+ * private service1: Service1
17
+ * @Module{... services:["otherService"]}
18
+ */
19
+ class ContainerResolutionException extends runtime_exception_1.RuntimeException {
20
+ constructor(entity, resolutionError, detail) {
21
+ super((0, constant_message_1.CONTAINER_RESOLUTION_ERROR)(entity, resolutionError), detail);
22
+ }
23
+ }
24
+ exports.ContainerResolutionException = ContainerResolutionException;
6
25
  /**
7
26
  * Excepción lanzada cuando se intenta obtener una entidad
8
27
  * (importar, controlador, servicio o exportar) que no fue
@@ -12,14 +31,9 @@ const constant_message_1 = require("./constant.message");
12
31
  * Esta clase extiende la base `RuntimeException`de @zanobijs/core
13
32
  * para proporcionar detalles adicionales del error.
14
33
  */
15
- class ContainerResolutionException extends runtime_exception_1.RuntimeException {
34
+ class ContainerResolutionEntityException extends runtime_exception_1.RuntimeException {
16
35
  constructor(entity, detail) {
17
- super((0, constant_message_1.CONTAINER_RESOLUTION_ERROR)(entity), detail);
36
+ super((0, constant_message_1.CONTAINER_RESOLUTION_ENTITY_ERROR)(entity), detail);
18
37
  }
19
38
  }
20
- exports.ContainerResolutionException = ContainerResolutionException;
21
- // export class ContainerInjectResolutionException extends RuntimeException {
22
- // constructor(entity: string, targetName: any, detail: any = ``) {
23
- // super(CONTAINER_RESOLUTION_INJECT_ERROR(entity, targetName), detail);
24
- // }
25
- // }
39
+ exports.ContainerResolutionEntityException = ContainerResolutionEntityException;
package/factory.d.ts CHANGED
@@ -37,5 +37,5 @@ export declare class Factory {
37
37
  * @returns {any} - Instancia resuelta.
38
38
  */
39
39
  get<T>(entity: string): T;
40
- evaluateOptions(): void;
40
+ private evaluateOptions;
41
41
  }
package/factory.js CHANGED
@@ -19,6 +19,8 @@ class Factory {
19
19
  logger;
20
20
  options;
21
21
  constructor(appModule, options = {}) {
22
+ process.env.ZANOBIJS_LOGGER = "false";
23
+ process.env.ZANOBIJS_LOGGER_USER = "false";
22
24
  this.options = options;
23
25
  this.evaluateOptions();
24
26
  this.logger = (0, utils_1.Logger)();
@@ -32,6 +34,7 @@ class Factory {
32
34
  * @private
33
35
  */
34
36
  registerClassesFromModule(module) {
37
+ this.logger.debug("Factory - Registering classes for module:", module.name);
35
38
  this.registerFromModule(module);
36
39
  const importedModules = this.moduleHandler.getImports();
37
40
  if (importedModules && importedModules.length) {
@@ -46,9 +49,13 @@ class Factory {
46
49
  * @private
47
50
  */
48
51
  registerFromModule(module) {
52
+ this.logger.debug("Factory - Setup:", module.name);
49
53
  this.moduleHandler.setup(module);
54
+ this.logger.debug("Factory - Initialize:", module.name);
50
55
  this.moduleHandler.initialize();
51
56
  Object.assign(this.registeredClasses, this.moduleHandler.getRegisterClass());
57
+ this.logger.success("Factory - Completion of module ", module.name);
58
+ this.logger.debug("===================================================");
52
59
  }
53
60
  /**
54
61
  * Crea el contenedor de inyección de dependencias y registra las clases.
@@ -57,7 +64,7 @@ class Factory {
57
64
  create() {
58
65
  this.container = (0, awilix_1.createContainer)({ injectionMode: awilix_1.InjectionMode.CLASSIC });
59
66
  this.container.register(this.registeredClasses);
60
- this.logger.info("Registered Classes", this.registeredClasses);
67
+ this.logger.info("Factory - classes and providers registered in the container", Object.keys(this.registeredClasses));
61
68
  return this;
62
69
  }
63
70
  /**
@@ -71,14 +78,19 @@ class Factory {
71
78
  }
72
79
  catch (error) {
73
80
  this.logger.info("Error resolving entity: ", error.message + "\n");
74
- throw new resolution_exception_1.ContainerResolutionException(entity, error.message);
81
+ const resolutionError = error.message.split("\n");
82
+ const EntityFound = resolutionError[0].match(/'([^']+)'/);
83
+ if (EntityFound[1] === entity) {
84
+ throw new resolution_exception_1.ContainerResolutionEntityException(entity, error.message);
85
+ }
86
+ throw new resolution_exception_1.ContainerResolutionException(entity, resolutionError[0], error.message);
75
87
  }
76
88
  }
77
89
  evaluateOptions() {
78
90
  if (this.options.activeLoggerSystem)
79
91
  process.env.ZANOBIJS_LOGGER = "true";
80
92
  if (this.options.activeLoggerUser)
81
- process.env.ZANOBIJS_LOGGER = "true";
93
+ process.env.ZANOBIJS_LOGGER_USER = "true";
82
94
  }
83
95
  }
84
96
  exports.Factory = Factory;
@@ -10,7 +10,6 @@ export declare class Injector {
10
10
  private listProviders;
11
11
  private metadata;
12
12
  private logger;
13
- private registeredClassParentModule;
14
13
  private moduleName;
15
14
  /**
16
15
  * En Constructor de la clase Injector obtenermos las instancias
@@ -18,7 +17,7 @@ export declare class Injector {
18
17
  * @param {Module} module - El módulo debe tener el decorador `@Module`
19
18
  * para poderlo procesar.
20
19
  */
21
- constructor(module: any);
20
+ constructor(module: any, listProviders: Map<string, any>);
22
21
  /**
23
22
  * Este método privado recorre el array de los servicios del modulo para
24
23
  * buscar los proveedores tipo objeto a injectar y los almacena en una
@@ -26,7 +25,6 @@ export declare class Injector {
26
25
  * @private
27
26
  */
28
27
  private scanProviders;
29
- setRegisteredClassParentModule(registerClass: any): void;
30
28
  /**
31
29
  * Método para obtener un objeto con los parámetros y valores
32
30
  * que se inyectarán en la clase (target).
@@ -41,7 +39,7 @@ export declare class Injector {
41
39
  * @param {any} target - La clase objetivo.
42
40
  * @returns - El injector configurado.
43
41
  */
44
- getInjector(target: any): {
42
+ getInjectorClass(target: any): {
45
43
  interface: any;
46
44
  injectionMode?: import("awilix").InjectionModeType;
47
45
  injector?: import("awilix").InjectorFunction;
@@ -61,6 +59,7 @@ export declare class Injector {
61
59
  dispose?: import("awilix").Disposer<object>;
62
60
  disposer(dispose: import("awilix").Disposer<object>): import("awilix").BuildResolver<object> & import("awilix").DisposableResolver<object>;
63
61
  };
64
- getAllProvider(): Map<any, any>;
62
+ getAllProvider(): Map<string, any>;
65
63
  getInjectProvider(provider: any): import("awilix").Resolver<any>;
64
+ funtionInjectData(injectData: any): () => any;
66
65
  }
@@ -11,10 +11,9 @@ const awilix_1 = require("awilix");
11
11
  */
12
12
  class Injector {
13
13
  module;
14
- listProviders = new Map();
14
+ listProviders;
15
15
  metadata;
16
16
  logger;
17
- registeredClassParentModule = {};
18
17
  moduleName = "";
19
18
  /**
20
19
  * En Constructor de la clase Injector obtenermos las instancias
@@ -22,11 +21,12 @@ class Injector {
22
21
  * @param {Module} module - El módulo debe tener el decorador `@Module`
23
22
  * para poderlo procesar.
24
23
  */
25
- constructor(module) {
24
+ constructor(module, listProviders) {
26
25
  this.metadata = metadata_1.Metadata.getInstance();
27
26
  this.logger = (0, utils_1.Logger)();
28
27
  this.moduleName = module.name;
29
28
  this.module = module;
29
+ this.listProviders = listProviders;
30
30
  this.scanProviders();
31
31
  }
32
32
  /**
@@ -36,6 +36,7 @@ class Injector {
36
36
  * @private
37
37
  */
38
38
  scanProviders() {
39
+ this.logger.debug("Injector - Scan provider to module:", this.moduleName);
39
40
  const { services } = this.metadata.getMetadataModule(this.module);
40
41
  services.forEach((service) => {
41
42
  if (typeof service === "object")
@@ -43,9 +44,6 @@ class Injector {
43
44
  });
44
45
  this.logger.debug("Injector - list provider", this.listProviders);
45
46
  }
46
- setRegisteredClassParentModule(registerClass) {
47
- this.registeredClassParentModule = registerClass;
48
- }
49
47
  /**
50
48
  * Método para obtener un objeto con los parámetros y valores
51
49
  * que se inyectarán en la clase (target).
@@ -59,21 +57,13 @@ class Injector {
59
57
  if (dInject.size > 0) {
60
58
  for (const key of dInject.keys()) {
61
59
  if (this.listProviders.has(key)) {
62
- this.logger.info(`"${key}" is on providers list.`);
63
60
  const paramName = dInject.get(key);
64
61
  const useValue = this.listProviders.get(key);
65
62
  injectData[paramName] = useValue;
66
63
  }
67
64
  else {
68
- if (key in this.registeredClassParentModule) {
69
- this.logger.info(`"${key}" is on registered Class in Parent Module.`);
70
- const paramName = dInject.get(key);
71
- injectData[paramName] = (0, awilix_1.aliasTo)(key);
72
- }
73
- else {
74
- this.logger.important(`It is injecting @INJECT('${key}') provider in '${target.name}' but is not registered in '${this.moduleName}' or in previously loaded @modules`);
75
- // throw new ContainerInjectResolutionException(key, target.name);
76
- }
65
+ this.logger.important(`It is injecting @INJECT('${key}') provider in '${target.name}' but is not registered in '${this.moduleName}' or in previously loaded @modules`);
66
+ // throw new ContainerInjectResolutionException(key, target.name);
77
67
  }
78
68
  }
79
69
  }
@@ -85,11 +75,12 @@ class Injector {
85
75
  * @param {any} target - La clase objetivo.
86
76
  * @returns - El injector configurado.
87
77
  */
88
- getInjector(target) {
78
+ getInjectorClass(target) {
89
79
  const injectData = this.getInjectData(target);
90
80
  let injector = (0, awilix_1.asClass)(target).scoped();
91
81
  if (!(0, shared_utils_1.isEmpty)(injectData)) {
92
- injector = injector.inject(() => injectData);
82
+ this.logger.debug(`Inject - list dependencies to inject of ${target.name}:`, injectData);
83
+ injector = injector.inject(this.funtionInjectData(injectData));
93
84
  }
94
85
  return {
95
86
  ...injector,
@@ -104,5 +95,8 @@ class Injector {
104
95
  ? (0, awilix_1.asFunction)(provider.value).scoped()
105
96
  : (0, awilix_1.asValue)(provider.value);
106
97
  }
98
+ funtionInjectData(injectData) {
99
+ return () => injectData;
100
+ }
107
101
  }
108
102
  exports.Injector = Injector;
@@ -11,6 +11,7 @@ export declare class Module {
11
11
  private dependenciesClass;
12
12
  private metadata;
13
13
  private types;
14
+ private listProviders;
14
15
  /**
15
16
  * Constructor del módulo.
16
17
  */
@@ -20,6 +20,7 @@ class Module {
20
20
  dependenciesClass = [];
21
21
  metadata;
22
22
  types = ["controller", "service"];
23
+ listProviders = new Map();
23
24
  /**
24
25
  * Constructor del módulo.
25
26
  */
@@ -34,7 +35,8 @@ class Module {
34
35
  setup(module) {
35
36
  if (this.metadata.isTypeModule(module)) {
36
37
  this.module = module;
37
- this.injector = new injector_1.Injector(module);
38
+ this.logger.debug("Module - Create Injector to module:", module.name);
39
+ this.injector = new injector_1.Injector(module, this.listProviders);
38
40
  }
39
41
  else {
40
42
  throw new exceptions_1.InvalidModuleAnnotationException();
@@ -44,9 +46,9 @@ class Module {
44
46
  * Inicializa el módulo extrayendo metadatos y registrando las entidades.
45
47
  */
46
48
  initialize() {
47
- this.getMetadataModule();
49
+ this.logger.debug("Module - Initialize:", this.module.name);
48
50
  this.registerAllProviders();
49
- this.injector.setRegisteredClassParentModule(this.registerClass);
51
+ this.getMetadataModule();
50
52
  this.registerDependencies();
51
53
  this.registerDependenciesToAlias();
52
54
  }
@@ -72,6 +74,7 @@ class Module {
72
74
  */
73
75
  registerEntities(entityType) {
74
76
  const entities = this.config[entityType];
77
+ this.logger.debug("Module - ..... searching for entities type ", entityType);
75
78
  if (entities && entities.length > 0) {
76
79
  const registeredEntities = entities
77
80
  .filter((target) => {
@@ -79,15 +82,19 @@ class Module {
79
82
  this.types.includes(this.metadata.determineType(target)));
80
83
  })
81
84
  .map((target) => {
85
+ this.logger.debug(`Module - Entity <<< ${target.name} >>>`);
82
86
  this.groupDependenciesForAlias(target);
83
87
  const targetName = (0, shared_utils_1.unCapitalize)(target.name);
84
88
  return {
85
- [target.name]: this.injector.getInjector(target),
89
+ [target.name]: this.injector.getInjectorClass(target),
86
90
  [targetName]: (0, awilix_1.aliasTo)(target.name),
87
91
  };
88
92
  });
89
93
  Object.assign(this.registerClass, ...registeredEntities);
90
94
  }
95
+ else {
96
+ this.logger.debug("Module - Does not have entities of that type", entityType);
97
+ }
91
98
  }
92
99
  /**
93
100
  * Agrupación de dependencias para alias
@@ -103,6 +110,7 @@ class Module {
103
110
  */
104
111
  groupDependenciesForAlias(target) {
105
112
  const dependencies = this.metadata.getClassDependencies(target);
113
+ this.logger.debug(`Module - List dependecies of ${target.name}`, dependencies);
106
114
  if (dependencies && !(0, shared_utils_1.isEmpty)(dependencies)) {
107
115
  this.dependenciesClass = [...this.dependenciesClass, ...dependencies];
108
116
  }
@@ -117,6 +125,7 @@ class Module {
117
125
  * contructor(private sA: ServiceA) // parametro con nombre diferente
118
126
  */
119
127
  registerDependenciesToAlias() {
128
+ this.logger.debug("Module - dependencies to register as candidates ", this.dependenciesClass);
120
129
  this.dependenciesClass.forEach((dependency) => {
121
130
  if (!this.registerClass[dependency.nameParameter]) {
122
131
  this.registerClass[dependency.nameParameter] = (0, awilix_1.aliasTo)(dependency.nameClassContainer);
@@ -124,6 +133,7 @@ class Module {
124
133
  });
125
134
  }
126
135
  registerAllProviders() {
136
+ this.logger.debug("Module - Register list provider:", this.module.name);
127
137
  const listProviders = this.injector.getAllProvider();
128
138
  listProviders.forEach((value, key) => {
129
139
  const providerInject = this.injector.getInjectProvider({
@@ -131,7 +141,7 @@ class Module {
131
141
  value,
132
142
  });
133
143
  this.registerClass[key] = providerInject;
134
- this.registerClass[(0, shared_utils_1.snakeToCamel)(key)] = (0, awilix_1.aliasTo)(key);
144
+ // this.registerClass[snakeToCamel(key)] = aliasTo(key);
135
145
  });
136
146
  }
137
147
  /**
@@ -146,7 +156,7 @@ class Module {
146
156
  * @returns {any} - Clases registradas.
147
157
  */
148
158
  getRegisterClass() {
149
- this.logger.debug("Module - register class", this.registerClass);
159
+ this.logger.debug("Module - List of candidate classes to register in container.", this.registerClass);
150
160
  return this.registerClass;
151
161
  }
152
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zanobijs/core",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.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": "fd630539d6115c6aa87037f5839011c9e6e42384"
32
+ "gitHead": "4905088f3170f544437adf304d28cb4f264902b9"
33
33
  }