@expressots/core 1.3.0 → 1.4.1

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 (69) hide show
  1. package/README.md +10 -14
  2. package/lib/CHANGELOG.md +23 -13
  3. package/lib/README.md +10 -14
  4. package/lib/cjs/application/app-container.js +28 -11
  5. package/lib/cjs/container-module/container-module.js +69 -16
  6. package/lib/cjs/container-module/index.js +2 -1
  7. package/lib/cjs/controller/base-controller.js +2 -2
  8. package/lib/cjs/decorator/index.js +17 -0
  9. package/lib/cjs/decorator/scope-binding.js +12 -0
  10. package/lib/cjs/error/error-handler-middleware.js +1 -3
  11. package/lib/cjs/error/index.js +1 -3
  12. package/lib/cjs/error/report.js +26 -2
  13. package/lib/cjs/index.js +1 -0
  14. package/lib/cjs/logger/general-logger.js +2 -2
  15. package/lib/cjs/types/application/app-container.d.ts +18 -6
  16. package/lib/cjs/types/application/app-container.d.ts.map +1 -1
  17. package/lib/cjs/types/container-module/container-module.d.ts +14 -8
  18. package/lib/cjs/types/container-module/container-module.d.ts.map +1 -1
  19. package/lib/cjs/types/container-module/index.d.ts +1 -1
  20. package/lib/cjs/types/container-module/index.d.ts.map +1 -1
  21. package/lib/cjs/types/decorator/index.d.ts +2 -0
  22. package/lib/cjs/types/decorator/index.d.ts.map +1 -0
  23. package/lib/cjs/types/decorator/scope-binding.d.ts +4 -0
  24. package/lib/cjs/types/decorator/scope-binding.d.ts.map +1 -0
  25. package/lib/cjs/types/error/error-handler-middleware.d.ts +3 -3
  26. package/lib/cjs/types/error/error-handler-middleware.d.ts.map +1 -1
  27. package/lib/cjs/types/error/index.d.ts +0 -1
  28. package/lib/cjs/types/error/index.d.ts.map +1 -1
  29. package/lib/cjs/types/error/report.d.ts +10 -3
  30. package/lib/cjs/types/error/report.d.ts.map +1 -1
  31. package/lib/cjs/types/index.d.ts +1 -0
  32. package/lib/cjs/types/index.d.ts.map +1 -1
  33. package/lib/esm/application/app-container.js +29 -12
  34. package/lib/esm/container-module/container-module.js +69 -17
  35. package/lib/esm/container-module/index.js +1 -1
  36. package/lib/esm/controller/base-controller.js +2 -2
  37. package/lib/esm/decorator/index.js +1 -0
  38. package/lib/esm/decorator/scope-binding.js +8 -0
  39. package/lib/esm/error/error-handler-middleware.js +1 -3
  40. package/lib/esm/error/index.js +0 -1
  41. package/lib/esm/error/report.js +26 -2
  42. package/lib/esm/index.mjs +1 -0
  43. package/lib/esm/logger/general-logger.js +2 -2
  44. package/lib/esm/types/application/app-container.d.ts +18 -6
  45. package/lib/esm/types/application/app-container.d.ts.map +1 -1
  46. package/lib/esm/types/container-module/container-module.d.ts +14 -8
  47. package/lib/esm/types/container-module/container-module.d.ts.map +1 -1
  48. package/lib/esm/types/container-module/index.d.ts +1 -1
  49. package/lib/esm/types/container-module/index.d.ts.map +1 -1
  50. package/lib/esm/types/decorator/index.d.ts +2 -0
  51. package/lib/esm/types/decorator/index.d.ts.map +1 -0
  52. package/lib/esm/types/decorator/scope-binding.d.ts +4 -0
  53. package/lib/esm/types/decorator/scope-binding.d.ts.map +1 -0
  54. package/lib/esm/types/error/error-handler-middleware.d.ts +3 -3
  55. package/lib/esm/types/error/error-handler-middleware.d.ts.map +1 -1
  56. package/lib/esm/types/error/index.d.ts +0 -1
  57. package/lib/esm/types/error/index.d.ts.map +1 -1
  58. package/lib/esm/types/error/report.d.ts +10 -3
  59. package/lib/esm/types/error/report.d.ts.map +1 -1
  60. package/lib/esm/types/index.d.ts +1 -0
  61. package/lib/esm/types/index.d.ts.map +1 -1
  62. package/lib/package.json +3 -3
  63. package/package.json +3 -3
  64. package/lib/cjs/error/application-error.js +0 -37
  65. package/lib/cjs/types/error/application-error.d.ts +0 -18
  66. package/lib/cjs/types/error/application-error.d.ts.map +0 -1
  67. package/lib/esm/error/application-error.js +0 -36
  68. package/lib/esm/types/error/application-error.d.ts +0 -18
  69. package/lib/esm/types/error/application-error.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/alogo.png" width="120" alt="Expresso TS Logo" /></a>
