typespeed 2.0.21 → 2.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/dist/core.decorator.js +1 -30
  2. package/dist/default/default-authentication.class.js +25 -0
  3. package/dist/default/express-server.class.js +11 -4
  4. package/dist/default/log-default.class.js +0 -6
  5. package/dist/factory/authentication-factory.class.js +11 -0
  6. package/dist/factory/log-factory.class.js +9 -0
  7. package/dist/route.decorator.js +92 -2
  8. package/dist/typespeed.d.ts +40 -3
  9. package/dist/typespeed.js +3 -1
  10. package/package.json +1 -1
  11. package/src/core.decorator.ts +1 -29
  12. package/src/default/default-authentication.class.ts +10 -0
  13. package/src/default/express-server.class.ts +12 -5
  14. package/src/default/log-default.class.ts +0 -10
  15. package/src/factory/authentication-factory.class.ts +9 -0
  16. package/src/factory/log-factory.class.ts +9 -2
  17. package/src/route.decorator.ts +91 -3
  18. package/src/typespeed.d.ts +40 -3
  19. package/src/typespeed.ts +1 -0
  20. package/test/node_modules/.package-lock.json +65 -101
  21. package/test/node_modules/@types/body-parser/LICENSE +21 -0
  22. package/test/node_modules/@types/body-parser/README.md +16 -0
  23. package/test/node_modules/@types/body-parser/index.d.ts +107 -0
  24. package/test/node_modules/@types/body-parser/package.json +58 -0
  25. package/test/node_modules/@types/connect/LICENSE +21 -0
  26. package/test/node_modules/@types/connect/README.md +16 -0
  27. package/test/node_modules/@types/connect/index.d.ts +93 -0
  28. package/test/node_modules/@types/connect/package.json +32 -0
  29. package/test/node_modules/@types/express/LICENSE +21 -0
  30. package/test/node_modules/@types/express/README.md +16 -0
  31. package/test/node_modules/@types/express/index.d.ts +136 -0
  32. package/test/node_modules/@types/express/package.json +45 -0
  33. package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
  34. package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
  35. package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
  36. package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
  37. package/test/node_modules/@types/mime/LICENSE +21 -0
  38. package/test/node_modules/@types/mime/Mime.d.ts +10 -0
  39. package/test/node_modules/@types/mime/README.md +16 -0
  40. package/test/node_modules/@types/mime/index.d.ts +35 -0
  41. package/test/node_modules/@types/mime/lite.d.ts +7 -0
  42. package/test/node_modules/@types/mime/package.json +29 -0
  43. package/test/node_modules/@types/qs/LICENSE +21 -0
  44. package/test/node_modules/@types/qs/README.md +16 -0
  45. package/test/node_modules/@types/qs/index.d.ts +62 -0
  46. package/test/node_modules/@types/qs/package.json +65 -0
  47. package/test/node_modules/@types/range-parser/LICENSE +21 -0
  48. package/test/node_modules/@types/range-parser/README.md +55 -0
  49. package/test/node_modules/@types/range-parser/index.d.ts +35 -0
  50. package/test/node_modules/@types/range-parser/package.json +25 -0
  51. package/test/node_modules/@types/send/LICENSE +21 -0
  52. package/test/node_modules/@types/send/README.md +16 -0
  53. package/test/node_modules/@types/send/index.d.ts +231 -0
  54. package/test/node_modules/@types/send/package.json +33 -0
  55. package/test/node_modules/@types/serve-static/LICENSE +21 -0
  56. package/test/node_modules/@types/serve-static/README.md +16 -0
  57. package/test/node_modules/@types/serve-static/index.d.ts +113 -0
  58. package/test/node_modules/@types/serve-static/package.json +38 -0
  59. package/test/src/config.json +5 -0
  60. package/test/src/custom-log.class.ts +6 -0
  61. package/test/src/jwt-authentication.class.ts +29 -0
  62. package/test/src/test-request.class.ts +36 -0
  63. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
  64. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
  65. package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
  66. package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
  67. package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
  68. package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
  69. package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
  70. package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
  71. package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
  72. package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
  73. package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
  74. package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
  75. package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
  76. package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
  77. package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
  78. package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
  79. package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
  80. package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  81. package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
  82. package/test/node_modules/amqplib/CHANGELOG.md +0 -430
  83. package/test/node_modules/amqplib/LICENSE +0 -6
  84. package/test/node_modules/amqplib/LICENSE-MIT +0 -21
  85. package/test/node_modules/amqplib/Makefile +0 -47
  86. package/test/node_modules/amqplib/README.md +0 -157
  87. package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
  88. package/test/node_modules/amqplib/callback_api.js +0 -22
  89. package/test/node_modules/amqplib/channel_api.js +0 -16
  90. package/test/node_modules/amqplib/examples/headers.js +0 -42
  91. package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
  92. package/test/node_modules/amqplib/examples/send_generators.js +0 -42
  93. package/test/node_modules/amqplib/examples/ssl.js +0 -64
  94. package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
  95. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
  96. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
  97. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
  98. package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
  99. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
  100. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
  101. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
  102. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
  103. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
  104. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
  105. package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
  106. package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
  107. package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
  108. package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
  109. package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
  110. package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
  111. package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
  112. package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
  113. package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
  114. package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
  115. package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
  116. package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
  117. package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
  118. package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
  119. package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
  120. package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
  121. package/test/node_modules/amqplib/lib/api_args.js +0 -314
  122. package/test/node_modules/amqplib/lib/bitset.js +0 -130
  123. package/test/node_modules/amqplib/lib/callback_model.js +0 -327
  124. package/test/node_modules/amqplib/lib/channel.js +0 -499
  125. package/test/node_modules/amqplib/lib/channel_model.js +0 -302
  126. package/test/node_modules/amqplib/lib/codec.js +0 -321
  127. package/test/node_modules/amqplib/lib/connect.js +0 -189
  128. package/test/node_modules/amqplib/lib/connection.js +0 -663
  129. package/test/node_modules/amqplib/lib/credentials.js +0 -42
  130. package/test/node_modules/amqplib/lib/defs.js +0 -4966
  131. package/test/node_modules/amqplib/lib/error.js +0 -24
  132. package/test/node_modules/amqplib/lib/format.js +0 -40
  133. package/test/node_modules/amqplib/lib/frame.js +0 -113
  134. package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
  135. package/test/node_modules/amqplib/lib/mux.js +0 -129
  136. package/test/node_modules/amqplib/package.json +0 -37
  137. package/test/node_modules/amqplib/test/bitset.js +0 -69
  138. package/test/node_modules/amqplib/test/callback_api.js +0 -312
  139. package/test/node_modules/amqplib/test/channel.js +0 -621
  140. package/test/node_modules/amqplib/test/channel_api.js +0 -596
  141. package/test/node_modules/amqplib/test/codec.js +0 -237
  142. package/test/node_modules/amqplib/test/connect.js +0 -197
  143. package/test/node_modules/amqplib/test/connection.js +0 -390
  144. package/test/node_modules/amqplib/test/data.js +0 -254
  145. package/test/node_modules/amqplib/test/frame.js +0 -198
  146. package/test/node_modules/amqplib/test/mux.js +0 -204
  147. package/test/node_modules/amqplib/test/util.js +0 -219
  148. package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
  149. package/test/node_modules/buffer-more-ints/LICENSE +0 -19
  150. package/test/node_modules/buffer-more-ints/README.md +0 -69
  151. package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
  152. package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
  153. package/test/node_modules/buffer-more-ints/package.json +0 -19
  154. package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
  155. package/test/node_modules/core-util-is/LICENSE +0 -19
  156. package/test/node_modules/core-util-is/README.md +0 -3
  157. package/test/node_modules/core-util-is/lib/util.js +0 -107
  158. package/test/node_modules/core-util-is/package.json +0 -38
  159. package/test/node_modules/debug/LICENSE +0 -20
  160. package/test/node_modules/debug/README.md +0 -481
  161. package/test/node_modules/debug/package.json +0 -59
  162. package/test/node_modules/debug/src/browser.js +0 -269
  163. package/test/node_modules/debug/src/common.js +0 -274
  164. package/test/node_modules/debug/src/index.js +0 -10
  165. package/test/node_modules/debug/src/node.js +0 -263
  166. package/test/node_modules/inherits/LICENSE +0 -16
  167. package/test/node_modules/inherits/README.md +0 -42
  168. package/test/node_modules/inherits/inherits.js +0 -9
  169. package/test/node_modules/inherits/inherits_browser.js +0 -27
  170. package/test/node_modules/inherits/package.json +0 -29
  171. package/test/node_modules/isarray/README.md +0 -54
  172. package/test/node_modules/isarray/build/build.js +0 -209
  173. package/test/node_modules/isarray/component.json +0 -19
  174. package/test/node_modules/isarray/index.js +0 -3
  175. package/test/node_modules/isarray/package.json +0 -25
  176. package/test/node_modules/ms/index.js +0 -162
  177. package/test/node_modules/ms/license.md +0 -21
  178. package/test/node_modules/ms/package.json +0 -37
  179. package/test/node_modules/ms/readme.md +0 -60
  180. package/test/node_modules/querystringify/LICENSE +0 -22
  181. package/test/node_modules/querystringify/README.md +0 -61
  182. package/test/node_modules/querystringify/index.js +0 -118
  183. package/test/node_modules/querystringify/package.json +0 -38
  184. package/test/node_modules/readable-stream/LICENSE +0 -18
  185. package/test/node_modules/readable-stream/README.md +0 -15
  186. package/test/node_modules/readable-stream/duplex.js +0 -1
  187. package/test/node_modules/readable-stream/float.patch +0 -923
  188. package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
  189. package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
  190. package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
  191. package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
  192. package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
  193. package/test/node_modules/readable-stream/package.json +0 -32
  194. package/test/node_modules/readable-stream/passthrough.js +0 -1
  195. package/test/node_modules/readable-stream/readable.js +0 -10
  196. package/test/node_modules/readable-stream/transform.js +0 -1
  197. package/test/node_modules/readable-stream/writable.js +0 -1
  198. package/test/node_modules/requires-port/.travis.yml +0 -19
  199. package/test/node_modules/requires-port/LICENSE +0 -22
  200. package/test/node_modules/requires-port/README.md +0 -47
  201. package/test/node_modules/requires-port/index.js +0 -38
  202. package/test/node_modules/requires-port/package.json +0 -47
  203. package/test/node_modules/requires-port/test.js +0 -98
  204. package/test/node_modules/safe-buffer/LICENSE +0 -21
  205. package/test/node_modules/safe-buffer/README.md +0 -584
  206. package/test/node_modules/safe-buffer/index.d.ts +0 -187
  207. package/test/node_modules/safe-buffer/index.js +0 -62
  208. package/test/node_modules/safe-buffer/package.json +0 -37
  209. package/test/node_modules/string_decoder/LICENSE +0 -20
  210. package/test/node_modules/string_decoder/README.md +0 -7
  211. package/test/node_modules/string_decoder/index.js +0 -221
  212. package/test/node_modules/string_decoder/package.json +0 -25
  213. package/test/node_modules/url-parse/LICENSE +0 -22
  214. package/test/node_modules/url-parse/README.md +0 -153
  215. package/test/node_modules/url-parse/dist/url-parse.js +0 -755
  216. package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
  217. package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
  218. package/test/node_modules/url-parse/index.js +0 -589
  219. package/test/node_modules/url-parse/package.json +0 -49
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.schedule = exports.getComponent = exports.getBean = exports.autoware = exports.config = exports.error = exports.value = exports.after = exports.before = exports.app = exports.log = exports.resource = exports.bean = exports.component = void 0;
3
+ exports.schedule = exports.getComponent = exports.getBean = exports.autoware = exports.config = exports.error = exports.value = exports.app = exports.log = exports.resource = exports.bean = exports.component = void 0;
4
4
  require("reflect-metadata");
