@expressots/core 2.16.2 → 3.0.0-beta.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 (185) hide show
  1. package/README.md +2 -2
  2. package/lib/CHANGELOG.md +312 -322
  3. package/lib/README.md +2 -2
  4. package/lib/cjs/application/application-container.js +18 -21
  5. package/lib/cjs/application/application-factory.js +4 -5
  6. package/lib/cjs/{common/server-env.types.js → application/application.types.js} +1 -0
  7. package/lib/cjs/application/index.js +3 -1
  8. package/lib/cjs/console/console.js +8 -20
  9. package/lib/cjs/container-module/container-module.js +10 -18
  10. package/lib/cjs/decorator/scope-binding.js +12 -11
  11. package/lib/cjs/di/annotation/decorator_utils.js +121 -0
  12. package/lib/cjs/di/annotation/inject.js +44 -0
  13. package/lib/cjs/di/annotation/inject_base.js +17 -0
  14. package/lib/cjs/di/annotation/injectable.js +43 -0
  15. package/lib/cjs/di/annotation/lazy_service_identifier.js +12 -0
  16. package/lib/cjs/di/annotation/multi_inject.js +30 -0
  17. package/lib/cjs/di/annotation/named.js +34 -0
  18. package/lib/cjs/di/annotation/optional.js +32 -0
  19. package/lib/cjs/di/annotation/post_construct.js +31 -0
  20. package/lib/cjs/di/annotation/pre_destroy.js +31 -0
  21. package/lib/cjs/di/annotation/property_event_decorator.js +15 -0
  22. package/lib/cjs/di/annotation/tagged.js +9 -0
  23. package/lib/cjs/di/annotation/target_name.js +35 -0
  24. package/lib/cjs/di/annotation/unmanaged.js +35 -0
  25. package/lib/cjs/di/binding-decorator/constants.js +7 -0
  26. package/lib/cjs/di/binding-decorator/decorator/fluent_provide.js +20 -0
  27. package/lib/cjs/di/binding-decorator/decorator/provide.js +37 -0
  28. package/lib/cjs/di/binding-decorator/factory/module_factory.js +17 -0
  29. package/lib/cjs/di/binding-decorator/index.js +14 -0
  30. package/lib/cjs/di/binding-decorator/syntax/provide_done_syntax.js +42 -0
  31. package/lib/cjs/di/binding-decorator/syntax/provide_in_syntax.js +33 -0
  32. package/lib/cjs/di/binding-decorator/syntax/provide_in_when_on_syntax.js +64 -0
  33. package/lib/cjs/di/binding-decorator/syntax/provide_on_syntax.js +22 -0
  34. package/lib/cjs/di/binding-decorator/syntax/provide_when_on_syntax.js +57 -0
  35. package/lib/cjs/di/binding-decorator/syntax/provide_when_syntax.js +89 -0
  36. package/lib/cjs/di/binding-decorator/utils/auto_wire.js +18 -0
  37. package/lib/cjs/di/bindings/binding.js +40 -0
  38. package/lib/cjs/di/bindings/binding_count.js +8 -0
  39. package/lib/cjs/di/constants/error_msgs.js +60 -0
  40. package/lib/cjs/di/constants/literal_types.js +26 -0
  41. package/lib/cjs/di/constants/metadata_keys.js +38 -0
  42. package/lib/cjs/di/container/container.js +521 -0
  43. package/lib/cjs/di/container/container_module.js +18 -0
  44. package/lib/cjs/di/container/container_snapshot.js +15 -0
  45. package/lib/cjs/di/container/lookup.js +132 -0
  46. package/lib/cjs/di/container/module_activation_store.js +49 -0
  47. package/lib/cjs/di/interfaces/interfaces.js +2 -0
  48. package/lib/cjs/di/inversify.js +78 -0
  49. package/lib/cjs/di/planning/context.js +17 -0
  50. package/lib/cjs/di/planning/metadata.js +42 -0
  51. package/lib/cjs/di/planning/metadata_reader.js +45 -0
  52. package/lib/cjs/di/planning/plan.js +10 -0
  53. package/lib/cjs/di/planning/planner.js +186 -0
  54. package/lib/cjs/di/planning/queryable_string.js +27 -0
  55. package/lib/cjs/di/planning/reflection_utils.js +178 -0
  56. package/lib/cjs/di/planning/request.js +23 -0
  57. package/lib/cjs/di/planning/target.js +108 -0
  58. package/lib/cjs/di/resolution/instantiation.js +150 -0
  59. package/lib/cjs/di/resolution/resolver.js +188 -0
  60. package/lib/cjs/di/scope/scope.js +50 -0
  61. package/lib/cjs/di/syntax/binding_in_syntax.js +23 -0
  62. package/lib/cjs/di/syntax/binding_in_when_on_syntax.js +75 -0
  63. package/lib/cjs/di/syntax/binding_on_syntax.js +18 -0
  64. package/lib/cjs/di/syntax/binding_to_syntax.js +111 -0
  65. package/lib/cjs/di/syntax/binding_when_on_syntax.js +64 -0
  66. package/lib/cjs/di/syntax/binding_when_syntax.js +84 -0
  67. package/lib/cjs/di/syntax/constraint_helpers.js +68 -0
  68. package/lib/cjs/di/utils/async.js +15 -0
  69. package/lib/cjs/di/utils/binding_utils.js +77 -0
  70. package/lib/cjs/di/utils/clonable.js +9 -0
  71. package/lib/cjs/di/utils/exceptions.js +46 -0
  72. package/lib/cjs/di/utils/factory_type.js +9 -0
  73. package/lib/cjs/di/utils/id.js +7 -0
  74. package/lib/cjs/di/utils/js.js +15 -0
  75. package/lib/cjs/di/utils/serialization.js +132 -0
  76. package/lib/cjs/error/app-error.js +5 -2
  77. package/lib/cjs/error/report.js +24 -15
  78. package/lib/cjs/index.js +1 -2
  79. package/lib/cjs/middleware/middleware-interface.js +2 -0
  80. package/lib/cjs/middleware/middleware-service.js +9 -24
  81. package/lib/cjs/provider/db-in-memory/base-repo.repository.js +3 -8
  82. package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +8 -5
  83. package/lib/cjs/provider/dto-validator/dto-validator.provider.js +4 -4
  84. package/lib/cjs/provider/dto-validator/package-resolver.js +56 -0
  85. package/lib/cjs/provider/environment/env-validator.provider.js +14 -12
  86. package/lib/cjs/provider/logger/logger.provider.js +10 -5
  87. package/lib/cjs/provider/provider-manager.js +21 -17
  88. package/lib/cjs/types/application/application-container.d.ts +12 -25
  89. package/lib/cjs/types/application/application-factory.d.ts +10 -7
  90. package/lib/cjs/types/{common/server-env.types.d.ts → application/application.types.d.ts} +1 -0
  91. package/lib/cjs/types/application/index.d.ts +1 -0
  92. package/lib/cjs/types/console/console.d.ts +3 -10
  93. package/lib/cjs/types/console/index.d.ts +2 -1
  94. package/lib/cjs/types/container-module/container-module.d.ts +3 -1
  95. package/lib/cjs/types/decorator/scope-binding.d.ts +9 -9
  96. package/lib/cjs/types/di/annotation/decorator_utils.d.ts +16 -0
  97. package/lib/cjs/types/di/annotation/inject.d.ts +16 -0
  98. package/lib/cjs/types/di/annotation/inject_base.d.ts +3 -0
  99. package/lib/cjs/types/di/annotation/injectable.d.ts +7 -0
  100. package/lib/cjs/types/di/annotation/lazy_service_identifier.d.ts +7 -0
  101. package/lib/cjs/types/di/annotation/multi_inject.d.ts +2 -0
  102. package/lib/cjs/types/di/annotation/named.d.ts +2 -0
  103. package/lib/cjs/types/di/annotation/optional.d.ts +2 -0
  104. package/lib/cjs/types/di/annotation/post_construct.d.ts +4 -0
  105. package/lib/cjs/types/di/annotation/pre_destroy.d.ts +4 -0
  106. package/lib/cjs/types/di/annotation/property_event_decorator.d.ts +4 -0
  107. package/lib/cjs/types/di/annotation/tagged.d.ts +2 -0
  108. package/lib/cjs/types/di/annotation/target_name.d.ts +3 -0
  109. package/lib/cjs/types/di/annotation/unmanaged.d.ts +3 -0
  110. package/lib/cjs/types/di/binding-decorator/constants.d.ts +4 -0
  111. package/lib/cjs/types/di/binding-decorator/decorator/fluent_provide.d.ts +4 -0
  112. package/lib/cjs/types/di/binding-decorator/decorator/provide.d.ts +4 -0
  113. package/lib/cjs/types/di/binding-decorator/factory/module_factory.d.ts +4 -0
  114. package/lib/cjs/types/di/binding-decorator/index.d.ts +8 -0
  115. package/lib/cjs/types/di/binding-decorator/interfaces/interfaces.d.ts +39 -0
  116. package/lib/cjs/types/di/binding-decorator/syntax/provide_done_syntax.d.ts +7 -0
  117. package/lib/cjs/types/di/binding-decorator/syntax/provide_in_syntax.d.ts +11 -0
  118. package/lib/cjs/types/di/binding-decorator/syntax/provide_in_when_on_syntax.d.ts +27 -0
  119. package/lib/cjs/types/di/binding-decorator/syntax/provide_on_syntax.d.ts +10 -0
  120. package/lib/cjs/types/di/binding-decorator/syntax/provide_when_on_syntax.d.ts +24 -0
  121. package/lib/cjs/types/di/binding-decorator/syntax/provide_when_syntax.d.ts +23 -0
  122. package/lib/cjs/types/di/binding-decorator/utils/auto_wire.d.ts +3 -0
  123. package/lib/cjs/types/di/bindings/binding.d.ts +20 -0
  124. package/lib/cjs/types/di/bindings/binding_count.d.ts +5 -0
  125. package/lib/cjs/types/di/constants/error_msgs.d.ts +32 -0
  126. package/lib/cjs/types/di/constants/literal_types.d.ts +5 -0
  127. package/lib/cjs/types/di/constants/metadata_keys.d.ts +13 -0
  128. package/lib/cjs/types/di/container/container.d.ts +73 -0
  129. package/lib/cjs/types/di/container/container_module.d.ts +11 -0
  130. package/lib/cjs/types/di/container/container_snapshot.d.ts +10 -0
  131. package/lib/cjs/types/di/container/lookup.d.ts +16 -0
  132. package/lib/cjs/types/di/container/module_activation_store.d.ts +10 -0
  133. package/lib/cjs/types/di/interfaces/interfaces.d.ts +299 -0
  134. package/lib/cjs/types/di/inversify.d.ts +25 -0
  135. package/lib/cjs/types/di/planning/context.d.ts +11 -0
  136. package/lib/cjs/types/di/planning/metadata.d.ts +8 -0
  137. package/lib/cjs/types/di/planning/metadata_reader.d.ts +6 -0
  138. package/lib/cjs/types/di/planning/plan.d.ts +7 -0
  139. package/lib/cjs/types/di/planning/planner.d.ts +5 -0
  140. package/lib/cjs/types/di/planning/queryable_string.d.ts +11 -0
  141. package/lib/cjs/types/di/planning/reflection_utils.d.ts +5 -0
  142. package/lib/cjs/types/di/planning/request.d.ts +14 -0
  143. package/lib/cjs/types/di/planning/target.d.ts +23 -0
  144. package/lib/cjs/types/di/resolution/instantiation.d.ts +3 -0
  145. package/lib/cjs/types/di/resolution/resolver.d.ts +3 -0
  146. package/lib/cjs/types/di/scope/scope.d.ts +3 -0
  147. package/lib/cjs/types/di/syntax/binding_in_syntax.d.ts +9 -0
  148. package/lib/cjs/types/di/syntax/binding_in_when_on_syntax.d.ts +29 -0
  149. package/lib/cjs/types/di/syntax/binding_on_syntax.d.ts +8 -0
  150. package/lib/cjs/types/di/syntax/binding_to_syntax.d.ts +18 -0
  151. package/lib/cjs/types/di/syntax/binding_when_on_syntax.d.ts +25 -0
  152. package/lib/cjs/types/di/syntax/binding_when_syntax.d.ts +21 -0
  153. package/lib/cjs/types/di/syntax/constraint_helpers.d.ts +6 -0
  154. package/lib/cjs/types/di/utils/async.d.ts +3 -0
  155. package/lib/cjs/types/di/utils/binding_utils.d.ts +4 -0
  156. package/lib/cjs/types/di/utils/clonable.d.ts +3 -0
  157. package/lib/cjs/types/di/utils/exceptions.d.ts +2 -0
  158. package/lib/cjs/types/di/utils/factory_type.d.ts +5 -0
  159. package/lib/cjs/types/di/utils/id.d.ts +2 -0
  160. package/lib/cjs/types/di/utils/js.d.ts +1 -0
  161. package/lib/cjs/types/di/utils/serialization.d.ts +10 -0
  162. package/lib/cjs/types/error/report.d.ts +7 -5
  163. package/lib/cjs/types/index.d.ts +1 -2
  164. package/lib/cjs/types/middleware/index.d.ts +2 -1
  165. package/lib/cjs/types/middleware/middleware-interface.d.ts +185 -0
  166. package/lib/cjs/types/middleware/middleware-service.d.ts +11 -163
  167. package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +4 -0
  168. package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +2 -3
  169. package/lib/cjs/types/{common → provider/dto-validator}/package-resolver.d.ts +1 -2
  170. package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +7 -3
  171. package/lib/cjs/types/provider/logger/logger.provider.d.ts +5 -0
  172. package/lib/cjs/types/provider/provider-manager.d.ts +22 -2
  173. package/lib/package.json +9 -15
  174. package/package.json +9 -15
  175. package/lib/cjs/common/index.js +0 -5
  176. package/lib/cjs/common/package-resolver.js +0 -34
  177. package/lib/cjs/controller/base-controller.js +0 -63
  178. package/lib/cjs/controller/index.js +0 -5
  179. package/lib/cjs/types/common/index.d.ts +0 -2
  180. package/lib/cjs/types/common/project-config.d.ts +0 -56
  181. package/lib/cjs/types/controller/base-controller.d.ts +0 -32
  182. package/lib/cjs/types/controller/index.d.ts +0 -1
  183. /package/lib/cjs/{common → console}/color-codes.js +0 -0
  184. /package/lib/cjs/{common/project-config.js → di/binding-decorator/interfaces/interfaces.js} +0 -0
  185. /package/lib/cjs/types/{common → console}/color-codes.d.ts +0 -0
