@expressots/core 1.9.0 → 2.0.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.
Files changed (93) hide show
  1. package/lib/CHANGELOG.md +54 -26
  2. package/lib/cjs/application/application-factory.js +83 -0
  3. package/lib/cjs/application/index.js +3 -5
  4. package/lib/cjs/controller/base-controller.js +1 -12
  5. package/lib/cjs/decorator/scope-binding.js +30 -0
  6. package/lib/cjs/index.js +1 -0
  7. package/lib/cjs/middleware/index.js +5 -0
  8. package/lib/cjs/middleware/interfaces/body-parser.interface.js +2 -0
  9. package/lib/cjs/middleware/interfaces/compression.interface.js +2 -0
  10. package/lib/cjs/middleware/interfaces/cors.interface.js +2 -0
  11. package/lib/cjs/middleware/interfaces/serve-static.interface.js +2 -0
  12. package/lib/cjs/middleware/middleware-resolver.js +64 -0
  13. package/lib/cjs/middleware/middleware-service.js +145 -0
  14. package/lib/cjs/provider/index.js +2 -2
  15. package/lib/cjs/types/application/application-factory.d.ts +34 -0
  16. package/lib/cjs/types/application/application-factory.d.ts.map +1 -0
  17. package/lib/cjs/types/application/index.d.ts +1 -1
  18. package/lib/cjs/types/application/index.d.ts.map +1 -1
  19. package/lib/cjs/types/controller/base-controller.d.ts +4 -10
  20. package/lib/cjs/types/controller/base-controller.d.ts.map +1 -1
  21. package/lib/cjs/types/decorator/scope-binding.d.ts +30 -0
  22. package/lib/cjs/types/decorator/scope-binding.d.ts.map +1 -1
  23. package/lib/cjs/types/index.d.ts +1 -0
  24. package/lib/cjs/types/index.d.ts.map +1 -1
  25. package/lib/cjs/types/middleware/index.d.ts +5 -0
  26. package/lib/cjs/types/middleware/index.d.ts.map +1 -0
  27. package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
  28. package/lib/cjs/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
  29. package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts +99 -0
  30. package/lib/cjs/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
  31. package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts +58 -0
  32. package/lib/cjs/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
  33. package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
  34. package/lib/cjs/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
  35. package/lib/cjs/types/middleware/middleware-resolver.d.ts +12 -0
  36. package/lib/cjs/types/middleware/middleware-resolver.d.ts.map +1 -0
  37. package/lib/cjs/types/middleware/middleware-service.d.ts +137 -0
  38. package/lib/cjs/types/middleware/middleware-service.d.ts.map +1 -0
  39. package/lib/cjs/types/provider/index.d.ts +1 -1
  40. package/lib/cjs/types/provider/index.d.ts.map +1 -1
  41. package/lib/esm/application/application-factory.js +72 -0
  42. package/lib/esm/application/index.js +3 -5
  43. package/lib/esm/controller/base-controller.js +1 -13
  44. package/lib/esm/decorator/scope-binding.js +30 -0
  45. package/lib/esm/index.mjs +1 -0
  46. package/lib/esm/middleware/index.js +5 -0
  47. package/lib/esm/middleware/interfaces/body-parser.interface.js +2 -0
  48. package/lib/esm/middleware/interfaces/compression.interface.js +2 -0
  49. package/lib/esm/middleware/interfaces/cors.interface.js +2 -0
  50. package/lib/esm/middleware/interfaces/serve-static.interface.js +2 -0
  51. package/lib/esm/middleware/middleware-resolver.js +65 -0
  52. package/lib/esm/middleware/middleware-service.js +144 -0
  53. package/lib/esm/provider/index.js +2 -2
  54. package/lib/esm/types/application/application-factory.d.ts +34 -0
  55. package/lib/esm/types/application/application-factory.d.ts.map +1 -0
  56. package/lib/esm/types/application/index.d.ts +1 -1
  57. package/lib/esm/types/application/index.d.ts.map +1 -1
  58. package/lib/esm/types/controller/base-controller.d.ts +4 -10
  59. package/lib/esm/types/controller/base-controller.d.ts.map +1 -1
  60. package/lib/esm/types/decorator/scope-binding.d.ts +30 -0
  61. package/lib/esm/types/decorator/scope-binding.d.ts.map +1 -1
  62. package/lib/esm/types/index.d.ts +1 -0
  63. package/lib/esm/types/index.d.ts.map +1 -1
  64. package/lib/esm/types/middleware/index.d.ts +5 -0
  65. package/lib/esm/types/middleware/index.d.ts.map +1 -0
  66. package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts +34 -0
  67. package/lib/esm/types/middleware/interfaces/body-parser.interface.d.ts.map +1 -0
  68. package/lib/esm/types/middleware/interfaces/compression.interface.d.ts +99 -0
  69. package/lib/esm/types/middleware/interfaces/compression.interface.d.ts.map +1 -0
  70. package/lib/esm/types/middleware/interfaces/cors.interface.d.ts +58 -0
  71. package/lib/esm/types/middleware/interfaces/cors.interface.d.ts.map +1 -0
  72. package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts +71 -0
  73. package/lib/esm/types/middleware/interfaces/serve-static.interface.d.ts.map +1 -0
  74. package/lib/esm/types/middleware/middleware-resolver.d.ts +12 -0
  75. package/lib/esm/types/middleware/middleware-resolver.d.ts.map +1 -0
  76. package/lib/esm/types/middleware/middleware-service.d.ts +137 -0
  77. package/lib/esm/types/middleware/middleware-service.d.ts.map +1 -0
  78. package/lib/esm/types/provider/index.d.ts +1 -1
  79. package/lib/esm/types/provider/index.d.ts.map +1 -1
  80. package/lib/package.json +7 -8
  81. package/package.json +7 -8
  82. package/lib/cjs/application/application.js +0 -141
  83. package/lib/cjs/provider/logger/winston-logger.js +0 -131
  84. package/lib/cjs/types/application/application.d.ts +0 -70
  85. package/lib/cjs/types/application/application.d.ts.map +0 -1
  86. package/lib/cjs/types/provider/logger/winston-logger.d.ts +0 -46
  87. package/lib/cjs/types/provider/logger/winston-logger.d.ts.map +0 -1
  88. package/lib/esm/application/application.js +0 -144
  89. package/lib/esm/provider/logger/winston-logger.js +0 -132
  90. package/lib/esm/types/application/application.d.ts +0 -70
  91. package/lib/esm/types/application/application.d.ts.map +0 -1
  92. package/lib/esm/types/provider/logger/winston-logger.d.ts +0 -46
  93. package/lib/esm/types/provider/logger/winston-logger.d.ts.map +0 -1
