@bool-ts/core 1.9.0 → 1.9.2
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/__test/_constants.ts +1 -0
- package/__test/container.ts +28 -0
- package/__test/controller.ts +1 -1
- package/__test/{module.ts → firstModule.ts} +4 -6
- package/__test/index.ts +2 -4
- package/__test/secondModule.ts +29 -0
- package/__test/tsconfig.json +1 -1
- package/__test/webSocket.ts +1 -1
- package/dist/decorators/arguments.d.ts +6 -1
- package/dist/decorators/container.d.ts +29 -0
- package/dist/decorators/http.d.ts +2 -0
- package/dist/decorators/index.d.ts +4 -2
- package/dist/decorators/module.d.ts +6 -2
- package/dist/decorators/webSocket.d.ts +2 -0
- package/dist/entities/httpRoute.d.ts +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/interfaces/context.d.ts +8 -2
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/keys/index.d.ts +3 -0
- package/dist/producers/context.d.ts +13 -0
- package/dist/{hooks → producers}/factory.d.ts +5 -2
- package/dist/{hooks → producers}/injector.d.ts +7 -1
- package/package.json +3 -3
- package/src/decorators/arguments.ts +126 -77
- package/src/decorators/container.ts +94 -0
- package/src/decorators/controller.ts +1 -1
- package/src/decorators/http.ts +9 -2
- package/src/decorators/index.ts +4 -1
- package/src/decorators/module.ts +27 -4
- package/src/decorators/webSocket.ts +6 -2
- package/src/entities/httpRoute.ts +2 -0
- package/src/index.ts +1 -1
- package/src/interfaces/context.ts +9 -2
- package/src/interfaces/index.ts +1 -1
- package/src/keys/index.ts +3 -0
- package/src/producers/context.ts +63 -0
- package/src/producers/factory.ts +2013 -0
- package/src/{hooks → producers}/injector.ts +41 -6
- package/src/hooks/factory.ts +0 -1701
- /package/dist/{hooks → producers}/index.d.ts +0 -0
- /package/src/{hooks → producers}/index.ts +0 -0
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
controllerKey,
|
|
4
|
+
dispatcherKey,
|
|
5
|
+
guardKey,
|
|
6
|
+
injectableKey,
|
|
7
|
+
injectKey,
|
|
8
|
+
middlewareKey,
|
|
9
|
+
webSocketKey
|
|
10
|
+
} from "../keys";
|
|
3
11
|
|
|
4
12
|
type TDefinition<T = any> = { new (...args: any[]): T } | string | symbol;
|
|
5
13
|
|
|
@@ -13,7 +21,19 @@ export class Injector implements IInjector {
|
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
23
|
*
|
|
16
|
-
* @param
|
|
24
|
+
* @param injectors
|
|
25
|
+
*/
|
|
26
|
+
constructor(...injectors: Array<Injector>) {
|
|
27
|
+
injectors.forEach((injector) => {
|
|
28
|
+
injector.entries.forEach(([key, value]) => {
|
|
29
|
+
this._mapper.set(key, value);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param definition
|
|
17
37
|
*/
|
|
18
38
|
get<T>(definition: TDefinition) {
|
|
19
39
|
if (this._mapper.has(definition)) {
|
|
@@ -27,11 +47,18 @@ export class Injector implements IInjector {
|
|
|
27
47
|
const ownMetadataKeys = Reflect.getMetadataKeys(definition);
|
|
28
48
|
|
|
29
49
|
if (
|
|
30
|
-
![
|
|
31
|
-
|
|
32
|
-
|
|
50
|
+
![
|
|
51
|
+
injectableKey,
|
|
52
|
+
controllerKey,
|
|
53
|
+
middlewareKey,
|
|
54
|
+
guardKey,
|
|
55
|
+
dispatcherKey,
|
|
56
|
+
webSocketKey
|
|
57
|
+
].some((value) => ownMetadataKeys.includes(value))
|
|
33
58
|
) {
|
|
34
|
-
throw Error(
|
|
59
|
+
throw Error(
|
|
60
|
+
"Missing dependency declaration, please check @Injectable() used on dependency(ies)."
|
|
61
|
+
);
|
|
35
62
|
}
|
|
36
63
|
|
|
37
64
|
// Initialize dependencies injection
|
|
@@ -50,8 +77,16 @@ export class Injector implements IInjector {
|
|
|
50
77
|
* @param value
|
|
51
78
|
*/
|
|
52
79
|
set(key: TDefinition, value: any) {
|
|
80
|
+
if (this._mapper.has(key)) {
|
|
81
|
+
throw Error(`${String(key)} already exists in injector collection.`);
|
|
82
|
+
}
|
|
83
|
+
|
|
53
84
|
this._mapper.set(key, value);
|
|
54
85
|
}
|
|
86
|
+
|
|
87
|
+
get entries() {
|
|
88
|
+
return [...this._mapper.entries()];
|
|
89
|
+
}
|
|
55
90
|
}
|
|
56
91
|
|
|
57
92
|
export default Injector;
|