@@ -5,13 +5,9 @@ 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
  Object.defineProperty(exports, "__esModule", { value: true });
12
9
  exports.Report = void 0;
13
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
14
- const logger_provider_1 = require("../provider/logger/logger.provider");
10
+ const inversify_1 = require("../di/inversify");
15
11
  const app_error_1 = require("./app-error");
16
12
  /**
17
13
  * Report class is a utility class to manage and log errors within the application.
@@ -20,7 +16,10 @@ const app_error_1 = require("./app-error");
20
16
  */
21
17
  let Report = class Report {
22
18
  constructor() {
23
- this.logger = new logger_provider_1.Logger();
19
+ this.name = "Report Provider";
20
+ this.version = "3.0.0";
21
+ this.author = "Richard Zampieri";
22
+ this.repo = "https://github.com/expressots/expressots";
24
23
  }
25
24
  /**
26
25
  * The Error method is responsible for generating a standardized error object,
@@ -34,20 +33,30 @@ let Report = class Report {
34
33
  *
35
34
  * @throws An object of the custom type AppError, which includes details about the error.
36
35
  */
37
- error(error, statusCode, service) {
38
- let appError = {};
39
- if (error instanceof Error) {
40
- appError = new app_error_1.AppError(error.message, statusCode, service);
36
+ error(
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ error, statusCode, service) {
39
+ let message = "";
40
+ if (error == null) {
41
+ // error is null or undefined
42
+ message = "";
43
+ }
44
+ else if (typeof error === "string") {
45
+ message = error;
46
+ }
47
+ else if (error instanceof Error) {
48
+ message = error.message;
49
+ }
50
+ else if (typeof error === "object" && "message" in error) {
51
+ message = error.message;
41
52
  }
42
53
  else {
43
- appError = new app_error_1.AppError(error, statusCode, service);
54
+ message = String(error);
44
55
  }
45
- this.logger.error(appError.message, appError.service || "service-undefined");
46
- return appError;
56
+ return new app_error_1.AppError(message, statusCode, service);
47
57
  }
48
58
  };
49
59
  exports.Report = Report;
50
60
  exports.Report = Report = __decorate([
51
- (0, inversify_binding_decorators_1.provide)(Report),
52
- __metadata("design:paramtypes", [])
61
+ (0, inversify_1.injectable)()
53
62
  ], Report);
package/lib/cjs/index.js CHANGED
@@ -15,11 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./application"), exports);
18
- __exportStar(require("./common"), exports);
19
18
  __exportStar(require("./console"), exports);
20
19
  __exportStar(require("./container-module"), exports);
21
- __exportStar(require("./controller"), exports);
22
20
  __exportStar(require("./decorator"), exports);
23
21
  __exportStar(require("./error"), exports);
24
22
  __exportStar(require("./middleware"), exports);
25
23
  __exportStar(require("./provider"), exports);
24
+ __exportStar(require("./di/inversify"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,35 +1,24 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
4
  };
11
5
  Object.defineProperty(exports, "__esModule", { value: true });
12
6
  exports.Middleware = exports.ExpressoMiddleware = void 0;
13
- const express_1 = __importDefault(require("express"));
14
- const index_1 = require("../decorator/index");
7
+ const express_1 = require("express");
15
8
  const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
16
9
  const logger_provider_1 = require("../provider/logger/logger.provider");
17
10
  const middleware_resolver_1 = require("./middleware-resolver");
18
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
19
11
  /**
20
12
  * Abstract class for creating custom Expresso middleware.
21
13
  * Custom middleware classes should extend this class and implement the use method.
22
14
  *
23
15
  */
24
- let ExpressoMiddleware = class ExpressoMiddleware {
16
+ class ExpressoMiddleware {
25
17
  get name() {
26
18
  return this.constructor.name;
27
19
  }
28
- };
20
+ }
29
21
  exports.ExpressoMiddleware = ExpressoMiddleware;
30
- exports.ExpressoMiddleware = ExpressoMiddleware = __decorate([
31
- (0, inversify_binding_decorators_1.provide)(ExpressoMiddleware)
32
- ], ExpressoMiddleware);
33
22
  /**
34
23
  * MiddlewareType Enum
35
24
  *
@@ -50,8 +39,9 @@ var MiddlewareType;
50
39
  * including adding Body Parser and retrieving all configured middlewares.
51
40
  *
52
41
  * @see IConfigure
42
+ * @public API
53
43
  */
54
- let Middleware = class Middleware {
44
+ class Middleware {
55
45
  constructor() {
56
46
  this.middlewarePipeline = [];
57
47
  this.logger = new logger_provider_1.Logger();
@@ -60,7 +50,6 @@ let Middleware = class Middleware {
60
50
  * Retrieves the type of the middleware.
61
51
  *
62
52
  * @param middleware - The middleware to be checked.
63
- *
64
53
  * @returns The type of the middleware.
65
54
  */
66
55
  getMiddlewareType(middleware) {
@@ -79,7 +68,6 @@ let Middleware = class Middleware {
79
68
  * Checks if a middleware with the given name exists in the middleware collection.
80
69
  *
81
70
  * @param middlewareName - The name of the middleware to be checked.
82
- *
83
71
  * @returns A boolean value indicating whether the middleware exists or not.
84
72
  */
85
73
  middlewareExists(middlewareName) {
@@ -107,7 +95,7 @@ let Middleware = class Middleware {
107
95
  else {
108
96
  this.middlewarePipeline.push({
109
97
  timestamp: new Date(),
110
- middleware: express_1.default.urlencoded(options),
98
+ middleware: (0, express_1.urlencoded)(options),
111
99
  });
112
100
  }
113
101
  }
@@ -134,7 +122,7 @@ let Middleware = class Middleware {
134
122
  else {
135
123
  this.middlewarePipeline.push({
136
124
  timestamp: new Date(),
137
- middleware: express_1.default.json(options),
125
+ middleware: (0, express_1.json)(options),
138
126
  });
139
127
  }
140
128
  }
@@ -305,7 +293,7 @@ let Middleware = class Middleware {
305
293
  else {
306
294
  this.middlewarePipeline.push({
307
295
  timestamp: new Date(),
308
- middleware: express_1.default.static(root, options),
296
+ middleware: (0, express_1.static)(root, options),
309
297
  });
310
298
  }
311
299
  }
@@ -496,8 +484,5 @@ let Middleware = class Middleware {
496
484
  getErrorHandler() {
497
485
  return this.errorHandler;
498
486
  }
499
- };
487
+ }
500
488
  exports.Middleware = Middleware;
501
- exports.Middleware = Middleware = __decorate([
502
- (0, index_1.provideSingleton)(Middleware)
503
- ], Middleware);
@@ -10,9 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BaseRepository = void 0;
13
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
13
+ const inversify_1 = require("../../di/inversify");
14
14
  const db_in_memory_provider_1 = require("./db-in-memory.provider");
15
- const inversify_1 = require("inversify");
16
15
  /**
17
16
  * Base Repository Class
18
17
  *
@@ -20,7 +19,7 @@ const inversify_1 = require("inversify");
20
19
  *
21
20
  * @decorator @provide(BaseRepository)
22
21
  */
23
- let BaseRepository = class BaseRepository {
22
+ class BaseRepository {
24
23
  /**
25
24
  * Constructor
26
25
  * @param tableName - The name of the table to interact with.
@@ -102,13 +101,9 @@ let BaseRepository = class BaseRepository {
102
101
  this.inMemoryDB.printTable(this.tableName);
103
102
  return this.table;
104
103
  }
105
- };
104
+ }
106
105
  exports.BaseRepository = BaseRepository;
107
106
  __decorate([
108
107
  (0, inversify_1.inject)(db_in_memory_provider_1.InMemoryDB),
109
108
  __metadata("design:type", db_in_memory_provider_1.InMemoryDB)
110
109
  ], BaseRepository.prototype, "inMemoryDB", void 0);
111
- exports.BaseRepository = BaseRepository = __decorate([
112
- (0, inversify_binding_decorators_1.provide)(BaseRepository),
113
- __metadata("design:paramtypes", [String])
114
- ], BaseRepository);
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.InMemoryDB = void 0;
10
- const inversify_1 = require("inversify");
10
+ const inversify_1 = require("../../di/inversify");
11
11
  /**
12
12
  * InMemoryDB Class
13
13
  *
@@ -15,14 +15,14 @@ const inversify_1 = require("inversify");
15
15
  * It is particularly useful for developers starting with ExpressoTS without any database connection.
16
16
  *
17
17
  * @decorator @provideSingleton(InMemoryDB)
18
+ * @public API
18
19
  */
19
- //@provideSingleton(InMemoryDB)
20
20
  let InMemoryDB = class InMemoryDB {
21
21
  constructor() {
22
- this.name = "InMemoryDB";
23
- this.version = "0.0.1";
22
+ this.name = "In Memory DB Provider";
23
+ this.version = "3.0.0";
24
24
  this.author = "Richard Zampieri";
25
- this.repo = "internal";
25
+ this.repo = "https://github.com/expressots/expressots";
26
26
  this.tables = {};
27
27
  }
28
28
  /**
@@ -32,6 +32,7 @@ let InMemoryDB = class InMemoryDB {
32
32
  *
33
33
  * @param tableName - The name of the table to retrieve.
34
34
  * @returns {IEntity[]} - An array of entities.
35
+ * @public API
35
36
  */
36
37
  getTable(tableName) {
37
38
  if (!this.tables[tableName]) {
@@ -43,6 +44,7 @@ let InMemoryDB = class InMemoryDB {
43
44
  * showTables Method
44
45
  *
45
46
  * Prints a list of all tables in the in-memory database to the standard output.
47
+ * @public API
46
48
  */
47
49
  showTables() {
48
50
  if (!this.tables) {
@@ -61,6 +63,7 @@ let InMemoryDB = class InMemoryDB {
61
63
  * If the table doesn't exist or is empty, it notifies the user.
62
64
  *
63
65
  * @param tableName - The name of the table to print.
66
+ * @public API
64
67
  */
65
68
  printTable(tableName) {
66
69
  if (!this.tables) {
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ValidateDTO = ValidateDTO;
4
4
  require("reflect-metadata");
5
5
  const status_code_1 = require("../../error/status-code");
6
- const package_resolver_1 = require("../../common/package-resolver");
6
+ const package_resolver_1 = require("./package-resolver");
7
7
  const logger_provider_1 = require("../logger/logger.provider");
8
8
  /**
9
9
  * Validate the DTO using class-validator and class-transformer.
10
10
  * @param type - The type of the DTO to validate.
11
11
  * @returns A RequestHandler function.
12
12
  * @throws An exception if the DTO is invalid.
13
- *
13
+ * @public API
14
14
  */
15
15
  function ValidateDTO(type) {
16
16
  return async (req, res, next) => {
17
17
  const logger = new logger_provider_1.Logger();
18
- const classValidator = (0, package_resolver_1.packageResolver)("class-validator");
19
- const classTransformer = (0, package_resolver_1.packageResolver)("class-transformer");
18
+ const classValidator = await (0, package_resolver_1.packageResolver)("class-validator");
19
+ const classTransformer = await (0, package_resolver_1.packageResolver)("class-transformer");
20
20
  if (!classValidator || !classTransformer) {
21
21
  return next();
22
22
  }
@@ -0,0 +1,56 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.packageResolver = packageResolver;
27
+ /* eslint-disable @typescript-eslint/no-explicit-any */
28
+ const logger_provider_1 = require("../logger/logger.provider");
29
+ /**
30
+ * Resolve package from the current working directory.
31
+ * @param packageName
32
+ * @param options
33
+ * @returns
34
+ */
35
+ async function packageResolver(packageName, ...options) {
36
+ const logger = new logger_provider_1.Logger();
37
+ try {
38
+ const hasPackage = require.resolve(packageName, {
39
+ paths: [process.cwd()],
40
+ });
41
+ if (hasPackage) {
42
+ const packageResolved = await Promise.resolve(`${hasPackage}`).then(s => __importStar(require(s)));
43
+ if (typeof packageResolved === "function") {
44
+ return packageResolved(...options);
45
+ }
46
+ if (packageResolved.default &&
47
+ typeof packageResolved.default === "function") {
48
+ return packageResolved.default(...options);
49
+ }
50
+ return packageResolved;
51
+ }
52
+ }
53
+ catch (error) {
54
+ logger.warn(`Package [${packageName}] not installed. Please install it using your package manager.`, "package-resolver");
55
+ }
56
+ }
@@ -13,22 +13,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.EnvValidatorProvider = void 0;
16
- const dotenv_1 = __importDefault(require("dotenv"));
17
- const inversify_1 = require("inversify");
18
16
  const fs_1 = __importDefault(require("fs"));
19
17
  const path_1 = __importDefault(require("path"));
18
+ const inversify_1 = require("../../di/inversify");
20
19
  const logger_provider_1 = require("../logger/logger.provider");
20
+ const shared_1 = require("@expressots/shared");
21
21
  /**
22
22
  * The EnvValidatorProvider class provides utility methods for working with environment variables.
23
23
  * It validates, loads, and retrieves environment variables from the .env file.
24
24
  * @provide EnvValidatorProvider
25
+ * @public API
25
26
  */
26
27
  let EnvValidatorProvider = class EnvValidatorProvider {
27
28
  constructor() {
28
- this.name = "EnvValidatorProvider";
29
- this.version = "0.0.1";
29
+ this.name = "Env Validator Provider";
30
+ this.version = "3.0.0";
30
31
  this.author = "Richard Zampieri";
31
- this.repo = "internal";
32
+ this.repo = "https://github.com/expressots/expressots";
32
33
  this.logger = new logger_provider_1.Logger();
33
34
  }
34
35
  /**
@@ -36,6 +37,7 @@ let EnvValidatorProvider = class EnvValidatorProvider {
36
37
  * @param key - The key of the environment variable.
37
38
  * @param defaultValue - The default value to return if the environment variable is not set.
38
39
  * @returns The value of the environment variable, or the default value if not set.
40
+ * @public API
39
41
  */
40
42
  get(key, defaultValue = undefined) {
41
43
  return process.env[key] ?? defaultValue;
@@ -43,25 +45,25 @@ let EnvValidatorProvider = class EnvValidatorProvider {
43
45
  /**
44
46
  * Validates and loads all environment variables from the .env file.
45
47
  * If the .env file does not exist or any environment variables are not set, the process will exit with an error.
48
+ * @param envFile -
49
+ * @public API
46
50
  */
47
- checkAll() {
51
+ checkFile(envFile) {
48
52
  // Get the full path of the .env file
49
- const envFilePath = path_1.default.join(process.cwd(), ".", ".env");
53
+ const envFilePath = path_1.default.join(process.cwd(), ".", envFile);
50
54
  // Check if the .env file exists
51
55
  if (!fs_1.default.existsSync(envFilePath)) {
52
- this.logger.error("Environment file .env is not defined.", "env-validator-provider");
56
+ this.logger.error(`Environment file [${envFile}] is not defined.`, "environment-provider");
53
57
  process.exit(1);
54
58
  }
55
- // Load the environment variables from the .env file
56
- const dotenvConfigOutput = dotenv_1.default.config({ path: envFilePath });
57
- const dotEnvParsed = dotenvConfigOutput.parsed;
59
+ const dotEnvParsed = (0, shared_1.parse)(fs_1.default.readFileSync(envFilePath, "utf8"));
58
60
  /* Verify if all environment variables are defined */
59
61
  let hasError = false;
60
62
  if (dotEnvParsed) {
61
63
  for (const key of Object.keys(dotEnvParsed)) {
62
64
  // Check if the environment variable is not defined or is an empty string
63
65
  if (!process.env[key] || process.env[key] === "") {
64
- this.logger.error(`Environment variable ${key} is not defined.`, "env-validator-provider");
66
+ this.logger.error(`Environment variable [ ${key} ] is not defined.`, "environment-provider");
65
67
  hasError = true;
66
68
  }
67
69
  }
@@ -10,8 +10,8 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Logger = void 0;
13
- const inversify_1 = require("inversify");
14
- const color_codes_1 = require("../../common/color-codes");
13
+ const inversify_1 = require("../../di/inversify");
14
+ const color_codes_1 = require("../../console/color-codes");
15
15
  /**
16
16
  * Applies a specified color to a text string.
17
17
  *
@@ -24,13 +24,14 @@ function colorText(text, color) {
24
24
  }
25
25
  /**
26
26
  * Class that provides logging functionality with colorized text.
27
+ * @public API
27
28
  */
28
29
  let Logger = class Logger {
29
30
  constructor() {
30
- this.name = "Logger";
31
- this.version = "0.0.1";
31
+ this.name = "Logger Provider";
32
+ this.version = "3.0.0";
32
33
  this.author = "Richard Zampieri";
33
- this.repo = "internal";
34
+ this.repo = "https://github.com/expressots/expressots";
34
35
  this.pid = process.pid;
35
36
  }
36
37
  /**
@@ -78,6 +79,7 @@ let Logger = class Logger {
78
79
  *
79
80
  * @param message - The message to log.
80
81
  * @param module - Optional module name.
82
+ * @public API
81
83
  */
82
84
  msg(message, module) {
83
85
  process.stdout.write(this.formatMessage("NONE", message, module));
@@ -87,6 +89,7 @@ let Logger = class Logger {
87
89
  *
88
90
  * @param message - The message to log.
89
91
  * @param module - Optional module name.
92
+ * @public API
90
93
  */
91
94
  info(message, module) {
92
95
  process.stdout.write(this.formatMessage("INFO", message, module));
@@ -96,6 +99,7 @@ let Logger = class Logger {
96
99
  *
97
100
  * @param message - The message to log.
98
101
  * @param module - Optional module name.
102
+ * @public API
99
103
  */
100
104
  warn(message, module) {
101
105
  process.stdout.write(this.formatMessage("WARN", message, module));
@@ -105,6 +109,7 @@ let Logger = class Logger {
105
109
  *
106
110
  * @param message - The message to log.
107
111
  * @param module - Optional module name.
112
+ * @public API
108
113
  */
109
114
  error(message, module) {
110
115
  process.stderr.write(this.formatMessage("ERROR", message, module));
@@ -1,22 +1,23 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.ProviderManager = void 0;
10
- require("reflect-metadata");
11
- const inversify_1 = require("inversify");
12
- const application_1 = require("../application");
13
- const decorator_1 = require("../decorator");
4
+ const inversify_1 = require("../di/inversify");
14
5
  const logger_provider_1 = require("./logger/logger.provider");
15
- let ProviderManager = class ProviderManager {
16
- constructor() {
17
- this.container = application_1.AppFactory.container;
6
+ /**
7
+ * ProviderManager Class - A class for managing dependency injection providers.
8
+ * @public API
9
+ */
10
+ class ProviderManager {
11
+ constructor(container) {
18
12
  this.logger = new logger_provider_1.Logger();
13
+ this.container = container;
19
14
  }
15
+ /**
16
+ * Register a provider with the container.
17
+ * @param serviceIdentifier - The service identifier for the provider.
18
+ * @param scope - The binding scope for the provider.
19
+ * @public API
20
+ */
20
21
  register(serviceIdentifier, scope = inversify_1.BindingScopeEnum.Request) {
21
22
  if (this.container.isBound(serviceIdentifier)) {
22
23
  this.logger.warn(`${serviceIdentifier.name} already registered`, "provider-manager");
@@ -34,6 +35,12 @@ let ProviderManager = class ProviderManager {
34
35
  break;
35
36
  }
36
37
  }
38
+ /**
39
+ * Get a provider from the container.
40
+ * @param provider - The provider class to get from the container.
41
+ * @returns An instance of the provider.
42
+ * @public API
43
+ */
37
44
  get(provider) {
38
45
  const serviceIdentifier = this.container.get(provider);
39
46
  if (!serviceIdentifier) {
@@ -42,8 +49,5 @@ let ProviderManager = class ProviderManager {
42
49
  }
43
50
  return serviceIdentifier;
44
51
  }
45
- };
52
+ }
46
53
  exports.ProviderManager = ProviderManager;
47
- exports.ProviderManager = ProviderManager = __decorate([
48
- (0, decorator_1.provideSingleton)(ProviderManager)
49
- ], ProviderManager);
@@ -1,23 +1,5 @@
1
1
  import "reflect-metadata";
2
- import { Container, ContainerModule, interfaces } from "inversify";
3
- /**
4
- * Interface for container options that can be passed to the AppContainer class.
5
- */
6
- interface ContainerOptions {
7
- /**
8
- * The default scope for bindings in the container.
9
- * It can be set to Request (default), Singleton, or Transient.
10
- */
11
- defaultScope?: interfaces.BindingScope;
12
- /**
13
- * Allows skipping of base class checks when working with derived classes.
14
- */
15
- skipBaseClassChecks?: boolean;
16
- /**
17
- * Allows auto-binding of injectable classes.
18
- */
19
- autoBindInjectable?: boolean;
20
- }
2
+ import { Container, ContainerModule, interfaces } from "../di/inversify";
21
3
  /**
22
4
  * The AppContainer class provides a container for managing dependency injection.
23
5
  * It allows the creation of a container with custom options, including default binding scope
@@ -28,10 +10,13 @@ interface ContainerOptions {
28
10
  * ```typescript
29
11
  * const container = new AppContainer();
30
12
  * container.create([new MyModule()]);
13
+ * ```
14
+ * @public API
31
15
  */
32
- declare class AppContainer {
16
+ export declare class AppContainer {
33
17
  private container;
34
18
  private options;
19
+ private logger;
35
20
  /**
36
21
  * Constructs the AppContainer instance.
37
22
  * @param options - The options for creating the container with default request scope.
@@ -39,27 +24,29 @@ declare class AppContainer {
39
24
  * @option options.skipBaseClassChecks - Allows skipping of base class checks when working with derived classes.
40
25
  * @option options.autoBindInjectable - Allows auto-binding of injectable classes.
41
26
  */
42
- constructor(options?: ContainerOptions);
27
+ constructor(options?: interfaces.ContainerOptions);
43
28
  /**
44
29
  * Creates and configures a new dependency injection container.
45
30
  * @param modules - An array of ContainerModule instances to load into the container.
46
31
  * @returns The configured dependency injection container.
47
32
  */
48
- create(modules: Array<ContainerModule>): Container;
33
+ create(modules: Array<ContainerModule>): void;
49
34
  /**
50
35
  * Retrieves the binding dictionary of the container.
51
36
  * @returns(void) Print table of the binding dictionary of the container.
37
+ * @public API
52
38
  */
53
39
  viewContainerBindings(): void;
54
40
  /**
55
41
  * Retrieves the container options.
56
42
  * @returns The container options.
43
+ * @public API
57
44
  */
58
45
  getContainerOptions(): interfaces.ContainerOptions;
59
46
  /**
60
- * Retrieves the container.
61
- * @returns The container.
47
+ * Retrieves the container instance.
48
+ * @returns The container instance.
49
+ * @public API
62
50
  */
63
51
  get Container(): Container;
64
52
  }
65
- export { AppContainer };
@@ -1,19 +1,22 @@
1
- import { IWebServer, IWebServerPublic, IWebServerConstructor } from "@expressots/adapter-express";
2
- import { Container } from "inversify";
1
+ import { IWebServer, IWebServerConstructor, IWebServerPublic } from "@expressots/shared";
2
+ /**
3
+ * Type guard to check if input is a constructor type of IWebServer.
4
+ * @param input - Input to check.
5
+ * @returns True if input is a constructor type of IWebServer.
6
+ */
7
+ export declare function isWebServerConstructor<T extends IWebServer>(input: unknown): input is IWebServerConstructor<T>;
3
8
  /**
4
9
  * AppFactory Class
5
10
  *
6
11
  * Responsible for creating an instance of the IWebServer implementation using a custom application type.
12
+ * @public API
7
13
  */
8
- declare class AppFactory {
9
- static container: Container;
14
+ export declare class AppFactory {
10
15
  private static logger;
11
16
  /**
12
17
  * Create an instance of a web server.
13
- * @param container - Dependency injection container.
14
18
  * @param webServerType - Constructor of a class that implements IWebServer.
15
19
  * @returns A promise that resolves to an instance of IWebServer.
16
20
  */
17
- static create<T extends IWebServer>(container: Container, webServerType: IWebServerConstructor<T>): Promise<IWebServerPublic>;
21
+ static create<T extends IWebServer>(webServerType: IWebServerConstructor<T>): Promise<IWebServerPublic>;
18
22
  }
19
- export { AppFactory };
@@ -2,6 +2,7 @@
2
2
  * Enum representing possible server environments.
3
3
  * @options Development - Development environment.
4
4
  * @options Production - Production environment.
5
+ * @public API
5
6
  */
6
7
  export declare enum ServerEnvironment {
7
8
  Development = "development",
@@ -1,2 +1,3 @@
1
1
  export { AppContainer } from "./application-container";
2
2
  export { AppFactory } from "./application-factory";
3
+ export { ServerEnvironment } from "./application.types";