@zanobijs/core 1.0.0-beta.1 → 1.0.0-beta.3
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 +173 -5
- package/__test__/factory.spec.js +33 -3
- package/__test__/mocks/classModule.mock.js +6 -6
- package/__test__/mocks/classWithDependeciesClass.mock.js +5 -5
- package/__test__/mocks/classWithDependeciesInject.mock.js +11 -11
- package/exceptions/constant.message.d.ts +1 -0
- package/exceptions/constant.message.js +3 -1
- package/exceptions/invalid.module.exception.d.ts +3 -3
- package/exceptions/invalid.module.exception.js +3 -3
- package/exceptions/resolution.exception.d.ts +13 -0
- package/exceptions/resolution.exception.js +20 -0
- package/factory.js +9 -1
- package/injector/injector.js +2 -2
- package/injector/module.js +2 -2
- package/metadata.d.ts +1 -1
- package/metadata.js +1 -1
- package/package.json +3 -3
- package/tsconfig.build.json +2 -2
- package/__test__/factory.spec.ts +0 -37
- package/__test__/injector/injector.spec.ts +0 -32
- package/__test__/injector/module.spec.ts +0 -66
- package/__test__/metadata.spec.ts +0 -71
- package/__test__/mocks/classModule.mock.ts +0 -55
- package/__test__/mocks/classWithDependeciesClass.mock.ts +0 -21
- package/__test__/mocks/classWithDependeciesInject.mock.ts +0 -47
- package/__test__/mocks/index.ts +0 -1
- package/exceptions/constant.message.ts +0 -1
- package/exceptions/index.ts +0 -2
- package/exceptions/invalid.module.exception.ts +0 -16
- package/factory.ts +0 -69
- package/index.ts +0 -2
- package/injector/index.ts +0 -2
- package/injector/injector.ts +0 -89
- package/injector/module.ts +0 -149
- package/interface/index.ts +0 -1
- package/metadata.ts +0 -178
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -11
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.3](https://github.com/devdroide/ZanobiJS/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2023-11-14)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @zanobijs/core
|
package/README.md
CHANGED
|
@@ -1,11 +1,179 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ZanobiJS
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
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
|
+
## Features
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
- Small and efficient.
|
|
7
|
+
- Written in TypeScript/JavaScript.
|
|
8
|
+
- Ideal for building server-side microservices.
|
|
9
|
+
- Optimized scalability and performance.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Install my-project with npm
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @zanobijs/common @zanobijs/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Directories
|
|
21
|
+
|
|
22
|
+
├── ...
|
|
23
|
+
├── example # Feature example
|
|
24
|
+
│ ├── example.controller.ts # Controller
|
|
25
|
+
| ├── example.service.ts # Service
|
|
26
|
+
├── app.module.ts # Main Module
|
|
27
|
+
├── index.ts # Handler or bootstrap
|
|
28
|
+
└── ...
|
|
29
|
+
## Usage/Examples
|
|
30
|
+
|
|
31
|
+
### example.service.ts
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
import { Inject, Injectable } from "@zanobijs/common";
|
|
35
|
+
|
|
36
|
+
@Injectable()
|
|
37
|
+
export class ServiceExample {
|
|
38
|
+
constructor(
|
|
39
|
+
@Inject("API_CLIENT") private apiClient: string,
|
|
40
|
+
@Inject("API_KEY") private apiKey: string
|
|
41
|
+
) {}
|
|
42
|
+
getHello() {
|
|
43
|
+
return "Hello ServiceExample";
|
|
44
|
+
}
|
|
45
|
+
getApiClient(){
|
|
46
|
+
return this.apiClient
|
|
47
|
+
}
|
|
48
|
+
getApiKey(){
|
|
49
|
+
return this.apiKey
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
### example.controller.ts
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import { Controller, Inject } from "@zanobijs/common";
|
|
58
|
+
import { ServiceExample } from "./example.service";
|
|
59
|
+
|
|
60
|
+
@Controller()
|
|
61
|
+
export class ControllerExample {
|
|
62
|
+
constructor(
|
|
63
|
+
private sExample: ServiceExample,
|
|
64
|
+
@Inject("API_URL") private apiUrl: string
|
|
65
|
+
) {
|
|
66
|
+
this.apiUrl = apiUrl;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getApiUrl() {
|
|
70
|
+
return this.apiUrl;
|
|
71
|
+
}
|
|
72
|
+
getHelloService() {
|
|
73
|
+
return this.sExample.getHello();
|
|
74
|
+
}
|
|
75
|
+
getClienteService() {
|
|
76
|
+
return this.sExample.getApiClient();
|
|
77
|
+
}
|
|
78
|
+
getKeyService() {
|
|
79
|
+
return this.sExample.getApiKey();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
### AppModule.ts
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
import { Module } from "@zanobijs/common";
|
|
87
|
+
import { ControllerExample } from "./example/example.controller";
|
|
88
|
+
import { ServiceExample } from "./example/example.service";
|
|
89
|
+
|
|
90
|
+
@Module({
|
|
91
|
+
imports: [],
|
|
92
|
+
controllers: [ControllerExample],
|
|
93
|
+
services: [
|
|
94
|
+
ServiceExample,
|
|
95
|
+
{
|
|
96
|
+
provider: "API_URL",
|
|
97
|
+
useValue: "https://url.com",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
provider: "API_KEY",
|
|
101
|
+
useValue: "myKey12345API",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
provider: "API_CLIENT",
|
|
105
|
+
useValue: "thisClientAPI",
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
exports: [],
|
|
109
|
+
})
|
|
110
|
+
export class AppModule {}
|
|
6
111
|
|
|
7
112
|
```
|
|
8
|
-
const core = require('core');
|
|
9
113
|
|
|
10
|
-
|
|
114
|
+
### Index.ts
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
import { Factory } from "@zanobijs/core";
|
|
118
|
+
import { AppModule } from "./app.module";
|
|
119
|
+
import { ControllerExample } from "./example/example.controller";
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
const bootstrap = () => {
|
|
123
|
+
const factory = new Factory(AppModule);
|
|
124
|
+
const app = factory.create();
|
|
125
|
+
const controllerExample = app.get<ControllerExample>(
|
|
126
|
+
"controllerExample"
|
|
127
|
+
);
|
|
128
|
+
console.log(controllerExample.getHelloService());
|
|
129
|
+
console.log(controllerExample.getApiUrl());
|
|
130
|
+
console.log(controllerExample.getClienteService());
|
|
131
|
+
console.log(controllerExample.getKeyService());
|
|
132
|
+
}
|
|
133
|
+
bootstrap();
|
|
134
|
+
// Hello ServiceExample
|
|
135
|
+
// https://url.com
|
|
136
|
+
// thisClientAPI
|
|
137
|
+
// myKey12345API
|
|
11
138
|
```
|
|
139
|
+
## Use Logger
|
|
140
|
+
|
|
141
|
+
- Import logger service of @zanobij/common/utils.
|
|
142
|
+
- Define whether the record is visible. [Default is false]
|
|
143
|
+
- Get the service.
|
|
144
|
+
- Use the different events (success, info, warn, error, debug).
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
import { Logger } from "@zanobijs/common/utils";
|
|
148
|
+
|
|
149
|
+
process.env.ZANOBIJS_LOGGER = "true";
|
|
150
|
+
|
|
151
|
+
const logger = Logger();
|
|
152
|
+
|
|
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");
|
|
158
|
+
|
|
159
|
+
// ***** PRINT *****
|
|
160
|
+
// [SUCCESS]: Lorem ipsum success <green print>
|
|
161
|
+
// [INFO]: Lorem ipsum info <blue print>
|
|
162
|
+
// [WARN]: Lorem ipsum warn <yellow print>
|
|
163
|
+
// [ERROR]: Lorem ipsum error <red print>
|
|
164
|
+
// [DEBUG]: Lorem ipsum debug <white print>
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
## Authors
|
|
168
|
+
|
|
169
|
+
- [@devdroide](https://www.github.com/devdroide)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
## Credits
|
|
173
|
+
|
|
174
|
+
ZanobiJS is heavily inspired [NestJS](https://nestjs.com/) and [AngularJS](https://angularjs.org/). Credits
|
|
175
|
+
|
|
176
|
+
Finally, it is an effort to provide help with the construction of lambdas initially.
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
Private - Read License
|
package/__test__/factory.spec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const chai_1 = require("chai");
|
|
4
|
-
// import { Module } from "zanobijs
|
|
4
|
+
// import { Module } from "@zanobijs/common";
|
|
5
5
|
const index_1 = require("../index");
|
|
6
6
|
const classModule_mock_1 = require("./mocks/classModule.mock");
|
|
7
7
|
describe("Core - factory", () => {
|
|
@@ -11,7 +11,7 @@ describe("Core - factory", () => {
|
|
|
11
11
|
class ModuleWithoutDecorator {
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
new index_1.Factory(ModuleWithoutDecorator);
|
|
15
15
|
}
|
|
16
16
|
catch (error) {
|
|
17
17
|
(0, chai_1.expect)(error.message).to.be.equal("The class must have an annotation @Module()");
|
|
@@ -23,11 +23,41 @@ describe("Core - factory", () => {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
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
|
+
});
|
|
26
57
|
it("should respond apiKey to controller the app", () => {
|
|
27
58
|
const app = factory.create();
|
|
28
59
|
const controllerWithDepen2 = app.get("controllerWithDepen2");
|
|
29
60
|
(0, chai_1.expect)(controllerWithDepen2.getApiKey()).to.be.equal("isApiKey_qwerty12345");
|
|
30
61
|
});
|
|
31
62
|
});
|
|
32
|
-
// it("", () => {});
|
|
33
63
|
});
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ModuleTestAll = exports.ModuleTestWithImports = exports.ModuleTestWithInjector = exports.ModuleTest = exports.ModuleTestEmpty = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const common_1 = require("@zanobijs/common");
|
|
6
6
|
const classWithDependeciesClass_mock_1 = require("./classWithDependeciesClass.mock");
|
|
7
7
|
const classWithDependeciesInject_mock_1 = require("./classWithDependeciesInject.mock");
|
|
8
8
|
let ModuleTestEmpty = class ModuleTestEmpty {
|
|
9
9
|
};
|
|
10
10
|
exports.ModuleTestEmpty = ModuleTestEmpty;
|
|
11
11
|
exports.ModuleTestEmpty = ModuleTestEmpty = tslib_1.__decorate([
|
|
12
|
-
(0,
|
|
12
|
+
(0, common_1.Module)({
|
|
13
13
|
imports: [],
|
|
14
14
|
controllers: [],
|
|
15
15
|
services: [],
|
|
@@ -20,7 +20,7 @@ let ModuleTest = class ModuleTest {
|
|
|
20
20
|
};
|
|
21
21
|
exports.ModuleTest = ModuleTest;
|
|
22
22
|
exports.ModuleTest = ModuleTest = tslib_1.__decorate([
|
|
23
|
-
(0,
|
|
23
|
+
(0, common_1.Module)({
|
|
24
24
|
imports: [],
|
|
25
25
|
controllers: [classWithDependeciesClass_mock_1.ControllerWithDepenClass],
|
|
26
26
|
services: [classWithDependeciesClass_mock_1.ServiceToController],
|
|
@@ -31,7 +31,7 @@ let ModuleTestWithInjector = class ModuleTestWithInjector {
|
|
|
31
31
|
};
|
|
32
32
|
exports.ModuleTestWithInjector = ModuleTestWithInjector;
|
|
33
33
|
exports.ModuleTestWithInjector = ModuleTestWithInjector = tslib_1.__decorate([
|
|
34
|
-
(0,
|
|
34
|
+
(0, common_1.Module)({
|
|
35
35
|
imports: [],
|
|
36
36
|
controllers: [classWithDependeciesInject_mock_1.ControllerWithDepen2],
|
|
37
37
|
services: [
|
|
@@ -48,7 +48,7 @@ let ModuleTestWithImports = class ModuleTestWithImports {
|
|
|
48
48
|
};
|
|
49
49
|
exports.ModuleTestWithImports = ModuleTestWithImports;
|
|
50
50
|
exports.ModuleTestWithImports = ModuleTestWithImports = tslib_1.__decorate([
|
|
51
|
-
(0,
|
|
51
|
+
(0, common_1.Module)({
|
|
52
52
|
imports: [ModuleTestWithInjector],
|
|
53
53
|
controllers: [],
|
|
54
54
|
services: [],
|
|
@@ -59,7 +59,7 @@ let ModuleTestAll = class ModuleTestAll {
|
|
|
59
59
|
};
|
|
60
60
|
exports.ModuleTestAll = ModuleTestAll;
|
|
61
61
|
exports.ModuleTestAll = ModuleTestAll = tslib_1.__decorate([
|
|
62
|
-
(0,
|
|
62
|
+
(0, common_1.Module)({
|
|
63
63
|
imports: [ModuleTestWithInjector],
|
|
64
64
|
controllers: [classWithDependeciesInject_mock_1.ControllerWithDepen2],
|
|
65
65
|
services: [
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ControllerWithDepenClass = exports.ServiceToController = exports.Service = exports.ServiceToService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const common_1 = require("@zanobijs/common");
|
|
6
6
|
let ServiceToService = class ServiceToService {
|
|
7
7
|
constructor() { }
|
|
8
8
|
};
|
|
9
9
|
exports.ServiceToService = ServiceToService;
|
|
10
10
|
exports.ServiceToService = ServiceToService = tslib_1.__decorate([
|
|
11
|
-
(0,
|
|
11
|
+
(0, common_1.Injectable)(),
|
|
12
12
|
tslib_1.__metadata("design:paramtypes", [])
|
|
13
13
|
], ServiceToService);
|
|
14
14
|
let Service = class Service {
|
|
@@ -16,7 +16,7 @@ let Service = class Service {
|
|
|
16
16
|
};
|
|
17
17
|
exports.Service = Service;
|
|
18
18
|
exports.Service = Service = tslib_1.__decorate([
|
|
19
|
-
(0,
|
|
19
|
+
(0, common_1.Injectable)(),
|
|
20
20
|
tslib_1.__metadata("design:paramtypes", [])
|
|
21
21
|
], Service);
|
|
22
22
|
let ServiceToController = class ServiceToController {
|
|
@@ -24,7 +24,7 @@ let ServiceToController = class ServiceToController {
|
|
|
24
24
|
};
|
|
25
25
|
exports.ServiceToController = ServiceToController;
|
|
26
26
|
exports.ServiceToController = ServiceToController = tslib_1.__decorate([
|
|
27
|
-
(0,
|
|
27
|
+
(0, common_1.Injectable)(),
|
|
28
28
|
tslib_1.__metadata("design:paramtypes", [])
|
|
29
29
|
], ServiceToController);
|
|
30
30
|
let ControllerWithDepenClass = class ControllerWithDepenClass {
|
|
@@ -35,6 +35,6 @@ let ControllerWithDepenClass = class ControllerWithDepenClass {
|
|
|
35
35
|
};
|
|
36
36
|
exports.ControllerWithDepenClass = ControllerWithDepenClass;
|
|
37
37
|
exports.ControllerWithDepenClass = ControllerWithDepenClass = tslib_1.__decorate([
|
|
38
|
-
(0,
|
|
38
|
+
(0, common_1.Controller)(),
|
|
39
39
|
tslib_1.__metadata("design:paramtypes", [ServiceToController])
|
|
40
40
|
], ControllerWithDepenClass);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceWithDepen2 = exports.ControllerWithDepen2 = exports.ServiceWithDepenParam = exports.ServiceToController2 = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const common_1 = require("@zanobijs/common");
|
|
6
6
|
let ServiceToController2 = class ServiceToController2 {
|
|
7
7
|
constructor() { }
|
|
8
8
|
getHello() {
|
|
@@ -11,7 +11,7 @@ let ServiceToController2 = class ServiceToController2 {
|
|
|
11
11
|
};
|
|
12
12
|
exports.ServiceToController2 = ServiceToController2;
|
|
13
13
|
exports.ServiceToController2 = ServiceToController2 = tslib_1.__decorate([
|
|
14
|
-
(0,
|
|
14
|
+
(0, common_1.Injectable)(),
|
|
15
15
|
tslib_1.__metadata("design:paramtypes", [])
|
|
16
16
|
], ServiceToController2);
|
|
17
17
|
let ServiceWithDepenParam = class ServiceWithDepenParam {
|
|
@@ -30,11 +30,11 @@ let ServiceWithDepenParam = class ServiceWithDepenParam {
|
|
|
30
30
|
};
|
|
31
31
|
exports.ServiceWithDepenParam = ServiceWithDepenParam;
|
|
32
32
|
exports.ServiceWithDepenParam = ServiceWithDepenParam = tslib_1.__decorate([
|
|
33
|
-
(0,
|
|
34
|
-
tslib_1.__param(1, (0,
|
|
35
|
-
tslib_1.__param(2, (0,
|
|
36
|
-
tslib_1.__param(3, (0,
|
|
37
|
-
tslib_1.__param(4, (0,
|
|
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
38
|
tslib_1.__metadata("design:paramtypes", [ServiceToController2, String, Number, Boolean, Array])
|
|
39
39
|
], ServiceWithDepenParam);
|
|
40
40
|
let ControllerWithDepen2 = class ControllerWithDepen2 {
|
|
@@ -54,8 +54,8 @@ let ControllerWithDepen2 = class ControllerWithDepen2 {
|
|
|
54
54
|
};
|
|
55
55
|
exports.ControllerWithDepen2 = ControllerWithDepen2;
|
|
56
56
|
exports.ControllerWithDepen2 = ControllerWithDepen2 = tslib_1.__decorate([
|
|
57
|
-
(0,
|
|
58
|
-
tslib_1.__param(1, (0,
|
|
57
|
+
(0, common_1.Controller)(),
|
|
58
|
+
tslib_1.__param(1, (0, common_1.Inject)("API_KEY")),
|
|
59
59
|
tslib_1.__metadata("design:paramtypes", [ServiceToController2, String])
|
|
60
60
|
], ControllerWithDepen2);
|
|
61
61
|
let ServiceWithDepen2 = class ServiceWithDepen2 {
|
|
@@ -68,7 +68,7 @@ let ServiceWithDepen2 = class ServiceWithDepen2 {
|
|
|
68
68
|
};
|
|
69
69
|
exports.ServiceWithDepen2 = ServiceWithDepen2;
|
|
70
70
|
exports.ServiceWithDepen2 = ServiceWithDepen2 = tslib_1.__decorate([
|
|
71
|
-
(0,
|
|
72
|
-
tslib_1.__param(1, (0,
|
|
71
|
+
(0, common_1.Injectable)(),
|
|
72
|
+
tslib_1.__param(1, (0, common_1.Inject)("API_KEY")),
|
|
73
73
|
tslib_1.__metadata("design:paramtypes", [ServiceWithDepenParam, String])
|
|
74
74
|
], ServiceWithDepen2);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MODULE_INVALID_ANNOTATION_ERROR = void 0;
|
|
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.`;
|
|
7
|
+
exports.CONTAINER_RESOLUTION_ERROR = CONTAINER_RESOLUTION_ERROR;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { RuntimeException } from "zanobijs
|
|
1
|
+
import { RuntimeException } from "@zanobijs/common/exceptions/runtime.exception";
|
|
2
2
|
/**
|
|
3
3
|
* Excepción lanzada cuando una clase Modulo no tiene el decorador `@Module`
|
|
4
|
-
* de zanobijs
|
|
4
|
+
* de @zanobijs/common
|
|
5
5
|
*
|
|
6
6
|
* @remarks
|
|
7
|
-
* Esta clase extiende la base `RuntimeException`de zanobijs
|
|
7
|
+
* Esta clase extiende la base `RuntimeException`de @zanobijs/common
|
|
8
8
|
* para proporcionar detalles adicionales específicos a esquemas de módulos inválidos.
|
|
9
9
|
*/
|
|
10
10
|
export declare class InvalidModuleAnnotationException extends RuntimeException {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InvalidModuleAnnotationException = void 0;
|
|
4
|
-
const runtime_exception_1 = require("zanobijs
|
|
4
|
+
const runtime_exception_1 = require("@zanobijs/common/exceptions/runtime.exception");
|
|
5
5
|
const constant_message_1 = require("./constant.message");
|
|
6
6
|
/**
|
|
7
7
|
* Excepción lanzada cuando una clase Modulo no tiene el decorador `@Module`
|
|
8
|
-
* de zanobijs
|
|
8
|
+
* de @zanobijs/common
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
|
-
* Esta clase extiende la base `RuntimeException`de zanobijs
|
|
11
|
+
* Esta clase extiende la base `RuntimeException`de @zanobijs/common
|
|
12
12
|
* para proporcionar detalles adicionales específicos a esquemas de módulos inválidos.
|
|
13
13
|
*/
|
|
14
14
|
class InvalidModuleAnnotationException extends runtime_exception_1.RuntimeException {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { RuntimeException } from "@zanobijs/common/exceptions/runtime.exception";
|
|
2
|
+
/**
|
|
3
|
+
* Excepción lanzada cuando se intenta obtener una entidad
|
|
4
|
+
* (importar, controlador, servicio o exportar) que no fue
|
|
5
|
+
* declarada en `@Module` de @zanobijs/common
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Esta clase extiende la base `RuntimeException`de @zanobijs/core
|
|
9
|
+
* para proporcionar detalles adicionales del error.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ContainerResolutionException extends RuntimeException {
|
|
12
|
+
constructor(entity: string, detail?: any);
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContainerResolutionException = void 0;
|
|
4
|
+
const runtime_exception_1 = require("@zanobijs/common/exceptions/runtime.exception");
|
|
5
|
+
const constant_message_1 = require("./constant.message");
|
|
6
|
+
/**
|
|
7
|
+
* Excepción lanzada cuando se intenta obtener una entidad
|
|
8
|
+
* (importar, controlador, servicio o exportar) que no fue
|
|
9
|
+
* declarada en `@Module` de @zanobijs/common
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Esta clase extiende la base `RuntimeException`de @zanobijs/core
|
|
13
|
+
* para proporcionar detalles adicionales del error.
|
|
14
|
+
*/
|
|
15
|
+
class ContainerResolutionException extends runtime_exception_1.RuntimeException {
|
|
16
|
+
constructor(entity, detail = ``) {
|
|
17
|
+
super((0, constant_message_1.CONTAINER_RESOLUTION_ERROR)(entity), detail);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ContainerResolutionException = ContainerResolutionException;
|
package/factory.js
CHANGED
|
@@ -4,6 +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
|
+
const resolution_exception_1 = require("./exceptions/resolution.exception");
|
|
7
9
|
/**
|
|
8
10
|
* Factory es una clase que facilita la creación y configuración de
|
|
9
11
|
* contenedores de inyección de dependencias utilizando metadatos y
|
|
@@ -58,7 +60,13 @@ class Factory {
|
|
|
58
60
|
* @returns {any} - Instancia resuelta.
|
|
59
61
|
*/
|
|
60
62
|
get(entity) {
|
|
61
|
-
|
|
63
|
+
try {
|
|
64
|
+
const entityUnCapitalize = (0, shared_utils_1.unCapitalize)(entity);
|
|
65
|
+
return this.container.resolve(entityUnCapitalize);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new resolution_exception_1.ContainerResolutionException(entity, error.message);
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
exports.Factory = Factory;
|
package/injector/injector.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Injector = void 0;
|
|
4
4
|
const metadata_1 = require("../metadata");
|
|
5
|
-
const utils_1 = require("zanobijs
|
|
6
|
-
const shared_utils_1 = require("zanobijs
|
|
5
|
+
const utils_1 = require("@zanobijs/common/utils");
|
|
6
|
+
const shared_utils_1 = require("@zanobijs/common/utils/shared.utils");
|
|
7
7
|
const awilix_1 = require("awilix");
|
|
8
8
|
/**
|
|
9
9
|
* La clase `Injector` es la encargada de manejar la inyección de dependencias
|
package/injector/module.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Module = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const awilix_1 = require("awilix");
|
|
6
|
-
const shared_utils_1 = require("zanobijs
|
|
7
|
-
const utils_1 = require("zanobijs
|
|
6
|
+
const shared_utils_1 = require("@zanobijs/common/utils/shared.utils");
|
|
7
|
+
const utils_1 = require("@zanobijs/common/utils");
|
|
8
8
|
const injector_1 = require("./injector");
|
|
9
9
|
const metadata_1 = require("../metadata");
|
|
10
10
|
const exceptions_1 = require("../exceptions");
|
package/metadata.d.ts
CHANGED
package/metadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Metadata = void 0;
|
|
4
|
-
const constants_1 = require("zanobijs
|
|
4
|
+
const constants_1 = require("@zanobijs/common/utils/constants");
|
|
5
5
|
/**
|
|
6
6
|
* La clase `Metadata` proporciona métodos para acceder y manipular
|
|
7
7
|
* metadatos relacionados con diversos componentes y módulos.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zanobijs/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
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>",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"reflect-metadata": "^0.1.13"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"zanobijs
|
|
31
|
+
"@zanobijs/common": "*"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "325565f63aecaf48b12620f23e232f28acbc4eed"
|
|
34
34
|
}
|
package/tsconfig.build.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"outDir": ".",
|
|
5
5
|
"rootDir": ".",
|
|
6
6
|
"paths": {
|
|
7
|
-
"zanobijs
|
|
8
|
-
"zanobijs
|
|
7
|
+
"@zanobijs/common": ["../common"],
|
|
8
|
+
"@zanobijs/common/*": ["../common/*"]
|
|
9
9
|
}
|
|
10
10
|
},
|
|
11
11
|
"exclude": ["node_modules", "dist", "test/**/*", "*.spec.ts"],
|
package/__test__/factory.spec.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
// import { Module } from "zanobijs-common";
|
|
3
|
-
import { Factory } from "../index";
|
|
4
|
-
import { ModuleTestAll } from "./mocks/classModule.mock";
|
|
5
|
-
import { ControllerWithDepen2 } from "./mocks/classWithDependeciesInject.mock";
|
|
6
|
-
|
|
7
|
-
describe("Core - factory", () => {
|
|
8
|
-
const factory = new Factory(ModuleTestAll);
|
|
9
|
-
describe("Create Factory App", () => {
|
|
10
|
-
it("should respond error to create factory by error @Module", () => {
|
|
11
|
-
class ModuleWithoutDecorator {}
|
|
12
|
-
try {
|
|
13
|
-
const factoryError = new Factory(ModuleWithoutDecorator);
|
|
14
|
-
} catch (error) {
|
|
15
|
-
expect(error.message).to.be.equal(
|
|
16
|
-
"The class must have an annotation @Module()",
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
it("should respond create factory", () => {
|
|
21
|
-
const app = factory.create();
|
|
22
|
-
expect(app).to.be.instanceOf(Factory);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
describe("Get Entities", () => {
|
|
26
|
-
it("should respond apiKey to controller the app", () => {
|
|
27
|
-
const app = factory.create();
|
|
28
|
-
const controllerWithDepen2 = app.get<ControllerWithDepen2>(
|
|
29
|
-
"controllerWithDepen2",
|
|
30
|
-
);
|
|
31
|
-
expect(controllerWithDepen2.getApiKey()).to.be.equal(
|
|
32
|
-
"isApiKey_qwerty12345",
|
|
33
|
-
);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
// it("", () => {});
|
|
37
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import { Injector } from "../../injector";
|
|
3
|
-
import { ModuleTestWithInjector } from "../mocks/classModule.mock";
|
|
4
|
-
import { ControllerWithDepen2 } from "../mocks/classWithDependeciesInject.mock";
|
|
5
|
-
import { ControllerWithDepenClass } from "../mocks/classWithDependeciesClass.mock";
|
|
6
|
-
|
|
7
|
-
describe("Core - Injector - injector", () => {
|
|
8
|
-
const injector = new Injector(ModuleTestWithInjector);
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
process.env.ZANOBI_DEBUG = "false";
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("Should respond an object with paramters to inject", () => {
|
|
14
|
-
const getInjectData = injector.getInjectData(ControllerWithDepenClass);
|
|
15
|
-
expect(getInjectData).to.is.empty;
|
|
16
|
-
});
|
|
17
|
-
it("Should respond an object without paramters to inject", () => {
|
|
18
|
-
const getInjectData = injector.getInjectData(ControllerWithDepen2);
|
|
19
|
-
expect(getInjectData).to.have.property("apiKey");
|
|
20
|
-
});
|
|
21
|
-
it("Should respond an object type asClass with paramters to inject", () => {
|
|
22
|
-
const getInject = injector.getInjector(ControllerWithDepen2);
|
|
23
|
-
expect(getInject).to.have.property("lifetime");
|
|
24
|
-
expect(getInject).to.have.property("inject");
|
|
25
|
-
expect(getInject).to.have.property("injector");
|
|
26
|
-
});
|
|
27
|
-
it("Should respond an object type asClass without injector", () => {
|
|
28
|
-
const getInject = injector.getInjector(ControllerWithDepenClass);
|
|
29
|
-
expect(getInject).to.not.have.property("injector");
|
|
30
|
-
});
|
|
31
|
-
// it("", () => {});
|
|
32
|
-
});
|