@zerooneit/expressive-tea 1.3.0-beta.4 → 1.3.0-beta.6

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 (48) hide show
  1. package/.eslintrc.js +44 -0
  2. package/.gitattributes +4 -0
  3. package/classes/Boot.d.ts +7 -4
  4. package/classes/Boot.js +53 -46
  5. package/classes/Engine.d.ts +15 -0
  6. package/classes/Engine.js +30 -0
  7. package/classes/LoadBalancer.js +1 -1
  8. package/classes/ProxyRoute.d.ts +3 -3
  9. package/decorators/annotations.d.ts +1 -1
  10. package/decorators/module.d.ts +4 -3
  11. package/decorators/module.js +2 -1
  12. package/decorators/proxy.d.ts +2 -2
  13. package/decorators/proxy.js +5 -1
  14. package/decorators/router.d.ts +4 -4
  15. package/decorators/router.js +6 -4
  16. package/decorators/server.d.ts +4 -4
  17. package/engines/constants/constants.d.ts +2 -0
  18. package/engines/constants/constants.js +5 -0
  19. package/engines/http/index.d.ts +5 -6
  20. package/engines/http/index.js +20 -22
  21. package/engines/socketio/index.d.ts +9 -0
  22. package/engines/socketio/index.js +23 -0
  23. package/engines/teacup/index.d.ts +5 -7
  24. package/engines/teacup/index.js +35 -52
  25. package/engines/teapot/index.d.ts +9 -10
  26. package/engines/teapot/index.js +51 -81
  27. package/engines/websocket/index.d.ts +5 -5
  28. package/engines/websocket/index.js +10 -13
  29. package/exceptions/RequestExceptions.d.ts +1 -1
  30. package/helpers/boot-helper.d.ts +2 -2
  31. package/helpers/boot-helper.js +3 -2
  32. package/helpers/promise-helper.d.ts +1 -0
  33. package/helpers/promise-helper.js +7 -0
  34. package/helpers/server.d.ts +5 -5
  35. package/helpers/server.js +12 -10
  36. package/helpers/teapot-helper.d.ts +6 -4
  37. package/helpers/teapot-helper.js +19 -4
  38. package/helpers/websocket-helper.d.ts +2 -2
  39. package/interfaces/index.d.ts +4 -0
  40. package/interfaces/index.js +2 -0
  41. package/inversify.config.d.ts +4 -4
  42. package/package.json +42 -33
  43. package/services/DependencyInjection.d.ts +4 -2
  44. package/services/DependencyInjection.js +2 -2
  45. package/services/WebsocketService.d.ts +2 -2
  46. package/tsconfig.linter.json +24 -0
  47. package/tslint-to-eslint-config.log +12 -0
  48. package/.circleci/config.yml +0 -58
package/.eslintrc.js ADDED
@@ -0,0 +1,44 @@
1
+ /*
2
+ 👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3
+ https://github.com/typescript-eslint/tslint-to-eslint-config
4
+
5
+ It represents the closest reasonable ESLint configuration to this
6
+ project's original TSLint configuration.
7
+
8
+ We recommend eventually switching this configuration to extend from
9
+ the recommended rulesets in typescript-eslint.
10
+ https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11
+
12
+ Happy linting! 💖
13
+ */
14
+ module.exports = {
15
+ env: {
16
+ browser: true,
17
+ es6: true,
18
+ node: true
19
+ },
20
+ extends: ['love', 'prettier'],
21
+ parser: '@typescript-eslint/parser',
22
+ parserOptions: {
23
+ project: 'tsconfig.linter.json',
24
+ sourceType: 'module'
25
+ },
26
+ plugins: ['eslint-plugin-jsdoc', 'eslint-plugin-prefer-arrow', '@typescript-eslint'],
27
+ root: true,
28
+ rules: {
29
+ semi: 'off',
30
+ '@typescript-eslint/array-type': ['error', { default: 'array'}],
31
+ '@typescript-eslint/semi': 'off',
32
+ '@typescript-eslint/return-await': 'off',
33
+ '@typescript-eslint/strict-boolean-expressions': 'off',
34
+ '@typescript-eslint/explicit-function-return-type': [0, {allowExpressions: true}],
35
+ '@typescript-eslint/no-extraneous-class': 'off',
36
+ '@typescript-eslint/no-unsafe-argument': 'warn',
37
+ 'no-duplicate-imports': 'off'
38
+ },
39
+ ignorePatterns: [
40
+ 'benchmark/**/*.ts',
41
+ '__test__/mock/*',
42
+ '__test__/**/helper/*',
43
+ ]
44
+ };
package/.gitattributes ADDED
@@ -0,0 +1,4 @@
1
+ /.yarn/** linguist-vendored
2
+ /.yarn/releases/* binary
3
+ /.yarn/plugins/**/* binary
4
+ /.pnp.* binary linguist-generated
package/classes/Boot.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  import 'reflect-metadata';
2
- import '../inversify.config';
3
- import { Express } from 'express';
2
+ import { type Express } from 'express';
3
+ import { type ExpressiveTeaApplication } from '@expressive-tea/commons/interfaces';
4
4
  import Settings from '../classes/Settings';
