@zerooneit/expressive-tea 1.2.0 → 1.2.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.
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.View = exports.Middleware = exports.Param = exports.Delete = exports.Patch = exports.Put = exports.Post = exports.Get = exports.Route = void 0;
3
4
  const express_1 = require("express");
4
5
  const lodash_1 = require("lodash");
5
6
  const MetaData_1 = require("../classes/MetaData");
@@ -29,12 +30,11 @@ function Route(mountpoint = '/') {
29
30
  constructor(...args) {
30
31
  super(...args);
31
32
  const handlers = MetaData_1.default.get(constants_1.ROUTER_HANDLERS_KEY, this) || [];
32
- this.router = express_1.Router();
33
+ this.router = (0, express_1.Router)();
33
34
  this.mountpoint = mountpoint;
34
- lodash_1.each(handlers, h => {
35
+ (0, lodash_1.each)(handlers, h => {
35
36
  const middlewares = h.handler.$middlewares || [];
36
37
  this.router[h.verb](h.route, ...middlewares, this.__registerHandler(h));
37
- console.log(`[${h.verb}] ${mountpoint}${h.route} - Register Route`);
38
38
  });
39
39
  }
40
40
  __mount(parent) {
@@ -48,14 +48,22 @@ function Route(mountpoint = '/') {
48
48
  const annotations = MetaData_1.default.get(constants_1.ROUTER_ANNOTATIONS_KEY, options.target, options.propertyKey);
49
49
  return async function exec(request, response, next) {
50
50
  try {
51
+ let isNextUsed = false;
52
+ const nextWrapper = () => (error) => {
53
+ next(error);
54
+ isNextUsed = true;
55
+ };
51
56
  // TODO: Must be Depecrated in prior version.
52
- const result = await options.handler.apply(self, server_1.mapArguments(decoratedArguments, request, response, next));
53
- if (!response.headersSent) {
54
- server_1.autoResponse(request, response, annotations, result);
57
+ const result = await options.handler.apply(self, (0, server_1.mapArguments)(decoratedArguments, request, response, nextWrapper()));
58
+ if (!response.headersSent && !isNextUsed) {
59
+ (0, server_1.autoResponse)(request, response, annotations, result);
55
60
  }
56
61
  }
57
62
  catch (e) {
58
- next(new RequestExceptions_1.GenericRequestException(e.message));
63
+ if (e instanceof RequestExceptions_1.GenericRequestException) {
64
+ return next(e);
65
+ }
66
+ next(new RequestExceptions_1.GenericRequestException(e.message || 'System Error'));
59
67
  }
60
68
  };
61
69
  }
@@ -81,7 +89,7 @@ exports.Route = Route;
81
89
  *
82
90
  */
83
91
  function Get(route = '*') {
84
- return server_1.generateRoute(route, 'get');
92
+ return (0, server_1.generateRoute)(route, 'get');
85
93
  }
86
94
  exports.Get = Get;
87
95
  /**
@@ -102,7 +110,7 @@ exports.Get = Get;
102
110
  *
103
111
  */
104
112
  function Post(route = '*') {
105
- return server_1.generateRoute(route, 'post');
113
+ return (0, server_1.generateRoute)(route, 'post');
106
114
  }
107
115
  exports.Post = Post;
108
116
  /**
@@ -123,7 +131,7 @@ exports.Post = Post;
123
131
  *
124
132
  */
125
133
  function Put(route = '*') {
126
- return server_1.generateRoute(route, 'put');
134
+ return (0, server_1.generateRoute)(route, 'put');
127
135
  }
128
136
  exports.Put = Put;
129
137
  /**
@@ -144,7 +152,7 @@ exports.Put = Put;
144
152
  *
145
153
  */
146
154
  function Patch(route = '*') {
147
- return server_1.generateRoute(route, 'patch');
155
+ return (0, server_1.generateRoute)(route, 'patch');
148
156
  }
149
157
  exports.Patch = Patch;
150
158
  /**
@@ -165,7 +173,7 @@ exports.Patch = Patch;
165
173
  *
166
174
  */
167
175
  function Delete(route = '*') {
168
- return server_1.generateRoute(route, 'delete');
176
+ return (0, server_1.generateRoute)(route, 'delete');
169
177
  }
170
178
  exports.Delete = Delete;
171
179
  /**
@@ -202,7 +210,7 @@ exports.Delete = Delete;
202
210
  *
203
211
  */
204
212
  function Param(route = '*') {
205
- return server_1.generateRoute(route, 'param');
213
+ return (0, server_1.generateRoute)(route, 'param');
206
214
  }
207
215
  exports.Param = Param;
208
216
  /**
@@ -263,8 +271,8 @@ exports.Middleware = Middleware;
263
271
  function View(viewName, route) {
264
272
  route = route || `/${viewName}`;
265
273
  return (target, propertyKey, descriptor) => {
266
- decorators_1.addAnnotation('view', target, propertyKey, viewName);
267
- server_1.router('get', route, target, descriptor.value, propertyKey);
274
+ (0, decorators_1.addAnnotation)('view', target, propertyKey, viewName);
275
+ (0, server_1.router)('get', route, target, descriptor.value, propertyKey);
268
276
  };
269
277
  }
270
278
  exports.View = View;
@@ -16,7 +16,7 @@ import { ExpressiveTeaServerProps, ExpressiveTeaStaticFileServer } from '../libs
16
16
  * {REPLACE-AT}Plug(BOOT_STAGES.BOOT_DEPENDENCIES, 'test', s => console.log, true)
17
17
  * class Example extends Boot {}
18
18
  */
19
- export declare function Plug(stage: BOOT_STAGES, name: string, method: (server: Express | never) => Promise<any> | any, required?: boolean): (target: any) => void;
19
+ export declare function Plug(stage: BOOT_STAGES, name: string, method: (server?: Express | never, ...extraArgs: unknown[]) => Promise<any> | any, required?: boolean): (target: any) => void;
20
20
  /**
21
21
  * Since version 1.1.0 Expressive Tea allow to use external plugins using the node
22
22
  * package @expressive-tea/plugin. This plugin engine allows to create more complex plugin configuration and provision
@@ -24,18 +24,19 @@ export declare function Plug(stage: BOOT_STAGES, name: string, method: (server:
24
24
  *
25
25
  * @decorator {ClassDecorator} Pour - Use Expressive Tea plugin definition instance.
26
26
  * @summary Attach an Expressive Tea Definition Instance.
27
- * @param plugin Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
27
+ * @param Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
28
+ * @param pluginArgs - Plugin Constructor Arguments
28
29
  * @version 1.1.0
29
30
  * @link https://www.npmjs.com/package/@expressive-tea/plugin Expressive Tea Plugin
30
31
  */
31
- export declare function Pour(Plugin: any): (target: any) => void;
32
+ export declare function Pour(Plugin: any, ...pluginArgs: any[]): (target: any) => void;
32
33
  /**
33
34
  * Server Settings Singleton Class Decorator this Provide the Configuration to the server or another component on
34
35
  * the projects,is working as a container to store user and library settings.
35
36
  * @decorator {ClassDecorator} ServerSettings - Declares Server Settings.
36
37
  * @summary Declare Server Properties.
37
38
  * @param {ExpressiveTeaModuleProps} options
38
- * @param {number} [port=3000] Select Port Number where the server should be listening.
39
+ * @param {object} [port=3000] Select Port Number where the server should be listening.
39
40
  */
40
41
  export declare function ServerSettings(options?: ExpressiveTeaServerProps): (target: any) => any;
41
42
  /**
@@ -78,3 +79,12 @@ export declare function Setting(settingName: string): (target: any, propertyName
78
79
  * @param {Class} Module
79
80
  */
80
81
  export declare function RegisterModule(Module: any): (target: any, property: any) => void;
82
+ export declare function Proxies(proxyContainers: any[]): (target: any) => void;
83
+ /**
84
+ * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
85
+ * and register modules.
86
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
87
+ * @summary This register the Module Classes created by the user.
88
+ * @param Modules
89
+ */
90
+ export declare function Modules(Modules: any[]): (target: any) => void;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Modules = exports.Proxies = exports.RegisterModule = exports.Setting = exports.ExpressDirecive = exports.Static = exports.ServerSettings = exports.Pour = exports.Plug = void 0;
3
4
  const lodash_1 = require("lodash");
4
5
  const MetaData_1 = require("../classes/MetaData");
5
6
  const Settings_1 = require("../classes/Settings");
6
- const object_helper_1 = require("../helpers/object-helper");
7
7
  const constants_1 = require("../libs/constants");
8
8
  /**
9
9
  * Define the Main Plugins Properties.
@@ -96,19 +96,20 @@ exports.Plug = Plug;
96
96
  *
97
97
  * @decorator {ClassDecorator} Pour - Use Expressive Tea plugin definition instance.
98
98
  * @summary Attach an Expressive Tea Definition Instance.
99
- * @param plugin Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
99
+ * @param Plugin - A Plugin Class which extends @expressive-tea/plugin/Plugin Class.
100
+ * @param pluginArgs - Plugin Constructor Arguments
100
101
  * @version 1.1.0
101
102
  * @link https://www.npmjs.com/package/@expressive-tea/plugin Expressive Tea Plugin
102
103
  */
103
- function Pour(Plugin) {
104
+ function Pour(Plugin, ...pluginArgs) {
104
105
  return (target) => {
105
- const stages = getStages(object_helper_1.getClass(target));
106
- const instance = new Plugin();
106
+ const stages = getStages(target);
107
+ const instance = new Plugin(...pluginArgs);
107
108
  const plugins = instance.register(Settings_1.default.getInstance().getOptions(), getRegisteredPlugins(target));
108
- constants_1.BOOT_ORDER.forEach(STAGE => {
109
+ constants_1.BOOT_STAGES_LIST.forEach(STAGE => {
109
110
  setStage(STAGE, (stages[STAGE] || []).concat(instance.getRegisteredStage(STAGE)), target);
110
111
  });
111
- setPlugins(lodash_1.orderBy(plugins, ['priority'], ['asc']), target);
112
+ setPlugins((0, lodash_1.orderBy)(plugins, ['priority'], ['asc']), target);
112
113
  };
113
114
  }
114
115
  exports.Pour = Pour;
@@ -118,12 +119,12 @@ exports.Pour = Pour;
118
119
  * @decorator {ClassDecorator} ServerSettings - Declares Server Settings.
119
120
  * @summary Declare Server Properties.
120
121
  * @param {ExpressiveTeaModuleProps} options
121
- * @param {number} [port=3000] Select Port Number where the server should be listening.
122
+ * @param {object} [port=3000] Select Port Number where the server should be listening.
122
123
  */
123
124
  function ServerSettings(options = {}) {
124
125
  return target => {
125
126
  Settings_1.default.getInstance().merge(options);
126
- MetaData_1.default.set(constants_1.BOOT_STAGES_KEY, constants_1.STAGES_INIT, target);
127
+ // MetaData.set(BOOT_STAGES_KEY, STAGES_INIT, target);
127
128
  return target;
128
129
  };
129
130
  }
@@ -143,7 +144,7 @@ exports.ServerSettings = ServerSettings;
143
144
  */
144
145
  function Static(root, virtual = null, options = {}) {
145
146
  return target => {
146
- if (lodash_1.isNil(root)) {
147
+ if ((0, lodash_1.isNil)(root)) {
147
148
  throw new Error('Root must be defined');
148
149
  }
149
150
  const registeredStatics = MetaData_1.default.get(constants_1.REGISTERED_STATIC_KEY, target) || [];
@@ -206,3 +207,30 @@ function RegisterModule(Module) {
206
207
  };
207
208
  }
208
209
  exports.RegisterModule = RegisterModule;
210
+ function Proxies(proxyContainers) {
211
+ return target => {
212
+ for (const proxyContainer of proxyContainers) {
213
+ const registeredProxyContainers = MetaData_1.default.get(constants_1.ROUTER_PROXIES_KEY, target) || [];
214
+ registeredProxyContainers.unshift(proxyContainer);
215
+ MetaData_1.default.set(constants_1.ROUTER_PROXIES_KEY, registeredProxyContainers, target);
216
+ }
217
+ };
218
+ }
219
+ exports.Proxies = Proxies;
220
+ /**
221
+ * Register Modules Method Decorator this Method Decorator is used at bootstrap level and should decorate bootstrap class
222
+ * and register modules.
223
+ * @decorator {MethodDecorator} RegisterModule - Register a Expressive Tea module to application.
224
+ * @summary This register the Module Classes created by the user.
225
+ * @param Modules
226
+ */
227
+ function Modules(Modules) {
228
+ return target => {
229
+ for (const Module of Modules) {
230
+ const registeredModules = MetaData_1.default.get(constants_1.REGISTERED_MODULE_KEY, target, 'start') || [];
231
+ registeredModules.unshift(Module);
232
+ MetaData_1.default.set(constants_1.REGISTERED_MODULE_KEY, registeredModules, target, 'start');
233
+ }
234
+ };
235
+ }
236
+ exports.Modules = Modules;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BootLoaderSoftExceptions = exports.BootLoaderRequiredExceptions = void 0;
3
4
  /**
4
5
  * @namespace Exceptions
5
6
  */
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnauthorizedException = exports.BadRequestException = exports.GenericRequestException = void 0;
3
4
  /**
4
5
  * @namespace Exceptions
5
6
  */
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAnnotation = void 0;
3
4
  const MetaData_1 = require("../classes/MetaData");
4
5
  const constants_1 = require("../libs/constants");
5
6
  function addAnnotation(type, target, propertyKey, ...args) {
@@ -163,3 +163,4 @@ export declare function descriptorOf(target: any, propertyKey: string): Property
163
163
  * @ignore
164
164
  */
165
165
  export declare function prototypeOf(target: any): any;
166
+ export declare function isAsyncFunction(fn: () => any): boolean;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAsyncFunction = exports.prototypeOf = exports.descriptorOf = exports.nameOfSymbol = exports.nameOfClass = exports.nameOf = exports.ancestorsOf = exports.getInheritedClass = exports.isPromise = exports.isEmpty = exports.isClass = exports.isObject = exports.isDate = exports.isCollection = exports.isArrayOrArrayClass = exports.isArray = exports.isBoolean = exports.isNumber = exports.isString = exports.primitiveOf = exports.isPrimitiveOrPrimitiveClass = exports.getClassOrSymbol = exports.classOf = exports.getClass = exports.getConstructor = void 0;
3
4
  /* istanbul ignore file */
4
5
  /**
5
6
  * Get the provide constructor.
6
7
  * @param targetClass
7
8
  * @ignore
8
9
  */
9
- exports.getConstructor = (targetClass) => typeof targetClass === 'function' ? targetClass : targetClass.constructor;
10
+ const getConstructor = (targetClass) => typeof targetClass === 'function' ? targetClass : targetClass.constructor;
11
+ exports.getConstructor = getConstructor;
10
12
  /**
11
13
  * Get the provide constructor if target is an instance.
12
14
  * @param target
@@ -230,7 +232,7 @@ function nameOf(obj) {
230
232
  default:
231
233
  return '' + obj;
232
234
  case 'symbol':
233
- return exports.nameOfSymbol(obj);
235
+ return (0, exports.nameOfSymbol)(obj);
234
236
  case 'function':
235
237
  return nameOfClass(obj);
236
238
  }
@@ -250,10 +252,11 @@ exports.nameOfClass = nameOfClass;
250
252
  * @param sym
251
253
  * @ignore
252
254
  */
253
- exports.nameOfSymbol = (sym) => sym
255
+ const nameOfSymbol = (sym) => sym
254
256
  .toString()
255
257
  .replace('Symbol(', '')
256
258
  .replace(')', '');
259
+ exports.nameOfSymbol = nameOfSymbol;
257
260
  /**
258
261
  *
259
262
  * @param target
@@ -275,3 +278,7 @@ function prototypeOf(target) {
275
278
  return classOf(target) === target ? target.prototype : target;
276
279
  }
277
280
  exports.prototypeOf = prototypeOf;
281
+ function isAsyncFunction(fn) {
282
+ return fn.constructor.name === 'AsyncFunction' || fn.constructor.name.includes('__awaiter');
283
+ }
284
+ exports.isAsyncFunction = isAsyncFunction;
@@ -1,6 +1,6 @@
1
1
  import { NextFunction, Request, Response } from 'express';
2
2
  import { ExpressiveTeaAnnotations, ExpressiveTeaArgumentOptions } from '../libs/interfaces';
3
- export declare function autoResponse(request: Request, response: Response, annotations: ExpressiveTeaAnnotations[], responseResult: any): void;
3
+ export declare function autoResponse(request: Request, response: Response, annotations: ExpressiveTeaAnnotations[], responseResult?: any): void;
4
4
  export declare function mapArguments(decoratedArguments: ExpressiveTeaArgumentOptions[], request: Request, response: Response, next: NextFunction): unknown[];
5
5
  export declare function extractParameters(target: unknown, args?: string | string[]): any;
6
6
  export declare function generateRoute(route: string, verb: string): (target: object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
package/helpers/server.js CHANGED
@@ -1,18 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.router = exports.generateRoute = exports.extractParameters = exports.mapArguments = exports.autoResponse = void 0;
3
4
  const lodash_1 = require("lodash");
4
5
  const MetaData_1 = require("../classes/MetaData");
5
6
  const constants_1 = require("../libs/constants");
6
7
  function autoResponse(request, response, annotations, responseResult) {
7
- const view = lodash_1.find(annotations, { type: 'view' });
8
+ const view = (0, lodash_1.find)(annotations, { type: 'view' });
8
9
  if (view) {
9
10
  return response.render(view.arguments[0], responseResult);
10
11
  }
11
- response.send(responseResult);
12
+ response.send((0, lodash_1.isNumber)(responseResult) ? responseResult.toString() : responseResult);
12
13
  }
13
14
  exports.autoResponse = autoResponse;
14
15
  function mapArguments(decoratedArguments, request, response, next) {
15
- return lodash_1.chain(decoratedArguments)
16
+ return (0, lodash_1.chain)(decoratedArguments)
16
17
  .sortBy('index')
17
18
  .map((argument) => {
18
19
  switch (argument.type) {
@@ -32,7 +33,7 @@ function mapArguments(decoratedArguments, request, response, next) {
32
33
  return;
33
34
  }
34
35
  })
35
- .thru((args) => lodash_1.size(args) ? args : [request, response, next])
36
+ .thru((args) => (0, lodash_1.size)(args) ? args : [request, response, next])
36
37
  .value();
37
38
  }
38
39
  exports.mapArguments = mapArguments;
@@ -44,9 +45,9 @@ function extractParameters(target, args) {
44
45
  return target;
45
46
  }
46
47
  if (Array.isArray(args)) {
47
- return lodash_1.pick(target, args);
48
+ return (0, lodash_1.pick)(target, args);
48
49
  }
49
- return lodash_1.get(target, args);
50
+ return (0, lodash_1.get)(target, args);
50
51
  }
51
52
  exports.extractParameters = extractParameters;
52
53
  function generateRoute(route, verb) {
Binary file
Binary file
Binary file
@@ -23,7 +23,8 @@ export declare enum BOOT_STAGES {
23
23
  INITIALIZE_MIDDLEWARES = 1,
24
24
  APPLICATION = 2,
25
25
  AFTER_APPLICATION_MIDDLEWARES = 3,
26
- START = 4
26
+ START = 4,
27
+ ON_HTTP_CREATION = 5
27
28
  }
28
29
  /**
29
30
  * This Determinate how the application is booting internally, this should not be modified unless you know what are you
@@ -37,12 +38,13 @@ export declare enum BOOT_STAGES {
37
38
  * @summary Current Aplication Boot Order
38
39
  */
39
40
  export declare const BOOT_ORDER: BOOT_STAGES[];
41
+ export declare const BOOT_STAGES_LIST: BOOT_STAGES[];
40
42
  export declare const STAGES_INIT: {
41
- 0: never[];
42
- 1: never[];
43
- 2: never[];
44
- 3: never[];
45
- 4: never[];
43
+ 0: any[];
44
+ 1: any[];
45
+ 2: any[];
46
+ 3: any[];
47
+ 4: any[];
46
48
  };
47
49
  export declare const EXPRESS_DIRECTIVES: string[];
48
50
  export declare const BOOT_STAGES_KEY = "boot:stage-settings";
@@ -55,6 +57,8 @@ export declare const REGISTERED_STATIC_KEY = "app:statics";
55
57
  export declare const REGISTERED_DIRECTIVES_KEY = "app:directives";
56
58
  export declare const ARGUMENTS_KEY = "app:routes:arguments";
57
59
  export declare const ROUTER_ANNOTATIONS_KEY = "app:routes:annotations";
60
+ export declare const ROUTER_PROXIES_KEY = "app:routes:proxies";
61
+ export declare const PROXY_SETTING_KEY = "app:proxy:settings";
58
62
  export declare const ARGUMENT_TYPES: {
59
63
  BODY: symbol;
60
64
  GET_PARAM: symbol;
@@ -63,3 +67,24 @@ export declare const ARGUMENT_TYPES: {
63
67
  REQUEST: symbol;
64
68
  RESPONSE: symbol;
65
69
  };
70
+ export declare enum PROXY_METHODS {
71
+ HOST = "host",
72
+ PROXY_REQ_PATH_RESOLVER = "proxyReqPathResolver",
73
+ FILTER = "filter",
74
+ USER_RES_DECORATOR = "userResDecorator",
75
+ USER_RES_HEADER_DECORATOR = "userResHeaderDecorator",
76
+ SKIP_TO_NEXT_HANDLER_FILTER = "skipToNextHandlerFilter",
77
+ PROXY_ERROR_HANDLER = "proxyErrorHandler",
78
+ PROXY_REQ_OPT_DECORATOR = "proxyReqOptDecorator",
79
+ PROXY_REQ_BODY_DECORATOR = "proxyReqBodyDecorator"
80
+ }
81
+ export declare enum PROXY_PROPERTIES {
82
+ LIMIT = "limit",
83
+ MEMOIZE_HOST = "memoizeHost",
84
+ HTTPS = "https",
85
+ PRESERVE_HOST_HDR = "preserveHostHdr",
86
+ PARSE_REQ_BODY = "parseReqBody",
87
+ REQ_AS_BUFFER = "reqAsBuffer",
88
+ REQ_BODY_ENCODING = "reqBodyEncoding",
89
+ TIMEOUT = "timeout"
90
+ }
package/libs/constants.js CHANGED
@@ -21,6 +21,7 @@
21
21
  * @summary Available Boot Stages
22
22
  */
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.PROXY_PROPERTIES = exports.PROXY_METHODS = exports.ARGUMENT_TYPES = exports.PROXY_SETTING_KEY = exports.ROUTER_PROXIES_KEY = exports.ROUTER_ANNOTATIONS_KEY = exports.ARGUMENTS_KEY = exports.REGISTERED_DIRECTIVES_KEY = exports.REGISTERED_STATIC_KEY = exports.PLUGINS_KEY = exports.REGISTERED_MODULE_KEY = exports.REGISTERED_MODEL_KEY = exports.ROUTER_MIDDLEWARES_KEY = exports.ROUTER_HANDLERS_KEY = exports.BOOT_STAGES_KEY = exports.EXPRESS_DIRECTIVES = exports.STAGES_INIT = exports.BOOT_STAGES_LIST = exports.BOOT_ORDER = exports.BOOT_STAGES = void 0;
24
25
  // tslint:enable:max-line-length
25
26
  var BOOT_STAGES;
26
27
  (function (BOOT_STAGES) {
@@ -29,6 +30,7 @@ var BOOT_STAGES;
29
30
  BOOT_STAGES[BOOT_STAGES["APPLICATION"] = 2] = "APPLICATION";
30
31
  BOOT_STAGES[BOOT_STAGES["AFTER_APPLICATION_MIDDLEWARES"] = 3] = "AFTER_APPLICATION_MIDDLEWARES";
31
32
  BOOT_STAGES[BOOT_STAGES["START"] = 4] = "START";
33
+ BOOT_STAGES[BOOT_STAGES["ON_HTTP_CREATION"] = 5] = "ON_HTTP_CREATION";
32
34
  })(BOOT_STAGES = exports.BOOT_STAGES || (exports.BOOT_STAGES = {}));
33
35
  /**
34
36
  * This Determinate how the application is booting internally, this should not be modified unless you know what are you
@@ -42,6 +44,13 @@ var BOOT_STAGES;
42
44
  * @summary Current Aplication Boot Order
43
45
  */
44
46
  exports.BOOT_ORDER = [
47
+ BOOT_STAGES.BOOT_DEPENDENCIES,
48
+ BOOT_STAGES.INITIALIZE_MIDDLEWARES,
49
+ // BOOT_STAGES.APPLICATION,
50
+ // BOOT_STAGES.AFTER_APPLICATION_MIDDLEWARES,
51
+ // BOOT_STAGES.START
52
+ ];
53
+ exports.BOOT_STAGES_LIST = [
45
54
  BOOT_STAGES.BOOT_DEPENDENCIES,
46
55
  BOOT_STAGES.INITIALIZE_MIDDLEWARES,
47
56
  BOOT_STAGES.APPLICATION,
@@ -82,6 +91,8 @@ exports.REGISTERED_STATIC_KEY = 'app:statics';
82
91
  exports.REGISTERED_DIRECTIVES_KEY = 'app:directives';
83
92
  exports.ARGUMENTS_KEY = 'app:routes:arguments';
84
93
  exports.ROUTER_ANNOTATIONS_KEY = 'app:routes:annotations';
94
+ exports.ROUTER_PROXIES_KEY = 'app:routes:proxies';
95
+ exports.PROXY_SETTING_KEY = 'app:proxy:settings';
85
96
  exports.ARGUMENT_TYPES = {
86
97
  BODY: Symbol('BODY'),
87
98
  GET_PARAM: Symbol('GET_PARAM'),
@@ -90,3 +101,26 @@ exports.ARGUMENT_TYPES = {
90
101
  REQUEST: Symbol('REQUEST'),
91
102
  RESPONSE: Symbol('RESPONSE')
92
103
  };
104
+ var PROXY_METHODS;
105
+ (function (PROXY_METHODS) {
106
+ PROXY_METHODS["HOST"] = "host";
107
+ PROXY_METHODS["PROXY_REQ_PATH_RESOLVER"] = "proxyReqPathResolver";
108
+ PROXY_METHODS["FILTER"] = "filter";
109
+ PROXY_METHODS["USER_RES_DECORATOR"] = "userResDecorator";
110
+ PROXY_METHODS["USER_RES_HEADER_DECORATOR"] = "userResHeaderDecorator";
111
+ PROXY_METHODS["SKIP_TO_NEXT_HANDLER_FILTER"] = "skipToNextHandlerFilter";
112
+ PROXY_METHODS["PROXY_ERROR_HANDLER"] = "proxyErrorHandler";
113
+ PROXY_METHODS["PROXY_REQ_OPT_DECORATOR"] = "proxyReqOptDecorator";
114
+ PROXY_METHODS["PROXY_REQ_BODY_DECORATOR"] = "proxyReqBodyDecorator";
115
+ })(PROXY_METHODS = exports.PROXY_METHODS || (exports.PROXY_METHODS = {}));
116
+ var PROXY_PROPERTIES;
117
+ (function (PROXY_PROPERTIES) {
118
+ PROXY_PROPERTIES["LIMIT"] = "limit";
119
+ PROXY_PROPERTIES["MEMOIZE_HOST"] = "memoizeHost";
120
+ PROXY_PROPERTIES["HTTPS"] = "https";
121
+ PROXY_PROPERTIES["PRESERVE_HOST_HDR"] = "preserveHostHdr";
122
+ PROXY_PROPERTIES["PARSE_REQ_BODY"] = "parseReqBody";
123
+ PROXY_PROPERTIES["REQ_AS_BUFFER"] = "reqAsBuffer";
124
+ PROXY_PROPERTIES["REQ_BODY_ENCODING"] = "reqBodyEncoding";
125
+ PROXY_PROPERTIES["TIMEOUT"] = "timeout";
126
+ })(PROXY_PROPERTIES = exports.PROXY_PROPERTIES || (exports.PROXY_PROPERTIES = {}));
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { Express, Router } from 'express';
2
+ /// <reference types="node" />
3
+ import { Express, Router, RequestHandler } from 'express';
3
4
  import * as http from 'http';
4
5
  import * as https from 'https';
5
6
  import { ExpressiveTeaMiddleware, ExpressMiddlewareHandler } from './types';
@@ -56,7 +57,7 @@ export interface ExpressiveTeaPluginProps {
56
57
  */
57
58
  export interface ExpressiveTeaModuleProps {
58
59
  controllers: any[];
59
- providers: any[];
60
+ providers?: any[];
60
61
  mountpoint: string;
61
62
  }
62
63
  export interface IExpressiveTeaModule {
@@ -114,3 +115,14 @@ export interface ExpressiveTeaAnnotations {
114
115
  export interface ExpressiveTeaMiddlewareExtends {
115
116
  $middlewares?: ExpressMiddlewareHandler[];
116
117
  }
118
+ export interface IExpressiveTeaProxySettings {
119
+ name: string;
120
+ source: string;
121
+ targetUrl: string;
122
+ }
123
+ export interface IExpressiveTeaProxy {
124
+ readonly source: string;
125
+ readonly target: string;
126
+ readonly proxyHandler: RequestHandler;
127
+ __register(server: Express): void;
128
+ }
package/libs/types.d.ts CHANGED
@@ -10,3 +10,5 @@ export declare type ClassDecorator = <TFunction extends Function>(target: TFunct
10
10
  export declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
11
11
  export declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor | void;
12
12
  export declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
13
+ export declare type ExpressiveTeaProxyOptions = 'proxyReqPathResolver' | 'host' | 'filter' | 'userResDecorator' | 'userResHeaderDecorator' | 'skipToNextHandlerFilter' | 'proxyErrorHandler' | 'proxyReqOptDecorator' | 'proxyReqBodyDecorator';
14
+ export declare type ExpressiveTeaProxyProperty = 'limit' | 'memoizeHost' | 'https' | 'preserveHostHdr' | 'parseReqBody' | 'reqAsBuffer' | 'reqBodyEncoding' | 'timeout';
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@zerooneit/expressive-tea",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "description": "A REST API over Express and Typescript",
5
5
  "main": "classes/Boot.js",
6
6
  "scripts": {
7
- "doc": "rimraf docs && npm run publish:prepare && jsdoc -c jsdocs.json",
8
- "doc:json": "jsdoc -c jsdocs-json.json",
9
- "test": "npm run linter && jest --clearCache && jest --coverage --silent --ci --detectOpenHandles --forceExit --runInBand",
10
- "test:dev": "npm run linter && jest --detectOpenHandles --forceExit",
7
+ "test": "npm run linter && jest --clearCache && jest --coverage --ci --detectOpenHandles --forceExit --silent --runInBand",
8
+ "test:dev": "npm run linter && jest --clearCache && jest --detectOpenHandles --forceExit",
11
9
  "linter": "tslint -c tslint.json -p tsconfig.json",
12
- "clean:build": "gulp clean",
13
- "publish:prepare": "gulp clean build",
14
- "postpublish": "gulp clean",
10
+ "build:dev": "tsc --project tsconfig.json --watch",
11
+ "build": "tsc --project tsconfig.json",
12
+ "clean:build": "trash '**/*.js' '**/*.d.ts' '**/*.js.map' '**/*.d.ts.map' '!node_modules/**/*' '!docs/**/*' '!coverage/**/*' '!gulpfile.js' '!tasks/*.js' '!jest.config.js' '!tools/**/*'",
13
+ "publish:prepare": "npm run clean:build && npm run build",
14
+ "postpublish": "npm run clean:build",
15
15
  "prepublishOnly": "npm test && npm run publish:prepare"
16
16
  },
17
17
  "publishConfig": {
@@ -23,37 +23,36 @@
23
23
  "license": "Apache-2.0",
24
24
  "devDependencies": {
25
25
  "@expressive-tea/plugin": "^0.0.4",
26
- "@types/bluebird": "3.5.29",
27
- "@types/express": "4.17.2",
28
- "@types/jest": "24.9.1",
29
- "@types/lodash": "4.14.149",
30
- "gulp": "4.0.2",
31
- "gulp-clean": "0.4.0",
32
- "gulp-typescript": "5.0.1",
33
- "jest": "24.9.0",
26
+ "@types/bluebird": "3.5.36",
27
+ "@types/express": "4.17.13",
28
+ "@types/jest": "28.1.0",
29
+ "@types/lodash": "4.14.182",
30
+ "@types/ws": "8.5.3",
31
+ "jest": "28.1.0",
34
32
  "jest-express": "^1.12.0",
35
- "jsdoc": "3.6.3",
36
- "jsdoc-json": "2.0.2",
37
- "minami": "1.2.3",
33
+ "jest-junit": "13.2.0",
38
34
  "reflect-metadata": "0.1.13",
39
- "rimraf": "2.7.1",
35
+ "rimraf": "3.0.2",
36
+ "supertest": "6.2.3",
40
37
  "toast-jsdoc": "1.0.2",
41
- "ts-jest": "24.3.0",
42
- "ts-node": "7.0.1",
43
- "tslint": "5.20.1",
44
- "typescript": "3.7.5"
38
+ "trash-cli": "5.0.0",
39
+ "ts-jest": "28.0.3",
40
+ "ts-node": "10.8.0",
41
+ "tslint": "6.1.3",
42
+ "typescript": "4.7.2"
45
43
  },
46
44
  "dependencies": {
47
45
  "bluebird": "3.7.2",
48
- "braintree-jsdoc-template": "3.3.0",
49
- "express": "4.17.1",
50
- "inversify": "5.0.1",
46
+ "express": "4.18.1",
47
+ "express-http-proxy": "^1.6.3",
48
+ "inversify": "6.0.1",
51
49
  "inversify-inject-decorators": "3.1.0",
52
- "lodash": "4.17.15"
50
+ "lodash": "4.17.21",
51
+ "ws": "8.7.0"
53
52
  },
54
53
  "repository": {
55
54
  "type": "git",
56
- "url": "git+https://github.com/Zero-OneiT/expresive-tea.git"
55
+ "url": "git+https://github.com/Expressive-Tea/expresive-tea.git"
57
56
  },
58
57
  "keywords": [
59
58
  "Typescript",
@@ -88,11 +87,7 @@
88
87
  "nodejs"
89
88
  ],
90
89
  "bugs": {
91
- "url": "https://github.com/Zero-OneiT/expresive-tea/issues"
90
+ "url": "https://github.com/Expressive-Tea/expresive-tea/issues"
92
91
  },
93
- "homepage": "https://github.com/Zero-OneiT/expresive-tea#readme",
94
- "jest": {
95
- "coverageDirectory": "./coverage/",
96
- "collectCoverage": true
97
- }
92
+ "homepage": "https://github.com/Expressive-Tea/expresive-tea#readme"
98
93
  }