typespeed 2.0.20 → 2.0.22

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 (222) hide show
  1. package/README.md +18 -13
  2. package/dist/core.decorator.js +1 -30
  3. package/dist/default/default-authentication.class.js +25 -0
  4. package/dist/default/express-server.class.js +11 -4
  5. package/dist/default/log-default.class.js +0 -6
  6. package/dist/factory/authentication-factory.class.js +11 -0
  7. package/dist/factory/log-factory.class.js +9 -0
  8. package/dist/route.decorator.js +92 -2
  9. package/dist/scaffold/command.js +1 -1
  10. package/dist/typespeed.d.ts +25 -3
  11. package/dist/typespeed.js +3 -1
  12. package/package.json +10 -1
  13. package/src/core.decorator.ts +1 -29
  14. package/src/default/default-authentication.class.ts +10 -0
  15. package/src/default/express-server.class.ts +12 -5
  16. package/src/default/log-default.class.ts +0 -10
  17. package/src/factory/authentication-factory.class.ts +9 -0
  18. package/src/factory/log-factory.class.ts +9 -2
  19. package/src/route.decorator.ts +91 -3
  20. package/src/scaffold/command.ts +1 -1
  21. package/src/typespeed.d.ts +25 -3
  22. package/src/typespeed.ts +1 -0
  23. package/test/node_modules/.package-lock.json +65 -101
  24. package/test/node_modules/@types/body-parser/LICENSE +21 -0
  25. package/test/node_modules/@types/body-parser/README.md +16 -0
  26. package/test/node_modules/@types/body-parser/index.d.ts +107 -0
  27. package/test/node_modules/@types/body-parser/package.json +58 -0
  28. package/test/node_modules/@types/connect/LICENSE +21 -0
  29. package/test/node_modules/@types/connect/README.md +16 -0
  30. package/test/node_modules/@types/connect/index.d.ts +93 -0
  31. package/test/node_modules/@types/connect/package.json +32 -0
  32. package/test/node_modules/@types/express/LICENSE +21 -0
  33. package/test/node_modules/@types/express/README.md +16 -0
  34. package/test/node_modules/@types/express/index.d.ts +136 -0
  35. package/test/node_modules/@types/express/package.json +45 -0
  36. package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
  37. package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
  38. package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
  39. package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
  40. package/test/node_modules/@types/mime/LICENSE +21 -0
  41. package/test/node_modules/@types/mime/Mime.d.ts +10 -0
  42. package/test/node_modules/@types/mime/README.md +16 -0
  43. package/test/node_modules/@types/mime/index.d.ts +35 -0
  44. package/test/node_modules/@types/mime/lite.d.ts +7 -0
  45. package/test/node_modules/@types/mime/package.json +29 -0
  46. package/test/node_modules/@types/qs/LICENSE +21 -0
  47. package/test/node_modules/@types/qs/README.md +16 -0
  48. package/test/node_modules/@types/qs/index.d.ts +62 -0
  49. package/test/node_modules/@types/qs/package.json +65 -0
  50. package/test/node_modules/@types/range-parser/LICENSE +21 -0
  51. package/test/node_modules/@types/range-parser/README.md +55 -0
  52. package/test/node_modules/@types/range-parser/index.d.ts +35 -0
  53. package/test/node_modules/@types/range-parser/package.json +25 -0
  54. package/test/node_modules/@types/send/LICENSE +21 -0
  55. package/test/node_modules/@types/send/README.md +16 -0
  56. package/test/node_modules/@types/send/index.d.ts +231 -0
  57. package/test/node_modules/@types/send/package.json +33 -0
  58. package/test/node_modules/@types/serve-static/LICENSE +21 -0
  59. package/test/node_modules/@types/serve-static/README.md +16 -0
  60. package/test/node_modules/@types/serve-static/index.d.ts +113 -0
  61. package/test/node_modules/@types/serve-static/package.json +38 -0
  62. package/test/src/config.json +5 -0
  63. package/test/src/custom-log.class.ts +6 -0
  64. package/test/src/jwt-authentication.class.ts +29 -0
  65. package/test/src/test-request.class.ts +36 -0
  66. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
  67. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
  68. package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
  69. package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
  70. package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
  71. package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
  72. package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
  73. package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
  74. package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
  75. package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
  76. package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
  77. package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
  78. package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
  79. package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
  80. package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
  81. package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
  82. package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
  83. package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  84. package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
  85. package/test/node_modules/amqplib/CHANGELOG.md +0 -430
  86. package/test/node_modules/amqplib/LICENSE +0 -6
  87. package/test/node_modules/amqplib/LICENSE-MIT +0 -21
  88. package/test/node_modules/amqplib/Makefile +0 -47
  89. package/test/node_modules/amqplib/README.md +0 -157
  90. package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
  91. package/test/node_modules/amqplib/callback_api.js +0 -22
  92. package/test/node_modules/amqplib/channel_api.js +0 -16
  93. package/test/node_modules/amqplib/examples/headers.js +0 -42
  94. package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
  95. package/test/node_modules/amqplib/examples/send_generators.js +0 -42
  96. package/test/node_modules/amqplib/examples/ssl.js +0 -64
  97. package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
  98. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
  99. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
  100. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
  101. package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
  102. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
  103. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
  104. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
  105. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
  106. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
  107. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
  108. package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
  109. package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
  110. package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
  111. package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
  112. package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
  113. package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
  114. package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
  115. package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
  116. package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
  117. package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
  118. package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
  119. package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
  120. package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
  121. package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
  122. package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
  123. package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
  124. package/test/node_modules/amqplib/lib/api_args.js +0 -314
  125. package/test/node_modules/amqplib/lib/bitset.js +0 -130
  126. package/test/node_modules/amqplib/lib/callback_model.js +0 -327
  127. package/test/node_modules/amqplib/lib/channel.js +0 -499
  128. package/test/node_modules/amqplib/lib/channel_model.js +0 -302
  129. package/test/node_modules/amqplib/lib/codec.js +0 -321
  130. package/test/node_modules/amqplib/lib/connect.js +0 -189
  131. package/test/node_modules/amqplib/lib/connection.js +0 -663
  132. package/test/node_modules/amqplib/lib/credentials.js +0 -42
  133. package/test/node_modules/amqplib/lib/defs.js +0 -4966
  134. package/test/node_modules/amqplib/lib/error.js +0 -24
  135. package/test/node_modules/amqplib/lib/format.js +0 -40
  136. package/test/node_modules/amqplib/lib/frame.js +0 -113
  137. package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
  138. package/test/node_modules/amqplib/lib/mux.js +0 -129
  139. package/test/node_modules/amqplib/package.json +0 -37
  140. package/test/node_modules/amqplib/test/bitset.js +0 -69
  141. package/test/node_modules/amqplib/test/callback_api.js +0 -312
  142. package/test/node_modules/amqplib/test/channel.js +0 -621
  143. package/test/node_modules/amqplib/test/channel_api.js +0 -596
  144. package/test/node_modules/amqplib/test/codec.js +0 -237
  145. package/test/node_modules/amqplib/test/connect.js +0 -197
  146. package/test/node_modules/amqplib/test/connection.js +0 -390
  147. package/test/node_modules/amqplib/test/data.js +0 -254
  148. package/test/node_modules/amqplib/test/frame.js +0 -198
  149. package/test/node_modules/amqplib/test/mux.js +0 -204
  150. package/test/node_modules/amqplib/test/util.js +0 -219
  151. package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
  152. package/test/node_modules/buffer-more-ints/LICENSE +0 -19
  153. package/test/node_modules/buffer-more-ints/README.md +0 -69
  154. package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
  155. package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
  156. package/test/node_modules/buffer-more-ints/package.json +0 -19
  157. package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
  158. package/test/node_modules/core-util-is/LICENSE +0 -19
  159. package/test/node_modules/core-util-is/README.md +0 -3
  160. package/test/node_modules/core-util-is/lib/util.js +0 -107
  161. package/test/node_modules/core-util-is/package.json +0 -38
  162. package/test/node_modules/debug/LICENSE +0 -20
  163. package/test/node_modules/debug/README.md +0 -481
  164. package/test/node_modules/debug/package.json +0 -59
  165. package/test/node_modules/debug/src/browser.js +0 -269
  166. package/test/node_modules/debug/src/common.js +0 -274
  167. package/test/node_modules/debug/src/index.js +0 -10
  168. package/test/node_modules/debug/src/node.js +0 -263
  169. package/test/node_modules/inherits/LICENSE +0 -16
  170. package/test/node_modules/inherits/README.md +0 -42
  171. package/test/node_modules/inherits/inherits.js +0 -9
  172. package/test/node_modules/inherits/inherits_browser.js +0 -27
  173. package/test/node_modules/inherits/package.json +0 -29
  174. package/test/node_modules/isarray/README.md +0 -54
  175. package/test/node_modules/isarray/build/build.js +0 -209
  176. package/test/node_modules/isarray/component.json +0 -19
  177. package/test/node_modules/isarray/index.js +0 -3
  178. package/test/node_modules/isarray/package.json +0 -25
  179. package/test/node_modules/ms/index.js +0 -162
  180. package/test/node_modules/ms/license.md +0 -21
  181. package/test/node_modules/ms/package.json +0 -37
  182. package/test/node_modules/ms/readme.md +0 -60
  183. package/test/node_modules/querystringify/LICENSE +0 -22
  184. package/test/node_modules/querystringify/README.md +0 -61
  185. package/test/node_modules/querystringify/index.js +0 -118
  186. package/test/node_modules/querystringify/package.json +0 -38
  187. package/test/node_modules/readable-stream/LICENSE +0 -18
  188. package/test/node_modules/readable-stream/README.md +0 -15
  189. package/test/node_modules/readable-stream/duplex.js +0 -1
  190. package/test/node_modules/readable-stream/float.patch +0 -923
  191. package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
  192. package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
  193. package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
  194. package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
  195. package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
  196. package/test/node_modules/readable-stream/package.json +0 -32
  197. package/test/node_modules/readable-stream/passthrough.js +0 -1
  198. package/test/node_modules/readable-stream/readable.js +0 -10
  199. package/test/node_modules/readable-stream/transform.js +0 -1
  200. package/test/node_modules/readable-stream/writable.js +0 -1
  201. package/test/node_modules/requires-port/.travis.yml +0 -19
  202. package/test/node_modules/requires-port/LICENSE +0 -22
  203. package/test/node_modules/requires-port/README.md +0 -47
  204. package/test/node_modules/requires-port/index.js +0 -38
  205. package/test/node_modules/requires-port/package.json +0 -47
  206. package/test/node_modules/requires-port/test.js +0 -98
  207. package/test/node_modules/safe-buffer/LICENSE +0 -21
  208. package/test/node_modules/safe-buffer/README.md +0 -584
  209. package/test/node_modules/safe-buffer/index.d.ts +0 -187
  210. package/test/node_modules/safe-buffer/index.js +0 -62
  211. package/test/node_modules/safe-buffer/package.json +0 -37
  212. package/test/node_modules/string_decoder/LICENSE +0 -20
  213. package/test/node_modules/string_decoder/README.md +0 -7
  214. package/test/node_modules/string_decoder/index.js +0 -221
  215. package/test/node_modules/string_decoder/package.json +0 -25
  216. package/test/node_modules/url-parse/LICENSE +0 -22
  217. package/test/node_modules/url-parse/README.md +0 -153
  218. package/test/node_modules/url-parse/dist/url-parse.js +0 -755
  219. package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
  220. package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
  221. package/test/node_modules/url-parse/index.js +0 -589
  222. package/test/node_modules/url-parse/package.json +0 -49