5
- import { ExpressiveTeaApplication } from '@expressive-tea/commons/interfaces';
6
5
  /**
7
6
  * Expressive Tea Application interface is the response from an started application, contains the express application
8
7
  * and a node http server instance.
9
8
  * @typedef {Object} ExpressiveTeaApplication
10
9
  * @property {Express} application - Express Application Instance
11
- * @property {HTTPServer} server - HTTP Server Object
10
+ * @property { HTTPServer } server - HTTP Server Object
12
11
  * @summary Application Interface
13
12
  */
14
13
  /**
@@ -37,6 +36,7 @@ declare abstract class Boot {
37
36
  * @summary Express Application instance internal property.
38
37
  */
39
38
  private readonly server;
39
+ private readonly containerDI;
40
40
  constructor();
41
41
  /**
42
42
  * Get Express Application
@@ -51,5 +51,8 @@ declare abstract class Boot {
51
51
  * @returns {Promise<ExpressiveTeaApplication>}
52
52
  */
53
53
  start(): Promise<ExpressiveTeaApplication>;
54
+ private initializeEngines;
55
+ private initializeHttp;
56
+ private initializeContainer;
54
57
  }
55
58
  export default Boot;
package/classes/Boot.js CHANGED
@@ -1,27 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("reflect-metadata");
4
- require("../inversify.config");
5
- const $P = require("bluebird");
6
- // tslint:disable-next-line:no-duplicate-imports
4
+ const inversify_config_1 = require("../inversify.config");
7
5
  const express = require("express");
6
+ const http_1 = require("../engines/http");
7
+ const websocket_1 = require("../engines/websocket");
8
+ const index_1 = require("../engines/teapot/index");
9
+ const teacup_1 = require("../engines/teacup");
10
+ const Engine_1 = require("../classes/Engine");
11
+ const Settings_1 = require("../classes/Settings");
12
+ const index_2 = require("../engines/socketio/index");
8
13
  const fs = require("fs");
9
14
  const http = require("http");
10
15
  const https = require("https");
11
- const Settings_1 = require("../classes/Settings");
12
- const constants_1 = require("@expressive-tea/commons/constants");
13
- const index_1 = require("../engines/http/index");
14
- const index_2 = require("../engines/websocket/index");
15
- const index_3 = require("../engines/teapot/index");
16
- const teacup_1 = require("../engines/teacup");
17
- // tslint:disable-next-line:no-duplicate-imports
18
- const inversify_config_1 = require("../inversify.config");
19
16
  /**
20
17
  * Expressive Tea Application interface is the response from an started application, contains the express application
21
18
  * and a node http server instance.
22
19
  * @typedef {Object} ExpressiveTeaApplication
23
20
  * @property {Express} application - Express Application Instance
24
- * @property {HTTPServer} server - HTTP Server Object
21
+ * @property { HTTPServer } server - HTTP Server Object
25
22
  * @summary Application Interface
26
23
  */
