@expressots/core 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/CHANGELOG.md +21 -21
- package/lib/cjs/application/application-factory.js +83 -0
- package/lib/cjs/application/index.js +3 -5
- package/lib/cjs/controller/base-controller.js +1 -12
- package/lib/cjs/decorator/scope-binding.js +30 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/middleware/index.js +5 -0
- package/lib/cjs/middleware/interfaces/body-parser.interface.js +2 -0
- package/lib/cjs/middleware/interfaces/compression.interface.js +2 -0
- package/lib/cjs/middleware/interfaces/cors.interface.js +2 -0
- package/lib/cjs/middleware/interfaces/serve-static.interface.js +2 -0
- package/lib/cjs/middleware/middleware-resolver.js +67 -0
- package/lib/cjs/middleware/middleware-service.js +145 -0
- package/lib/cjs/provider/index.js +2 -2
- package/lib/cjs/types/application/application-factory.d.ts +34 -0
- package/lib/cjs/types/application/application-factory.d.ts.map +1 -0
- package/lib/cjs/types/application/index.d.ts +1 -1
- package/lib/cjs/types/application/index.d.ts.map +1 -1
- package/lib/cjs/types/controller/base-controller.d.ts +4 -10
- package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
- package/lib/cjs/types/decorator/scope-binding.d.ts +30 -0
- package/lib/cjs/types/decorator/scope-binding.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -0
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/middleware/index.d.ts +5 -0
- package/lib/cjs/types/middleware/index.d.ts.map +1 -0
- package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
- package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
- package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts +99 -0
- package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
- package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts +58 -0
- package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
- package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
- package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
- package/lib/cjs/types/middleware/middleware-resolver.d.ts +12 -0
- package/lib/cjs/types/middleware/middleware-resolver.d.ts.map +1 -0
- package/lib/cjs/types/middleware/middleware-service.d.ts +137 -0
- package/lib/cjs/types/middleware/middleware-service.d.ts.map +1 -0
- package/lib/cjs/types/provider/index.d.ts +1 -1
- package/lib/cjs/types/provider/index.d.ts.map +1 -1
- package/lib/esm/application/application-factory.js +72 -0
- package/lib/esm/application/index.js +3 -5
- package/lib/esm/controller/base-controller.js +1 -13
- package/lib/esm/decorator/scope-binding.js +30 -0
- package/lib/esm/index.mjs +1 -0
- package/lib/esm/middleware/index.js +5 -0
- package/lib/esm/middleware/interfaces/body-parser.interface.js +2 -0
- package/lib/esm/middleware/interfaces/compression.interface.js +2 -0
- package/lib/esm/middleware/interfaces/cors.interface.js +2 -0
- package/lib/esm/middleware/interfaces/serve-static.interface.js +2 -0
- package/lib/esm/middleware/middleware-resolver.js +68 -0
- package/lib/esm/middleware/middleware-service.js +144 -0
- package/lib/esm/provider/index.js +2 -2
- package/lib/esm/types/application/application-factory.d.ts +34 -0
- package/lib/esm/types/application/application-factory.d.ts.map +1 -0
- package/lib/esm/types/application/index.d.ts +1 -1
- package/lib/esm/types/application/index.d.ts.map +1 -1
- package/lib/esm/types/controller/base-controller.d.ts +4 -10
- package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
- package/lib/esm/types/decorator/scope-binding.d.ts +30 -0
- package/lib/esm/types/decorator/scope-binding.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +1 -0
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/middleware/index.d.ts +5 -0
- package/lib/esm/types/middleware/index.d.ts.map +1 -0
- package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
- package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
- package/lib/esm/types/middleware/interfaces/compression.interface.d.ts +99 -0
- package/lib/esm/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
- package/lib/esm/types/middleware/interfaces/cors.interface.d.ts +58 -0
- package/lib/esm/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
- package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
- package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
- package/lib/esm/types/middleware/middleware-resolver.d.ts +12 -0
- package/lib/esm/types/middleware/middleware-resolver.d.ts.map +1 -0
- package/lib/esm/types/middleware/middleware-service.d.ts +137 -0
- package/lib/esm/types/middleware/middleware-service.d.ts.map +1 -0
- package/lib/esm/types/provider/index.d.ts +1 -1
- package/lib/esm/types/provider/index.d.ts.map +1 -1
- package/lib/package.json +5 -1
- package/package.json +6 -2
- package/lib/cjs/application/application.js +0 -141
- package/lib/cjs/types/application/application.d.ts +0 -70
- package/lib/cjs/types/application/application.d.ts.map +0 -1
- package/lib/esm/application/application.js +0 -144
- package/lib/esm/types/application/application.d.ts +0 -70
- package/lib/esm/types/application/application.d.ts.map +0 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import http from "http";
|
|
3
|
+
interface ServeStaticOptions<R extends http.ServerResponse = http.ServerResponse> {
|
|
4
|
+
/**
|
|
5
|
+
* Enable or disable accepting ranged requests, defaults to true.
|
|
6
|
+
* Disabling this will not send Accept-Ranges and ignore the contents of the Range request header.
|
|
7
|
+
*/
|
|
8
|
+
acceptRanges?: boolean | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Enable or disable setting Cache-Control response header, defaults to true.
|
|
11
|
+
* Disabling this will ignore the immutable and maxAge options.
|
|
12
|
+
*/
|
|
13
|
+
cacheControl?: boolean | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot (".").
|
|
16
|
+
* Note this check is done on the path itself without checking if the path actually exists on the disk.
|
|
17
|
+
* If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny").
|
|
18
|
+
* The default value is 'ignore'.
|
|
19
|
+
* 'allow' No special treatment for dotfiles
|
|
20
|
+
* 'deny' Send a 403 for any request for a dotfile
|
|
21
|
+
* 'ignore' Pretend like the dotfile does not exist and call next()
|
|
22
|
+
*/
|
|
23
|
+
dotfiles?: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Enable or disable etag generation, defaults to true.
|
|
26
|
+
*/
|
|
27
|
+
etag?: boolean | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for.
|
|
30
|
+
* The first that exists will be served. Example: ['html', 'htm'].
|
|
31
|
+
* The default value is false.
|
|
32
|
+
*/
|
|
33
|
+
extensions?: Array<string> | false | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Let client errors fall-through as unhandled requests, otherwise forward a client error.
|
|
36
|
+
* The default value is true.
|
|
37
|
+
*/
|
|
38
|
+
fallthrough?: boolean | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Enable or disable the immutable directive in the Cache-Control response header.
|
|
41
|
+
* If enabled, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.
|
|
42
|
+
*/
|
|
43
|
+
immutable?: boolean | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* By default this module will send "index.html" files in response to a request on a directory.
|
|
46
|
+
* To disable this set false or to supply a new index pass a string or an array in preferred order.
|
|
47
|
+
*/
|
|
48
|
+
index?: boolean | string | Array<string> | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.
|
|
51
|
+
*/
|
|
52
|
+
lastModified?: boolean | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.
|
|
55
|
+
*/
|
|
56
|
+
maxAge?: number | string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Redirect to trailing "/" when the pathname is a dir. Defaults to true.
|
|
59
|
+
*/
|
|
60
|
+
redirect?: boolean | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Function to set custom headers on response. Alterations to the headers need to occur synchronously.
|
|
63
|
+
* The function is called as fn(res, path, stat), where the arguments are:
|
|
64
|
+
* res the response object
|
|
65
|
+
* path the file path that is being sent
|
|
66
|
+
* stat the stat object of the file that is being sent
|
|
67
|
+
*/
|
|
68
|
+
setHeaders?: ((res: R, path: string, stat: any) => any) | undefined;
|
|
69
|
+
}
|
|
70
|
+
export { ServeStaticOptions };
|
|
71
|
+
//# sourceMappingURL=serve-static.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-static.interface.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/middleware/interfaces/serve-static.interface.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,UAAU,kBAAkB,CAC1B,CAAC,SAAS,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc;IAEnD;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE3B;;;;OAIG;IACH,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,SAAS,CAAC;IAE/C;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAElC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEhC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAErD;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAEnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAErC;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAE/B;;;;;;OAMG;IAEH,UAAU,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC;CACrE;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
/**
|
|
3
|
+
* A utility function that wraps the creation and retrieval of middleware.
|
|
4
|
+
* It creates a new instance of MiddlewareResolver and calls the getMiddleware method.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} middleware - The name of the middleware to be retrieved.
|
|
7
|
+
* @param {...any} options - Optional arguments to configure the middleware.
|
|
8
|
+
* @returns {express.RequestHandler | null} - Returns the configured middleware or null if not found or not installed.
|
|
9
|
+
*/
|
|
10
|
+
declare function middlewareResolver(middleware: string, ...options: any): express.RequestHandler | null;
|
|
11
|
+
export { middlewareResolver };
|
|
12
|
+
//# sourceMappingURL=middleware-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-resolver.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-resolver.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAqE9B;;;;;;;GAOG;AACH,iBAAS,kBAAkB,CACzB,UAAU,EAAE,MAAM,EAClB,GAAG,OAAO,EAAE,GAAG,GACd,OAAO,CAAC,cAAc,GAAG,IAAI,CAG/B;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { OptionsJson } from "./interfaces/body-parser.interface";
|
|
3
|
+
import { CompressionOptions } from "./interfaces/compression.interface";
|
|
4
|
+
import { CorsOptions } from "./interfaces/cors.interface";
|
|
5
|
+
import { ServeStaticOptions } from "./interfaces/serve-static.interface";
|
|
6
|
+
type ExpressHandler = express.ErrorRequestHandler | express.RequestParamHandler | express.RequestHandler | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Interface for configuring and managing middlewares in the application.
|
|
9
|
+
* Provides methods to be added automatically in the application without the need to import packages.
|
|
10
|
+
*/
|
|
11
|
+
interface IMiddleware {
|
|
12
|
+
/**
|
|
13
|
+
* Adds a Body Parser middleware to the middleware collection.
|
|
14
|
+
* The body parser is responsible for parsing the incoming request bodies in a middleware.
|
|
15
|
+
*
|
|
16
|
+
* @param options - Optional configuration options for the JSON body parser.
|
|
17
|
+
*/
|
|
18
|
+
addBodyParser(options?: OptionsJson): void;
|
|
19
|
+
/**
|
|
20
|
+
* Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
|
|
23
|
+
*/
|
|
24
|
+
addCors(options?: CorsOptions): void;
|
|
25
|
+
/**
|
|
26
|
+
* Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
|
|
29
|
+
*/
|
|
30
|
+
addCompression(options?: CompressionOptions): void;
|
|
31
|
+
/**
|
|
32
|
+
* Configures the error handling middleware for the application.
|
|
33
|
+
*
|
|
34
|
+
* @param errorHandling - The Express error handler function that takes care of processing errors and formulating the response.
|
|
35
|
+
*/
|
|
36
|
+
setErrorHandler(errorHandling?: ExpressHandler): void;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a middleware to serve static files from the specified root directory.
|
|
39
|
+
* Allows the application to serve files like images, CSS, JavaScript, etc.
|
|
40
|
+
*
|
|
41
|
+
* @param root - The root directory from which the static assets are to be served.
|
|
42
|
+
* @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
|
|
43
|
+
*/
|
|
44
|
+
serveStatic(root: string, options?: ServeStaticOptions): void;
|
|
45
|
+
/**
|
|
46
|
+
* Adds a middleware to the middleware collection.
|
|
47
|
+
*
|
|
48
|
+
* @param middleware - The Express request handler function to be added to the middleware collection.
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
addMiddleware(middleware: express.RequestHandler): void;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves all the middlewares that have been added.
|
|
54
|
+
*
|
|
55
|
+
* @returns An array of Express request handlers representing the middlewares.
|
|
56
|
+
*/
|
|
57
|
+
getMiddlewares(): Array<express.RequestHandler>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets the configured error handler middleware.
|
|
60
|
+
*
|
|
61
|
+
* @returns The error handler middleware.
|
|
62
|
+
*/
|
|
63
|
+
getErrorHandler(): ExpressHandler;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Singleton class that implements the IConfigure interface.
|
|
67
|
+
* Manages the middleware configuration for the application,
|
|
68
|
+
* including adding Body Parser and retrieving all configured middlewares.
|
|
69
|
+
*
|
|
70
|
+
* @see IConfigure
|
|
71
|
+
*/
|
|
72
|
+
declare class Middleware implements IMiddleware {
|
|
73
|
+
private middlewares;
|
|
74
|
+
private errorHandler;
|
|
75
|
+
private logger;
|
|
76
|
+
/**
|
|
77
|
+
* Checks if a middleware with the given name exists in the middleware collection.
|
|
78
|
+
*
|
|
79
|
+
* @param middlewareName - The name of the middleware to be checked.
|
|
80
|
+
*
|
|
81
|
+
* @returns A boolean value indicating whether the middleware exists or not.
|
|
82
|
+
*/
|
|
83
|
+
private middlewareExists;
|
|
84
|
+
/**
|
|
85
|
+
* Adds a Body Parser middleware to the middleware collection using the given options.
|
|
86
|
+
*
|
|
87
|
+
* @param options - Optional configuration options for the JSON body parser.
|
|
88
|
+
*/
|
|
89
|
+
addBodyParser(options?: OptionsJson): void;
|
|
90
|
+
/**
|
|
91
|
+
* Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
|
|
92
|
+
*
|
|
93
|
+
* @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
|
|
94
|
+
*/
|
|
95
|
+
addCors(options?: CorsOptions): void;
|
|
96
|
+
/**
|
|
97
|
+
* Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Optional configuration options for Compression. Allows fine-tuning the compression behavior, such as setting the compression level, threshold, and filter functions to determine which requests should be compressed.
|
|
100
|
+
*/
|
|
101
|
+
addCompression(options?: CompressionOptions): void;
|
|
102
|
+
/**
|
|
103
|
+
* Configures the error handling middleware for the application.
|
|
104
|
+
*
|
|
105
|
+
* @param errorHandling - The Express error handler function that takes care of processing errors and formulating the response.
|
|
106
|
+
*/
|
|
107
|
+
setErrorHandler(errorHandling?: ExpressHandler): void;
|
|
108
|
+
/**
|
|
109
|
+
* Adds a middleware to serve static files from the specified root directory.
|
|
110
|
+
* Allows the application to serve files like images, CSS, JavaScript, etc.
|
|
111
|
+
*
|
|
112
|
+
* @param root - The root directory from which the static assets are to be served.
|
|
113
|
+
* @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
|
|
114
|
+
*/
|
|
115
|
+
serveStatic(root: string, options?: ServeStaticOptions): void;
|
|
116
|
+
/**
|
|
117
|
+
* Adds a middleware to the middleware collection.
|
|
118
|
+
*
|
|
119
|
+
* @param middleware - The Express request handler function to be added to the middleware collection.
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
addMiddleware(middleware: express.RequestHandler): void;
|
|
123
|
+
/**
|
|
124
|
+
* Retrieves all the middlewares that have been added to the collection.
|
|
125
|
+
*
|
|
126
|
+
* @returns An array of Express request handlers representing the middlewares.
|
|
127
|
+
*/
|
|
128
|
+
getMiddlewares(): Array<express.RequestHandler>;
|
|
129
|
+
/**
|
|
130
|
+
* Gets the configured error handler middleware.
|
|
131
|
+
*
|
|
132
|
+
* @returns The error handler middleware.
|
|
133
|
+
*/
|
|
134
|
+
getErrorHandler(): ExpressHandler;
|
|
135
|
+
}
|
|
136
|
+
export { Middleware, IMiddleware };
|
|
137
|
+
//# sourceMappingURL=middleware-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware-service.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/middleware-service.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAGzE,KAAK,cAAc,GACf,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,GAC3B,OAAO,CAAC,cAAc,GACtB,SAAS,CAAC;AAEd;;;GAGG;AACH,UAAU,WAAW;IACnB;;;;;OAKG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAE3C;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAErC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;IAEtD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE9D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAExD;;;;OAIG;IACH,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAEhD;;;;OAIG;IACH,eAAe,IAAI,cAAc,CAAC;CACnC;AAED;;;;;;GAMG;AACH,cACM,UAAW,YAAW,WAAW;IACrC,OAAO,CAAC,WAAW,CAAqC;IACxD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,MAAM,CAAwB;IAEtC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;OAIG;IACI,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IAajD;;;;OAIG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI;IASpC;;;;OAIG;IACH,cAAc,CAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAUlD;;;;OAIG;IACH,eAAe,CAAC,aAAa,CAAC,EAAE,cAAc,GAAG,IAAI;IAQrD;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAa7D;;;;;OAKG;IACH,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,cAAc,GAAG,IAAI;IAavD;;;;OAIG;IACI,cAAc,IAAI,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC;IAItD;;;;OAIG;IACI,eAAe,IAAI,cAAc;CAGzC;AAED,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Provider, IProvider } from "./provider-service";
|
|
2
2
|
export { Logger } from "./logger/logger-service";
|
|
3
|
-
export { EnvValidatorProvider } from "./environment/env-validator.provider";
|
|
3
|
+
export { EnvValidatorProvider as Env } from "./environment/env-validator.provider";
|
|
4
4
|
export { ValidateDTO } from "./dto-validator/dto-validator.provider";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,oBAAoB,IAAI,GAAG,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC"}
|
package/lib/package.json
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"coverage": "vitest run --coverage",
|
|
64
64
|
"test": "vitest run",
|
|
65
65
|
"test:watch": "vitest",
|
|
66
|
-
"format
|
|
66
|
+
"format": "prettier --write \"packages/**/*.ts\" --cache",
|
|
67
67
|
"lint": "eslint \"packages/**/*.ts\"",
|
|
68
68
|
"lint:fix": "eslint \"packages/**/*.ts\" --fix"
|
|
69
69
|
},
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@commitlint/cli": "^17.7.1",
|
|
82
82
|
"@commitlint/config-conventional": "^17.7.0",
|
|
83
|
+
"@expressots/adapter-express": "latest",
|
|
83
84
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
84
85
|
"@types/express": "^4.17.17",
|
|
85
86
|
"@types/node": "^20.4.9",
|
|
@@ -95,6 +96,9 @@
|
|
|
95
96
|
"vite": "4.4.9",
|
|
96
97
|
"vitest": "0.34.4"
|
|
97
98
|
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"@expressots/adapter-express": "latest"
|
|
101
|
+
},
|
|
98
102
|
"release-it": {
|
|
99
103
|
"git": {
|
|
100
104
|
"commitMessage": "chore(release): ${version}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressots/core",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"description": "Expressots - modern, fast, lightweight nodejs web framework (@core)",
|
|
5
5
|
"author": "Richard Zampieri",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"coverage": "vitest run --coverage",
|
|
64
64
|
"test": "vitest run",
|
|
65
65
|
"test:watch": "vitest",
|
|
66
|
-
"format
|
|
66
|
+
"format": "prettier --write \"packages/**/*.ts\" --cache",
|
|
67
67
|
"lint": "eslint \"packages/**/*.ts\"",
|
|
68
68
|
"lint:fix": "eslint \"packages/**/*.ts\" --fix"
|
|
69
69
|
},
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@commitlint/cli": "^17.7.1",
|
|
82
82
|
"@commitlint/config-conventional": "^17.7.0",
|
|
83
|
+
"@expressots/adapter-express": "latest",
|
|
83
84
|
"@release-it/conventional-changelog": "^7.0.1",
|
|
84
85
|
"@types/express": "^4.17.17",
|
|
85
86
|
"@types/node": "^20.4.9",
|
|
@@ -95,6 +96,9 @@
|
|
|
95
96
|
"vite": "4.4.9",
|
|
96
97
|
"vitest": "0.34.4"
|
|
97
98
|
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"@expressots/adapter-express": "latest"
|
|
101
|
+
},
|
|
98
102
|
"release-it": {
|
|
99
103
|
"git": {
|
|
100
104
|
"commitMessage": "chore(release): ${version}"
|
|
@@ -1,141 +0,0 @@
|
|
|
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
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
var Application_1;
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.ServerEnvironment = exports.Application = exports.AppInstance = void 0;
|
|
17
|
-
const process_1 = __importDefault(require("process"));
|
|
18
|
-
const express_1 = __importDefault(require("express"));
|
|
19
|
-
const inversify_binding_decorators_1 = require("inversify-binding-decorators");
|
|
20
|
-
const inversify_express_utils_1 = require("inversify-express-utils");
|
|
21
|
-
const console_1 = require("../console/console");
|
|
22
|
-
const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
|
|
23
|
-
/**
|
|
24
|
-
* Enum representing possible server environments.
|
|
25
|
-
*/
|
|
26
|
-
var ServerEnvironment;
|
|
27
|
-
(function (ServerEnvironment) {
|
|
28
|
-
ServerEnvironment["Development"] = "development";
|
|
29
|
-
ServerEnvironment["Staging"] = "staging";
|
|
30
|
-
ServerEnvironment["Production"] = "production";
|
|
31
|
-
})(ServerEnvironment || (exports.ServerEnvironment = ServerEnvironment = {}));
|
|
32
|
-
/**
|
|
33
|
-
* The Application class provides a way to configure and manage an Express application.
|
|
34
|
-
* @provide Application
|
|
35
|
-
*/
|
|
36
|
-
let Application = Application_1 = class Application {
|
|
37
|
-
/**
|
|
38
|
-
* Constructs a new instance of the Application class.
|
|
39
|
-
*/
|
|
40
|
-
constructor() { }
|
|
41
|
-
/**
|
|
42
|
-
* Configure services that should be initialized before the server starts.
|
|
43
|
-
*/
|
|
44
|
-
configureServices() { }
|
|
45
|
-
/**
|
|
46
|
-
* Configure services that should be executed after the server starts.
|
|
47
|
-
*/
|
|
48
|
-
postServerInitialization() { }
|
|
49
|
-
/**
|
|
50
|
-
* Perform actions or cleanup after the server is shutdown.
|
|
51
|
-
*/
|
|
52
|
-
serverShutdown() { }
|
|
53
|
-
/**
|
|
54
|
-
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
55
|
-
*/
|
|
56
|
-
handleExit() {
|
|
57
|
-
this.serverShutdown();
|
|
58
|
-
process_1.default.exit(0);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Create and configure the Express application.
|
|
62
|
-
* @param container - The InversifyJS container.
|
|
63
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
64
|
-
* @returns The configured Application instance.
|
|
65
|
-
*/
|
|
66
|
-
create(container, middlewares = []) {
|
|
67
|
-
this.configureServices();
|
|
68
|
-
const expressServer = new inversify_express_utils_1.InversifyExpressServer(container);
|
|
69
|
-
expressServer.setConfig((app) => {
|
|
70
|
-
// Detect if a middleware in the array has a body parser. If so, replace the default body parser.
|
|
71
|
-
const hasCustomBodyParser = middlewares.some((middleware) => {
|
|
72
|
-
const middlewareName = middleware.name.toLowerCase();
|
|
73
|
-
return (middlewareName.includes("json") ||
|
|
74
|
-
middlewareName.includes("urlencoded"));
|
|
75
|
-
});
|
|
76
|
-
if (!hasCustomBodyParser) {
|
|
77
|
-
/* Default body parser application/json */
|
|
78
|
-
app.use(express_1.default.json());
|
|
79
|
-
/* Default body parser application/x-www-form-urlencoded */
|
|
80
|
-
app.use(express_1.default.urlencoded({ extended: true }));
|
|
81
|
-
}
|
|
82
|
-
middlewares.forEach((middleware) => {
|
|
83
|
-
app.use(middleware);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
expressServer.setErrorConfig((app) => {
|
|
87
|
-
app.use(error_handler_middleware_1.default);
|
|
88
|
-
});
|
|
89
|
-
this.app = expressServer.build();
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Start listening on the given port and environment.
|
|
94
|
-
* @param port - The port number to listen on.
|
|
95
|
-
* @param environment - The server environment.
|
|
96
|
-
* @param consoleMessage - Optional message to display in the console.
|
|
97
|
-
*/
|
|
98
|
-
listen(port, environment, consoleMessage) {
|
|
99
|
-
this.port = port;
|
|
100
|
-
this.environment = environment;
|
|
101
|
-
this.app.listen(this.port, () => {
|
|
102
|
-
new console_1.Console().messageServer(this.port, this.environment, consoleMessage);
|
|
103
|
-
[
|
|
104
|
-
"SIGTERM",
|
|
105
|
-
"SIGHUP",
|
|
106
|
-
"SIGBREAK",
|
|
107
|
-
"SIGQUIT",
|
|
108
|
-
"SIGINT",
|
|
109
|
-
].forEach((signal) => {
|
|
110
|
-
process_1.default.on(signal, this.handleExit.bind(this));
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
this.postServerInitialization();
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Configures the application's view engine based on the provided configuration options.
|
|
117
|
-
*
|
|
118
|
-
* @public
|
|
119
|
-
* @method setEngine
|
|
120
|
-
* @template T - A generic type extending from RenderTemplateOptions.
|
|
121
|
-
*
|
|
122
|
-
* @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
|
|
123
|
-
* that provides the configuration options for setting the view engine.
|
|
124
|
-
* This includes the extension name, view path, and the engine function itself.
|
|
125
|
-
*/
|
|
126
|
-
setEngine(options) {
|
|
127
|
-
if ("extName" in options) {
|
|
128
|
-
const { extName, viewPath, engine } = options;
|
|
129
|
-
this.app.engine(extName, engine);
|
|
130
|
-
this.app.set("view engine", extName);
|
|
131
|
-
this.app.set("views", viewPath);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
exports.Application = Application;
|
|
136
|
-
exports.Application = Application = Application_1 = __decorate([
|
|
137
|
-
(0, inversify_binding_decorators_1.provide)(Application_1),
|
|
138
|
-
__metadata("design:paramtypes", [])
|
|
139
|
-
], Application);
|
|
140
|
-
const appServerInstance = new Application();
|
|
141
|
-
exports.AppInstance = appServerInstance;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { Container } from "inversify";
|
|
3
|
-
import { IApplicationMessageToConsole } from "../console/console";
|
|
4
|
-
import { RenderTemplateOptions } from "../render";
|
|
5
|
-
/**
|
|
6
|
-
* Enum representing possible server environments.
|
|
7
|
-
*/
|
|
8
|
-
declare enum ServerEnvironment {
|
|
9
|
-
Development = "development",
|
|
10
|
-
Staging = "staging",
|
|
11
|
-
Production = "production"
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The Application class provides a way to configure and manage an Express application.
|
|
15
|
-
* @provide Application
|
|
16
|
-
*/
|
|
17
|
-
declare class Application {
|
|
18
|
-
private app;
|
|
19
|
-
private port;
|
|
20
|
-
private environment;
|
|
21
|
-
/**
|
|
22
|
-
* Constructs a new instance of the Application class.
|
|
23
|
-
*/
|
|
24
|
-
constructor();
|
|
25
|
-
/**
|
|
26
|
-
* Configure services that should be initialized before the server starts.
|
|
27
|
-
*/
|
|
28
|
-
protected configureServices(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Configure services that should be executed after the server starts.
|
|
31
|
-
*/
|
|
32
|
-
protected postServerInitialization(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Perform actions or cleanup after the server is shutdown.
|
|
35
|
-
*/
|
|
36
|
-
protected serverShutdown(): void;
|
|
37
|
-
/**
|
|
38
|
-
* Handles process exit by calling serverShutdown and then exiting the process.
|
|
39
|
-
*/
|
|
40
|
-
private handleExit;
|
|
41
|
-
/**
|
|
42
|
-
* Create and configure the Express application.
|
|
43
|
-
* @param container - The InversifyJS container.
|
|
44
|
-
* @param middlewares - An array of Express middlewares to be applied.
|
|
45
|
-
* @returns The configured Application instance.
|
|
46
|
-
*/
|
|
47
|
-
create(container: Container, middlewares?: Array<express.RequestHandler>): Application;
|
|
48
|
-
/**
|
|
49
|
-
* Start listening on the given port and environment.
|
|
50
|
-
* @param port - The port number to listen on.
|
|
51
|
-
* @param environment - The server environment.
|
|
52
|
-
* @param consoleMessage - Optional message to display in the console.
|
|
53
|
-
*/
|
|
54
|
-
listen(port: number, environment: ServerEnvironment, consoleMessage?: IApplicationMessageToConsole): void;
|
|
55
|
-
/**
|
|
56
|
-
* Configures the application's view engine based on the provided configuration options.
|
|
57
|
-
*
|
|
58
|
-
* @public
|
|
59
|
-
* @method setEngine
|
|
60
|
-
* @template T - A generic type extending from RenderTemplateOptions.
|
|
61
|
-
*
|
|
62
|
-
* @param {T} options - An object of type T (must be an object that extends RenderTemplateOptions)
|
|
63
|
-
* that provides the configuration options for setting the view engine.
|
|
64
|
-
* This includes the extension name, view path, and the engine function itself.
|
|
65
|
-
*/
|
|
66
|
-
setEngine<T extends RenderTemplateOptions>(options: T): void;
|
|
67
|
-
}
|
|
68
|
-
declare const appServerInstance: Application;
|
|
69
|
-
export { appServerInstance as AppInstance, Application, ServerEnvironment };
|
|
70
|
-
//# sourceMappingURL=application.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAW,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAe,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAE/D;;GAEG;AACH,aAAK,iBAAiB;IACpB,WAAW,gBAAgB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;CAC1B;AAED;;;GAGG;AACH,cACM,WAAW;IACf,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,WAAW,CAAoB;IAEvC;;OAEG;;IAGH;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAEnC;;OAEG;IACH,SAAS,CAAC,wBAAwB,IAAI,IAAI;IAE1C;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IAEhC;;OAEG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACI,MAAM,CACX,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAM,GAC9C,WAAW;IAqCd;;;;;OAKG;IACI,MAAM,CACX,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,iBAAiB,EAC9B,cAAc,CAAC,EAAE,4BAA4B,GAC5C,IAAI;IAuBP;;;;;;;;;;OAUG;IACI,SAAS,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;CAQpE;AAED,QAAA,MAAM,iBAAiB,EAAE,WAA+B,CAAC;AAEzD,OAAO,EAAE,iBAAiB,IAAI,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,CAAC"}
|