From 263d12dce314cc4125a0f5b14eaa0b5e171f165f Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Wed, 13 Sep 2023 16:57:29 -0700 Subject: [PATCH] feat: add expressjs adapter --- README.md | 23 +++++---- package.json | 7 +-- src/adapter-express/application-base.ts | 60 ++++++++++++++++++++++ src/adapter-express/application-express.ts | 2 +- 4 files changed, 76 insertions(+), 16 deletions(-) create mode 100644 src/adapter-express/application-base.ts diff --git a/README.md b/README.md index 53814a1..e2ba7e1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ + [![Contributors][contributors-shield]][contributors-url] [![Forks][forks-shield]][forks-url] [![Stargazers][stars-shield]][stars-url] @@ -44,6 +45,7 @@ + # About The Project 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 -[contributors-shield]: https://img.shields.io/github/contributors/expressots/expressots?style=for-the-badge -[contributors-url]: https://github.com/expressots/expressots/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/expressots/expressots?style=for-the-badge -[forks-url]: https://github.com/expressots/expressots/forks -[stars-shield]: https://img.shields.io/github/stars/expressots/expressots?style=for-the-badge -[stars-url]: https://github.com/expressots/expressots/stargazers -[issues-shield]: https://img.shields.io/github/issues/expressots/expressots?style=for-the-badge -[issues-url]: https://github.com/expressots/expressots/issues -[license-shield]: https://img.shields.io/github/license/expressots/expressots?style=for-the-badge -[license-url]: https://github.com/expressots/expressots/blob/main/LICENSE + +[contributors-shield]: https://img.shields.io/github/contributors/expressots/adapter-express?style=for-the-badge +[contributors-url]: https://github.com/expressots/adapter-express/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/expressots/adapter-express?style=for-the-badge +[forks-url]: https://github.com/expressots/adapter-express/forks +[stars-shield]: https://img.shields.io/github/stars/expressots/adapter-express?style=for-the-badge +[stars-url]: https://github.com/expressots/adapter-express/stargazers +[issues-shield]: https://img.shields.io/github/issues/expressots/adapter-express?style=for-the-badge +[issues-url]: https://github.com/expressots/expressadapter-expressots/issues +[license-shield]: https://img.shields.io/github/license/expressots/adapter-express?style=for-the-badge +[license-url]: https://github.com/expressots/adapter-express/blob/main/LICENSE [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 [linkedin-url]: https://www.linkedin.com/company/expresso-ts/ [product-screenshot]: images/screenshot.png diff --git a/package.json b/package.json index b8b911a..e08d4db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@expressots/adapter-express", - "version": "0.0.1-dev.1", + "version": "1.0.0", "description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)", "author": "", "main": "./lib/cjs/index.js", @@ -76,7 +76,7 @@ "devDependencies": { "@commitlint/cli": "^17.7.1", "@commitlint/config-conventional": "^17.7.0", - "@expressots/core": "latest", + "@expressots/core": "^1.9.0", "@release-it/conventional-changelog": "^7.0.1", "@types/jest": "^29.5.0", "@types/node": "^20.4.9", @@ -90,9 +90,6 @@ "ts-jest": "^29.0.5", "typescript": "^5.2.2" }, - "peerDependencies": { - "@expressots/core": "latest" - }, "release-it": { "git": { "commitMessage": "chore(release): ${version}" diff --git a/src/adapter-express/application-base.ts b/src/adapter-express/application-base.ts new file mode 100644 index 0000000..f15568c --- /dev/null +++ b/src/adapter-express/application-base.ts @@ -0,0 +1,60 @@ +import { provide } from "inversify-binding-decorators"; + +/** + * Abstract class ApplicationBase. + * + * ApplicationBase serves as the foundational structure for building + * server applications. It declares the lifecycle hooks that allow + * subclasses to configure services, handle post-server initialization, + * and perform cleanup when the server is shutting down. Extending + * classes are required to provide implementations for these methods + * to define specific behaviors for their particular use cases. + * + * @example + * class Application extends ApplicationBase { + * protected configureServices() { //... } + * protected postServerInitialization() { //... } + * protected serverShutdown() { //... } + * } + * + * @export + * @abstract + */ +@provide(ApplicationBase) +abstract class ApplicationBase { + /** + * Method to configure services that should be initialized + * before the server starts. It must be implemented by the + * extending class to set up necessary services or configurations. + * Can return a Promise for async configuration. + * + * @abstract + * @returns {void | Promise} + */ + protected abstract configureServices(): void | Promise; + + /** + * Method to configure services or actions that should be executed + * after the server starts. It allows the extending class to perform + * any necessary operations once the server is up and running. + * Can return a Promise for async execution. + * + * @abstract + * @returns {void | Promise} + */ + protected abstract postServerInitialization(): void | Promise; + + /** + * Method to perform any necessary actions or cleanup after the server + * is shutting down. This might include closing database connections, + * stopping background tasks, or other cleanup activities. It provides + * a clean exit point for the server. + * Can return a Promise for async cleanup. + * + * @abstract + * @returns {void | Promise} + */ + protected abstract serverShutdown(): void | Promise; +} + +export { ApplicationBase }; diff --git a/src/adapter-express/application-express.ts b/src/adapter-express/application-express.ts index cdc2b52..8abfee8 100644 --- a/src/adapter-express/application-express.ts +++ b/src/adapter-express/application-express.ts @@ -10,10 +10,10 @@ import { Logger, IHandlebars, RenderTemplateOptions, - ApplicationBase, } from "@expressots/core"; import { IApplicationExpress } from "./application-express.interface"; import { InversifyExpressServer } from "./express-utils/inversify-express-server"; +import { ApplicationBase } from "./application-base"; /** * Enum representing possible server environments.