@expressots/core 2.16.2 → 3.0.0-beta.3

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 (194) hide show
  1. package/README.md +2 -2
  2. package/lib/CHANGELOG.md +321 -321
  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 +44 -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 +29 -88
  82. package/lib/cjs/provider/db-in-memory/db-in-memory.interface.js +2 -0
  83. package/lib/cjs/provider/db-in-memory/db-in-memory.provider.js +92 -60
  84. package/lib/cjs/provider/db-in-memory/db-in-memory.types.js +25 -0
  85. package/lib/cjs/provider/db-in-memory/index.js +11 -0
  86. package/lib/cjs/provider/dto-validator/dto-validator.provider.js +4 -4
  87. package/lib/cjs/provider/dto-validator/package-resolver.js +56 -0
  88. package/lib/cjs/provider/environment/env-validator.provider.js +14 -12
  89. package/lib/cjs/provider/index.js +16 -5
  90. package/lib/cjs/provider/logger/logger.provider.js +10 -5
  91. package/lib/cjs/provider/provider-manager.js +72 -29
  92. package/lib/cjs/types/application/application-container.d.ts +12 -25
  93. package/lib/cjs/types/application/application-factory.d.ts +10 -7
  94. package/lib/cjs/types/{common/server-env.types.d.ts → application/application.types.d.ts} +1 -0
  95. package/lib/cjs/types/application/index.d.ts +1 -0
  96. package/lib/cjs/types/console/console.d.ts +3 -10
  97. package/lib/cjs/types/console/index.d.ts +2 -1
  98. package/lib/cjs/types/container-module/container-module.d.ts +3 -1
  99. package/lib/cjs/types/decorator/scope-binding.d.ts +9 -9
  100. package/lib/cjs/types/di/annotation/decorator_utils.d.ts +16 -0
  101. package/lib/cjs/types/di/annotation/inject.d.ts +16 -0
  102. package/lib/cjs/types/di/annotation/inject_base.d.ts +3 -0
  103. package/lib/cjs/types/di/annotation/injectable.d.ts +7 -0
  104. package/lib/cjs/types/di/annotation/lazy_service_identifier.d.ts +7 -0
  105. package/lib/cjs/types/di/annotation/multi_inject.d.ts +2 -0
  106. package/lib/cjs/types/di/annotation/named.d.ts +2 -0
  107. package/lib/cjs/types/di/annotation/optional.d.ts +2 -0
  108. package/lib/cjs/types/di/annotation/post_construct.d.ts +4 -0
  109. package/lib/cjs/types/di/annotation/pre_destroy.d.ts +4 -0
  110. package/lib/cjs/types/di/annotation/property_event_decorator.d.ts +4 -0
  111. package/lib/cjs/types/di/annotation/tagged.d.ts +2 -0
  112. package/lib/cjs/types/di/annotation/target_name.d.ts +3 -0
  113. package/lib/cjs/types/di/annotation/unmanaged.d.ts +3 -0
  114. package/lib/cjs/types/di/binding-decorator/constants.d.ts +4 -0
  115. package/lib/cjs/types/di/binding-decorator/decorator/fluent_provide.d.ts +4 -0
  116. package/lib/cjs/types/di/binding-decorator/decorator/provide.d.ts +4 -0
  117. package/lib/cjs/types/di/binding-decorator/factory/module_factory.d.ts +4 -0
  118. package/lib/cjs/types/di/binding-decorator/index.d.ts +8 -0
  119. package/lib/cjs/types/di/binding-decorator/interfaces/interfaces.d.ts +39 -0
  120. package/lib/cjs/types/di/binding-decorator/syntax/provide_done_syntax.d.ts +7 -0
  121. package/lib/cjs/types/di/binding-decorator/syntax/provide_in_syntax.d.ts +11 -0
  122. package/lib/cjs/types/di/binding-decorator/syntax/provide_in_when_on_syntax.d.ts +27 -0
  123. package/lib/cjs/types/di/binding-decorator/syntax/provide_on_syntax.d.ts +10 -0
  124. package/lib/cjs/types/di/binding-decorator/syntax/provide_when_on_syntax.d.ts +24 -0
  125. package/lib/cjs/types/di/binding-decorator/syntax/provide_when_syntax.d.ts +23 -0
  126. package/lib/cjs/types/di/binding-decorator/utils/auto_wire.d.ts +3 -0
  127. package/lib/cjs/types/di/bindings/binding.d.ts +20 -0
  128. package/lib/cjs/types/di/bindings/binding_count.d.ts +5 -0
  129. package/lib/cjs/types/di/constants/error_msgs.d.ts +32 -0
  130. package/lib/cjs/types/di/constants/literal_types.d.ts +5 -0
  131. package/lib/cjs/types/di/constants/metadata_keys.d.ts +13 -0
  132. package/lib/cjs/types/di/container/container.d.ts +73 -0
  133. package/lib/cjs/types/di/container/container_module.d.ts +11 -0
  134. package/lib/cjs/types/di/container/container_snapshot.d.ts +10 -0
  135. package/lib/cjs/types/di/container/lookup.d.ts +16 -0
  136. package/lib/cjs/types/di/container/module_activation_store.d.ts +10 -0
  137. package/lib/cjs/types/di/interfaces/interfaces.d.ts +299 -0
  138. package/lib/cjs/types/di/inversify.d.ts +25 -0
  139. package/lib/cjs/types/di/planning/context.d.ts +11 -0
  140. package/lib/cjs/types/di/planning/metadata.d.ts +8 -0
  141. package/lib/cjs/types/di/planning/metadata_reader.d.ts +6 -0
  142. package/lib/cjs/types/di/planning/plan.d.ts +7 -0
  143. package/lib/cjs/types/di/planning/planner.d.ts +5 -0
  144. package/lib/cjs/types/di/planning/queryable_string.d.ts +11 -0
  145. package/lib/cjs/types/di/planning/reflection_utils.d.ts +5 -0
  146. package/lib/cjs/types/di/planning/request.d.ts +14 -0
  147. package/lib/cjs/types/di/planning/target.d.ts +23 -0
  148. package/lib/cjs/types/di/resolution/instantiation.d.ts +3 -0
  149. package/lib/cjs/types/di/resolution/resolver.d.ts +3 -0
  150. package/lib/cjs/types/di/scope/scope.d.ts +3 -0
  151. package/lib/cjs/types/di/syntax/binding_in_syntax.d.ts +9 -0
  152. package/lib/cjs/types/di/syntax/binding_in_when_on_syntax.d.ts +29 -0
  153. package/lib/cjs/types/di/syntax/binding_on_syntax.d.ts +8 -0
  154. package/lib/cjs/types/di/syntax/binding_to_syntax.d.ts +18 -0
  155. package/lib/cjs/types/di/syntax/binding_when_on_syntax.d.ts +25 -0
  156. package/lib/cjs/types/di/syntax/binding_when_syntax.d.ts +21 -0
  157. package/lib/cjs/types/di/syntax/constraint_helpers.d.ts +6 -0
  158. package/lib/cjs/types/di/utils/async.d.ts +3 -0
  159. package/lib/cjs/types/di/utils/binding_utils.d.ts +4 -0
  160. package/lib/cjs/types/di/utils/clonable.d.ts +3 -0
  161. package/lib/cjs/types/di/utils/exceptions.d.ts +2 -0
  162. package/lib/cjs/types/di/utils/factory_type.d.ts +5 -0
  163. package/lib/cjs/types/di/utils/id.d.ts +2 -0
  164. package/lib/cjs/types/di/utils/js.d.ts +1 -0
  165. package/lib/cjs/types/di/utils/serialization.d.ts +10 -0
  166. package/lib/cjs/types/error/report.d.ts +7 -5
  167. package/lib/cjs/types/index.d.ts +1 -2
  168. package/lib/cjs/types/middleware/index.d.ts +2 -1
  169. package/lib/cjs/types/middleware/middleware-interface.d.ts +185 -0
  170. package/lib/cjs/types/middleware/middleware-service.d.ts +11 -163
  171. package/lib/cjs/types/provider/db-in-memory/base-repo.repository.d.ts +15 -60
  172. package/lib/cjs/types/provider/db-in-memory/db-in-memory.interface.d.ts +43 -0
  173. package/lib/cjs/types/provider/db-in-memory/db-in-memory.provider.d.ts +25 -35
  174. package/lib/cjs/types/provider/db-in-memory/db-in-memory.types.d.ts +14 -0
  175. package/lib/cjs/types/provider/db-in-memory/index.d.ts +4 -0
  176. package/lib/cjs/types/provider/dto-validator/dto-validator.provider.d.ts +2 -3
  177. package/lib/cjs/types/{common → provider/dto-validator}/package-resolver.d.ts +1 -2
  178. package/lib/cjs/types/provider/environment/env-validator.provider.d.ts +7 -3
  179. package/lib/cjs/types/provider/index.d.ts +1 -2
  180. package/lib/cjs/types/provider/logger/logger.provider.d.ts +5 -0
  181. package/lib/cjs/types/provider/provider-manager.d.ts +46 -6
  182. package/lib/package.json +9 -15
  183. package/package.json +9 -15
  184. package/lib/cjs/common/index.js +0 -5
  185. package/lib/cjs/common/package-resolver.js +0 -34
  186. package/lib/cjs/controller/base-controller.js +0 -63
  187. package/lib/cjs/controller/index.js +0 -5
  188. package/lib/cjs/types/common/index.d.ts +0 -2
  189. package/lib/cjs/types/common/project-config.d.ts +0 -56
  190. package/lib/cjs/types/controller/base-controller.d.ts +0 -32
  191. package/lib/cjs/types/controller/index.d.ts +0 -1
  192. /package/lib/cjs/{common → console}/color-codes.js +0 -0
  193. /package/lib/cjs/{common/project-config.js → di/binding-decorator/interfaces/interfaces.js} +0 -0
  194. /package/lib/cjs/types/{common → console}/color-codes.d.ts +0 -0
