@expressots/adapter-express 1.2.0 → 1.2.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.
- package/lib/CHANGELOG.md +15 -0
- package/lib/cjs/adapter-express/application-express.js +78 -120
- package/lib/cjs/adapter-express/application-express.types.js +22 -0
- package/lib/cjs/adapter-express/express-utils/decorators.js +125 -10
- 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 +21 -41
- 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 +81 -5
- package/lib/cjs/types/adapter-express/index.d.ts +3 -2
- package/lib/package.json +22 -21
- package/package.json +22 -21
- /package/lib/cjs/adapter-express/{application-base.js → application-express.base.js} +0 -0
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [1.2.2](https://github.com/expressots/adapter-express/compare/1.2.1...1.2.2) (2024-04-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* validate parameter types in param decorator by default ([b7a8657](https://github.com/expressots/adapter-express/commit/b7a8657598ce51a6fa44c3a388d38106b47ad70d))
|
|
9
|
+
|
|
10
|
+
## [1.2.1](https://github.com/expressots/adapter-express/compare/1.2.0...1.2.1) (2024-04-04)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Code Refactoring
|
|
14
|
+
|
|
15
|
+
* adapter expressto to be used in AppFactory ([239501e](https://github.com/expressots/adapter-express/commit/239501e41bfd98ecc0893a50c34de58dd8914d9e))
|
|
16
|
+
* rename items for standardization and improve doc ([2e691d5](https://github.com/expressots/adapter-express/commit/2e691d50731e8d4d689fe4b4420daab8ba2f5803))
|
|
17
|
+
|
|
3
18
|
## [1.2.0](https://github.com/expressots/adapter-express/compare/1.1.1...1.2.0) (2024-3-5)
|
|
4
19
|
|
|
5
20
|
|
|
@@ -5,50 +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
|
|
27
|
-
/**
|
|
28
|
-
* Abstract class for creating custom Expresso middleware.
|
|
29
|
-
* Custom middleware classes should extend this class and implement the use method.
|
|
30
|
-
*
|
|
31
|
-
*/
|
|
32
|
-
class ExpressoMiddleware {
|
|
33
|
-
get name() {
|
|
34
|
-
return this.constructor.name;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Enum representing possible server environments.
|
|
39
|
-
*/
|
|
40
|
-
var ServerEnvironment;
|
|
41
|
-
(function (ServerEnvironment) {
|
|
42
|
-
ServerEnvironment["Development"] = "development";
|
|
43
|
-
ServerEnvironment["Production"] = "production";
|
|
44
|
-
})(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
|
|
18
|
+
const application_express_types_1 = require("./application-express.types");
|
|
45
19
|
/**
|
|
46
|
-
* The
|
|
47
|
-
* @
|
|
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.
|
|
48
29
|
*/
|
|
49
|
-
let
|
|
30
|
+
let AppExpress = class AppExpress extends application_express_base_1.ApplicationBase {
|
|
50
31
|
constructor() {
|
|
51
32
|
super(...arguments);
|
|
33
|
+
this.globalPrefix = "/";
|
|
52
34
|
this.middlewares = [];
|
|
53
35
|
}
|
|
54
36
|
configureServices() { }
|
|
@@ -61,40 +43,46 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
61
43
|
this.serverShutdown();
|
|
62
44
|
process_1.default.exit(0);
|
|
63
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Configures the InversifyJS container.
|
|
48
|
+
* @param container - The InversifyJS container.
|
|
49
|
+
*/
|
|
50
|
+
async configure(container) {
|
|
51
|
+
this.container = container;
|
|
52
|
+
this.console = this.container.get(core_1.Console);
|
|
53
|
+
}
|
|
64
54
|
/**
|
|
65
55
|
* Configures the Express application with the provided middleware entries.
|
|
66
56
|
* @param app - The Express application instance.
|
|
67
57
|
* @param middlewareEntries - An array of Express middleware entries to be applied.
|
|
68
58
|
*/
|
|
69
|
-
configureMiddleware(app, middlewareEntries) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
app.use(path, middleware.use);
|
|
87
|
-
}
|
|
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);
|
|
88
76
|
}
|
|
89
77
|
}
|
|
90
78
|
}
|
|
91
|
-
else {
|
|
92
|
-
const middleware = entry;
|
|
93
|
-
middleware.use = middleware.use.bind(middleware);
|
|
94
|
-
app.use(middleware.use);
|
|
95
|
-
}
|
|
96
79
|
}
|
|
97
|
-
|
|
80
|
+
else {
|
|
81
|
+
const middleware = entry;
|
|
82
|
+
middleware.use = middleware.use.bind(middleware);
|
|
83
|
+
app.use(middleware.use);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
98
86
|
}
|
|
99
87
|
/**
|
|
100
88
|
* Create and configure the Express application.
|
|
@@ -102,41 +90,25 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
102
90
|
* @param middlewares - An array of Express middlewares to be applied.
|
|
103
91
|
* @returns The configured Application instance.
|
|
104
92
|
*/
|
|
105
|
-
init(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
rootPath: this.globalPrefix,
|
|
114
|
-
});
|
|
115
|
-
expressServer.setConfig((app) => {
|
|
116
|
-
this.configureMiddleware(app, this.middlewares);
|
|
117
|
-
});
|
|
118
|
-
expressServer.setErrorConfig((app) => {
|
|
119
|
-
if (middleware.getErrorHandler()) {
|
|
120
|
-
app.use(middleware.getErrorHandler());
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
this.app = expressServer.build();
|
|
124
|
-
return this;
|
|
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,
|
|
125
101
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* Create and configure the Express application.
|
|
129
|
-
* @param container - The InversifyJS container.
|
|
130
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
131
|
-
* @returns The configured Application instance.
|
|
132
|
-
*/
|
|
133
|
-
create(container, middlewares = []) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
this.container = container;
|
|
136
|
-
this.middlewares = middlewares;
|
|
137
|
-
this.globalPrefix = this.globalPrefix || "/";
|
|
138
|
-
return this;
|
|
102
|
+
expressServer.setConfig((app) => {
|
|
103
|
+
this.configureMiddleware(app, this.middlewares);
|
|
139
104
|
});
|
|
105
|
+
expressServer.setErrorConfig((app) => {
|
|
106
|
+
if (middleware.getErrorHandler()) {
|
|
107
|
+
app.use(middleware.getErrorHandler());
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
this.app = expressServer.build();
|
|
111
|
+
return this;
|
|
140
112
|
}
|
|
141
113
|
/**
|
|
142
114
|
* Start listening on the given port and environment.
|
|
@@ -144,23 +116,18 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
144
116
|
* @param environment - The server environment.
|
|
145
117
|
* @param consoleMessage - Optional message to display in the console.
|
|
146
118
|
*/
|
|
147
|
-
listen(port, environment, consoleMessage) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.environment
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const console = this.container.get(core_1.Console);
|
|
157
|
-
console.messageServer(this.port, this.environment, consoleMessage);
|
|
158
|
-
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
159
|
-
process_1.default.on(signal, this.handleExit.bind(this));
|
|
160
|
-
});
|
|
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));
|
|
161
128
|
});
|
|
162
|
-
yield Promise.resolve(this.postServerInitialization());
|
|
163
129
|
});
|
|
130
|
+
await this.postServerInitialization();
|
|
164
131
|
}
|
|
165
132
|
/**
|
|
166
133
|
* Sets the global route prefix for the application.
|
|
@@ -200,24 +167,15 @@ let ApplicationExpress = class ApplicationExpress extends application_base_1.App
|
|
|
200
167
|
*/
|
|
201
168
|
isDevelopment() {
|
|
202
169
|
if (this.app) {
|
|
203
|
-
return this.app.get("env") === ServerEnvironment.Development;
|
|
170
|
+
return this.app.get("env") === application_express_types_1.ServerEnvironment.Development;
|
|
204
171
|
}
|
|
205
172
|
this.container
|
|
206
173
|
.get(core_1.Logger)
|
|
207
174
|
.error("isDevelopment() method must be called on `PostServerInitialization`", "application");
|
|
208
175
|
return false;
|
|
209
176
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Verifies if the current environment is production.
|
|
212
|
-
*
|
|
213
|
-
* @returns A boolean value indicating whether the current environment is production or not.
|
|
214
|
-
*
|
|
215
|
-
*/
|
|
216
|
-
get ExpressApp() {
|
|
217
|
-
return this.app;
|
|
218
|
-
}
|
|
219
177
|
};
|
|
220
|
-
exports.AppExpress =
|
|
221
|
-
exports.AppExpress =
|
|
222
|
-
(0, inversify_binding_decorators_1.provide)(
|
|
223
|
-
],
|
|
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 = {}));
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.params = exports.
|
|
3
|
+
exports.params = exports.principal = exports.next = exports.cookies = exports.headers = exports.body = exports.query = exports.param = exports.response = exports.request = exports.httpMethod = exports.Delete = exports.Head = exports.Patch = exports.Put = exports.Post = exports.Get = exports.All = exports.controller = exports.injectHttpContext = void 0;
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
7
|
exports.injectHttpContext = (0, inversify_1.inject)(constants_1.TYPE.HttpContext);
|
|
8
|
+
/**
|
|
9
|
+
* Controller decorator to define a new controller
|
|
10
|
+
* @param path route path
|
|
11
|
+
* @param middleware array of middleware to be applied to all routes in the controller
|
|
12
|
+
*/
|
|
8
13
|
function controller(path, ...middleware) {
|
|
9
14
|
return (target) => {
|
|
10
15
|
const currentMetadata = {
|
|
@@ -20,34 +25,99 @@ function controller(path, ...middleware) {
|
|
|
20
25
|
};
|
|
21
26
|
}
|
|
22
27
|
exports.controller = controller;
|
|
23
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Decorator to allow accept all HTTP methods
|
|
30
|
+
* @param path route path, wildcard
|
|
31
|
+
* @param middleware array of middleware to be applied to all routes defined in path logic
|
|
32
|
+
*/
|
|
33
|
+
function All(path, ...middleware) {
|
|
24
34
|
return httpMethod("all", path, ...middleware);
|
|
25
35
|
}
|
|
26
|
-
exports.
|
|
36
|
+
exports.All = All;
|
|
37
|
+
/**
|
|
38
|
+
* Decorator to allow GET HTTP method
|
|
39
|
+
* @param path route path
|
|
40
|
+
* @param middleware array of middleware to be applied to the route
|
|
41
|
+
*/
|
|
27
42
|
function Get(path, ...middleware) {
|
|
28
|
-
return
|
|
43
|
+
return enhancedHttpMethod("get", path, ...middleware);
|
|
29
44
|
}
|
|
30
45
|
exports.Get = Get;
|
|
46
|
+
/**
|
|
47
|
+
* Decorator to allow POST HTTP method
|
|
48
|
+
* @param path route path
|
|
49
|
+
* @param middleware array of middleware to be applied to the route
|
|
50
|
+
*/
|
|
31
51
|
function Post(path, ...middleware) {
|
|
32
52
|
return httpMethod("post", path, ...middleware);
|
|
33
53
|
}
|
|
34
54
|
exports.Post = Post;
|
|
55
|
+
/**
|
|
56
|
+
* Decorator to allow PUT HTTP method
|
|
57
|
+
* @param path route path
|
|
58
|
+
* @param middleware array of middleware to be applied to the route
|
|
59
|
+
*/
|
|
35
60
|
function Put(path, ...middleware) {
|
|
36
|
-
return
|
|
61
|
+
return enhancedHttpMethod("put", path, ...middleware);
|
|
37
62
|
}
|
|
38
63
|
exports.Put = Put;
|
|
64
|
+
/**
|
|
65
|
+
* Decorator to allow PATCH HTTP method
|
|
66
|
+
* @param path route path
|
|
67
|
+
* @param middleware array of middleware to be applied to the route
|
|
68
|
+
*/
|
|
39
69
|
function Patch(path, ...middleware) {
|
|
40
|
-
return
|
|
70
|
+
return enhancedHttpMethod("patch", path, ...middleware);
|
|
41
71
|
}
|
|
42
72
|
exports.Patch = Patch;
|
|
73
|
+
/**
|
|
74
|
+
* Decorator to allow HEAD HTTP method
|
|
75
|
+
* @param path route path
|
|
76
|
+
* @param middleware array of middleware to be applied to the route
|
|
77
|
+
*/
|
|
43
78
|
function Head(path, ...middleware) {
|
|
44
79
|
return httpMethod("head", path, ...middleware);
|
|
45
80
|
}
|
|
46
81
|
exports.Head = Head;
|
|
82
|
+
/**
|
|
83
|
+
* Decorator to allow DELETE HTTP method
|
|
84
|
+
* @param path route path
|
|
85
|
+
* @param middleware array of middleware to be applied to the route
|
|
86
|
+
*/
|
|
47
87
|
function Delete(path, ...middleware) {
|
|
48
|
-
return
|
|
88
|
+
return enhancedHttpMethod("delete", path, ...middleware);
|
|
49
89
|
}
|
|
50
90
|
exports.Delete = Delete;
|
|
91
|
+
function enhancedHttpMethod(method, path, ...middleware) {
|
|
92
|
+
return (target, key) => {
|
|
93
|
+
const metadata = {
|
|
94
|
+
key,
|
|
95
|
+
method,
|
|
96
|
+
middleware,
|
|
97
|
+
path,
|
|
98
|
+
target,
|
|
99
|
+
};
|
|
100
|
+
let metadataList = [];
|
|
101
|
+
if (!Reflect.hasOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor)) {
|
|
102
|
+
Reflect.defineMetadata(constants_1.METADATA_KEY.controllerMethod, metadataList, target.constructor);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
metadataList = Reflect.getOwnMetadata(constants_1.METADATA_KEY.controllerMethod, target.constructor);
|
|
106
|
+
}
|
|
107
|
+
metadataList.push(metadata);
|
|
108
|
+
const paramsInfo = Reflect.getMetadata("design:paramtypes", target, key) || [];
|
|
109
|
+
metadataList.forEach((m) => {
|
|
110
|
+
m.middleware.unshift((req, res, next) => {
|
|
111
|
+
req.params &&
|
|
112
|
+
Object.keys(req.params).forEach((param, idx) => {
|
|
113
|
+
const type = paramsInfo[idx];
|
|
114
|
+
req.params[param] = convertToType(req.params[param], type);
|
|
115
|
+
});
|
|
116
|
+
next();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
}
|
|
51
121
|
function httpMethod(method, path, ...middleware) {
|
|
52
122
|
return (target, key) => {
|
|
53
123
|
const metadata = {
|
|
@@ -68,18 +138,51 @@ function httpMethod(method, path, ...middleware) {
|
|
|
68
138
|
};
|
|
69
139
|
}
|
|
70
140
|
exports.httpMethod = httpMethod;
|
|
71
|
-
|
|
72
|
-
* Parameter
|
|
141
|
+
/**
|
|
142
|
+
* Parameter decorator to inject the request object
|
|
143
|
+
* @returns ParameterDecorator
|
|
73
144
|
*/
|
|
74
145
|
exports.request = paramDecoratorFactory(constants_1.PARAMETER_TYPE.REQUEST);
|
|
146
|
+
/**
|
|
147
|
+
* Parameter decorator to inject the response object
|
|
148
|
+
* @returns ParameterDecorator
|
|
149
|
+
*/
|
|
75
150
|
exports.response = paramDecoratorFactory(constants_1.PARAMETER_TYPE.RESPONSE);
|
|
151
|
+
/**
|
|
152
|
+
* Parameter decorator to inject parameters from the route
|
|
153
|
+
* @returns ParameterDecorator
|
|
154
|
+
*/
|
|
76
155
|
exports.param = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PARAMS);
|
|
156
|
+
/**
|
|
157
|
+
* Parameter decorator to inject query parameters
|
|
158
|
+
* @returns ParameterDecorator
|
|
159
|
+
*/
|
|
77
160
|
exports.query = paramDecoratorFactory(constants_1.PARAMETER_TYPE.QUERY);
|
|
161
|
+
/**
|
|
162
|
+
* Parameter decorator to inject the request body
|
|
163
|
+
* @returns ParameterDecorator
|
|
164
|
+
*/
|
|
78
165
|
exports.body = paramDecoratorFactory(constants_1.PARAMETER_TYPE.BODY);
|
|
166
|
+
/**
|
|
167
|
+
* Parameter decorator to inject the request headers
|
|
168
|
+
* @returns ParameterDecorator
|
|
169
|
+
*/
|
|
79
170
|
exports.headers = paramDecoratorFactory(constants_1.PARAMETER_TYPE.HEADERS);
|
|
171
|
+
/**
|
|
172
|
+
* Parameter decorator to inject the request cookies
|
|
173
|
+
* @returns ParameterDecorator
|
|
174
|
+
*/
|
|
80
175
|
exports.cookies = paramDecoratorFactory(constants_1.PARAMETER_TYPE.COOKIES);
|
|
176
|
+
/**
|
|
177
|
+
* Parameter decorator next function
|
|
178
|
+
* @returns ParameterDecorator
|
|
179
|
+
*/
|
|
81
180
|
exports.next = paramDecoratorFactory(constants_1.PARAMETER_TYPE.NEXT);
|
|
82
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Parameter decorator to inject the principal object obtained from AuthProvider
|
|
183
|
+
* @returns ParameterDecorator
|
|
184
|
+
*/
|
|
185
|
+
exports.principal = paramDecoratorFactory(constants_1.PARAMETER_TYPE.PRINCIPAL);
|
|
83
186
|
function paramDecoratorFactory(parameterType) {
|
|
84
187
|
return (name) => params(parameterType, name);
|
|
85
188
|
}
|
|
@@ -108,3 +211,15 @@ function params(type, parameterName) {
|
|
|
108
211
|
};
|
|
109
212
|
}
|
|
110
213
|
exports.params = params;
|
|
214
|
+
function convertToType(value, type) {
|
|
215
|
+
if (type === Number) {
|
|
216
|
+
return Number(value);
|
|
217
|
+
}
|
|
218
|
+
else if (type === String) {
|
|
219
|
+
return value;
|
|
220
|
+
}
|
|
221
|
+
else if (type === Boolean) {
|
|
222
|
+
return value === "true" || value === "1";
|
|
223
|
+
}
|
|
224
|
+
return value;
|
|
225
|
+
}
|
|
@@ -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,37 +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
|
-
* ExpressHandler Type
|
|
8
|
-
*
|
|
9
|
-
* The ExpressHandler type is a union type that represents various types of Express middleware functions.
|
|
10
|
-
* It can be one of the following types:
|
|
11
|
-
* - express.ErrorRequestHandler: Handles errors in the middleware pipeline.
|
|
12
|
-
* - express.RequestParamHandler: Handles parameters in the middleware pipeline.
|
|
13
|
-
* - express.RequestHandler: General request handler.
|
|
14
|
-
* - undefined: Represents the absence of a handler.
|
|
15
|
-
*/
|
|
16
|
-
type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
17
|
-
/**
|
|
18
|
-
* Enum representing possible server environments.
|
|
19
|
-
*/
|
|
20
|
-
declare enum ServerEnvironment {
|
|
21
|
-
Development = "development",
|
|
22
|
-
Production = "production"
|
|
23
|
-
}
|
|
2
|
+
import { Container } from "inversify";
|
|
3
|
+
import { ApplicationBase } from "./application-express.base";
|
|
4
|
+
import { IWebServer, ServerEnvironment } from "./application-express.types";
|
|
24
5
|
/**
|
|
25
|
-
* The
|
|
26
|
-
* @
|
|
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.
|
|
27
15
|
*/
|
|
28
|
-
declare class
|
|
16
|
+
declare class AppExpress extends ApplicationBase implements IWebServer {
|
|
29
17
|
private app;
|
|
30
18
|
private port;
|
|
31
19
|
private environment;
|
|
32
20
|
private container;
|
|
33
|
-
private middlewares;
|
|
34
21
|
private globalPrefix;
|
|
22
|
+
private middlewares;
|
|
23
|
+
private console;
|
|
35
24
|
protected configureServices(): void | Promise<void>;
|
|
36
25
|
protected postServerInitialization(): void | Promise<void>;
|
|
37
26
|
protected serverShutdown(): void | Promise<void>;
|
|
@@ -39,6 +28,11 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
39
28
|
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
40
29
|
*/
|
|
41
30
|
private handleExit;
|
|
31
|
+
/**
|
|
32
|
+
* Configures the InversifyJS container.
|
|
33
|
+
* @param container - The InversifyJS container.
|
|
34
|
+
*/
|
|
35
|
+
configure(container: Container): Promise<void>;
|
|
42
36
|
/**
|
|
43
37
|
* Configures the Express application with the provided middleware entries.
|
|
44
38
|
* @param app - The Express application instance.
|
|
@@ -52,13 +46,6 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
52
46
|
* @returns The configured Application instance.
|
|
53
47
|
*/
|
|
54
48
|
private init;
|
|
55
|
-
/**
|
|
56
|
-
* Create and configure the Express application.
|
|
57
|
-
* @param container - The InversifyJS container.
|
|
58
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
59
|
-
* @returns The configured Application instance.
|
|
60
|
-
*/
|
|
61
|
-
create(container: Container, middlewares?: Array<ExpressHandler>): Promise<ApplicationExpress>;
|
|
62
49
|
/**
|
|
63
50
|
* Start listening on the given port and environment.
|
|
64
51
|
* @param port - The port number to listen on.
|
|
@@ -94,12 +81,5 @@ declare class ApplicationExpress extends ApplicationBase implements IApplication
|
|
|
94
81
|
* @returns A boolean value indicating whether the current environment is development or not.
|
|
95
82
|
*/
|
|
96
83
|
protected isDevelopment(): boolean;
|
|
97
|
-
/**
|
|
98
|
-
* Verifies if the current environment is production.
|
|
99
|
-
*
|
|
100
|
-
* @returns A boolean value indicating whether the current environment is production or not.
|
|
101
|
-
*
|
|
102
|
-
*/
|
|
103
|
-
get ExpressApp(): express.Application;
|
|
104
84
|
}
|
|
105
|
-
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,23 +1,99 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { PARAMETER_TYPE, HTTP_VERBS_ENUM } from "./constants";
|
|
3
|
-
import type {
|
|
4
|
-
export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<
|
|
3
|
+
import type { HandlerDecorator, Middleware } from "./interfaces";
|
|
4
|
+
export declare const injectHttpContext: (target: import("inversify/lib/annotation/decorator_utils").DecoratorTarget<unknown>, targetKey?: string | symbol, indexOrPropertyDescriptor?: number | TypedPropertyDescriptor<unknown>) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Controller decorator to define a new controller
|
|
7
|
+
* @param path route path
|
|
8
|
+
* @param middleware array of middleware to be applied to all routes in the controller
|
|
9
|
+
*/
|
|
5
10
|
export declare function controller(path: string, ...middleware: Array<Middleware>): (target: NewableFunction) => void;
|
|
6
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Decorator to allow accept all HTTP methods
|
|
13
|
+
* @param path route path, wildcard
|
|
14
|
+
* @param middleware array of middleware to be applied to all routes defined in path logic
|
|
15
|
+
*/
|
|
16
|
+
export declare function All(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
17
|
+
/**
|
|
18
|
+
* Decorator to allow GET HTTP method
|
|
19
|
+
* @param path route path
|
|
20
|
+
* @param middleware array of middleware to be applied to the route
|
|
21
|
+
*/
|
|
7
22
|
export declare function Get(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
23
|
+
/**
|
|
24
|
+
* Decorator to allow POST HTTP method
|
|
25
|
+
* @param path route path
|
|
26
|
+
* @param middleware array of middleware to be applied to the route
|
|
27
|
+
*/
|
|
8
28
|
export declare function Post(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
29
|
+
/**
|
|
30
|
+
* Decorator to allow PUT HTTP method
|
|
31
|
+
* @param path route path
|
|
32
|
+
* @param middleware array of middleware to be applied to the route
|
|
33
|
+
*/
|
|
9
34
|
export declare function Put(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
35
|
+
/**
|
|
36
|
+
* Decorator to allow PATCH HTTP method
|
|
37
|
+
* @param path route path
|
|
38
|
+
* @param middleware array of middleware to be applied to the route
|
|
39
|
+
*/
|
|
10
40
|
export declare function Patch(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
41
|
+
/**
|
|
42
|
+
* Decorator to allow HEAD HTTP method
|
|
43
|
+
* @param path route path
|
|
44
|
+
* @param middleware array of middleware to be applied to the route
|
|
45
|
+
*/
|
|
11
46
|
export declare function Head(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
47
|
+
/**
|
|
48
|
+
* Decorator to allow DELETE HTTP method
|
|
49
|
+
* @param path route path
|
|
50
|
+
* @param middleware array of middleware to be applied to the route
|
|
51
|
+
*/
|
|
12
52
|
export declare function Delete(path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
13
53
|
export declare function httpMethod(method: keyof typeof HTTP_VERBS_ENUM, path: string, ...middleware: Array<Middleware>): HandlerDecorator;
|
|
54
|
+
/**
|
|
55
|
+
* Parameter decorator to inject the request object
|
|
56
|
+
* @returns ParameterDecorator
|
|
57
|
+
*/
|
|
14
58
|
export declare const request: () => ParameterDecorator;
|
|
59
|
+
/**
|
|
60
|
+
* Parameter decorator to inject the response object
|
|
61
|
+
* @returns ParameterDecorator
|
|
62
|
+
*/
|
|
15
63
|
export declare const response: () => ParameterDecorator;
|
|
64
|
+
/**
|
|
65
|
+
* Parameter decorator to inject parameters from the route
|
|
66
|
+
* @returns ParameterDecorator
|
|
67
|
+
*/
|
|
16
68
|
export declare const param: (paramName?: string) => ParameterDecorator;
|
|
69
|
+
/**
|
|
70
|
+
* Parameter decorator to inject query parameters
|
|
71
|
+
* @returns ParameterDecorator
|
|
72
|
+
*/
|
|
17
73
|
export declare const query: (queryParamName?: string) => ParameterDecorator;
|
|
74
|
+
/**
|
|
75
|
+
* Parameter decorator to inject the request body
|
|
76
|
+
* @returns ParameterDecorator
|
|
77
|
+
*/
|
|
18
78
|
export declare const body: () => ParameterDecorator;
|
|
79
|
+
/**
|
|
80
|
+
* Parameter decorator to inject the request headers
|
|
81
|
+
* @returns ParameterDecorator
|
|
82
|
+
*/
|
|
19
83
|
export declare const headers: (headerName?: string) => ParameterDecorator;
|
|
84
|
+
/**
|
|
85
|
+
* Parameter decorator to inject the request cookies
|
|
86
|
+
* @returns ParameterDecorator
|
|
87
|
+
*/
|
|
20
88
|
export declare const cookies: (cookieName?: string) => ParameterDecorator;
|
|
89
|
+
/**
|
|
90
|
+
* Parameter decorator next function
|
|
91
|
+
* @returns ParameterDecorator
|
|
92
|
+
*/
|
|
21
93
|
export declare const next: () => ParameterDecorator;
|
|
22
|
-
|
|
23
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Parameter decorator to inject the principal object obtained from AuthProvider
|
|
96
|
+
* @returns ParameterDecorator
|
|
97
|
+
*/
|
|
98
|
+
export declare const principal: () => ParameterDecorator;
|
|
99
|
+
export declare function params(type: PARAMETER_TYPE, parameterName?: string): ParameterDecorator;
|
|
@@ -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.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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
73
|
"@commitlint/cli": "^18.0.0",
|
|
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": "
|
|
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.2.
|
|
3
|
+
"version": "1.2.2",
|
|
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
73
|
"@commitlint/cli": "^18.0.0",
|
|
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": "
|
|
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
|