@zerooneit/expressive-tea 1.3.0-beta.6 → 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 (78) hide show
  1. package/.swcrc +61 -0
  2. package/README.md +564 -174
  3. package/classes/Boot.d.ts +89 -2
  4. package/classes/Boot.js +149 -31
  5. package/classes/Engine.d.ts +58 -10
  6. package/classes/Engine.js +69 -9
  7. package/classes/EngineRegistry.d.ts +154 -0
  8. package/classes/EngineRegistry.js +247 -0
  9. package/classes/LoadBalancer.js +2 -5
  10. package/classes/ProxyRoute.js +5 -5
  11. package/classes/Settings.d.ts +31 -2
  12. package/classes/Settings.js +64 -11
  13. package/decorators/annotations.d.ts +1 -1
  14. package/decorators/annotations.js +17 -17
  15. package/decorators/env.d.ts +145 -0
  16. package/decorators/env.js +177 -0
  17. package/decorators/health.d.ts +115 -0
  18. package/decorators/health.js +124 -0
  19. package/decorators/module.d.ts +15 -16
  20. package/decorators/module.js +14 -24
  21. package/decorators/proxy.d.ts +26 -11
  22. package/decorators/proxy.js +35 -49
  23. package/decorators/router.d.ts +17 -16
  24. package/decorators/router.js +31 -53
  25. package/decorators/server.d.ts +7 -7
  26. package/decorators/server.js +48 -50
  27. package/engines/health/index.d.ts +120 -0
  28. package/engines/health/index.js +179 -0
  29. package/engines/http/index.d.ts +6 -10
  30. package/engines/http/index.js +18 -17
  31. package/engines/index.d.ts +32 -0
  32. package/engines/index.js +112 -0
  33. package/engines/socketio/index.d.ts +2 -4
  34. package/engines/socketio/index.js +14 -7
  35. package/engines/teacup/index.d.ts +12 -2
  36. package/engines/teacup/index.js +56 -10
  37. package/engines/teapot/index.d.ts +12 -2
  38. package/engines/teapot/index.js +58 -17
  39. package/engines/websocket/index.d.ts +1 -1
  40. package/engines/websocket/index.js +8 -3
  41. package/eslint.config.mjs +138 -0
  42. package/exceptions/RequestExceptions.d.ts +3 -3
  43. package/helpers/boot-helper.d.ts +4 -4
  44. package/helpers/boot-helper.js +27 -22
  45. package/helpers/decorators.js +7 -6
  46. package/helpers/promise-helper.d.ts +1 -1
  47. package/helpers/promise-helper.js +1 -2
  48. package/helpers/server.d.ts +31 -5
  49. package/helpers/server.js +98 -60
  50. package/helpers/teapot-helper.d.ts +2 -3
  51. package/helpers/teapot-helper.js +34 -8
  52. package/helpers/websocket-helper.d.ts +1 -3
  53. package/helpers/websocket-helper.js +3 -3
  54. package/interfaces/index.d.ts +1 -1
  55. package/inversify.config.d.ts +4 -4
  56. package/inversify.config.js +1 -1
  57. package/libs/utilities.d.ts +21910 -0
  58. package/libs/utilities.js +420 -0
  59. package/mixins/module.d.ts +45 -0
  60. package/mixins/module.js +71 -0
  61. package/mixins/proxy.d.ts +46 -0
  62. package/mixins/proxy.js +86 -0
  63. package/mixins/route.d.ts +48 -0
  64. package/mixins/route.js +96 -0
  65. package/package.json +85 -73
  66. package/services/DependencyInjection.d.ts +94 -8
  67. package/services/DependencyInjection.js +121 -3
  68. package/services/WebsocketService.d.ts +2 -4
  69. package/services/WebsocketService.js +5 -3
  70. package/types/core.d.ts +14 -0
  71. package/types/core.js +2 -0
  72. package/types/injection-types.d.ts +6 -0
  73. package/types/injection-types.js +10 -0
  74. package/types/inversify.d.ts +5 -0
  75. package/types/inversify.js +3 -0
  76. package/.eslintrc.js +0 -44
  77. package/tsconfig.linter.json +0 -24
  78. package/tslint-to-eslint-config.log +0 -12
