@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.
- package/.eslintrc.js +44 -0
- package/.gitattributes +4 -0
- package/classes/Boot.d.ts +7 -4
- package/classes/Boot.js +53 -46
- package/classes/Engine.d.ts +15 -0
- package/classes/Engine.js +30 -0
- package/classes/LoadBalancer.js +1 -1
- package/classes/ProxyRoute.d.ts +3 -3
- package/decorators/annotations.d.ts +1 -1
- package/decorators/module.d.ts +4 -3
- package/decorators/module.js +2 -1
- package/decorators/proxy.d.ts +2 -2
- package/decorators/proxy.js +5 -1
- package/decorators/router.d.ts +4 -4
- package/decorators/router.js +6 -4
- package/decorators/server.d.ts +4 -4
- package/engines/constants/constants.d.ts +2 -0
- package/engines/constants/constants.js +5 -0
- package/engines/http/index.d.ts +5 -6
- package/engines/http/index.js +20 -22
- package/engines/socketio/index.d.ts +9 -0
- package/engines/socketio/index.js +23 -0
- package/engines/teacup/index.d.ts +5 -7
- package/engines/teacup/index.js +35 -52
- package/engines/teapot/index.d.ts +9 -10
- package/engines/teapot/index.js +51 -81
- package/engines/websocket/index.d.ts +5 -5
- package/engines/websocket/index.js +10 -13
- package/exceptions/RequestExceptions.d.ts +1 -1
- package/helpers/boot-helper.d.ts +2 -2
- package/helpers/boot-helper.js +3 -2
- package/helpers/promise-helper.d.ts +1 -0
- package/helpers/promise-helper.js +7 -0
- package/helpers/server.d.ts +5 -5
- package/helpers/server.js +12 -10
- package/helpers/teapot-helper.d.ts +6 -4
- package/helpers/teapot-helper.js +19 -4
- package/helpers/websocket-helper.d.ts +2 -2
- package/interfaces/index.d.ts +4 -0
- package/interfaces/index.js +2 -0
- package/inversify.config.d.ts +4 -4
- package/package.json +42 -33
- package/services/DependencyInjection.d.ts +4 -2
- package/services/DependencyInjection.js +2 -2
- package/services/WebsocketService.d.ts +2 -2
- package/tsconfig.linter.json +24 -0
- package/tslint-to-eslint-config.log +12 -0
- 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
package/classes/Boot.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
-
import '
|
|
3
|
-
import {
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
package/classes/LoadBalancer.js
CHANGED
|
@@ -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 =
|
|
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;
|
package/classes/ProxyRoute.d.ts
CHANGED
|
@@ -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.
|
package/decorators/module.d.ts
CHANGED
|
@@ -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[]) =>
|
|
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[];
|
package/decorators/module.js
CHANGED
|
@@ -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) {
|
package/decorators/proxy.d.ts
CHANGED
|
@@ -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;
|
package/decorators/proxy.js
CHANGED
|
@@ -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-
|
|
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,
|
package/decorators/router.d.ts
CHANGED
|
@@ -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):
|
|
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.
|
package/decorators/router.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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);
|
package/decorators/server.d.ts
CHANGED
|
@@ -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:
|
|
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,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';
|
package/engines/http/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
}
|
package/engines/http/index.js
CHANGED
|
@@ -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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
}
|