@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
@@ -1,13 +1,16 @@
1
+ import { IProvider } from "../provider";
1
2
  import { AppError } from "./app-error";
2
3
  /**
3
4
  * Report class is a utility class to manage and log errors within the application.
4
5
  * It is responsible for creating a standardized error object, logging it,
5
6
  * and then throwing the error for further handling.
6
7
  */
7
- declare class Report {
8
+ export declare class Report implements IProvider {
9
+ name: string;
10
+ version: string;
11
+ author: string;
12
+ repo: string;
8
13
  static stack: string;
9
- private logger;
10
- constructor();
11
14
  /**
12
15
  * The Error method is responsible for generating a standardized error object,
13
16
  * logging the error, and then throwing it for further handling.
@@ -20,6 +23,5 @@ declare class Report {
20
23
  *
21
24
  * @throws An object of the custom type AppError, which includes details about the error.
22
25
  */
23
- error(error: Error | string, statusCode?: number, service?: string): AppError;
26
+ error(error: Error | string | object | any, statusCode?: number, service?: string): AppError;
24
27
  }
25
- export { Report };
@@ -1,9 +1,8 @@
1
1
  export * from "./application";
2
- export * from "./common";
3
2
  export * from "./console";
4
3
  export * from "./container-module";
5
- export * from "./controller";
6
4
  export * from "./decorator";
7
5
  export * from "./error";
8
6
  export * from "./middleware";
9
7
  export * from "./provider";
8
+ export * from "./di/inversify";
@@ -1,4 +1,5 @@
1
- export { IMiddleware, Middleware, ExpressHandler, ExpressoMiddleware, MiddlewareOptions, ErrorHandlerOptions, } from "./middleware-service";
1
+ export { Middleware, ExpressHandler, ExpressoMiddleware, MiddlewareOptions, } from "./middleware-service";
2
+ export { ErrorHandlerOptions, IMiddleware } from "./middleware-interface";
2
3
  export { OptionsJson } from "./interfaces/body-parser.interface";
3
4
  export { CorsOptions } from "./interfaces/cors.interface";
4
5
  export { CompressionOptions } from "./interfaces/compression.interface";
@@ -0,0 +1,185 @@
1
+ import { ExpressHandler, MiddlewareOptions } from "./middleware-service";
2
+ import { OptionsJson } from "./interfaces/body-parser.interface";
3
+ import { CompressionOptions } from "./interfaces/compression.interface";
4
+ import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
5
+ import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
6
+ import { CorsOptions } from "./interfaces/cors.interface";
7
+ import { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
8
+ import { SessionOptions } from "./interfaces/express-session.interface";
9
+ import { OptionsHelmet } from "./interfaces/helmet.interface";
10
+ import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
11
+ import { multer } from "./interfaces/multer.interface";
12
+ import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
13
+ import { ServeStaticOptions } from "./interfaces/serve-static.interface";
14
+ import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
15
+ /**
16
+ * ErrorHandlerOptions Interface
17
+ *
18
+ * The ErrorHandlerOptions interface specifies the configuration options for the error handler middleware.
19
+ * @param errorHandler: An Express error handler function that takes care of processing errors and formulating the response.
20
+ * @param showStackTrace: A boolean value indicating whether to include the stack trace in the error response. The default value is false.
21
+ * @public API
22
+ */
23
+ export interface ErrorHandlerOptions {
24
+ errorHandler?: ExpressHandler;
25
+ showStackTrace?: boolean;
26
+ }
27
+ /**
28
+ * Interface for configuring and managing middlewares in the application.
29
+ * Provides methods to be added automatically in the application without the need to import packages.
30
+ * @public API
31
+ */
32
+ export interface IMiddleware {
33
+ /**
34
+ * Adds a URL Encoded Parser middleware to the middleware collection.
35
+ * The URL Encoded Parser is responsible for parsing the URL-encoded data in the incoming request bodies.
36
+ *
37
+ * @param options - Optional configuration options for the URL Encoded Parser.
38
+ * @public API
39
+ */
40
+ addUrlEncodedParser(options?: OptionsUrlencoded): void;
41
+ /**
42
+ * Adds a Rate Limit middleware to the middleware collection.
43
+ * The rate limiter is responsible for adding dynamic rate limit and request throttling to the application.
44
+ *
45
+ * @param options - Optional configuration options for the rate limiter.
46
+ * @public API
47
+ */
48
+ addRateLimiter(options?: RateLimitOptions): void;
49
+ /**
50
+ * Adds a Body Parser middleware to the middleware collection.
51
+ * The body parser is responsible for parsing the incoming request bodies in a middleware.
52
+ *
53
+ * @param options - Optional configuration options for the JSON body parser.
54
+ * @public API
55
+ */
56
+ addBodyParser(options?: OptionsJson): void;
57
+ /**
58
+ * Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
59
+ *
60
+ * @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
61
+ * @public API
62
+ */
63
+ addCors(options?: CorsOptions): void;
64
+ /**
65
+ * Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
66
+ *
67
+ * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
68
+ * @public API
69
+ */
70
+ addCompression(options?: CompressionOptions): void;
71
+ /**
72
+ * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
73
+ *
74
+ * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
75
+ * @param options - Optional configuration options for Cookie Parser.
76
+ * @public API
77
+ */
78
+ addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
79
+ /**
80
+ * Adds Cookie Session middleware to enable cookie-based sessions.
81
+ *
82
+ * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
83
+ * @public API
84
+ */
85
+ addCookieSession(options: CookieSessionOptions): void;
86
+ /**
87
+ * Adds Morgan middleware to log HTTP requests.
88
+ *
89
+ * @param format - The log format. Can be a string or a function.
90
+ * @param options - Optional configuration options for Morgan. Defines the behavior of the logger like the output stream, buffer duration, etc.
91
+ * @public API
92
+ */
93
+ addMorgan(format: string | FormatFn, options?: OptionsMorgan): void;
94
+ /**
95
+ * Adds a middleware to serve the favicon to the middleware collection.
96
+ * The favicon is the icon that is displayed in the browser tab for the application.
97
+ *
98
+ * @param path - The path to the favicon file.
99
+ * @param options - Optional configuration options for serving the favicon. Defines the behavior of the favicon middleware like cache control, custom headers, etc.
100
+ * @public API
101
+ */
102
+ addServeFavicon(path: string | Buffer, options?: ServeFaviconOptions): void;
103
+ /**
104
+ * Add a middleware to enable express-session.
105
+ *
106
+ * @param options - Optional configuration options for Session.
107
+ * @public API
108
+ */
109
+ addSession(options: SessionOptions): void;
110
+ /**
111
+ * Configures the error handling middleware for the application.
112
+ *
113
+ * @param options - The object containing the configuration options for the error handler middleware.
114
+ * @option errorHandler - The Express error handler function that takes care of processing errors and formulating the response.
115
+ * @option showStackTrace - A boolean value indicating whether to show the stack trace in the response.
116
+ * @public API
117
+ */
118
+ setErrorHandler(options?: ErrorHandlerOptions): void;
119
+ /**
120
+ * Adds a middleware to serve static files from the specified root directory.
121
+ * Allows the application to serve files like images, CSS, JavaScript, etc.
122
+ *
123
+ * @param root - The root directory from which the static assets are to be served.
124
+ * @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
125
+ * @public API
126
+ */
127
+ serveStatic(root: string, options?: ServeStaticOptions): void;
128
+ /**
129
+ * Adds a middleware to the middleware collection.
130
+ *
131
+ * @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
132
+ * that is composed by a route and an expressjs handler, or a custom Expresso middleware.
133
+ *
134
+ * @example Express Handler
135
+ * const middleware = (req, res, next) => {
136
+ * // Your middleware logic here
137
+ * next();
138
+ * }
139
+ *
140
+ * @example Middleware Configuration Object
141
+ * const middleware = {
142
+ * path: "/",
143
+ * middlewares: [] // Array of Express Handlers
144
+ * }
145
+ *
146
+ * @example Expresso Middleware
147
+ * class CustomMiddleware implements IExpressoMiddleware {
148
+ * use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
149
+ * // Your middleware logic here
150
+ * next();
151
+ * }
152
+ * }
153
+ * @public API
154
+ */
155
+ addMiddleware(options: MiddlewareOptions): void;
156
+ /**
157
+ * View middleware pipeline formatted.
158
+ * @returns void
159
+ * @public API
160
+ */
161
+ viewMiddlewarePipeline(): void;
162
+ /**
163
+ * Gets the configured error handler middleware.
164
+ *
165
+ * @returns The error handler middleware.
166
+ * @public API
167
+ */
168
+ getErrorHandler(): ExpressHandler;
169
+ /**
170
+ * Adds Helmet middleware to enhance security by setting various HTTP headers.
171
+ *
172
+ * @param options - Optional configuration options for Helmet.
173
+ * @returns The configuration options for Helmet middleware.
174
+ * @public API
175
+ */
176
+ addHelmet(options?: OptionsHelmet): void;
177
+ /**
178
+ * Adds Multer middleware for handling multipart/form-data, typically used for file uploads.
179
+ *
180
+ * @param options - Optional configuration options for Multer.
181
+ * @returns The Multer middleware.
182
+ * @public API
183
+ */
184
+ setupMulter(options?: multer.Options): multer.Multer;
185
+ }
@@ -1,16 +1,17 @@
1
- import express, { Request, Response, NextFunction } from "express";
1
+ import { ErrorRequestHandler, NextFunction, Request, RequestHandler, RequestParamHandler, Response } from "express";
2
+ import { ErrorHandlerOptions, IMiddleware } from "./middleware-interface";
2
3
  import { OptionsJson } from "./interfaces/body-parser.interface";
3
4
  import { CompressionOptions } from "./interfaces/compression.interface";
4
- import { CorsOptions } from "./interfaces/cors.interface";
5
5
  import { CookieParserOptions } from "./interfaces/cookie-parser.interface";
6
- import { ServeStaticOptions } from "./interfaces/serve-static.interface";
7
6
  import { CookieSessionOptions } from "./interfaces/cookie-session/cookie-session.interface";
8
- import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
9
- import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
7
+ import { CorsOptions } from "./interfaces/cors.interface";
10
8
  import { RateLimitOptions } from "./interfaces/express-rate-limit.interface";
9
+ import { SessionOptions } from "./interfaces/express-session.interface";
11
10
  import { OptionsHelmet } from "./interfaces/helmet.interface";
11
+ import { FormatFn, OptionsMorgan } from "./interfaces/morgan.interface";
12
12
  import { multer } from "./interfaces/multer.interface";
13
- import { SessionOptions } from "./interfaces/express-session.interface";
13
+ import { ServeFaviconOptions } from "./interfaces/serve-favicon.interface";
14
+ import { ServeStaticOptions } from "./interfaces/serve-static.interface";
14
15
  import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
15
16
  /**
16
17
  * ExpressHandler Type
@@ -22,7 +23,7 @@ import { OptionsUrlencoded } from "./interfaces/url-encoded.interface";
22
23
  * - express.RequestHandler: General request handler.
23
24
  * - undefined: Represents the absence of a handler.
24
25
  */
25
- export type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
26
+ export type ExpressHandler = ErrorRequestHandler | RequestParamHandler | RequestHandler | undefined;
26
27
  /**
27
28
  * Expresso middleware interface.
28
29
  */
@@ -67,166 +68,15 @@ interface MiddlewarePipeline {
67
68
  timestamp: Date;
68
69
  middleware: ExpressHandler | MiddlewareConfig | IExpressoMiddleware;
69
70
  }
70
- /**
71
- * ErrorHandlerOptions Interface
72
- *
73
- * The ErrorHandlerOptions interface specifies the configuration options for the error handler middleware.
74
- * @param errorHandler: An Express error handler function that takes care of processing errors and formulating the response.
75
- * @param showStackTrace: A boolean value indicating whether to include the stack trace in the error response. The default value is false.
76
- */
77
- export interface ErrorHandlerOptions {
78
- errorHandler?: ExpressHandler;
79
- showStackTrace?: boolean;
80
- }
81
- /**
82
- * Interface for configuring and managing middlewares in the application.
83
- * Provides methods to be added automatically in the application without the need to import packages.
84
- */
85
- interface IMiddleware {
86
- /**
87
- * Adds a URL Encoded Parser middleware to the middleware collection.
88
- * The URL Encoded Parser is responsible for parsing the URL-encoded data in the incoming request bodies.
89
- *
90
- * @param options - Optional configuration options for the URL Encoded Parser.
91
- */
92
- addUrlEncodedParser(options?: OptionsUrlencoded): void;
93
- /**
94
- * Adds a Rate Limit middleware to the middleware collection.
95
- * The rate limiter is responsible for adding dynamic rate limit and request throttling to the application.
96
- *
97
- * @param options - Optional configuration options for the rate limiter.
98
- */
99
- addRateLimiter(options?: RateLimitOptions): void;
100
- /**
101
- * Adds a Body Parser middleware to the middleware collection.
102
- * The body parser is responsible for parsing the incoming request bodies in a middleware.
103
- *
104
- * @param options - Optional configuration options for the JSON body parser.
105
- */
106
- addBodyParser(options?: OptionsJson): void;
107
- /**
108
- * Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
109
- *
110
- * @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
111
- */
112
- addCors(options?: CorsOptions): void;
113
- /**
114
- * Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
115
- *
116
- * @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
117
- */
118
- addCompression(options?: CompressionOptions): void;
119
- /**
120
- * Adds Cookie Parser middleware to parse the cookie header and populate req.cookies with an object keyed by the cookie names.
121
- *
122
- * @param secret - A string or array used for signing cookies. This is optional and if not specified, the cookie-parser will not parse signed cookies.
123
- * @param options - Optional configuration options for Cookie Parser.
124
- */
125
- addCookieParser(secret?: string | Array<string> | undefined, options?: CookieParserOptions): void;
126
- /**
127
- * Adds Cookie Session middleware to enable cookie-based sessions.
128
- *
129
- * @param options - Optional configuration options for Cookie Session. Defines the behavior of cookie sessions like the name of the cookie, keys to sign the cookie, etc.
130
- */
131
- addCookieSession(options: CookieSessionOptions): void;
132
- /**
133
- * Adds Morgan middleware to log HTTP requests.
134
- *
135
- * @param format - The log format. Can be a string or a function.
136
- * @param options - Optional configuration options for Morgan. Defines the behavior of the logger like the output stream, buffer duration, etc.
137
- */
138
- addMorgan(format: string | FormatFn, options?: OptionsMorgan): void;
139
- /**
140
- * Adds a middleware to serve the favicon to the middleware collection.
141
- * The favicon is the icon that is displayed in the browser tab for the application.
142
- *
143
- * @param path - The path to the favicon file.
144
- * @param options - Optional configuration options for serving the favicon. Defines the behavior of the favicon middleware like cache control, custom headers, etc.
145
- */
146
- addServeFavicon(path: string | Buffer, options?: ServeFaviconOptions): void;
147
- /**
148
- * Add a middleware to enable express-session.
149
- *
150
- * @param options - Optional configuration options for Session.
151
- *
152
- */
153
- addSession(options: SessionOptions): void;
154
- /**
155
- * Configures the error handling middleware for the application.
156
- *
157
- * @param options - The object containing the configuration options for the error handler middleware.
158
- * @param errorHandler - The Express error handler function that takes care of processing errors and formulating the response.
159
- * @param showStackTrace - A boolean value indicating whether to show the stack trace in the response.
160
- */
161
- setErrorHandler(options?: ErrorHandlerOptions): void;
162
- /**
163
- * Adds a middleware to serve static files from the specified root directory.
164
- * Allows the application to serve files like images, CSS, JavaScript, etc.
165
- *
166
- * @param root - The root directory from which the static assets are to be served.
167
- * @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
168
- */
169
- serveStatic(root: string, options?: ServeStaticOptions): void;
170
- /**
171
- * Adds a middleware to the middleware collection.
172
- *
173
- * @param options - The Express request handler function to be added to the middleware collection, or a middleware configuration object
174
- * that is composed by a route and an expressjs handler, or a custom Expresso middleware.
175
- *
176
- * @example Express Handler
177
- * const middleware = (req, res, next) => {
178
- * // Your middleware logic here
179
- * next();
180
- * }
181
- *
182
- * @example Middleware Configuration Object
183
- * const middleware = {
184
- * path: "/",
185
- * middlewares: [] // Array of Express Handlers
186
- * }
187
- *
188
- * @example Expresso Middleware
189
- * class CustomMiddleware implements IExpressoMiddleware {
190
- * use(req: Request, res: Response, next: NextFunction): Promise<void> | void {
191
- * // Your middleware logic here
192
- * next();
193
- * }
194
- * }
195
- */
196
- addMiddleware(options: MiddlewareOptions): void;
197
- /**
198
- * View middleware pipeline formatted.
199
- * @returns void
200
- */
201
- viewMiddlewarePipeline(): void;
202
- /**
203
- * Gets the configured error handler middleware.
204
- *
205
- * @returns The error handler middleware.
206
- */
207
- getErrorHandler(): ExpressHandler;
208
- /**
209
- * Adds Helmet middleware to enhance security by setting various HTTP headers.
210
- *
211
- * @param options - Optional configuration options for Helmet.
212
- * @returns The configuration options for Helmet middleware.
213
- */
214
- addHelmet(options?: OptionsHelmet): void;
215
- /**
216
- * Adds Multer middleware for handling multipart/form-data, typically used for file uploads.
217
- *
218
- * @param options - Optional configuration options for Multer.
219
- */
220
- setupMulter(options?: multer.Options): multer.Multer;
221
- }
222
71
  /**
223
72
  * Singleton class that implements the IConfigure interface.
224
73
  * Manages the middleware configuration for the application,
225
74
  * including adding Body Parser and retrieving all configured middlewares.
226
75
  *
227
76
  * @see IConfigure
77
+ * @public API
228
78
  */
229
- declare class Middleware implements IMiddleware {
79
+ export declare class Middleware implements IMiddleware {
230
80
  private middlewarePipeline;
231
81
  private errorHandler;
232
82
  private logger;
@@ -234,7 +84,6 @@ declare class Middleware implements IMiddleware {
234
84
  * Retrieves the type of the middleware.
235
85
  *
236
86
  * @param middleware - The middleware to be checked.
237
- *
238
87
  * @returns The type of the middleware.
239
88
  */
240
89
  private getMiddlewareType;
@@ -242,7 +91,6 @@ declare class Middleware implements IMiddleware {
242
91
  * Checks if a middleware with the given name exists in the middleware collection.
243
92
  *
244
93
  * @param middlewareName - The name of the middleware to be checked.
245
- *
246
94
  * @returns A boolean value indicating whether the middleware exists or not.
247
95
  */
248
96
  private middlewareExists;
@@ -394,4 +242,4 @@ declare class Middleware implements IMiddleware {
394
242
  */
395
243
  getErrorHandler(): ExpressHandler;
396
244
  }
397
- export { Middleware, IMiddleware };
245
+ export {};
@@ -9,6 +9,7 @@ export interface IMemoryDBEntity {
9
9
  * It is particularly useful for developers starting with ExpressoTS without any database connection.
10
10
  *
11
11
  * @decorator @provideSingleton(InMemoryDB)
12
+ * @public API
12
13
  */
13
14
  export declare class InMemoryDB implements IProvider {
14
15
  name: string;
@@ -23,12 +24,14 @@ export declare class InMemoryDB implements IProvider {
23
24
  *
24
25
  * @param tableName - The name of the table to retrieve.
25
26
  * @returns {IEntity[]} - An array of entities.
27
+ * @public API
26
28
  */
27
29
  getTable(tableName: string): Array<IMemoryDBEntity>;
28
30
  /**
29
31
  * showTables Method
30
32
  *
31
33
  * Prints a list of all tables in the in-memory database to the standard output.
34
+ * @public API
32
35
  */
33
36
  showTables(): void;
34
37
  /**
@@ -38,6 +41,7 @@ export declare class InMemoryDB implements IProvider {
38
41
  * If the table doesn't exist or is empty, it notifies the user.
39
42
  *
40
43
  * @param tableName - The name of the table to print.
44
+ * @public API
41
45
  */
42
46
  printTable(tableName: string): void;
43
47
  }
@@ -5,7 +5,6 @@ import { RequestHandler } from "express";
5
5
  * @param type - The type of the DTO to validate.
6
6
  * @returns A RequestHandler function.
7
7
  * @throws An exception if the DTO is invalid.
8
- *
8
+ * @public API
9
9
  */
10
- declare function ValidateDTO<T extends object>(type: new () => T): RequestHandler;
11
- export { ValidateDTO };
10
+ export declare function ValidateDTO<T extends object>(type: new () => T): RequestHandler;
@@ -4,5 +4,4 @@
4
4
  * @param options
5
5
  * @returns
6
6
  */
7
- declare function packageResolver(packageName: string, ...options: Array<any>): any;
8
- export { packageResolver };
7
+ export declare function packageResolver(packageName: string, ...options: Array<any>): Promise<any>;
@@ -4,8 +4,9 @@ type DefaultValueType = string | number | boolean | undefined;
4
4
  * The EnvValidatorProvider class provides utility methods for working with environment variables.
5
5
  * It validates, loads, and retrieves environment variables from the .env file.
6
6
  * @provide EnvValidatorProvider
7
+ * @public API
7
8
  */
8
- declare class EnvValidatorProvider implements IProvider {
9
+ export declare class EnvValidatorProvider implements IProvider {
9
10
  name: string;
10
11
  version: string;
11
12
  author: string;
@@ -17,13 +18,16 @@ declare class EnvValidatorProvider implements IProvider {
17
18
  * @param key - The key of the environment variable.
18
19
  * @param defaultValue - The default value to return if the environment variable is not set.
19
20
  * @returns The value of the environment variable, or the default value if not set.
21
+ * @public API
20
22
  */
21
23
  get(key: string, defaultValue?: DefaultValueType): DefaultValueType;
22
24
  /**
23
25
  * Validates and loads all environment variables from the .env file.
24
26
  * If the .env file does not exist or any environment variables are not set, the process will exit with an error.
27
+ * @param envFile -
28
+ * @public API
25
29
  */
26
- checkAll(): void;
30
+ checkFile(envFile: string): void;
27
31
  }
28
32
  declare global {
29
33
  interface String {
@@ -32,4 +36,4 @@ declare global {
32
36
  AsString(): string | undefined;
33
37
  }
34
38
  }
35
- export { EnvValidatorProvider };
39
+ export {};
@@ -5,6 +5,7 @@ import { IProvider } from "../provider-manager";
5
5
  type LogLevel = "INFO" | "WARN" | "ERROR" | "NONE";
6
6
  /**
7
7
  * Class that provides logging functionality with colorized text.
8
+ * @public API
8
9
  */
9
10
  declare class Logger implements IProvider {
10
11
  private pid;
@@ -27,6 +28,7 @@ declare class Logger implements IProvider {
27
28
  *
28
29
  * @param message - The message to log.
29
30
  * @param module - Optional module name.
31
+ * @public API
30
32
  */
31
33
  msg(message: string, module?: string): void;
32
34
  /**
@@ -34,6 +36,7 @@ declare class Logger implements IProvider {
34
36
  *
35
37
  * @param message - The message to log.
36
38
  * @param module - Optional module name.
39
+ * @public API
37
40
  */
38
41
  info(message: string, module?: string): void;
39
42
  /**
@@ -41,6 +44,7 @@ declare class Logger implements IProvider {
41
44
  *
42
45
  * @param message - The message to log.
43
46
  * @param module - Optional module name.
47
+ * @public API
44
48
  */
45
49
  warn(message: string, module?: string): void;
46
50
  /**
@@ -48,6 +52,7 @@ declare class Logger implements IProvider {
48
52
  *
49
53
  * @param message - The message to log.
50
54
  * @param module - Optional module name.
55
+ * @public API
51
56
  */
52
57
  error(message: string, module?: string): void;
53
58
  }
@@ -1,5 +1,8 @@
1
- import "reflect-metadata";
2
- import { interfaces } from "inversify";
1
+ import { interfaces } from "../di/inversify";
2
+ /**
3
+ * Provider Interface - Represents a provider object with name, version, author, and repository information.
4
+ * @public API
5
+ */
3
6
  export interface IProvider {
4
7
  name: string;
5
8
  version: string;
@@ -7,10 +10,27 @@ export interface IProvider {
7
10
  repo: string;
8
11
  }
9
12
  type ClassType<T> = new () => T;
13
+ /**
14
+ * ProviderManager Class - A class for managing dependency injection providers.
15
+ * @public API
16
+ */
10
17
  export declare class ProviderManager {
11
18
  private container;
12
19
  private logger;
20
+ constructor(container: interfaces.Container);
21
+ /**
22
+ * Register a provider with the container.
23
+ * @param serviceIdentifier - The service identifier for the provider.
24
+ * @param scope - The binding scope for the provider.
25
+ * @public API
26
+ */
13
27
  register(serviceIdentifier: interfaces.ServiceIdentifier<unknown>, scope?: interfaces.BindingScope): void;
28
+ /**
29
+ * Get a provider from the container.
30
+ * @param provider - The provider class to get from the container.
31
+ * @returns An instance of the provider.
32
+ * @public API
33
+ */
14
34
  get<P>(provider: ClassType<P>): P;
15
35
  }
16
36
  export {};