@expressots/adapter-express 3.0.0-beta.1 → 3.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CHANGELOG.md +18 -0
- package/lib/cjs/adapter-express/index.js +1 -0
- package/lib/cjs/adapter-express/micro-api/application-express-micro-container.js +51 -0
- package/lib/cjs/adapter-express/micro-api/application-express-micro-route.js +101 -0
- package/lib/cjs/adapter-express/micro-api/application-express-micro.js +177 -0
- package/lib/cjs/adapter-express/micro-api/index.js +5 -0
- package/lib/cjs/types/adapter-express/index.d.ts +1 -0
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-container.d.ts +47 -0
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro-route.d.ts +93 -0
- package/lib/cjs/types/adapter-express/micro-api/application-express-micro.d.ts +79 -0
- package/lib/cjs/types/adapter-express/micro-api/index.d.ts +1 -0
- package/lib/package.json +2 -2
- package/package.json +2 -2
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [3.0.0-beta.2](https://github.com/expressots/adapter-express/compare/3.0.0-beta.1...3.0.0) (2024-11-24)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
- add getHttpServer method and update listen method to return a promise ([82895c2](https://github.com/expressots/adapter-express/commit/82895c279c6103c7e96ee01810030d656142d509))
|
|
6
|
+
- add unit tests for various utility functions and application lifecycle methods ([d3d91b0](https://github.com/expressots/adapter-express/commit/d3d91b05205460eac1399c991dd25b06d942d93d))
|
|
7
|
+
- add unit tests IOC container addScoped, addSingleton, addTransient, get ([e3028fa](https://github.com/expressots/adapter-express/commit/e3028fa3bd7e0c57835dbd200f0621d3a9a27a1e))
|
|
8
|
+
- implement Express Micro API adapter with route management and IoC container ([1720378](https://github.com/expressots/adapter-express/commit/1720378011603b1d0b8806e92f6b469067be577a))
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
- exclude dependency injection files from coverage collection ([e8fdd90](https://github.com/expressots/adapter-express/commit/e8fdd908258b83f35d1121c1000b45039f6fd960))
|
|
13
|
+
- update @expressots/core dependency version to use semantic versioning ([2130e4d](https://github.com/expressots/adapter-express/commit/2130e4d850c35ad35855c7def32fb86ddeffca64))
|
|
14
|
+
|
|
15
|
+
### Code Refactoring
|
|
16
|
+
|
|
17
|
+
- clean up whitespace and formatting in various test files ([5be0404](https://github.com/expressots/adapter-express/commit/5be0404cec12363d40a1181c7209527369422cf3))
|
|
18
|
+
|
|
1
19
|
## [3.0.0-beta.1](https://github.com/expressots/adapter-express/compare/1.8.2...3.0.0) (2024-11-18)
|
|
2
20
|
|
|
3
21
|
### Features
|
|
@@ -18,6 +18,7 @@ exports.RenderEngine = exports.AppExpress = void 0;
|
|
|
18
18
|
__exportStar(require("./express-utils"), exports);
|
|
19
19
|
var application_express_1 = require("./application-express");
|
|
20
20
|
Object.defineProperty(exports, "AppExpress", { enumerable: true, get: function () { return application_express_1.AppExpress; } });
|
|
21
|
+
__exportStar(require("./micro-api"), exports);
|
|
21
22
|
var shared_1 = require("@expressots/shared");
|
|
22
23
|
Object.defineProperty(exports, "RenderEngine", { enumerable: true, get: function () { return shared_1.RenderEngine; } });
|
|
23
24
|
__exportStar(require("./render"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IOC = void 0;
|
|
4
|
+
const core_1 = require("@expressots/core");
|
|
5
|
+
/**
|
|
6
|
+
* Inversion of Control Container
|
|
7
|
+
* @public API
|
|
8
|
+
*/
|
|
9
|
+
class IOC {
|
|
10
|
+
constructor(containerOptions) {
|
|
11
|
+
this.container = new core_1.Container(containerOptions);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Add a singleton to the container
|
|
15
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
16
|
+
* @param concrete - The concrete class if identifier is provided
|
|
17
|
+
* @public API
|
|
18
|
+
*/
|
|
19
|
+
addSingleton(concrete) {
|
|
20
|
+
this.container.bind(concrete).toSelf().inSingletonScope();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Add a transient to the container
|
|
24
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
25
|
+
* @param concrete - The concrete class if identifier is provided
|
|
26
|
+
* @public API
|
|
27
|
+
*/
|
|
28
|
+
addTransient(concrete) {
|
|
29
|
+
this.container.bind(concrete).toSelf().inTransientScope();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Add a scoped to the container
|
|
33
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
34
|
+
* @param concrete - The concrete class if identifier is provided
|
|
35
|
+
* @public API
|
|
36
|
+
*/
|
|
37
|
+
addScoped(concrete) {
|
|
38
|
+
this.container.bind(concrete).toSelf().inRequestScope();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get an instance from the container
|
|
42
|
+
* @param identifier - The identifier for the instance
|
|
43
|
+
* @returns The resolved instance
|
|
44
|
+
* @public API
|
|
45
|
+
*/
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
get(identifier) {
|
|
48
|
+
return this.container.get(identifier);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.IOC = IOC;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Route = void 0;
|
|
4
|
+
const core_1 = require("@expressots/core");
|
|
5
|
+
class Route {
|
|
6
|
+
constructor(app) {
|
|
7
|
+
this.logger = new core_1.Logger();
|
|
8
|
+
this.routes = [];
|
|
9
|
+
this.globalPrefix = "";
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Set the global route prefix
|
|
14
|
+
* @param prefix
|
|
15
|
+
* @public API
|
|
16
|
+
*/
|
|
17
|
+
setGlobalRoutePrefix(prefix) {
|
|
18
|
+
this.globalPrefix = prefix;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Define a route
|
|
22
|
+
* @param method - HTTP method
|
|
23
|
+
* @param path - Route path
|
|
24
|
+
* @param handler - Route handler
|
|
25
|
+
* @param middleware - Route middleware
|
|
26
|
+
* @public API
|
|
27
|
+
*/
|
|
28
|
+
define(method, path, handler, ...middleware) {
|
|
29
|
+
const normalizedPath = `${this.globalPrefix.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
30
|
+
this.routes.push({ method, path: normalizedPath, handler, middleware });
|
|
31
|
+
this.logger.info(`Route ${method.toUpperCase()} '${normalizedPath}' added.`, "Route");
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Define a GET route
|
|
35
|
+
* @param path - Route path
|
|
36
|
+
* @param handler - Route handler
|
|
37
|
+
* @param middleware - Route middleware
|
|
38
|
+
* @public API
|
|
39
|
+
*/
|
|
40
|
+
get(path, handler, ...middleware) {
|
|
41
|
+
this.define("get", path, handler, ...middleware);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Define a POST route
|
|
45
|
+
* @param path - Route path
|
|
46
|
+
* @param handler - Route handler
|
|
47
|
+
* @param middleware - Route middleware
|
|
48
|
+
* @public API
|
|
49
|
+
*/
|
|
50
|
+
post(path, handler, ...middleware) {
|
|
51
|
+
this.define("post", path, handler, ...middleware);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Define a PUT route
|
|
55
|
+
* @param path - Route path
|
|
56
|
+
* @param handler - Route handler
|
|
57
|
+
* @param middleware - Route middleware
|
|
58
|
+
* @public API
|
|
59
|
+
*/
|
|
60
|
+
put(path, handler, ...middleware) {
|
|
61
|
+
this.define("put", path, handler, ...middleware);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Define a DELETE route
|
|
65
|
+
* @param path - Route path
|
|
66
|
+
* @param handler - Route handler
|
|
67
|
+
* @param middleware - Route middleware
|
|
68
|
+
* @public API
|
|
69
|
+
*/
|
|
70
|
+
delete(path, handler, ...middleware) {
|
|
71
|
+
this.define("delete", path, handler, ...middleware);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Define a PATCH route
|
|
75
|
+
* @param path - Route path
|
|
76
|
+
* @param handler - Route handler
|
|
77
|
+
* @param middleware - Route middleware
|
|
78
|
+
* @public API
|
|
79
|
+
*/
|
|
80
|
+
patch(path, handler, ...middleware) {
|
|
81
|
+
this.define("patch", path, handler, ...middleware);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Apply the routes to the Express application
|
|
85
|
+
*/
|
|
86
|
+
applyRoutes() {
|
|
87
|
+
this.routes.forEach(({ method, path, handler, middleware }) => {
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
|
+
this.app[method](path, ...middleware, handler);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the routes
|
|
94
|
+
* @returns Array of route definitions
|
|
95
|
+
* @public API
|
|
96
|
+
*/
|
|
97
|
+
get Routes() {
|
|
98
|
+
return this.routes;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Route = Route;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMicroAPI = createMicroAPI;
|
|
7
|
+
const core_1 = require("@expressots/core");
|
|
8
|
+
const shared_1 = require("@expressots/shared");
|
|
9
|
+
const express_1 = __importDefault(require("express"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const application_express_micro_container_1 = require("./application-express-micro-container");
|
|
12
|
+
const application_express_micro_route_1 = require("./application-express-micro-route");
|
|
13
|
+
class AppExpressMicro {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.logger = new core_1.Logger();
|
|
16
|
+
this.globalPrefix = "/";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handle the exit of the server
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
handleExit() {
|
|
23
|
+
this.logger.info("Server shutting down.", "MicroAPI");
|
|
24
|
+
process.exit(0);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Configure the middleware for the application
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
configureMiddleware() {
|
|
31
|
+
const sortedMiddlewarePipeline = this.middlewareManager.getMiddlewarePipeline();
|
|
32
|
+
const pipeline = sortedMiddlewarePipeline.map((entry) => entry.middleware);
|
|
33
|
+
for (const entry of pipeline) {
|
|
34
|
+
if (typeof entry === "function") {
|
|
35
|
+
this.app.use(entry);
|
|
36
|
+
}
|
|
37
|
+
else if (entry.middlewares) {
|
|
38
|
+
const { path, middlewares } = entry;
|
|
39
|
+
for (const mid of middlewares) {
|
|
40
|
+
if (path) {
|
|
41
|
+
this.app.use(path, mid);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.app.use(mid);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set the global route prefix
|
|
52
|
+
* @param prefix - The global route prefix
|
|
53
|
+
* @public API
|
|
54
|
+
*/
|
|
55
|
+
setGlobalRoutePrefix(prefix) {
|
|
56
|
+
this.globalPrefix = prefix;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initialize the environment for the application
|
|
60
|
+
* @param environment - The environment to initialize
|
|
61
|
+
* @param options - Options for the environment initialization
|
|
62
|
+
* @public API
|
|
63
|
+
*/
|
|
64
|
+
initEnvironment(environment, options) {
|
|
65
|
+
this.environment = environment;
|
|
66
|
+
if (options === undefined) {
|
|
67
|
+
(0, shared_1.config)({ path: ".env" });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
if (!options.env[environment]) {
|
|
71
|
+
this.logger.error(`Environment configuration for [${environment}] does not exist.`, "adapter-express");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const envFileName = options.env[environment];
|
|
76
|
+
if (!fs_1.default.existsSync(envFileName)) {
|
|
77
|
+
this.logger.error(`Environment file [${envFileName}] does not exist.`, "adapter-express");
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
(0, shared_1.config)({ path: envFileName });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the Middleware instance
|
|
88
|
+
* @returns IMiddleware
|
|
89
|
+
* @public API
|
|
90
|
+
*/
|
|
91
|
+
get Middleware() {
|
|
92
|
+
return this.middlewareManager;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the Route instance
|
|
96
|
+
* @returns IRoute
|
|
97
|
+
* @public API
|
|
98
|
+
*/
|
|
99
|
+
get Route() {
|
|
100
|
+
return this.routeManager;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the Container instance
|
|
104
|
+
* @returns IIOC
|
|
105
|
+
* @public API
|
|
106
|
+
*/
|
|
107
|
+
get Container() {
|
|
108
|
+
return this.container;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the Express HTTP Server instance
|
|
112
|
+
* @returns express.Application
|
|
113
|
+
* @public API
|
|
114
|
+
*/
|
|
115
|
+
getHttpServer() {
|
|
116
|
+
return this.app;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a new instance of the Express Micro API adapter
|
|
120
|
+
* @param config - Configuration options
|
|
121
|
+
* @returns ICreateMicroAPI
|
|
122
|
+
* @public API
|
|
123
|
+
*/
|
|
124
|
+
create(config) {
|
|
125
|
+
this.app = (0, express_1.default)();
|
|
126
|
+
this.routeManager = new application_express_micro_route_1.Route(this.app);
|
|
127
|
+
this.container = new application_express_micro_container_1.IOC(config?.containerOptions);
|
|
128
|
+
this.middlewareManager = new core_1.Middleware();
|
|
129
|
+
this.environment = "development";
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Build the Web Server Micro API
|
|
134
|
+
* @returns IWebServerMicroAPI
|
|
135
|
+
* @public API
|
|
136
|
+
*/
|
|
137
|
+
build() {
|
|
138
|
+
this.routeManager.setGlobalRoutePrefix(this.globalPrefix);
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Listen for incoming requests
|
|
143
|
+
* @param port - The port to listen on
|
|
144
|
+
* @param appInfo - Information about the application
|
|
145
|
+
* @public API
|
|
146
|
+
*/
|
|
147
|
+
async listen(port, appInfo) {
|
|
148
|
+
const logger = new core_1.Logger();
|
|
149
|
+
this.port = typeof port === "string" ? parseInt(port, 10) : port || 3000;
|
|
150
|
+
this.configureMiddleware();
|
|
151
|
+
this.routeManager.applyRoutes();
|
|
152
|
+
if (this.Middleware.getErrorHandler()) {
|
|
153
|
+
this.app.use(this.Middleware.getErrorHandler());
|
|
154
|
+
}
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
this.app.listen(this.port, () => {
|
|
157
|
+
const appInfoNormalized = appInfo ? `${appInfo?.appName} - ${appInfo?.appVersion} ` : "";
|
|
158
|
+
logger.info(`${appInfoNormalized}[${this.port}:${this.environment}]`, "MicroAPI");
|
|
159
|
+
["SIGTERM", "SIGHUP", "SIGBREAK", "SIGQUIT", "SIGINT"].forEach((signal) => {
|
|
160
|
+
process.on(signal, this.handleExit.bind(this));
|
|
161
|
+
});
|
|
162
|
+
resolve();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Create a new instance of the Express Micro API adapter
|
|
169
|
+
* @param config - Configuration options
|
|
170
|
+
* @returns ICreateMicroAPI
|
|
171
|
+
* @public API
|
|
172
|
+
*/
|
|
173
|
+
function createMicroAPI(config) {
|
|
174
|
+
const microAPI = new AppExpressMicro();
|
|
175
|
+
const create = microAPI.create.bind(microAPI);
|
|
176
|
+
return create(config);
|
|
177
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMicroAPI = void 0;
|
|
4
|
+
var application_express_micro_1 = require("./application-express-micro");
|
|
5
|
+
Object.defineProperty(exports, "createMicroAPI", { enumerable: true, get: function () { return application_express_micro_1.createMicroAPI; } });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./express-utils";
|
|
2
2
|
export { AppExpress } from "./application-express";
|
|
3
|
+
export * from "./micro-api";
|
|
3
4
|
export { IWebServerPublic, IWebServer, IWebServerConstructor, Environment, IEnvironment, RenderEngine, } from "@expressots/shared";
|
|
4
5
|
export * from "./render";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { interfaces } from "@expressots/core";
|
|
2
|
+
/**
|
|
3
|
+
* Inversion of Control Container interface
|
|
4
|
+
* @public API
|
|
5
|
+
*/
|
|
6
|
+
export interface IIOC {
|
|
7
|
+
addSingleton<T>(concrete: interfaces.Newable<T>): void;
|
|
8
|
+
addTransient<T>(concrete: interfaces.Newable<T>): void;
|
|
9
|
+
addScoped<T>(concrete: interfaces.Newable<T>): void;
|
|
10
|
+
get<I>(identifier: interfaces.ServiceIdentifier<I>): I;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Inversion of Control Container
|
|
14
|
+
* @public API
|
|
15
|
+
*/
|
|
16
|
+
export declare class IOC {
|
|
17
|
+
private container;
|
|
18
|
+
constructor(containerOptions?: interfaces.ContainerOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Add a singleton to the container
|
|
21
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
22
|
+
* @param concrete - The concrete class if identifier is provided
|
|
23
|
+
* @public API
|
|
24
|
+
*/
|
|
25
|
+
addSingleton<T>(concrete: interfaces.Newable<T>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Add a transient to the container
|
|
28
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
29
|
+
* @param concrete - The concrete class if identifier is provided
|
|
30
|
+
* @public API
|
|
31
|
+
*/
|
|
32
|
+
addTransient<T>(concrete: interfaces.Newable<T>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Add a scoped to the container
|
|
35
|
+
* @param identifierOrConcrete - The identifier or concrete class
|
|
36
|
+
* @param concrete - The concrete class if identifier is provided
|
|
37
|
+
* @public API
|
|
38
|
+
*/
|
|
39
|
+
addScoped<T>(concrete: interfaces.Newable<T>): void;
|
|
40
|
+
/**
|
|
41
|
+
* Get an instance from the container
|
|
42
|
+
* @param identifier - The identifier for the instance
|
|
43
|
+
* @returns The resolved instance
|
|
44
|
+
* @public API
|
|
45
|
+
*/
|
|
46
|
+
get(identifier: interfaces.ServiceIdentifier): any;
|
|
47
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { Middleware } from "../express-utils/interfaces";
|
|
3
|
+
type RouteDefinition = {
|
|
4
|
+
method: "get" | "post" | "put" | "patch" | "delete";
|
|
5
|
+
path: string;
|
|
6
|
+
handler: express.RequestHandler;
|
|
7
|
+
middleware: Array<Middleware>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Route manager for Express Micro API adapter
|
|
11
|
+
* @public API
|
|
12
|
+
*/
|
|
13
|
+
export interface IRoute {
|
|
14
|
+
define(method: "get" | "post" | "put" | "delete" | "patch", path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
15
|
+
get(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
16
|
+
post(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
17
|
+
put(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
18
|
+
delete(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
19
|
+
patch(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class Route implements IRoute {
|
|
22
|
+
private logger;
|
|
23
|
+
private routes;
|
|
24
|
+
private app;
|
|
25
|
+
private globalPrefix;
|
|
26
|
+
constructor(app: express.Application);
|
|
27
|
+
/**
|
|
28
|
+
* Set the global route prefix
|
|
29
|
+
* @param prefix
|
|
30
|
+
* @public API
|
|
31
|
+
*/
|
|
32
|
+
setGlobalRoutePrefix(prefix: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Define a route
|
|
35
|
+
* @param method - HTTP method
|
|
36
|
+
* @param path - Route path
|
|
37
|
+
* @param handler - Route handler
|
|
38
|
+
* @param middleware - Route middleware
|
|
39
|
+
* @public API
|
|
40
|
+
*/
|
|
41
|
+
define(method: "get" | "post" | "put" | "delete" | "patch", path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Define a GET route
|
|
44
|
+
* @param path - Route path
|
|
45
|
+
* @param handler - Route handler
|
|
46
|
+
* @param middleware - Route middleware
|
|
47
|
+
* @public API
|
|
48
|
+
*/
|
|
49
|
+
get(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Define a POST route
|
|
52
|
+
* @param path - Route path
|
|
53
|
+
* @param handler - Route handler
|
|
54
|
+
* @param middleware - Route middleware
|
|
55
|
+
* @public API
|
|
56
|
+
*/
|
|
57
|
+
post(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Define a PUT route
|
|
60
|
+
* @param path - Route path
|
|
61
|
+
* @param handler - Route handler
|
|
62
|
+
* @param middleware - Route middleware
|
|
63
|
+
* @public API
|
|
64
|
+
*/
|
|
65
|
+
put(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
66
|
+
/**
|
|
67
|
+
* Define a DELETE route
|
|
68
|
+
* @param path - Route path
|
|
69
|
+
* @param handler - Route handler
|
|
70
|
+
* @param middleware - Route middleware
|
|
71
|
+
* @public API
|
|
72
|
+
*/
|
|
73
|
+
delete(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Define a PATCH route
|
|
76
|
+
* @param path - Route path
|
|
77
|
+
* @param handler - Route handler
|
|
78
|
+
* @param middleware - Route middleware
|
|
79
|
+
* @public API
|
|
80
|
+
*/
|
|
81
|
+
patch(path: string, handler: express.RequestHandler, ...middleware: Array<Middleware>): void;
|
|
82
|
+
/**
|
|
83
|
+
* Apply the routes to the Express application
|
|
84
|
+
*/
|
|
85
|
+
applyRoutes(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get the routes
|
|
88
|
+
* @returns Array of route definitions
|
|
89
|
+
* @public API
|
|
90
|
+
*/
|
|
91
|
+
get Routes(): Array<RouteDefinition>;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { IMiddleware, interfaces } from "@expressots/core";
|
|
2
|
+
import { Env, IConsoleMessage } from "@expressots/shared";
|
|
3
|
+
import express from "express";
|
|
4
|
+
import { IIOC } from "./application-express-micro-container";
|
|
5
|
+
import { IRoute } from "./application-express-micro-route";
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the Express Micro API adapter
|
|
8
|
+
* @public API
|
|
9
|
+
*/
|
|
10
|
+
export type MicroAPIConfig = {
|
|
11
|
+
containerOptions: interfaces.ContainerOptions;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Interface for the Create Method of Express Micro API adapter
|
|
15
|
+
*/
|
|
16
|
+
export interface ICreateMicroAPI {
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the environment for the application
|
|
19
|
+
* @param environment - The environment to initialize
|
|
20
|
+
* @param options - Options for the environment initialization
|
|
21
|
+
* @public API
|
|
22
|
+
*/
|
|
23
|
+
initEnvironment(environment: Env.Environment, options?: Env.IEnvironment): void;
|
|
24
|
+
/**
|
|
25
|
+
* Set the global route prefix
|
|
26
|
+
* @param prefix - The global route prefix
|
|
27
|
+
* @public API
|
|
28
|
+
*/
|
|
29
|
+
setGlobalRoutePrefix(prefix: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get the Container instance
|
|
32
|
+
* @returns IIOC - The container instance interface
|
|
33
|
+
* @public API
|
|
34
|
+
*/
|
|
35
|
+
get Container(): IIOC;
|
|
36
|
+
/**
|
|
37
|
+
* Get the Express HTTP Server instance
|
|
38
|
+
* @returns express.Application
|
|
39
|
+
* @public API
|
|
40
|
+
*/
|
|
41
|
+
getHttpServer(): express.Application;
|
|
42
|
+
/**
|
|
43
|
+
* Build the Web Server Micro API
|
|
44
|
+
* @returns IWebServerMicroAPI
|
|
45
|
+
* @public API
|
|
46
|
+
*/
|
|
47
|
+
build(): IWebServerMicroAPI;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Interface for the Build Method of the Web Server Micro API adapter
|
|
51
|
+
*/
|
|
52
|
+
export interface IWebServerMicroAPI {
|
|
53
|
+
/**
|
|
54
|
+
* Get the Middleware instance
|
|
55
|
+
* @returns IMiddleware
|
|
56
|
+
* @public API
|
|
57
|
+
*/
|
|
58
|
+
get Middleware(): IMiddleware;
|
|
59
|
+
/**
|
|
60
|
+
* Get the Route instance
|
|
61
|
+
* @returns IRoute
|
|
62
|
+
* @public API
|
|
63
|
+
*/
|
|
64
|
+
get Route(): IRoute;
|
|
65
|
+
/**
|
|
66
|
+
* Listen for incoming requests
|
|
67
|
+
* @param port - The port to listen on
|
|
68
|
+
* @param appInfo - Information about the application
|
|
69
|
+
* @public API
|
|
70
|
+
*/
|
|
71
|
+
listen(port: number | string, appInfo?: IConsoleMessage): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Create a new instance of the Express Micro API adapter
|
|
75
|
+
* @param config - Configuration options
|
|
76
|
+
* @returns ICreateMicroAPI
|
|
77
|
+
* @public API
|
|
78
|
+
*/
|
|
79
|
+
export declare function createMicroAPI(config?: MicroAPIConfig): ICreateMicroAPI;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createMicroAPI, MicroAPIConfig } from "./application-express-micro";
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@codecov/vite-plugin": "^0.0.1-beta.6",
|
|
71
71
|
"@commitlint/cli": "19.2.1",
|
|
72
72
|
"@commitlint/config-conventional": "19.2.2",
|
|
73
|
-
"@expressots/core": "3.0.0-beta.1",
|
|
73
|
+
"@expressots/core": "^3.0.0-beta.1",
|
|
74
74
|
"@expressots/shared": "0.2.0",
|
|
75
75
|
"@release-it/conventional-changelog": "8.0.1",
|
|
76
76
|
"@types/express": "4.17.21",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/adapter-express",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@adapter-express)",
|
|
5
5
|
"author": "",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"@codecov/vite-plugin": "^0.0.1-beta.6",
|
|
71
71
|
"@commitlint/cli": "19.2.1",
|
|
72
72
|
"@commitlint/config-conventional": "19.2.2",
|
|
73
|
-
"@expressots/core": "3.0.0-beta.1",
|
|
73
|
+
"@expressots/core": "^3.0.0-beta.1",
|
|
74
74
|
"@expressots/shared": "0.2.0",
|
|
75
75
|
"@release-it/conventional-changelog": "8.0.1",
|
|
76
76
|
"@types/express": "4.17.21",
|