27
24
  /**
@@ -42,6 +39,7 @@ class Boot {
42
39
  * @summary Express Application instance internal property.
43
40
  */
44
41
  this.server = express();
42
+ this.containerDI = inversify_config_1.default.createChild();
45
43
  this.settings = Settings_1.default.getInstance(this);
46
44
  }
47
45
  /**
@@ -59,40 +57,49 @@ class Boot {
59
57
  * @returns {Promise<ExpressiveTeaApplication>}
60
58
  */
61
59
  async start() {
62
- return new $P(async (resolver, rejector) => {
63
- try {
64
- const localContainer = inversify_config_1.default.createChild();
65
- const privateKey = this.settings.get('privateKey');
66
- const certificate = this.settings.get('certificate');
67
- const server = http.createServer(this.server);
68
- const secureServer = privateKey && certificate && https.createServer({
69
- cert: fs.readFileSync(certificate).toString('utf-8'),
70
- key: fs.readFileSync(privateKey).toString('utf-8')
71
- }, this.server);
72
- // Injectables
73
- localContainer.bind('server').toConstantValue(server);
74
- localContainer.bind('secureServer').toConstantValue(secureServer || undefined);
75
- localContainer.bind('context').toConstantValue(this);
76
- localContainer.bind('settings').toConstantValue(this.settings);
77
- const httpEngine = localContainer.resolve(index_1.default);
78
- const websocketEngine = localContainer.resolve(index_2.default);
79
- const teapotEngine = localContainer.resolve(index_3.default);
80
- const teacupEngine = localContainer.resolve(teacup_1.default);
81
- await websocketEngine.init();
82
- await httpEngine.init();
83
- await httpEngine.resolveProxyContainers();
84
- await httpEngine.resolveStages(constants_1.BOOT_ORDER);
85
- await httpEngine.resolveStages([constants_1.BOOT_STAGES.AFTER_APPLICATION_MIDDLEWARES, constants_1.BOOT_STAGES.ON_HTTP_CREATION], server, secureServer);
86
- const listenerServers = await httpEngine.start();
87
- await httpEngine.resolveStages([constants_1.BOOT_STAGES.START], ...listenerServers);
88
- await teapotEngine.start();
89
- await teacupEngine.start();
90
- resolver({ application: this.server, server, secureServer });
91
- }
92
- catch (e) {
93
- return rejector(e);
94
- }
95
- });
60
+ // Initialize Server
61
+ const [server, secureServer] = this.initializeHttp();
62
+ // Injectables
63
+ this.initializeContainer(server, secureServer);
64
+ // Initialize Engines
65
+ const availableEngines = [
66
+ http_1.default,
67
+ index_2.default,
68
+ websocket_1.default,
69
+ index_1.default,
70
+ teacup_1.default
71
+ ];
72
+ const registeredEngines = availableEngines.filter(Engine => Engine.canRegister(this, this.settings));
73
+ this.initializeEngines(registeredEngines);
74
+ // Resolve Engines
75
+ const readyEngines = registeredEngines.map(Engine => this.containerDI.resolve(Engine));
76
+ // Initialize Engines
77
+ await Engine_1.default.exec(readyEngines.reverse(), 'init');
78
+ await Engine_1.default.exec(readyEngines, 'start');
79
+ return ({ application: this.server, server, secureServer });
80
+ }
81
+ initializeEngines(registeredEngines) {
82
+ for (const Engine of registeredEngines) {
83
+ this.containerDI.bind(Engine).to(Engine);
84
+ }
85
+ }
86
+ initializeHttp() {
87
+ const privateKey = this.settings.get('privateKey');
88
+ const certificate = this.settings.get('certificate');
89
+ const server = http.createServer(this.server);
90
+ const secureServer = privateKey &&
91
+ certificate &&
92
+ https.createServer({
93
+ cert: fs.readFileSync(certificate).toString('utf-8'),
94
+ key: fs.readFileSync(privateKey).toString('utf-8')
95
+ });
96
+ return [server, secureServer];
97
+ }
98
+ initializeContainer(server, secureServer) {
99
+ this.containerDI.bind('server').toConstantValue(server);
100
+ this.containerDI.bind('secureServer').toConstantValue(secureServer !== null && secureServer !== void 0 ? secureServer : undefined);
101
+ this.containerDI.bind('context').toConstantValue(this);
102
+ this.containerDI.bind('settings').toConstantValue(this.settings);
96
103
  }