@@ -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
  }
@@ -1,6 +1,20 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseRepository = exports.InMemoryDB = exports.ValidateDTO = exports.Env = exports.Logger = exports.ProviderManager = void 0;
17
+ exports.ValidateDTO = exports.Env = exports.Logger = exports.ProviderManager = void 0;
4
18
  var provider_manager_1 = require("./provider-manager");
5
19
  Object.defineProperty(exports, "ProviderManager", { enumerable: true, get: function () { return provider_manager_1.ProviderManager; } });
6
20
  var logger_provider_1 = require("./logger/logger.provider");
@@ -9,7 +23,4 @@ var env_validator_provider_1 = require("./environment/env-validator.provider");
9
23
  Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
10
24
  var dto_validator_provider_1 = require("./dto-validator/dto-validator.provider");
11
25
  Object.defineProperty(exports, "ValidateDTO", { enumerable: true, get: function () { return dto_validator_provider_1.ValidateDTO; } });
12
- var db_in_memory_provider_1 = require("./db-in-memory/db-in-memory.provider");
13
- Object.defineProperty(exports, "InMemoryDB", { enumerable: true, get: function () { return db_in_memory_provider_1.InMemoryDB; } });
14
- var base_repo_repository_1 = require("./db-in-memory/base-repo.repository");
15
- Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repo_repository_1.BaseRepository; } });
26
+ __exportStar(require("./db-in-memory"), exports);
@@ -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,49 +1,92 @@
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
  }