2
+ <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
3
3
  </p>
4
4
 
5
5
  # Expresso TS
@@ -32,13 +32,15 @@ The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) i
32
32
 
33
33
  Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
34
34
 
35
- ## Support
35
+ ## Support the project
36
36
 
37
- ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
37
+ Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
38
38
 
39
- - Become a sponsor on GitHub
40
- - Follow the organization on GitHub and Star the project
41
- - Contribute submitting issues and pull requests
39
+ - Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
40
+ - Follow the **[organization](https://github.com/expressots)** on GitHub and Star the project
41
+ - Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
42
+ - Join our **[Discord](https://discord.com/invite/PyPJfGK)**
43
+ - Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
42
44
  - Share the project with your friends and colleagues
43
45
 
44
46
  ## Contributors
@@ -46,7 +48,7 @@ ExpressoTS is an MIT-licensed open source project. It's an independent project w
46
48
  - [Daniel Boll](https://github.com/daniel-boll)
47
49
  - [Felipe Fontana](https://github.com/f0ntana)
48
50
  - [Juliano Soares](https://github.com/juliano-soares)
49
- - [Vitor Caminha](https://github.com/VitorCaminha)
51
+ - [Vitor Caminha](https://github.com/VitorCaminha)
50
52
  - [Ariel Betti](https://github.com/ArielBetti)
51
53
  - [Rodrigo da Hora](https://github.com/dahorarodrigo)
52
54
 
@@ -54,12 +56,6 @@ ExpressoTS is an MIT-licensed open source project. It's an independent project w
54
56
 
55
57
  - Work in progress
56
58
 
57
- ## Stay in touch
58
-
59
- - Author: Richard Zampieri
60
- - Website: [https://expresso-ts.com](https://expresso-ts.com)
61
- - Twitch channel: [Richard Zampieri](https://www.twitch.tv/richardzampieri)
62
-
63
59
  ## License
64
60
 
65
- ExpressoTS is **[MIT licensed](LICENSE.md)**
61
+ ExpressoTS is **[MIT licensed](LICENSE.md)**
package/lib/CHANGELOG.md CHANGED
@@ -1,18 +1,28 @@
1
1
 
2
2
 
3
- ## [1.3.0](https://github.com/expressots/expressots/compare/v1.2.1...v1.3.0) (2023-04-21)
4
-
5
-
6
- ### Features
7
-
8
- * add user repository as singleton provider in opinionated template ([#24](https://github.com/expressots/expressots/issues/24)) ([3b5bded](https://github.com/expressots/expressots/commit/3b5bded07769d51f69b481e4b5e9b45c27d13a69))
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * add gitignore on opinionated template ([315d355](https://github.com/expressots/expressots/commit/315d355ed87eb6be85daddc250289d5e0d41cd21))
14
- * findall use case query db in memory ([ff8feea](https://github.com/expressots/expressots/commit/ff8feeaf36d0b74eebd9ab4e22f1910cff0a4df8))
15
- * the number of constructor arguments ([ccf2a48](https://github.com/expressots/expressots/commit/ccf2a4878e795e0182608546eae8cd83e3bea775))
3
+ ## [1.4.0](https://github.com/expressots/expressots/compare/v1.3.0...v1.4.0) (2023-05-14)
4
+
5
+ * add DI (dependency injection) singleton, transient, scope to container, providers, entities, etc
6
+
7
+ ### Bug Fixes
8
+
9
+ * update sponsor link on package
10
+ * add example with controller only ([11b4ce3](https://github.com/expressots/expressots/commit/11b4ce3124482122a4f47fb27b7a1b1e02731621))
11
+ * opinionated template ientity id ([dd50ca0](https://github.com/expressots/expressots/commit/dd50ca0926c98890cbe1342f804ca34152c4a9f9))
12
+
13
+ ## [1.3.0](https://github.com/expressots/expressots/compare/v1.2.1...v1.3.0) (2023-04-21)
14
+
15
+
16
+ ### Features
17
+
18
+ * add user repository as singleton provider in opinionated template ([#24](https://github.com/expressots/expressots/issues/24)) ([3b5bded](https://github.com/expressots/expressots/commit/3b5bded07769d51f69b481e4b5e9b45c27d13a69))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * add gitignore on opinionated template ([315d355](https://github.com/expressots/expressots/commit/315d355ed87eb6be85daddc250289d5e0d41cd21))
24
+ * findall use case query db in memory ([ff8feea](https://github.com/expressots/expressots/commit/ff8feeaf36d0b74eebd9ab4e22f1910cff0a4df8))
25
+ * the number of constructor arguments ([ccf2a48](https://github.com/expressots/expressots/commit/ccf2a4878e795e0182608546eae8cd83e3bea775))
16
26
  * update core pkg templates to always download latest ([ca443eb](https://github.com/expressots/expressots/commit/ca443eb6be103725c73442f49e2fec14d797bba1))
17
27
 
18
28
  ## [1.2.1](https://github.com/expressots/expressots/compare/v1.2.0...v1.2.1) (2023-04-18)
package/lib/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/alogo.png" width="120" alt="Expresso TS Logo" /></a>
2
+ <a href="https://expresso-ts.com/" target="blank"><img src="https://github.com/expressots/expressots/blob/main/media/expressots.png" width="120" alt="Expresso TS Logo" /></a>
3
3
  </p>
4
4
 
5
5
  # Expresso TS
@@ -32,13 +32,15 @@ The [Issue Reporting Channel](https://github.com/expressots/expressots/issues) i
32
32
 
33
33
  Before you create an issue, please make sure you read the [Contribution Guidelines](CONTRIBUTING.md).
34
34
 
35
- ## Support
35
+ ## Support the project
36
36
 
37
- ExpressoTS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
37
+ Expresso TS is an MIT-licensed open source project. It's an independent project with ongoing development made possible thanks to your support. If you'd like to help, please consider:
38
38
 
39
- - Become a sponsor on GitHub
40
- - Follow the organization on GitHub and Star the project
41
- - Contribute submitting issues and pull requests
39
+ - Become a sponsor on **[Sponsor no GitHub](https://github.com/sponsors/expressots)**
40
+ - Follow the **[organization](https://github.com/expressots)** on GitHub and Star the project
41
+ - Subscribe to the Twitch channel: **[Richard Zampieri](https://www.twitch.tv/richardzampieri)**
42
+ - Join our **[Discord](https://discord.com/invite/PyPJfGK)**
43
+ - Contribute submitting **[issues and pull requests](https://github.com/expressots/expressots/issues/new/choose)**
42
44
  - Share the project with your friends and colleagues
43
45
 
44
46
  ## Contributors
@@ -46,7 +48,7 @@ ExpressoTS is an MIT-licensed open source project. It's an independent project w
46
48
  - [Daniel Boll](https://github.com/daniel-boll)
47
49
  - [Felipe Fontana](https://github.com/f0ntana)
48
50
  - [Juliano Soares](https://github.com/juliano-soares)
49
- - [Vitor Caminha](https://github.com/VitorCaminha)
51
+ - [Vitor Caminha](https://github.com/VitorCaminha)
50
52
  - [Ariel Betti](https://github.com/ArielBetti)
51
53
  - [Rodrigo da Hora](https://github.com/dahorarodrigo)
52
54
 
@@ -54,12 +56,6 @@ ExpressoTS is an MIT-licensed open source project. It's an independent project w
54
56
 
55
57
  - Work in progress
56
58
 
57
- ## Stay in touch
58
-
59
- - Author: Richard Zampieri
60
- - Website: [https://expresso-ts.com](https://expresso-ts.com)
61
- - Twitch channel: [Richard Zampieri](https://www.twitch.tv/richardzampieri)
62
-
63
59
  ## License
64
60
 
65
- ExpressoTS is **[MIT licensed](LICENSE.md)**
61
+ ExpressoTS is **[MIT licensed](LICENSE.md)**
@@ -5,9 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
8
  var AppContainer_1;
12
9
  Object.defineProperty(exports, "__esModule", { value: true });
13
10
  exports.AppContainer = void 0;
@@ -18,23 +15,43 @@ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
18
15
  * @provide AppContainer
19
16
  */
20
17
  let AppContainer = AppContainer_1 = class AppContainer {
21
- /**
22
- * Constructs a new instance of the AppContainer class.
23
- */
24
- constructor() { }
25
18
  /**
26
19
  * Creates and configures a new dependency injection container.
27
20
  * @param modules - An array of ContainerModule instances to load into the container.
21
+ * @param defaultScope - The default scope to use for bindings. Scoped (Request) by default, but offers Singleton and Transient as well.
28
22
  * @returns The configured dependency injection container.
29
23
  */
30
- create(modules) {
31
- this.container = new inversify_1.Container();
24
+ create(modules, defaultScope = inversify_1.BindingScopeEnum.Request) {
25
+ this.container = new inversify_1.Container({
26
+ autoBindInjectable: true,
27
+ defaultScope,
28
+ });
32
29
  this.container.load((0, inversify_binding_decorators_1.buildProviderModule)(), ...modules);
33
30
  return this.container;
34
31
  }
32
+ /**
33
+ * Retrieves the binding dictionary of the container.
34
+ * @returns The binding dictionary of the container.
35
+ */
36
+ getBindingDictionary() {
37
+ return this.container["_bindingDictionary"]._map;
38
+ }
39
+ /**
40
+ * Retrieves the container options.
41
+ * @returns The container options.
42
+ */
43
+ getContainerOptions() {
44
+ return this.container["options"];
45
+ }
46
+ /**
47
+ * Retrieves the container.
48
+ * @returns The container.
49
+ */
50
+ get Container() {
51
+ return this.container;
52
+ }
35
53
  };
36
54
  AppContainer = AppContainer_1 = __decorate([
37
- (0, inversify_binding_decorators_1.provide)(AppContainer_1),
38
- __metadata("design:paramtypes", [])
55
+ (0, inversify_binding_decorators_1.provide)(AppContainer_1)
39
56
  ], AppContainer);
40
57
  exports.AppContainer = AppContainer;
@@ -5,20 +5,45 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
8
  var BaseModule_1;
12
9
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.CreateModule = void 0;
10
+ exports.scope = exports.CreateModule = void 0;
14
11
  const inversify_1 = require("inversify");
15
12
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
13
+ const decorator_1 = require("../decorator");
14
+ /**
15
+ * Key to be used for storing and retrieving binding type metadata.
16
+ */
17
+ const BINDING_TYPE_METADATA_KEY = "binding-type";
18
+ /**
19
+ * The scope decorator is a higher order function that can be used to decorate a class with a binding type.
20
+ * @param binding An instance of interfaces.BindingScope which represents the binding type.
21
+ * @returns A decorator function that can be used to decorate a class with a binding type.
22
+ */
23
+ const scope = (binding) => {
24
+ return function (target) {
25
+ if (!Reflect.hasMetadata(BINDING_TYPE_METADATA_KEY, target)) {
26
+ Reflect.defineMetadata(BINDING_TYPE_METADATA_KEY, binding, target);
27
+ switch (binding) {
28
+ case inversify_1.BindingScopeEnum.Singleton:
29
+ (0, decorator_1.provideSingleton)(target);
30
+ break;
31
+ case inversify_1.BindingScopeEnum.Transient:
32
+ (0, decorator_1.provideTransient)(target);
33
+ break;
34
+ default:
35
+ (0, inversify_binding_decorators_1.provide)(target);
36
+ break;
37
+ }
38
+ }
39
+ };
40
+ };
41
+ exports.scope = scope;
16
42
  /**
17
43
  * The BaseModule class provides methods for creating InversifyJS container modules.
18
44
  * @provide BaseModule
19
45
  */
20
46
  let BaseModule = BaseModule_1 = class BaseModule {
21
- constructor() { }
22
47
  /**
23
48
  * Create a map of symbols for the provided controllers.
24
49
  * @param controllers - An array of controller classes.
@@ -34,23 +59,51 @@ let BaseModule = BaseModule_1 = class BaseModule {
34
59
  return symbols;
35
60
  }
36
61
  /**
37
- * Create an InversifyJS ContainerModule for the provided controllers.
38
- * @param controllers - An array of controller classes.
39
- * @returns A ContainerModule with the controller bindings.
40
- */
41
- static createContainerModule(controllers) {
62
+ * Create an InversifyJS ContainerModule for the provided controllers.
63
+ * @param controllers - An array of controller classes.
64
+ * @param scope - An optional binding scope to be used for all controllers.
65
+ * @returns A ContainerModule with the controller bindings.
66
+ */
67
+ static createContainerModule(controllers, scope) {
42
68
  const symbols = BaseModule_1.createSymbols(controllers);
43
- return new inversify_1.ContainerModule(bind => {
44
- for (const symbol of symbols) {
45
- const target = symbol.valueOf();
46
- bind(target[0]).to(target[1]);
69
+ return new inversify_1.ContainerModule((bind) => {
70
+ for (const [symbol, target] of symbols) {
71
+ if (scope) {
72
+ switch (scope) {
73
+ case inversify_1.BindingScopeEnum.Singleton:
74
+ bind(symbol).to(target).inSingletonScope();
75
+ break;
76
+ case inversify_1.BindingScopeEnum.Transient:
77
+ bind(symbol).to(target).inTransientScope();
78
+ break;
79
+ case inversify_1.BindingScopeEnum.Request:
80
+ bind(symbol).to(target).inRequestScope();
81
+ break;
82
+ }
83
+ }
84
+ else {
85
+ const bindingType = Reflect.getMetadata(BINDING_TYPE_METADATA_KEY, target);
86
+ switch (bindingType) {
87
+ case inversify_1.BindingScopeEnum.Singleton:
88
+ bind(symbol).to(target).inSingletonScope();
89
+ break;
90
+ case inversify_1.BindingScopeEnum.Transient:
91
+ bind(symbol).to(target).inTransientScope();
92
+ break;
93
+ case inversify_1.BindingScopeEnum.Request:
94
+ bind(symbol).to(target).inRequestScope();
95
+ break;
96
+ default:
97
+ bind(symbol).to(target).inRequestScope();
98
+ break;
99
+ }
100
+ }
47
101
  }
48
102
  });
49
103
  }
50
104
  };
51
105
  BaseModule = BaseModule_1 = __decorate([
52
- (0, inversify_binding_decorators_1.provide)(BaseModule_1),
53
- __metadata("design:paramtypes", [])
106
+ (0, inversify_binding_decorators_1.provide)(BaseModule_1)
54
107
  ], BaseModule);
55
108
  const CreateModule = BaseModule.createContainerModule;
56
109
  exports.CreateModule = CreateModule;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CreateModule = void 0;
3
+ exports.scope = exports.CreateModule = void 0;
4
4
  var container_module_1 = require("./container-module");
5
5
  Object.defineProperty(exports, "CreateModule", { enumerable: true, get: function () { return container_module_1.CreateModule; } });
6
+ Object.defineProperty(exports, "scope", { enumerable: true, get: function () { return container_module_1.scope; } });
@@ -49,7 +49,7 @@ let BaseController = BaseController_1 = class BaseController {
49
49
  return res.status(successStatusCode).json(dataReturn);
50
50
  }
51
51
  catch (error) {
52
- error_1.Report.Error(error);
52
+ error_1.Report.Error(error, undefined, this.serviceName);
53
53
  }
54
54
  });
55
55
  }
@@ -66,7 +66,7 @@ let BaseController = BaseController_1 = class BaseController {
66
66
  return res.status(successStatusCode).json(dataReturn);
67
67
  }
68
68
  catch (error) {
69
- error_1.Report.Error(error);
69
+ error_1.Report.Error(error, undefined, this.serviceName);
70
70
  }
71
71
  }
72
72
  };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./scope-binding"), exports);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.provideTransient = exports.provideSingleton = void 0;
4
+ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
5
+ const provideSingleton = (identifier) => {
6
+ return (0, inversify_binding_decorators_1.fluentProvide)(identifier).inSingletonScope().done();
7
+ };
8
+ exports.provideSingleton = provideSingleton;
9
+ const provideTransient = (identifier) => {
10
+ return (0, inversify_binding_decorators_1.fluentProvide)(identifier).inTransientScope().done();
11
+ };
12
+ exports.provideTransient = provideTransient;
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const status_code_1 = require("./status-code");
4
- const logger_1 = require("../logger");
5
4
  /**
6
5
  * errorHandler is a custom Express error-handling middleware function.
7
6
  * It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
8
- * @param error - An instance of AppError containing error details.
7
+ * @param error - An instance of IAppError containing error details.
9
8
  * @param req - The Express request object.
10
9
  * @param res - The Express response object.
11
10
  * @param next - The Express next function for passing control to the next middleware function.
12
11
  */
13
12
  function errorHandler(error, req, res, next) {
14
- (0, logger_1.log)(logger_1.LogLevel.Error, error, error.service || "service-undefined");
15
13
  res.status(error.statusCode || status_code_1.StatusCode.InternalServerError).json({ statusCode: error.statusCode, error: error.message });
16
14
  }
17
15
  exports.default = errorHandler;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Report = exports.AppError = exports.StatusCode = void 0;
3
+ exports.Report = exports.StatusCode = void 0;
4
4
  var status_code_1 = require("./status-code");
5
5
  Object.defineProperty(exports, "StatusCode", { enumerable: true, get: function () { return status_code_1.StatusCode; } });
6
- var application_error_1 = require("./application-error");
7
- Object.defineProperty(exports, "AppError", { enumerable: true, get: function () { return application_error_1.AppError; } });
8
6
  var report_1 = require("./report");
9
7
  Object.defineProperty(exports, "Report", { enumerable: true, get: function () { return report_1.Report; } });
@@ -9,6 +9,7 @@ var Report_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.Report = void 0;
11
11
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
12
+ const logger_1 = require("../logger");
12
13
  /**
13
14
  * Report class is a utility class to manage and throw application-specific errors.
14
15
  */
@@ -17,8 +18,31 @@ let Report = Report_1 = class Report {
17
18
  * Error method takes an instance of AppError and throws it.
18
19
  * @param error - An instance of AppError containing error details.
19
20
  */
20
- static Error(error) {
21
- throw error;
21
+ static Error(error, statusCode, service) {
22
+ var _a, _b;
23
+ let appError = {};
24
+ Error.captureStackTrace(this, this.Error);
25
+ const callerName = (_b = (_a = this.stack.split("\n")[1]) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.split(" ")[1];
26
+ if (error instanceof Error) {
27
+ appError = {
28
+ statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
29
+ message: error.message,
30
+ service: service !== null && service !== void 0 ? service : callerName,
31
+ name: error.name,
32
+ stack: error.stack
33
+ };
34
+ }
35
+ else {
36
+ appError = {
37
+ statusCode: statusCode !== null && statusCode !== void 0 ? statusCode : 500,
38
+ message: error,
39
+ service: service !== null && service !== void 0 ? service : callerName,
40
+ name: this.Error.name,
41
+ stack: this.stack
42
+ };
43
+ }
44
+ (0, logger_1.log)(logger_1.LogLevel.Error, appError, appError.service || "service-undefined");
45
+ throw appError;
22
46
  }
23
47
  };
24
48
  Report = Report_1 = __decorate([
package/lib/cjs/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./common"), exports);
19
19
  __exportStar(require("./console"), exports);
20
20
  __exportStar(require("./container-module"), exports);
21
21
  __exportStar(require("./controller"), exports);
22
+ __exportStar(require("./decorator"), exports);
22
23
  __exportStar(require("./environment"), exports);
23
24
  __exportStar(require("./error"), exports);
24
25
  __exportStar(require("./logger"), exports);
@@ -40,8 +40,8 @@ let GeneralLogger = GeneralLogger_1 = class GeneralLogger {
40
40
  */
41
41
  createConsoleTransport() {
42
42
  const consoleTransport = new winston_1.transports.Console({
43
- level: "debug",
44
- handleExceptions: true,
43
+ level: (process.env.ENVIRONMENT !== "Development" && "debug") || "debug",
44
+ handleExceptions: false,
45
45
  handleRejections: true
46
46
  });
47
47
  return consoleTransport;
@@ -1,20 +1,32 @@
1
- import { Container, ContainerModule } from "inversify";
1
+ import { Container, ContainerModule, interfaces } from "inversify";
2
2
  /**
3
3
  * The AppContainer class provides a container for managing dependency injection.
4
4
  * @provide AppContainer
5
5
  */
6
6
  declare class AppContainer {
7
7
  private container;
8
- /**
9
- * Constructs a new instance of the AppContainer class.
10
- */
11
- constructor();
12
8
  /**
13
9
  * Creates and configures a new dependency injection container.
14
10
  * @param modules - An array of ContainerModule instances to load into the container.
11
+ * @param defaultScope - The default scope to use for bindings. Scoped (Request) by default, but offers Singleton and Transient as well.
15
12
  * @returns The configured dependency injection container.
16
13
  */
17
- create(modules: ContainerModule[]): Container;
14
+ create(modules: ContainerModule[], defaultScope?: interfaces.BindingScope): Container;
15
+ /**
16
+ * Retrieves the binding dictionary of the container.
17
+ * @returns The binding dictionary of the container.
18
+ */
19
+ getBindingDictionary(): Map<any, any>;
20
+ /**
21
+ * Retrieves the container options.
22
+ * @returns The container options.
23
+ */
24
+ getContainerOptions(): interfaces.ContainerOptions;
25
+ /**
26
+ * Retrieves the container.
27
+ * @returns The container.
28
+ */
29
+ get Container(): Container;
18
30
  }
19
31
  export { AppContainer };
20
32
  //# sourceMappingURL=app-container.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-container.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/app-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAGvD;;;GAGG;AACH,cACM,YAAY;IAEd,OAAO,CAAC,SAAS,CAAY;IAE7B;;OAEG;;IAGH;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,SAAS;CAKvD;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"app-container.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/app-container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGrF;;;GAGG;AACH,cACM,YAAY;IAEd,OAAO,CAAC,SAAS,CAAa;IAC9B;;;;;OAKG;IACI,MAAM,CACT,OAAO,EAAE,eAAe,EAAE,EAC1B,YAAY,GAAE,UAAU,CAAC,YAAuC,GACjE,SAAS;IAWZ;;;OAGG;IACI,oBAAoB,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC;IAI5C;;;OAGG;IACI,mBAAmB,IAAI,UAAU,CAAC,gBAAgB;IAIzD;;;OAGG;IACH,IAAW,SAAS,IAAI,SAAS,CAEhC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -1,10 +1,15 @@
1
- import { ContainerModule } from "inversify";
1
+ import { ContainerModule, interfaces } from "inversify";
2
+ /**
3
+ * The scope decorator is a higher order function that can be used to decorate a class with a binding type.
4
+ * @param binding An instance of interfaces.BindingScope which represents the binding type.
5
+ * @returns A decorator function that can be used to decorate a class with a binding type.
6
+ */
7
+ declare const scope: (binding: interfaces.BindingScope) => (target: any) => void;
2
8
  /**
3
9
  * The BaseModule class provides methods for creating InversifyJS container modules.
4
10
  * @provide BaseModule
5
11
  */
6
12
  declare class BaseModule {
7
- constructor();
8
13
  /**
9
14
  * Create a map of symbols for the provided controllers.
10
15
  * @param controllers - An array of controller classes.
@@ -12,12 +17,13 @@ declare class BaseModule {
12
17
  */
13
18
  private static createSymbols;
14
19
  /**
15
- * Create an InversifyJS ContainerModule for the provided controllers.
16
- * @param controllers - An array of controller classes.
17
- * @returns A ContainerModule with the controller bindings.
18
- */
19
- static createContainerModule(controllers: any[]): ContainerModule;
20
+ * Create an InversifyJS ContainerModule for the provided controllers.
21
+ * @param controllers - An array of controller classes.
22
+ * @param scope - An optional binding scope to be used for all controllers.
23
+ * @returns A ContainerModule with the controller bindings.
24
+ */
25
+ static createContainerModule(controllers: any[], scope?: interfaces.BindingScope): ContainerModule;
20
26
  }
21
27
  declare const CreateModule: typeof BaseModule.createContainerModule;
22
- export { CreateModule };
28
+ export { CreateModule, scope };
23
29
  //# sourceMappingURL=container-module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"container-module.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/container-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAQ5C;;;GAGG;AACH,cACM,UAAU;;IAIZ;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAa3B;;;;MAIE;WACW,qBAAqB,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,eAAe;CAY3E;AAED,QAAA,MAAM,YAAY,yCAAmC,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"container-module.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/container-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAS1E;;;;GAIG;AACH,QAAA,MAAM,KAAK,YAAa,WAAW,YAAY,cAClB,GAAG,SAiB/B,CAAC;AAOF;;;GAGG;AACH,cACM,UAAU;IACZ;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAY5B;;;;;OAKG;WACW,qBAAqB,CAC/B,WAAW,EAAE,GAAG,EAAE,EAClB,KAAK,CAAC,EAAE,UAAU,CAAC,YAAY,GAChC,eAAe;CAyCrB;AAED,QAAA,MAAM,YAAY,yCAAmC,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC"}
@@ -1,2 +1,2 @@
1
- export { CreateModule } from "./container-module";
1
+ export { CreateModule, scope } from "./container-module";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/container-module/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./scope-binding";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,4 @@
1
+ declare const provideSingleton: (identifier: any) => (target: any) => any;
2
+ declare const provideTransient: (identifier: any) => (target: any) => any;
3
+ export { provideSingleton, provideTransient };
4
+ //# sourceMappingURL=scope-binding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope-binding.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/scope-binding.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
@@ -1,13 +1,13 @@
1
1
  import { NextFunction, Request, Response } from "express";
2
- import { AppError } from "./application-error";
2
+ import { IAppError } from "./report";
3
3
  /**
4
4
  * errorHandler is a custom Express error-handling middleware function.
5
5
  * It logs the error, sets the status code, and sends a JSON response containing the status code and error message.
6
- * @param error - An instance of AppError containing error details.
6
+ * @param error - An instance of IAppError containing error details.
7
7
  * @param req - The Express request object.
8
8
  * @param res - The Express response object.
9
9
  * @param next - The Express next function for passing control to the next middleware function.
10
10
  */
11
- declare function errorHandler(error: AppError, req: Request, res: Response, next: NextFunction): void;
11
+ declare function errorHandler(error: IAppError, req: Request, res: Response, next: NextFunction): void;
12
12
  export default errorHandler;
13
13
  //# sourceMappingURL=error-handler-middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAI/C;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAI5F;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"error-handler-middleware.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/error-handler-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAIrC;;;;;;;GAOG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAE7F;AAED,eAAe,YAAY,CAAC"}
@@ -1,4 +1,3 @@
1
1
  export { StatusCode } from './status-code';
2
- export { AppError } from './application-error';
3
2
  export { Report } from './report';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/error/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC"}