@@ -1,13 +1,28 @@
1
- import { type ExpressiveTeaProxyOptions, type ExpressiveTeaProxyProperty, type MethodDecorator } from '@expressive-tea/commons/types';
2
- import { type Express, type RequestHandler } from 'express';
3
- export declare function ProxyContainer(source: string, targetUrl: string): <T extends new (...args: any[]) => any>(ProxyContainerClass: T) => {
4
- new (...args: any[]): {
5
- [x: string]: any;
6
- readonly source: string;
7
- readonly target: string;
8
- readonly proxyHandler: RequestHandler;
9
- __register(server: Express): void;
10
- };
11
- } & T;
1
+ import { type ExpressiveTeaProxyOptions, type ExpressiveTeaProxyProperty, type MethodDecorator } from '@expressive-tea/commons';
2
+ import { type ProxifiedClass } from '../mixins/proxy';
3
+ import { type Constructor } from '../types/core';
4
+ /**
5
+ * ProxyContainer decorator - Creates an HTTP proxy for a microservice
6
+ *
7
+ * Transforms a class into an HTTP proxy that forwards requests from a source path
8
+ * to a target URL. Supports custom request/response transformations and options.
9
+ *
10
+ * @template TBase - The base constructor type being decorated
11
+ * @param {string} source - The source path to proxy from (e.g., '/api')
12
+ * @param {string} targetUrl - The target URL to proxy to (e.g., 'http://api.example.com')
13
+ * @returns {(target: TBase) => ProxifiedClass<TBase>} Decorator function that returns a proxified class
14
+ *
15
+ * @example
16
+ * {REPLACE-AT}ProxyContainer('/api', 'http://api.example.com')
17
+ * class ApiProxy {
18
+ * {REPLACE-AT}ProxyOption('host')
19
+ * getHost() {
20
+ * return 'http://api.example.com';
21
+ * }
22
+ * }
23
+ *
24
+ * @since 1.0.0
25
+ */
26
+ export declare function ProxyContainer<TBase extends Constructor = Constructor>(source: string, targetUrl: string): (ProxyContainerClass: TBase) => ProxifiedClass<TBase>;
12
27
  export declare function ProxyOption(option: ExpressiveTeaProxyOptions): MethodDecorator;
13
28
  export declare function ProxyProperty(option: ExpressiveTeaProxyProperty, value: any): PropertyDecorator;
@@ -1,74 +1,60 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProxyProperty = exports.ProxyOption = exports.ProxyContainer = void 0;
4
- const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
5
- const httpProxy = require("express-http-proxy");
6
- const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
7
- const lodash_1 = require("lodash");
3
+ exports.ProxyContainer = ProxyContainer;
4
+ exports.ProxyOption = ProxyOption;
5
+ exports.ProxyProperty = ProxyProperty;
6
+ const commons_1 = require("@expressive-tea/commons");
7
+ const commons_2 = require("@expressive-tea/commons");
8
8
  const RequestExceptions_1 = require("../exceptions/RequestExceptions");
9
- const constants_1 = require("@expressive-tea/commons/constants");
10
- const NON_ASYNC_METHODS = ['host'];
9
+ const commons_3 = require("@expressive-tea/commons");
10
+ const proxy_1 = require("../mixins/proxy");
11
+ const NON_ASYNC_METHODS = new Set(['host']);
12
+ /**
13
+ * ProxyContainer decorator - Creates an HTTP proxy for a microservice
14
+ *
15
+ * Transforms a class into an HTTP proxy that forwards requests from a source path
16
+ * to a target URL. Supports custom request/response transformations and options.
17
+ *
18
+ * @template TBase - The base constructor type being decorated
19
+ * @param {string} source - The source path to proxy from (e.g., '/api')
20
+ * @param {string} targetUrl - The target URL to proxy to (e.g., 'http://api.example.com')
21
+ * @returns {(target: TBase) => ProxifiedClass<TBase>} Decorator function that returns a proxified class
22
+ *
23
+ * @example
24
+ * {REPLACE-AT}ProxyContainer('/api', 'http://api.example.com')
25
+ * class ApiProxy {
26
+ * {REPLACE-AT}ProxyOption('host')
27
+ * getHost() {
28
+ * return 'http://api.example.com';
29
+ * }
30
+ * }
31
+ *
32
+ * @since 1.0.0
33
+ */
11
34
  function ProxyContainer(source, targetUrl) {
12
35
  return (ProxyContainerClass) => {
13
- class ExpressiveTeaProxy extends ProxyContainerClass {
14
- constructor(...args) {
15
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
16
- super(...args);
17
- this.source = source;
18
- this.target = targetUrl;
19
- const options = {};
20
- const host = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, constants_1.PROXY_METHODS.HOST);
21
- for (const value of Object.values(constants_1.PROXY_METHODS)) {
22
- if (value !== constants_1.PROXY_METHODS.HOST) {
23
- options[value] = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, value);
24
- }
25
- }
26
- for (const value of Object.values(constants_1.PROXY_PROPERTIES)) {
27
- const key = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, value);
28
- if (!(0, lodash_1.isUndefined)(key)) {
29
- // @ts-expect-error:next-line
30
- options[value] = this[key];
31
- }
32
- }
33
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
34
- this.proxyHandler = httpProxy(host ? host.value.bind(this) : this.target);
35
- }
36
- __register(server) {
37
- const proxyMetadata = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, (0, object_helper_1.getClass)(this));
38
- console.info(`[PROXY - ${proxyMetadata.name}] ${this.source} -> ${this.target}`);
39
- server.use(this.source, this.proxyHandler);
40
- }
41
- }
42
- ;
43
36
  const settings = {
44
37
  source,
45
38
  targetUrl,
46
39
  name: ProxyContainerClass.name
47
40
  };
