@expressots/adapter-express 0.0.1-dev.1 → 1.1.0
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/README.md +13 -10
- package/lib/CHANGELOG.md +20 -0
- package/lib/README.md +13 -10
- package/lib/cjs/adapter-express/application-base.js +36 -0
- package/lib/cjs/adapter-express/application-express.js +21 -4
- package/lib/cjs/types/adapter-express/application-base.d.ts +55 -0
- package/lib/cjs/types/adapter-express/application-base.d.ts.map +1 -0
- package/lib/cjs/types/adapter-express/application-express.d.ts +2 -1
- package/lib/cjs/types/adapter-express/application-express.d.ts.map +1 -1
- package/lib/esm/adapter-express/application-base.js +36 -0
- package/lib/esm/adapter-express/application-express.js +21 -4
- package/lib/esm/types/adapter-express/application-base.d.ts +55 -0
- package/lib/esm/types/adapter-express/application-base.d.ts.map +1 -0
- package/lib/esm/types/adapter-express/application-express.d.ts +2 -1
- package/lib/esm/types/adapter-express/application-express.d.ts.map +1 -1
- package/lib/package.json +3 -5
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<a name="readme-top"></a>
|
|
2
2
|
|
|
3
3
|
<!-- PROJECT SHIELDS -->
|
|
4
|
+
|
|
4
5
|
[![Contributors][contributors-shield]][contributors-url]
|
|
5
6
|
[![Forks][forks-shield]][forks-url]
|
|
6
7
|
[![Stargazers][stars-shield]][stars-url]
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
</details>
|
|
45
46
|
|
|
46
47
|
<!-- ABOUT THE PROJECT -->
|
|
48
|
+
|
|
47
49
|
# About The Project
|
|
48
50
|
|
|
49
51
|
ExpressoTS is a [Typescript](https://www.typescriptlang.org/) + [Node.js](https://nodejs.org/en/) lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🐎
|
|
@@ -92,16 +94,17 @@ Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/expres
|
|
|
92
94
|
|
|
93
95
|
<!-- MARKDOWN LINKS & IMAGES -->
|
|
94
96
|
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
95
|
-
|
|
96
|
-
[contributors-
|
|
97
|
-
[
|
|
98
|
-
[forks-
|
|
99
|
-
[
|
|
100
|
-
[stars-
|
|
101
|
-
[
|
|
102
|
-
[issues-
|
|
103
|
-
[
|
|
104
|
-
[license-
|
|
97
|
+
|
|
98
|
+
[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge
|
|
99
|
+
[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors
|
|
100
|
+
[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge
|
|
101
|
+
[forks-url]: https://github.com/expressots/adapter-express/forks
|
|
102
|
+
[stars-shield]: https://img.shields.io/github/stars/expressots/adapter-express?style=for-the-badge
|
|
103
|
+
[stars-url]: https://github.com/expressots/adapter-express/stargazers
|
|
104
|
+
[issues-shield]: https://img.shields.io/github/issues/expressots/adapter-express?style=for-the-badge
|
|
105
|
+
[issues-url]: https://github.com/expressots/expressadapter-expressots/issues
|
|
106
|
+
[license-shield]: https://img.shields.io/github/license/expressots/adapter-express?style=for-the-badge
|
|
107
|
+
[license-url]: https://github.com/expressots/adapter-express/blob/main/LICENSE
|
|
105
108
|
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
|
|
106
109
|
[linkedin-url]: https://www.linkedin.com/company/expresso-ts/
|
|
107
110
|
[product-screenshot]: images/screenshot.png
|
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## 1.1.0 (2023-09-21)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add express as an adapter ([2870790](https://github.com/expressots/adapter-express/commit/28707900882422d0f882e5e18c9bf01457e5640d))
|
|
9
|
+
* add expressjs adapter ([263d12d](https://github.com/expressots/adapter-express/commit/263d12dce314cc4125a0f5b14eaa0b5e171f165f))
|
|
10
|
+
* add peer dependency @expressots/core ([7e8ec24](https://github.com/expressots/adapter-express/commit/7e8ec240fe5caf72a0c371ba317c0d0f52898571))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* add dev 0 package version ([748b62a](https://github.com/expressots/adapter-express/commit/748b62ad101ed6efe4454f9a9f0d684f1118dec6))
|
|
16
|
+
* add dev version ([31baee3](https://github.com/expressots/adapter-express/commit/31baee3e7dd578e14fbc6e1e11eb88ae939e1d28))
|
|
17
|
+
* consume new middlewareConfig base ([bed7b4a](https://github.com/expressots/adapter-express/commit/bed7b4ae682a8c8d55c705e5d2f9b40b136e2af1))
|
|
18
|
+
* expose controller interface ([468818f](https://github.com/expressots/adapter-express/commit/468818fec78e06392cb6024cb4b257edebfd8d38))
|
|
19
|
+
* signature to [@core-v2](https://github.com/core-v2).2 ([4fb5c58](https://github.com/expressots/adapter-express/commit/4fb5c58aa4f011c3aa97803ebc8a80ae72d5b56d))
|
|
20
|
+
* update [@core](https://github.com/core) dependency to altest ([0138609](https://github.com/expressots/adapter-express/commit/01386093f6116e4731270fd17a1250b564387c56))
|
|
21
|
+
* update peer dependecy for [@core](https://github.com/core) ([16a01f3](https://github.com/expressots/adapter-express/commit/16a01f353f3285a68a2038ceb40b6498c64c5a34))
|
|
22
|
+
|
|
3
23
|
## 0.0.1 (2023-09-05)
|
|
4
24
|
|
|
5
25
|
|
package/lib/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<a name="readme-top"></a>
|
|
2
2
|
|
|
3
3
|
<!-- PROJECT SHIELDS -->
|
|
4
|
+
|
|
4
5
|
[![Contributors][contributors-shield]][contributors-url]
|
|
5
6
|
[![Forks][forks-shield]][forks-url]
|
|
6
7
|
[![Stargazers][stars-shield]][stars-url]
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
</details>
|
|
45
46
|
|
|
46
47
|
<!-- ABOUT THE PROJECT -->
|
|
48
|
+
|
|
47
49
|
# About The Project
|
|
48
50
|
|
|
49
51
|
ExpressoTS is a [Typescript](https://www.typescriptlang.org/) + [Node.js](https://nodejs.org/en/) lightweight framework for quick building scalable, easy to read and maintain, server-side applications 🐎
|
|
@@ -92,16 +94,17 @@ Distributed under the MIT License. See [`LICENSE.txt`](https://github.com/expres
|
|
|
92
94
|
|
|
93
95
|
<!-- MARKDOWN LINKS & IMAGES -->
|
|
94
96
|
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
95
|
-
|
|
96
|
-
[contributors-
|
|
97
|
-
[
|
|
98
|
-
[forks-
|
|
99
|
-
[
|
|
100
|
-
[stars-
|
|
101
|
-
[
|
|
102
|
-
[issues-
|
|
103
|
-
[
|
|
104
|
-
[license-
|
|
97
|
+
|
|
98
|
+
[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge
|
|
99
|
+
[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors
|
|
100
|
+
[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge
|
|
101
|
+
[forks-url]: https://github.com/expressots/adapter-express/forks
|
|
102
|
+
[stars-shield]: https://img.shields.io/github/stars/expressots/adapter-express?style=for-the-badge
|
|
103
|
+
[stars-url]: https://github.com/expressots/adapter-express/stargazers
|
|
104
|
+
[issues-shield]: https://img.shields.io/github/issues/expressots/adapter-express?style=for-the-badge
|
|
105
|
+
[issues-url]: https://github.com/expressots/expressadapter-expressots/issues
|
|
106
|
+
[license-shield]: https://img.shields.io/github/license/expressots/adapter-express?style=for-the-badge
|
|
107
|
+
[license-url]: https://github.com/expressots/adapter-express/blob/main/LICENSE
|
|
105
108
|
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
|
|
106
109
|
[linkedin-url]: https://www.linkedin.com/company/expresso-ts/
|
|
107
110
|
[product-screenshot]: images/screenshot.png
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ApplicationBase = void 0;
|
|
10
|
+
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
11
|
+
/**
|
|
12
|
+
* Abstract class ApplicationBase.
|
|
13
|
+
*
|
|
14
|
+
* ApplicationBase serves as the foundational structure for building
|
|
15
|
+
* server applications. It declares the lifecycle hooks that allow
|
|
16
|
+
* subclasses to configure services, handle post-server initialization,
|
|
17
|
+
* and perform cleanup when the server is shutting down. Extending
|
|
18
|
+
* classes are required to provide implementations for these methods
|
|
19
|
+
* to define specific behaviors for their particular use cases.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* class Application extends ApplicationBase {
|
|
23
|
+
* protected configureServices() { //... }
|
|
24
|
+
* protected postServerInitialization() { //... }
|
|
25
|
+
* protected serverShutdown() { //... }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @export
|
|
29
|
+
* @abstract
|
|
30
|
+
*/
|
|
31
|
+
let ApplicationBase = class ApplicationBase {
|
|
32
|
+
};
|
|
33
|
+
exports.ApplicationBase = ApplicationBase;
|
|
34
|
+
exports.ApplicationBase = ApplicationBase = __decorate([
|
|
35
|
+
(0, inversify_binding_decorators_1.provide)(ApplicationBase)
|
|
36
|
+
], ApplicationBase);
|
|
@@ -23,6 +23,7 @@ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
|
23
23
|
const process_1 = __importDefault(require("process"));
|
|
24
24
|
const core_1 = require("@expressots/core");
|
|
25
25
|
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
26
|
+
const application_base_1 = require("./application-base");
|
|
26
27
|
/**
|
|
27
28
|
* Enum representing possible server environments.
|
|
28
29
|
*/
|
|
@@ -35,7 +36,7 @@ var ServerEnvironment;
|
|
|
35
36
|
* The Application class provides a way to configure and manage an Express application.
|
|
36
37
|
* @provide Application
|
|
37
38
|
*/
|
|
38
|
-
let ApplicationExpress = class ApplicationExpress extends
|
|
39
|
+
let ApplicationExpress = class ApplicationExpress extends application_base_1.ApplicationBase {
|
|
39
40
|
constructor() {
|
|
40
41
|
super(...arguments);
|
|
41
42
|
this.middlewares = [];
|
|
@@ -61,11 +62,27 @@ let ApplicationExpress = class ApplicationExpress extends core_1.ApplicationBase
|
|
|
61
62
|
this.container = container;
|
|
62
63
|
yield Promise.resolve(this.configureServices());
|
|
63
64
|
const middleware = container.get(core_1.Middleware);
|
|
64
|
-
|
|
65
|
+
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
66
|
+
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
67
|
+
this.middlewares.push(...middlewares, ...pipeline);
|
|
68
|
+
const allMiddlewareEntries = [...this.middlewares];
|
|
65
69
|
const expressServer = new inversify_express_server_1.InversifyExpressServer(container);
|
|
66
70
|
expressServer.setConfig((app) => {
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
allMiddlewareEntries.forEach((entry) => {
|
|
72
|
+
if (typeof entry === "function") {
|
|
73
|
+
app.use(entry);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const { path, middlewares } = entry;
|
|
77
|
+
middlewares.forEach((middleware) => {
|
|
78
|
+
if (path) {
|
|
79
|
+
app.use(path, middleware);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
app.use(middleware);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
69
86
|
});
|
|
70
87
|
});
|
|
71
88
|
expressServer.setErrorConfig((app) => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class ApplicationBase.
|
|
3
|
+
*
|
|
4
|
+
* ApplicationBase serves as the foundational structure for building
|
|
5
|
+
* server applications. It declares the lifecycle hooks that allow
|
|
6
|
+
* subclasses to configure services, handle post-server initialization,
|
|
7
|
+
* and perform cleanup when the server is shutting down. Extending
|
|
8
|
+
* classes are required to provide implementations for these methods
|
|
9
|
+
* to define specific behaviors for their particular use cases.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* class Application extends ApplicationBase {
|
|
13
|
+
* protected configureServices() { //... }
|
|
14
|
+
* protected postServerInitialization() { //... }
|
|
15
|
+
* protected serverShutdown() { //... }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @export
|
|
19
|
+
* @abstract
|
|
20
|
+
*/
|
|
21
|
+
declare abstract class ApplicationBase {
|
|
22
|
+
/**
|
|
23
|
+
* Method to configure services that should be initialized
|
|
24
|
+
* before the server starts. It must be implemented by the
|
|
25
|
+
* extending class to set up necessary services or configurations.
|
|
26
|
+
* Can return a Promise for async configuration.
|
|
27
|
+
*
|
|
28
|
+
* @abstract
|
|
29
|
+
* @returns {void | Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
protected abstract configureServices(): void | Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Method to configure services or actions that should be executed
|
|
34
|
+
* after the server starts. It allows the extending class to perform
|
|
35
|
+
* any necessary operations once the server is up and running.
|
|
36
|
+
* Can return a Promise for async execution.
|
|
37
|
+
*
|
|
38
|
+
* @abstract
|
|
39
|
+
* @returns {void | Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
protected abstract postServerInitialization(): void | Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Method to perform any necessary actions or cleanup after the server
|
|
44
|
+
* is shutting down. This might include closing database connections,
|
|
45
|
+
* stopping background tasks, or other cleanup activities. It provides
|
|
46
|
+
* a clean exit point for the server.
|
|
47
|
+
* Can return a Promise for async cleanup.
|
|
48
|
+
*
|
|
49
|
+
* @abstract
|
|
50
|
+
* @returns {void | Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
protected abstract serverShutdown(): void | Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export { ApplicationBase };
|
|
55
|
+
//# sourceMappingURL=application-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-base.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-base.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,uBACe,eAAe;IAC5B;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE5D;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,wBAAwB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnE;;;;;;;;;OASG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAC1D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import { Container } from "inversify";
|
|
3
|
-
import { IApplicationMessageToConsole, RenderTemplateOptions
|
|
3
|
+
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
4
4
|
import { IApplicationExpress } from "./application-express.interface";
|
|
5
|
+
import { ApplicationBase } from "./application-base";
|
|
5
6
|
/**
|
|
6
7
|
* Enum representing possible server environments.
|
|
7
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-express.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAEL,4BAA4B,EAK5B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"application-express.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAEL,4BAA4B,EAK5B,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAarD;;GAEG;AACH,aAAK,iBAAiB;IACpB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,cACM,kBAAmB,SAAQ,eAAgB,YAAW,mBAAmB;IAC7E,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,WAAW,CAA6B;IAEhD,SAAS,CAAC,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IACnD,SAAS,CAAC,wBAAwB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1D,SAAS,CAAC,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhD;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACU,MAAM,CACjB,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAM,GAC9C,OAAO,CAAC,kBAAkB,CAAC;IA0C9B;;;;;OAKG;IACU,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,EAC9B,cAAc,CAAC,EAAE,4BAA4B,GAC5C,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;;;;;;;;OAUG;IACI,SAAS,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IASnE;;;;OAIG;IACH,SAAS,CAAC,aAAa,IAAI,OAAO;IAWlC;;;;;OAKG;IACH,IAAW,UAAU,IAAI,OAAO,CAAC,WAAW,CAE3C;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,UAAU,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ApplicationBase = void 0;
|
|
10
|
+
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
11
|
+
/**
|
|
12
|
+
* Abstract class ApplicationBase.
|
|
13
|
+
*
|
|
14
|
+
* ApplicationBase serves as the foundational structure for building
|
|
15
|
+
* server applications. It declares the lifecycle hooks that allow
|
|
16
|
+
* subclasses to configure services, handle post-server initialization,
|
|
17
|
+
* and perform cleanup when the server is shutting down. Extending
|
|
18
|
+
* classes are required to provide implementations for these methods
|
|
19
|
+
* to define specific behaviors for their particular use cases.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* class Application extends ApplicationBase {
|
|
23
|
+
* protected configureServices() { //... }
|
|
24
|
+
* protected postServerInitialization() { //... }
|
|
25
|
+
* protected serverShutdown() { //... }
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* @export
|
|
29
|
+
* @abstract
|
|
30
|
+
*/
|
|
31
|
+
let ApplicationBase = class ApplicationBase {
|
|
32
|
+
};
|
|
33
|
+
exports.ApplicationBase = ApplicationBase;
|
|
34
|
+
exports.ApplicationBase = ApplicationBase = __decorate([
|
|
35
|
+
(0, inversify_binding_decorators_1.provide)(ApplicationBase)
|
|
36
|
+
], ApplicationBase);
|
|
@@ -14,6 +14,7 @@ const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
|
14
14
|
const process_1 = __importDefault(require("process"));
|
|
15
15
|
const core_1 = require("@expressots/core");
|
|
16
16
|
const inversify_express_server_1 = require("./express-utils/inversify-express-server");
|
|
17
|
+
const application_base_1 = require("./application-base");
|
|
17
18
|
/**
|
|
18
19
|
* Enum representing possible server environments.
|
|
19
20
|
*/
|
|
@@ -26,7 +27,7 @@ var ServerEnvironment;
|
|
|
26
27
|
* The Application class provides a way to configure and manage an Express application.
|
|
27
28
|
* @provide Application
|
|
28
29
|
*/
|
|
29
|
-
let ApplicationExpress = class ApplicationExpress extends
|
|
30
|
+
let ApplicationExpress = class ApplicationExpress extends application_base_1.ApplicationBase {
|
|
30
31
|
app;
|
|
31
32
|
port;
|
|
32
33
|
environment;
|
|
@@ -52,11 +53,27 @@ let ApplicationExpress = class ApplicationExpress extends core_1.ApplicationBase
|
|
|
52
53
|
this.container = container;
|
|
53
54
|
await Promise.resolve(this.configureServices());
|
|
54
55
|
const middleware = container.get(core_1.Middleware);
|
|
55
|
-
|
|
56
|
+
const sortedMiddlewarePipeline = middleware.getMiddlewarePipeline();
|
|
57
|
+
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
58
|
+
this.middlewares.push(...middlewares, ...pipeline);
|
|
59
|
+
const allMiddlewareEntries = [...this.middlewares];
|
|
56
60
|
const expressServer = new inversify_express_server_1.InversifyExpressServer(container);
|
|
57
61
|
expressServer.setConfig((app) => {
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
allMiddlewareEntries.forEach((entry) => {
|
|
63
|
+
if (typeof entry === "function") {
|
|
64
|
+
app.use(entry);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
const { path, middlewares } = entry;
|
|
68
|
+
middlewares.forEach((middleware) => {
|
|
69
|
+
if (path) {
|
|
70
|
+
app.use(path, middleware);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
app.use(middleware);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
60
77
|
});
|
|
61
78
|
});
|
|
62
79
|
expressServer.setErrorConfig((app) => {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract class ApplicationBase.
|
|
3
|
+
*
|
|
4
|
+
* ApplicationBase serves as the foundational structure for building
|
|
5
|
+
* server applications. It declares the lifecycle hooks that allow
|
|
6
|
+
* subclasses to configure services, handle post-server initialization,
|
|
7
|
+
* and perform cleanup when the server is shutting down. Extending
|
|
8
|
+
* classes are required to provide implementations for these methods
|
|
9
|
+
* to define specific behaviors for their particular use cases.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* class Application extends ApplicationBase {
|
|
13
|
+
* protected configureServices() { //... }
|
|
14
|
+
* protected postServerInitialization() { //... }
|
|
15
|
+
* protected serverShutdown() { //... }
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* @export
|
|
19
|
+
* @abstract
|
|
20
|
+
*/
|
|
21
|
+
declare abstract class ApplicationBase {
|
|
22
|
+
/**
|
|
23
|
+
* Method to configure services that should be initialized
|
|
24
|
+
* before the server starts. It must be implemented by the
|
|
25
|
+
* extending class to set up necessary services or configurations.
|
|
26
|
+
* Can return a Promise for async configuration.
|
|
27
|
+
*
|
|
28
|
+
* @abstract
|
|
29
|
+
* @returns {void | Promise<void>}
|
|
30
|
+
*/
|
|
31
|
+
protected abstract configureServices(): void | Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Method to configure services or actions that should be executed
|
|
34
|
+
* after the server starts. It allows the extending class to perform
|
|
35
|
+
* any necessary operations once the server is up and running.
|
|
36
|
+
* Can return a Promise for async execution.
|
|
37
|
+
*
|
|
38
|
+
* @abstract
|
|
39
|
+
* @returns {void | Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
protected abstract postServerInitialization(): void | Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Method to perform any necessary actions or cleanup after the server
|
|
44
|
+
* is shutting down. This might include closing database connections,
|
|
45
|
+
* stopping background tasks, or other cleanup activities. It provides
|
|
46
|
+
* a clean exit point for the server.
|
|
47
|
+
* Can return a Promise for async cleanup.
|
|
48
|
+
*
|
|
49
|
+
* @abstract
|
|
50
|
+
* @returns {void | Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
protected abstract serverShutdown(): void | Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export { ApplicationBase };
|
|
55
|
+
//# sourceMappingURL=application-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-base.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-base.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,uBACe,eAAe;IAC5B;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE5D;;;;;;;;OAQG;IACH,SAAS,CAAC,QAAQ,CAAC,wBAAwB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEnE;;;;;;;;;OASG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAC1D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import { Container } from "inversify";
|
|
3
|
-
import { IApplicationMessageToConsole, RenderTemplateOptions
|
|
3
|
+
import { IApplicationMessageToConsole, RenderTemplateOptions } from "@expressots/core";
|
|
4
4
|
import { IApplicationExpress } from "./application-express.interface";
|
|
5
|
+
import { ApplicationBase } from "./application-base";
|
|
5
6
|
/**
|
|
6
7
|
* Enum representing possible server environments.
|
|
7
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"application-express.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAEL,4BAA4B,EAK5B,qBAAqB,
|
|
1
|
+
{"version":3,"file":"application-express.d.ts","sourceRoot":"","sources":["../../../../src/adapter-express/application-express.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAEL,4BAA4B,EAK5B,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAarD;;GAEG;AACH,aAAK,iBAAiB;IACpB,WAAW,gBAAgB;IAC3B,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,cACM,kBAAmB,SAAQ,eAAgB,YAAW,mBAAmB;IAC7E,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,WAAW,CAA6B;IAEhD,SAAS,CAAC,iBAAiB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IACnD,SAAS,CAAC,wBAAwB,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1D,SAAS,CAAC,cAAc,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhD;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACU,MAAM,CACjB,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAM,GAC9C,OAAO,CAAC,kBAAkB,CAAC;IA0C9B;;;;;OAKG;IACU,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,EAC9B,cAAc,CAAC,EAAE,4BAA4B,GAC5C,OAAO,CAAC,IAAI,CAAC;IAmBhB;;;;;;;;;;OAUG;IACI,SAAS,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IASnE;;;;OAIG;IACH,SAAS,CAAC,aAAa,IAAI,OAAO;IAWlC;;;;;OAKG;IACH,IAAW,UAAU,IAAI,OAAO,CAAC,WAAW,CAE3C;CACF;AAED,OAAO,EAAE,kBAAkB,IAAI,UAAU,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -76,8 +76,9 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@commitlint/cli": "^17.7.1",
|
|
78
78
|
"@commitlint/config-conventional": "^17.7.0",
|
|
79
|
-
"@expressots/core": "
|
|
79
|
+
"@expressots/core": "^2.2.0",
|
|
80
80
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
81
|
+
"@types/express": "^4.17.17",
|
|
81
82
|
"@types/jest": "^29.5.0",
|
|
82
83
|
"@types/node": "^20.4.9",
|
|
83
84
|
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
@@ -90,9 +91,6 @@
|
|
|
90
91
|
"ts-jest": "^29.0.5",
|
|
91
92
|
"typescript": "^5.2.2"
|
|
92
93
|
},
|
|
93
|
-
"peerDependencies": {
|
|
94
|
-
"@expressots/core": "latest"
|
|
95
|
-
},
|
|
96
94
|
"release-it": {
|
|
97
95
|
"git": {
|
|
98
96
|
"commitMessage": "chore(release): ${version}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -76,8 +76,9 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@commitlint/cli": "^17.7.1",
|
|
78
78
|
"@commitlint/config-conventional": "^17.7.0",
|
|
79
|
-
"@expressots/core": "
|
|
79
|
+
"@expressots/core": "^2.2.0",
|
|
80
80
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
81
|
+
"@types/express": "^4.17.17",
|
|
81
82
|
"@types/jest": "^29.5.0",
|
|
82
83
|
"@types/node": "^20.4.9",
|
|
83
84
|
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
@@ -90,9 +91,6 @@
|
|
|
90
91
|
"ts-jest": "^29.0.5",
|
|
91
92
|
"typescript": "^5.2.2"
|
|
92
93
|
},
|
|
93
|
-
"peerDependencies": {
|
|
94
|
-
"@expressots/core": "latest"
|
|
95
|
-
},
|
|
96
94
|
"release-it": {
|
|
97
95
|
"git": {
|
|
98
96
|
"commitMessage": "chore(release): ${version}"
|