@zanobijs/core 1.0.0-beta.3 → 1.0.0-beta.5
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/README.md +37 -11
- package/exceptions/constant.message.d.ts +2 -1
- package/exceptions/constant.message.js +4 -2
- package/exceptions/resolution.exception.d.ts +18 -2
- package/exceptions/resolution.exception.js +24 -5
- package/factory.d.ts +5 -1
- package/factory.js +29 -5
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/injector/injector.d.ts +7 -2
- package/injector/injector.js +24 -5
- package/injector/module.d.ts +2 -0
- package/injector/module.js +33 -5
- package/interfaces/factory.interface.d.ts +4 -0
- package/interfaces/factory.interface.js +2 -0
- package/interfaces/index.d.ts +1 -0
- package/{__test__/mocks → interfaces}/index.js +1 -1
- package/package.json +3 -4
- package/tsconfig.build.json +1 -1
- package/__test__/factory.spec.d.ts +0 -1
- package/__test__/factory.spec.js +0 -63
- package/__test__/injector/injector.spec.d.ts +0 -1
- package/__test__/injector/injector.spec.js +0 -32
- package/__test__/injector/module.spec.d.ts +0 -1
- package/__test__/injector/module.spec.js +0 -60
- package/__test__/metadata.spec.d.ts +0 -1
- package/__test__/metadata.spec.js +0 -70
- package/__test__/mocks/classModule.mock.d.ts +0 -10
- package/__test__/mocks/classModule.mock.js +0 -74
- package/__test__/mocks/classWithDependeciesClass.mock.d.ts +0 -13
- package/__test__/mocks/classWithDependeciesClass.mock.js +0 -40
- package/__test__/mocks/classWithDependeciesInject.mock.d.ts +0 -24
- package/__test__/mocks/classWithDependeciesInject.mock.js +0 -74
- package/__test__/mocks/index.d.ts +0 -1
- package/interface/index.d.ts +0 -0
- package/interface/index.js +0 -1
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.
|
|
6
|
+
# [1.0.0-beta.5](https://github.com/devdroide/ZanobiJS/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2024-04-15)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @zanobijs/core
|
package/README.md
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://zanobijs.vercel.app/" target="blank"><img src="https://zanobijs.vercel.app/_astro/ZanobiHero.__7I9OCQ_ZkaY1J.webp" width="120" alt="ZanobiJS Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<H1 align="center">Welcome to ZanobiJS</H1>
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@zanobijs/cli)
|
|
8
|
+
[](https://mochajs.org/)
|
|
9
|
+
[](https://mochajs.org/)
|
|
10
|
+
[](https://nodejs.org)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
12
|
+
[](https://en.wikipedia.org/wiki/MIT_License)
|
|
13
|
+
[](https://zanobijs.vercel.app/)
|
|
2
14
|
|
|
3
15
|
It is a mini-framework for Node.js that allows you to build server-side microservices in an efficient and scalable way. It is designed to be small and efficient, but powerful enough for enterprise applications. ZanobiJS is written in TypeScript and JavaScript, giving you the flexibility to choose the language you prefer.
|
|
4
16
|
## Features
|
|
@@ -8,6 +20,9 @@ It is a mini-framework for Node.js that allows you to build server-side microser
|
|
|
8
20
|
- Ideal for building server-side microservices.
|
|
9
21
|
- Optimized scalability and performance.
|
|
10
22
|
|
|
23
|
+
## Getting started
|
|
24
|
+
|
|
25
|
+
If you want to consult the [guide](https://zanobijs.vercel.app/en/) and learn about the project, visit [zanobijs.vercel.app](https://zanobijs.vercel.app/en/)
|
|
11
26
|
|
|
12
27
|
## Installation
|
|
13
28
|
|
|
@@ -136,6 +151,9 @@ bootstrap();
|
|
|
136
151
|
// thisClientAPI
|
|
137
152
|
// myKey12345API
|
|
138
153
|
```
|
|
154
|
+
> [!Note]
|
|
155
|
+
> It can also be used in [AWS lambda](https://zanobijs.vercel.app/en/01-getting-started/first-step/#setting), see how to do it in the [guide](https://zanobijs.vercel.app/en/01-getting-started/first-step/#setting)
|
|
156
|
+
|
|
139
157
|
## Use Logger
|
|
140
158
|
|
|
141
159
|
- Import logger service of @zanobij/common/utils.
|
|
@@ -144,17 +162,22 @@ bootstrap();
|
|
|
144
162
|
- Use the different events (success, info, warn, error, debug).
|
|
145
163
|
|
|
146
164
|
```javascript
|
|
147
|
-
|
|
165
|
+
// Index.ts - This is important for the operation
|
|
166
|
+
const factory = new Factory(AppModule, {
|
|
167
|
+
activeLoggerUser: true
|
|
168
|
+
});
|
|
148
169
|
|
|
149
|
-
|
|
170
|
+
// use en services controllers, etc
|
|
150
171
|
|
|
151
|
-
|
|
172
|
+
import { LoggerUser } from "@zanobijs/common/utils";
|
|
152
173
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
174
|
+
const logUser = LoggerUser();
|
|
175
|
+
|
|
176
|
+
logUser.success("Lorem ipsum success");
|
|
177
|
+
logUser.info("Lorem ipsum info");
|
|
178
|
+
logUser.warn("Lorem ipsum warn");
|
|
179
|
+
logUser.error("Lorem ipsum error");
|
|
180
|
+
logUser.debug("Lorem ipsum debug");
|
|
158
181
|
|
|
159
182
|
// ***** PRINT *****
|
|
160
183
|
// [SUCCESS]: Lorem ipsum success <green print>
|
|
@@ -171,9 +194,12 @@ logger.debug("Lorem ipsum debug");
|
|
|
171
194
|
|
|
172
195
|
## Credits
|
|
173
196
|
|
|
174
|
-
ZanobiJS is heavily inspired [NestJS](https://nestjs.com/) and [AngularJS](https://angularjs.org/).
|
|
197
|
+
ZanobiJS is heavily inspired by [NestJS](https://nestjs.com/) and [AngularJS](https://angularjs.org/).
|
|
198
|
+
|
|
199
|
+
Additionally, it is used [Awilix](https://github.com/jeffijoe/awilix#readme) which is a container for Extremely powerful and effective dependency injection.
|
|
200
|
+
|
|
201
|
+
Finally, it is an effort that we make and that we hope can help in the construction of projects.
|
|
175
202
|
|
|
176
|
-
Finally, it is an effort to provide help with the construction of lambdas initially.
|
|
177
203
|
## License
|
|
178
204
|
|
|
179
205
|
Private - Read License
|
|
@@ -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,7 +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) =>
|
|
6
|
+
const CONTAINER_RESOLUTION_ERROR = (entity, resolutionError) => `${resolutionError} please review '${entity}' and its dependencies.`;
|
|
7
7
|
exports.CONTAINER_RESOLUTION_ERROR = CONTAINER_RESOLUTION_ERROR;
|
|
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
|
|
12
|
-
constructor(entity: string, detail
|
|
27
|
+
export declare class ContainerResolutionEntityException extends RuntimeException {
|
|
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,9 +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
|
|
16
|
-
constructor(entity, detail
|
|
17
|
-
super((0, constant_message_1.
|
|
34
|
+
class ContainerResolutionEntityException extends runtime_exception_1.RuntimeException {
|
|
35
|
+
constructor(entity, detail) {
|
|
36
|
+
super((0, constant_message_1.CONTAINER_RESOLUTION_ENTITY_ERROR)(entity), detail);
|
|
18
37
|
}
|
|
19
38
|
}
|
|
20
|
-
exports.
|
|
39
|
+
exports.ContainerResolutionEntityException = ContainerResolutionEntityException;
|
package/factory.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
+
import { IFactoryOptions } from "./interfaces";
|
|
2
3
|
/**
|
|
3
4
|
* Factory es una clase que facilita la creación y configuración de
|
|
4
5
|
* contenedores de inyección de dependencias utilizando metadatos y
|
|
@@ -9,7 +10,9 @@ export declare class Factory {
|
|
|
9
10
|
private moduleHandler;
|
|
10
11
|
private registeredClasses;
|
|
11
12
|
private container;
|
|
12
|
-
|
|
13
|
+
private logger;
|
|
14
|
+
private options;
|
|
15
|
+
constructor(appModule: any, options?: IFactoryOptions);
|
|
13
16
|
/**
|
|
14
17
|
* Este método registra clases desde el módulo proporcionado
|
|
15
18
|
* y recorre sus importaciones de forma recursiva para registrar
|
|
@@ -34,4 +37,5 @@ export declare class Factory {
|
|
|
34
37
|
* @returns {any} - Instancia resuelta.
|
|
35
38
|
*/
|
|
36
39
|
get<T>(entity: string): T;
|
|
40
|
+
private evaluateOptions;
|
|
37
41
|
}
|
package/factory.js
CHANGED
|
@@ -4,8 +4,8 @@ exports.Factory = void 0;
|
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const awilix_1 = require("awilix");
|
|
6
6
|
const module_1 = require("./injector/module");
|
|
7
|
-
const shared_utils_1 = require("@zanobijs/common/utils/shared.utils");
|
|
8
7
|
const resolution_exception_1 = require("./exceptions/resolution.exception");
|
|
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
|
|
@@ -16,7 +16,14 @@ class Factory {
|
|
|
16
16
|
moduleHandler;
|
|
17
17
|
registeredClasses = {};
|
|
18
18
|
container;
|
|
19
|
-
|
|
19
|
+
logger;
|
|
20
|
+
options;
|
|
21
|
+
constructor(appModule, options = {}) {
|
|
22
|
+
process.env.ZANOBIJS_LOGGER = "false";
|
|
23
|
+
process.env.ZANOBIJS_LOGGER_USER = "false";
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.evaluateOptions();
|
|
26
|
+
this.logger = (0, utils_1.Logger)();
|
|
20
27
|
this.moduleHandler = new module_1.Module();
|
|
21
28
|
this.registerClassesFromModule(appModule);
|
|
22
29
|
}
|
|
@@ -27,6 +34,7 @@ class Factory {
|
|
|
27
34
|
* @private
|
|
28
35
|
*/
|
|
29
36
|
registerClassesFromModule(module) {
|
|
37
|
+
this.logger.debug("Factory - Registering classes for module:", module.name);
|
|
30
38
|
this.registerFromModule(module);
|
|
31
39
|
const importedModules = this.moduleHandler.getImports();
|
|
32
40
|
if (importedModules && importedModules.length) {
|
|
@@ -41,9 +49,13 @@ class Factory {
|
|
|
41
49
|
* @private
|
|
42
50
|
*/
|
|
43
51
|
registerFromModule(module) {
|
|
52
|
+
this.logger.debug("Factory - Setup:", module.name);
|
|
44
53
|
this.moduleHandler.setup(module);
|
|
54
|
+
this.logger.debug("Factory - Initialize:", module.name);
|
|
45
55
|
this.moduleHandler.initialize();
|
|
46
56
|
Object.assign(this.registeredClasses, this.moduleHandler.getRegisterClass());
|
|
57
|
+
this.logger.success("Factory - Completion of module ", module.name);
|
|
58
|
+
this.logger.debug("===================================================");
|
|
47
59
|
}
|
|
48
60
|
/**
|
|
49
61
|
* Crea el contenedor de inyección de dependencias y registra las clases.
|
|
@@ -52,6 +64,7 @@ class Factory {
|
|
|
52
64
|
create() {
|
|
53
65
|
this.container = (0, awilix_1.createContainer)({ injectionMode: awilix_1.InjectionMode.CLASSIC });
|
|
54
66
|
this.container.register(this.registeredClasses);
|
|
67
|
+
this.logger.info("Factory - classes and providers registered in the container", Object.keys(this.registeredClasses));
|
|
55
68
|
return this;
|
|
56
69
|
}
|
|
57
70
|
/**
|
|
@@ -61,12 +74,23 @@ class Factory {
|
|
|
61
74
|
*/
|
|
62
75
|
get(entity) {
|
|
63
76
|
try {
|
|
64
|
-
|
|
65
|
-
return this.container.resolve(entityUnCapitalize);
|
|
77
|
+
return this.container.resolve(entity);
|
|
66
78
|
}
|
|
67
79
|
catch (error) {
|
|
68
|
-
|
|
80
|
+
this.logger.info("Error resolving entity: ", error.message + "\n");
|
|
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);
|
|
69
87
|
}
|
|
70
88
|
}
|
|
89
|
+
evaluateOptions() {
|
|
90
|
+
if (this.options.activeLoggerSystem)
|
|
91
|
+
process.env.ZANOBIJS_LOGGER = "true";
|
|
92
|
+
if (this.options.activeLoggerUser)
|
|
93
|
+
process.env.ZANOBIJS_LOGGER_USER = "true";
|
|
94
|
+
}
|
|
71
95
|
}
|
|
72
96
|
exports.Factory = Factory;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,3 +5,4 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
var factory_1 = require("./factory");
|
|
6
6
|
Object.defineProperty(exports, "Factory", { enumerable: true, get: function () { return factory_1.Factory; } });
|
|
7
7
|
tslib_1.__exportStar(require("./injector"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./interfaces"), exports);
|
package/injector/injector.d.ts
CHANGED
|
@@ -10,13 +10,14 @@ export declare class Injector {
|
|
|
10
10
|
private listProviders;
|
|
11
11
|
private metadata;
|
|
12
12
|
private logger;
|
|
13
|
+
private moduleName;
|
|
13
14
|
/**
|
|
14
15
|
* En Constructor de la clase Injector obtenermos las instancias
|
|
15
16
|
* de Metadata y Logger e inciamos el escaneo de proveedores.
|
|
16
17
|
* @param {Module} module - El módulo debe tener el decorador `@Module`
|
|
17
18
|
* para poderlo procesar.
|
|
18
19
|
*/
|
|
19
|
-
constructor(module: any);
|
|
20
|
+
constructor(module: any, listProviders: Map<string, any>);
|
|
20
21
|
/**
|
|
21
22
|
* Este método privado recorre el array de los servicios del modulo para
|
|
22
23
|
* buscar los proveedores tipo objeto a injectar y los almacena en una
|
|
@@ -38,7 +39,7 @@ export declare class Injector {
|
|
|
38
39
|
* @param {any} target - La clase objetivo.
|
|
39
40
|
* @returns - El injector configurado.
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
getInjectorClass(target: any): {
|
|
42
43
|
interface: any;
|
|
43
44
|
injectionMode?: import("awilix").InjectionModeType;
|
|
44
45
|
injector?: import("awilix").InjectorFunction;
|
|
@@ -54,7 +55,11 @@ export declare class Injector {
|
|
|
54
55
|
name?: string;
|
|
55
56
|
lifetime?: import("awilix").LifetimeType;
|
|
56
57
|
register?: (...args: any[]) => import("awilix").Resolver<object>;
|
|
58
|
+
isLeakSafe?: boolean;
|
|
57
59
|
dispose?: import("awilix").Disposer<object>;
|
|
58
60
|
disposer(dispose: import("awilix").Disposer<object>): import("awilix").BuildResolver<object> & import("awilix").DisposableResolver<object>;
|
|
59
61
|
};
|
|
62
|
+
getAllProvider(): Map<string, any>;
|
|
63
|
+
getInjectProvider(provider: any): import("awilix").Resolver<any>;
|
|
64
|
+
funtionInjectData(injectData: any): () => any;
|
|
60
65
|
}
|
package/injector/injector.js
CHANGED
|
@@ -11,19 +11,22 @@ const awilix_1 = require("awilix");
|
|
|
11
11
|
*/
|
|
12
12
|
class Injector {
|
|
13
13
|
module;
|
|
14
|
-
listProviders
|
|
14
|
+
listProviders;
|
|
15
15
|
metadata;
|
|
16
16
|
logger;
|
|
17
|
+
moduleName = "";
|
|
17
18
|
/**
|
|
18
19
|
* En Constructor de la clase Injector obtenermos las instancias
|
|
19
20
|
* de Metadata y Logger e inciamos el escaneo de proveedores.
|
|
20
21
|
* @param {Module} module - El módulo debe tener el decorador `@Module`
|
|
21
22
|
* para poderlo procesar.
|
|
22
23
|
*/
|
|
23
|
-
constructor(module) {
|
|
24
|
+
constructor(module, listProviders) {
|
|
24
25
|
this.metadata = metadata_1.Metadata.getInstance();
|
|
25
26
|
this.logger = (0, utils_1.Logger)();
|
|
27
|
+
this.moduleName = module.name;
|
|
26
28
|
this.module = module;
|
|
29
|
+
this.listProviders = listProviders;
|
|
27
30
|
this.scanProviders();
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
@@ -33,6 +36,7 @@ class Injector {
|
|
|
33
36
|
* @private
|
|
34
37
|
*/
|
|
35
38
|
scanProviders() {
|
|
39
|
+
this.logger.debug("Injector - Scan provider to module:", this.moduleName);
|
|
36
40
|
const { services } = this.metadata.getMetadataModule(this.module);
|
|
37
41
|
services.forEach((service) => {
|
|
38
42
|
if (typeof service === "object")
|
|
@@ -53,11 +57,14 @@ class Injector {
|
|
|
53
57
|
if (dInject.size > 0) {
|
|
54
58
|
for (const key of dInject.keys()) {
|
|
55
59
|
if (this.listProviders.has(key)) {
|
|
56
|
-
this.logger.info(`"${key}" is on providers list.`);
|
|
57
60
|
const paramName = dInject.get(key);
|
|
58
61
|
const useValue = this.listProviders.get(key);
|
|
59
62
|
injectData[paramName] = useValue;
|
|
60
63
|
}
|
|
64
|
+
else {
|
|
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);
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
return injectData;
|
|
@@ -68,16 +75,28 @@ class Injector {
|
|
|
68
75
|
* @param {any} target - La clase objetivo.
|
|
69
76
|
* @returns - El injector configurado.
|
|
70
77
|
*/
|
|
71
|
-
|
|
78
|
+
getInjectorClass(target) {
|
|
72
79
|
const injectData = this.getInjectData(target);
|
|
73
80
|
let injector = (0, awilix_1.asClass)(target).scoped();
|
|
74
81
|
if (!(0, shared_utils_1.isEmpty)(injectData)) {
|
|
75
|
-
|
|
82
|
+
this.logger.debug(`Inject - list dependencies to inject of ${target.name}:`, injectData);
|
|
83
|
+
injector = injector.inject(this.funtionInjectData(injectData));
|
|
76
84
|
}
|
|
77
85
|
return {
|
|
78
86
|
...injector,
|
|
79
87
|
interface: target,
|
|
80
88
|
};
|
|
81
89
|
}
|
|
90
|
+
getAllProvider() {
|
|
91
|
+
return this.listProviders;
|
|
92
|
+
}
|
|
93
|
+
getInjectProvider(provider) {
|
|
94
|
+
return typeof provider.value === "function"
|
|
95
|
+
? (0, awilix_1.asFunction)(provider.value).scoped()
|
|
96
|
+
: (0, awilix_1.asValue)(provider.value);
|
|
97
|
+
}
|
|
98
|
+
funtionInjectData(injectData) {
|
|
99
|
+
return () => injectData;
|
|
100
|
+
}
|
|
82
101
|
}
|
|
83
102
|
exports.Injector = Injector;
|
package/injector/module.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -63,6 +64,7 @@ export declare class Module {
|
|
|
63
64
|
* contructor(private sA: ServiceA) // parametro con nombre diferente
|
|
64
65
|
*/
|
|
65
66
|
private registerDependenciesToAlias;
|
|
67
|
+
private registerAllProviders;
|
|
66
68
|
/**
|
|
67
69
|
* Devuelve las importaciones del módulo.
|
|
68
70
|
* @returns {any[] | undefined} - Importaciones del módulo.
|
package/injector/module.js
CHANGED
|
@@ -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.
|
|
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,6 +46,8 @@ class Module {
|
|
|
44
46
|
* Inicializa el módulo extrayendo metadatos y registrando las entidades.
|
|
45
47
|
*/
|
|
46
48
|
initialize() {
|
|
49
|
+
this.logger.debug("Module - Initialize:", this.module.name);
|
|
50
|
+
this.registerAllProviders();
|
|
47
51
|
this.getMetadataModule();
|
|
48
52
|
this.registerDependencies();
|
|
49
53
|
this.registerDependenciesToAlias();
|
|
@@ -70,17 +74,27 @@ class Module {
|
|
|
70
74
|
*/
|
|
71
75
|
registerEntities(entityType) {
|
|
72
76
|
const entities = this.config[entityType];
|
|
77
|
+
this.logger.debug("Module - ..... searching for entities type ", entityType);
|
|
73
78
|
if (entities && entities.length > 0) {
|
|
74
79
|
const registeredEntities = entities
|
|
75
|
-
.filter((target) =>
|
|
76
|
-
|
|
80
|
+
.filter((target) => {
|
|
81
|
+
return ((0, shared_utils_1.isClass)(target) &&
|
|
82
|
+
this.types.includes(this.metadata.determineType(target)));
|
|
83
|
+
})
|
|
77
84
|
.map((target) => {
|
|
85
|
+
this.logger.debug(`Module - Entity <<< ${target.name} >>>`);
|
|
78
86
|
this.groupDependenciesForAlias(target);
|
|
79
87
|
const targetName = (0, shared_utils_1.unCapitalize)(target.name);
|
|
80
|
-
return {
|
|
88
|
+
return {
|
|
89
|
+
[target.name]: this.injector.getInjectorClass(target),
|
|
90
|
+
[targetName]: (0, awilix_1.aliasTo)(target.name),
|
|
91
|
+
};
|
|
81
92
|
});
|
|
82
93
|
Object.assign(this.registerClass, ...registeredEntities);
|
|
83
94
|
}
|
|
95
|
+
else {
|
|
96
|
+
this.logger.debug("Module - Does not have entities of that type", entityType);
|
|
97
|
+
}
|
|
84
98
|
}
|
|
85
99
|
/**
|
|
86
100
|
* Agrupación de dependencias para alias
|
|
@@ -96,6 +110,7 @@ class Module {
|
|
|
96
110
|
*/
|
|
97
111
|
groupDependenciesForAlias(target) {
|
|
98
112
|
const dependencies = this.metadata.getClassDependencies(target);
|
|
113
|
+
this.logger.debug(`Module - List dependecies of ${target.name}`, dependencies);
|
|
99
114
|
if (dependencies && !(0, shared_utils_1.isEmpty)(dependencies)) {
|
|
100
115
|
this.dependenciesClass = [...this.dependenciesClass, ...dependencies];
|
|
101
116
|
}
|
|
@@ -110,12 +125,25 @@ class Module {
|
|
|
110
125
|
* contructor(private sA: ServiceA) // parametro con nombre diferente
|
|
111
126
|
*/
|
|
112
127
|
registerDependenciesToAlias() {
|
|
128
|
+
this.logger.debug("Module - dependencies to register as candidates ", this.dependenciesClass);
|
|
113
129
|
this.dependenciesClass.forEach((dependency) => {
|
|
114
130
|
if (!this.registerClass[dependency.nameParameter]) {
|
|
115
131
|
this.registerClass[dependency.nameParameter] = (0, awilix_1.aliasTo)(dependency.nameClassContainer);
|
|
116
132
|
}
|
|
117
133
|
});
|
|
118
134
|
}
|
|
135
|
+
registerAllProviders() {
|
|
136
|
+
this.logger.debug("Module - Register list provider:", this.module.name);
|
|
137
|
+
const listProviders = this.injector.getAllProvider();
|
|
138
|
+
listProviders.forEach((value, key) => {
|
|
139
|
+
const providerInject = this.injector.getInjectProvider({
|
|
140
|
+
key,
|
|
141
|
+
value,
|
|
142
|
+
});
|
|
143
|
+
this.registerClass[key] = providerInject;
|
|
144
|
+
// this.registerClass[snakeToCamel(key)] = aliasTo(key);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
119
147
|
/**
|
|
120
148
|
* Devuelve las importaciones del módulo.
|
|
121
149
|
* @returns {any[] | undefined} - Importaciones del módulo.
|
|
@@ -128,7 +156,7 @@ class Module {
|
|
|
128
156
|
* @returns {any} - Clases registradas.
|
|
129
157
|
*/
|
|
130
158
|
getRegisterClass() {
|
|
131
|
-
this.logger.debug("Module - register
|
|
159
|
+
this.logger.debug("Module - List of candidate classes to register in container.", this.registerClass);
|
|
132
160
|
return this.registerClass;
|
|
133
161
|
}
|
|
134
162
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./factory.interface";
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zanobijs/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
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>",
|
|
7
7
|
"license": "ZanobiJS Usage License \n\n Review the LICENSE file.\n\n Revise el archivo de LICENCIA.",
|
|
8
|
-
"main": "index.js",
|
|
9
8
|
"typings": "index.d.ts",
|
|
10
9
|
"repository": {
|
|
11
10
|
"type": "git",
|
|
@@ -24,11 +23,11 @@
|
|
|
24
23
|
},
|
|
25
24
|
"homepage": "https://github.com/devdroide/ZanobiJS#readme",
|
|
26
25
|
"dependencies": {
|
|
27
|
-
"awilix": "
|
|
26
|
+
"awilix": "10.0.2",
|
|
28
27
|
"reflect-metadata": "^0.1.13"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
30
|
"@zanobijs/common": "*"
|
|
32
31
|
},
|
|
33
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "83ec232affe492416cca5de8ee6bd19fcee99c0c"
|
|
34
33
|
}
|
package/tsconfig.build.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/__test__/factory.spec.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
// import { Module } from "@zanobijs/common";
|
|
5
|
-
const index_1 = require("../index");
|
|
6
|
-
const classModule_mock_1 = require("./mocks/classModule.mock");
|
|
7
|
-
describe("Core - factory", () => {
|
|
8
|
-
const factory = new index_1.Factory(classModule_mock_1.ModuleTestAll);
|
|
9
|
-
describe("Create Factory App", () => {
|
|
10
|
-
it("should respond error to create factory by error @Module", () => {
|
|
11
|
-
class ModuleWithoutDecorator {
|
|
12
|
-
}
|
|
13
|
-
try {
|
|
14
|
-
new index_1.Factory(ModuleWithoutDecorator);
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
(0, chai_1.expect)(error.message).to.be.equal("The class must have an annotation @Module()");
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
it("should respond create factory", () => {
|
|
21
|
-
const app = factory.create();
|
|
22
|
-
(0, chai_1.expect)(app).to.be.instanceOf(index_1.Factory);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe("Get Entities", () => {
|
|
26
|
-
it("should respond error by resolve entity controller", () => {
|
|
27
|
-
const app = factory.create();
|
|
28
|
-
try {
|
|
29
|
-
app.get("SomeController");
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
console.log(error);
|
|
33
|
-
(0, chai_1.expect)(error.message).to.be.equal("No 'SomeController' was found registered in @modulo.");
|
|
34
|
-
(0, chai_1.expect)(error.detail).to.have.string("Could not resolve 'someController'.");
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
it("should respond error by resolve entity controller with number in name", () => {
|
|
38
|
-
const app = factory.create();
|
|
39
|
-
try {
|
|
40
|
-
app.get("123SomeController");
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
(0, chai_1.expect)(error.message).to.be.equal("No '123SomeController' was found registered in @modulo.");
|
|
44
|
-
(0, chai_1.expect)(error.detail).to.have.string("Could not resolve '123SomeController'.");
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
it("should respond error by resolve entity controller with special character", () => {
|
|
48
|
-
const app = factory.create();
|
|
49
|
-
try {
|
|
50
|
-
app.get("*123SomeController");
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
(0, chai_1.expect)(error.message).to.be.equal("No '*123SomeController' was found registered in @modulo.");
|
|
54
|
-
(0, chai_1.expect)(error.detail).to.have.string("Could not resolve '*123SomeController'.");
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
it("should respond apiKey to controller the app", () => {
|
|
58
|
-
const app = factory.create();
|
|
59
|
-
const controllerWithDepen2 = app.get("controllerWithDepen2");
|
|
60
|
-
(0, chai_1.expect)(controllerWithDepen2.getApiKey()).to.be.equal("isApiKey_qwerty12345");
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const injector_1 = require("../../injector");
|
|
5
|
-
const classModule_mock_1 = require("../mocks/classModule.mock");
|
|
6
|
-
const classWithDependeciesInject_mock_1 = require("../mocks/classWithDependeciesInject.mock");
|
|
7
|
-
const classWithDependeciesClass_mock_1 = require("../mocks/classWithDependeciesClass.mock");
|
|
8
|
-
describe("Core - Injector - injector", () => {
|
|
9
|
-
const injector = new injector_1.Injector(classModule_mock_1.ModuleTestWithInjector);
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
process.env.ZANOBI_DEBUG = "false";
|
|
12
|
-
});
|
|
13
|
-
it("Should respond an object with paramters to inject", () => {
|
|
14
|
-
const getInjectData = injector.getInjectData(classWithDependeciesClass_mock_1.ControllerWithDepenClass);
|
|
15
|
-
(0, chai_1.expect)(getInjectData).to.is.empty;
|
|
16
|
-
});
|
|
17
|
-
it("Should respond an object without paramters to inject", () => {
|
|
18
|
-
const getInjectData = injector.getInjectData(classWithDependeciesInject_mock_1.ControllerWithDepen2);
|
|
19
|
-
(0, chai_1.expect)(getInjectData).to.have.property("apiKey");
|
|
20
|
-
});
|
|
21
|
-
it("Should respond an object type asClass with paramters to inject", () => {
|
|
22
|
-
const getInject = injector.getInjector(classWithDependeciesInject_mock_1.ControllerWithDepen2);
|
|
23
|
-
(0, chai_1.expect)(getInject).to.have.property("lifetime");
|
|
24
|
-
(0, chai_1.expect)(getInject).to.have.property("inject");
|
|
25
|
-
(0, chai_1.expect)(getInject).to.have.property("injector");
|
|
26
|
-
});
|
|
27
|
-
it("Should respond an object type asClass without injector", () => {
|
|
28
|
-
const getInject = injector.getInjector(classWithDependeciesClass_mock_1.ControllerWithDepenClass);
|
|
29
|
-
(0, chai_1.expect)(getInject).to.not.have.property("injector");
|
|
30
|
-
});
|
|
31
|
-
// it("", () => {});
|
|
32
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("reflect-metadata");
|
|
4
|
-
const chai_1 = require("chai");
|
|
5
|
-
const injector_1 = require("../../injector");
|
|
6
|
-
const classModule_mock_1 = require("../mocks/classModule.mock");
|
|
7
|
-
describe("Core - Injector - module", () => {
|
|
8
|
-
let moduleInstance;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
moduleInstance = new injector_1.Module();
|
|
11
|
-
});
|
|
12
|
-
describe("setup", () => {
|
|
13
|
-
it("should respond that setup no is a module", () => {
|
|
14
|
-
try {
|
|
15
|
-
const mockModule = {};
|
|
16
|
-
moduleInstance.setup(mockModule);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
(0, chai_1.expect)(error.message).to.equal("The class must have an annotation @Module()");
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
it("should respond no problem with the setup.", () => {
|
|
23
|
-
moduleInstance.setup(classModule_mock_1.ModuleTestWithInjector);
|
|
24
|
-
(0, chai_1.expect)(moduleInstance.getRegisterClass()).to.is.empty;
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
describe("Module initialize", () => {
|
|
28
|
-
it("should respond that call getMetadataModule and register on Module", () => {
|
|
29
|
-
let metadataCalled = false;
|
|
30
|
-
let registerDependencies = false;
|
|
31
|
-
let registerDependenciesToAlias = false;
|
|
32
|
-
moduleInstance["getMetadataModule"] = () => {
|
|
33
|
-
metadataCalled = true;
|
|
34
|
-
};
|
|
35
|
-
moduleInstance["registerDependencies"] = () => {
|
|
36
|
-
registerDependencies = true;
|
|
37
|
-
};
|
|
38
|
-
moduleInstance["registerDependenciesToAlias"] = () => {
|
|
39
|
-
registerDependenciesToAlias = true;
|
|
40
|
-
};
|
|
41
|
-
moduleInstance.initialize();
|
|
42
|
-
(0, chai_1.expect)(metadataCalled).to.be.true;
|
|
43
|
-
(0, chai_1.expect)(registerDependencies).to.be.true;
|
|
44
|
-
(0, chai_1.expect)(registerDependenciesToAlias).to.be.true;
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe("Module get information", () => {
|
|
48
|
-
it("Should respond apiKey and sContro2 in registered providers", () => {
|
|
49
|
-
moduleInstance.setup(classModule_mock_1.ModuleTestWithInjector);
|
|
50
|
-
moduleInstance.initialize();
|
|
51
|
-
(0, chai_1.expect)(moduleInstance.getRegisterClass()).to.have.property("sContro2");
|
|
52
|
-
(0, chai_1.expect)(moduleInstance.getRegisterClass()).to.have.property("apiKey");
|
|
53
|
-
});
|
|
54
|
-
it("Should respond imports of module", () => {
|
|
55
|
-
moduleInstance.setup(classModule_mock_1.ModuleTestWithImports);
|
|
56
|
-
moduleInstance.initialize();
|
|
57
|
-
(0, chai_1.expect)(moduleInstance.getImports()).to.not.empty;
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const chai_1 = require("chai");
|
|
4
|
-
const metadata_1 = require("../metadata");
|
|
5
|
-
const classModule_mock_1 = require("./mocks/classModule.mock");
|
|
6
|
-
const classWithDependeciesInject_mock_1 = require("./mocks/classWithDependeciesInject.mock");
|
|
7
|
-
const classWithDependeciesClass_mock_1 = require("./mocks/classWithDependeciesClass.mock");
|
|
8
|
-
describe("Core - metadata", () => {
|
|
9
|
-
class genericClassForTesting {
|
|
10
|
-
}
|
|
11
|
-
const metadata = metadata_1.Metadata.getInstance();
|
|
12
|
-
describe("Is Type", () => {
|
|
13
|
-
it("should respond false to is module", () => {
|
|
14
|
-
(0, chai_1.expect)(metadata.isTypeModule(genericClassForTesting)).to.be.false;
|
|
15
|
-
});
|
|
16
|
-
it("should respond false to is imports", () => {
|
|
17
|
-
(0, chai_1.expect)(metadata.isTypeImport(genericClassForTesting)).to.be.false;
|
|
18
|
-
});
|
|
19
|
-
it("should respond false to is controllers", () => {
|
|
20
|
-
(0, chai_1.expect)(metadata.isTypeController(genericClassForTesting)).to.be.false;
|
|
21
|
-
});
|
|
22
|
-
it("should respond false to is services", () => {
|
|
23
|
-
(0, chai_1.expect)(metadata.isTypeService(genericClassForTesting)).to.be.false;
|
|
24
|
-
});
|
|
25
|
-
it("should respond false to is exports", () => {
|
|
26
|
-
(0, chai_1.expect)(metadata.isTypeExports(genericClassForTesting)).to.be.false;
|
|
27
|
-
});
|
|
28
|
-
it("should respond true to is module", () => {
|
|
29
|
-
(0, chai_1.expect)(metadata.isTypeModule(classModule_mock_1.ModuleTestEmpty)).to.be.true;
|
|
30
|
-
});
|
|
31
|
-
it("should respond determine type of service", () => {
|
|
32
|
-
(0, chai_1.expect)(metadata.determineType(classWithDependeciesInject_mock_1.ServiceWithDepenParam)).to.be.equal("service");
|
|
33
|
-
});
|
|
34
|
-
it("should respond determine type of unknown", () => {
|
|
35
|
-
class ServiceTest {
|
|
36
|
-
}
|
|
37
|
-
try {
|
|
38
|
-
metadata.determineType(ServiceTest);
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
(0, chai_1.expect)(error.message).to.be.equal("ServiceTest type is unknown");
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe("Get Metadata", () => {
|
|
46
|
-
it("Should respond the metadata of the decorator module", () => {
|
|
47
|
-
const metadata2 = metadata_1.Metadata.getInstance();
|
|
48
|
-
const resultMetadata = metadata2.getMetadataModule(classModule_mock_1.ModuleTest);
|
|
49
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("imports");
|
|
50
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("controllers");
|
|
51
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("services");
|
|
52
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("exports");
|
|
53
|
-
});
|
|
54
|
-
it("should respond the dependency metadata of a controller", () => {
|
|
55
|
-
const resultMetadata = metadata.getAllDependencies(classWithDependeciesClass_mock_1.ControllerWithDepenClass);
|
|
56
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dClass");
|
|
57
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dParam");
|
|
58
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dInject");
|
|
59
|
-
(0, chai_1.expect)(resultMetadata.dInject).to.be.empty;
|
|
60
|
-
});
|
|
61
|
-
it("should respond the dependency metadata of a service", () => {
|
|
62
|
-
const resultMetadata = metadata.getAllDependencies(classWithDependeciesInject_mock_1.ServiceWithDepenParam);
|
|
63
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dClass");
|
|
64
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dParam");
|
|
65
|
-
(0, chai_1.expect)(resultMetadata).to.have.property("dInject");
|
|
66
|
-
(0, chai_1.expect)(resultMetadata.dInject).to.not.be.empty;
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe("", () => { });
|
|
70
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModuleTestAll = exports.ModuleTestWithImports = exports.ModuleTestWithInjector = exports.ModuleTest = exports.ModuleTestEmpty = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@zanobijs/common");
|
|
6
|
-
const classWithDependeciesClass_mock_1 = require("./classWithDependeciesClass.mock");
|
|
7
|
-
const classWithDependeciesInject_mock_1 = require("./classWithDependeciesInject.mock");
|
|
8
|
-
let ModuleTestEmpty = class ModuleTestEmpty {
|
|
9
|
-
};
|
|
10
|
-
exports.ModuleTestEmpty = ModuleTestEmpty;
|
|
11
|
-
exports.ModuleTestEmpty = ModuleTestEmpty = tslib_1.__decorate([
|
|
12
|
-
(0, common_1.Module)({
|
|
13
|
-
imports: [],
|
|
14
|
-
controllers: [],
|
|
15
|
-
services: [],
|
|
16
|
-
exports: [],
|
|
17
|
-
})
|
|
18
|
-
], ModuleTestEmpty);
|
|
19
|
-
let ModuleTest = class ModuleTest {
|
|
20
|
-
};
|
|
21
|
-
exports.ModuleTest = ModuleTest;
|
|
22
|
-
exports.ModuleTest = ModuleTest = tslib_1.__decorate([
|
|
23
|
-
(0, common_1.Module)({
|
|
24
|
-
imports: [],
|
|
25
|
-
controllers: [classWithDependeciesClass_mock_1.ControllerWithDepenClass],
|
|
26
|
-
services: [classWithDependeciesClass_mock_1.ServiceToController],
|
|
27
|
-
exports: [],
|
|
28
|
-
})
|
|
29
|
-
], ModuleTest);
|
|
30
|
-
let ModuleTestWithInjector = class ModuleTestWithInjector {
|
|
31
|
-
};
|
|
32
|
-
exports.ModuleTestWithInjector = ModuleTestWithInjector;
|
|
33
|
-
exports.ModuleTestWithInjector = ModuleTestWithInjector = tslib_1.__decorate([
|
|
34
|
-
(0, common_1.Module)({
|
|
35
|
-
imports: [],
|
|
36
|
-
controllers: [classWithDependeciesInject_mock_1.ControllerWithDepen2],
|
|
37
|
-
services: [
|
|
38
|
-
classWithDependeciesInject_mock_1.ServiceToController2,
|
|
39
|
-
{
|
|
40
|
-
provider: "API_KEY",
|
|
41
|
-
useValue: "isApiKey_qwerty12345"
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
exports: [],
|
|
45
|
-
})
|
|
46
|
-
], ModuleTestWithInjector);
|
|
47
|
-
let ModuleTestWithImports = class ModuleTestWithImports {
|
|
48
|
-
};
|
|
49
|
-
exports.ModuleTestWithImports = ModuleTestWithImports;
|
|
50
|
-
exports.ModuleTestWithImports = ModuleTestWithImports = tslib_1.__decorate([
|
|
51
|
-
(0, common_1.Module)({
|
|
52
|
-
imports: [ModuleTestWithInjector],
|
|
53
|
-
controllers: [],
|
|
54
|
-
services: [],
|
|
55
|
-
exports: [],
|
|
56
|
-
})
|
|
57
|
-
], ModuleTestWithImports);
|
|
58
|
-
let ModuleTestAll = class ModuleTestAll {
|
|
59
|
-
};
|
|
60
|
-
exports.ModuleTestAll = ModuleTestAll;
|
|
61
|
-
exports.ModuleTestAll = ModuleTestAll = tslib_1.__decorate([
|
|
62
|
-
(0, common_1.Module)({
|
|
63
|
-
imports: [ModuleTestWithInjector],
|
|
64
|
-
controllers: [classWithDependeciesInject_mock_1.ControllerWithDepen2],
|
|
65
|
-
services: [
|
|
66
|
-
classWithDependeciesInject_mock_1.ServiceToController2,
|
|
67
|
-
{
|
|
68
|
-
provider: "API_SECRET",
|
|
69
|
-
useValue: "isApiSecret_cvbdfgert"
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
exports: [],
|
|
73
|
-
})
|
|
74
|
-
], ModuleTestAll);
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare class ServiceToService {
|
|
2
|
-
constructor();
|
|
3
|
-
}
|
|
4
|
-
export declare class Service {
|
|
5
|
-
constructor();
|
|
6
|
-
}
|
|
7
|
-
export declare class ServiceToController {
|
|
8
|
-
constructor();
|
|
9
|
-
}
|
|
10
|
-
export declare class ControllerWithDepenClass {
|
|
11
|
-
private servicio;
|
|
12
|
-
constructor(servicio: ServiceToController);
|
|
13
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControllerWithDepenClass = exports.ServiceToController = exports.Service = exports.ServiceToService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@zanobijs/common");
|
|
6
|
-
let ServiceToService = class ServiceToService {
|
|
7
|
-
constructor() { }
|
|
8
|
-
};
|
|
9
|
-
exports.ServiceToService = ServiceToService;
|
|
10
|
-
exports.ServiceToService = ServiceToService = tslib_1.__decorate([
|
|
11
|
-
(0, common_1.Injectable)(),
|
|
12
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
13
|
-
], ServiceToService);
|
|
14
|
-
let Service = class Service {
|
|
15
|
-
constructor() { }
|
|
16
|
-
};
|
|
17
|
-
exports.Service = Service;
|
|
18
|
-
exports.Service = Service = tslib_1.__decorate([
|
|
19
|
-
(0, common_1.Injectable)(),
|
|
20
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
21
|
-
], Service);
|
|
22
|
-
let ServiceToController = class ServiceToController {
|
|
23
|
-
constructor() { }
|
|
24
|
-
};
|
|
25
|
-
exports.ServiceToController = ServiceToController;
|
|
26
|
-
exports.ServiceToController = ServiceToController = tslib_1.__decorate([
|
|
27
|
-
(0, common_1.Injectable)(),
|
|
28
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
29
|
-
], ServiceToController);
|
|
30
|
-
let ControllerWithDepenClass = class ControllerWithDepenClass {
|
|
31
|
-
servicio;
|
|
32
|
-
constructor(servicio) {
|
|
33
|
-
this.servicio = servicio;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
exports.ControllerWithDepenClass = ControllerWithDepenClass;
|
|
37
|
-
exports.ControllerWithDepenClass = ControllerWithDepenClass = tslib_1.__decorate([
|
|
38
|
-
(0, common_1.Controller)(),
|
|
39
|
-
tslib_1.__metadata("design:paramtypes", [ServiceToController])
|
|
40
|
-
], ControllerWithDepenClass);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare class ServiceToController2 {
|
|
2
|
-
constructor();
|
|
3
|
-
getHello(): string;
|
|
4
|
-
}
|
|
5
|
-
export declare class ServiceWithDepenParam {
|
|
6
|
-
private servicio;
|
|
7
|
-
private userName;
|
|
8
|
-
private userAge;
|
|
9
|
-
private userLogin;
|
|
10
|
-
private userHobbis;
|
|
11
|
-
constructor(servicio: ServiceToController2, userName: string, userAge: number, userLogin: boolean, userHobbis: string[]);
|
|
12
|
-
}
|
|
13
|
-
export declare class ControllerWithDepen2 {
|
|
14
|
-
private sContro2;
|
|
15
|
-
private apiKey;
|
|
16
|
-
constructor(sContro2: ServiceToController2, apiKey: string);
|
|
17
|
-
getApiKey(): string;
|
|
18
|
-
getHelloService(): string;
|
|
19
|
-
}
|
|
20
|
-
export declare class ServiceWithDepen2 {
|
|
21
|
-
private serviceWithDepenParam;
|
|
22
|
-
private api_key;
|
|
23
|
-
constructor(serviceWithDepenParam: ServiceWithDepenParam, api_key: string);
|
|
24
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ServiceWithDepen2 = exports.ControllerWithDepen2 = exports.ServiceWithDepenParam = exports.ServiceToController2 = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const common_1 = require("@zanobijs/common");
|
|
6
|
-
let ServiceToController2 = class ServiceToController2 {
|
|
7
|
-
constructor() { }
|
|
8
|
-
getHello() {
|
|
9
|
-
return "Hello ServiceToController2";
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
exports.ServiceToController2 = ServiceToController2;
|
|
13
|
-
exports.ServiceToController2 = ServiceToController2 = tslib_1.__decorate([
|
|
14
|
-
(0, common_1.Injectable)(),
|
|
15
|
-
tslib_1.__metadata("design:paramtypes", [])
|
|
16
|
-
], ServiceToController2);
|
|
17
|
-
let ServiceWithDepenParam = class ServiceWithDepenParam {
|
|
18
|
-
servicio;
|
|
19
|
-
userName;
|
|
20
|
-
userAge;
|
|
21
|
-
userLogin;
|
|
22
|
-
userHobbis;
|
|
23
|
-
constructor(servicio, userName, userAge, userLogin, userHobbis) {
|
|
24
|
-
this.servicio = servicio;
|
|
25
|
-
this.userName = userName;
|
|
26
|
-
this.userAge = userAge;
|
|
27
|
-
this.userLogin = userLogin;
|
|
28
|
-
this.userHobbis = userHobbis;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
exports.ServiceWithDepenParam = ServiceWithDepenParam;
|
|
32
|
-
exports.ServiceWithDepenParam = ServiceWithDepenParam = tslib_1.__decorate([
|
|
33
|
-
(0, common_1.Injectable)(),
|
|
34
|
-
tslib_1.__param(1, (0, common_1.Inject)("USER_NAME")),
|
|
35
|
-
tslib_1.__param(2, (0, common_1.Inject)("USER_AGE")),
|
|
36
|
-
tslib_1.__param(3, (0, common_1.Inject)("USER_LOGIN")),
|
|
37
|
-
tslib_1.__param(4, (0, common_1.Inject)("USER_LIKE")),
|
|
38
|
-
tslib_1.__metadata("design:paramtypes", [ServiceToController2, String, Number, Boolean, Array])
|
|
39
|
-
], ServiceWithDepenParam);
|
|
40
|
-
let ControllerWithDepen2 = class ControllerWithDepen2 {
|
|
41
|
-
sContro2;
|
|
42
|
-
apiKey;
|
|
43
|
-
constructor(sContro2, apiKey) {
|
|
44
|
-
this.sContro2 = sContro2;
|
|
45
|
-
this.apiKey = apiKey;
|
|
46
|
-
this.apiKey = apiKey;
|
|
47
|
-
}
|
|
48
|
-
getApiKey() {
|
|
49
|
-
return this.apiKey;
|
|
50
|
-
}
|
|
51
|
-
getHelloService() {
|
|
52
|
-
return this.sContro2.getHello();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.ControllerWithDepen2 = ControllerWithDepen2;
|
|
56
|
-
exports.ControllerWithDepen2 = ControllerWithDepen2 = tslib_1.__decorate([
|
|
57
|
-
(0, common_1.Controller)(),
|
|
58
|
-
tslib_1.__param(1, (0, common_1.Inject)("API_KEY")),
|
|
59
|
-
tslib_1.__metadata("design:paramtypes", [ServiceToController2, String])
|
|
60
|
-
], ControllerWithDepen2);
|
|
61
|
-
let ServiceWithDepen2 = class ServiceWithDepen2 {
|
|
62
|
-
serviceWithDepenParam;
|
|
63
|
-
api_key;
|
|
64
|
-
constructor(serviceWithDepenParam, api_key) {
|
|
65
|
-
this.serviceWithDepenParam = serviceWithDepenParam;
|
|
66
|
-
this.api_key = api_key;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
exports.ServiceWithDepen2 = ServiceWithDepen2;
|
|
70
|
-
exports.ServiceWithDepen2 = ServiceWithDepen2 = tslib_1.__decorate([
|
|
71
|
-
(0, common_1.Injectable)(),
|
|
72
|
-
tslib_1.__param(1, (0, common_1.Inject)("API_KEY")),
|
|
73
|
-
tslib_1.__metadata("design:paramtypes", [ServiceWithDepenParam, String])
|
|
74
|
-
], ServiceWithDepen2);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./classModule.mock";
|
package/interface/index.d.ts
DELETED
|
File without changes
|
package/interface/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|