48
- Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, settings, ProxyContainerClass);
49
- return ExpressiveTeaProxy;
41
+ commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, settings, ProxyContainerClass);
42
+ return (0, proxy_1.Proxify)(ProxyContainerClass, source, targetUrl);
50
43
  };
51
44
  }
52
- exports.ProxyContainer = ProxyContainer;
53
45
  function ProxyOption(option) {
54
46
  return (target, propertyKey, descriptor) => {
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
56
- if (NON_ASYNC_METHODS.includes(option) && (0, object_helper_1.isAsyncFunction)(descriptor.value)) {
47
+ if (NON_ASYNC_METHODS.has(option) && (0, commons_2.isAsyncFunction)(descriptor.value)) {
57
48
  throw new RequestExceptions_1.GenericRequestException(`${String(propertyKey)} must not be declared as Async Function.`);
58
49
  }
59
- Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, descriptor, target, option);
50
+ commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, descriptor, target, option);
60
51
  };
61
52
  }
62
- exports.ProxyOption = ProxyOption;
63
53
  function ProxyProperty(option, value) {
64
54
  return (target, propertyKey) => {
65
- Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, propertyKey, target, option);
66
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
- let currentValue = target[propertyKey];
55
+ commons_1.Metadata.set(commons_3.PROXY_SETTING_KEY, propertyKey, target, option);
68
56
  Object.defineProperty(target, propertyKey, {
69
57
  get: () => value,
70
- set: () => { currentValue = value; }
71
58
  });
72
59
  };
73
60
  }
74
- exports.ProxyProperty = ProxyProperty;
@@ -1,6 +1,7 @@
1
- import { Router } from 'express';
2
- import { type ExpressiveTeaHandlerOptions } from '@expressive-tea/commons/interfaces';
3
- import { type ClassDecorator, type ExpressMiddlewareHandler, type MethodDecorator } from '@expressive-tea/commons/types';
1
+ import { type ClassDecorator, type MethodDecorator } from '@expressive-tea/commons';
2
+ import { type RouterizedClass } from '../mixins/route';
3
+ import { type Constructor, TFunction } from '../types/core';
4
+ import { type RequestHandler } from 'express';
4
5
  /**
5
6
  * @module Decorators/Router
6
7
  */