5
5
  const fs = require("fs");
6
6
  const path = require("path");
@@ -147,35 +147,6 @@ function error(message, ...optionalParams) {
147
147
  }
148
148
  }
149
149
  exports.error = error;
150
- function before(constructorFunction, methodName) {
151
- const targetBean = getComponent(constructorFunction);
152
- return function (target, propertyKey) {
153
- const currentMethod = targetBean[methodName];
154
- Object.assign(targetBean, {
155
- [methodName]: function (...args) {
156
- target[propertyKey](...args);
157
- log("========== before ==========");
158
- return currentMethod.apply(targetBean, args);
159
- }
160
- });
161
- };
162
- }
163
- exports.before = before;
164
- function after(constructorFunction, methodName) {
165
- const targetBean = getComponent(constructorFunction);
166
- return function (target, propertyKey) {
167
- const currentMethod = targetBean[methodName];
168
- Object.assign(targetBean, {
169
- [methodName]: function (...args) {
170
- const result = currentMethod.apply(targetBean, args);
171
- const afterResult = target[propertyKey](result);
172
- log("========== after ==========");
173
- return afterResult !== null && afterResult !== void 0 ? afterResult : result;
174
- }
175
- });
176
- };
177
- }
178
- exports.after = after;
179
150
  function schedule(cronTime) {
180
151
  return (target, propertyKey) => {
181
152
  new cron.CronJob(cronTime, target[propertyKey]).start();
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const authentication_factory_class_1 = require("../factory/authentication-factory.class");
13
+ const core_decorator_1 = require("../core.decorator");
14
+ class DefaultAuthentication extends authentication_factory_class_1.default {
15
+ getAuthentication() {
16
+ return new DefaultAuthentication();
17
+ }
18
+ }
19
+ __decorate([
20
+ core_decorator_1.bean,
21
+ __metadata("design:type", Function),
22
+ __metadata("design:paramtypes", []),
23
+ __metadata("design:returntype", authentication_factory_class_1.default)
24
+ ], DefaultAuthentication.prototype, "getAuthentication", null);
25
+ exports.default = DefaultAuthentication;
@@ -21,6 +21,7 @@ const server_factory_class_1 = require("../factory/server-factory.class");
21
21
  const route_decorator_1 = require("../route.decorator");
22
22
  const core_decorator_1 = require("../core.decorator");
23
23
  const redis_class_1 = require("./redis.class");
24
+ const authentication_factory_class_1 = require("../factory/authentication-factory.class");
24
25
  class ExpressServer extends server_factory_class_1.default {
25
26
  getSever() {
26
27
  const server = new ExpressServer();
@@ -31,6 +32,7 @@ class ExpressServer extends server_factory_class_1.default {
31
32
  this.middlewareList.push(middleware);
32
33
  }
33
34
  start(port) {
35
+ this.app.use(this.authentication.afterCompletion);
34
36
  this.middlewareList.forEach(middleware => {
35
37
  this.app.use(middleware);
36
38
  });
@@ -59,10 +61,6 @@ class ExpressServer extends server_factory_class_1.default {
59
61
  }
60
62
  this.app.use(expressSession(sessionConfig));
61
63
  }
62
- if (this.static) {
63
- const staticPath = process.cwd() + this.static;
64
- this.app.use(express.static(staticPath));
65
- }
66
64
  if (this.favicon) {
67
65
  const faviconPath = process.cwd() + this.favicon;
68
66
  this.app.use(serveFavicon(faviconPath));
@@ -73,6 +71,11 @@ class ExpressServer extends server_factory_class_1.default {
73
71
  if (this.cookieConfig) {
74
72
  this.app.use(cookieParser(this.cookieConfig["secret"] || undefined, this.cookieConfig["options"] || {}));
75
73
  }
74
+ this.app.use(this.authentication.preHandle);
75
+ if (this.static) {
76
+ const staticPath = process.cwd() + this.static;
77
+ this.app.use(express.static(staticPath));
78
+ }
76
79
  (0, route_decorator_1.setRouter)(this.app);
77
80
  const errorPageDir = __dirname + "/pages";
78
81
  this.app.use((req, res) => {
@@ -138,6 +141,10 @@ __decorate([
138
141
  core_decorator_1.autoware,
139
142
  __metadata("design:type", redis_class_1.default)
140
143
  ], ExpressServer.prototype, "redisClient", void 0);
144
+ __decorate([
145
+ core_decorator_1.autoware,
146
+ __metadata("design:type", authentication_factory_class_1.default)
147
+ ], ExpressServer.prototype, "authentication", void 0);
141
148
  __decorate([
142
149
  core_decorator_1.bean,
143
150
  __metadata("design:type", Function),
@@ -15,12 +15,6 @@ class LogDefault extends log_factory_class_1.default {
15
15
  createLog() {
16
16
  return new LogDefault();
17
17
  }
18
- log(message, ...optionalParams) {
19
- console.log(message, ...optionalParams);
20
- }
21
- error(message, ...optionalParams) {
22
- console.error(message, ...optionalParams);
23
- }
24
18
  }
25
19
  __decorate([
26
20
  core_decorator_1.bean,
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class AuthenticationFactory {
4
+ preHandle(req, res, next) {
5
+ next();
6
+ }
7
+ afterCompletion(req, res, next) {
8
+ next();
9
+ }
10
+ }
11
+ exports.default = AuthenticationFactory;
@@ -1,5 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class LogFactory {
4
+ log(message, ...optionalParams) {
5
+ console.log(message, ...optionalParams);
6
+ }
7
+ error(message, ...optionalParams) {
8
+ console.error(message, ...optionalParams);
9
+ }
10
+ debug(message, ...optionalParams) {
11
+ console.debug(message, ...optionalParams);
12
+ }
4
13
  }
5
14
  exports.default = LogFactory;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jwt = exports.upload = exports.setRouter = exports.requestMapping = exports.postMapping = exports.getMapping = void 0;
3
+ exports.jwt = exports.upload = exports.setRouter = exports.requestMapping = exports.postMapping = exports.getMapping = exports.after = exports.before = exports.response = exports.res = exports.request = exports.req = exports.reqParam = exports.reqForm = exports.reqQuery = exports.reqBody = exports.next = void 0;
4
4
  const multiparty = require("multiparty");
5
5
  const express_jwt_1 = require("express-jwt");
6
6
  const core_decorator_1 = require("./core.decorator");
@@ -9,6 +9,8 @@ const routerMapper = {
9
9
  "post": {},
10
10
  "all": {}
11
11
  };
12
+ const routerParams = {};
13
+ const routerParamsTotal = {};
12
14
  const routerMiddleware = {};
13
15
  function setRouter(app) {
14
16
  ["get", "post", "all"].forEach(method => {
@@ -33,7 +35,19 @@ function mapperFunction(method, value) {
33
35
  "invoker": async (req, res, next) => {
34
36
  const routerBean = (0, core_decorator_1.getComponent)(target.constructor);
35
37
  try {
36
- const testResult = await routerBean[propertyKey](req, res);
38
+ let paramTotal = routerBean[propertyKey].length;
39
+ if (routerParamsTotal[[target.constructor.name, propertyKey].toString()]) {
40
+ paramTotal = Math.max(paramTotal, routerParamsTotal[[target.constructor.name, propertyKey].toString()]);
41
+ }
42
+ let args = [req, res, next];
43
+ if (paramTotal > 0) {
44
+ for (let i = 0; i < paramTotal; i++) {
45
+ if (routerParams[[target.constructor.name, propertyKey, i].toString()]) {
46
+ args[i] = routerParams[[target.constructor.name, propertyKey, i].toString()](req, res, next);
47
+ }
48
+ }
49
+ }
50
+ const testResult = await routerBean[propertyKey].apply(routerBean, args);
37
51
  if (typeof testResult === "object") {
38
52
  res.json(testResult);
39
53
  }
@@ -78,6 +92,82 @@ function jwt(jwtConfig) {
78
92
  };
79
93
  }
80
94
  exports.jwt = jwt;
95
+ function before(constructorFunction, methodName) {
96
+ const targetBean = (0, core_decorator_1.getComponent)(constructorFunction);
97
+ return function (target, propertyKey) {
98
+ const currentMethod = targetBean[methodName];
99
+ if (currentMethod.length > 0) {
100
+ routerParamsTotal[[constructorFunction.name, methodName].toString()] = currentMethod.length;
101
+ }
102
+ Object.assign(targetBean, {
103
+ [methodName]: function (...args) {
104
+ target[propertyKey](...args);
105
+ return currentMethod.apply(targetBean, args);
106
+ }
107
+ });
108
+ };
109
+ }
110
+ exports.before = before;
111
+ function after(constructorFunction, methodName) {
112
+ const targetBean = (0, core_decorator_1.getComponent)(constructorFunction);
113
+ return function (target, propertyKey) {
114
+ const currentMethod = targetBean[methodName];
115
+ if (currentMethod.length > 0) {
116
+ routerParamsTotal[[constructorFunction.name, methodName].toString()] = currentMethod.length;
117
+ }
118
+ Object.assign(targetBean, {
119
+ [methodName]: function (...args) {
120
+ const result = currentMethod.apply(targetBean, args);
121
+ const afterResult = target[propertyKey](result);
122
+ return afterResult !== null && afterResult !== void 0 ? afterResult : result;
123
+ }
124
+ });
125
+ };
126
+ }
127
+ exports.after = after;
128
+ function req(target, propertyKey, parameterIndex) {
129
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
130
+ routerParams[key] = (req, res, next) => req;
131
+ }
132
+ exports.req = req;
133
+ exports.request = req;
134
+ function res(target, propertyKey, parameterIndex) {
135
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
136
+ routerParams[key] = (req, res, next) => res;
137
+ }
138
+ exports.res = res;
139
+ exports.response = res;
140
+ function next(target, propertyKey, parameterIndex) {
141
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
142
+ routerParams[key] = (req, res, next) => next;
143
+ }
144
+ exports.next = next;
145
+ function reqBody(target, propertyKey, parameterIndex) {
146
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
147
+ routerParams[key] = (req, res, next) => req.body;
148
+ }
149
+ exports.reqBody = reqBody;
150
+ function reqParam(paramName) {
151
+ return (target, propertyKey, parameterIndex) => {
152
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
153
+ routerParams[key] = (req, res, next) => req.params[paramName];
154
+ };
155
+ }
156
+ exports.reqParam = reqParam;
157
+ function reqQuery(paramName) {
158
+ return (target, propertyKey, parameterIndex) => {
159
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
160
+ routerParams[key] = (req, res, next) => req.query[paramName];
161
+ };
162
+ }
163
+ exports.reqQuery = reqQuery;
164
+ function reqForm(paramName) {
165
+ return (target, propertyKey, parameterIndex) => {
166
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
167
+ routerParams[key] = (req, res, next) => req.body[paramName];
168
+ };
169
+ }
170
+ exports.reqForm = reqForm;
81
171
  const getMapping = (value) => mapperFunction("get", value);
82
172
  exports.getMapping = getMapping;
83
173
  const postMapping = (value) => mapperFunction("post", value);
@@ -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 服务实例 */
@@ -192,12 +207,17 @@ declare abstract class LogFactory {
192
207
  * 日志打印方法
193
208
  * @param message 日志内容
194
209
  */
195
- abstract log(message?: any, ...optionalParams: any[]): void;
210
+ log(message?: any, ...optionalParams: any[]): void;
196
211
  /**
197
212
  * 错误日志打印方法
198
213
  * @param message 日志内容
199
214
  */
200
- abstract error(message?: any, ...optionalParams: any[]): void;
215
+ error(message?: any, ...optionalParams: any[]): void;
216
+ /**
217
+ * 调试日志打印方法
218
+ * @param message 日志内容
219
+ */
220
+ debug(message?: any, ...optionalParams: any[]): void;
201
221
  }
202
222
  /**数据源工厂类 */
203
223
  declare abstract class DataSourceFactory {
@@ -234,6 +254,23 @@ declare abstract class CacheFactory {
234
254
  /**清空缓存 */
235
255
  abstract flush(): void;
236
256
  }
257
+ /**认证类 */
258
+ declare abstract class AuthenticationFactory {
259
+ /**
260
+ * 路由页面执行前认证
261
+ * @param req 请求对象
262
+ * @param res 响应对象
263
+ * @param next 下一步函数
264
+ */
265
+ preHandle(req: express.Request, res: express.Response, next: express.NextFunction): void;
266
+ /**
267
+ * 开始执行中间件前认证
268
+ * @param req 请求对象
269
+ * @param res 响应对象
270
+ * @param next 下一步函数
271
+ */
272
+ afterCompletion(req: express.Request, res: express.Response, next: express.NextFunction): void;
273
+ }
237
274
  /**Redis 操作类 */
238
275
  declare class Redis extends IoRedis {
239
276
  /**获取 Redis 实例 */
@@ -322,4 +359,4 @@ declare class ExpressServer extends ServerFactory {
322
359
  private setDefaultMiddleware;
323
360
  }
324
361
 
325
- export { ExpressServer, LogDefault, NodeCache, RabbitMQ, rabbitListener, ReadWriteDb, Redis, CacheFactory, DataSourceFactory, LogFactory, ServerFactory, 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/dist/typespeed.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ReadWriteDb = exports.Redis = exports.NodeCache = exports.LogDefault = exports.ExpressServer = exports.ServerFactory = exports.DataSourceFactory = exports.CacheFactory = exports.LogFactory = void 0;
17
+ exports.ReadWriteDb = exports.Redis = exports.NodeCache = exports.LogDefault = exports.ExpressServer = exports.AuthenticationFactory = exports.ServerFactory = exports.DataSourceFactory = exports.CacheFactory = exports.LogFactory = void 0;
18
18
  __exportStar(require("./core.decorator"), exports);
19
19
  __exportStar(require("./route.decorator"), exports);
20
20
  __exportStar(require("./database.decorator"), exports);
@@ -26,6 +26,8 @@ var data_source_factory_class_1 = require("./factory/data-source-factory.class")
26
26
  Object.defineProperty(exports, "DataSourceFactory", { enumerable: true, get: function () { return data_source_factory_class_1.default; } });
27
27
  var server_factory_class_1 = require("./factory/server-factory.class");
28
28
  Object.defineProperty(exports, "ServerFactory", { enumerable: true, get: function () { return server_factory_class_1.default; } });
29
+ var authentication_factory_class_1 = require("./factory/authentication-factory.class");
30
+ Object.defineProperty(exports, "AuthenticationFactory", { enumerable: true, get: function () { return authentication_factory_class_1.default; } });
29
31
  var express_server_class_1 = require("./default/express-server.class");
30
32
  Object.defineProperty(exports, "ExpressServer", { enumerable: true, get: function () { return express_server_class_1.default; } });
31
33
  var log_default_class_1 = require("./default/log-default.class");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.0.21",
3
+ "version": "2.0.23",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -145,34 +145,6 @@ function error(message?: any, ...optionalParams: any[]) {
145
145
  }
146
146
  }
147
147
 
148
- function before(constructorFunction, methodName: string) {
149
- const targetBean = getComponent(constructorFunction);
150
- return function (target, propertyKey: string) {
151
- const currentMethod = targetBean[methodName];
152
- Object.assign(targetBean, {
153
- [methodName]: function (...args) {
154
- target[propertyKey](...args);
155
- log("========== before ==========");
156
- return currentMethod.apply(targetBean, args);
157
- }
158
- })
159
- };
160
- }
161
-
162
- function after(constructorFunction, methodName: string) {
163
- const targetBean = getComponent(constructorFunction);
164
- return function (target, propertyKey: string) {
165
- const currentMethod = targetBean[methodName];
166
- Object.assign(targetBean, {
167
- [methodName]: function (...args) {
168
- const result = currentMethod.apply(targetBean, args);
169
- const afterResult = target[propertyKey](result);
170
- log("========== after ==========");
171
- return afterResult ?? result;
172
- }
173
- })
174
- };
175
- }
176
148
 
177
149
  function schedule(cronTime: string | Date) {
178
150
  return (target: any, propertyKey: string) => {
@@ -180,4 +152,4 @@ function schedule(cronTime: string | Date) {
180
152
  }
181
153
  }
182
154
 
183
- export { component, bean, resource, log, app, before, after, value, error, config, autoware, getBean, getComponent, schedule };
155
+ export { component, bean, resource, log, app, value, error, config, autoware, getBean, getComponent, schedule };
@@ -0,0 +1,10 @@
1
+ import AuthenticationFactory from "../factory/authentication-factory.class";
2
+ import { bean } from "../core.decorator";
3
+
4
+ export default class DefaultAuthentication extends AuthenticationFactory{
5
+ @bean
6
+ public getAuthentication(): AuthenticationFactory {
7
+ return new DefaultAuthentication();
8
+ }
9
+ }
10
+
@@ -10,6 +10,7 @@ import ServerFactory from "../factory/server-factory.class";
10
10
  import { setRouter } from "../route.decorator";
11
11
  import { bean, log, value, error, autoware } from "../core.decorator";
12
12
  import Redis from "./redis.class";
13
+ import AuthenticationFactory from "../factory/authentication-factory.class";
13
14
 
14
15
  export default class ExpressServer extends ServerFactory {
15
16
 
@@ -37,6 +38,9 @@ export default class ExpressServer extends ServerFactory {
37
38
  @autoware
38
39
  private redisClient: Redis;
39
40
 
41
+ @autoware
42
+ public authentication: AuthenticationFactory;
43
+
40
44
  @bean
41
45
  public getSever(): ServerFactory {
42
46
  const server = new ExpressServer();
@@ -49,6 +53,8 @@ export default class ExpressServer extends ServerFactory {
49
53
  }
50
54
 
51
55
  public start(port: number) {
56
+ this.app.use(this.authentication.afterCompletion);
57
+
52
58
  this.middlewareList.forEach(middleware => {
53
59
  this.app.use(middleware);
54
60
  });
@@ -82,11 +88,6 @@ export default class ExpressServer extends ServerFactory {
82
88
  this.app.use(expressSession(sessionConfig));
83
89
  }
84
90
 
85
- if (this.static) {
86
- const staticPath = process.cwd() + this.static;
87
- this.app.use(express.static(staticPath))
88
- }
89
-
90
91
  if (this.favicon) {
91
92
  const faviconPath = process.cwd() + this.favicon;
92
93
  this.app.use(serveFavicon(faviconPath));
@@ -100,6 +101,12 @@ export default class ExpressServer extends ServerFactory {
100
101
  this.app.use(cookieParser(this.cookieConfig["secret"] || undefined, this.cookieConfig["options"] || {}));
101
102
  }
102
103
 
104
+ this.app.use(this.authentication.preHandle);
105
+
106
+ if (this.static) {
107
+ const staticPath = process.cwd() + this.static;
108
+ this.app.use(express.static(staticPath))
109
+ }
103
110
  setRouter(this.app);
104
111
 
105
112
  const errorPageDir = __dirname + "/pages";
@@ -2,18 +2,8 @@ import { bean } from "../core.decorator";
2
2
  import LogFactory from "../factory/log-factory.class";
3
3
 
4
4
  export default class LogDefault extends LogFactory {
5
-
6
5
  @bean
7
6
  createLog(): LogFactory {
8
7
  return new LogDefault();
9
8
  }
10
-
11
- public log(message?: any, ...optionalParams: any[]): void {
12
- console.log(message, ...optionalParams);
13
- }
14
-
15
- public error(message?: any, ...optionalParams: any[]) : void{
16
- console.error(message, ...optionalParams);
17
- }
18
-
19
9
  }
@@ -0,0 +1,9 @@
1
+ import * as express from 'express';
2
+ export default abstract class AuthenticationFactory {
3
+ public preHandle(req: express.Request, res: express.Response, next: express.NextFunction): void{
4
+ next();
5
+ }
6
+ public afterCompletion(req: express.Request, res: express.Response, next: express.NextFunction): void{
7
+ next();
8
+ }
9
+ }
@@ -1,4 +1,11 @@
1
1
  export default abstract class LogFactory {
2
- abstract log(message?: any, ...optionalParams: any[]) : void;
3
- abstract error(message?: any, ...optionalParams: any[]) : void;
2
+ public log(message?: any, ...optionalParams: any[]) : void {
3
+ console.log(message, ...optionalParams);
4
+ }
5
+ public error(message?: any, ...optionalParams: any[]) : void {
6
+ console.error(message, ...optionalParams);
7
+ }
8
+ public debug(message?: any, ...optionalParams: any[]) : void {
9
+ console.debug(message, ...optionalParams);
10
+ }
4
11
  }
@@ -2,13 +2,15 @@ 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";
5
6
 
6
7
  const routerMapper = {
7
8
  "get": {},
8
9
  "post": {},
9
10
  "all": {}
10
11
  };
11
-
12
+ const routerParams = {};
13
+ const routerParamsTotal = {};
12
14
  const routerMiddleware = {};
13
15
  function setRouter(app: express.Application) {
14
16
  ["get", "post", "all"].forEach(method => {
@@ -32,7 +34,19 @@ function mapperFunction(method: string, value: string) {
32
34
  "invoker": async (req, res, next) => {
33
35
  const routerBean = getComponent(target.constructor);
34
36
  try {
35
- const testResult = await routerBean[propertyKey](req, res);
37
+ let paramTotal = routerBean[propertyKey].length;
38
+ if(routerParamsTotal[[target.constructor.name, propertyKey].toString()]){
39
+ paramTotal = Math.max(paramTotal, routerParamsTotal[[target.constructor.name, propertyKey].toString()]);
40
+ }
41
+ let args = [req, res, next];
42
+ if(paramTotal > 0) {
43
+ for(let i = 0; i < paramTotal; i++) {
44
+ if(routerParams[[target.constructor.name, propertyKey, i].toString()]){
45
+ args[i] = routerParams[[target.constructor.name, propertyKey, i].toString()](req, res, next);
46
+ }
47
+ }
48
+ }
49
+ const testResult = await routerBean[propertyKey].apply(routerBean, args);
36
50
  if (typeof testResult === "object") {
37
51
  res.json(testResult);
38
52
  } else if (typeof testResult !== "undefined") {
@@ -75,8 +89,82 @@ function jwt(jwtConfig) {
75
89
  }
76
90
  }
77
91
 
92
+ function before(constructorFunction, methodName: string) {
93
+ const targetBean = getComponent(constructorFunction);
94
+ return function (target, propertyKey: string) {
95
+ const currentMethod = targetBean[methodName];
96
+ if(currentMethod.length > 0){
97
+ routerParamsTotal[[constructorFunction.name, methodName].toString()] = currentMethod.length;
98
+ }
99
+ Object.assign(targetBean, {
100
+ [methodName]: function (...args) {
101
+ target[propertyKey](...args);
102
+ return currentMethod.apply(targetBean, args);
103
+ }
104
+ })
105
+ };
106
+ }
107
+
108
+ function after(constructorFunction, methodName: string) {
109
+ const targetBean = getComponent(constructorFunction);
110
+ return function (target, propertyKey: string) {
111
+ const currentMethod = targetBean[methodName];
112
+ if(currentMethod.length > 0){
113
+ routerParamsTotal[[constructorFunction.name, methodName].toString()] = currentMethod.length;
114
+ }
115
+ Object.assign(targetBean, {
116
+ [methodName]: function (...args) {
117
+ const result = currentMethod.apply(targetBean, args);
118
+ const afterResult = target[propertyKey](result);
119
+ return afterResult ?? result;
120
+ }
121
+ })
122
+ };
123
+ }
124
+
125
+ function req(target: any, propertyKey: string, parameterIndex: number) {
126
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
127
+ routerParams[key] = (req, res, next) => req;
128
+ }
129
+
130
+ function res(target: any, propertyKey: string, parameterIndex: number) {
131
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
132
+ routerParams[key] = (req, res, next) => res;
133
+ }
134
+
135
+ function next(target: any, propertyKey: string, parameterIndex: number) {
136
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
137
+ routerParams[key] = (req, res, next) => next;
138
+ }
139
+
140
+ function reqBody(target: any, propertyKey: string, parameterIndex: number) {
141
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
142
+ routerParams[key] = (req, res, next) => req.body;
143
+ }
144
+
145
+ function reqParam(paramName: string) {
146
+ return (target: any, propertyKey: string, parameterIndex: number) => {
147
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
148
+ routerParams[key] = (req, res, next) => req.params[paramName];
149
+ }
150
+ }
151
+
152
+ function reqQuery(paramName: string) {
153
+ return (target: any, propertyKey: string, parameterIndex: number) => {
154
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
155
+ routerParams[key] = (req, res, next) => req.query[paramName];
156
+ }
157
+ }
158
+
159
+ function reqForm(paramName: string) {
160
+ return (target: any, propertyKey: string, parameterIndex: number) => {
161
+ const key = [target.constructor.name, propertyKey, parameterIndex].toString();
162
+ routerParams[key] = (req, res, next) => req.body[paramName];
163
+ }
164
+ }
165
+
78
166
  const getMapping = (value: string) => mapperFunction("get", value);
79
167
  const postMapping = (value: string) => mapperFunction("post", value);
80
168
  const requestMapping = (value: string) => mapperFunction("all", value);
81
169
 
82
- export { getMapping, postMapping, requestMapping, setRouter, upload, jwt };
170
+ export { next, reqBody, reqQuery, reqForm, reqParam, req, req as request, res, res as response, before, after, getMapping, postMapping, requestMapping, setRouter, upload, jwt };