20
- register(serviceIdentifier, scope = inversify_1.BindingScopeEnum.Request) {
15
+ /**
16
+ * Register a provider with the container.
17
+ * @public API
18
+ */
19
+ register(serviceIdentifier, constructorOrScope, scope = inversify_1.BindingScopeEnum.Request) {
21
20
  if (this.container.isBound(serviceIdentifier)) {
22
21
  this.logger.warn(`${serviceIdentifier.name} already registered`, "provider-manager");
23
22
  return;
24
23
  }
24
+ let binding;
25
+ if (typeof constructorOrScope === "function") {
26
+ // Overload where constructor is provided
27
+ const constructor = constructorOrScope;
28
+ const scopeDefinition = scope || inversify_1.BindingScopeEnum.Transient;
29
+ binding = this.container.bind(serviceIdentifier).to(constructor);
30
+ this.applyScope(binding, scopeDefinition);
31
+ }
32
+ else {
33
+ const scopeDefinition = constructorOrScope ||
34
+ inversify_1.BindingScopeEnum.Transient;
35
+ binding = this.container.bind(serviceIdentifier).toSelf();
36
+ this.applyScope(binding, scopeDefinition);
37
+ }
38
+ }
39
+ /**
40
+ * Get a provider from the container.
41
+ * @param serviceIdentifier - The service identifier to get from the container.
42
+ * @returns An instance of the provider.
43
+ * @public API
44
+ */
45
+ get(serviceIdentifier) {
46
+ if (!this.container.isBound(serviceIdentifier)) {
47
+ this.logger.error(`${this.getServiceIdentifierName(serviceIdentifier)} not registered`, "ProviderManager");
48
+ throw new Error(`Provider ${this.getServiceIdentifierName(serviceIdentifier)} not registered`);
49
+ }
50
+ return this.container.get(serviceIdentifier);
51
+ }
52
+ /**
53
+ * Apply the scope to the binding.
54
+ * @param binding - The binding to apply the scope to.
55
+ * @param scope - The scope to apply.
56
+ * @private
57
+ */
58
+ applyScope(binding, scope) {
25
59
  switch (scope) {
26
60
  case inversify_1.BindingScopeEnum.Singleton:
27
- this.container.bind(serviceIdentifier).toSelf().inSingletonScope();
28
- break;
29
- case inversify_1.BindingScopeEnum.Transient:
30
- this.container.bind(serviceIdentifier).toSelf().inTransientScope();
61
+ binding.inSingletonScope();
31
62
  break;
32
63
  case inversify_1.BindingScopeEnum.Request:
33
- this.container.bind(serviceIdentifier).toSelf().inRequestScope();
64
+ binding.inRequestScope();
65
+ break;
66
+ case inversify_1.BindingScopeEnum.Transient:
67
+ default:
68
+ binding.inTransientScope();
34
69
  break;
35
70
  }
36
71
  }
37
- get(provider) {
38
- const serviceIdentifier = this.container.get(provider);
39
- if (!serviceIdentifier) {
40
- this.logger.error(`${provider.name} not registered`, "provider-manager");
41
- throw new Error(`Provider ${provider.name} not registered`);
72
+ /**
73
+ * Get the name of the service identifier for logging purposes.
74
+ * @param serviceIdentifier - The service identifier.
75
+ * @returns The name of the service identifier.
76
+ * @private
77
+ */
78
+ getServiceIdentifierName(
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ serviceIdentifier) {
81
+ if (typeof serviceIdentifier === "function") {
82
+ return serviceIdentifier.name;
83
+ }
84
+ else if (typeof serviceIdentifier === "symbol") {
85
+ return serviceIdentifier.toString();
86
+ }
87
+ else {
88
+ return serviceIdentifier;
42
89
  }
43
- return serviceIdentifier;
44
90
  }
45
- };
91
+ }
46
92
  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";
@@ -1,15 +1,9 @@
1
- /**
2
- * Interface representing application message details for console output.
3
- */
4
- interface IApplicationMessageToConsole {
5
- appName: string;
6
- appVersion: string;
7
- }
1
+ import { IConsoleMessage } from "@expressots/shared";
8
2
  /**
9
3
  * The Console class provides methods for displaying styled messages in the console.
10
4
  * @provide Console
11
5
  */
12
- declare class Console {
6
+ export declare class Console {
13
7
  /**
14
8
  * Print a message to the console with the specified color style.
15
9
  * @param message - The message to be printed.
@@ -22,6 +16,5 @@ declare class Console {
22
16
  * @param environment - The server environment.
23
17
  * @param consoleMessage - Optional application message details for console output.
24
18
  */
25
- messageServer(port: number, environment: string, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
19
+ messageServer(port: number, environment: string, consoleMessage?: IConsoleMessage): Promise<void>;
26
20
  }
27
- export { Console, IApplicationMessageToConsole };
@@ -1 +1,2 @@
1
- export { Console, IApplicationMessageToConsole } from "./console";
1
+ export { IConsoleMessage } from "@expressots/shared";
2
+ export { Console } from "./console";
@@ -1,4 +1,4 @@
1
- import { ContainerModule, interfaces } from "inversify";
1
+ import { ContainerModule, interfaces } from "../di/inversify";
2
2
  /**
3
3
  * Key to be used for storing and retrieving binding type metadata.
4
4
  */
@@ -7,6 +7,7 @@ export declare const BINDING_TYPE_METADATA_KEY = "binding-type";
7
7
  * The scope decorator is a higher order function that can be used to decorate a class with a binding type.
8
8
  * @param binding An instance of interfaces.BindingScope which represents the binding type.
9
9
  * @returns A decorator function that can be used to decorate a class with a binding type.
10
+ * @public API
10
11
  */
11
12
  declare const scope: (binding: interfaces.BindingScope) => (target: any) => void;
12
13
  /**
@@ -26,6 +27,7 @@ export declare class BaseModule {
26
27
  * @param controllers - An array of controller classes.
27
28
  * @param scope - An optional binding scope to be used for all controllers.
28
29
  * @returns A ContainerModule with the controller bindings.
30
+ * @public API
29
31
  */
30
32
  static createContainerModule(controllers: Array<any>, scope?: interfaces.BindingScope): ContainerModule;
31
33
  }
@@ -6,15 +6,15 @@
6
6
  *
7
7
  * @example
8
8
  * ```typescript
9
- * @provide(ServiceIdentifier)
9
+ * provide(ServiceIdentifier)
10
10
  * class MyService {}
11
11
  * ```
12
+ * @public API
12
13
  */
13
- declare const provide: (identifier: any) => (target: any) => any;
14
+ export declare const provide: (identifier: any) => (target: any) => any;
14
15
  /**
15
16
  * Provides a singleton binding for the given identifier.
16
17
  *
17
- * @remarks
18
18
  * Singleton binding ensures that the same instance of a dependency is reused within the entire container.
19
19
  *
20
20
  * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
@@ -22,15 +22,15 @@ declare const provide: (identifier: any) => (target: any) => any;
22
22
  *
23
23
  * @example
24
24
  * ```typescript
25
- * @provideSingleton(ServiceIdentifier)
25
+ * provideSingleton(ServiceIdentifier)
26
26
  * class MyService {}
27
27
  * ```
28
+ * @public API
28
29
  */
29
- declare const provideSingleton: (identifier: any) => (target: any) => any;
30
+ export declare const provideSingleton: (identifier: any) => (target: any) => any;
30
31
  /**
31
32
  * Provides a transient binding for the given identifier.
32
33
  *
33
- * @remarks
34
34
  * Transient binding ensures that a new instance of a dependency is created every time it is resolved.
35
35
  *
36
36
  * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
@@ -38,9 +38,9 @@ declare const provideSingleton: (identifier: any) => (target: any) => any;
38
38
  *
39
39
  * @example
40
40
  * ```typescript
41
- * @provideTransient(ServiceIdentifier)
41
+ * provideTransient(ServiceIdentifier)
42
42
  * class MyService {}
43
43
  * ```
44
+ * @public API
44
45
  */
45
- declare const provideTransient: (identifier: any) => (target: any) => any;
46
- export { provide, provideSingleton, provideTransient };
46
+ export declare const provideTransient: (identifier: any) => (target: any) => any;
@@ -0,0 +1,16 @@
1
+ import { interfaces } from "../interfaces/interfaces";
2
+ type Prototype<T> = {
3
+ [Property in keyof T]: T[Property] extends NewableFunction ? T[Property] : T[Property] | undefined;
4
+ } & {
5
+ constructor: NewableFunction;
6
+ };
7
+ interface ConstructorFunction<T = Record<string, unknown>> {
8
+ new (...args: Array<unknown>): T;
9
+ prototype: Prototype<T>;
10
+ }
11
+ export type DecoratorTarget<T = unknown> = ConstructorFunction<T> | Prototype<T>;
12
+ declare function tagParameter(annotationTarget: DecoratorTarget, parameterName: string | symbol | undefined, parameterIndex: number, metadata: interfaces.MetadataOrMetadataArray): void;
13
+ declare function tagProperty(annotationTarget: DecoratorTarget, propertyName: string | symbol, metadata: interfaces.MetadataOrMetadataArray): void;
14
+ declare function createTaggedDecorator(metadata: interfaces.MetadataOrMetadataArray): <T>(target: DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<T>) => void;
15
+ declare function decorate(decorator: DecoratorTarget | ParameterDecorator | MethodDecorator, target: object, parameterIndexOrProperty?: number | string): void;
16
+ export { decorate, tagParameter, tagProperty, createTaggedDecorator };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Marks a constructor parameter for injection.
3
+ * @param serviceIdentifier The service identifier
4
+ * @return The decorator function
5
+ * @example
6
+ * ```typescript
7
+ * class Engine {}
8
+ *
9
+ * class Car {
10
+ * constructor(@inject(Engine) engine: Engine) {}
11
+ * }
12
+ * ```
13
+ * @public API
14
+ */
15
+ declare const inject: <T = unknown>(serviceIdentifier: import("./lazy_service_identifier").ServiceIdentifierOrFunc<T>) => (target: import("./decorator_utils").DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<T>) => void;
16
+ export { inject };
@@ -0,0 +1,3 @@
1
+ import { DecoratorTarget } from "./decorator_utils";
2
+ import { ServiceIdentifierOrFunc } from "./lazy_service_identifier";
3
+ export declare function injectBase(metadataKey: string): <T = unknown>(serviceIdentifier: ServiceIdentifierOrFunc<T>) => (target: DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<T>) => void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Marks a class as injectable.
3
+ * @returns A decorator function
4
+ * @public API
5
+ */
6
+ declare function injectable(): <T extends abstract new (...args: any) => unknown>(target: T) => T;
7
+ export { injectable };
@@ -0,0 +1,7 @@
1
+ import { interfaces } from "../interfaces/interfaces";
2
+ export type ServiceIdentifierOrFunc<T> = interfaces.ServiceIdentifier<T> | LazyServiceIdentifier<T>;
3
+ export declare class LazyServiceIdentifier<T = unknown> {
4
+ private _cb;
5
+ constructor(cb: () => interfaces.ServiceIdentifier<T>);
6
+ unwrap(): interfaces.ServiceIdentifier<T>;
7
+ }
@@ -0,0 +1,2 @@
1
+ declare const multiInject: <T = unknown>(serviceIdentifier: import("./lazy_service_identifier").ServiceIdentifierOrFunc<T>) => (target: import("./decorator_utils").DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<T>) => void;
2
+ export { multiInject };
@@ -0,0 +1,2 @@
1
+ declare function named(name: string | number | symbol): <T>(target: import("./decorator_utils").DecoratorTarget, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<T>) => void;
2
+ export { named };
@@ -0,0 +1,2 @@
1
+ declare function optional(): ParameterDecorator;
2
+ export { optional };
@@ -0,0 +1,4 @@
1
+ declare const postConstruct: () => (target: {
2
+ constructor: NewableFunction;
3
+ }, propertyKey: string) => void;
4
+ export { postConstruct };
@@ -0,0 +1,4 @@
1
+ declare const preDestroy: () => (target: {
2
+ constructor: NewableFunction;
3
+ }, propertyKey: string) => void;
4
+ export { preDestroy };
@@ -0,0 +1,4 @@
1
+ declare function propertyEventDecorator(eventKey: string, errorMessage: string): () => (target: {
2
+ constructor: NewableFunction;
3
+ }, propertyKey: string) => void;
4
+ export { propertyEventDecorator };
@@ -0,0 +1,2 @@
1
+ declare function tagged<T>(metadataKey: string | number | symbol, metadataValue: T | unknown): ParameterDecorator;
2
+ export { tagged };
@@ -0,0 +1,3 @@
1
+ import { DecoratorTarget } from "./decorator_utils";
2
+ declare function targetName(name: string): (target: DecoratorTarget, targetKey: string, index: number) => void;
3
+ export { targetName };
@@ -0,0 +1,3 @@
1
+ import { DecoratorTarget } from "./decorator_utils";
2
+ declare function unmanaged(): (target: DecoratorTarget, targetKey: string | undefined, index: number) => void;
3
+ export { unmanaged };
@@ -0,0 +1,4 @@
1
+ declare const METADATA_KEY: {
2
+ provide: string;
3
+ };
4
+ export { METADATA_KEY };
@@ -0,0 +1,4 @@
1
+ import interfaces from "../interfaces/interfaces";
2
+ import { interfaces as inversifyInterfaces } from "../../../di/inversify";
3
+ declare function fluentProvide(serviceIdentifier: inversifyInterfaces.ServiceIdentifier<any>): interfaces.ProvideInWhenOnSyntax<any>;
4
+ export default fluentProvide;
@@ -0,0 +1,4 @@
1
+ import "reflect-metadata";
2
+ import { interfaces as inversifyInterfaces } from "../../../di/inversify";
3
+ declare function provide(serviceIdentifier: inversifyInterfaces.ServiceIdentifier<any>, force?: boolean): any;
4
+ export default provide;
@@ -0,0 +1,4 @@
1
+ import "reflect-metadata";
2
+ import { interfaces as inversifyInterfaces } from "../../inversify";
3
+ declare function buildProviderModule(): inversifyInterfaces.ContainerModule;
4
+ export default buildProviderModule;
@@ -0,0 +1,8 @@
1
+ import autoProvide from "./utils/auto_wire";
2
+ import provide from "./decorator/provide";
3
+ import fluentProvide from "./decorator/fluent_provide";
4
+ import buildProviderModule from "./factory/module_factory";
5
+ export { fluentProvide };
6
+ export { provide };
7
+ export { autoProvide };
8
+ export { buildProviderModule };