@@ -11,21 +12,21 @@ import { type ClassDecorator, type ExpressMiddlewareHandler, type MethodDecorato
11
12
  * to allow Expressive Tea Setting up the Controller as part of a Module.
12
13
  *
13
14
  * @decorator {ClassDecorator} Route - Assign a route to controller endpoints.
15
+ * @template TBase - The base constructor type being decorated
16
+ * @param {string} mountpoint - Register the url part to mount the Controller (default: '/')
17
+ * @returns {(target: TBase) => RouterizedClass<TBase>} Decorator function that returns a routerized class
14
18
  * @summary Generate a Placeholder endpoint root for controller routes.
15
- * @param {string} mountpoint Register the url part to mount the Controller.
19
+ *
16
20
  * @example
17
- * {REPLACE-AT}Route('/)
18
- * class Example {}
21
+ * {REPLACE-AT}Route('/users')
22
+ * class UserController {
23
+ * {REPLACE-AT}Get('/')
24
+ * getUsers() { return ['user1', 'user2']; }
25
+ * }
26
+ *
27
+ * @since 1.0.0
19
28
  */
20
- export declare function Route(mountpoint?: string): <T extends new (...args: any[]) => any>(RouterClass: T) => {
21
- new (...args: any[]): {
22
- [x: string]: any;
23
- readonly router: Router;
24
- readonly mountpoint: string;
25
- __mount(parent: Router): this;
26
- __registerHandler(options: ExpressiveTeaHandlerOptions): ExpressMiddlewareHandler;
27
- };
28
- } & T;
29
+ export declare function Route<TBase extends Constructor = Constructor>(mountpoint?: string): (RouterClass: TBase) => RouterizedClass<TBase>;
29
30
  /**
30
31
  * Define a GET Endpoint response over the controller router and can define in which route should be responds and
31
32
  * by default this is responding to everything on the controller root path.
@@ -178,7 +179,7 @@ export declare function Param(route?: string): (target: object, propertyKey: str
178
179
  *
179
180
  * @param {Function} middleware Register a middleware over router.
180
181
  */
181
- export declare function Middleware(middleware: (...args: any[]) => any): ClassDecorator & MethodDecorator;
182
+ export declare function Middleware(middleware: RequestHandler | TFunction<RequestHandler>): ClassDecorator & MethodDecorator;
182
183
  /**
183
184
  * Will generate a GET route to respond rendering a view template setting up before; the controller method <b>MUST</b>
184
185
  * return an object in order to fulfilled the local variables into the view.
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.View = exports.Middleware = exports.Param = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.Route = void 0;
4
- const express_1 = require("express");
5
- const lodash_1 = require("lodash");
6
- const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
3
+ exports.Route = Route;
4
+ exports.Get = Get;
5
+ exports.Post = Post;
6
+ exports.Put = Put;
7
+ exports.Patch = Patch;
8
+ exports.Delete = Delete;
9
+ exports.Param = Param;
10
+ exports.Middleware = Middleware;
11
+ exports.View = View;
12
+ const commons_1 = require("@expressive-tea/commons");
13
+ /* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */
7
14
  const decorators_1 = require("../helpers/decorators");
8
15
  const server_1 = require("../helpers/server");
9
- const constants_1 = require("@expressive-tea/commons/constants");
16
+ const commons_2 = require("@expressive-tea/commons");
17
+ const route_1 = require("../mixins/route");
10
18
  /**
11
19
  * @module Decorators/Router
12
20
  */
@@ -17,47 +25,25 @@ const constants_1 = require("@expressive-tea/commons/constants");
17
25
  * to allow Expressive Tea Setting up the Controller as part of a Module.
18
26
  *
19
27
  * @decorator {ClassDecorator} Route - Assign a route to controller endpoints.
28
+ * @template TBase - The base constructor type being decorated
29
+ * @param {string} mountpoint - Register the url part to mount the Controller (default: '/')
30
+ * @returns {(target: TBase) => RouterizedClass<TBase>} Decorator function that returns a routerized class
20
31
  * @summary Generate a Placeholder endpoint root for controller routes.
21
- * @param {string} mountpoint Register the url part to mount the Controller.
32
+ *
22
33
  * @example
23
- * {REPLACE-AT}Route('/)
24
- * class Example {}
34
+ * {REPLACE-AT}Route('/users')
35
+ * class UserController {
36
+ * {REPLACE-AT}Get('/')
37
+ * getUsers() { return ['user1', 'user2']; }
38
+ * }
39
+ *
40
+ * @since 1.0.0
25
41
  */
26
42
  function Route(mountpoint = '/') {
27
43
  return (RouterClass) => {
28
- return class ExpressiveTeaRoute extends RouterClass {
29
- constructor(...args) {
30
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
31
- super(...args);
32
- const handlers = Metadata_1.default.get(constants_1.ROUTER_HANDLERS_KEY, this) || [];
33
- this.router = (0, express_1.Router)();
34
- this.mountpoint = mountpoint;
35
- (0, lodash_1.each)(handlers, h => {
36
- var _a;
37
- const middlewares = (_a = h.handler.$middlewares) !== null && _a !== void 0 ? _a : [];
38
- this.router[h.verb](h.route, ...middlewares, this.__registerHandler(h));
39
- });
40
- }
41
- __mount(parent) {
42
- const rootMiddlewares = Metadata_1.default.get(constants_1.ROUTER_MIDDLEWARES_KEY, this) || [];
43
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
44
- parent.use(this.mountpoint, ...rootMiddlewares, this.router);
45
- return this;
46
- }
47
- __registerHandler(options) {
48
- const decoratedArguments = Metadata_1.default.get(constants_1.ARGUMENTS_KEY, options.target, options.propertyKey);
49
- const annotations = Metadata_1.default.get(constants_1.ROUTER_ANNOTATIONS_KEY, options.target, options.propertyKey);
50
- return server_1.executeRequest.bind({
51
- options,
52
- decoratedArguments,
53
- annotations,
54
- self: this
55
- });
56
- }
57
- };
44
+ return (0, route_1.Routerize)(RouterClass, mountpoint);
58
45
  };
59
46
  }
60
- exports.Route = Route;
61
47
  /**
62
48
  * Define a GET Endpoint response over the controller router and can define in which route should be responds and
63
49
  * by default this is responding to everything on the controller root path.
@@ -78,7 +64,6 @@ exports.Route = Route;
78
64
  function Get(route = '*') {
79
65
  return (0, server_1.generateRoute)(route, 'get');
80
66
  }
81
- exports.Get = Get;
82
67
  /**
83
68
  * Define a POST Endpoint response over the controller router and can define in which route should be responds and
84
69
  * by default this is responding to everything on the controller root path.
@@ -99,7 +84,6 @@ exports.Get = Get;
99
84
  function Post(route = '*') {
100
85
  return (0, server_1.generateRoute)(route, 'post');
101
86
  }
102
- exports.Post = Post;
103
87
  /**
104
88
  * Define a PUT Endpoint response over the controller router and can define in which route should be responds and
105
89
  * by default this is responding to everything on the controller root path.
@@ -120,7 +104,6 @@ exports.Post = Post;
120
104
  function Put(route = '*') {
121
105
  return (0, server_1.generateRoute)(route, 'put');
122
106
  }
123
- exports.Put = Put;
124
107
  /**
125
108
  * Define a PATCH Endpoint response over the controller router and can define in which route should be responds and
126
109
  * by default this is responding to everything on the controller root path.
@@ -141,7 +124,6 @@ exports.Put = Put;
141
124
  function Patch(route = '*') {
142
125
  return (0, server_1.generateRoute)(route, 'patch');
143
126
  }
144
- exports.Patch = Patch;
145
127
  /**
146
128
  * Define a DELETE Endpoint response over the controller router and can define in which route should be responds and
147
129
  * by default this is responding to everything on the controller root path.
@@ -162,7 +144,6 @@ exports.Patch = Patch;
162
144
  function Delete(route = '*') {
163
145
  return (0, server_1.generateRoute)(route, 'delete');
164
146
  }
165
- exports.Delete = Delete;
166
147
  /**
167
148
  * Define a Route path parameter transformation method as mentioned on Express this is just call by controller endpoints
168
149
  * route paths and it helps to define logic on each route path parameters. Example, you can require transform userId
@@ -199,7 +180,6 @@ exports.Delete = Delete;
199
180
  function Param(route = '*') {
200
181
  return (0, server_1.generateRoute)(route, 'param');
201
182
  }
202
- exports.Param = Param;
203
183
  /**
204
184
  * Middleware Decorator is following the middleware functionality inheritance from Express framework itself and follow
205
185
  * the same rules, that execute any code before response the request and can change the current request or response
@@ -230,15 +210,14 @@ exports.Param = Param;
230
210
  */
231
211
  function Middleware(middleware) {
232
212
  return (target, property, descriptor) => {
233
- if (!property) {
234
- rootMiddleware(target, middleware);
213
+ if (property) {
214
+ routeMiddleware(target, descriptor, middleware);
235
215
  }
236
216
  else {
237
- routeMiddleware(target, descriptor, middleware);
217
+ rootMiddleware(target, middleware);
238
218
  }
239
219
  };
240
220
  }
241
- exports.Middleware = Middleware;
242
221
  /**
243
222
  * Will generate a GET route to respond rendering a view template setting up before; the controller method <b>MUST</b>
244
223
  * return an object in order to fulfilled the local variables into the view.
@@ -262,13 +241,12 @@ function View(viewName, route) {
262
241
  (0, server_1.router)('get', route, target, descriptor.value, propertyKey);
263
242
  };
264
243
  }
265
- exports.View = View;
266
244
  function rootMiddleware(target, middleware) {
267
- const existedRoutesHandlers = Metadata_1.default.get(constants_1.ROUTER_MIDDLEWARES_KEY, target) || [];
245
+ const existedRoutesHandlers = commons_1.Metadata.get(commons_2.ROUTER_MIDDLEWARES_KEY, target) || [];
268
246
  existedRoutesHandlers.unshift(middleware);
269
- Metadata_1.default.set(constants_1.ROUTER_MIDDLEWARES_KEY, existedRoutesHandlers, target);
247
+ commons_1.Metadata.set(commons_2.ROUTER_MIDDLEWARES_KEY, existedRoutesHandlers, target);
270
248
  }
271
- function routeMiddleware(target, descriptor, middleware) {
249
+ function routeMiddleware(_, descriptor, middleware) {
272
250
  descriptor.value.$middlewares = descriptor.value.$middlewares || [];
273
251
  descriptor.value.$middlewares.unshift(middleware);
274
252
  }
@@ -1,6 +1,7 @@
1
1
  import { type Express } from 'express';
2
- import { type BOOT_STAGES } from '@expressive-tea/commons/constants';
3
- import { type ExpressiveTeaPotSettings, type ExpressiveTeaServerProps, type ExpressiveTeaStaticFileServer, type ExpressiveTeaCupSettings } from '@expressive-tea/commons/interfaces';
2
+ import { type BOOT_STAGES } from '@expressive-tea/commons';
3
+ import { type ExpressiveTeaPotSettings, type ExpressiveTeaServerProps, type ExpressiveTeaStaticFileServer, type ExpressiveTeaCupSettings } from '@expressive-tea/commons';
4
+ import { Newable } from 'inversify';
4
5
  /**
5
6
  * Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
6
7
  * be useful to attach a simple Express Server configuration.
@@ -16,7 +17,7 @@ import { type ExpressiveTeaPotSettings, type ExpressiveTeaServerProps, type Expr
16
17
  * {REPLACE-AT}Plug(BOOT_STAGES.BOOT_DEPENDENCIES, 'test', s => console.log, true)
17
18
  * class Example extends Boot {}
18
19
  */
19
- export declare function Plug(stage: BOOT_STAGES, name: string, method: (server?: Express | never, ...extraArgs: unknown[]) => Promise<any> | any, required?: boolean): (target: any) => void;
20
+ export declare function Plug(stage: BOOT_STAGES, name: string, method: (server?: Express, ...extraArgs: unknown[]) => Promise<void> | void, required?: boolean): (target: any) => void;
20
21
  /**
21
22
  * Since version 1.1.0 Expressive Tea allow to use external plugins using the node
22
23
  * package @expressive-tea/plugin. This plugin engine allows to create more complex plugin configuration and provision
@@ -29,7 +30,7 @@ export declare function Plug(stage: BOOT_STAGES, name: string, method: (server?:
29
30
  * @version 1.1.0
30
31
  * @link https://www.npmjs.com/package/@expressive-tea/plugin Expressive Tea Plugin
31
32
  */
32
- export declare function Pour(Plugin: any, ...pluginArgs: any[]): (target: any) => void;
33
+ export declare function Pour(Plugin: Newable<any>, ...pluginArgs: any[]): (target: any) => void;
33
34
  /**
34
35
  * Server Settings Singleton Class Decorator this Provide the Configuration to the server or another component on
35
36
  * the projects,is working as a container to store user and library settings.
@@ -67,9 +68,8 @@ export declare function ExpressDirective(name: string, ...settings: any[]): (tar
67
68
  * All properties will contains the settings value or undefined if current settings is not founded.
68
69
  * @decorator {PropertyDecorator} Setting - Assign Server Settings to Property as default value.
69
70
  * @summary Automatically assign a settings declared on the Server Settings decorator to a class property.
70
- * @param {string} settingName The Setting name tha
71
71
  */
72
- export declare function Setting(settingName: string): (target: any, propertyName: string) => any;
72
+ export declare function Setting(): (target: any, propertyName: string) => any;
73
73
  /**
74
74
  * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
75
75
  * and register modules.
@@ -87,6 +87,6 @@ export declare function Proxies(proxyContainers: any[]): (target: any) => void;
87
87
  * @param {Class} Module
88
88
  * @deprecated Use the new decorator Modules that allow add modules into registered modules.
89
89
  */
90
- export declare function RegisterModule(Module: any): (target: any, property: string | symbol) => void;
90
+ export declare function RegisterModule(Module: any): (_: any, __: any) => never;
91
91
  export declare function Teapot(teapotSettings: ExpressiveTeaPotSettings): (target: object) => void;
92
92
  export declare function Teacup(teacupSettings: ExpressiveTeaCupSettings): (target: object) => void;
@@ -1,10 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Teacup = exports.Teapot = exports.RegisterModule = exports.Proxies = exports.Modules = exports.Setting = exports.ExpressDirective = exports.Static = exports.ServerSettings = exports.Pour = exports.Plug = void 0;
4
- const lodash_1 = require("lodash");
5
- const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
3
+ exports.Plug = Plug;
4
+ exports.Pour = Pour;
5
+ exports.ServerSettings = ServerSettings;
6
+ exports.Static = Static;
7
+ exports.ExpressDirective = ExpressDirective;
8
+ exports.Setting = Setting;
9
+ exports.Modules = Modules;
10
+ exports.Proxies = Proxies;
11
+ exports.RegisterModule = RegisterModule;
12
+ exports.Teapot = Teapot;
13
+ exports.Teacup = Teacup;
14
+ const utilities_1 = require("../libs/utilities");
15
+ const commons_1 = require("@expressive-tea/commons");
6
16
  const Settings_1 = require("../classes/Settings");
7
- const constants_1 = require("@expressive-tea/commons/constants");
17
+ const commons_2 = require("@expressive-tea/commons");
18
+ const DependencyInjection_1 = require("../services/DependencyInjection");
8
19
  /**
9
20
  * Define the Main Plugins Properties.
10
21
  * @typedef {Object} ExpressiveTeaPluginProps
@@ -46,10 +57,10 @@ const constants_1 = require("@expressive-tea/commons/constants");
46
57
  * @module Decorators/Server
47
58
  */
48
59
  function getStages(target) {
49
- return Metadata_1.default.get(constants_1.BOOT_STAGES_KEY, target) || {};
60
+ return commons_1.Metadata.get(commons_2.BOOT_STAGES_KEY, target) || {};
50
61
  }
51
62
  function getRegisteredPlugins(target) {
52
- return Metadata_1.default.get(constants_1.PLUGINS_KEY, target) || [];
63
+ return commons_1.Metadata.get(commons_2.PLUGINS_KEY, target) || [];
53
64
  }
54
65
  function getStage(stage, target) {
55
66
  const stages = getStages(target);
@@ -61,10 +72,10 @@ function getStage(stage, target) {
61
72
  function setStage(stage, value, target) {
62
73
  const stages = getStages(target);
63
74
  stages[stage] = value;
64
- Metadata_1.default.set(constants_1.BOOT_STAGES_KEY, stages, target);
75
+ commons_1.Metadata.set(commons_2.BOOT_STAGES_KEY, stages, target);
65
76
  }
66
77
  function setPlugins(plugins, target) {
67
- Metadata_1.default.set(constants_1.PLUGINS_KEY, plugins, target);
78
+ commons_1.Metadata.set(commons_2.PLUGINS_KEY, plugins, target);
68
79
  }
69
80
  /**
70
81
  * Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
@@ -88,7 +99,6 @@ function Plug(stage, name, method, required = false) {
88
99
  setStage(stage, selectedStage, target);
89
100
  };
90
101
  }
91
- exports.Plug = Plug;
92
102
  /**
93
103
  * Since version 1.1.0 Expressive Tea allow to use external plugins using the node
94
104
  * package @expressive-tea/plugin. This plugin engine allows to create more complex plugin configuration and provision
@@ -104,15 +114,17 @@ exports.Plug = Plug;
104
114
  function Pour(Plugin, ...pluginArgs) {
105
115
  return (target) => {
106
116
  const stages = getStages(target);
107
- const instance = new Plugin(...pluginArgs);
117
+ DependencyInjection_1.default.Container.bind(Plugin)
118
+ .toDynamicValue(() => new Plugin(...pluginArgs))
119
+ .inSingletonScope();
120
+ const instance = DependencyInjection_1.default.Container.get(Plugin);
108
121
  const plugins = instance.register(Settings_1.default.getInstance(target).getOptions(), getRegisteredPlugins(target));
109
- constants_1.BOOT_STAGES_LIST.forEach(STAGE => {
122
+ commons_2.BOOT_STAGES_LIST.forEach(STAGE => {
110
123
  setStage(STAGE, (stages[STAGE] || []).concat(instance.getRegisteredStage(STAGE)), target);
111
124
  });
112
- setPlugins((0, lodash_1.orderBy)(plugins, ['priority'], ['asc']), target);
125
+ setPlugins((0, utilities_1.orderBy)(plugins, ['priority'], ['asc']), target);
113
126
  };
114
127
  }
115
- exports.Pour = Pour;
116
128
  /**
117
129
  * Server Settings Singleton Class Decorator this Provide the Configuration to the server or another component on
118
130
  * the projects,is working as a container to store user and library settings.
@@ -121,12 +133,11 @@ exports.Pour = Pour;
121
133
  * @param {ExpressiveTeaModuleProps} options
122
134
  */
123
135
  function ServerSettings(options = {}) {
124
- return target => {
136
+ return (target) => {
125
137
  Settings_1.default.getInstance(target).merge(options);
126
138
  return target;
127
139
  };
128
140
  }
129
- exports.ServerSettings = ServerSettings;
130
141
  /**
131
142
  * Create a new middleware function to serve files from within a given root directory. The file to serve will be
132
143
  * determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404
@@ -141,16 +152,15 @@ exports.ServerSettings = ServerSettings;
141
152
  * with virtual path if defined.
142
153
  */
143
154
  function Static(root, virtual = null, options = {}) {
144
- return target => {
145
- if ((0, lodash_1.isNil)(root)) {
155
+ return (target) => {
156
+ if ((0, utilities_1.isNil)(root)) {
146
157
  throw new Error('Root must be defined');
147
158
  }
148
- const registeredStatics = Metadata_1.default.get(constants_1.REGISTERED_STATIC_KEY, target) || [];
159
+ const registeredStatics = commons_1.Metadata.get(commons_2.REGISTERED_STATIC_KEY, target) || [];
149
160
  registeredStatics.unshift({ root, options, virtual });
150
- Metadata_1.default.set(constants_1.REGISTERED_STATIC_KEY, registeredStatics, target);
161
+ commons_1.Metadata.set(commons_2.REGISTERED_STATIC_KEY, registeredStatics, target);
151
162
  };
152
163
  }
153
- exports.Static = Static;
154
164
  /**
155
165
  * Set or Update Express application settings, and allow to change the behavior of the server where is listed on the
156
166
  * next link {@link http://expressjs.com/en/4x/api.html#app.settings.table Express Settings} as this is using the same
@@ -161,24 +171,22 @@ exports.Static = Static;
161
171
  * @decorator {ClassDecorator} ExpressDirective - Set a Express App Setting.
162
172
  */
163
173
  function ExpressDirective(name, ...settings) {
164
- return target => {
165
- if (!constants_1.EXPRESS_DIRECTIVES.includes(name)) {
174
+ return (target) => {
175
+ if (!commons_2.EXPRESS_DIRECTIVES.includes(name)) {
166
176
  throw new Error(`Directive Name ${name} is not valid express behavior setting`);
167
177
  }
168
- const registeredDirectives = Metadata_1.default.get(constants_1.REGISTERED_DIRECTIVES_KEY, target) || [];
178
+ const registeredDirectives = commons_1.Metadata.get(commons_2.REGISTERED_DIRECTIVES_KEY, target) || [];
169
179
  registeredDirectives.unshift({ name, settings });
170
- Metadata_1.default.set(constants_1.REGISTERED_DIRECTIVES_KEY, registeredDirectives, target);
180
+ commons_1.Metadata.set(commons_2.REGISTERED_DIRECTIVES_KEY, registeredDirectives, target);
171
181
  };
172
182
  }
173
- exports.ExpressDirective = ExpressDirective;
174
183
  /**
175
184
  * Setting Property Decorator Automatically assign a settings declared on Settings Service into the decorated property.
176
185
  * All properties will contains the settings value or undefined if current settings is not founded.
177
186
  * @decorator {PropertyDecorator} Setting - Assign Server Settings to Property as default value.
178
187
  * @summary Automatically assign a settings declared on the Server Settings decorator to a class property.
179
- * @param {string} settingName The Setting name tha
180
188
  */
181
- function Setting(settingName) {
189
+ function Setting() {
182
190
  return (target, propertyName) => {
183
191
  Object.defineProperty(target, propertyName, {
184
192
  configurable: false,
@@ -186,7 +194,6 @@ function Setting(settingName) {
186
194
  });
187
195
  };
188
196
  }
189
- exports.Setting = Setting;
190
197
  /**
191
198
  * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
192
199
  * and register modules.
@@ -195,25 +202,23 @@ exports.Setting = Setting;
195
202
  * @param Modules
196
203
  */
197
204
  function Modules(Modules) {
198
- return target => {
205
+ return (target) => {
199
206
  for (const Module of Modules) {
200
- const registeredModules = Metadata_1.default.get(constants_1.REGISTERED_MODULE_KEY, target, 'start') || [];
207
+ const registeredModules = commons_1.Metadata.get(commons_2.REGISTERED_MODULE_KEY, target, 'start') || [];
201
208
  registeredModules.unshift(Module);
202
- Metadata_1.default.set(constants_1.REGISTERED_MODULE_KEY, registeredModules, target, 'start');
209
+ commons_1.Metadata.set(commons_2.REGISTERED_MODULE_KEY, registeredModules, target, 'start');
203
210
  }
204
211
  };
205
212
  }
206
- exports.Modules = Modules;
207
213
  function Proxies(proxyContainers) {
208
- return target => {
214
+ return (target) => {
209
215
  for (const proxyContainer of proxyContainers) {
210
- const registeredProxyContainers = Metadata_1.default.get(constants_1.ROUTER_PROXIES_KEY, target) || [];
216
+ const registeredProxyContainers = commons_1.Metadata.get(commons_2.ROUTER_PROXIES_KEY, target) || [];
211
217
  registeredProxyContainers.unshift(proxyContainer);
212
- Metadata_1.default.set(constants_1.ROUTER_PROXIES_KEY, registeredProxyContainers, target);
218
+ commons_1.Metadata.set(commons_2.ROUTER_PROXIES_KEY, registeredProxyContainers, target);
213
219
  }
214
220
  };
215
221
  }
216
- exports.Proxies = Proxies;
217
222
  /**
218
223
  * Register Module Method Decorator this Method Decorator is used at bootstrap level and should decorate the start
219
224
  * method with a Module Class.
@@ -222,28 +227,21 @@ exports.Proxies = Proxies;
222
227
  * @param {Class} Module
223
228
  * @deprecated Use the new decorator Modules that allow add modules into registered modules.
224
229
  */
230
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
225
231
  function RegisterModule(Module) {
226
- return (target, property) => {
227
- if (property !== 'start') {
228
- throw new Error('Register Module needs to decorate ONLY start method');
229
- }
230
- const registeredModules = Metadata_1.default.get(constants_1.REGISTERED_MODULE_KEY, target, property) || [];
231
- registeredModules.push(Module);
232
- Metadata_1.default.set(constants_1.REGISTERED_MODULE_KEY, registeredModules, target, property);
232
+ return (_, __) => {
233
+ throw new Error('RegisterModule is deprecated, use the new decorator Modules that allow add modules into registered modules.');
233
234
  };
234
235
  }
235
- exports.RegisterModule = RegisterModule;
236
236
  function Teapot(teapotSettings) {
237
237
  return (target) => {
238
- Metadata_1.default.set(constants_1.ASSIGN_TEAPOT_KEY, true, target, 'isTeapotActive');
239
- Metadata_1.default.set(constants_1.ASSIGN_TEAPOT_KEY, teapotSettings, target);
238
+ commons_1.Metadata.set(commons_2.ASSIGN_TEAPOT_KEY, true, target, 'isTeapotActive');
239
+ commons_1.Metadata.set(commons_2.ASSIGN_TEAPOT_KEY, teapotSettings, target);
240
240
  };
241
241
  }
242
- exports.Teapot = Teapot;
243
242
  function Teacup(teacupSettings) {
244
243
  return (target) => {
245
- Metadata_1.default.set(constants_1.ASSIGN_TEACUP_KEY, true, target, 'isTeacupActive');
246
- Metadata_1.default.set(constants_1.ASSIGN_TEACUP_KEY, teacupSettings, target);
244
+ commons_1.Metadata.set(commons_2.ASSIGN_TEACUP_KEY, true, target, 'isTeacupActive');
245
+ commons_1.Metadata.set(commons_2.ASSIGN_TEACUP_KEY, teacupSettings, target);
247
246
  };
248
247
  }
249
- exports.Teacup = Teacup;