@zanobijs/core 1.0.0-beta.3 → 1.0.0-beta.4

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +37 -11
  3. package/exceptions/constant.message.js +6 -1
  4. package/exceptions/resolution.exception.d.ts +1 -1
  5. package/exceptions/resolution.exception.js +6 -1
  6. package/factory.d.ts +5 -1
  7. package/factory.js +16 -4
  8. package/index.d.ts +1 -0
  9. package/index.js +1 -0
  10. package/injector/injector.d.ts +6 -0
  11. package/injector/injector.js +25 -0
  12. package/injector/module.d.ts +1 -0
  13. package/injector/module.js +21 -3
  14. package/interfaces/factory.interface.d.ts +4 -0
  15. package/interfaces/factory.interface.js +2 -0
  16. package/interfaces/index.d.ts +1 -0
  17. package/{__test__/mocks → interfaces}/index.js +1 -1
  18. package/package.json +3 -4
  19. package/tsconfig.build.json +1 -1
  20. package/__test__/factory.spec.d.ts +0 -1
  21. package/__test__/factory.spec.js +0 -63
  22. package/__test__/injector/injector.spec.d.ts +0 -1
  23. package/__test__/injector/injector.spec.js +0 -32
  24. package/__test__/injector/module.spec.d.ts +0 -1
  25. package/__test__/injector/module.spec.js +0 -60
  26. package/__test__/metadata.spec.d.ts +0 -1
  27. package/__test__/metadata.spec.js +0 -70
  28. package/__test__/mocks/classModule.mock.d.ts +0 -10
  29. package/__test__/mocks/classModule.mock.js +0 -74
  30. package/__test__/mocks/classWithDependeciesClass.mock.d.ts +0 -13
  31. package/__test__/mocks/classWithDependeciesClass.mock.js +0 -40
  32. package/__test__/mocks/classWithDependeciesInject.mock.d.ts +0 -24
  33. package/__test__/mocks/classWithDependeciesInject.mock.js +0 -74
  34. package/__test__/mocks/index.d.ts +0 -1
  35. package/interface/index.d.ts +0 -0
  36. 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.3](https://github.com/devdroide/ZanobiJS/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2023-11-14)
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)
7
7
 
8
8
  **Note:** Version bump only for package @zanobijs/core