package/README.md CHANGED
@@ -6,29 +6,34 @@
6
6
  [![downloads](https://badgen.net/npm/dt/typespeed?color=pink)](https://www.npmjs.com/package/typespeed)
7
7
  [![license](https://badgen.net/github/license/speedphp/typespeed)](https://github.com/SpeedPHP/typespeed/blob/main/LICENSE)
8
8
 
9
- ## 特点
9
+ ### 特点
10
10
 
11
+ - 遵循 MIT 许可的开源项目。
12
+ - 提供 22 个 TypeScript 装饰器,这些装饰器构成了完整的 Web 框架功能,包括对象管理、Web 路由、数据库操作等。
13
+ - 通过命令行脚手架,可以快速创建项目,零配置启动。
14
+ - 基于依赖注入、AOP、中间件和启动扫描等编程理念开发实现。
15
+ - 底层采用 ExpressJS 实现,提供稳定、快速的 Web 服务。
16
+ - 框架提供了两种风格不同却各具优点的数据操作模式。
11
17
 
18
+ ### 安装
12
19
 
13
- ## 快速开始
20
+ TypeSpeed 环境要求 NodeJS 16+,TypeScript 运行时。
14
21
 
15
22
  ```sh
16
- nodemon
23
+ npm install typespeed -g
17
24
  ```
25
+ ### 使用
18
26
 
19
- ### 环境要求
27
+ ```sh
28
+ typespeed new blog
20
29
 
21
- * node v16+
30
+ cd ./blog
22
31
 
23
- * typescript
24
- ```sh
25
- npm install typescript@latest -g
26
- ```
32
+ npm install
27
33
 
28
- ### 安装
29
-
30
- ## 使用
34
+ npm run test
35
+ ```
31
36
 
32
- ## 开源协议
37
+ ### 开源协议
33
38
 
34
39
  [MIT](LICENSE) © speedphp
@@ -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);
@@ -25,7 +25,7 @@ program.on('--help', () => {
25
25
  console.log('');
26
26
  console.log(' Examples:');
27
27
  console.log('');
28
- console.log(' $ speed new blog');
28
+ console.log(' $ typespeed new blog');
29
29
  });
30
30
  program.parse(process.argv);
31
31
  function mkFile(fileName, targetPath, appName) {
@@ -192,12 +192,17 @@ declare abstract class LogFactory {
192
192
  * 日志打印方法
193
193
  * @param message 日志内容
194
194
  */
195
- abstract log(message?: any, ...optionalParams: any[]): void;
195
+ log(message?: any, ...optionalParams: any[]): void;
196
196
  /**
197
197
  * 错误日志打印方法
198
198
  * @param message 日志内容
199
199
  */
200
- abstract error(message?: any, ...optionalParams: any[]): void;
200
+ error(message?: any, ...optionalParams: any[]): void;
201
+ /**
202
+ * 调试日志打印方法
203
+ * @param message 日志内容
204
+ */
205
+ debug(message?: any, ...optionalParams: any[]): void;
201
206
  }
202
207
  /**数据源工厂类 */
203
208
  declare abstract class DataSourceFactory {
@@ -234,6 +239,23 @@ declare abstract class CacheFactory {
234
239
  /**清空缓存 */
235
240
  abstract flush(): void;
236
241
  }
242
+ /**认证类 */
243
+ declare abstract class AuthenticationFactory {
244
+ /**
245
+ * 路由页面执行前认证
246
+ * @param req 请求对象
247
+ * @param res 响应对象
248
+ * @param next 下一步函数
249
+ */
250
+ preHandle(req: express.Request, res: express.Response, next: express.NextFunction): void;
251
+ /**
252
+ * 开始执行中间件前认证
253
+ * @param req 请求对象
254
+ * @param res 响应对象
255
+ * @param next 下一步函数
256
+ */
257
+ afterCompletion(req: express.Request, res: express.Response, next: express.NextFunction): void;
258
+ }
237
259
  /**Redis 操作类 */
238
260
  declare class Redis extends IoRedis {
239
261
  /**获取 Redis 实例 */
@@ -322,4 +344,4 @@ declare class ExpressServer extends ServerFactory {
322
344
  private setDefaultMiddleware;
323
345
  }
324
346
 
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 };
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};
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.20",
3
+ "version": "2.0.22",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -20,6 +20,15 @@
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/speedphp/typespeed.git"
22
22
  },
23
+ "keywords": [
24
+ "framework",
25
+ "express",
26
+ "web",
27
+ "app",
28
+ "api",
29
+ "model",
30
+ "middleware"
31
+ ],
23
32
  "dependencies": {
24
33
  "@types/node": "^18.0.6",
25
34
  "commander": "^9.4.0",
@@ -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
  }