@bool-ts/core 1.0.4 → 1.0.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/__test/module.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Module } from "../src";
2
2
  import { TestController } from "./controller";
3
- import { TestRepository } from "./repository";
3
+ // import { TestRepository } from "./repository";
4
4
  import { TestService } from "./service";
5
5
 
6
6
  @Module({
@@ -8,7 +8,7 @@ import { TestService } from "./service";
8
8
  TestController
9
9
  ],
10
10
  dependencies: [
11
- TestService,
11
+ // TestService,
12
12
  // TestRepository
13
13
  ]
14
14
  })
@@ -7,19 +7,18 @@ export const Injector = new class {
7
7
  * @param constructor
8
8
  */
9
9
  get(target) {
10
- if (this._mapper.has(target)) {
11
- return this._mapper.get(target);
10
+ if (this._mapper.has(target.constructor)) {
11
+ return this._mapper.get(target.constructor);
12
12
  }
13
- const ownMetadataKeys = Reflect.getOwnMetadataKeys(target);
13
+ const ownMetadataKeys = Reflect.getOwnMetadataKeys(target.constructor);
14
14
  if (!ownMetadataKeys.includes(injectableKey)) {
15
- console.error("Current metadata keys:", ownMetadataKeys, Reflect.getOwnMetadataKeys(target.constructor));
16
15
  throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
17
16
  }
18
17
  // Initialize dependencies injection
19
18
  const dependencies = Reflect.getOwnMetadata("design:paramtypes", target) || [];
20
19
  const injections = dependencies.map(dependency => Injector.get(dependency));
21
- const instance = new target(...injections);
22
- this._mapper.set(target, instance);
20
+ const instance = target.constructor(...injections);
21
+ this._mapper.set(target.constructor, instance);
23
22
  return instance;
24
23
  }
25
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bool-ts/core",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -15,26 +15,25 @@ export const Injector: IInjector = new class {
15
15
  *
16
16
  * @param constructor
17
17
  */
18
- get<T>(
19
- target: new (...args: any[]) => T
18
+ get<T extends Object>(
19
+ target: T
20
20
  ) {
21
- if (this._mapper.has(target)) {
22
- return this._mapper.get(target) as T;
21
+ if (this._mapper.has(target.constructor)) {
22
+ return this._mapper.get(target.constructor) as T;
23
23
  }
24
24
 
25
- const ownMetadataKeys = Reflect.getOwnMetadataKeys(target);
25
+ const ownMetadataKeys = Reflect.getOwnMetadataKeys(target.constructor);
26
26
 
27
27
  if (!ownMetadataKeys.includes(injectableKey)) {
28
- console.error("Current metadata keys:", ownMetadataKeys, Reflect.getOwnMetadataKeys((target as Function).constructor));
29
28
  throw Error("Missing dependency declaration, please check @Injectable() used on dependency(ies).");
30
29
  }
31
30
 
32
31
  // Initialize dependencies injection
33
32
  const dependencies: any[] = Reflect.getOwnMetadata("design:paramtypes", target) || [];
34
33
  const injections: any[] = dependencies.map(dependency => Injector.get(dependency));
35
- const instance = new target(...injections);
34
+ const instance = target.constructor(...injections);
36
35
 
37
- this._mapper.set(target, instance);
36
+ this._mapper.set(target.constructor, instance);
38
37
 
39
38
  return instance;
40
39
  }