@expressots/adapter-express 1.8.2 → 3.0.0-beta.2

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 (49) hide show
  1. package/lib/CHANGELOG.md +168 -139
  2. package/lib/cjs/adapter-express/application-express.base.js +2 -12
  3. package/lib/cjs/adapter-express/application-express.js +132 -52
  4. package/lib/cjs/adapter-express/application-express.types.js +0 -20
  5. package/lib/cjs/adapter-express/express-utils/base-middleware.js +2 -2
  6. package/lib/cjs/adapter-express/express-utils/constants.js +1 -3
  7. package/lib/cjs/adapter-express/express-utils/decorators.js +26 -12
  8. package/lib/cjs/adapter-express/express-utils/http-status-middleware.js +10 -5
  9. package/lib/cjs/adapter-express/express-utils/utils.js +3 -0
  10. package/lib/cjs/adapter-express/index.js +4 -1
  11. package/lib/cjs/adapter-express/micro-api/application-express-micro-container.js +51 -0
  12. package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +101 -0
  13. package/lib/cjs/adapter-express/micro-api/application-express-micro.js +177 -0
  14. package/lib/cjs/adapter-express/micro-api/index.js +5 -0
  15. package/lib/cjs/adapter-express/render/constants.js +40 -0
  16. package/lib/cjs/adapter-express/render/engine.js +52 -11
  17. package/lib/cjs/adapter-express/render/index.js +0 -3
  18. package/lib/cjs/di/di.interfaces.js +10 -0
  19. package/lib/cjs/types/adapter-express/application-express.base.d.ts +17 -0
  20. package/lib/cjs/types/adapter-express/application-express.d.ts +58 -23
  21. package/lib/cjs/types/adapter-express/application-express.types.d.ts +1 -41
  22. package/lib/cjs/types/adapter-express/express-utils/base-middleware.d.ts +1 -1
  23. package/lib/cjs/types/adapter-express/express-utils/constants.d.ts +1 -1
  24. package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +18 -4
  25. package/lib/cjs/types/adapter-express/express-utils/http-status-middleware.d.ts +2 -0
  26. package/lib/cjs/types/adapter-express/express-utils/interfaces.d.ts +1 -1
  27. package/lib/cjs/types/adapter-express/express-utils/inversify-express-server.d.ts +1 -1
  28. package/lib/cjs/types/adapter-express/express-utils/utils.d.ts +1 -1
  29. package/lib/cjs/types/adapter-express/index.d.ts +2 -2
  30. package/lib/cjs/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
  31. package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +93 -0
  32. package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +79 -0
  33. package/lib/cjs/types/adapter-express/micro-api/index.d.ts +1 -0
  34. package/lib/cjs/types/adapter-express/render/constants.d.ts +26 -0
  35. package/lib/cjs/types/adapter-express/render/engine.d.ts +14 -22
  36. package/lib/cjs/types/adapter-express/render/index.d.ts +4 -4
  37. package/lib/cjs/types/di/di.interfaces.d.ts +289 -0
  38. package/lib/package.json +11 -16
  39. package/package.json +11 -16
  40. package/lib/cjs/adapter-express/application-express.interface.js +0 -2
  41. package/lib/cjs/adapter-express/render/ejs/ejs.config.js +0 -37
  42. package/lib/cjs/adapter-express/render/ejs/ejs.types.js +0 -3
  43. package/lib/cjs/adapter-express/render/handlebars/hbs.config.js +0 -38
  44. package/lib/cjs/adapter-express/render/pug/pug.config.js +0 -25
  45. package/lib/cjs/types/adapter-express/application-express.interface.d.ts +0 -20
  46. package/lib/cjs/types/adapter-express/render/ejs/ejs.config.d.ts +0 -21
  47. package/lib/cjs/types/adapter-express/render/ejs/ejs.types.d.ts +0 -169
  48. package/lib/cjs/types/adapter-express/render/handlebars/hbs.config.d.ts +0 -20
  49. package/lib/cjs/types/adapter-express/render/pug/pug.config.d.ts +0 -17
@@ -1,26 +1,40 @@
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;
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;
7
24
  };
8
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
27
  };
11
28
  Object.defineProperty(exports, "__esModule", { value: true });
12
29
  exports.AppExpress = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const process_1 = __importStar(require("process"));
13
32
  const core_1 = require("@expressots/core");