@@ -4,10 +4,40 @@ exports.provideTransient = exports.provideSingleton = void 0;
4
4
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
5
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
6
  const inversify_binding_decorators_1 = require("inversify-binding-decorators");
7
+ /**
8
+ * Provides a singleton binding for the given identifier.
9
+ *
10
+ * @remarks
11
+ * Singleton binding ensures that the same instance of a dependency is reused within the entire container.
12
+ *
13
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
14
+ * @returns A fluent interface for further configuring the binding.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * @provideSingleton(ServiceIdentifier)
19
+ * class MyService {}
20
+ * ```
21
+ */
7
22
  const provideSingleton = (identifier) => {
8
23
  return (0, inversify_binding_decorators_1.fluentProvide)(identifier).inSingletonScope().done();
9
24
  };
10
25
  exports.provideSingleton = provideSingleton;
26
+ /**
27
+ * Provides a transient binding for the given identifier.
28
+ *
29
+ * @remarks
30
+ * Transient binding ensures that a new instance of a dependency is created every time it is resolved.
31
+ *
32
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
33
+ * @returns A fluent interface for further configuring the binding.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * @provideTransient(ServiceIdentifier)
38
+ * class MyService {}
39
+ * ```
40
+ */
11
41
  const provideTransient = (identifier) => {
12
42
  return (0, inversify_binding_decorators_1.fluentProvide)(identifier).inTransientScope().done();
13
43
  };
package/lib/esm/index.mjs CHANGED
@@ -21,5 +21,6 @@ __exportStar(require("./container-module"), exports);
21
21
  __exportStar(require("./controller"), exports);
