@expressots/adapter-express 1.1.1 → 1.2.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.
- package/lib/CHANGELOG.md +18 -0
- package/lib/cjs/adapter-express/application-express.js +83 -96
- package/lib/cjs/adapter-express/application-express.types.js +22 -0
- package/lib/cjs/adapter-express/express-utils/inversify-express-server.js +43 -58
- package/lib/cjs/adapter-express/express-utils/utils.js +1 -1
- package/lib/cjs/adapter-express/index.js +2 -1
- package/lib/cjs/types/adapter-express/{application-base.d.ts → application-express.base.d.ts} +11 -18
- package/lib/cjs/types/adapter-express/application-express.d.ts +25 -29
- package/lib/cjs/types/adapter-express/application-express.interface.d.ts +4 -6
- package/lib/cjs/types/adapter-express/application-express.types.d.ts +62 -0
- package/lib/cjs/types/adapter-express/express-utils/decorators.d.ts +1 -1
- package/lib/cjs/types/adapter-express/index.d.ts +3 -2
- package/lib/package.json +23 -22
- package/package.json +23 -22
- /package/lib/cjs/adapter-express/{application-base.js → application-express.base.js} +0 -0
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [1.2.1](https://github.com/expressots/adapter-express/compare/1.2.0...1.2.1) (2024-04-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Code Refactoring
|
|
7
|
+
|
|
8
|
+
* adapter expressto to be used in AppFactory ([239501e](https://github.com/expressots/adapter-express/commit/239501e41bfd98ecc0893a50c34de58dd8914d9e))
|
|
9
|
+
* rename items for standardization and improve doc ([2e691d5](https://github.com/expressots/adapter-express/commit/2e691d50731e8d4d689fe4b4420daab8ba2f5803))
|
|
10
|
+
|
|
11
|
+
## [1.2.0](https://github.com/expressots/adapter-express/compare/1.1.1...1.2.0) (2024-3-5)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* add expressots middleware support ([809f148](https://github.com/expressots/adapter-express/commit/809f148a2b9a6bb0aa41f231595b3a4c394574ee))
|
|
17
|
+
* bump @commitlint/cli from 17.8.1 to 18.0.0 ([15fbb1a](https://github.com/expressots/adapter-express/commit/15fbb1a84c758df25b60f2a893fd44829db3c0dc))
|
|
18
|
+
* fix middleware binding to constructor ([3a6f7dc](https://github.com/expressots/adapter-express/commit/3a6f7dca40889133b09630582c775156392c4fd7))
|
|
19
|
+
* fix path call on expresso middleware ([934ae17](https://github.com/expressots/adapter-express/commit/934ae17110489315536e28b71cde24f5f18d88dc))
|
|
20
|
+
|
|
3
21
|
## [1.1.1](https://github.com/expressots/adapter-express/compare/1.1.0...1.1.1) (2023-10-10)
|
|
4
22
|
|
|
5
23
|
|
|
@@ -5,40 +5,32 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
-
});
|
|
16
|
-
};
|
|
17
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
10
|
};
|
|
20
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
12
|
+
exports.AppExpress = void 0;
|
|
13
|
+
const core_1 = require("@expressots/core");
|
|
22
14
|
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
23
15
|
const process_1 = __importDefault(require("process"));
|
|
24
|
-
const
|
|
16
|
+
const application_express_base_1 = require("./application-express.base");
|
|
25
17
|
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
26
|
-
const
|
|
18
|
+
const application_express_types_1 = require("./application-express.types");
|
|
27
19
|
/**
|
|
28
|
-
*
|
|
20
|
+
* The AppExpress class provides methods for configuring and running an Express application.
|
|
21
|
+
* @class AppExpress
|
|
22
|
+
* @implements {IWebServer} - Interface for the WebServer application implementation.
|
|
23
|
+
* @extends {ApplicationBase} - Base class for the application implementation that provides lifecycle hooks.
|
|
24
|
+
* @method configure - Configures the InversifyJS container.
|
|
25
|
+
* @method listen - Start listening on the given port and environment.
|
|
26
|
+
* @method setGlobalRoutePrefix - Sets the global route prefix for the application.
|
|
27
|
+
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
28
|
+
* @method isDevelopment - Verifies if the current environment is development.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
(function (ServerEnvironment) {
|
|
32
|
-
ServerEnvironment["Development"] = "development";
|
|
33
|
-
ServerEnvironment["Production"] = "production";
|
|
34
|
-
})(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
|
|
35
|
-
/**
|
|
36
|
-
* The Application class provides a way to configure and manage an Express application.
|
|
37
|
-
* @provide Application
|
|
38
|
-
*/
|
|
39
|
-
let ApplicationExpress = class ApplicationExpress extends application_base_1.ApplicationBase {
|
|
30
|
+
let AppExpress = class AppExpress extends application_express_base_1.ApplicationBase {
|
|
40
31
|
constructor() {
|
|
41
32
|
super(...arguments);
|
|
33
|
+
this.globalPrefix = "/";
|
|
42
34
|
this.middlewares = [];
|
|
43
35
|
}
|
|
44
36
|
configureServices() { }
|
|
@@ -52,48 +44,45 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
52
44
|
process_1.default.exit(0);
|
|
53
45
|
}
|
|
54
46
|
/**
|
|
55
|
-
*
|
|
47
|
+
* Configures the InversifyJS container.
|
|
56
48
|
* @param container - The InversifyJS container.
|
|
57
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
58
|
-
* @returns The configured Application instance.
|
|
59
49
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
50
|
+
async configure(container) {
|
|
51
|
+
this.container = container;
|
|
52
|
+
this.console = this.container.get(core_1.Console);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configures the Express application with the provided middleware entries.
|
|
56
|
+
* @param app - The Express application instance.
|
|
57
|
+
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
58
|
+
*/
|
|
59
|
+
async configureMiddleware(app, middlewareEntries) {
|
|
60
|
+
for (const entry of middlewareEntries) {
|
|
61
|
+
if (typeof entry === "function") {
|
|
62
|
+
app.use(entry);
|
|
63
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
64
|
+
}
|
|
65
|
+
else if (entry?.hasOwnProperty("path")) {
|
|
66
|
+
const { path, middlewares } = entry;
|
|
67
|
+
for (const mid of middlewares) {
|
|
68
|
+
if (path) {
|
|
69
|
+
if (typeof mid === "function") {
|
|
70
|
+
app.use(path, mid);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const middleware = mid;
|
|
74
|
+
middleware.use = middleware.use.bind(middleware);
|
|
75
|
+
app.use(path, middleware.use);
|
|
76
|
+
}
|
|
86
77
|
}
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
expressServer.setErrorConfig((app) => {
|
|
90
|
-
if (middleware.getErrorHandler()) {
|
|
91
|
-
app.use(middleware.getErrorHandler());
|
|
92
78
|
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const middleware = entry;
|
|
82
|
+
middleware.use = middleware.use.bind(middleware);
|
|
83
|
+
app.use(middleware.use);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
97
86
|
}
|
|
98
87
|
/**
|
|
99
88
|
* Create and configure the Express application.
|
|
@@ -101,13 +90,25 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
101
90
|
* @param middlewares - An array of Express middlewares to be applied.
|
|
102
91
|
* @returns The configured Application instance.
|
|
103
92
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
async init() {
|
|
94
|
+
await this.configureServices();
|
|
95
|
+
const middleware = this.container.get(core_1.Middleware);
|
|
96
|
+
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
97
|
+
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
98
|
+
this.middlewares.push(...pipeline);
|
|
99
|
+
const expressServer = new inversify_express_server_1.InversifyExpressServer(this.container, null, {
|
|
100
|
+
rootPath: this.globalPrefix,
|
|
101
|
+
});
|
|
102
|
+
expressServer.setConfig((app) => {
|
|
103
|
+
this.configureMiddleware(app, this.middlewares);
|
|
110
104
|
});
|
|
105
|
+
expressServer.setErrorConfig((app) => {
|
|
106
|
+
if (middleware.getErrorHandler()) {
|
|
107
|
+
app.use(middleware.getErrorHandler());
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
this.app = expressServer.build();
|
|
111
|
+
return this;
|
|
111
112
|
}
|
|
112
113
|
/**
|
|
113
114
|
* Start listening on the given port and environment.
|
|
@@ -115,23 +116,18 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
115
116
|
* @param environment - The server environment.
|
|
116
117
|
* @param consoleMessage - Optional message to display in the console.
|
|
117
118
|
*/
|
|
118
|
-
listen(port, environment, consoleMessage) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.environment
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const console = this.container.get(core_1.Console);
|
|
128
|
-
console.messageServer(this.port, this.environment, consoleMessage);
|
|
129
|
-
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
130
|
-
process_1.default.on(signal, this.handleExit.bind(this));
|
|
131
|
-
});
|
|
119
|
+
async listen(port, environment, consoleMessage) {
|
|
120
|
+
await this.init();
|
|
121
|
+
this.port = port;
|
|
122
|
+
this.environment = environment;
|
|
123
|
+
this.app.set("env", environment);
|
|
124
|
+
this.app.listen(this.port, () => {
|
|
125
|
+
this.console.messageServer(this.port, this.environment, consoleMessage);
|
|
126
|
+
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
127
|
+
process_1.default.on(signal, this.handleExit.bind(this));
|
|
132
128
|
});
|
|
133
|
-
yield Promise.resolve(this.postServerInitialization());
|
|
134
129
|
});
|
|
130
|
+
await this.postServerInitialization();
|
|
135
131
|
}
|
|
136
132
|
/**
|
|
137
133
|
* Sets the global route prefix for the application.
|
|
@@ -171,24 +167,15 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
171
167
|
*/
|
|
172
168
|
isDevelopment() {
|
|
173
169
|
if (this.app) {
|
|
174
|
-
return this.app.get("env") === ServerEnvironment.Development;
|
|
170
|
+
return this.app.get("env") === application_express_types_1.ServerEnvironment.Development;
|
|
175
171
|
}
|
|
176
172
|
this.container
|
|
177
173
|
.get(core_1.Logger)
|
|
178
174
|
.error("isDevelopment() method must be called on `PostServerInitialization`", "application");
|
|
179
175
|
return false;
|
|
180
176
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Verifies if the current environment is production.
|
|
183
|
-
*
|
|
184
|
-
* @returns A boolean value indicating whether the current environment is production or not.
|
|
185
|
-
*
|
|
186
|
-
*/
|
|
187
|
-
get ExpressApp() {
|
|
188
|
-
return this.app;
|
|
189
|
-
}
|
|
190
177
|
};
|
|
191
|
-
exports.AppExpress =
|
|
192
|
-
exports.AppExpress =
|
|
193
|
-
(0, inversify_binding_decorators_1.provide)(
|
|
194
|
-
],
|
|
178
|
+
exports.AppExpress = AppExpress;
|
|
179
|
+
exports.AppExpress = AppExpress = __decorate([
|
|
180
|
+
(0, inversify_binding_decorators_1.provide)(AppExpress)
|
|
181
|
+
], AppExpress);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
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 = {}));
|
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.InversifyExpressServer = void 0;
|
|
36
27
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
@@ -97,11 +88,11 @@ class InversifyExpressServer {
|
|
|
97
88
|
// it creates a new httpContext and attaches it to the
|
|
98
89
|
// current request as metadata using Reflect
|
|
99
90
|
this._app.all("*", (req, res, next) => {
|
|
100
|
-
void (() =>
|
|
101
|
-
const httpContext =
|
|
91
|
+
void (async () => {
|
|
92
|
+
const httpContext = await this._createHttpContext(req, res, next);
|
|
102
93
|
Reflect.defineMetadata(constants_1.METADATA_KEY.httpContext, httpContext, req);
|
|
103
94
|
next();
|
|
104
|
-
})
|
|
95
|
+
})();
|
|
105
96
|
});
|
|
106
97
|
// register server-level middleware before anything else
|
|
107
98
|
if (this._configFn) {
|
|
@@ -170,36 +161,34 @@ class InversifyExpressServer {
|
|
|
170
161
|
target.append(name, typeof headerValue === "number" ? headerValue.toString() : headerValue);
|
|
171
162
|
}
|
|
172
163
|
}
|
|
173
|
-
handleHttpResponseMessage(message, res) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
});
|
|
164
|
+
async handleHttpResponseMessage(message, res) {
|
|
165
|
+
this.copyHeadersTo(message.headers, res);
|
|
166
|
+
if (message.content !== undefined) {
|
|
167
|
+
this.copyHeadersTo(message.content.headers, res);
|
|
168
|
+
res
|
|
169
|
+
.status(message.statusCode)
|
|
170
|
+
// If the content is a number, ensure we change it to a string, else our content is
|
|
171
|
+
// treated as a statusCode rather than as the content of the Response
|
|
172
|
+
.send(await message.content.readAsync());
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
res.sendStatus(message.statusCode);
|
|
176
|
+
}
|
|
188
177
|
}
|
|
189
178
|
handlerFactory(controllerName, key, parameterMetadata) {
|
|
190
|
-
return (req, res, next) =>
|
|
179
|
+
return async (req, res, next) => {
|
|
191
180
|
try {
|
|
192
181
|
const args = this.extractParameters(req, res, next, parameterMetadata);
|
|
193
182
|
const httpContext = this._getHttpContext(req);
|
|
194
183
|
httpContext.container.bind(constants_1.TYPE.HttpContext).toConstantValue(httpContext);
|
|
195
184
|
// invoke controller's action
|
|
196
|
-
const value =
|
|
185
|
+
const value = await httpContext.container.getNamed(constants_1.TYPE.Controller, controllerName)[key](...args);
|
|
197
186
|
if (value instanceof httpResponseMessage_1.HttpResponseMessage) {
|
|
198
|
-
|
|
187
|
+
await this.handleHttpResponseMessage(value, res);
|
|
199
188
|
}
|
|
200
189
|
else if ((0, utils_1.instanceOfIHttpActionResult)(value)) {
|
|
201
|
-
const httpResponseMessage =
|
|
202
|
-
|
|
190
|
+
const httpResponseMessage = await value.executeAsync();
|
|
191
|
+
await this.handleHttpResponseMessage(httpResponseMessage, res);
|
|
203
192
|
}
|
|
204
193
|
else if (value instanceof Function) {
|
|
205
194
|
value();
|
|
@@ -214,36 +203,32 @@ class InversifyExpressServer {
|
|
|
214
203
|
catch (err) {
|
|
215
204
|
next(err);
|
|
216
205
|
}
|
|
217
|
-
}
|
|
206
|
+
};
|
|
218
207
|
}
|
|
219
208
|
_getHttpContext(req) {
|
|
220
209
|
return Reflect.getMetadata(constants_1.METADATA_KEY.httpContext, req);
|
|
221
210
|
}
|
|
222
|
-
_createHttpContext(req, res, next) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
};
|
|
233
|
-
});
|
|
211
|
+
async _createHttpContext(req, res, next) {
|
|
212
|
+
const principal = await this._getCurrentUser(req, res, next);
|
|
213
|
+
return {
|
|
214
|
+
// We use a childContainer for each request so we can be
|
|
215
|
+
// sure that the binding is unique for each HTTP request
|
|
216
|
+
container: this._container.createChild(),
|
|
217
|
+
request: req,
|
|
218
|
+
response: res,
|
|
219
|
+
user: principal,
|
|
220
|
+
};
|
|
234
221
|
}
|
|
235
|
-
_getCurrentUser(req, res, next) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
isResourceOwner: (_resourceId) => Promise.resolve(false),
|
|
246
|
-
});
|
|
222
|
+
async _getCurrentUser(req, res, next) {
|
|
223
|
+
if (this._AuthProvider !== undefined) {
|
|
224
|
+
const authProvider = this._container.get(constants_1.TYPE.AuthProvider);
|
|
225
|
+
return authProvider.getUser(req, res, next);
|
|
226
|
+
}
|
|
227
|
+
return Promise.resolve({
|
|
228
|
+
details: null,
|
|
229
|
+
isAuthenticated: () => Promise.resolve(false),
|
|
230
|
+
isInRole: (_role) => Promise.resolve(false),
|
|
231
|
+
isResourceOwner: (_resourceId) => Promise.resolve(false),
|
|
247
232
|
});
|
|
248
233
|
}
|
|
249
234
|
extractParameters(req, res, next, params) {
|
|
@@ -286,7 +271,7 @@ class InversifyExpressServer {
|
|
|
286
271
|
return args;
|
|
287
272
|
}
|
|
288
273
|
getParam(source, paramType, injectRoot, name) {
|
|
289
|
-
const key = paramType === "headers" ? name
|
|
274
|
+
const key = paramType === "headers" ? name?.toLowerCase() : name;
|
|
290
275
|
const param = source[paramType];
|
|
291
276
|
if (injectRoot) {
|
|
292
277
|
return param;
|
|
@@ -40,7 +40,7 @@ function getControllerParameterMetadata(constructor) {
|
|
|
40
40
|
const parameterMetadata = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerParameter, constructor);
|
|
41
41
|
const genericMetadata = Reflect.getMetadata(constants_1.METADATA_KEY.controllerParameter, Reflect.getPrototypeOf(constructor));
|
|
42
42
|
if (genericMetadata !== undefined && parameterMetadata !== undefined) {
|
|
43
|
-
return
|
|
43
|
+
return { ...parameterMetadata, ...genericMetadata };
|
|
44
44
|
}
|
|
45
45
|
if (genericMetadata !== undefined) {
|
|
46
46
|
return genericMetadata;
|
|
@@ -18,4 +18,5 @@ exports.ServerEnvironment = 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
|
-
|
|
21
|
+
var application_express_types_1 = require("./application-express.types");
|
|
22
|
+
Object.defineProperty(exports, "ServerEnvironment", { enumerable: true, get: function () { return application_express_types_1.ServerEnvironment; } });
|
package/lib/cjs/types/adapter-express/{application-base.d.ts → application-express.base.d.ts}
RENAMED
|
@@ -18,37 +18,30 @@
|
|
|
18
18
|
* @export
|
|
19
19
|
* @abstract
|
|
20
20
|
*/
|
|
21
|
-
declare abstract class ApplicationBase {
|
|
21
|
+
export declare abstract class ApplicationBase {
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* Can return a Promise for async configuration.
|
|
23
|
+
* Implement this method to set up required services or configurations before
|
|
24
|
+
* the server starts. This is essential for initializing dependencies or settings
|
|
25
|
+
* necessary for server operation. Supports asynchronous setup with a Promise.
|
|
27
26
|
*
|
|
28
27
|
* @abstract
|
|
29
28
|
* @returns {void | Promise<void>}
|
|
30
29
|
*/
|
|
31
30
|
protected abstract configureServices(): void | Promise<void>;
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* Can return a Promise for async execution.
|
|
32
|
+
* Implement this method to execute actions or configurations after the server
|
|
33
|
+
* has started. Use this for operations that need to run once the server is
|
|
34
|
+
* operational. Supports asynchronous execution with a Promise.
|
|
37
35
|
*
|
|
38
36
|
* @abstract
|
|
39
37
|
* @returns {void | Promise<void>}
|
|
40
38
|
*/
|
|
41
39
|
protected abstract postServerInitialization(): void | Promise<void>;
|
|
42
40
|
/**
|
|
43
|
-
*
|
|
44
|
-
* is shutting down.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* Can return a Promise for async cleanup.
|
|
48
|
-
*
|
|
49
|
-
* @abstract
|
|
50
|
-
* @returns {void | Promise<void>}
|
|
41
|
+
* Implement this method to handle cleanup and final actions when the server
|
|
42
|
+
* is shutting down. Ideal for closing resources, stopping tasks, or other
|
|
43
|
+
* cleanup procedures to ensure a graceful server shutdown. Supports asynchronous
|
|
44
|
+
* cleanup with a Promise.
|
|
51
45
|
*/
|
|
52
46
|
protected abstract serverShutdown(): void | Promise<void>;
|
|
53
47
|
}
|
|
54
|
-
export { ApplicationBase };
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { Container } from "inversify";
|
|
3
1
|
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
4
|
-
import {
|
|
5
|
-
import { ApplicationBase } from "./application-base";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Enum representing possible server environments.
|
|
9
|
-
*/
|
|
10
|
-
declare enum ServerEnvironment {
|
|
11
|
-
Development = "development",
|
|
12
|
-
Production = "production"
|
|
13
|
-
}
|
|
2
|
+
import { Container } from "inversify";
|
|
3
|
+
import { ApplicationBase } from "./application-express.base";
|
|
4
|
+
import { IWebServer, ServerEnvironment } from "./application-express.types";
|
|
14
5
|
/**
|
|
15
|
-
* The
|
|
16
|
-
* @
|
|
6
|
+
* The AppExpress class provides methods for configuring and running an Express application.
|
|
7
|
+
* @class AppExpress
|
|
8
|
+
* @implements {IWebServer} - Interface for the WebServer application implementation.
|
|
9
|
+
* @extends {ApplicationBase} - Base class for the application implementation that provides lifecycle hooks.
|
|
10
|
+
* @method configure - Configures the InversifyJS container.
|
|
11
|
+
* @method listen - Start listening on the given port and environment.
|
|
12
|
+
* @method setGlobalRoutePrefix - Sets the global route prefix for the application.
|
|
13
|
+
* @method setEngine - Configures the application's view engine based on the provided configuration options.
|
|
14
|
+
* @method isDevelopment - Verifies if the current environment is development.
|
|
17
15
|
*/
|
|
18
|
-
declare class
|
|
16
|
+
declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
19
17
|
private app;
|
|
20
18
|
private port;
|
|
21
19
|
private environment;
|
|
22
20
|
private container;
|
|
23
|
-
private middlewares;
|
|
24
21
|
private globalPrefix;
|
|
22
|
+
private middlewares;
|
|
23
|
+
private console;
|
|
25
24
|
protected configureServices(): void | Promise<void>;
|
|
26
25
|
protected postServerInitialization(): void | Promise<void>;
|
|
27
26
|
protected serverShutdown(): void | Promise<void>;
|
|
@@ -30,19 +29,23 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
30
29
|
*/
|
|
31
30
|
private handleExit;
|
|
32
31
|
/**
|
|
33
|
-
*
|
|
32
|
+
* Configures the InversifyJS container.
|
|
34
33
|
* @param container - The InversifyJS container.
|
|
35
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
36
|
-
* @returns The configured Application instance.
|
|
37
34
|
*/
|
|
38
|
-
|
|
35
|
+
configure(container: Container): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Configures the Express application with the provided middleware entries.
|
|
38
|
+
* @param app - The Express application instance.
|
|
39
|
+
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
40
|
+
*/
|
|
41
|
+
private configureMiddleware;
|
|
39
42
|
/**
|
|
40
43
|
* Create and configure the Express application.
|
|
41
44
|
* @param container - The InversifyJS container.
|
|
42
45
|
* @param middlewares - An array of Express middlewares to be applied.
|
|
43
46
|
* @returns The configured Application instance.
|
|
44
47
|
*/
|
|
45
|
-
|
|
48
|
+
private init;
|
|
46
49
|
/**
|
|
47
50
|
* Start listening on the given port and environment.
|
|
48
51
|
* @param port - The port number to listen on.
|
|
@@ -78,12 +81,5 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
78
81
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
79
82
|
*/
|
|
80
83
|
protected isDevelopment(): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Verifies if the current environment is production.
|
|
83
|
-
*
|
|
84
|
-
* @returns A boolean value indicating whether the current environment is production or not.
|
|
85
|
-
*
|
|
86
|
-
*/
|
|
87
|
-
get ExpressApp(): express.Application;
|
|
88
84
|
}
|
|
89
|
-
export {
|
|
85
|
+
export { AppExpress };
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
2
|
-
import { ServerEnvironment } from "./application-express";
|
|
2
|
+
import { ServerEnvironment } from "./application-express.types";
|
|
3
3
|
/**
|
|
4
|
-
* Interface
|
|
5
|
-
* @interface IApplicationExpress
|
|
4
|
+
* Public Interface for the WebServer application.
|
|
6
5
|
*/
|
|
7
|
-
interface
|
|
6
|
+
export interface IWebServerPublic {
|
|
8
7
|
/**
|
|
9
8
|
* Start listening on the given port and environment.
|
|
10
9
|
* @param port - The port number to listen on.
|
|
11
10
|
* @param environment - The server environment.
|
|
12
11
|
* @param consoleMessage - Optional message to display in the console.
|
|
13
12
|
*/
|
|
14
|
-
listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void
|
|
13
|
+
listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
|
|
15
14
|
/**
|
|
16
15
|
* Configures the application's view engine based on the provided configuration options.
|
|
17
16
|
*
|
|
@@ -25,4 +24,3 @@ interface IApplicationExpress {
|
|
|
25
24
|
*/
|
|
26
25
|
setEngine<T extends RenderTemplateOptions>(options: T): void;
|
|
27
26
|
}
|
|
28
|
-
export { IApplicationExpress };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import express, { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
3
|
+
import { Container } from "inversify";
|
|
4
|
+
/**
|
|
5
|
+
* Interface for the WebServer application implementation.
|
|
6
|
+
*/
|
|
7
|
+
export interface IWebServer {
|
|
8
|
+
configure(container: Container): Promise<void>;
|
|
9
|
+
listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): Promise<void>;
|
|
10
|
+
setEngine<T extends RenderTemplateOptions>(options: T): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Constructor type for IWebServer.
|
|
14
|
+
*/
|
|
15
|
+
export interface IWebServerConstructor<T extends IWebServer> {
|
|
16
|
+
new (): T;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* ExpressHandler Type
|
|
20
|
+
*
|
|
21
|
+
* The ExpressHandler type is a union type that represents various types of Express middleware functions.
|
|
22
|
+
* It can be one of the following types:
|
|
23
|
+
* - express.ErrorRequestHandler: Handles errors in the middleware pipeline.
|
|
24
|
+
* - express.RequestParamHandler: Handles parameters in the middleware pipeline.
|
|
25
|
+
* - express.RequestHandler: General request handler.
|
|
26
|
+
* - undefined: Represents the absence of a handler.
|
|
27
|
+
*/
|
|
28
|
+
export type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* MiddlewareConfig Interface
|
|
31
|
+
*
|
|
32
|
+
* The MiddlewareConfig interface specifies the structure for middleware configuration objects.
|
|
33
|
+
* - path: Optional. The route path for which the middleware is configured.
|
|
34
|
+
* - middlewares: An array of ExpressHandler types that make up the middleware pipeline for the route specified by 'path'.
|
|
35
|
+
*/
|
|
36
|
+
export type MiddlewareConfig = {
|
|
37
|
+
path?: string;
|
|
38
|
+
middlewares: Array<ExpressHandler>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Expresso middleware interface.
|
|
42
|
+
*/
|
|
43
|
+
interface IExpressoMiddleware {
|
|
44
|
+
use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Abstract class for creating custom Expresso middleware.
|
|
48
|
+
* Custom middleware classes should extend this class and implement the use method.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
export declare abstract class ExpressoMiddleware implements IExpressoMiddleware {
|
|
52
|
+
get name(): string;
|
|
53
|
+
abstract use(req: Request, res: Response, next: NextFunction): Promise<void> | void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Enum representing possible server environments.
|
|
57
|
+
*/
|
|
58
|
+
export declare enum ServerEnvironment {
|
|
59
|
+
Development = "development",
|
|
60
|
+
Production = "production"
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants";
|
|
3
3
|
import type { Controller, HandlerDecorator, Middleware } from "./interfaces";
|
|
4
|
-
export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<
|
|
4
|
+
export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
|
|
5
5
|
export declare function controller(path: string, ...middleware: Array<Middleware>): (target: NewableFunction) => void;
|
|
6
6
|
export declare function all(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
7
7
|
export declare function Get(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from "./express-utils";
|
|
2
|
-
export { AppExpress
|
|
3
|
-
export {
|
|
2
|
+
export { AppExpress } from "./application-express";
|
|
3
|
+
export { IWebServerPublic } from "./application-express.interface";
|
|
4
|
+
export { IWebServer, IWebServerConstructor, ServerEnvironment } from "./application-express.types";
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -56,35 +56,36 @@
|
|
|
56
56
|
"build": "npm run clean && npm run build:cjs && npm run copy",
|
|
57
57
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
58
58
|
"release": "release-it",
|
|
59
|
+
"prepublish": "npm run build && npm pack",
|
|
59
60
|
"test": "jest",
|
|
60
61
|
"format": "prettier --write \"src/**/*.ts\" --cache",
|
|
61
62
|
"lint": "eslint \"src/**/*.ts\"",
|
|
62
63
|
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"dotenv": "
|
|
66
|
-
"inversify": "
|
|
67
|
-
"inversify-binding-decorators": "
|
|
68
|
-
"jest": "
|
|
69
|
-
"reflect-metadata": "
|
|
66
|
+
"dotenv": "16.4.5",
|
|
67
|
+
"inversify": "6.0.2",
|
|
68
|
+
"inversify-binding-decorators": "4.0.0",
|
|
69
|
+
"jest": "29.5.0",
|
|
70
|
+
"reflect-metadata": "0.2.2"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@commitlint/cli": "^
|
|
73
|
-
"@commitlint/config-conventional": "
|
|
74
|
-
"@expressots/core": "
|
|
75
|
-
"@release-it/conventional-changelog": "
|
|
76
|
-
"@types/express": "
|
|
77
|
-
"@types/jest": "
|
|
78
|
-
"@types/node": "
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "
|
|
80
|
-
"@typescript-eslint/parser": "
|
|
81
|
-
"eslint": "
|
|
82
|
-
"eslint-config-prettier": "
|
|
83
|
-
"husky": "
|
|
84
|
-
"prettier": "
|
|
85
|
-
"release-it": "
|
|
86
|
-
"ts-jest": "
|
|
87
|
-
"typescript": "
|
|
73
|
+
"@commitlint/cli": "^18.0.0",
|
|
74
|
+
"@commitlint/config-conventional": "17.7.0",
|
|
75
|
+
"@expressots/core": "latest",
|
|
76
|
+
"@release-it/conventional-changelog": "7.0.1",
|
|
77
|
+
"@types/express": "4.17.21",
|
|
78
|
+
"@types/jest": "29.5.0",
|
|
79
|
+
"@types/node": "20.4.9",
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "6.6.0",
|
|
81
|
+
"@typescript-eslint/parser": "6.6.0",
|
|
82
|
+
"eslint": "8.48.0",
|
|
83
|
+
"eslint-config-prettier": "9.0.0",
|
|
84
|
+
"husky": "8.0.3",
|
|
85
|
+
"prettier": "3.0.3",
|
|
86
|
+
"release-it": "16.1.5",
|
|
87
|
+
"ts-jest": "29.0.5",
|
|
88
|
+
"typescript": "5.2.2"
|
|
88
89
|
},
|
|
89
90
|
"release-it": {
|
|
90
91
|
"git": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -56,35 +56,36 @@
|
|
|
56
56
|
"build": "npm run clean && npm run build:cjs && npm run copy",
|
|
57
57
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
58
58
|
"release": "release-it",
|
|
59
|
+
"prepublish": "npm run build && npm pack",
|
|
59
60
|
"test": "jest",
|
|
60
61
|
"format": "prettier --write \"src/**/*.ts\" --cache",
|
|
61
62
|
"lint": "eslint \"src/**/*.ts\"",
|
|
62
63
|
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
63
64
|
},
|
|
64
65
|
"dependencies": {
|
|
65
|
-
"dotenv": "
|
|
66
|
-
"inversify": "
|
|
67
|
-
"inversify-binding-decorators": "
|
|
68
|
-
"jest": "
|
|
69
|
-
"reflect-metadata": "
|
|
66
|
+
"dotenv": "16.4.5",
|
|
67
|
+
"inversify": "6.0.2",
|
|
68
|
+
"inversify-binding-decorators": "4.0.0",
|
|
69
|
+
"jest": "29.5.0",
|
|
70
|
+
"reflect-metadata": "0.2.2"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@commitlint/cli": "^
|
|
73
|
-
"@commitlint/config-conventional": "
|
|
74
|
-
"@expressots/core": "
|
|
75
|
-
"@release-it/conventional-changelog": "
|
|
76
|
-
"@types/express": "
|
|
77
|
-
"@types/jest": "
|
|
78
|
-
"@types/node": "
|
|
79
|
-
"@typescript-eslint/eslint-plugin": "
|
|
80
|
-
"@typescript-eslint/parser": "
|
|
81
|
-
"eslint": "
|
|
82
|
-
"eslint-config-prettier": "
|
|
83
|
-
"husky": "
|
|
84
|
-
"prettier": "
|
|
85
|
-
"release-it": "
|
|
86
|
-
"ts-jest": "
|
|
87
|
-
"typescript": "
|
|
73
|
+
"@commitlint/cli": "^18.0.0",
|
|
74
|
+
"@commitlint/config-conventional": "17.7.0",
|
|
75
|
+
"@expressots/core": "latest",
|
|
76
|
+
"@release-it/conventional-changelog": "7.0.1",
|
|
77
|
+
"@types/express": "4.17.21",
|
|
78
|
+
"@types/jest": "29.5.0",
|
|
79
|
+
"@types/node": "20.4.9",
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "6.6.0",
|
|
81
|
+
"@typescript-eslint/parser": "6.6.0",
|
|
82
|
+
"eslint": "8.48.0",
|
|
83
|
+
"eslint-config-prettier": "9.0.0",
|
|
84
|
+
"husky": "8.0.3",
|
|
85
|
+
"prettier": "3.0.3",
|
|
86
|
+
"release-it": "16.1.5",
|
|
87
|
+
"ts-jest": "29.0.5",
|
|
88
|
+
"typescript": "5.2.2"
|
|
88
89
|
},
|
|
89
90
|
"release-it": {
|
|
90
91
|
"git": {
|
|
File without changes
|