14
- const inversify_binding_decorators_1 = require("inversify-binding-decorators");
15
- const process_1 = __importDefault(require("process"));
33
+ const shared_1 = require("@expressots/shared");
16
34
  const application_express_base_1 = require("./application-express.base");
17
- const application_express_types_1 = require("./application-express.types");
18
35
  const http_status_middleware_1 = require("./express-utils/http-status-middleware");
19
36
  const inversify_express_server_1 = require("./express-utils/inversify-express-server");
20
- const ejs_config_1 = require("./render/ejs/ejs.config");
21
37
  const engine_1 = require("./render/engine");
22
- const hbs_config_1 = require("./render/handlebars/hbs.config");
23
- const pug_config_1 = require("./render/pug/pug.config");
24
38
  /**
25
39
  * The AppExpress class provides methods for configuring and running an Express application.
26
40
  * @class AppExpress
@@ -32,14 +46,17 @@ const pug_config_1 = require("./render/pug/pug.config");
32
46
  * @method setEngine - Configures the application's view engine based on the provided configuration options.
33
47
  * @method isDevelopment - Verifies if the current environment is development.
34
48
  */
35
- let AppExpress = class AppExpress extends application_express_base_1.ApplicationBase {
49
+ class AppExpress extends application_express_base_1.ApplicationBase {
36
50
  constructor() {
37
- super(...arguments);
51
+ super();
38
52
  this.logger = new core_1.Logger();
53
+ this.console = new core_1.Console();
39
54
  this.globalPrefix = "/";
40
55
  this.middlewares = [];
41
56
  this.renderOptions = {};
57
+ this.globalConfiguration();
42
58
  }
59
+ globalConfiguration() { }
43
60
  configureServices() { }
44
61
  postServerInitialization() { }
45
62
  serverShutdown() { }
@@ -51,12 +68,42 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
51
68
  process_1.default.exit(0);
52
69
  }
53
70
  /**
54
- * Configures the InversifyJS container.
55
- * @param container - The InversifyJS container.
71
+ * Initialize the InversifyJS container with the provided modules and options.
72
+ * @param appModules - An array of application modules to be loaded into the container.
73
+ * @param containerOptions - Container global configuration options.
74
+ * @option skipBaseClassChecks - Skip the base class checks for the container.
75
+ * @option autoBindInjectable - Automatically bind the injectable classes.
76
+ * @option defaultScope - The default scope to use for bindings.
77
+ *
78
+ * @returns The configured AppContainer instance.
79
+ * @public API
80
+ */
81
+ configContainer(appModules, containerOptions) {
82
+ this.appContainer = new core_1.AppContainer(containerOptions ? containerOptions : {});
83
+ if (!appModules) {
84
+ this.logger.error("No modules provided for container configuration", "adapter-express");
85
+ return;
86
+ }
87
+ this.appContainer.create(appModules);
88
+ this.providerManager = new core_1.ProviderManager(this.appContainer.Container);
89
+ this.middlewareManager = new core_1.Middleware();
90
+ return this.appContainer;
91
+ }
92
+ /**
93
+ * Get the ProviderManager instance.
94
+ * @returns The ProviderManager instance.
95
+ * @public API
56
96
  */
57
- async configure(container) {
58
- this.container = container;
59
- this.console = this.container.get(core_1.Console);
97
+ get Provider() {
98
+ return this.providerManager;
99
+ }
100
+ /**
101
+ * Get the Middleware instance.
102
+ * @returns The Middleware instance.
103
+ * @public API
104
+ */
105
+ get Middleware() {
106
+ return this.middlewareManager;
60
107
  }
61
108
  /**
62
109
  * Configures the Express application with the provided middleware entries.
@@ -98,22 +145,25 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
98
145
  * @returns The configured Application instance.
99
146
  */
100
147
  async init() {
148
+ if (!this.appContainer) {
149
+ this.logger.error("No container provided for application configuration", "adapter-express");
150
+ (0, process_1.exit)(1);
151
+ }
101
152
  await this.configureServices();
102
- const middleware = this.container.get(core_1.Middleware);
103
- const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
153
+ const sortedMiddlewarePipeline = this.Middleware.getMiddlewarePipeline();
104
154
  const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
105
155
  this.middlewares.push(...pipeline);
106
156
  /* Apply the status code to the response */
107
- this.middlewares.unshift(new http_status_middleware_1.HttpStatusCodeMiddleware());
108
- const expressServer = new inversify_express_server_1.InversifyExpressServer(this.container, null, {
157
+ this.middlewares.unshift(new http_status_middleware_1.HttpStatusCodeMiddleware(this.globalPrefix));
158
+ const expressServer = new inversify_express_server_1.InversifyExpressServer(this.appContainer.Container, null, {
109
159
  rootPath: this.globalPrefix,
110
160
  });
111
161
  expressServer.setConfig((app) => {
112
162
  this.configureMiddleware(app, this.middlewares);
113
163
  });
114
164
  expressServer.setErrorConfig((app) => {
115
- if (middleware.getErrorHandler()) {
116
- app.use(middleware.getErrorHandler());
165
+ if (this.Middleware.getErrorHandler()) {
166
+ app.use(this.Middleware.getErrorHandler());
117
167
  }
118
168
  });
119
169
  this.app = expressServer.build();
@@ -122,17 +172,17 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
122
172
  /**
123
173
  * Start listening on the given port and environment.
124
174
  * @param port - The port number to listen on.
125
- * @param environment - The server environment.
126
- * @param consoleMessage - Optional message to display in the console.
175
+ * @param appInfo - Optional message to display the app name and version.
176
+ * @public API
127
177
  */
128
- async listen(port, environment, consoleMessage) {
178
+ async listen(port, appInfo) {
129
179
  await this.init();
130
180
  await this.configEngine();
131
- this.port = port || 3000;
132
- this.environment = environment;
133
- this.app.set("env", environment);
181
+ this.environment = this.environment || "development";
182
+ this.app.set("env", this.environment);
183
+ this.port = typeof port === "string" ? parseInt(port, 10) : port || 3000;
134
184
  this.app.listen(this.port, () => {
135
- this.console.messageServer(this.port, this.environment, consoleMessage);
185
+ this.console.messageServer(this.port, this.environment, appInfo);
136
186
  ["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
137
187
  process_1.default.on(signal, this.handleExit.bind(this));
138
188
  });
@@ -141,12 +191,9 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
141
191
  }
142
192
  /**
143
193
  * Sets the global route prefix for the application.
144
- *
145
- * @public
146
194
  * @method setGlobalRoutePrefix
147
- *
148
195
  * @param {string} prefix - The prefix to use for all routes.
149
- *
196
+ * @public API
150
197
  */
151
198
  setGlobalRoutePrefix(prefix) {
152
199
  this.globalPrefix = prefix;
@@ -157,14 +204,14 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
157
204
  async configEngine() {
158
205
  if (this.renderOptions.engine) {
159
206
  switch (this.renderOptions.engine) {
160
- case engine_1.Engine.HBS:
161
- await (0, hbs_config_1.setEngineHandlebars)(this.app, this.renderOptions.options);
207
+ case shared_1.RenderEngine.Engine.HBS:
208
+ await (0, engine_1.setEngineHandlebars)(this.app, this.renderOptions.options);
162
209
  break;
163
- case engine_1.Engine.EJS:
164
- await (0, ejs_config_1.setEngineEjs)(this.app, this.renderOptions.options);
210
+ case shared_1.RenderEngine.Engine.EJS:
211
+ await (0, engine_1.setEngineEjs)(this.app, this.renderOptions.options);
165
212
  break;
166
- case engine_1.Engine.PUG:
167
- await (0, pug_config_1.setEnginePug)(this.app, this.renderOptions.options);
213
+ case shared_1.RenderEngine.Engine.PUG:
214
+ await (0, engine_1.setEnginePug)(this.app, this.renderOptions.options);
168
215
  break;
169
216
  default:
170
217
  throw new Error("Unsupported engine type!");
@@ -173,13 +220,12 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
173
220
  }
174
221
  /**
175
222
  * Configures the application's view engine based on the provided configuration options.
176
- *
177
- * @public
178
223
  * @method setEngine
179
224
  * @template T - A generic type extending from RenderTemplateOptions.
180
225
  *
181
226
  * @param {Engine} engine - The view engine to set
182
227
  * @param {EngineOptions} [options] - The configuration options for the view engine
228
+ * @public API
183
229
  */
184
230
  async setEngine(engine, options) {
185
231
  try {
@@ -196,21 +242,58 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
196
242
  }
197
243
  /**
198
244
  * Verifies if the current environment is development.
199
- *
200
245
  * @returns A boolean value indicating whether the current environment is development or not.
246
+ * @public API
201
247
  */
202
248
  isDevelopment() {
203
249
  if (this.app) {
204
- return this.app.get("env") === application_express_types_1.ServerEnvironment.Development;
250
+ return this.app.get("env") === "development";
205
251
  }
206
- this.container
207
- .get(core_1.Logger)
208
- .error("isDevelopment() method must be called on `PostServerInitialization`", "application");
252
+ this.appContainer.Container.get(core_1.Logger).error("isDevelopment() method must be called on `PostServerInitialization`", "application");
209
253
  return false;
210
254
  }
255
+ /**
256
+ * Load environment variables from the specified file based on the environment configuration.
257
+ * @param environment - The environment to load configuration for.
258
+ * @param options - The options to use for loading the environment configuration.
259
+ * @option env - The environment configuration options.
260
+ * @example
261
+ * ```typescript
262
+ * {
263
+ env: {
264
+ development: ".env.development",
265
+ production: ".env.production"
266
+ }
267
+ }
268
+ * ```
269
+ * @public API
270
+ */
271
+ initEnvironment(environment, options) {
272
+ this.environment = environment;
273
+ if (options === undefined) {
274
+ (0, shared_1.config)({ path: ".env" });
275
+ }
276
+ else {
277
+ if (!options.env[environment]) {
278
+ this.logger.error(`Environment configuration for [${environment}] does not exist.`, "adapter-express");
279
+ process_1.default.exit(1);
280
+ }
281
+ else {
282
+ const envFileName = options.env[environment];
283
+ if (!fs_1.default.existsSync(envFileName)) {
284
+ this.logger.error(`Environment file [${envFileName}] does not exist.`, "adapter-express");
285
+ process_1.default.exit(1);
286
+ }
287
+ else {
288
+ (0, shared_1.config)({ path: envFileName });
289
+ }
290
+ }
291
+ }
292
+ }
211
293
  /**
212
294
  * Get the underlying HTTP server. (default: Express.js)
213
295
  * @returns The underlying HTTP server after initialization.
296
+ * @public API
214
297
  */
215
298
  async getHttpServer() {
216
299
  if (!this.app) {
@@ -219,8 +302,5 @@ let AppExpress = class AppExpress extends application_express_base_1.Application
219
302
  }
220
303
  return this.app;
221
304
  }
222
- };
305
+ }
223
306
  exports.AppExpress = AppExpress;
224
- exports.AppExpress = AppExpress = __decorate([
225
- (0, inversify_binding_decorators_1.provide)(AppExpress)
226
- ], AppExpress);
@@ -1,22 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ServerEnvironment = exports.ExpressoMiddleware = void 0;
4
- /**
5
- * Abstract class for creating custom Expresso middleware.
6
- * Custom middleware classes should extend this class and implement the use method.
7
- *
8
- */
9
- class ExpressoMiddleware {
10
- get name() {
11
- return this.constructor.name;
12
- }
13
- }
14
- exports.ExpressoMiddleware = ExpressoMiddleware;
15
- /**
16
- * Enum representing possible server environments.
17
- */
18
- var ServerEnvironment;
19
- (function (ServerEnvironment) {
20
- ServerEnvironment["Development"] = "development";
21
- ServerEnvironment["Production"] = "production";
22
- })(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
@@ -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.BaseMiddleware = void 0;
10
- const inversify_1 = require("inversify");
10
+ const core_1 = require("@expressots/core");
11
11
  let BaseMiddleware = class BaseMiddleware {
12
12
  bind(serviceIdentifier) {
13
13
  return this.httpContext.container.bind(serviceIdentifier);
@@ -15,5 +15,5 @@ let BaseMiddleware = class BaseMiddleware {
15
15
  };
16
16
  exports.BaseMiddleware = BaseMiddleware;
17
17
  exports.BaseMiddleware = BaseMiddleware = __decorate([
18
- (0, inversify_1.injectable)()
18
+ (0, core_1.injectable)()
19
19
  ], BaseMiddleware);
@@ -46,7 +46,5 @@ var HTTP_VERBS_ENUM;
46
46
  })(HTTP_VERBS_ENUM || (exports.HTTP_VERBS_ENUM = HTTP_VERBS_ENUM = {}));
47
47
  const DUPLICATED_CONTROLLER_NAME = (name) => `Two controllers cannot have the same name: ${name}`;
48
48
  exports.DUPLICATED_CONTROLLER_NAME = DUPLICATED_CONTROLLER_NAME;
49
- exports.NO_CONTROLLERS_FOUND = "No controllers" +
50
- "have been found! Please ensure that you have register" +
51
- "at least one Controller.";
49
+ exports.NO_CONTROLLERS_FOUND = "No controller found! Please ensure that you have register at least one Controller.";
52
50
  exports.DEFAULT_ROUTING_ROOT_PATH = "/";
@@ -16,15 +16,16 @@ exports.Render = Render;
16
16
  exports.getRenderMetadata = getRenderMetadata;
17
17
  exports.FileUpload = FileUpload;
18
18
  require("reflect-metadata");
19
- const inversify_1 = require("inversify");
19
+ const core_1 = require("@expressots/core");
20
20
  const constants_1 = require("./constants");
21
21
  const resolver_multer_1 = require("./resolver-multer");
22
- const core_1 = require("@expressots/core");
23
- exports.injectHttpContext = (0, inversify_1.inject)(constants_1.TYPE.HttpContext);
22
+ const core_2 = require("@expressots/core");
23
+ exports.injectHttpContext = (0, core_1.inject)(constants_1.TYPE.HttpContext);
24
24
  /**
25
25
  * Controller decorator to define a new controller
26
26
  * @param path route path
27
27
  * @param middleware array of middleware to be applied to all routes in the controller
28
+ * @public API
28
29
  */
29
30
  function controller(path, ...middleware) {
30
31
  return (target) => {
@@ -46,7 +47,7 @@ function controller(path, ...middleware) {
46
47
  Reflect.defineMetadata(constants_1.HTTP_CODE_METADATA.httpCode, statusCodePathMapping, Reflect);
47
48
  Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.statusCode, Reflect);
48
49
  Reflect.deleteMetadata(constants_1.HTTP_CODE_METADATA.path, Reflect);
49
- (0, inversify_1.decorate)((0, inversify_1.injectable)(), target);
50
+ (0, core_1.decorate)((0, core_1.injectable)(), target);
50
51
  Reflect.defineMetadata(constants_1.METADATA_KEY.controller, currentMetadata, target);
51
52
  const previousMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controller, Reflect) || [];
52
53
  const newMetadata = [currentMetadata, ...previousMetadata];
@@ -57,14 +58,14 @@ function controller(path, ...middleware) {
57
58
  * Http decorator to define the status code for a route
58
59
  * @param code
59
60
  * @returns MethodDecorator
60
- * @example
61
- * ```ts
61
+ * @example ```typescript
62
62
  * @Http(200)
63
63
  * @Get("/")
64
64
  * hello() {
65
65
  * return "Hello World";
66
66
  * }
67
67
  * ```
68
+ * @public API
68
69
  */
69
70
  function Http(code) {
70
71
  // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any
@@ -84,6 +85,7 @@ function Http(code) {
84
85
  * Decorator to allow accept all HTTP methods
85
86
  * @param path route path, wildcard
86
87
  * @param middleware array of middleware to be applied to all routes defined in path logic
88
+ * @public API
87
89
  */
88
90
  function All(path, ...middleware) {
89
91
  return Method("all", path, ...middleware);
@@ -92,6 +94,7 @@ function All(path, ...middleware) {
92
94
  * Decorator to allow GET HTTP method
93
95
  * @param path route path
94
96
  * @param middleware array of middleware to be applied to the route
97
+ * @public API
95
98
  */
96
99
  function Get(path, ...middleware) {
97
100
  return enhancedHttpMethod("get", path, ...middleware);
@@ -100,6 +103,7 @@ function Get(path, ...middleware) {
100
103
  * Decorator to allow POST HTTP method
101
104
  * @param path route path
102
105
  * @param middleware array of middleware to be applied to the route
106
+ * @public API
103
107
  */
104
108
  function Post(path, ...middleware) {
105
109
  return Method("post", path, ...middleware);
@@ -108,6 +112,7 @@ function Post(path, ...middleware) {
108
112
  * Decorator to allow PUT HTTP method
109
113
  * @param path route path
110
114
  * @param middleware array of middleware to be applied to the route
115
+ * @public API
111
116
  */
112
117
  function Put(path, ...middleware) {
113
118
  return enhancedHttpMethod("put", path, ...middleware);
@@ -116,6 +121,7 @@ function Put(path, ...middleware) {
116
121
  * Decorator to allow PATCH HTTP method
117
122
  * @param path route path
118
123
  * @param middleware array of middleware to be applied to the route
124
+ * @public API
119
125
  */
120
126
  function Patch(path, ...middleware) {
121
127
  return enhancedHttpMethod("patch", path, ...middleware);
@@ -124,6 +130,7 @@ function Patch(path, ...middleware) {
124
130
  * Decorator to allow HEAD HTTP method
125
131
  * @param path route path
126
132
  * @param middleware array of middleware to be applied to the route
133
+ * @public API
127
134
  */
128
135
  function Head(path, ...middleware) {
129
136
  return Method("head", path, ...middleware);
@@ -132,6 +139,7 @@ function Head(path, ...middleware) {
132
139
  * Decorator to allow DELETE HTTP method
133
140
  * @param path route path
134
141
  * @param middleware array of middleware to be applied to the route
142
+ * @public API
135
143
  */
136
144
  function Delete(path, ...middleware) {
137
145
  return enhancedHttpMethod("delete", path, ...middleware);
@@ -191,6 +199,7 @@ function enhancedHttpMethod(method, path, ...middleware) {
191
199
  * @param method custom HTTP method
192
200
  * @param path route path
193
201
  * @param middleware array of middleware to be applied to the route
202
+ * @public API
194
203
  */
195
204
  function Method(method, path, ...middleware) {
196
205
  return (target, key) => {
@@ -281,6 +290,9 @@ function paramDecoratorFactory(parameterType) {
281
290
  /**
282
291
  * Parameter decorator to inject the request object
283
292
  * @returns ParameterDecorator
293
+ * @param type - The type of parameter to inject
294
+ * @param parameterName - The name of the parameter to inject
295
+ * @public API
284
296
  */
285
297
  function params(type, parameterName) {
286
298
  return (target, methodName, index) => {
@@ -310,7 +322,8 @@ function params(type, parameterName) {
310
322
  * Render decorator to define the template and default data for a route
311
323
  * @param template The template to render
312
324
  * @param defaultData The default data to pass to the template
313
- * @returns
325
+ * @returns MethodDecorator
326
+ * @public API
314
327
  */
315
328
  function Render(template, defaultData) {
316
329
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -357,6 +370,7 @@ function isResponse(obj) {
357
370
  * @param multerOptions
358
371
  * @default { none: true }
359
372
  * @returns MethodDecorator
373
+ * @public API
360
374
  */
361
375
  function FileUpload(options, multerOptions) {
362
376
  const multer = (0, resolver_multer_1.packageResolver)("multer");
@@ -398,7 +412,7 @@ function FileUpload(options, multerOptions) {
398
412
  * @returns
399
413
  */
400
414
  function inferMulterMethod(options) {
401
- const report = new core_1.Report();
415
+ const report = new core_2.Report();
402
416
  if (options.none)
403
417
  return "none";
404
418
  if (options.any)
@@ -409,17 +423,17 @@ function inferMulterMethod(options) {
409
423
  return "array";
410
424
  if (options.fieldName)
411
425
  return "single";
412
- throw report.error("Invalid options provided for FileUpload.", core_1.StatusCode.InternalServerError, "multer-decorator");
426
+ throw report.error("Invalid options provided for FileUpload.", core_2.StatusCode.InternalServerError, "multer-decorator");
413
427
  }
414
428
  /**
415
429
  * Get the multer middleware based on the method
416
430
  * @param upload
417
431
  * @param options
418
432
  * @param method
419
- * @returns
433
+ * @returns RequestHandler
420
434
  */
421
435
  function getMulterMiddleware(upload, options, method) {
422
- const report = new core_1.Report();
436
+ const report = new core_2.Report();
423
437
  switch (method) {
424
438
  case "single":
425
439
  return upload.single(options.fieldName);
@@ -437,6 +451,6 @@ function getMulterMiddleware(upload, options, method) {
437
451
  case "any":
438
452
  return upload.any();
439
453
  default:
440
- throw report.error(`Unsupported Multer method: ${method}`, core_1.StatusCode.InternalServerError, "multer-decorator");
454
+ throw report.error(`Unsupported Multer method: ${method}`, core_2.StatusCode.InternalServerError, "multer-decorator");
441
455
  }
442
456
  }
@@ -9,14 +9,19 @@ const constants_1 = require("./constants");
9
9
  * @returns express.RequestHandler
10
10
  */
11
11
  class HttpStatusCodeMiddleware extends core_1.ExpressoMiddleware {
12
+ constructor(globalPrefix = "/") {
13
+ super();
14
+ this.globalPrefix = globalPrefix;
15
+ }
12
16
  use(req, res, next) {
13
17
  const statusCodeMapping = Reflect.getMetadata(constants_1.HTTP_CODE_METADATA.httpCode, Reflect);
14
- let path = req.path.endsWith("/") ? req.path.slice(0, -1) : req.path;
15
- const formattedMethod = req.method.toLowerCase();
16
- if (path === "/" || path === "") {
17
- path = "/";
18
+ let path = req.path;
19
+ if (this.globalPrefix !== "/" && path.startsWith(this.globalPrefix)) {
20
+ path = path.slice(this.globalPrefix.length);
18
21
  }
19
- path = `${path}/-${formattedMethod}`;
22
+ path = path.endsWith("/") ? path.slice(0, -1) : path;
23
+ const formattedMethod = req.method.toLowerCase();
24
+ path = `${path || "/"}/-${formattedMethod}`;
20
25
  const statusCode = statusCodeMapping[path];
21
26
  if (statusCode) {
22
27
  res.status(statusCode);
@@ -7,12 +7,15 @@ exports.getControllerMethodMetadata = getControllerMethodMetadata;
7
7
  exports.getControllerParameterMetadata = getControllerParameterMetadata;
8
8
  exports.cleanUpMetadata = cleanUpMetadata;
9
9
  exports.instanceOfIHttpActionResult = instanceOfIHttpActionResult;
10
+ const core_1 = require("@expressots/core");
10
11
  const constants_1 = require("./constants");
11
12
  function getControllersFromContainer(container, forceControllers) {
12
13
  if (container.isBound(constants_1.TYPE.Controller)) {
13
14
  return container.getAll(constants_1.TYPE.Controller);
14
15
  }
15
16
  if (forceControllers) {
17
+ const logger = new core_1.Logger();
18
+ logger.error(constants_1.NO_CONTROLLERS_FOUND, "adapter-express");
16
19
  throw new Error(constants_1.NO_CONTROLLERS_FOUND);
17
20
  }
18
21
  else {
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AppExpress = void 0;
17
+ exports.RenderEngine = exports.AppExpress = void 0;
18
18
  __exportStar(require("./express-utils"), exports);
19
19
  var application_express_1 = require("./application-express");
20
20
  Object.defineProperty(exports, "AppExpress", { enumerable: true, get: function () { return application_express_1.AppExpress; } });
21
+ __exportStar(require("./micro-api"), exports);
22
+ var shared_1 = require("@expressots/shared");
23
+ Object.defineProperty(exports, "RenderEngine", { enumerable: true, get: function () { return shared_1.RenderEngine; } });
21
24
  __exportStar(require("./render"), exports);
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IOC = void 0;
4
+ const core_1 = require("@expressots/core");
5
+ /**
6
+ * Inversion of Control Container
7
+ * @public API
8
+ */
9
+ class IOC {
10
+ constructor(containerOptions) {
11
+ this.container = new core_1.Container(containerOptions);
12
+ }
13
+ /**
14
+ * Add a singleton to the container
15
+ * @param identifierOrConcrete - The identifier or concrete class
16
+ * @param concrete - The concrete class if identifier is provided
17
+ * @public API
18
+ */
19
+ addSingleton(concrete) {
20
+ this.container.bind(concrete).toSelf().inSingletonScope();
21
+ }
22
+ /**
23
+ * Add a transient to the container
24
+ * @param identifierOrConcrete - The identifier or concrete class
25
+ * @param concrete - The concrete class if identifier is provided
26
+ * @public API
27
+ */
28
+ addTransient(concrete) {
29
+ this.container.bind(concrete).toSelf().inTransientScope();
30
+ }
31
+ /**
32
+ * Add a scoped to the container
33
+ * @param identifierOrConcrete - The identifier or concrete class
34
+ * @param concrete - The concrete class if identifier is provided
35
+ * @public API
36
+ */
37
+ addScoped(concrete) {
38
+ this.container.bind(concrete).toSelf().inRequestScope();
39
+ }
40
+ /**
41
+ * Get an instance from the container
42
+ * @param identifier - The identifier for the instance
43
+ * @returns The resolved instance
44
+ * @public API
45
+ */
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ get(identifier) {
48
+ return this.container.get(identifier);
49
+ }
50
+ }
51
+ exports.IOC = IOC;