22
22
  __exportStar(require("./decorator"), exports);
23
23
  __exportStar(require("./error"), exports);
24
+ __exportStar(require("./middleware"), exports);
24
25
  __exportStar(require("./provider"), exports);
25
26
  __exportStar(require("./render"), exports);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Middleware = void 0;
4
+ var middleware_service_1 = require("./middleware-service");
5
+ Object.defineProperty(exports, "Middleware", { enumerable: true, get: function () { return middleware_service_1.Middleware; } });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.middlewareResolver = void 0;
4
+ const logger_service_1 = require("../provider/logger/logger-service");
5
+ /**
6
+ * MiddlewareResolver class is responsible for resolving and retrieving Express middlewares
7
+ * by their names. It maintains a registry of available middlewares and provides
8
+ * a method to retrieve them by their name. If a middleware is not installed, it logs
9
+ * an informative message.
10
+ */
11
+ class MiddlewareResolver {
12
+ logger;
13
+ constructor() {
14
+ this.logger = new logger_service_1.Logger();
15
+ }
16
+ /**
17
+ * A registry object mapping middleware names to their corresponding package names.
18
+ * It is used to identify and require the middleware from the current working directory.
19
+ */
20
+ middlewareRegistry = {
21
+ cors: "cors",
22
+ compression: "compression",
23
+ // Add other middlewares
24
+ };
25
+ /**
26
+ * Retrieves a middleware by its name and optionally configures it with provided options.
27
+ *
28
+ * @param {string} middlewareName - The name of the middleware to be retrieved.
29
+ * @param {...any} options - Optional arguments to configure the middleware.
30
+ * @returns {express.RequestHandler | null} - Returns the configured middleware or null if not found or not installed.
31
+ */
32
+ getMiddleware(middlewareName, ...options) {
33
+ const packageName = this.middlewareRegistry[middlewareName];
34
+ if (!packageName) {
35
+ console.error(`Middleware ${middlewareName} not found`);
36
+ return null;
37
+ }
38
+ let hasMiddleware = "";
39
+ try {
40
+ hasMiddleware = require.resolve(packageName, { paths: [process.cwd()] });
41
+ }
42
+ catch (error) {
43
+ this.logger.warn(`Middleware [${middlewareName}] not installed. Please install it using your package manager.`, "middleware-resolver");
44
+ }
45
+ if (hasMiddleware) {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ const middleware = require(hasMiddleware);
48
+ return middleware(...options) || middleware.default(...options);
49
+ }
50
+ return null;
51
+ }
52
+ }
53
+ /**
54
+ * A utility function that wraps the creation and retrieval of middleware.
55
+ * It creates a new instance of MiddlewareResolver and calls the getMiddleware method.
56
+ *
57
+ * @param {string} middleware - The name of the middleware to be retrieved.
58
+ * @param {...any} options - Optional arguments to configure the middleware.
59
+ * @returns {express.RequestHandler | null} - Returns the configured middleware or null if not found or not installed.
60
+ */
61
+ function middlewareResolver(middleware, ...options) {
62
+ const resolver = new MiddlewareResolver();
63
+ return resolver.getMiddleware(middleware, ...options);
64
+ }
65
+ exports.middlewareResolver = middlewareResolver;
@@ -0,0 +1,144 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ var Middleware_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.Middleware = void 0;
14
+ const express_1 = __importDefault(require("express"));
15
+ const index_1 = require("../decorator/index");
16
+ const error_handler_middleware_1 = __importDefault(require("../error/error-handler-middleware"));
17
+ const logger_service_1 = require("../provider/logger/logger-service");
18
+ const middleware_resolver_1 = require("./middleware-resolver");
19
+ /**
20
+ * Singleton class that implements the IConfigure interface.
21
+ * Manages the middleware configuration for the application,
22
+ * including adding Body Parser and retrieving all configured middlewares.
23
+ *
24
+ * @see IConfigure
25
+ */
26
+ let Middleware = Middleware_1 = class Middleware {
27
+ middlewares = [];
28
+ errorHandler;
29
+ logger = new logger_service_1.Logger();
30
+ /**
31
+ * Checks if a middleware with the given name exists in the middleware collection.
32
+ *
33
+ * @param middlewareName - The name of the middleware to be checked.
34
+ *
35
+ * @returns A boolean value indicating whether the middleware exists or not.
36
+ */
37
+ middlewareExists(middlewareName) {
38
+ const middlewares = this.getMiddlewares();
39
+ const middlewareIndex = middlewares.findIndex((m) => m.name === middlewareName);
40
+ return middlewareIndex !== -1;
41
+ }
42
+ /**
43
+ * Adds a Body Parser middleware to the middleware collection using the given options.
44
+ *
45
+ * @param options - Optional configuration options for the JSON body parser.
46
+ */
47
+ addBodyParser(options) {
48
+ const middlewareExist = this.middlewareExists("jsonParser");
49
+ if (middlewareExist) {
50
+ this.logger.warn(`[jsonParser] already exists. Skipping...`, "configure-service");
51
+ }
52
+ else {
53
+ this.middlewares.push(express_1.default.json(options));
54
+ }
55
+ }
56
+ /**
57
+ * Adds Cross-Origin Resource Sharing (CORS) middleware to enable or control cross-origin requests.
58
+ *
59
+ * @param options - Optional configuration options for CORS. Defines the behavior of CORS requests like allowed origins, methods, headers, etc.
60
+ */
61
+ addCors(options) {
62
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("cors", options);
63
+ const middlewareExist = this.middlewareExists("cors");
64
+ if (middleware && !middlewareExist) {
65
+ this.middlewares.push(middleware);
66
+ }
67
+ }
68
+ /**
69
+ * Adds Compression middleware to reduce the size of the response body and improve the speed of the client-server communication.
70
+ *
71
+ * @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.
72
+ */
73
+ addCompression(options) {
74
+ const middleware = (0, middleware_resolver_1.middlewareResolver)("compression", options);
75
+ const middlewareExist = this.middlewareExists("compression");
76
+ if (middleware && !middlewareExist) {
77
+ this.middlewares.push(middleware);
78
+ }
79
+ }
80
+ /**
81
+ * Configures the error handling middleware for the application.
82
+ *
83
+ * @param errorHandling - The Express error handler function that takes care of processing errors and formulating the response.
84
+ */
85
+ setErrorHandler(errorHandling) {
86
+ if (!errorHandling) {
87
+ this.errorHandler = error_handler_middleware_1.default;
88
+ }
89
+ else {
90
+ this.errorHandler = errorHandling;
91
+ }
92
+ }
93
+ /**
94
+ * Adds a middleware to serve static files from the specified root directory.
95
+ * Allows the application to serve files like images, CSS, JavaScript, etc.
96
+ *
97
+ * @param root - The root directory from which the static assets are to be served.
98
+ * @param options - Optional configuration options for serving static files. Defines behavior like cache control, custom headers, etc.
99
+ */
100
+ serveStatic(root, options) {
101
+ const middlewareExist = this.middlewareExists("serveStatic");
102
+ if (middlewareExist) {
103
+ this.logger.warn(`[serveStatic] already exists. Skipping...`, "configure-service");
104
+ }
105
+ else {
106
+ this.middlewares.push(express_1.default.static(root, options));
107
+ }
108
+ }
109
+ /**
110
+ * Adds a middleware to the middleware collection.
111
+ *
112
+ * @param middleware - The Express request handler function to be added to the middleware collection.
113
+ *
114
+ */
115
+ addMiddleware(middleware) {
116
+ const middlewareExist = this.middlewareExists(middleware.name);
117
+ if (middlewareExist) {
118
+ this.logger.warn(`[${middleware.name}] already exists. Skipping...`, "configure-service");
119
+ }
120
+ else {
121
+ this.middlewares.push(middleware);
122
+ }
123
+ }
124
+ /**
125
+ * Retrieves all the middlewares that have been added to the collection.
126
+ *
127
+ * @returns An array of Express request handlers representing the middlewares.
128
+ */
129
+ getMiddlewares() {
130
+ return this.middlewares;
131
+ }
132
+ /**
133
+ * Gets the configured error handler middleware.
134
+ *
135
+ * @returns The error handler middleware.
136
+ */
137
+ getErrorHandler() {
138
+ return this.errorHandler;
139
+ }
140
+ };
141
+ exports.Middleware = Middleware;
142
+ exports.Middleware = Middleware = Middleware_1 = __decorate([
143
+ (0, index_1.provideSingleton)(Middleware_1)
144
+ ], Middleware);
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidateDTO = exports.EnvValidatorProvider = exports.Logger = exports.Provider = void 0;
3
+ exports.ValidateDTO = exports.Env = exports.Logger = exports.Provider = void 0;
4
4
  var provider_service_1 = require("./provider-service");
