typespeed 2.0.22 → 2.1.1

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.
@@ -15,9 +15,9 @@ const routerMiddleware = {};
15
15
  function setRouter(app) {
16
16
  ["get", "post", "all"].forEach(method => {
17
17
  for (let key in routerMapper[method]) {
18
- let rounterFunction = routerMapper[method][key];
18
+ const rounterFunction = routerMapper[method][key];
19
19
  if (routerMiddleware[rounterFunction["name"]]) {
20
- let args = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
20
+ const args = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
21
21
  app[method].apply(app, args);
22
22
  }
23
23
  else {
@@ -32,6 +32,8 @@ function mapperFunction(method, value) {
32
32
  routerMapper[method][value] = {
33
33
  "path": value,
34
34
  "name": [target.constructor.name, propertyKey].toString(),
35
+ "target": target.constructor,
36
+ "propertyKey": propertyKey,
35
37
  "invoker": async (req, res, next) => {
36
38
  const routerBean = (0, core_decorator_1.getComponent)(target.constructor);
37
39
  try {
@@ -39,7 +41,7 @@ function mapperFunction(method, value) {
39
41
  if (routerParamsTotal[[target.constructor.name, propertyKey].toString()]) {
40
42
  paramTotal = Math.max(paramTotal, routerParamsTotal[[target.constructor.name, propertyKey].toString()]);
41
43
  }
42
- let args = [req, res, next];
44
+ const args = [req, res, next];
43
45
  if (paramTotal > 0) {
44
46
  for (let i = 0; i < paramTotal; i++) {
45
47
  if (routerParams[[target.constructor.name, propertyKey, i].toString()]) {
@@ -169,6 +169,21 @@ declare function after(constructorFunction: any, methodName: string): (target: a
169
169
  declare function schedule(cronTime: string | Date): (target: any, propertyKey: string) => void;
170
170
  /**RabbitMQ 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
171
171
  declare function rabbitListener(queue: string): (target: any, propertyKey: string) => void;
172
+ /** request 对象装饰器,作为路由页面方法参数,获取 request 对象 */
173
+ declare function req(target: any, propertyKey: string, parameterIndex: number) : void;
174
+ /** response 对象装饰器,作为路由页面方法参数,获取 response 对象 */
175
+ declare function res(target: any, propertyKey: string, parameterIndex: number) : void;
176
+ /** next 函数装饰器,作为路由页面方法参数,获取 next 函数 */
177
+ declare function next(target: any, propertyKey: string, parameterIndex: number) : void;
178
+ /** request.body 对象装饰器,作为路由页面方法参数,获取 request.body 对象 */
179
+ declare function reqBody(target: any, propertyKey: string, parameterIndex: number) : void;
180
+ /** request.param 值装饰器,作为路由页面方法参数,获取 request.params 内容 */
181
+ declare function reqParam(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
182
+ /** request.query 值装饰器,作为路由页面方法参数,获取 request.query 内容 */
183
+ declare function reqQuery(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
184
+ /** request 表单值装饰器,作为路由页面方法参数,获取 request.body 表单内容 */
185
+ declare function reqForm(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
186
+
172
187
  /**框架 Web 服务工厂类 */
173
188
  declare abstract class ServerFactory {
174
189
  /**Web 服务实例 */
@@ -344,4 +359,4 @@ declare class ExpressServer extends ServerFactory {
344
359
  private setDefaultMiddleware;
345
360
  }
346
361
 
347
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model};
362
+ export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.0.22",
3
+ "version": "2.1.1",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -52,6 +52,7 @@
52
52
  "tracer": "^1.1.6",
53
53
  "typescript": "^4.7.4",
54
54
  "walk-sync": "^3.0.0",
55
- "amqplib": "0.10.3"
55
+ "amqplib": "0.10.3",
56
+ "swagger-ui-express": "4.6.3"
56
57
  }
57
58
  }
@@ -54,12 +54,12 @@ export default class ExpressServer extends ServerFactory {
54
54
 
55
55
  public start(port: number) {
56
56
  this.app.use(this.authentication.afterCompletion);
57
-
58
57
  this.middlewareList.forEach(middleware => {
59
58
  this.app.use(middleware);
60
59
  });
61
60
 
62
61
  this.setDefaultMiddleware();
62
+
63
63
  this.app.listen(port, () => {
64
64
  log("server start at port: " + port);
65
65
  });
@@ -2,7 +2,6 @@ import * as express from "express";
2
2
  import * as multiparty from "multiparty";
3
3
  import { expressjwt } from "express-jwt";
4
4
  import { getComponent } from "./core.decorator";
5
- import { param } from "./database.decorator";
6
5
 
7
6
  const routerMapper = {
8
7
  "get": {},
@@ -15,9 +14,9 @@ const routerMiddleware = {};
15
14
  function setRouter(app: express.Application) {
16
15
  ["get", "post", "all"].forEach(method => {
17
16
  for (let key in routerMapper[method]) {
18
- let rounterFunction = routerMapper[method][key];
17
+ const rounterFunction = routerMapper[method][key];
19
18
  if (routerMiddleware[rounterFunction["name"]]) {
20
- let args: Array<any> = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
19
+ const args: Array<any> = [key, ...routerMiddleware[rounterFunction["name"]], rounterFunction["invoker"]];
21
20
  app[method].apply(app, args);
22
21
  } else {
23
22
  app[method](key, rounterFunction["invoker"]);
@@ -31,6 +30,8 @@ function mapperFunction(method: string, value: string) {
31
30
  routerMapper[method][value] = {
32
31
  "path": value,
33
32
  "name": [target.constructor.name, propertyKey].toString(),
33
+ "target": target.constructor,
34
+ "propertyKey": propertyKey,
34
35
  "invoker": async (req, res, next) => {
35
36
  const routerBean = getComponent(target.constructor);
36
37
  try {
@@ -38,7 +39,7 @@ function mapperFunction(method: string, value: string) {
38
39
  if(routerParamsTotal[[target.constructor.name, propertyKey].toString()]){
39
40
  paramTotal = Math.max(paramTotal, routerParamsTotal[[target.constructor.name, propertyKey].toString()]);
40
41
  }
41
- let args = [req, res, next];
42
+ const args = [req, res, next];
42
43
  if(paramTotal > 0) {
43
44
  for(let i = 0; i < paramTotal; i++) {
44
45
  if(routerParams[[target.constructor.name, propertyKey, i].toString()]){
@@ -169,6 +169,21 @@ declare function after(constructorFunction: any, methodName: string): (target: a
169
169
  declare function schedule(cronTime: string | Date): (target: any, propertyKey: string) => void;
170
170
  /**RabbitMQ 监听装饰器,参数是监听的队列名称,当接受到消息时将执行被装饰方法 */
171
171
  declare function rabbitListener(queue: string): (target: any, propertyKey: string) => void;
172
+ /** request 对象装饰器,作为路由页面方法参数,获取 request 对象 */
173
+ declare function req(target: any, propertyKey: string, parameterIndex: number) : void;
174
+ /** response 对象装饰器,作为路由页面方法参数,获取 response 对象 */
175
+ declare function res(target: any, propertyKey: string, parameterIndex: number) : void;
176
+ /** next 函数装饰器,作为路由页面方法参数,获取 next 函数 */
177
+ declare function next(target: any, propertyKey: string, parameterIndex: number) : void;
178
+ /** request.body 对象装饰器,作为路由页面方法参数,获取 request.body 对象 */
179
+ declare function reqBody(target: any, propertyKey: string, parameterIndex: number) : void;
180
+ /** request.param 值装饰器,作为路由页面方法参数,获取 request.params 内容 */
181
+ declare function reqParam(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
182
+ /** request.query 值装饰器,作为路由页面方法参数,获取 request.query 内容 */
183
+ declare function reqQuery(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
184
+ /** request 表单值装饰器,作为路由页面方法参数,获取 request.body 表单内容 */
185
+ declare function reqForm(paramName: string) : (target: any, propertyKey: string, parameterIndex: number) => void;
186
+
172
187
  /**框架 Web 服务工厂类 */
173
188
  declare abstract class ServerFactory {
174
189
  /**Web 服务实例 */
@@ -344,4 +359,4 @@ declare class ExpressServer extends ServerFactory {
344
359
  private setDefaultMiddleware;
345
360
  }
346
361
 
347
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model};
362
+ export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, AuthenticationFactory, next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule, getMapping, postMapping, requestMapping, setRouter, upload, jwt, insert, update, remove, select, param, resultType, cache, Model};
@@ -0,0 +1,5 @@
1
+ import UserDto from "./user-dto.class";
2
+
3
+ export default class MutilUsers {
4
+ constructor(public group: string, public users: UserDto[]){}
5
+ }
@@ -1,5 +1,6 @@
1
- import { component, getMapping, postMapping, log } from "../../";
2
- import { req, res, reqQuery, reqBody, reqForm, reqParam } from "../../src/route.decorator";
1
+ import { component, getMapping, postMapping, log, req, res, reqQuery, reqBody, reqForm, reqParam } from "../../";
2
+ import MutilUsers from "./entities/mutil-users.class";
3
+ import UserDto from "./entities/user-dto.class";
3
4
 
4
5
 
5
6
  @component
@@ -11,15 +12,15 @@ export default class TestRequest {
11
12
  }
12
13
 
13
14
  @getMapping("/request/query")
14
- testQuery(req, res, @reqQuery("id") id: number) {
15
+ async testQuery(req, res, @reqQuery("id") id: number): Promise<MutilUsers> {
15
16
  log("id: " + id);
16
- res.send("test query");
17
+ return Promise.resolve(new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]));
17
18
  }
18
19
 
19
20
  @postMapping("/request/body")
20
- testBody(@res res, @reqBody body: object) {
21
+ testBody(@res res, @reqBody body: object):MutilUsers {
21
22
  log("body: " + JSON.stringify(body));
22
- res.send("test body");
23
+ return new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]);
23
24
  }
24
25
 
25
26
  @postMapping("/request/form")