package/README.md CHANGED
@@ -1,4 +1,16 @@
1
- # ZanobiJS
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
+ [![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/)
9
+ [![test](https://img.shields.io/badge/test-mocha-CC0000.svg)](https://mochajs.org/)
10
+ [![nodejs](https://img.shields.io/badge/nodejs->=16.0.0-darkgreen.svg)](https://nodejs.org)
11
+ [![typescrit](https://img.shields.io/badge/TS->=5.2.2-darkblue.svg)](https://www.typescriptlang.org/)
12
+ [![licence](https://img.shields.io/badge/licence-MIT-purple.svg)](https://en.wikipedia.org/wiki/MIT_License)
13
+ [![Doc](https://img.shields.io/badge/ZNB-Documentation-blue.svg)](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
- import { Logger } from "@zanobijs/common/utils";
165
+ // Index.ts - This is important for the operation
166
+ const factory = new Factory(AppModule, {
167
+ activeLoggerUser: true
168
+ });
148
169
 
149
- process.env.ZANOBIJS_LOGGER = "true";
170
+ // use en services controllers, etc
150
171
 
151
- const logger = Logger();
172
+ import { LoggerUser } from "@zanobijs/common/utils";
152
173
 
153
- logger.success("Lorem ipsum success");
154
- logger.info("Lorem ipsum info");
155
- logger.warn("Lorem ipsum warn");
156
- logger.error("Lorem ipsum error");
157
- logger.debug("Lorem ipsum debug");
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/). Credits
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
@@ -3,5 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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) => `No '${entity}' was found registered in @modulo.`;
6
+ const CONTAINER_RESOLUTION_ERROR = (entity) => `'${entity}' is not registered in any @module.`;
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`;
@@ -9,5 +9,5 @@ import { RuntimeException } from "@zanobijs/common/exceptions/runtime.exception"
9
9
  * para proporcionar detalles adicionales del error.
10
10
  */
11
11
  export declare class ContainerResolutionException extends RuntimeException {
12
- constructor(entity: string, detail?: any);
12
+ constructor(entity: string, detail: any);
13
13
  }
@@ -13,8 +13,13 @@ const constant_message_1 = require("./constant.message");
13
13
  * para proporcionar detalles adicionales del error.
14
14
  */
15
15
  class ContainerResolutionException extends runtime_exception_1.RuntimeException {
16
- constructor(entity, detail = ``) {
16
+ constructor(entity, detail) {
17
17
  super((0, constant_message_1.CONTAINER_RESOLUTION_ERROR)(entity), detail);
18
18
  }
19
19
  }
20
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
+ // }
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
- constructor(appModule: any);
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
+ evaluateOptions(): void;
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,12 @@ class Factory {
16
16
  moduleHandler;
17
17
  registeredClasses = {};
18
18
  container;
19
- constructor(appModule) {
19
+ logger;
20
+ options;
21
+ constructor(appModule, options = {}) {
22
+ this.options = options;
23
+ this.evaluateOptions();
24
+ this.logger = (0, utils_1.Logger)();
20
25
  this.moduleHandler = new module_1.Module();
21
26
  this.registerClassesFromModule(appModule);
22
27
  }
@@ -52,6 +57,7 @@ class Factory {
52
57
  create() {
53
58
  this.container = (0, awilix_1.createContainer)({ injectionMode: awilix_1.InjectionMode.CLASSIC });
54
59
  this.container.register(this.registeredClasses);
60
+ this.logger.info("Registered Classes", this.registeredClasses);
55
61
  return this;
56
62
  }
57
63
  /**
@@ -61,12 +67,18 @@ class Factory {
61
67
  */
62
68
  get(entity) {
63
69
  try {
64
- const entityUnCapitalize = (0, shared_utils_1.unCapitalize)(entity);
65
- return this.container.resolve(entityUnCapitalize);
70
+ return this.container.resolve(entity);
66
71
  }
67
72
  catch (error) {
73
+ this.logger.info("Error resolving entity: ", error.message + "\n");
68
74
  throw new resolution_exception_1.ContainerResolutionException(entity, error.message);
69
75
  }
70
76
  }
77
+ evaluateOptions() {
78
+ if (this.options.activeLoggerSystem)
79
+ process.env.ZANOBIJS_LOGGER = "true";
80
+ if (this.options.activeLoggerUser)
81
+ process.env.ZANOBIJS_LOGGER = "true";
82
+ }
71
83
  }
72
84
  exports.Factory = Factory;
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { Factory } from './factory';
2
2
  export * from "./injector";
3
+ export * from "./interfaces";
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);
@@ -10,6 +10,8 @@ export declare class Injector {
10
10
  private listProviders;
11
11
  private metadata;
12
12
  private logger;
13
+ private registeredClassParentModule;
14
+ private moduleName;
13
15
  /**
14
16
  * En Constructor de la clase Injector obtenermos las instancias
15
17
  * de Metadata y Logger e inciamos el escaneo de proveedores.
@@ -24,6 +26,7 @@ export declare class Injector {
24
26
  * @private
25
27
  */
26
28
  private scanProviders;
29
+ setRegisteredClassParentModule(registerClass: any): void;
27
30
  /**
28
31
  * Método para obtener un objeto con los parámetros y valores
29
32
  * que se inyectarán en la clase (target).
@@ -54,7 +57,10 @@ export declare class Injector {
54
57
  name?: string;
55
58
  lifetime?: import("awilix").LifetimeType;
56
59
  register?: (...args: any[]) => import("awilix").Resolver<object>;
60
+ isLeakSafe?: boolean;
57
61
  dispose?: import("awilix").Disposer<object>;
58
62
  disposer(dispose: import("awilix").Disposer<object>): import("awilix").BuildResolver<object> & import("awilix").DisposableResolver<object>;
59
63
  };
64
+ getAllProvider(): Map<any, any>;
65
+ getInjectProvider(provider: any): import("awilix").Resolver<any>;
60
66
  }
@@ -14,6 +14,8 @@ class Injector {
14
14
  listProviders = new Map();
15
15
  metadata;
16
16
  logger;
17
+ registeredClassParentModule = {};
18
+ moduleName = "";
17
19
  /**
18
20
  * En Constructor de la clase Injector obtenermos las instancias
19
21
  * de Metadata y Logger e inciamos el escaneo de proveedores.
@@ -23,6 +25,7 @@ class Injector {
23
25
  constructor(module) {
24
26
  this.metadata = metadata_1.Metadata.getInstance();
25
27
  this.logger = (0, utils_1.Logger)();
28
+ this.moduleName = module.name;
26
29
  this.module = module;
27
30
  this.scanProviders();
28
31
  }
@@ -40,6 +43,9 @@ class Injector {
40
43
  });
41
44
  this.logger.debug("Injector - list provider", this.listProviders);
42
45
  }
46
+ setRegisteredClassParentModule(registerClass) {
47
+ this.registeredClassParentModule = registerClass;
48
+ }
43
49
  /**
44
50
  * Método para obtener un objeto con los parámetros y valores
45
51
  * que se inyectarán en la clase (target).
@@ -58,6 +64,17 @@ class Injector {
58
64
  const useValue = this.listProviders.get(key);
59
65
  injectData[paramName] = useValue;
60
66
  }
67
+ 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
+ }
77
+ }
61
78
  }
62
79
  }
63
80
  return injectData;
@@ -79,5 +96,13 @@ class Injector {
79
96
  interface: target,
80
97
  };
81
98
  }
99
+ getAllProvider() {
100
+ return this.listProviders;
101
+ }
102
+ getInjectProvider(provider) {
103
+ return typeof provider.value === "function"
104
+ ? (0, awilix_1.asFunction)(provider.value).scoped()
105
+ : (0, awilix_1.asValue)(provider.value);
106
+ }
82
107
  }
83
108
  exports.Injector = Injector;
@@ -63,6 +63,7 @@ export declare class Module {
63
63
  * contructor(private sA: ServiceA) // parametro con nombre diferente
64
64
  */
65
65
  private registerDependenciesToAlias;
66
+ private registerAllProviders;
66
67
  /**
67
68
  * Devuelve las importaciones del módulo.
68
69
  * @returns {any[] | undefined} - Importaciones del módulo.
@@ -45,6 +45,8 @@ class Module {
45
45
  */
46
46
  initialize() {
47
47
  this.getMetadataModule();
48
+ this.registerAllProviders();
49
+ this.injector.setRegisteredClassParentModule(this.registerClass);
48
50
  this.registerDependencies();
49
51
  this.registerDependenciesToAlias();
50
52
  }
@@ -72,12 +74,17 @@ class Module {
72
74
  const entities = this.config[entityType];
73
75
  if (entities && entities.length > 0) {
74
76
  const registeredEntities = entities
75
- .filter((target) => (0, shared_utils_1.isClass)(target) &&
76
- this.types.includes(this.metadata.determineType(target)))
77
+ .filter((target) => {
78
+ return ((0, shared_utils_1.isClass)(target) &&
79
+ this.types.includes(this.metadata.determineType(target)));
80
+ })
77
81
  .map((target) => {
78
82
  this.groupDependenciesForAlias(target);
79
83
  const targetName = (0, shared_utils_1.unCapitalize)(target.name);
80
- return { [targetName]: this.injector.getInjector(target) };
84
+ return {
85
+ [target.name]: this.injector.getInjector(target),
86
+ [targetName]: (0, awilix_1.aliasTo)(target.name),
87
+ };
81
88
  });
82
89
  Object.assign(this.registerClass, ...registeredEntities);
83
90
  }
@@ -116,6 +123,17 @@ class Module {
116
123
  }
117
124
  });
118
125
  }
126
+ registerAllProviders() {
127
+ const listProviders = this.injector.getAllProvider();
128
+ listProviders.forEach((value, key) => {
129
+ const providerInject = this.injector.getInjectProvider({
130
+ key,
131
+ value,
132
+ });
133
+ this.registerClass[key] = providerInject;
134
+ this.registerClass[(0, shared_utils_1.snakeToCamel)(key)] = (0, awilix_1.aliasTo)(key);
135
+ });
136
+ }
119
137
  /**
120
138
  * Devuelve las importaciones del módulo.
121
139
  * @returns {any[] | undefined} - Importaciones del módulo.
@@ -0,0 +1,4 @@
1
+ export interface IFactoryOptions {
2
+ activeLoggerSystem?: boolean;
3
+ activeLoggerUser?: boolean;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from "./factory.interface";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./classModule.mock"), exports);
4
+ tslib_1.__exportStar(require("./factory.interface"), exports);
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@zanobijs/core",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
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": "^9.0.0",
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": "325565f63aecaf48b12620f23e232f28acbc4eed"
32
+ "gitHead": "fd630539d6115c6aa87037f5839011c9e6e42384"
34
33
  }
@@ -8,7 +8,7 @@
8
8
  "@zanobijs/common/*": ["../common/*"]
9
9
  }
10
10
  },
11
- "exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"],
11
+ "exclude": ["node_modules", "dist", "__test__/**/*", "*.spec.ts"],
12
12
  "references": [
13
13
  {
14
14
  "path": "../common/tsconfig.build.json"
@@ -1 +0,0 @@
1
- export {};
@@ -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,10 +0,0 @@
1
- export declare class ModuleTestEmpty {
2
- }
3
- export declare class ModuleTest {
4
- }
5
- export declare class ModuleTestWithInjector {
6
- }
7
- export declare class ModuleTestWithImports {
8
- }
9
- export declare class ModuleTestAll {
10
- }
@@ -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";
File without changes
@@ -1 +0,0 @@
1
- "use strict";