97
104
  }
98
105
  exports.default = Boot;
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import Settings from './Settings';
4
+ import Boot from './Boot';
5
+ import http from 'http';
6
+ import https from 'https';
7
+ export default class ExpressiveTeaEngine {
8
+ protected readonly settings: Settings;
9
+ protected readonly context: Boot;
10
+ protected readonly server: http.Server;
11
+ protected readonly serverSecure?: https.Server;
12
+ constructor(ctx: any, server: any, serverSecure: any, settings: any);
13
+ static exec(availableEngines: ExpressiveTeaEngine[], method: string): any;
14
+ static canRegister(ctx?: Boot, settings?: Settings): boolean;
15
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const inversify_1 = require("inversify");
5
+ let ExpressiveTeaEngine = class ExpressiveTeaEngine {
6
+ constructor(ctx, server, serverSecure, settings) {
7
+ this.settings = settings;
8
+ this.context = ctx;
9
+ this.server = server;
10
+ this.serverSecure = serverSecure;
11
+ }
12
+ static exec(availableEngines, method) {
13
+ return Promise.all(availableEngines
14
+ .filter(engine => typeof engine[method] === 'function')
15
+ .map(engine => engine[method]()));
16
+ }
17
+ static canRegister(ctx, settings) {
18
+ return false;
19
+ }
20
+ };
21
+ ExpressiveTeaEngine = tslib_1.__decorate([
22
+ (0, inversify_1.injectable)(),
23
+ tslib_1.__param(0, (0, inversify_1.inject)('context')),
24
+ tslib_1.__param(1, (0, inversify_1.inject)('server')),
25
+ tslib_1.__param(2, (0, inversify_1.inject)('secureServer')),
26
+ tslib_1.__param(2, (0, inversify_1.optional)()),
27
+ tslib_1.__param(3, (0, inversify_1.inject)('settings')),
28
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Object, Object])
29
+ ], ExpressiveTeaEngine);
30
+ exports.default = ExpressiveTeaEngine;
@@ -5,7 +5,7 @@ class LoadBalancer {
5
5
  * @offset should be used for unit testing and nothing else.
6
6
  */
7
7
  constructor(count, offset = 0) {
8
- this.bins = new Array(count);
8
+ this.bins = [];
9
9
  // Initializes the elements of the array to zero.
10
10
  for (let i = 0; i < this.bins.length; i++) {
11
11
  this.bins[i] = offset;
@@ -1,9 +1,9 @@
1
- import { RequestHandler } from 'express';
1
+ import { type RequestHandler } from 'express';
2
2
  export default class ProxyRoute {
3
3
  readonly registeredOn: string;
4
4
  private balancer;
5
- private servers;
6
- private clients;
5
+ private readonly servers;
6
+ private readonly clients;
7
7
  private lastServerSelected;
8
8
  constructor(registeredOn: string);
9
9
  hasClients(): boolean;
@@ -1,4 +1,4 @@
1
- import { ParameterDecorator } from '@expressive-tea/commons/types';
1
+ import { type ParameterDecorator } from '@expressive-tea/commons/types';
2
2
  /**
3
3
  * Is passing directly to the decorated argument described <a href="http://expressjs.com/en/4x/api.html#req">here</a>.
4
4
  * @decorator {ParameterDecorator} request - Assign express Request instance to parameter.
@@ -1,5 +1,5 @@
1
- import { Express, Router } from 'express';
2
- import { ExpressiveTeaModuleProps } from '@expressive-tea/commons/interfaces';
1
+ import { type Express, Router } from 'express';
2
+ import { type ExpressiveTeaModuleProps } from '@expressive-tea/commons/interfaces';
3
3
  /**
4
4
  * @typedef {Object} ExpressiveTeaModuleProps
5
5
  * @property {Object[]} controllers Controllers Assigned to Module
@@ -24,8 +24,9 @@ import { ExpressiveTeaModuleProps } from '@expressive-tea/commons/interfaces';
24
24
  * })
25
25
  * class Example {}
26
26
  */
27
- export declare function Module(options: ExpressiveTeaModuleProps): <T extends new (...args: any[]) => {}>(Module: T) => {
27
+ export declare function Module(options: ExpressiveTeaModuleProps): <T extends new (...args: any[]) => any>(Module: T) => {
28
28
  new (...args: any[]): {
29
+ [x: string]: any;
29
30
  readonly settings: ExpressiveTeaModuleProps;
30
31
  readonly router: Router;
31
32
  readonly controllers: any[];
@@ -32,10 +32,11 @@ function Module(options) {
32
32
  return (Module) => {
33
33
  return class ExpressiveTeaModule extends Module {
34
34
  constructor(...args) {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
35
36
  super(...args);
36
37
  this.router = (0, express_1.Router)();
37
38
  this.settings = options;
38
- (0, lodash_1.each)(this.settings.providers, P => DependencyInjection_1.default.setProvider(P));
39
+ (0, lodash_1.each)(this.settings.providers, (P) => { DependencyInjection_1.default.setProvider(P); });
39
40
  this.controllers = (0, lodash_1.map)(this.settings.controllers, C => new C());
40
41
  }
41
42
  __register(server) {
@@ -1,5 +1,5 @@
1
- import { ExpressiveTeaProxyOptions, ExpressiveTeaProxyProperty, MethodDecorator } from '@expressive-tea/commons/types';
2
- import { Express, RequestHandler } from 'express';
1
+ import { type ExpressiveTeaProxyOptions, type ExpressiveTeaProxyProperty, type MethodDecorator } from '@expressive-tea/commons/types';
2
+ import { type Express, type RequestHandler } from 'express';
3
3
  export declare function ProxyContainer(source: string, targetUrl: string): <T extends new (...args: any[]) => any>(ProxyContainerClass: T) => {
4
4
  new (...args: any[]): {
5
5
  [x: string]: any;
@@ -12,6 +12,7 @@ function ProxyContainer(source, targetUrl) {
12
12
  return (ProxyContainerClass) => {
13
13
  class ExpressiveTeaProxy extends ProxyContainerClass {
14
14
  constructor(...args) {
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
15
16
  super(...args);
16
17
  this.source = source;
17
18
  this.target = targetUrl;
@@ -25,10 +26,11 @@ function ProxyContainer(source, targetUrl) {
25
26
  for (const value of Object.values(constants_1.PROXY_PROPERTIES)) {
26
27
  const key = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, value);
27
28
  if (!(0, lodash_1.isUndefined)(key)) {
28
- // @ts-ignore:next-line
29
+ // @ts-expect-error:next-line
29
30
  options[value] = this[key];
30
31
  }
31
32
  }
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
32
34
  this.proxyHandler = httpProxy(host ? host.value.bind(this) : this.target);
33
35
  }
34
36
  __register(server) {
@@ -50,6 +52,7 @@ function ProxyContainer(source, targetUrl) {
50
52
  exports.ProxyContainer = ProxyContainer;
51
53
  function ProxyOption(option) {
52
54
  return (target, propertyKey, descriptor) => {
55
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
53
56
  if (NON_ASYNC_METHODS.includes(option) && (0, object_helper_1.isAsyncFunction)(descriptor.value)) {
54
57
  throw new RequestExceptions_1.GenericRequestException(`${String(propertyKey)} must not be declared as Async Function.`);
55
58
  }
@@ -60,6 +63,7 @@ exports.ProxyOption = ProxyOption;
60
63
  function ProxyProperty(option, value) {
61
64
  return (target, propertyKey) => {
62
65
  Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, propertyKey, target, option);
66
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
63
67
  let currentValue = target[propertyKey];
64
68
  Object.defineProperty(target, propertyKey, {
65
69
  get: () => value,
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express';
2
- import { ExpressiveTeaHandlerOptions } from '@expressive-tea/commons/interfaces';
3
- import { ClassDecorator, ExpressMiddlewareHandler, MethodDecorator } from '@expressive-tea/commons/types';
2
+ import { type ExpressiveTeaHandlerOptions } from '@expressive-tea/commons/interfaces';
3
+ import { type ClassDecorator, type ExpressMiddlewareHandler, type MethodDecorator } from '@expressive-tea/commons/types';
4
4
  /**
5
5
  * @module Decorators/Router
6
6
  */
@@ -22,7 +22,7 @@ export declare function Route(mountpoint?: string): <T extends new (...args: any
22
22
  [x: string]: any;
23
23
  readonly router: Router;
24
24
  readonly mountpoint: string;
25
- __mount(parent: Router): any;
25
+ __mount(parent: Router): this;
26
26
  __registerHandler(options: ExpressiveTeaHandlerOptions): ExpressMiddlewareHandler;
27
27
  };
28
28
  } & T;
@@ -178,7 +178,7 @@ export declare function Param(route?: string): (target: object, propertyKey: str
178
178
  *
179
179
  * @param {Function} middleware Register a middleware over router.
180
180
  */
181
- export declare function Middleware(middleware: any): ClassDecorator & MethodDecorator;
181
+ export declare function Middleware(middleware: (...args: any[]) => any): ClassDecorator & MethodDecorator;
182
182
  /**
183
183
  * Will generate a GET route to respond rendering a view template setting up before; the controller method <b>MUST</b>
184
184
  * return an object in order to fulfilled the local variables into the view.
@@ -27,29 +27,31 @@ function Route(mountpoint = '/') {
27
27
  return (RouterClass) => {
28
28
  return class ExpressiveTeaRoute extends RouterClass {
29
29
  constructor(...args) {
30
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
30
31
  super(...args);
31
32
  const handlers = Metadata_1.default.get(constants_1.ROUTER_HANDLERS_KEY, this) || [];
32
33
  this.router = (0, express_1.Router)();
33
34
  this.mountpoint = mountpoint;
34
35
  (0, lodash_1.each)(handlers, h => {
35
- const middlewares = h.handler.$middlewares || [];
36
+ var _a;
37
+ const middlewares = (_a = h.handler.$middlewares) !== null && _a !== void 0 ? _a : [];
36
38
  this.router[h.verb](h.route, ...middlewares, this.__registerHandler(h));
37
39
  });
38
40
  }
39
41
  __mount(parent) {
40
42
  const rootMiddlewares = Metadata_1.default.get(constants_1.ROUTER_MIDDLEWARES_KEY, this) || [];
43
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
41
44
  parent.use(this.mountpoint, ...rootMiddlewares, this.router);
42
45
  return this;
43
46
  }
44
47
  __registerHandler(options) {
45
- const self = this;
46
48
  const decoratedArguments = Metadata_1.default.get(constants_1.ARGUMENTS_KEY, options.target, options.propertyKey);
47
49
  const annotations = Metadata_1.default.get(constants_1.ROUTER_ANNOTATIONS_KEY, options.target, options.propertyKey);
48
50
  return server_1.executeRequest.bind({
49
51
  options,
50
52
  decoratedArguments,
51
53
  annotations,
52
- self
54
+ self: this
53
55
  });
54
56
  }
55
57
  };
@@ -254,7 +256,7 @@ exports.Middleware = Middleware;
254
256
  *
255
257
  */
256
258
  function View(viewName, route) {
257
- route = route || `/${viewName}`;
259
+ route = route !== null && route !== void 0 ? route : `/${viewName}`;
258
260
  return (target, propertyKey, descriptor) => {
259
261
  (0, decorators_1.addAnnotation)('view', target, propertyKey, viewName);
260
262
  (0, server_1.router)('get', route, target, descriptor.value, propertyKey);
@@ -1,6 +1,6 @@
1
- import { Express } from 'express';
2
- import { BOOT_STAGES } from '@expressive-tea/commons/constants';
3
- import { ExpressiveTeaPotSettings, ExpressiveTeaServerProps, ExpressiveTeaStaticFileServer, ExpressiveTeaCupSettings } from '@expressive-tea/commons/interfaces';
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';
4
4
  /**
5
5
  * Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
6
6
  * be useful to attach a simple Express Server configuration.
@@ -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: any) => void;
90
+ export declare function RegisterModule(Module: any): (target: any, property: string | symbol) => void;
91
91
  export declare function Teapot(teapotSettings: ExpressiveTeaPotSettings): (target: object) => void;
92
92
  export declare function Teacup(teacupSettings: ExpressiveTeaCupSettings): (target: object) => void;
@@ -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';
@@ -3,15 +3,14 @@
3
3
  import * as http from 'http';
4
4
  import * as https from 'https';
5
5
  import { BOOT_STAGES } from '@expressive-tea/commons/constants';
6
- export default class HTTPEngine {
7
- private readonly settings;
8
- private readonly context;
9
- private readonly server;
10
- private readonly serverSecure?;
11
- constructor(ctx: any, server: any, serverSecure: any, settings: any);
6
+ import ExpressiveTeaEngine from '../../classes/Engine';
7
+ import Boot from '../../classes/Boot';
8
+ import Settings from '../../classes/Settings';
9
+ export default class HTTPEngine extends ExpressiveTeaEngine {
12
10
  private listen;
13
11
  start(): Promise<(http.Server | https.Server)[]>;
14
12
  init(): Promise<void>;
15
13
  resolveStages(stages: BOOT_STAGES[], ...extraArgs: any[]): Promise<void[]>;
16
14
  resolveProxyContainers(): Promise<void>;
15
+ static canRegister(ctx?: Boot, settings?: Settings): boolean;
17
16
  }
@@ -1,21 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const $P = require("bluebird");
5
4
  const inversify_1 = require("inversify");
6
5
  const boot_helper_1 = require("../../helpers/boot-helper");
7
6
  const constants_1 = require("@expressive-tea/commons/constants");
8
7
  const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
9
8
  const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
10
- let HTTPEngine = class HTTPEngine {
11
- constructor(ctx, server, serverSecure, settings) {
12
- this.context = ctx;
13
- this.server = server;
14
- this.serverSecure = serverSecure;
15
- this.settings = settings;
16
- }
17
- listen(server, port) {
18
- return new $P((resolve, reject) => {
9
+ const Engine_1 = require("../../classes/Engine");
10
+ let HTTPEngine = class HTTPEngine extends Engine_1.default {
11
+ async listen(server, port) {
12
+ return new Promise((resolve, reject) => {
19
13
  server.listen(port);
20
14
  server.on('error', error => {
21
15
  reject(error);
@@ -27,34 +21,38 @@ let HTTPEngine = class HTTPEngine {
27
21
  });
28
22
  }
29
23
  async start() {
30
- return [
24
+ console.log('Starting Server Test');
25
+ const listenerServers = [
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
31
27
  await this.listen(this.server, this.settings.get('port')),
32
28
  (this.serverSecure) ? await this.listen(this.serverSecure, this.settings.get('securePort')) : null
33
29
  ];
30
+ await this.resolveStages([constants_1.BOOT_STAGES.START], ...listenerServers);
31
+ return listenerServers;
34
32
  }
35
33
  async init() {
36
34
  await (0, boot_helper_1.resolveDirectives)(this.context, this.context.getApplication());
37
35
  await (0, boot_helper_1.resolveStatic)(this.context, this.context.getApplication());
36
+ // HTTP Engine Resolve Stages
37
+ await this.resolveProxyContainers();
38
+ await this.resolveStages(constants_1.BOOT_ORDER);
39
+ await this.resolveStages([constants_1.BOOT_STAGES.AFTER_APPLICATION_MIDDLEWARES, constants_1.BOOT_STAGES.ON_HTTP_CREATION], this.server, this.serverSecure);
38
40
  }
39
41
  async resolveStages(stages, ...extraArgs) {
40
- return $P.map(stages, s => {
41
- return (0, boot_helper_1.resolveStage)(s, this.context, this.context.getApplication(), ...extraArgs);
42
- });
42
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
43
+ return Promise.all(stages.map(async (s) => (0, boot_helper_1.resolveStage)(s, this.context, this.context.getApplication(), ...extraArgs)));
43
44
  }
44
45
  async resolveProxyContainers() {
45
46
  const ProxyContainers = Metadata_1.default.get(constants_1.ROUTER_PROXIES_KEY, (0, object_helper_1.getClass)(this.context)) || [];
46
47
  for (const Container of ProxyContainers) {
47
- (0, boot_helper_1.resolveProxy)(Container, this.context.getApplication());
48
+ await (0, boot_helper_1.resolveProxy)(Container, this.context.getApplication());
48
49
  }
49
50
  }
51
+ static canRegister(ctx, settings) {
52
+ return true;
53
+ }
50
54
  };
51
55
  HTTPEngine = tslib_1.__decorate([
52
- (0, inversify_1.injectable)(),
53
- tslib_1.__param(0, (0, inversify_1.inject)('context')),
54
- tslib_1.__param(1, (0, inversify_1.inject)('server')),
55
- tslib_1.__param(2, (0, inversify_1.inject)('secureServer')),
56
- tslib_1.__param(2, (0, inversify_1.optional)()),
57
- tslib_1.__param(3, (0, inversify_1.inject)('settings')),
58
- tslib_1.__metadata("design:paramtypes", [Object, Object, Object, Object])
56
+ (0, inversify_1.injectable)()
59
57
  ], HTTPEngine);
60
58
  exports.default = HTTPEngine;
@@ -0,0 +1,9 @@
1
+ import ExpressiveTeaEngine from '../../classes/Engine';
2
+ import type Boot from '../../classes/Boot';
3
+ import type Settings from '../../classes/Settings';
4
+ export default class SocketIOEngine extends ExpressiveTeaEngine {
5
+ private io;
6
+ private ioSecure;
7
+ init(): Promise<void>;
8
+ static canRegister(ctx?: Boot, settings?: Settings): boolean;
9
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const socket_io_1 = require("socket.io");
4
+ const Engine_1 = require("../../classes/Engine");
5
+ const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
6
+ const constants_1 = require("../constants/constants");
7
+ class SocketIOEngine extends Engine_1.default {
8
+ async init() {
9
+ const commonConfig = {
10
+ path: '/exp-tea/',
11
+ transports: ['websocket', 'polling']
12
+ };
13
+ this.io = this.server && new socket_io_1.Server(this.server, Object.assign({}, commonConfig));
14
+ this.ioSecure = this.serverSecure && new socket_io_1.Server(this.serverSecure, Object.assign({}, commonConfig));
15
+ Metadata_1.default.set(constants_1.SOCKET_IO_INSTANCE_KEY, this.io, this.context);
16
+ Metadata_1.default.set(constants_1.SOCKET_IO_SECURE_INSTANCE_KEY, this.ioSecure, this.context);
17
+ }
18
+ static canRegister(ctx, settings) {
19
+ return true;
20
+ }
21
+ }
22
+ exports.default = SocketIOEngine;
23
+ ;
@@ -1,10 +1,8 @@
1
- export default class TeacupEngine {
2
- private readonly settings;
3
- private readonly context;
4
- private readonly server;
5
- private readonly serverSecure?;
1
+ import ExpressiveTeaEngine from '../../classes/Engine';
2
+ import Boot from '../../classes/Boot';
3
+ import Settings from '../../classes/Settings';
4
+ export default class TeacupEngine extends ExpressiveTeaEngine {
6
5
  private teacupSettings;
7
- private isActive;
8
6
  private publicKey;
9
7
  private privateKey;
10
8
  private publicServerKey;
@@ -12,8 +10,8 @@ export default class TeacupEngine {
12
10
  private clientSignature;
13
11
  private client;
14
12
  private header;
15
- constructor(ctx: any, settings: any, server: any, serverSecure: any);
16
13
  private handshaked;
17
14
  private accepted;
18
15
  start(): Promise<void>;
16
+ static canRegister(ctx?: Boot, settings?: Settings): boolean;
19
17
  }