5
5
  Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return provider_service_1.Provider; } });
6
6
  var logger_service_1 = require("./logger/logger-service");
7
7
  Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_service_1.Logger; } });
8
8
  var env_validator_provider_1 = require("./environment/env-validator.provider");
9
- Object.defineProperty(exports, "EnvValidatorProvider", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
9
+ Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return env_validator_provider_1.EnvValidatorProvider; } });
10
10
  var dto_validator_provider_1 = require("./dto-validator/dto-validator.provider");
11
11
  Object.defineProperty(exports, "ValidateDTO", { enumerable: true, get: function () { return dto_validator_provider_1.ValidateDTO; } });
@@ -0,0 +1,34 @@
1
+ import express from "express";
2
+ import { Container } from "inversify";
3
+ import { AppExpress, IApplicationExpress } from "@expressots/adapter-express";
4
+ /**
5
+ * AppFactory Class
6
+ *
7
+ * Responsible for creating an instance of the Application,
8
+ * either using a custom application type or with provided middlewares.
9
+ */
10
+ declare class AppFactory {
11
+ private static logger;
12
+ /**
13
+ * Creates an instance of the application using a custom application type.
14
+ * @param container - InversifyJS container to resolve dependencies.
15
+ * @param CustomAppType - Custom application class extending Application.
16
+ * @returns Instance of the application.
17
+ */
18
+ static create(container: Container, CustomAppType: new () => AppExpress, httpServerFactory?: new () => AppExpress): Promise<IApplicationExpress>;
19
+ /**
20
+ * Creates an instance of the application with provided middlewares.
21
+ * @param container - InversifyJS container to resolve dependencies.
22
+ * @param middlewares - Array of Express middlewares to be applied.
23
+ * @returns Instance of the application.
24
+ */
25
+ static create(container: Container, middlewares: Array<express.RequestHandler>, httpServerFactory?: new () => AppExpress): Promise<AppExpress>;
26
+ /**
27
+ * Checks if the provided parameter is a custom application type.
28
+ * @param appTypeOrMiddlewares - Custom application class or array of middlewares.
29
+ * @returns True if the provided parameter is a custom application type.
30
+ */
31
+ private static isOpinionated;
32
+ }
33
+ export { AppFactory };
34
+ //# sourceMappingURL=application-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-factory.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/application-factory.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAK9E;;;;;GAKG;AACH,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAC,MAAM,CAAwB;IAC7C;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,UAAU,UAAU,EACnC,iBAAiB,CAAC,EAAE,UAAU,UAAU,GACvC,OAAO,CAAC,mBAAmB,CAAC;IAO/B;;;;;OAKG;WACiB,MAAM,CACxB,SAAS,EAAE,SAAS,EACpB,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAC1C,iBAAiB,CAAC,EAAE,UAAU,UAAU,GACvC,OAAO,CAAC,UAAU,CAAC;IA+DtB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;CAK7B;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -1,3 +1,3 @@
1
- export { AppInstance, Application, ServerEnvironment } from "./application";
2
1
  export { AppContainer } from "./app-container";
