@zerooneit/expressive-tea 1.3.0-beta.1 → 1.3.0-beta.3
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/classes/Boot.d.ts +1 -1
- package/classes/Boot.js +3 -2
- package/classes/Settings.d.ts +1 -1
- package/classes/Settings.js +11 -11
- package/decorators/annotations.d.ts +1 -1
- package/decorators/annotations.js +4 -4
- package/decorators/module.d.ts +1 -1
- package/decorators/proxy.d.ts +13 -0
- package/decorators/proxy.js +70 -0
- package/decorators/router.d.ts +4 -3
- package/decorators/router.js +10 -10
- package/decorators/server.d.ts +3 -2
- package/decorators/server.js +29 -19
- package/engines/http/index.d.ts +3 -1
- package/engines/http/index.js +16 -6
- package/engines/teacup/index.js +26 -25
- package/engines/teapot/index.js +30 -30
- package/engines/websocket/index.js +6 -5
- package/helpers/boot-helper.d.ts +2 -1
- package/helpers/boot-helper.js +13 -8
- package/helpers/decorators.js +4 -4
- package/helpers/server.d.ts +3 -3
- package/helpers/server.js +9 -9
- package/helpers/teapot-helper.d.ts +1 -0
- package/helpers/websocket-helper.d.ts +1 -0
- package/libs/classNames.d.ts +1 -0
- package/libs/classNames.js +4 -0
- package/package.json +29 -30
- package/services/WebsocketService.d.ts +1 -0
- package/classes/MetaData.d.ts +0 -17
- package/classes/MetaData.js +0 -68
- package/helpers/object-helper.d.ts +0 -166
- package/helpers/object-helper.js +0 -288
- package/libs/constants.d.ts +0 -69
- package/libs/constants.js +0 -101
- package/libs/interfaces.d.ts +0 -127
- package/libs/interfaces.js +0 -2
- package/libs/types.d.ts +0 -12
- package/libs/types.js +0 -2
- package/yarn-error.log +0 -5906
package/classes/Boot.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import 'reflect-metadata';
|
|
|
2
2
|
import '../inversify.config';
|
|
3
3
|
import { Express } from 'express';
|
|
4
4
|
import Settings from '../classes/Settings';
|
|
5
|
-
import { ExpressiveTeaApplication } from '
|
|
5
|
+
import { ExpressiveTeaApplication } from '@expressive-tea/commons/interfaces';
|
|
6
6
|
/**
|
|
7
7
|
* Expressive Tea Application interface is the response from an started application, contains the express application
|
|
8
8
|
* and a node http server instance.
|
package/classes/Boot.js
CHANGED
|
@@ -9,7 +9,7 @@ const fs = require("fs");
|
|
|
9
9
|
const http = require("http");
|
|
10
10
|
const https = require("https");
|
|
11
11
|
const Settings_1 = require("../classes/Settings");
|
|
12
|
-
const constants_1 = require("
|
|
12
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
13
13
|
const index_1 = require("../engines/http/index");
|
|
14
14
|
const index_2 = require("../engines/websocket/index");
|
|
15
15
|
const index_3 = require("../engines/teapot/index");
|
|
@@ -71,7 +71,7 @@ class Boot {
|
|
|
71
71
|
}, this.server);
|
|
72
72
|
// Injectables
|
|
73
73
|
localContainer.bind('server').toConstantValue(server);
|
|
74
|
-
localContainer.bind('secureServer').toConstantValue(secureServer);
|
|
74
|
+
localContainer.bind('secureServer').toConstantValue(secureServer || undefined);
|
|
75
75
|
localContainer.bind('context').toConstantValue(this);
|
|
76
76
|
localContainer.bind('settings').toConstantValue(this.settings);
|
|
77
77
|
const httpEngine = localContainer.resolve(index_1.default);
|
|
@@ -80,6 +80,7 @@ class Boot {
|
|
|
80
80
|
const teacupEngine = localContainer.resolve(teacup_1.default);
|
|
81
81
|
await websocketEngine.init();
|
|
82
82
|
await httpEngine.init();
|
|
83
|
+
await httpEngine.resolveProxyContainers();
|
|
83
84
|
await httpEngine.resolveStages(constants_1.BOOT_ORDER);
|
|
84
85
|
await httpEngine.resolveStages([constants_1.BOOT_STAGES.AFTER_APPLICATION_MIDDLEWARES, constants_1.BOOT_STAGES.ON_HTTP_CREATION], server, secureServer);
|
|
85
86
|
const listenerServers = await httpEngine.start();
|
package/classes/Settings.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExpressiveTeaServerProps } from '
|
|
1
|
+
import { ExpressiveTeaServerProps } from '@expressive-tea/commons/interfaces';
|
|
2
2
|
/**
|
|
3
3
|
* Declare the properties which the server will save into settings, is a semi dynamic object since is allowed to save
|
|
4
4
|
* any property but is contains only one defined property to keep the port of the server.
|
package/classes/Settings.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const _ = require("lodash");
|
|
6
6
|
const inversify_1 = require("inversify");
|
|
7
|
-
const object_helper_1 = require("
|
|
7
|
+
const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
|
|
8
8
|
const server_1 = require("../helpers/server");
|
|
9
9
|
/**
|
|
10
10
|
* Declare the properties which the server will save into settings, is a semi dynamic object since is allowed to save
|
|
@@ -25,14 +25,6 @@ const server_1 = require("../helpers/server");
|
|
|
25
25
|
* @summary Singleton Class to Store Server Settings
|
|
26
26
|
*/
|
|
27
27
|
let Settings = Settings_1 = class Settings {
|
|
28
|
-
constructor(options = { port: 3000, securePort: 4443 }, isIsolated = false) {
|
|
29
|
-
if (Settings_1.instance && !isIsolated) {
|
|
30
|
-
return Settings_1.instance;
|
|
31
|
-
}
|
|
32
|
-
const settingsFile = (0, server_1.fileSettings)();
|
|
33
|
-
this.options = Object.assign({}, { port: 3000, securePort: 4443 }, settingsFile, options);
|
|
34
|
-
Settings_1.instance = this;
|
|
35
|
-
}
|
|
36
28
|
/**
|
|
37
29
|
* Reset Singleton instance to the default values, all changes will be erased is not recommendable to use it
|
|
38
30
|
* multiple times since all your options will be lost. Unless you have an option how to recover this is not
|
|
@@ -65,6 +57,14 @@ let Settings = Settings_1 = class Settings {
|
|
|
65
57
|
}
|
|
66
58
|
return Settings_1.instance || new Settings_1();
|
|
67
59
|
}
|
|
60
|
+
constructor(options = { port: 3000, securePort: 4443 }, isIsolated = false) {
|
|
61
|
+
if (Settings_1.instance && !isIsolated) {
|
|
62
|
+
return Settings_1.instance;
|
|
63
|
+
}
|
|
64
|
+
const settingsFile = (0, server_1.fileSettings)();
|
|
65
|
+
this.options = Object.assign({}, { port: 3000, securePort: 4443 }, settingsFile, options);
|
|
66
|
+
Settings_1.instance = this;
|
|
67
|
+
}
|
|
68
68
|
/**
|
|
69
69
|
* It will return the latest snapshot options registered at the time that this method is called, as Expressive Tea
|
|
70
70
|
* is designed as async methods some time options should not be available.
|
|
@@ -112,8 +112,8 @@ let Settings = Settings_1 = class Settings {
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
Settings.isolatedContext = new Map();
|
|
115
|
-
Settings = Settings_1 =
|
|
115
|
+
Settings = Settings_1 = tslib_1.__decorate([
|
|
116
116
|
(0, inversify_1.injectable)(),
|
|
117
|
-
|
|
117
|
+
tslib_1.__metadata("design:paramtypes", [Object, Boolean])
|
|
118
118
|
], Settings);
|
|
119
119
|
exports.default = Settings;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ParameterDecorator } from '
|
|
1
|
+
import { 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,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.param = exports.body = exports.query = exports.next = exports.response = exports.request = void 0;
|
|
4
|
-
const
|
|
5
|
-
const constants_1 = require("
|
|
4
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
5
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
6
6
|
/**
|
|
7
7
|
* @module Decorators/Annotations
|
|
8
8
|
*/
|
|
9
9
|
function addToArguments(target, propertyKey, parameterIndex, type, args) {
|
|
10
|
-
const decoratedParameters =
|
|
10
|
+
const decoratedParameters = Metadata_1.default.get(constants_1.ARGUMENTS_KEY, target, propertyKey) || [];
|
|
11
11
|
decoratedParameters.unshift({
|
|
12
12
|
arguments: args,
|
|
13
13
|
index: parameterIndex,
|
|
14
14
|
key: propertyKey,
|
|
15
15
|
type
|
|
16
16
|
});
|
|
17
|
-
|
|
17
|
+
Metadata_1.default.set(constants_1.ARGUMENTS_KEY, decoratedParameters, target, propertyKey);
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Is passing directly to the decorated argument described <a href="http://expressjs.com/en/4x/api.html#req">here</a>.
|
package/decorators/module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Express, Router } from 'express';
|
|
2
|
-
import { ExpressiveTeaModuleProps } from '
|
|
2
|
+
import { ExpressiveTeaModuleProps } from '@expressive-tea/commons/interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {Object} ExpressiveTeaModuleProps
|
|
5
5
|
* @property {Object[]} controllers Controllers Assigned to Module
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExpressiveTeaProxyOptions, ExpressiveTeaProxyProperty, MethodDecorator } from '@expressive-tea/commons/types';
|
|
2
|
+
import { Express, RequestHandler } from 'express';
|
|
3
|
+
export declare function ProxyContainer(source: string, targetUrl: string): <T extends new (...args: any[]) => any>(ProxyContainerClass: T) => {
|
|
4
|
+
new (...args: any[]): {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
readonly source: string;
|
|
7
|
+
readonly target: string;
|
|
8
|
+
readonly proxyHandler: RequestHandler;
|
|
9
|
+
__register(server: Express): void;
|
|
10
|
+
};
|
|
11
|
+
} & T;
|
|
12
|
+
export declare function ProxyOption(option: ExpressiveTeaProxyOptions): MethodDecorator;
|
|
13
|
+
export declare function ProxyProperty(option: ExpressiveTeaProxyProperty, value: any): PropertyDecorator;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyProperty = exports.ProxyOption = exports.ProxyContainer = void 0;
|
|
4
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
5
|
+
const httpProxy = require("express-http-proxy");
|
|
6
|
+
const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
|
|
7
|
+
const lodash_1 = require("lodash");
|
|
8
|
+
const RequestExceptions_1 = require("../exceptions/RequestExceptions");
|
|
9
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
10
|
+
const NON_ASYNC_METHODS = ['host'];
|
|
11
|
+
function ProxyContainer(source, targetUrl) {
|
|
12
|
+
return (ProxyContainerClass) => {
|
|
13
|
+
class ExpressiveTeaProxy extends ProxyContainerClass {
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
super(...args);
|
|
16
|
+
this.source = source;
|
|
17
|
+
this.target = targetUrl;
|
|
18
|
+
const options = {};
|
|
19
|
+
const host = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, constants_1.PROXY_METHODS.HOST);
|
|
20
|
+
for (const value of Object.values(constants_1.PROXY_METHODS)) {
|
|
21
|
+
if (value !== constants_1.PROXY_METHODS.HOST) {
|
|
22
|
+
options[value] = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const value of Object.values(constants_1.PROXY_PROPERTIES)) {
|
|
26
|
+
const key = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, this, value);
|
|
27
|
+
if (!(0, lodash_1.isUndefined)(key)) {
|
|
28
|
+
// @ts-ignore:next-line
|
|
29
|
+
options[value] = this[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
this.proxyHandler = httpProxy(host ? host.value.bind(this) : this.target);
|
|
33
|
+
}
|
|
34
|
+
__register(server) {
|
|
35
|
+
const proxyMetadata = Metadata_1.default.get(constants_1.PROXY_SETTING_KEY, (0, object_helper_1.getClass)(this));
|
|
36
|
+
console.info(`[PROXY - ${proxyMetadata.name}] ${this.source} -> ${this.target}`);
|
|
37
|
+
server.use(this.source, this.proxyHandler);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
;
|
|
41
|
+
const settings = {
|
|
42
|
+
source,
|
|
43
|
+
targetUrl,
|
|
44
|
+
name: ProxyContainerClass.name
|
|
45
|
+
};
|
|
46
|
+
Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, settings, ProxyContainerClass);
|
|
47
|
+
return ExpressiveTeaProxy;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
exports.ProxyContainer = ProxyContainer;
|
|
51
|
+
function ProxyOption(option) {
|
|
52
|
+
return (target, propertyKey, descriptor) => {
|
|
53
|
+
if (NON_ASYNC_METHODS.includes(option) && (0, object_helper_1.isAsyncFunction)(descriptor.value)) {
|
|
54
|
+
throw new RequestExceptions_1.GenericRequestException(`${String(propertyKey)} must not be declared as Async Function.`);
|
|
55
|
+
}
|
|
56
|
+
Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, descriptor, target, option);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.ProxyOption = ProxyOption;
|
|
60
|
+
function ProxyProperty(option, value) {
|
|
61
|
+
return (target, propertyKey) => {
|
|
62
|
+
Metadata_1.default.set(constants_1.PROXY_SETTING_KEY, propertyKey, target, option);
|
|
63
|
+
let currentValue = target[propertyKey];
|
|
64
|
+
Object.defineProperty(target, propertyKey, {
|
|
65
|
+
get: () => value,
|
|
66
|
+
set: () => { currentValue = value; }
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
exports.ProxyProperty = ProxyProperty;
|
package/decorators/router.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
-
import { ExpressiveTeaHandlerOptions } from '
|
|
3
|
-
import { ExpressMiddlewareHandler, MethodDecorator } from '
|
|
2
|
+
import { ExpressiveTeaHandlerOptions } from '@expressive-tea/commons/interfaces';
|
|
3
|
+
import { ClassDecorator, ExpressMiddlewareHandler, MethodDecorator } from '@expressive-tea/commons/types';
|
|
4
4
|
/**
|
|
5
5
|
* @module Decorators/Router
|
|
6
6
|
*/
|
|
@@ -17,8 +17,9 @@ import { ExpressMiddlewareHandler, MethodDecorator } from '../libs/types';
|
|
|
17
17
|
* {REPLACE-AT}Route('/)
|
|
18
18
|
* class Example {}
|
|
19
19
|
*/
|
|
20
|
-
export declare function Route(mountpoint?: string): <T extends new (...args: any[]) =>
|
|
20
|
+
export declare function Route(mountpoint?: string): <T extends new (...args: any[]) => any>(RouterClass: T) => {
|
|
21
21
|
new (...args: any[]): {
|
|
22
|
+
[x: string]: any;
|
|
22
23
|
readonly router: Router;
|
|
23
24
|
readonly mountpoint: string;
|
|
24
25
|
__mount(parent: Router): any;
|
package/decorators/router.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.View = exports.Middleware = exports.Param = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.Route = void 0;
|
|
4
4
|
const express_1 = require("express");
|
|
5
5
|
const lodash_1 = require("lodash");
|
|
6
|
-
const
|
|
6
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
7
7
|
const decorators_1 = require("../helpers/decorators");
|
|
8
8
|
const server_1 = require("../helpers/server");
|
|
9
|
-
const constants_1 = require("
|
|
9
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
10
10
|
/**
|
|
11
11
|
* @module Decorators/Router
|
|
12
12
|
*/
|
|
@@ -24,11 +24,11 @@ const constants_1 = require("../libs/constants");
|
|
|
24
24
|
* class Example {}
|
|
25
25
|
*/
|
|
26
26
|
function Route(mountpoint = '/') {
|
|
27
|
-
return (
|
|
28
|
-
return class ExpressiveTeaRoute extends
|
|
27
|
+
return (RouterClass) => {
|
|
28
|
+
return class ExpressiveTeaRoute extends RouterClass {
|
|
29
29
|
constructor(...args) {
|
|
30
30
|
super(...args);
|
|
31
|
-
const handlers =
|
|
31
|
+
const handlers = Metadata_1.default.get(constants_1.ROUTER_HANDLERS_KEY, this) || [];
|
|
32
32
|
this.router = (0, express_1.Router)();
|
|
33
33
|
this.mountpoint = mountpoint;
|
|
34
34
|
(0, lodash_1.each)(handlers, h => {
|
|
@@ -37,14 +37,14 @@ function Route(mountpoint = '/') {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
__mount(parent) {
|
|
40
|
-
const rootMiddlewares =
|
|
40
|
+
const rootMiddlewares = Metadata_1.default.get(constants_1.ROUTER_MIDDLEWARES_KEY, this) || [];
|
|
41
41
|
parent.use(this.mountpoint, ...rootMiddlewares, this.router);
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
44
|
__registerHandler(options) {
|
|
45
45
|
const self = this;
|
|
46
|
-
const decoratedArguments =
|
|
47
|
-
const annotations =
|
|
46
|
+
const decoratedArguments = Metadata_1.default.get(constants_1.ARGUMENTS_KEY, options.target, options.propertyKey);
|
|
47
|
+
const annotations = Metadata_1.default.get(constants_1.ROUTER_ANNOTATIONS_KEY, options.target, options.propertyKey);
|
|
48
48
|
return server_1.executeRequest.bind({
|
|
49
49
|
options,
|
|
50
50
|
decoratedArguments,
|
|
@@ -262,9 +262,9 @@ function View(viewName, route) {
|
|
|
262
262
|
}
|
|
263
263
|
exports.View = View;
|
|
264
264
|
function rootMiddleware(target, middleware) {
|
|
265
|
-
const existedRoutesHandlers =
|
|
265
|
+
const existedRoutesHandlers = Metadata_1.default.get(constants_1.ROUTER_MIDDLEWARES_KEY, target) || [];
|
|
266
266
|
existedRoutesHandlers.unshift(middleware);
|
|
267
|
-
|
|
267
|
+
Metadata_1.default.set(constants_1.ROUTER_MIDDLEWARES_KEY, existedRoutesHandlers, target);
|
|
268
268
|
}
|
|
269
269
|
function routeMiddleware(target, descriptor, middleware) {
|
|
270
270
|
descriptor.value.$middlewares = descriptor.value.$middlewares || [];
|
package/decorators/server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Express } from 'express';
|
|
2
|
-
import { BOOT_STAGES } from '
|
|
3
|
-
import { ExpressiveTeaPotSettings, ExpressiveTeaServerProps, ExpressiveTeaStaticFileServer, ExpressiveTeaCupSettings } from '
|
|
2
|
+
import { BOOT_STAGES } from '@expressive-tea/commons/constants';
|
|
3
|
+
import { ExpressiveTeaPotSettings, ExpressiveTeaServerProps, ExpressiveTeaStaticFileServer, 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.
|
|
@@ -78,6 +78,7 @@ export declare function Setting(settingName: string): (target: any, propertyName
|
|
|
78
78
|
* @param Modules
|
|
79
79
|
*/
|
|
80
80
|
export declare function Modules(Modules: any[]): (target: any) => void;
|
|
81
|
+
export declare function Proxies(proxyContainers: any[]): (target: any) => void;
|
|
81
82
|
/**
|
|
82
83
|
* Register Module Method Decorator this Method Decorator is used at bootstrap level and should decorate the start
|
|
83
84
|
* method with a Module Class.
|
package/decorators/server.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Teacup = exports.Teapot = exports.RegisterModule = exports.Modules = exports.Setting = exports.ExpressDirective = exports.Static = exports.ServerSettings = exports.Pour = exports.Plug = void 0;
|
|
3
|
+
exports.Teacup = exports.Teapot = exports.RegisterModule = exports.Proxies = exports.Modules = exports.Setting = exports.ExpressDirective = exports.Static = exports.ServerSettings = exports.Pour = exports.Plug = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
6
6
|
const Settings_1 = require("../classes/Settings");
|
|
7
|
-
const constants_1 = require("
|
|
7
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
8
8
|
/**
|
|
9
9
|
* Define the Main Plugins Properties.
|
|
10
10
|
* @typedef {Object} ExpressiveTeaPluginProps
|
|
@@ -46,10 +46,10 @@ const constants_1 = require("../libs/constants");
|
|
|
46
46
|
* @module Decorators/Server
|
|
47
47
|
*/
|
|
48
48
|
function getStages(target) {
|
|
49
|
-
return
|
|
49
|
+
return Metadata_1.default.get(constants_1.BOOT_STAGES_KEY, target) || {};
|
|
50
50
|
}
|
|
51
51
|
function getRegisteredPlugins(target) {
|
|
52
|
-
return
|
|
52
|
+
return Metadata_1.default.get(constants_1.PLUGINS_KEY, target) || [];
|
|
53
53
|
}
|
|
54
54
|
function getStage(stage, target) {
|
|
55
55
|
const stages = getStages(target);
|
|
@@ -61,10 +61,10 @@ function getStage(stage, target) {
|
|
|
61
61
|
function setStage(stage, value, target) {
|
|
62
62
|
const stages = getStages(target);
|
|
63
63
|
stages[stage] = value;
|
|
64
|
-
|
|
64
|
+
Metadata_1.default.set(constants_1.BOOT_STAGES_KEY, stages, target);
|
|
65
65
|
}
|
|
66
66
|
function setPlugins(plugins, target) {
|
|
67
|
-
|
|
67
|
+
Metadata_1.default.set(constants_1.PLUGINS_KEY, plugins, target);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Plug Class Decorator create a simple plugin to execute in one of the public stages defined on BOOT_STAGES, might
|
|
@@ -145,9 +145,9 @@ function Static(root, virtual = null, options = {}) {
|
|
|
145
145
|
if ((0, lodash_1.isNil)(root)) {
|
|
146
146
|
throw new Error('Root must be defined');
|
|
147
147
|
}
|
|
148
|
-
const registeredStatics =
|
|
148
|
+
const registeredStatics = Metadata_1.default.get(constants_1.REGISTERED_STATIC_KEY, target) || [];
|
|
149
149
|
registeredStatics.unshift({ root, options, virtual });
|
|
150
|
-
|
|
150
|
+
Metadata_1.default.set(constants_1.REGISTERED_STATIC_KEY, registeredStatics, target);
|
|
151
151
|
};
|
|
152
152
|
}
|
|
153
153
|
exports.Static = Static;
|
|
@@ -165,9 +165,9 @@ function ExpressDirective(name, ...settings) {
|
|
|
165
165
|
if (!constants_1.EXPRESS_DIRECTIVES.includes(name)) {
|
|
166
166
|
throw new Error(`Directive Name ${name} is not valid express behavior setting`);
|
|
167
167
|
}
|
|
168
|
-
const registeredDirectives =
|
|
168
|
+
const registeredDirectives = Metadata_1.default.get(constants_1.REGISTERED_DIRECTIVES_KEY, target) || [];
|
|
169
169
|
registeredDirectives.unshift({ name, settings });
|
|
170
|
-
|
|
170
|
+
Metadata_1.default.set(constants_1.REGISTERED_DIRECTIVES_KEY, registeredDirectives, target);
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
173
|
exports.ExpressDirective = ExpressDirective;
|
|
@@ -197,13 +197,23 @@ exports.Setting = Setting;
|
|
|
197
197
|
function Modules(Modules) {
|
|
198
198
|
return target => {
|
|
199
199
|
for (const Module of Modules) {
|
|
200
|
-
const registeredModules =
|
|
200
|
+
const registeredModules = Metadata_1.default.get(constants_1.REGISTERED_MODULE_KEY, target, 'start') || [];
|
|
201
201
|
registeredModules.unshift(Module);
|
|
202
|
-
|
|
202
|
+
Metadata_1.default.set(constants_1.REGISTERED_MODULE_KEY, registeredModules, target, 'start');
|
|
203
203
|
}
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
exports.Modules = Modules;
|
|
207
|
+
function Proxies(proxyContainers) {
|
|
208
|
+
return target => {
|
|
209
|
+
for (const proxyContainer of proxyContainers) {
|
|
210
|
+
const registeredProxyContainers = Metadata_1.default.get(constants_1.ROUTER_PROXIES_KEY, target) || [];
|
|
211
|
+
registeredProxyContainers.unshift(proxyContainer);
|
|
212
|
+
Metadata_1.default.set(constants_1.ROUTER_PROXIES_KEY, registeredProxyContainers, target);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
exports.Proxies = Proxies;
|
|
207
217
|
/**
|
|
208
218
|
* Register Module Method Decorator this Method Decorator is used at bootstrap level and should decorate the start
|
|
209
219
|
* method with a Module Class.
|
|
@@ -217,23 +227,23 @@ function RegisterModule(Module) {
|
|
|
217
227
|
if (property !== 'start') {
|
|
218
228
|
throw new Error('Register Module needs to decorate ONLY start method');
|
|
219
229
|
}
|
|
220
|
-
const registeredModules =
|
|
230
|
+
const registeredModules = Metadata_1.default.get(constants_1.REGISTERED_MODULE_KEY, target, property) || [];
|
|
221
231
|
registeredModules.push(Module);
|
|
222
|
-
|
|
232
|
+
Metadata_1.default.set(constants_1.REGISTERED_MODULE_KEY, registeredModules, target, property);
|
|
223
233
|
};
|
|
224
234
|
}
|
|
225
235
|
exports.RegisterModule = RegisterModule;
|
|
226
236
|
function Teapot(teapotSettings) {
|
|
227
237
|
return (target) => {
|
|
228
|
-
|
|
229
|
-
|
|
238
|
+
Metadata_1.default.set(constants_1.ASSIGN_TEAPOT_KEY, true, target, 'isTeapotActive');
|
|
239
|
+
Metadata_1.default.set(constants_1.ASSIGN_TEAPOT_KEY, teapotSettings, target);
|
|
230
240
|
};
|
|
231
241
|
}
|
|
232
242
|
exports.Teapot = Teapot;
|
|
233
243
|
function Teacup(teacupSettings) {
|
|
234
244
|
return (target) => {
|
|
235
|
-
|
|
236
|
-
|
|
245
|
+
Metadata_1.default.set(constants_1.ASSIGN_TEACUP_KEY, true, target, 'isTeacupActive');
|
|
246
|
+
Metadata_1.default.set(constants_1.ASSIGN_TEACUP_KEY, teacupSettings, target);
|
|
237
247
|
};
|
|
238
248
|
}
|
|
239
249
|
exports.Teacup = Teacup;
|
package/engines/http/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import * as http from 'http';
|
|
3
4
|
import * as https from 'https';
|
|
4
|
-
import { BOOT_STAGES } from '
|
|
5
|
+
import { BOOT_STAGES } from '@expressive-tea/commons/constants';
|
|
5
6
|
export default class HTTPEngine {
|
|
6
7
|
private readonly settings;
|
|
7
8
|
private readonly context;
|
|
@@ -12,4 +13,5 @@ export default class HTTPEngine {
|
|
|
12
13
|
start(): Promise<(http.Server | https.Server)[]>;
|
|
13
14
|
init(): Promise<void>;
|
|
14
15
|
resolveStages(stages: BOOT_STAGES[], ...extraArgs: any[]): Promise<void[]>;
|
|
16
|
+
resolveProxyContainers(): Promise<void>;
|
|
15
17
|
}
|
package/engines/http/index.js
CHANGED
|
@@ -4,6 +4,9 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const $P = require("bluebird");
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const boot_helper_1 = require("../../helpers/boot-helper");
|
|
7
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
8
|
+
const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
|
|
9
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
7
10
|
let HTTPEngine = class HTTPEngine {
|
|
8
11
|
constructor(ctx, server, serverSecure, settings) {
|
|
9
12
|
this.context = ctx;
|
|
@@ -38,13 +41,20 @@ let HTTPEngine = class HTTPEngine {
|
|
|
38
41
|
return (0, boot_helper_1.resolveStage)(s, this.context, this.context.getApplication(), ...extraArgs);
|
|
39
42
|
});
|
|
40
43
|
}
|
|
44
|
+
async resolveProxyContainers() {
|
|
45
|
+
const ProxyContainers = Metadata_1.default.get(constants_1.ROUTER_PROXIES_KEY, (0, object_helper_1.getClass)(this.context)) || [];
|
|
46
|
+
for (const Container of ProxyContainers) {
|
|
47
|
+
(0, boot_helper_1.resolveProxy)(Container, this.context.getApplication());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
41
50
|
};
|
|
42
|
-
HTTPEngine =
|
|
51
|
+
HTTPEngine = tslib_1.__decorate([
|
|
43
52
|
(0, inversify_1.injectable)(),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
(0,
|
|
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])
|
|
49
59
|
], HTTPEngine);
|
|
50
60
|
exports.default = HTTPEngine;
|
package/engines/teacup/index.js
CHANGED
|
@@ -6,18 +6,32 @@ const url = require("url");
|
|
|
6
6
|
// tslint:disable-next-line:no-duplicate-imports
|
|
7
7
|
const socket_io_client_1 = require("socket.io-client");
|
|
8
8
|
const inversify_1 = require("inversify");
|
|
9
|
-
const
|
|
10
|
-
const constants_1 = require("
|
|
9
|
+
const Metadata_1 = require("@expressive-tea/commons/classes/Metadata");
|
|
10
|
+
const constants_1 = require("@expressive-tea/commons/constants");
|
|
11
11
|
const teapot_helper_1 = require("../../helpers/teapot-helper");
|
|
12
|
-
const object_helper_1 = require("
|
|
12
|
+
const object_helper_1 = require("@expressive-tea/commons/helpers/object-helper");
|
|
13
13
|
let TeacupEngine = class TeacupEngine {
|
|
14
|
+
header() {
|
|
15
|
+
console.log(chalk.white.bold('Teacup Engine is initializing...'));
|
|
16
|
+
console.log(chalk `
|
|
17
|
+
{grey ( (}
|
|
18
|
+
{white.bold ) )}
|
|
19
|
+
{magenta.bold ........}
|
|
20
|
+
{magenta.bold | |]}
|
|
21
|
+
{magenta.bold \\ /} {yellow.bold [${this.teacupSettings.address}]}
|
|
22
|
+
{magenta.bold \`----'}
|
|
23
|
+
|
|
24
|
+
{yellow.bold NOTICE:}
|
|
25
|
+
All Communication are encrypted to ensure intruder can not connected, however, please does not share any sensitive data like keys or passwords to avoid security issues.
|
|
26
|
+
`);
|
|
27
|
+
}
|
|
14
28
|
constructor(ctx, settings, server, serverSecure) {
|
|
15
29
|
this.server = server;
|
|
16
30
|
this.serverSecure = serverSecure;
|
|
17
31
|
this.settings = settings;
|
|
18
32
|
this.context = ctx;
|
|
19
|
-
this.teacupSettings =
|
|
20
|
-
this.isActive =
|
|
33
|
+
this.teacupSettings = Metadata_1.default.get(constants_1.ASSIGN_TEACUP_KEY, (0, object_helper_1.getClass)(this.context));
|
|
34
|
+
this.isActive = Metadata_1.default.get(constants_1.ASSIGN_TEACUP_KEY, (0, object_helper_1.getClass)(this.context), 'isTeacupActive');
|
|
21
35
|
if (!this.isActive) {
|
|
22
36
|
return;
|
|
23
37
|
}
|
|
@@ -32,20 +46,6 @@ let TeacupEngine = class TeacupEngine {
|
|
|
32
46
|
autoConnect: false
|
|
33
47
|
});
|
|
34
48
|
}
|
|
35
|
-
header() {
|
|
36
|
-
console.log(chalk.white.bold('Teacup Engine is initializing...'));
|
|
37
|
-
console.log(chalk `
|
|
38
|
-
{grey ( (}
|
|
39
|
-
{white.bold ) )}
|
|
40
|
-
{magenta.bold ........}
|
|
41
|
-
{magenta.bold | |]}
|
|
42
|
-
{magenta.bold \\ /} {yellow.bold [${this.teacupSettings.address}]}
|
|
43
|
-
{magenta.bold \`----'}
|
|
44
|
-
|
|
45
|
-
{yellow.bold NOTICE:}
|
|
46
|
-
All Communication are encrypted to ensure intruder can not connected, however, please does not share any sensitive data like keys or passwords to avoid security issues.
|
|
47
|
-
`);
|
|
48
|
-
}
|
|
49
49
|
handshaked(data) {
|
|
50
50
|
try {
|
|
51
51
|
console.log(chalk `{cyan.bold [TEACUP]} - [{magenta.bold ${this.client.id}}]: {yellow.bold Started Verification}`);
|
|
@@ -95,12 +95,13 @@ All Communication are encrypted to ensure intruder can not connected, however, p
|
|
|
95
95
|
this.client.connect();
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
TeacupEngine =
|
|
98
|
+
TeacupEngine = tslib_1.__decorate([
|
|
99
99
|
(0, inversify_1.injectable)(),
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
(0,
|
|
100
|
+
tslib_1.__param(0, (0, inversify_1.inject)('context')),
|
|
101
|
+
tslib_1.__param(1, (0, inversify_1.inject)('settings')),
|
|
102
|
+
tslib_1.__param(2, (0, inversify_1.inject)('server')),
|
|
103
|
+
tslib_1.__param(3, (0, inversify_1.inject)('secureServer')),
|
|
104
|
+
tslib_1.__param(3, (0, inversify_1.optional)()),
|
|
105
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object, Object, Object])
|
|
105
106
|
], TeacupEngine);
|
|
106
107
|
exports.default = TeacupEngine;
|