@bool-ts/core 1.9.1 → 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.
@@ -1,5 +1,13 @@
1
1
  import "reflect-metadata";
2
- import { controllerKey, dispatcherKey, guardKey, injectableKey, injectKey, middlewareKey, webSocketKey } from "../keys";
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 constructor
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
- ![injectableKey, controllerKey, middlewareKey, guardKey, dispatcherKey, webSocketKey].some((value) =>
31
- ownMetadataKeys.includes(value)
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("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
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;