2
+ export { AppFactory } from "./application-factory";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/application/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1,31 +1,25 @@
1
1
  import { Response } from "express";
2
- import { interfaces } from "inversify-express-utils";
2
+ import { Controller } from "@expressots/adapter-express";
3
3
  /**
4
4
  * The BaseController class is an abstract base class for controllers.
5
5
  * It provides methods for handling use case calls and sending appropriate responses.
6
6
  * @provide BaseController
7
7
  */
8
- declare abstract class BaseController implements interfaces.Controller {
9
- private serviceName;
10
- /**
11
- * Constructs a new BaseController instance with a specified service name.
12
- * @param serviceName - The name of the service associated with the controller.
13
- */
14
- constructor(serviceName?: string);
8
+ declare abstract class BaseController implements Controller {
15
9
  /**
16
10
  * Calls an asynchronous use case and sends an appropriate response based on the result.
17
11
  * @param useCase - A promise representing the asynchronous use case to call.
18
12
  * @param res - The Express response object.
19
13
  * @param successStatusCode - The HTTP status code to return upon successful execution.
20
14
  */
21
- protected callUseCaseAsync(useCase: Promise<any>, res: any, successStatusCode: number): Promise<any>;
15
+ protected callUseCaseAsync(useCase: Promise<any>, res: Response, successStatusCode: number): Promise<any>;
22
16
  /**
23
17
  * Calls a use case and sends an appropriate response based on the result.
24
18
  * @param useCase - The use case to call.
25
19
  * @param res - The Express response object.
26
20
  * @param successStatusCode - The HTTP status code to return upon successful execution.
27
21
  */
28
- protected callUseCase(useCase: any, res: any, successStatusCode: number): any;
22
+ protected callUseCase(useCase: any, res: Response, successStatusCode: number): any;
29
23
  /**
30
24
  * Synchronously renders a template with the given options using the Express `Response` object's render method.
31
25
  *
@@ -1 +1 @@
1
- {"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU,CAAC,UAAU;IAC5D,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,WAAW,GAAE,MAAW;IAIpC;;;;;OAKG;cACa,gBAAgB,CAC9B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,MAAM;IAK3B;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM;IAIvE;;;;;;;;;;OAUG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,IAAI;IAI5E;;;;;;;;;;OAUG;IACH,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,KAAK,GACX,OAAO,CAAC,MAAM,CAAC;CAUnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"base-controller.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/controller/base-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD;;;;GAIG;AACH,uBACe,cAAe,YAAW,UAAU;IACjD;;;;;OAKG;cACa,gBAAgB,CAC9B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,GAAG,EAAE,QAAQ,EACb,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,GAAG,CAAC;IAIf;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,QAAQ,EACb,iBAAiB,EAAE,MAAM,GACxB,GAAG;IAIN;;;;;;;;;;OAUG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,IAAI;IAI5E;;;;;;;;;;OAUG;IACH,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,QAAQ,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,KAAK,GACX,OAAO,CAAC,MAAM,CAAC;CAUnB;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,4 +1,34 @@
1
+ /**
2
+ * Provides a singleton binding for the given identifier.
3
+ *
4
+ * @remarks
5
+ * Singleton binding ensures that the same instance of a dependency is reused within the entire container.
6
+ *
7
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
8
+ * @returns A fluent interface for further configuring the binding.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * @provideSingleton(ServiceIdentifier)
13
+ * class MyService {}
14
+ * ```
15
+ */
1
16
  declare const provideSingleton: (identifier: any) => (target: any) => any;
17
+ /**
18
+ * Provides a transient binding for the given identifier.
19
+ *
20
+ * @remarks
21
+ * Transient binding ensures that a new instance of a dependency is created every time it is resolved.
22
+ *
23
+ * @param identifier - The identifier (e.g., symbol, string, class) for the dependency being registered.
24
+ * @returns A fluent interface for further configuring the binding.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * @provideTransient(ServiceIdentifier)
29
+ * class MyService {}
30
+ * ```
31
+ */
2
32
  declare const provideTransient: (identifier: any) => (target: any) => any;
3
33
  export { provideSingleton, provideTransient };
4
34
  //# sourceMappingURL=scope-binding.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scope-binding.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/scope-binding.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"scope-binding.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/decorator/scope-binding.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,gBAAgB,eAAgB,GAAG,yBAExC,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC"}
@@ -5,6 +5,7 @@ export * from "./container-module";
5
5
  export * from "./controller";
6
6
  export * from "./decorator";
7
7
  export * from "./error";
8
+ export * from "./middleware";
8
9
  export * from "./provider";
9
10
  export * from "./render";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { IMiddleware, Middleware } from "./middleware-service";
2
+ export { OptionsJson } from "./interfaces/body-parser.interface";
3
+ export { CorsOptions } from "./interfaces/cors.interface";
4
+ export { CompressionOptions } from "./interfaces/compression.interface";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/core/src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import * as http from "http";
4
+ interface OptionsJson {
5
+ /** When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true. */
6
+ inflate?: boolean | undefined;
7
+ /**
8
+ * Controls the maximum request body size. If this is a number,
9
+ * then the value specifies the number of bytes; if it is a string,
10
+ * the value is passed to the bytes library for parsing. Defaults to '100kb'.
11
+ */
12
+ limit?: number | string | undefined;
13
+ /**
14
+ * The type option is used to determine what media type the middleware will parse
15
+ */
16
+ type?: string | Array<string> | ((req: http.IncomingMessage) => any) | undefined;
17
+ /**
18
+ * The verify option, if supplied, is called as verify(req, res, buf, encoding),
19
+ * where buf is a Buffer of the raw request body and encoding is the encoding of the request.
20
+ */
21
+ verify?(req: http.IncomingMessage, res: http.ServerResponse, buf: Buffer, encoding: string): void;
22
+ /**
23
+ *
24
+ * The reviver option is passed directly to JSON.parse as the second argument.
25
+ */
26
+ reviver?(key: string, value: any): any;
27
+ /**
28
+ * When set to `true`, will only accept arrays and objects;
29
+ * when `false` will accept anything JSON.parse accepts. Defaults to `true`.
30
+ */
31
+ strict?: boolean | undefined;
32
+ }
33
+ export { OptionsJson };
34
+ //# sourceMappingURL=body-parser.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-parser.interface.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/middleware/interfaces/body-parser.interface.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,UAAU,WAAW;IACnB,wIAAwI;IACxI,OAAO,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC;;OAEG;IACH,IAAI,CAAC,EACD,MAAM,GACN,KAAK,CAAC,MAAM,CAAC,GACb,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,KAAK,GAAG,CAAC,GACpC,SAAS,CAAC;IACd;;;OAGG;IACH,MAAM,CAAC,CACL,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,GACf,IAAI,CAAC;IACR;;;OAGG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IACvC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B;AAED,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,99 @@
1
+ import express from "express";
2
+ interface CompressionFilter {
3
+ (req: express.Request, res: express.Response): boolean;
4
+ }
5
+ interface CompressionOptions {
6
+ /**
7
+ * @default zlib.constants.Z_DEFAULT_CHUNK or 16384
8
+ * @see {@link https://nodejs.org/api/zlib.html#zlib_memory_usage_tuning| Node.js documentation}
9
+ * @see {@link https://github.com/expressjs/compression#chunksize|chunkSize documentation}
10
+ */
11
+ chunkSize?: number | undefined;
12
+ /**
13
+ * A function to decide if the response should be considered for compression. This function is called as
14
+ * `filter(req, res)` and is expected to return `true` to consider the response for compression, or `false` to
15
+ * not compress the response.
16
+ *
17
+ * The default filter function uses the `compressible` module to determine if `res.getHeader('Content-Type')`
18
+ * is compressible.
19
+ *
20
+ * @see {@link https://github.com/expressjs/compression#filter|`filter` documentation}
21
+ * @see {@link https://www.npmjs.com/package/compressible|compressible module}
22
+ */
23
+ filter?: CompressionFilter | undefined;
24
+ /**
25
+ * The level of zlib compression to apply to responses. A higher level will result in better compression, but
26
+ * will take longer to complete. A lower level will result in less compression, but will be much faster.
27
+ *
28
+ * This is an integer in the range of `0` (no compression) to `9` (maximum compression). The special value `-1`
29
+ * can be used to mean the "default compression level", which is a default compromise between speed and
30
+ * compression (currently equivalent to level 6).
31
+ *
32
+ * - `-1` Default compression level (also `zlib.constants.Z_DEFAULT_COMPRESSION`).
33
+ * - `0` No compression (also `zlib.constants.Z_NO_COMPRESSION`).
34
+ * - `1` Fastest compression (also `zlib.constants.Z_BEST_SPEED`).
35
+ * - `2`
36
+ * - `3`
37
+ * - `4`
38
+ * - `5`
39
+ * - `6` (currently what `zlib.constants.Z_DEFAULT_COMPRESSION` points to).
40
+ * - `7`
41
+ * - `8`
42
+ * - `9` Best compression (also `zlib.constants.Z_BEST_COMPRESSION`).
43
+ *
44
+ * **Note** in the list above, `zlib` is from `zlib = require('zlib')`.
45
+ *
46
+ * @default zlib.constants.DEFAULT_COMPRESSION or -1
47
+ * @see {@link https://github.com/expressjs/compression#level|`level` documentation}
48
+ */
49
+ level?: number | undefined;
50
+ /**
51
+ * This specifies how much memory should be allocated for the internal compression state and is an integer in
52
+ * the range of `1` (minimum level) and `9` (maximum level).
53
+ *
54
+ * @default zlib.constants.DEFAULT_MEMLEVEL or 8
55
+ * @see {@link https://nodejs.org/api/zlib.html#zlib_memory_usage_tuning|Node.js documentation}
56
+ * @see {@link https://github.com/expressjs/compression#memlevel|`memLevel` documentation}
57
+ */
58
+ memLevel?: number | undefined;
59
+ /**
60
+ * This is used to tune the compression algorithm. This value only affects the compression ratio, not the
61
+ * correctness of the compressed output, even if it is not set appropriately.
62
+ *
63
+ * - `zlib.constants.Z_DEFAULT_STRATEGY` Use for normal data.
64
+ * - `zlib.constants.Z_FILTERED` Use for data produced by a filter (or predictor). Filtered data consists mostly of small
65
+ * values with a somewhat random distribution. In this case, the compression algorithm is tuned to compress
66
+ * them better. The effect is to force more Huffman coding and less string matching; it is somewhat intermediate
67
+ * between `zlib.constants.Z_DEFAULT_STRATEGY` and `zlib.constants.Z_HUFFMAN_ONLY`.
68
+ * - `zlib.constants.Z_FIXED` Use to prevent the use of dynamic Huffman codes, allowing for a simpler decoder for special applications.
69
+ * - `zlib.constants.Z_HUFFMAN_ONLY` Use to force Huffman encoding only (no string match).
70
+ * - `zlib.constants.Z_RLE` Use to limit match distances to one (run-length encoding). This is designed to be almost as
71
+ * fast as `zlib.constants.Z_HUFFMAN_ONLY`, but give better compression for PNG image data.
72
+ *
73
+ * **Note** in the list above, `zlib` is from `zlib = require('zlib')`.
74
+ */
75
+ strategy?: number | undefined;
76
+ /**
77
+ * The byte threshold for the response body size before compression is considered for the response, defaults to
78
+ * 1kb. This is a number of bytes or any string accepted by the bytes module.
79
+ *
80
+ * **Note** this is only an advisory setting; if the response size cannot be determined at the time the response
81
+ * headers are written, then it is assumed the response is *over* the threshold. To guarantee the response size
82
+ * can be determined, be sure set a `Content-Length` response header.
83
+ *
84
+ * @see {@link https://www.npmjs.com/package/bytes|`bytes` module}
85
+ * @see {@link https://github.com/expressjs/compression#threshold|`threshold` documentation}
86
+ */
87
+ threshold?: number | string | undefined;
88
+ /**
89
+ * @default zlib.constants.Z_DEFAULT_WINDOWBITS or 15.
90
+ * @see {@link https://nodejs.org/api/zlib.html#zlib_memory_usage_tuning|Node.js documentation}
91
+ */
92
+ windowBits?: number | undefined;
93
+ /**
94
+ * In addition , `zlib` options may be passed in to the options object.
95
+ */
96
+ [property: string]: any;
97
+ }
98
+ export { CompressionOptions };
99
+ //# sourceMappingURL=compression.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compression.interface.d.ts","sourceRoot":"","sources":["../../../../../packages/core/src/middleware/interfaces/compression.interface.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,UAAU,iBAAiB;IACzB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC;CACxD;AAED,UAAU,kBAAkB;IAC1B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3B;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC;;OAEG;IACH,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}