@expressive-tea/core 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 (94) hide show
  1. package/.gitattributes +4 -0
  2. package/.swcrc +61 -0
  3. package/LICENSE +201 -0
  4. package/README.md +627 -0
  5. package/banner.png +0 -0
  6. package/classes/Boot.d.ts +145 -0
  7. package/classes/Boot.js +223 -0
  8. package/classes/Engine.d.ts +63 -0
  9. package/classes/Engine.js +90 -0
  10. package/classes/EngineRegistry.d.ts +154 -0
  11. package/classes/EngineRegistry.js +247 -0
  12. package/classes/LoadBalancer.d.ts +8 -0
  13. package/classes/LoadBalancer.js +28 -0
  14. package/classes/ProxyRoute.d.ts +14 -0
  15. package/classes/ProxyRoute.js +40 -0
  16. package/classes/Settings.d.ts +128 -0
  17. package/classes/Settings.js +172 -0
  18. package/decorators/annotations.d.ts +91 -0
  19. package/decorators/annotations.js +132 -0
  20. package/decorators/env.d.ts +145 -0
  21. package/decorators/env.js +177 -0
  22. package/decorators/health.d.ts +115 -0
  23. package/decorators/health.js +124 -0
  24. package/decorators/module.d.ts +34 -0
  25. package/decorators/module.js +39 -0
  26. package/decorators/proxy.d.ts +28 -0
  27. package/decorators/proxy.js +60 -0
  28. package/decorators/router.d.ts +199 -0
  29. package/decorators/router.js +252 -0
  30. package/decorators/server.d.ts +92 -0
  31. package/decorators/server.js +247 -0
  32. package/engines/constants/constants.d.ts +2 -0
  33. package/engines/constants/constants.js +5 -0
  34. package/engines/health/index.d.ts +120 -0
  35. package/engines/health/index.js +179 -0
  36. package/engines/http/index.d.ts +12 -0
  37. package/engines/http/index.js +59 -0
  38. package/engines/index.d.ts +32 -0
  39. package/engines/index.js +112 -0
  40. package/engines/socketio/index.d.ts +7 -0
  41. package/engines/socketio/index.js +30 -0
  42. package/engines/teacup/index.d.ts +27 -0
  43. package/engines/teacup/index.js +136 -0
  44. package/engines/teapot/index.d.ts +32 -0
  45. package/engines/teapot/index.js +167 -0
  46. package/engines/websocket/index.d.ts +9 -0
  47. package/engines/websocket/index.js +39 -0
  48. package/eslint.config.mjs +138 -0
  49. package/exceptions/BootLoaderExceptions.d.ts +26 -0
  50. package/exceptions/BootLoaderExceptions.js +31 -0
  51. package/exceptions/RequestExceptions.d.ts +75 -0
  52. package/exceptions/RequestExceptions.js +89 -0
  53. package/helpers/boot-helper.d.ts +7 -0
  54. package/helpers/boot-helper.js +84 -0
  55. package/helpers/decorators.d.ts +1 -0
  56. package/helpers/decorators.js +15 -0
  57. package/helpers/promise-helper.d.ts +1 -0
  58. package/helpers/promise-helper.js +6 -0
  59. package/helpers/server.d.ts +35 -0
  60. package/helpers/server.js +141 -0
  61. package/helpers/teapot-helper.d.ts +18 -0
  62. package/helpers/teapot-helper.js +88 -0
  63. package/helpers/websocket-helper.d.ts +3 -0
  64. package/helpers/websocket-helper.js +20 -0
  65. package/images/announcement-01.png +0 -0
  66. package/images/logo-sticky-01.png +0 -0
  67. package/images/logo-wp-01.png +0 -0
  68. package/images/logo.png +0 -0
  69. package/images/zero-oneit.png +0 -0
  70. package/interfaces/index.d.ts +4 -0
  71. package/interfaces/index.js +2 -0
  72. package/inversify.config.d.ts +9 -0
  73. package/inversify.config.js +8 -0
  74. package/libs/classNames.d.ts +1 -0
  75. package/libs/classNames.js +4 -0
  76. package/libs/utilities.d.ts +21910 -0
  77. package/libs/utilities.js +420 -0
  78. package/mixins/module.d.ts +45 -0
  79. package/mixins/module.js +71 -0
  80. package/mixins/proxy.d.ts +46 -0
  81. package/mixins/proxy.js +86 -0
  82. package/mixins/route.d.ts +48 -0
  83. package/mixins/route.js +96 -0
  84. package/package.json +137 -0
  85. package/services/DependencyInjection.d.ts +159 -0
  86. package/services/DependencyInjection.js +201 -0
  87. package/services/WebsocketService.d.ts +18 -0
  88. package/services/WebsocketService.js +47 -0
  89. package/types/core.d.ts +14 -0
  90. package/types/core.js +2 -0
  91. package/types/injection-types.d.ts +6 -0
  92. package/types/injection-types.js +10 -0
  93. package/types/inversify.d.ts +5 -0
  94. package/types/inversify.js +3 -0
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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 */
14
+ const decorators_1 = require("../helpers/decorators");
15
+ const server_1 = require("../helpers/server");
16
+ const commons_2 = require("@expressive-tea/commons");
17
+ const route_1 = require("../mixins/route");
18
+ /**
19
+ * @module Decorators/Router
20
+ */
21
+ /**
22
+ * Route Controller Decorator assign a router point into the module mount-point placeholder and is used just to create
23
+ * a bucket to contains all the endpoints defined by method of the Controller. If mount-point is not defined automati-
24
+ * cally this must considerate mounted on root, but is mandatory define the Controller with this decorator in order
25
+ * to allow Expressive Tea Setting up the Controller as part of a Module.
26
+ *
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
31
+ * @summary Generate a Placeholder endpoint root for controller routes.
32
+ *
33
+ * @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
41
+ */
42
+ function Route(mountpoint = '/') {
43
+ return (RouterClass) => {
44
+ return (0, route_1.Routerize)(RouterClass, mountpoint);
45
+ };
46
+ }
47
+ /**
48
+ * Define a GET Endpoint response over the controller router and can define in which route should be responds and
49
+ * by default this is responding to everything on the controller root path.
50
+ * @decorator {MethodDecorator} Get - Create an GET Response over the designed route.
51
+ * @summary Define a GET Controller Endpoint on Controller.
52
+ * @param {string} route URL Part to mount create a handler.
53
+ * @example
54
+ * {REPLACE-AT}Route('/')
55
+ * class GenericController {
56
+ * {REPLACE-AT}Get() // This Response to all GET Requests for controller route.
57
+ * methodError() {}
58
+ *
59
+ * {REPLACE-AT}Get('/data') // This Response to "/data" GET Requests for controller route.
60
+ * methodData() {}
61
+ * }
62
+ *
63
+ */
64
+ function Get(route = '*') {
65
+ return (0, server_1.generateRoute)(route, 'get');
66
+ }
67
+ /**
68
+ * Define a POST Endpoint response over the controller router and can define in which route should be responds and
69
+ * by default this is responding to everything on the controller root path.
70
+ * @decorator {MethodDecorator} POST - Create an POST Response over the designed route.
71
+ * @summary Define a POST Controller Endpoint on Controller.
72
+ * @param {string} route URL Part to mount create a handler.
73
+ * @example
74
+ * {REPLACE-AT}Route('/')
75
+ * class GenericController {
76
+ * {REPLACE-AT}Post() // This Response to all GET Requests for controller route.
77
+ * methodError() {}
78
+ *
79
+ * {REPLACE-AT}Post('/data') // This Response to "/data" GET Requests for controller route.
80
+ * methodData() {}
81
+ * }
82
+ *
83
+ */
84
+ function Post(route = '*') {
85
+ return (0, server_1.generateRoute)(route, 'post');
86
+ }
87
+ /**
88
+ * Define a PUT Endpoint response over the controller router and can define in which route should be responds and
89
+ * by default this is responding to everything on the controller root path.
90
+ * @decorator {MethodDecorator} Put - Create an PUT Response over the designed route.
91
+ * @summary Define a PUT Controller Endpoint on Controller.
92
+ * @param {string} route URL Part to mount create a handler.
93
+ * @example
94
+ * {REPLACE-AT}Route('/')
95
+ * class GenericController {
96
+ * {REPLACE-AT}Put() // This Response to all PUT Requests for controller route.
97
+ * methodError() {}
98
+ *
99
+ * {REPLACE-AT}Put('/data') // This Response to "/data" PUT Requests for controller route.
100
+ * methodData() {}
101
+ * }
102
+ *
103
+ */
104
+ function Put(route = '*') {
105
+ return (0, server_1.generateRoute)(route, 'put');
106
+ }
107
+ /**
108
+ * Define a PATCH Endpoint response over the controller router and can define in which route should be responds and
109
+ * by default this is responding to everything on the controller root path.
110
+ * @decorator {MethodDecorator} Patch - Create an PATCH Response over the designed route.
111
+ * @summary Define a PATCH Controller Endpoint on Controller.
112
+ * @param {string} route URL Part to mount create a handler.
113
+ * @example
114
+ * {REPLACE-AT}Route('/')
115
+ * class GenericController {
116
+ * {REPLACE-AT}Patch() // This Response to all PATCH Requests for controller route.
117
+ * methodError() {}
118
+ *
119
+ * {REPLACE-AT}Patch('/data') // This Response to "/data" PATCH Requests for controller route.
120
+ * methodData() {}
121
+ * }
122
+ *
123
+ */
124
+ function Patch(route = '*') {
125
+ return (0, server_1.generateRoute)(route, 'patch');
126
+ }
127
+ /**
128
+ * Define a DELETE Endpoint response over the controller router and can define in which route should be responds and
129
+ * by default this is responding to everything on the controller root path.
130
+ * @decorator {MethodDecorator} Delete - Create an DELETE Response over the designed route.
131
+ * @summary Define a DELETE Controller Endpoint on Controller.
132
+ * @param {string} route URL Part to mount create a handler.
133
+ * @example
134
+ * {REPLACE-AT}Route('/')
135
+ * class GenericController {
136
+ * {REPLACE-AT}Delete() // This Response to all DELETE Requests for controller route.
137
+ * methodError() {}
138
+ *
139
+ * {REPLACE-AT}Delete('/data') // This Response to "/data" DELETE Requests for controller route.
140
+ * methodData() {}
141
+ * }
142
+ *
143
+ */
144
+ function Delete(route = '*') {
145
+ return (0, server_1.generateRoute)(route, 'delete');
146
+ }
147
+ /**
148
+ * Define a Route path parameter transformation method as mentioned on Express this is just call by controller endpoints
149
+ * route paths and it helps to define logic on each route path parameters. Example, you can require transform userId
150
+ * parameter and added to request object.
151
+ *
152
+ * The method to response this must follow the Express callback notation (Request, Response, Next, paramValue) which
153
+ * also must be use Next method to allow continue the process flow from Express.
154
+ * @decorator {MethodDecorator} Param - Create a transformation middleware for router parameters.
155
+ * @summary Define a Parameter transformation on router path..
156
+ * @param {string} route URL Part to mount create a handler.
157
+ * @example
158
+ * {REPLACE-AT}Route('/')
159
+ * class GenericController {
160
+ * {REPLACE-AT}Param('userId') // This Response to all GET Requests for controller route.
161
+ * async methodError(req, res, next, param, id) {
162
+ * const user = await User.find(id)
163
+ * try {
164
+ * if(!user) throw new Error('User not Found');
165
+ *
166
+ * req.user = user;
167
+ * next();
168
+ * } catch(e) {
169
+ * next(e);
170
+ * }
171
+ * }
172
+ *
173
+ * {REPLACE-AT}Get('/:userId') // This Response to "/:userId" GET Requests for controller route.
174
+ * methodData(req, res) {
175
+ * res.json(req.user);
176
+ * }
177
+ * }
178
+ *
179
+ */
180
+ function Param(route = '*') {
181
+ return (0, server_1.generateRoute)(route, 'param');
182
+ }
183
+ /**
184
+ * Middleware Decorator is following the middleware functionality inheritance from Express framework itself and follow
185
+ * the same rules, that execute any code before response the request and can change the current request or response
186
+ * object, and requires use next callback to pass control to next middleware.
187
+ *
188
+ * This define the middlewares at Controller and Controller methods level, for application levels please see the
189
+ * Plug Decorator which can be useful to declare at that level..
190
+ * @decorator {MethodDecorator|ClassDecorator} Middleware - Attach a middleware definition on the root route or endpoint
191
+ * routes.
192
+ * @summary Assign a middleware to the Controller or Method route path flow.
193
+ * @example
194
+ * {REPLACE-AT}Middleware((req, res, next) {
195
+ * req.controllerName = 'Example';
196
+ * next();
197
+ * })
198
+ * class ExampleController {
199
+ * {REPLACE-AT}Get('/someResponse')
200
+ * {REPLACE-AT}Middleware((req, res, next) {
201
+ * req.methodName = 'someResponse';
202
+ * next();
203
+ * })
204
+ * someRespone(req, res) {
205
+ * res.send(`${req.controllerName}:${req.methodName}`);
206
+ * }
207
+ * }
208
+ *
209
+ * @param {Function} middleware Register a middleware over router.
210
+ */
211
+ function Middleware(middleware) {
212
+ return (target, property, descriptor) => {
213
+ if (property) {
214
+ routeMiddleware(target, descriptor, middleware);
215
+ }
216
+ else {
217
+ rootMiddleware(target, middleware);
218
+ }
219
+ };
220
+ }
221
+ /**
222
+ * Will generate a GET route to respond rendering a view template setting up before; the controller method <b>MUST</b>
223
+ * return an object in order to fulfilled the local variables into the view.
224
+ * @decorator {MethodDecorator} View - Create a Vew Response over the designed route.
225
+ * @summary Define a View response endpoint on Controller.
226
+ * @param {string} viewName - View render layout name defined by configuration.
227
+ * @param {string} route - URL Part to mount create a handler.
228
+ * @return {object} Controller must return and object as local variables for the view.
229
+ * @example
230
+ * {REPLACE-AT}Route('/')
231
+ * class GenericController {
232
+ * {REPLACE-AT}View('login', '/view') // This Response to all GET Requests for controller route.
233
+ * methodError() {}
234
+ * }
235
+ *
236
+ */
237
+ function View(viewName, route) {
238
+ route = route !== null && route !== void 0 ? route : `/${viewName}`;
239
+ return (target, propertyKey, descriptor) => {
240
+ (0, decorators_1.addAnnotation)('view', target, propertyKey, viewName);
241
+ (0, server_1.router)('get', route, target, descriptor.value, propertyKey);
242
+ };
243
+ }
244
+ function rootMiddleware(target, middleware) {
245
+ const existedRoutesHandlers = commons_1.Metadata.get(commons_2.ROUTER_MIDDLEWARES_KEY, target) || [];
246
+ existedRoutesHandlers.unshift(middleware);
247
+ commons_1.Metadata.set(commons_2.ROUTER_MIDDLEWARES_KEY, existedRoutesHandlers, target);
248
+ }
249
+ function routeMiddleware(_, descriptor, middleware) {
250
+ descriptor.value.$middlewares = descriptor.value.$middlewares || [];
251
+ descriptor.value.$middlewares.unshift(middleware);
252
+ }
@@ -0,0 +1,92 @@
1
+ import { type Express } from 'express';
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';
5
+ /**
6
+ * Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
7
+ * be useful to attach a simple Express Server configuration.
8
+ *
9
+ * @decorator {ClassDecorator} Plug - Simple Plugin Decorator.
10
+ * @summary This Decorators is add plugin initialization to one of the selected stages.
11
+ * @param {ExpressiveTeaModuleProps} options
12
+ * @param {BOOT_STAGES} stage Boot Stage where the plugin should run or initialize.
13
+ * @param {string} name Plugin Name (recommended short names)
14
+ * @param {Function} method A Function to initialize the plugin, it will get a express application as argument.
15
+ * @param {boolean} required A Flag to let know if this is a hard requirement.
16
+ * @example
17
+ * {REPLACE-AT}Plug(BOOT_STAGES.BOOT_DEPENDENCIES, 'test', s => console.log, true)
18
+ * class Example extends Boot {}
19
+ */
20
+ export declare function Plug(stage: BOOT_STAGES, name: string, method: (server?: Express, ...extraArgs: unknown[]) => Promise<void> | void, required?: boolean): (target: any) => void;
21
+ /**
22
+ * Since version 1.1.0 Expressive Tea allow to use external plugins using the node
23
+ * package @expressive-tea/plugin. This plugin engine allows to create more complex plugin configuration and provision
24
+ * since is allowing multi Boot Stage configuration and check other plugin dependencies.
25
+ *
26
+ * @decorator {ClassDecorator} Pour - Use Expressive Tea plugin definition instance.
27
+ * @summary Attach an Expressive Tea Definition Instance.
28
+ * @param Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
29
+ * @param pluginArgs any[] - Arguments passed directly to the Plugin constructor.
30
+ * @version 1.1.0
31
+ * @link https://www.npmjs.com/package/@expressive-tea/plugin Expressive Tea Plugin
32
+ */
33
+ export declare function Pour(Plugin: Newable<any>, ...pluginArgs: any[]): (target: any) => void;
34
+ /**
35
+ * Server Settings Singleton Class Decorator this Provide the Configuration to the server or another component on
36
+ * the projects,is working as a container to store user and library settings.
37
+ * @decorator {ClassDecorator} ServerSettings - Declares Server Settings.
38
+ * @summary Declare Server Properties.
39
+ * @param {ExpressiveTeaModuleProps} options
40
+ */
41
+ export declare function ServerSettings(options?: ExpressiveTeaServerProps): (target: any) => any;
42
+ /**
43
+ * Create a new middleware function to serve files from within a given root directory. The file to serve will be
44
+ * determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404
45
+ * response, this module will instead call next() to move on to the next middleware, allowing for stacking
46
+ * and fall-backs. Check it out {@link https://expressjs.com/en/4x/api.html#express.static Express Static} to more
47
+ * information.
48
+ * @summary Static File Server
49
+ * @param {string} root - Root directory
50
+ * @param {string} [virtual=null] - Virtual Path
51
+ * @param {object} [options={}] - Static Server Options
52
+ * @decorator {ClassDecorator} Static - Create an Static mount static file server on root directory
53
+ * with virtual path if defined.
54
+ */
55
+ export declare function Static(root: string, virtual?: string | null, options?: ExpressiveTeaStaticFileServer): (target: any) => void;
56
+ /**
57
+ * Set or Update Express application settings, and allow to change the behavior of the server where is listed on the
58
+ * next link {@link http://expressjs.com/en/4x/api.html#app.settings.table Express Settings} as this is using the same
59
+ * principle of app.set you should understand that is only apply the special settings mentioned above.
60
+ * @summary Express Setting Directive
61
+ * @param {string} name - Express Directive Setting Name
62
+ * @param {*} settings - Setting Arguments
63
+ * @decorator {ClassDecorator} ExpressDirective - Set a Express App Setting.
64
+ */
65
+ export declare function ExpressDirective(name: string, ...settings: any[]): (target: any) => void;
66
+ /**
67
+ * Setting Property Decorator Automatically assign a settings declared on Settings Service into the decorated property.
68
+ * All properties will contains the settings value or undefined if current settings is not founded.
69
+ * @decorator {PropertyDecorator} Setting - Assign Server Settings to Property as default value.
70
+ * @summary Automatically assign a settings declared on the Server Settings decorator to a class property.
71
+ */
72
+ export declare function Setting(): (target: any, propertyName: string) => any;
73
+ /**
74
+ * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
75
+ * and register modules.
76
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
77
+ * @summary This register the Module Classes created by the user.
78
+ * @param Modules
79
+ */
80
+ export declare function Modules(Modules: any[]): (target: any) => void;
81
+ export declare function Proxies(proxyContainers: any[]): (target: any) => void;
82
+ /**
83
+ * Register Module Method Decorator this Method Decorator is used at bootstrap level and should decorate the start
84
+ * method with a Module Class.
85
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
86
+ * @summary <b>ONLY</b> Decorate Start Method, this register the Module Classes created by the user.
87
+ * @param {Class} Module
88
+ * @deprecated Use the new decorator Modules that allow add modules into registered modules.
89
+ */
90
+ export declare function RegisterModule(Module: any): (_: any, __: any) => never;
91
+ export declare function Teapot(teapotSettings: ExpressiveTeaPotSettings): (target: object) => void;
92
+ export declare function Teacup(teacupSettings: ExpressiveTeaCupSettings): (target: object) => void;
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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");
16
+ const Settings_1 = require("../classes/Settings");
17
+ const commons_2 = require("@expressive-tea/commons");
18
+ const DependencyInjection_1 = require("../services/DependencyInjection");
19
+ /**
20
+ * Define the Main Plugins Properties.
21
+ * @typedef {Object} ExpressiveTeaPluginProps
22
+ * @property {string} name - Define a Plugin Name
23
+ * @property {number} priority - Define a Plugin Priority.
24
+ * @summary Plugin Properties
25
+ */
26
+ /**
27
+ * Declare an annotation only usable at Class Level Declaration
28
+ * @typedef {Function} ClassDecorator()
29
+ * @summary Class Decorator
30
+ * @example
31
+ * {REPLACE-AT}Decorator
32
+ * class Decorated {}
33
+ */
34
+ /**
35
+ * Declare an annotation only usable at Method Class Level Declaration
36
+ * @typedef {Function} MethodDecorator
37
+ * @summary Method Decorator
38
+ * @example
39
+ * class Decorated {
40
+ * {REPLACE-AT}MethodDecorator()
41
+ * decoratedMethod(){}
42
+ * }
43
+ *
44
+ */
45
+ /**
46
+ * Declare an annotation only usable at Property Class Level Declaration
47
+ * @typedef {Function} PropertyDecorator
48
+ * @summary Property Decorator
49
+ * @example
50
+ * class Decorated {
51
+ * {REPLACE-AT}PropertyDecorator()
52
+ * decoratedProperty:string = '';
53
+ * }
54
+ */
55
+ /**
56
+ * Declare an annotation only usable at Property Class Level Declaration
57
+ * @module Decorators/Server
58
+ */
59
+ function getStages(target) {
60
+ return commons_1.Metadata.get(commons_2.BOOT_STAGES_KEY, target) || {};
61
+ }
62
+ function getRegisteredPlugins(target) {
63
+ return commons_1.Metadata.get(commons_2.PLUGINS_KEY, target) || [];
64
+ }
65
+ function getStage(stage, target) {
66
+ const stages = getStages(target);
67
+ if (!stages[stage]) {
68
+ stages[stage] = [];
69
+ }
70
+ return stages[stage];
71
+ }
72
+ function setStage(stage, value, target) {
73
+ const stages = getStages(target);
74
+ stages[stage] = value;
75
+ commons_1.Metadata.set(commons_2.BOOT_STAGES_KEY, stages, target);
76
+ }
77
+ function setPlugins(plugins, target) {
78
+ commons_1.Metadata.set(commons_2.PLUGINS_KEY, plugins, target);
79
+ }
80
+ /**
81
+ * Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
82
+ * be useful to attach a simple Express Server configuration.
83
+ *
84
+ * @decorator {ClassDecorator} Plug - Simple Plugin Decorator.
85
+ * @summary This Decorators is add plugin initialization to one of the selected stages.
86
+ * @param {ExpressiveTeaModuleProps} options
87
+ * @param {BOOT_STAGES} stage Boot Stage where the plugin should run or initialize.
88
+ * @param {string} name Plugin Name (recommended short names)
89
+ * @param {Function} method A Function to initialize the plugin, it will get a express application as argument.
90
+ * @param {boolean} required A Flag to let know if this is a hard requirement.
91
+ * @example
92
+ * {REPLACE-AT}Plug(BOOT_STAGES.BOOT_DEPENDENCIES, 'test', s => console.log, true)
93
+ * class Example extends Boot {}
94
+ */
95
+ function Plug(stage, name, method, required = false) {
96
+ return (target) => {
97
+ const selectedStage = getStage(stage, target);
98
+ selectedStage.unshift({ method, required, name });
99
+ setStage(stage, selectedStage, target);
100
+ };
101
+ }
102
+ /**
103
+ * Since version 1.1.0 Expressive Tea allow to use external plugins using the node
104
+ * package @expressive-tea/plugin. This plugin engine allows to create more complex plugin configuration and provision
105
+ * since is allowing multi Boot Stage configuration and check other plugin dependencies.
106
+ *
107
+ * @decorator {ClassDecorator} Pour - Use Expressive Tea plugin definition instance.
108
+ * @summary Attach an Expressive Tea Definition Instance.
109
+ * @param Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
110
+ * @param pluginArgs any[] - Arguments passed directly to the Plugin constructor.
111
+ * @version 1.1.0
112
+ * @link https://www.npmjs.com/package/@expressive-tea/plugin Expressive Tea Plugin
113
+ */
114
+ function Pour(Plugin, ...pluginArgs) {
115
+ return (target) => {
116
+ const stages = getStages(target);
117
+ DependencyInjection_1.default.Container.bind(Plugin)
118
+ .toDynamicValue(() => new Plugin(...pluginArgs))
119
+ .inSingletonScope();
120
+ const instance = DependencyInjection_1.default.Container.get(Plugin);
121
+ const plugins = instance.register(Settings_1.default.getInstance(target).getOptions(), getRegisteredPlugins(target));
122
+ commons_2.BOOT_STAGES_LIST.forEach(STAGE => {
123
+ setStage(STAGE, (stages[STAGE] || []).concat(instance.getRegisteredStage(STAGE)), target);
124
+ });
125
+ setPlugins((0, utilities_1.orderBy)(plugins, ['priority'], ['asc']), target);
126
+ };
127
+ }
128
+ /**
129
+ * Server Settings Singleton Class Decorator this Provide the Configuration to the server or another component on
130
+ * the projects,is working as a container to store user and library settings.
131
+ * @decorator {ClassDecorator} ServerSettings - Declares Server Settings.
132
+ * @summary Declare Server Properties.
133
+ * @param {ExpressiveTeaModuleProps} options
134
+ */
135
+ function ServerSettings(options = {}) {
136
+ return (target) => {
137
+ Settings_1.default.getInstance(target).merge(options);
138
+ return target;
139
+ };
140
+ }
141
+ /**
142
+ * Create a new middleware function to serve files from within a given root directory. The file to serve will be
143
+ * determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404
144
+ * response, this module will instead call next() to move on to the next middleware, allowing for stacking
145
+ * and fall-backs. Check it out {@link https://expressjs.com/en/4x/api.html#express.static Express Static} to more
146
+ * information.
147
+ * @summary Static File Server
148
+ * @param {string} root - Root directory
149
+ * @param {string} [virtual=null] - Virtual Path
150
+ * @param {object} [options={}] - Static Server Options
151
+ * @decorator {ClassDecorator} Static - Create an Static mount static file server on root directory
152
+ * with virtual path if defined.
153
+ */
154
+ function Static(root, virtual = null, options = {}) {
155
+ return (target) => {
156
+ if ((0, utilities_1.isNil)(root)) {
157
+ throw new Error('Root must be defined');
158
+ }
159
+ const registeredStatics = commons_1.Metadata.get(commons_2.REGISTERED_STATIC_KEY, target) || [];
160
+ registeredStatics.unshift({ root, options, virtual });
161
+ commons_1.Metadata.set(commons_2.REGISTERED_STATIC_KEY, registeredStatics, target);
162
+ };
163
+ }
164
+ /**
165
+ * Set or Update Express application settings, and allow to change the behavior of the server where is listed on the
166
+ * next link {@link http://expressjs.com/en/4x/api.html#app.settings.table Express Settings} as this is using the same
167
+ * principle of app.set you should understand that is only apply the special settings mentioned above.
168
+ * @summary Express Setting Directive
169
+ * @param {string} name - Express Directive Setting Name
170
+ * @param {*} settings - Setting Arguments
171
+ * @decorator {ClassDecorator} ExpressDirective - Set a Express App Setting.
172
+ */
173
+ function ExpressDirective(name, ...settings) {
174
+ return (target) => {
175
+ if (!commons_2.EXPRESS_DIRECTIVES.includes(name)) {
176
+ throw new Error(`Directive Name ${name} is not valid express behavior setting`);
177
+ }
178
+ const registeredDirectives = commons_1.Metadata.get(commons_2.REGISTERED_DIRECTIVES_KEY, target) || [];
179
+ registeredDirectives.unshift({ name, settings });
180
+ commons_1.Metadata.set(commons_2.REGISTERED_DIRECTIVES_KEY, registeredDirectives, target);
181
+ };
182
+ }
183
+ /**
184
+ * Setting Property Decorator Automatically assign a settings declared on Settings Service into the decorated property.
185
+ * All properties will contains the settings value or undefined if current settings is not founded.
186
+ * @decorator {PropertyDecorator} Setting - Assign Server Settings to Property as default value.
187
+ * @summary Automatically assign a settings declared on the Server Settings decorator to a class property.
188
+ */
189
+ function Setting() {
190
+ return (target, propertyName) => {
191
+ Object.defineProperty(target, propertyName, {
192
+ configurable: false,
193
+ get: () => Settings_1.default.getInstance(target).get(propertyName)
194
+ });
195
+ };
196
+ }
197
+ /**
198
+ * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
199
+ * and register modules.
200
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
201
+ * @summary This register the Module Classes created by the user.
202
+ * @param Modules
203
+ */
204
+ function Modules(Modules) {
205
+ return (target) => {
206
+ for (const Module of Modules) {
207
+ const registeredModules = commons_1.Metadata.get(commons_2.REGISTERED_MODULE_KEY, target, 'start') || [];
208
+ registeredModules.unshift(Module);
209
+ commons_1.Metadata.set(commons_2.REGISTERED_MODULE_KEY, registeredModules, target, 'start');
210
+ }
211
+ };
212
+ }
213
+ function Proxies(proxyContainers) {
214
+ return (target) => {
215
+ for (const proxyContainer of proxyContainers) {
216
+ const registeredProxyContainers = commons_1.Metadata.get(commons_2.ROUTER_PROXIES_KEY, target) || [];
217
+ registeredProxyContainers.unshift(proxyContainer);
218
+ commons_1.Metadata.set(commons_2.ROUTER_PROXIES_KEY, registeredProxyContainers, target);
219
+ }
220
+ };
221
+ }
222
+ /**
223
+ * Register Module Method Decorator this Method Decorator is used at bootstrap level and should decorate the start
224
+ * method with a Module Class.
225
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
226
+ * @summary <b>ONLY</b> Decorate Start Method, this register the Module Classes created by the user.
227
+ * @param {Class} Module
228
+ * @deprecated Use the new decorator Modules that allow add modules into registered modules.
229
+ */
230
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
231
+ function RegisterModule(Module) {
232
+ return (_, __) => {
233
+ throw new Error('RegisterModule is deprecated, use the new decorator Modules that allow add modules into registered modules.');
234
+ };
235
+ }
236
+ function Teapot(teapotSettings) {
237
+ return (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
+ };
241
+ }
242
+ function Teacup(teacupSettings) {
243
+ return (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);
246
+ };
247
+ }
@@ -0,0 +1,2 @@
1
+ export declare const SOCKET_IO_INSTANCE_KEY = "SOCKETIO:INSTANCE";
2
+ export declare const SOCKET_IO_SECURE_INSTANCE_KEY = "SOCKETIO:INSTANCE:SECURE";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SOCKET_IO_SECURE_INSTANCE_KEY = exports.SOCKET_IO_INSTANCE_KEY = void 0;
4
+ exports.SOCKET_IO_INSTANCE_KEY = 'SOCKETIO:INSTANCE';
5
+ exports.SOCKET_IO_SECURE_INSTANCE_KEY = 'SOCKETIO:INSTANCE:SECURE';