typespeed 2.2.1 → 2.3.2

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 (262) hide show
  1. package/app/nodemon.json +5 -0
  2. package/{test → app}/package.json +0 -1
  3. package/{test → app}/src/config-development.json +8 -1
  4. package/{test → app}/src/config.json +3 -4
  5. package/{test → app}/src/custom-log.class.ts +1 -1
  6. package/{test → app}/src/jwt-authentication.class.ts +3 -2
  7. package/{test → app}/src/main.ts +9 -2
  8. package/{test → app}/src/test-database.class.ts +1 -1
  9. package/app/src/test-log.class.ts +11 -0
  10. package/{test → app}/src/test-mq.class.ts +2 -6
  11. package/{test → app}/src/test-orm.class.ts +8 -8
  12. package/{test → app}/src/test-request.class.ts +4 -4
  13. package/{test → app}/src/user-model.class.ts +12 -11
  14. package/dist/core.decorator.js +1 -84
  15. package/dist/database.decorator.js +1 -1
  16. package/dist/default/express-server.class.js +10 -11
  17. package/dist/default/node-cache.class.js +2 -1
  18. package/dist/default/rabbitmq.class.js +3 -2
  19. package/dist/default/read-write-db.class.js +8 -7
  20. package/dist/default/redis.class.js +3 -2
  21. package/dist/factory/log-factory.class.js +0 -3
  22. package/dist/typespeed.js +85 -1
  23. package/package.json +15 -3
  24. package/src/core.decorator.ts +1 -85
  25. package/src/database.decorator.ts +1 -1
  26. package/src/default/express-server.class.ts +4 -5
  27. package/src/default/node-cache.class.ts +2 -1
  28. package/src/default/rabbitmq.class.ts +2 -1
  29. package/src/default/read-write-db.class.ts +2 -2
  30. package/src/default/redis.class.ts +2 -2
  31. package/src/factory/log-factory.class.ts +0 -3
  32. package/src/factory/server-factory.class.ts +1 -1
  33. package/src/typespeed.ts +86 -1
  34. package/test/database.test.ts +61 -0
  35. package/test/first-page.test.ts +41 -0
  36. package/test/hooks.ts +10 -0
  37. package/test/mq.test.ts +34 -0
  38. package/test/orm.test.ts +65 -0
  39. package/test/request.test.ts +50 -0
  40. package/test/second-page.test.ts +51 -0
  41. package/tsconfig.json +2 -3
  42. package/test/nodemon.json +0 -6
  43. package/test/src/test-log.class.ts +0 -9
  44. /package/{test → app}/node_modules/.package-lock.json +0 -0
  45. /package/{test → app}/node_modules/@types/body-parser/LICENSE +0 -0
  46. /package/{test → app}/node_modules/@types/body-parser/README.md +0 -0
  47. /package/{test → app}/node_modules/@types/body-parser/index.d.ts +0 -0
  48. /package/{test → app}/node_modules/@types/body-parser/package.json +0 -0
  49. /package/{test → app}/node_modules/@types/connect/LICENSE +0 -0
  50. /package/{test → app}/node_modules/@types/connect/README.md +0 -0
  51. /package/{test → app}/node_modules/@types/connect/index.d.ts +0 -0
  52. /package/{test → app}/node_modules/@types/connect/package.json +0 -0
  53. /package/{test → app}/node_modules/@types/express/LICENSE +0 -0
  54. /package/{test → app}/node_modules/@types/express/README.md +0 -0
  55. /package/{test → app}/node_modules/@types/express/index.d.ts +0 -0
  56. /package/{test → app}/node_modules/@types/express/package.json +0 -0
  57. /package/{test → app}/node_modules/@types/express-serve-static-core/LICENSE +0 -0
  58. /package/{test → app}/node_modules/@types/express-serve-static-core/README.md +0 -0
  59. /package/{test → app}/node_modules/@types/express-serve-static-core/index.d.ts +0 -0
  60. /package/{test → app}/node_modules/@types/express-serve-static-core/package.json +0 -0
  61. /package/{test → app}/node_modules/@types/mime/LICENSE +0 -0
  62. /package/{test → app}/node_modules/@types/mime/Mime.d.ts +0 -0
  63. /package/{test → app}/node_modules/@types/mime/README.md +0 -0
  64. /package/{test → app}/node_modules/@types/mime/index.d.ts +0 -0
  65. /package/{test → app}/node_modules/@types/mime/lite.d.ts +0 -0
  66. /package/{test → app}/node_modules/@types/mime/package.json +0 -0
  67. /package/{test → app}/node_modules/@types/node/LICENSE +0 -0
  68. /package/{test → app}/node_modules/@types/node/README.md +0 -0
  69. /package/{test → app}/node_modules/@types/node/assert/strict.d.ts +0 -0
  70. /package/{test → app}/node_modules/@types/node/assert.d.ts +0 -0
  71. /package/{test → app}/node_modules/@types/node/async_hooks.d.ts +0 -0
  72. /package/{test → app}/node_modules/@types/node/buffer.d.ts +0 -0
  73. /package/{test → app}/node_modules/@types/node/child_process.d.ts +0 -0
  74. /package/{test → app}/node_modules/@types/node/cluster.d.ts +0 -0
  75. /package/{test → app}/node_modules/@types/node/console.d.ts +0 -0
  76. /package/{test → app}/node_modules/@types/node/constants.d.ts +0 -0
  77. /package/{test → app}/node_modules/@types/node/crypto.d.ts +0 -0
  78. /package/{test → app}/node_modules/@types/node/dgram.d.ts +0 -0
  79. /package/{test → app}/node_modules/@types/node/diagnostics_channel.d.ts +0 -0
  80. /package/{test → app}/node_modules/@types/node/dns/promises.d.ts +0 -0
  81. /package/{test → app}/node_modules/@types/node/dns.d.ts +0 -0
  82. /package/{test → app}/node_modules/@types/node/dom-events.d.ts +0 -0
  83. /package/{test → app}/node_modules/@types/node/domain.d.ts +0 -0
  84. /package/{test → app}/node_modules/@types/node/events.d.ts +0 -0
  85. /package/{test → app}/node_modules/@types/node/fs/promises.d.ts +0 -0
  86. /package/{test → app}/node_modules/@types/node/fs.d.ts +0 -0
  87. /package/{test → app}/node_modules/@types/node/globals.d.ts +0 -0
  88. /package/{test → app}/node_modules/@types/node/globals.global.d.ts +0 -0
  89. /package/{test → app}/node_modules/@types/node/http.d.ts +0 -0
  90. /package/{test → app}/node_modules/@types/node/http2.d.ts +0 -0
  91. /package/{test → app}/node_modules/@types/node/https.d.ts +0 -0
  92. /package/{test → app}/node_modules/@types/node/index.d.ts +0 -0
  93. /package/{test → app}/node_modules/@types/node/inspector.d.ts +0 -0
  94. /package/{test → app}/node_modules/@types/node/module.d.ts +0 -0
  95. /package/{test → app}/node_modules/@types/node/net.d.ts +0 -0
  96. /package/{test → app}/node_modules/@types/node/os.d.ts +0 -0
  97. /package/{test → app}/node_modules/@types/node/package.json +0 -0
  98. /package/{test → app}/node_modules/@types/node/path.d.ts +0 -0
  99. /package/{test → app}/node_modules/@types/node/perf_hooks.d.ts +0 -0
  100. /package/{test → app}/node_modules/@types/node/process.d.ts +0 -0
  101. /package/{test → app}/node_modules/@types/node/punycode.d.ts +0 -0
  102. /package/{test → app}/node_modules/@types/node/querystring.d.ts +0 -0
  103. /package/{test → app}/node_modules/@types/node/readline/promises.d.ts +0 -0
  104. /package/{test → app}/node_modules/@types/node/readline.d.ts +0 -0
  105. /package/{test → app}/node_modules/@types/node/repl.d.ts +0 -0
  106. /package/{test → app}/node_modules/@types/node/stream/consumers.d.ts +0 -0
  107. /package/{test → app}/node_modules/@types/node/stream/promises.d.ts +0 -0
  108. /package/{test → app}/node_modules/@types/node/stream/web.d.ts +0 -0
  109. /package/{test → app}/node_modules/@types/node/stream.d.ts +0 -0
  110. /package/{test → app}/node_modules/@types/node/string_decoder.d.ts +0 -0
  111. /package/{test → app}/node_modules/@types/node/test.d.ts +0 -0
  112. /package/{test → app}/node_modules/@types/node/timers/promises.d.ts +0 -0
  113. /package/{test → app}/node_modules/@types/node/timers.d.ts +0 -0
  114. /package/{test → app}/node_modules/@types/node/tls.d.ts +0 -0
  115. /package/{test → app}/node_modules/@types/node/trace_events.d.ts +0 -0
  116. /package/{test → app}/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -0
  117. /package/{test → app}/node_modules/@types/node/ts4.8/assert.d.ts +0 -0
  118. /package/{test → app}/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -0
  119. /package/{test → app}/node_modules/@types/node/ts4.8/buffer.d.ts +0 -0
  120. /package/{test → app}/node_modules/@types/node/ts4.8/child_process.d.ts +0 -0
  121. /package/{test → app}/node_modules/@types/node/ts4.8/cluster.d.ts +0 -0
  122. /package/{test → app}/node_modules/@types/node/ts4.8/console.d.ts +0 -0
  123. /package/{test → app}/node_modules/@types/node/ts4.8/constants.d.ts +0 -0
  124. /package/{test → app}/node_modules/@types/node/ts4.8/crypto.d.ts +0 -0
  125. /package/{test → app}/node_modules/@types/node/ts4.8/dgram.d.ts +0 -0
  126. /package/{test → app}/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -0
  127. /package/{test → app}/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -0
  128. /package/{test → app}/node_modules/@types/node/ts4.8/dns.d.ts +0 -0
  129. /package/{test → app}/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -0
  130. /package/{test → app}/node_modules/@types/node/ts4.8/domain.d.ts +0 -0
  131. /package/{test → app}/node_modules/@types/node/ts4.8/events.d.ts +0 -0
  132. /package/{test → app}/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -0
  133. /package/{test → app}/node_modules/@types/node/ts4.8/fs.d.ts +0 -0
  134. /package/{test → app}/node_modules/@types/node/ts4.8/globals.d.ts +0 -0
  135. /package/{test → app}/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -0
  136. /package/{test → app}/node_modules/@types/node/ts4.8/http.d.ts +0 -0
  137. /package/{test → app}/node_modules/@types/node/ts4.8/http2.d.ts +0 -0
  138. /package/{test → app}/node_modules/@types/node/ts4.8/https.d.ts +0 -0
  139. /package/{test → app}/node_modules/@types/node/ts4.8/index.d.ts +0 -0
  140. /package/{test → app}/node_modules/@types/node/ts4.8/inspector.d.ts +0 -0
  141. /package/{test → app}/node_modules/@types/node/ts4.8/module.d.ts +0 -0
  142. /package/{test → app}/node_modules/@types/node/ts4.8/net.d.ts +0 -0
  143. /package/{test → app}/node_modules/@types/node/ts4.8/os.d.ts +0 -0
  144. /package/{test → app}/node_modules/@types/node/ts4.8/path.d.ts +0 -0
  145. /package/{test → app}/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -0
  146. /package/{test → app}/node_modules/@types/node/ts4.8/process.d.ts +0 -0
  147. /package/{test → app}/node_modules/@types/node/ts4.8/punycode.d.ts +0 -0
  148. /package/{test → app}/node_modules/@types/node/ts4.8/querystring.d.ts +0 -0
  149. /package/{test → app}/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -0
  150. /package/{test → app}/node_modules/@types/node/ts4.8/readline.d.ts +0 -0
  151. /package/{test → app}/node_modules/@types/node/ts4.8/repl.d.ts +0 -0
  152. /package/{test → app}/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -0
  153. /package/{test → app}/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -0
  154. /package/{test → app}/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -0
  155. /package/{test → app}/node_modules/@types/node/ts4.8/stream.d.ts +0 -0
  156. /package/{test → app}/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -0
  157. /package/{test → app}/node_modules/@types/node/ts4.8/test.d.ts +0 -0
  158. /package/{test → app}/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -0
  159. /package/{test → app}/node_modules/@types/node/ts4.8/timers.d.ts +0 -0
  160. /package/{test → app}/node_modules/@types/node/ts4.8/tls.d.ts +0 -0
  161. /package/{test → app}/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -0
  162. /package/{test → app}/node_modules/@types/node/ts4.8/tty.d.ts +0 -0
  163. /package/{test → app}/node_modules/@types/node/ts4.8/url.d.ts +0 -0
  164. /package/{test → app}/node_modules/@types/node/ts4.8/util.d.ts +0 -0
  165. /package/{test → app}/node_modules/@types/node/ts4.8/v8.d.ts +0 -0
  166. /package/{test → app}/node_modules/@types/node/ts4.8/vm.d.ts +0 -0
  167. /package/{test → app}/node_modules/@types/node/ts4.8/wasi.d.ts +0 -0
  168. /package/{test → app}/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -0
  169. /package/{test → app}/node_modules/@types/node/ts4.8/zlib.d.ts +0 -0
  170. /package/{test → app}/node_modules/@types/node/tty.d.ts +0 -0
  171. /package/{test → app}/node_modules/@types/node/url.d.ts +0 -0
  172. /package/{test → app}/node_modules/@types/node/util.d.ts +0 -0
  173. /package/{test → app}/node_modules/@types/node/v8.d.ts +0 -0
  174. /package/{test → app}/node_modules/@types/node/vm.d.ts +0 -0
  175. /package/{test → app}/node_modules/@types/node/wasi.d.ts +0 -0
  176. /package/{test → app}/node_modules/@types/node/worker_threads.d.ts +0 -0
  177. /package/{test → app}/node_modules/@types/node/zlib.d.ts +0 -0
  178. /package/{test → app}/node_modules/@types/qs/LICENSE +0 -0
  179. /package/{test → app}/node_modules/@types/qs/README.md +0 -0
  180. /package/{test → app}/node_modules/@types/qs/index.d.ts +0 -0
  181. /package/{test → app}/node_modules/@types/qs/package.json +0 -0
  182. /package/{test → app}/node_modules/@types/range-parser/LICENSE +0 -0
  183. /package/{test → app}/node_modules/@types/range-parser/README.md +0 -0
  184. /package/{test → app}/node_modules/@types/range-parser/index.d.ts +0 -0
  185. /package/{test → app}/node_modules/@types/range-parser/package.json +0 -0
  186. /package/{test → app}/node_modules/@types/send/LICENSE +0 -0
  187. /package/{test → app}/node_modules/@types/send/README.md +0 -0
  188. /package/{test → app}/node_modules/@types/send/index.d.ts +0 -0
  189. /package/{test → app}/node_modules/@types/send/package.json +0 -0
  190. /package/{test → app}/node_modules/@types/serve-static/LICENSE +0 -0
  191. /package/{test → app}/node_modules/@types/serve-static/README.md +0 -0
  192. /package/{test → app}/node_modules/@types/serve-static/index.d.ts +0 -0
  193. /package/{test → app}/node_modules/@types/serve-static/package.json +0 -0
  194. /package/{test → app}/node_modules/colors/LICENSE +0 -0
  195. /package/{test → app}/node_modules/colors/README.md +0 -0
  196. /package/{test → app}/node_modules/colors/examples/normal-usage.js +0 -0
  197. /package/{test → app}/node_modules/colors/examples/safe-string.js +0 -0
  198. /package/{test → app}/node_modules/colors/index.d.ts +0 -0
  199. /package/{test → app}/node_modules/colors/lib/colors.js +0 -0
  200. /package/{test → app}/node_modules/colors/lib/custom/trap.js +0 -0
  201. /package/{test → app}/node_modules/colors/lib/custom/zalgo.js +0 -0
  202. /package/{test → app}/node_modules/colors/lib/extendStringPrototype.js +0 -0
  203. /package/{test → app}/node_modules/colors/lib/index.js +0 -0
  204. /package/{test → app}/node_modules/colors/lib/maps/america.js +0 -0
  205. /package/{test → app}/node_modules/colors/lib/maps/rainbow.js +0 -0
  206. /package/{test → app}/node_modules/colors/lib/maps/random.js +0 -0
  207. /package/{test → app}/node_modules/colors/lib/maps/zebra.js +0 -0
  208. /package/{test → app}/node_modules/colors/lib/styles.js +0 -0
  209. /package/{test → app}/node_modules/colors/lib/system/has-flag.js +0 -0
  210. /package/{test → app}/node_modules/colors/lib/system/supports-colors.js +0 -0
  211. /package/{test → app}/node_modules/colors/package.json +0 -0
  212. /package/{test → app}/node_modules/colors/safe.d.ts +0 -0
  213. /package/{test → app}/node_modules/colors/safe.js +0 -0
  214. /package/{test → app}/node_modules/colors/themes/generic-logging.js +0 -0
  215. /package/{test → app}/node_modules/dateformat/LICENSE +0 -0
  216. /package/{test → app}/node_modules/dateformat/Readme.md +0 -0
  217. /package/{test → app}/node_modules/dateformat/lib/dateformat.js +0 -0
  218. /package/{test → app}/node_modules/dateformat/package.json +0 -0
  219. /package/{test → app}/node_modules/mkdirp/CHANGELOG.md +0 -0
  220. /package/{test → app}/node_modules/mkdirp/LICENSE +0 -0
  221. /package/{test → app}/node_modules/mkdirp/bin/cmd.js +0 -0
  222. /package/{test → app}/node_modules/mkdirp/index.js +0 -0
  223. /package/{test → app}/node_modules/mkdirp/lib/find-made.js +0 -0
  224. /package/{test → app}/node_modules/mkdirp/lib/mkdirp-manual.js +0 -0
  225. /package/{test → app}/node_modules/mkdirp/lib/mkdirp-native.js +0 -0
  226. /package/{test → app}/node_modules/mkdirp/lib/opts-arg.js +0 -0
  227. /package/{test → app}/node_modules/mkdirp/lib/path-arg.js +0 -0
  228. /package/{test → app}/node_modules/mkdirp/lib/use-native.js +0 -0
  229. /package/{test → app}/node_modules/mkdirp/package.json +0 -0
  230. /package/{test → app}/node_modules/mkdirp/readme.markdown +0 -0
  231. /package/{test → app}/node_modules/tinytim/.travis.yml +0 -0
  232. /package/{test → app}/node_modules/tinytim/README.md +0 -0
  233. /package/{test → app}/node_modules/tinytim/index.js +0 -0
  234. /package/{test → app}/node_modules/tinytim/lib/index.js +0 -0
  235. /package/{test → app}/node_modules/tinytim/lib/tinytim.js +0 -0
  236. /package/{test → app}/node_modules/tinytim/package.json +0 -0
  237. /package/{test → app}/node_modules/tinytim/test/files/html.tim +0 -0
  238. /package/{test → app}/node_modules/tinytim/test/files/string.tim +0 -0
  239. /package/{test → app}/node_modules/tinytim/test/files/string2.tim +0 -0
  240. /package/{test → app}/node_modules/tinytim/test/render-file-replace.js +0 -0
  241. /package/{test → app}/node_modules/tinytim/test/render-replace.js +0 -0
  242. /package/{test → app}/node_modules/tinytim/test/tim-replace.js +0 -0
  243. /package/{test → app}/node_modules/tracer/README.md +0 -0
  244. /package/{test → app}/node_modules/tracer/lib/color_console.js +0 -0
  245. /package/{test → app}/node_modules/tracer/lib/console.js +0 -0
  246. /package/{test → app}/node_modules/tracer/lib/dailyfile.js +0 -0
  247. /package/{test → app}/node_modules/tracer/lib/index.js +0 -0
  248. /package/{test → app}/node_modules/tracer/lib/settings.js +0 -0
  249. /package/{test → app}/node_modules/tracer/lib/utils.js +0 -0
  250. /package/{test → app}/node_modules/tracer/package.json +0 -0
  251. /package/{test → app}/node_modules/tracer/types/index.d.ts +0 -0
  252. /package/{test → app}/src/aop-test.class.ts +0 -0
  253. /package/{test → app}/src/config-production.json +0 -0
  254. /package/{test → app}/src/entities/mutil-users.class.ts +0 -0
  255. /package/{test → app}/src/entities/user-dto.class.ts +0 -0
  256. /package/{test → app}/src/first-page.class.ts +0 -0
  257. /package/{test → app}/src/second-page.class.ts +0 -0
  258. /package/{test → app}/src/views/index.html +0 -0
  259. /package/{test → app}/src/views/upload.html +0 -0
  260. /package/{test → app}/static/favicon.ico +0 -0
  261. /package/{test → app}/static/k.jpg +0 -0
  262. /package/{test → app}/tsconfig.json +0 -0
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.2.1",
3
+ "version": "2.3.2",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
7
7
  "scripts": {
8
+ "test": "mocha --require ts-node/register test/**/*.ts --exit",
9
+ "test-with-coverage": "nyc --reporter=text npm test",
10
+ "start": "ts-node --transpile-only app/src/main.ts",
8
11
  "build": "tsc -p .",
9
12
  "postbuild": "cp src/typespeed.d.ts dist/typespeed.d.ts && cp -r src/default/pages dist/default/pages && cp -r src/scaffold/templates dist/scaffold/templates",
10
13
  "prebuild": "rm -rf dist",
@@ -30,7 +33,6 @@
30
33
  "middleware"
31
34
  ],
32
35
  "dependencies": {
33
- "@types/node": "^18.0.6",
34
36
  "commander": "^9.4.0",
35
37
  "compression": "^1.7.4",
36
38
  "connect-redis": "^6.1.3",
@@ -50,8 +52,18 @@
50
52
  "reflect-metadata": "^0.1.13",
51
53
  "serve-favicon": "^2.5.0",
52
54
  "tracer": "^1.1.6",
53
- "typescript": "^4.7.4",
54
55
  "walk-sync": "^3.0.0",
55
56
  "amqplib": "0.10.3"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^18.0.6",
60
+ "@types/express": "^4.17.13",
61
+ "@types/mocha": "^10.0.1",
62
+ "chai": "4.3.7",
63
+ "chai-http": "^4.4.0",
64
+ "mocha": "10.2.0",
65
+ "nyc": "^15.1.0",
66
+ "ts-node": "^10.9.1",
67
+ "typescript": "^4.9.5"
56
68
  }
57
69
  }
@@ -1,55 +1,11 @@
1
1
  import "reflect-metadata";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import * as walkSync from "walk-sync";
5
2
  import * as cron from "cron";
6
3
  import LogFactory from "./factory/log-factory.class";
7
4
 
8
- let globalConfig = {};
9
5
  const resourceObjects = new Map<string, object>();
10
6
  const beanMapper: Map<string, any> = new Map<string, any>();
11
7
  const objectMapper: Map<string, any> = new Map<string, any>();
12
8
 
13
- function app<T extends { new(...args: any[]): {} }>(constructor: T) {
14
- const coreDir = __dirname;
15
- const mainPath = path.dirname(getRootPath() || process.argv[1]);
16
- const configFile = mainPath + "/config.json";
17
- if (fs.existsSync(configFile)) {
18
- globalConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
19
- const nodeEnv = process.env.NODE_ENV || "development";
20
- const envConfigFile = mainPath + "/config-" + nodeEnv + ".json";
21
- if (fs.existsSync(envConfigFile)) {
22
- globalConfig = Object.assign(globalConfig, JSON.parse(fs.readFileSync(envConfigFile, "utf-8")));
23
- }
24
- }
25
-
26
- const coreFiles = walkSync(coreDir, { globs: ['**/*.ts'], ignore: ['**/*.d.ts', 'scaffold/**'] });
27
- const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
28
-
29
- (async function () {
30
- try {
31
- for (let p of coreFiles) {
32
- let moduleName = p.replace(".d.ts", "").replace(".ts", "");
33
- await import(coreDir + "/" + moduleName);
34
- }
35
-
36
- for (let p of mainFiles) {
37
- let moduleName = p.replace(".d.ts", "").replace(".ts", "");
38
- await import(mainPath + "/" + moduleName);
39
- }
40
- } catch (err) {
41
- console.error(err);
42
- }
43
- //log("main start")
44
- const main = new constructor();
45
- main["main"]();
46
- }());
47
- }
48
-
49
- function config(node: string) {
50
- return globalConfig[node] || null;
51
- }
52
-
53
9
  function component(constructorFunction) {
54
10
  objectMapper.set(constructorFunction.name, new constructorFunction());
55
11
  }
@@ -72,28 +28,6 @@ function getBean(mappingClass: Function): any {
72
28
  return bean["factory"];
73
29
  }
74
30
 
75
- function value(configPath: string): any {
76
- return function (target: any, propertyKey: string) {
77
- if (globalConfig === undefined) {
78
- Object.defineProperty(target, propertyKey, {
79
- get: () => {
80
- return undefined;
81
- }
82
- });
83
- } else {
84
- let pathNodes = configPath.split(".");
85
- let nodeValue = globalConfig;
86
- for (let i = 0; i < pathNodes.length; i++) {
87
- nodeValue = nodeValue[pathNodes[i]];
88
- }
89
- Object.defineProperty(target, propertyKey, {
90
- get: () => {
91
- return nodeValue;
92
- }
93
- });
94
- }
95
- };
96
- }
97
31
 
98
32
  function autoware(target: any, propertyKey: string): void {
99
33
  const type = Reflect.getMetadata("design:type", target, propertyKey);
@@ -145,28 +79,10 @@ function error(message?: any, ...optionalParams: any[]) {
145
79
  }
146
80
  }
147
81
 
148
- function getRootPath() {
149
- const lines = new Error().stack.split("\n");
150
- let rootPath = "";
151
- let lastLine = "";
152
- for (let line of lines) {
153
- if (line.includes("at ") &&
154
- line.includes("node:internal/modules/cjs/loader") &&
155
- line.includes("Module._compile") &&
156
- lastLine.includes("at ") &&
157
- lastLine.includes("Object.<anonymous>")) {
158
- rootPath = lastLine.split("(")[1].split(":")[0];
159
- break;
160
- }
161
- lastLine = line;
162
- }
163
- return rootPath;
164
- }
165
-
166
82
  function schedule(cronTime: string | Date) {
167
83
  return (target: any, propertyKey: string) => {
168
84
  new cron.CronJob(cronTime, target[propertyKey]).start();
169
85
  }
170
86
  }
171
87
 
172
- export { component, bean, resource, log, app, value, error, config, autoware, getBean, getComponent, schedule };
88
+ export { component, bean, resource, log, error, autoware, getBean, getComponent, schedule };
@@ -72,7 +72,7 @@ function select(sql: string) {
72
72
 
73
73
  function resultType(dataClass) {
74
74
  return function (target, propertyKey: string) {
75
- resultTypeMap.set([target.constructor.name, propertyKey].toString(), new dataClass());
75
+ resultTypeMap.set([target.constructor.name, propertyKey].toString(), dataClass);
76
76
  //never return
77
77
  };
78
78
  }
@@ -8,7 +8,8 @@ import * as expressSession from "express-session";
8
8
  import * as connectRedis from "connect-redis";
9
9
  import ServerFactory from "../factory/server-factory.class";
10
10
  import { setRouter } from "../route.decorator";
11
- import { bean, log, value, error, autoware } from "../core.decorator";
11
+ import { value } from "../typespeed";
12
+ import { bean, log, error, autoware } from "../core.decorator";
12
13
  import Redis from "./redis.class";
13
14
  import AuthenticationFactory from "../factory/authentication-factory.class";
14
15
 
@@ -52,7 +53,7 @@ export default class ExpressServer extends ServerFactory {
52
53
  this.middlewareList.push(middleware);
53
54
  }
54
55
 
55
- public start(port: number): any {
56
+ public start(port: number, callback?: Function): any {
56
57
  this.app.use(this.authentication.afterCompletion);
57
58
  this.middlewareList.forEach(middleware => {
58
59
  this.app.use(middleware);
@@ -60,9 +61,7 @@ export default class ExpressServer extends ServerFactory {
60
61
 
61
62
  this.setDefaultMiddleware();
62
63
 
63
- return this.app.listen(port, () => {
64
- log("server start at port: " + port);
65
- });
64
+ return this.app.listen(port, callback);
66
65
  }
67
66
 
68
67
  private setDefaultMiddleware() {
@@ -1,6 +1,7 @@
1
1
  import CacheFactory from "../factory/cache-factory.class";
2
2
  import * as cache from "node-cache";
3
- import { value, bean } from "../core.decorator";
3
+ import { value } from "../typespeed";
4
+ import { bean } from "../core.decorator";
4
5
 
5
6
  export default class NodeCache extends CacheFactory {
6
7
  private NodeCache: any;
@@ -1,4 +1,5 @@
1
- import { bean, config } from "../core.decorator";
1
+ import { bean } from "../core.decorator";
2
+ import { config } from "../typespeed";
2
3
  import { connect } from "amqplib";
3
4
  let rabbitConnection = null;
4
5
 
@@ -1,7 +1,7 @@
1
1
  import { createConnection, createPool } from "mysql2";
2
2
  import DataSourceFactory from "../factory/data-source-factory.class";
3
- import { bean, config } from "../core.decorator";
4
-
3
+ import { bean } from "../core.decorator";
4
+ import { config } from "../typespeed";
5
5
  export default class ReadWriteDb extends DataSourceFactory {
6
6
  private readonly readSession;
7
7
  private readonly writeSession;
@@ -1,6 +1,6 @@
1
- import { bean, config } from "../core.decorator";
1
+ import { bean } from "../core.decorator";
2
2
  import IoRedis from "ioredis";
3
-
3
+ import { config } from "../typespeed";
4
4
  export default class Redis extends IoRedis {
5
5
 
6
6
  @bean
@@ -5,7 +5,4 @@ export default abstract class LogFactory {
5
5
  public error(message?: any, ...optionalParams: any[]) : void {
6
6
  console.error(message, ...optionalParams);
7
7
  }
8
- public debug(message?: any, ...optionalParams: any[]) : void {
9
- console.debug(message, ...optionalParams);
10
- }
11
8
  }
@@ -2,5 +2,5 @@ export default abstract class ServerFactory {
2
2
  public app;
3
3
  protected middlewareList: Array<any> = [];
4
4
  public abstract setMiddleware(middleware: any);
5
- public abstract start(port: number);
5
+ public abstract start(port: number, callback?: Function): any;
6
6
  }
package/src/typespeed.ts CHANGED
@@ -1,8 +1,93 @@
1
+ import "reflect-metadata";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import * as walkSync from "walk-sync";
5
+
6
+ let globalConfig = {};
7
+ const coreDir = __dirname;
8
+ const mainPath = path.dirname(getRootPath(new Error().stack.split("\n")) || process.argv[1]);
9
+ const configFile = mainPath + "/config.json";
10
+ if (fs.existsSync(configFile)) {
11
+ globalConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
12
+ const nodeEnv = process.env.NODE_ENV || "development";
13
+ const envConfigFile = mainPath + "/config-" + nodeEnv + ".json";
14
+ if (fs.existsSync(envConfigFile)) {
15
+ globalConfig = Object.assign(globalConfig, JSON.parse(fs.readFileSync(envConfigFile, "utf-8")));
16
+ }
17
+ }
18
+
19
+ function app<T extends { new(...args: any[]): {} }>(constructor: T) {
20
+ const coreFiles = walkSync(coreDir, { globs: ['**/*.ts'], ignore: ['**/*.d.ts', 'scaffold/**'] });
21
+ const mainFiles = walkSync(mainPath, { globs: ['**/*.ts'] });
22
+
23
+ (async function () {
24
+ try {
25
+ for (let p of coreFiles) {
26
+ let moduleName = p.replace(".d.ts", "").replace(".ts", "");
27
+ await import(coreDir + "/" + moduleName);
28
+ }
29
+
30
+ for (let p of mainFiles) {
31
+ let moduleName = p.replace(".d.ts", "").replace(".ts", "");
32
+ await import(mainPath + "/" + moduleName);
33
+ }
34
+ } catch (err) {
35
+ console.error(err);
36
+ }
37
+ //log("main start")
38
+ const main = new constructor();
39
+ main["main"]();
40
+ }());
41
+ }
42
+
43
+ function config(node: string) {
44
+ return globalConfig[node] || null;
45
+ }
46
+
47
+ function value(configPath: string): any {
48
+ return function (target: any, propertyKey: string) {
49
+ if (globalConfig === undefined) {
50
+ Object.defineProperty(target, propertyKey, {
51
+ get: () => {
52
+ return undefined;
53
+ }
54
+ });
55
+ } else {
56
+ let pathNodes = configPath.split(".");
57
+ let nodeValue = globalConfig;
58
+ for (let i = 0; i < pathNodes.length; i++) {
59
+ nodeValue = nodeValue[pathNodes[i]];
60
+ }
61
+ Object.defineProperty(target, propertyKey, {
62
+ get: () => {
63
+ return nodeValue;
64
+ }
65
+ });
66
+ }
67
+ };
68
+ }
69
+
70
+ function getRootPath(lines: string[]) {
71
+ const macths = ["at Function.Module._load", "at Module.require", "at require", "at Object.<anonymous>"];
72
+ let matchIndex = 0;
73
+ for (let line of lines) {
74
+ if (line.includes(macths[matchIndex])) {
75
+ if(matchIndex === macths.length - 1) {
76
+ return line.split("(")[1].split(":")[0];
77
+ }
78
+ matchIndex++;
79
+ }else{
80
+ matchIndex = 0;
81
+ }
82
+ }
83
+ return undefined;
84
+ }
85
+
86
+ export { app, value, config };
1
87
  export * from "./core.decorator";
2
88
  export * from "./route.decorator";
3
89
  export * from "./database.decorator";
4
90
 
5
-
6
91
  export { default as LogFactory} from "./factory/log-factory.class";
7
92
  export { default as CacheFactory} from "./factory/cache-factory.class";
8
93
  export { default as DataSourceFactory} from "./factory/data-source-factory.class";
@@ -0,0 +1,61 @@
1
+ const chaiObj = require('chai');
2
+ chaiObj.use(require("chai-http"));
3
+ const expect = chaiObj.expect;
4
+ describe("Test Database", () => {
5
+ const testDatabase = [
6
+ {
7
+ "url": "/db/insert?id=" + Math.ceil(Math.random() * 1000),
8
+ "expect": "Insert success",
9
+ },
10
+ {
11
+ "url": "/db/insert2",
12
+ "expect": "Insert success",
13
+ },
14
+ {
15
+ "url": "/db/update",
16
+ "expect": "update success",
17
+ },
18
+ {
19
+ "url": "/db/set-cache?value=zzz",
20
+ "expect": "set cache success",
21
+ },
22
+ {
23
+ "url": "/db/get-cache",
24
+ "expect": "zzz",
25
+ }
26
+ ]
27
+ testDatabase.forEach((testRequest) => {
28
+ it(testRequest.url, (done) => {
29
+ chaiObj.request("http://localhost:8081").get(testRequest.url).end((err, res) => {
30
+ chaiObj.assert.equal(testRequest.expect, res.text);
31
+ return done();
32
+ });
33
+ });
34
+ });
35
+ it("/db/select1", (done) => {
36
+ chaiObj.request("http://localhost:8081").get("/db/select1").end((err, res) => {
37
+ const dataList = JSON.parse(res.text);
38
+ expect(dataList).to.be.an('array');
39
+ expect(dataList[0]).to.have.property("id").which.is.a("number").equal(1);
40
+ done();
41
+ });
42
+ });
43
+ it("/db/select", (done) => {
44
+ chaiObj.request("http://localhost:8081").get("/db/select").end((err, res) => {
45
+ const dataList = JSON.parse(res.text);
46
+ expect(dataList).to.be.an('array');
47
+ expect(dataList[0]).to.have.property('id');
48
+ done();
49
+ });
50
+ });
51
+ it("/db/select-user", (done) => {
52
+ chaiObj.request("http://localhost:8081").get("/db/select-user").end((err, res) => {
53
+ const dataList = JSON.parse(res.text);
54
+ expect(dataList).to.be.an('array');
55
+ expect(dataList[0]).to.have.property('id');
56
+ done();
57
+ });
58
+ });
59
+ });
60
+
61
+ export {};
@@ -0,0 +1,41 @@
1
+ const chaiObj = require('chai');
2
+ chaiObj.use(require("chai-http"));
3
+
4
+ describe("Test First page", () => {
5
+ const firstPageRequests = [
6
+ {
7
+ "url": "/first",
8
+ "expect": "FirstPage index running",
9
+ },
10
+ {
11
+ "url": "/first/sendJson",
12
+ "expect": JSON.stringify({
13
+ "from": "sendJson",
14
+ "to": "Browser"
15
+ }),
16
+ },
17
+ {
18
+ "url": "/first/sendResult",
19
+ "expect": "sendResult",
20
+ },
21
+ {
22
+ "url": "/first/renderTest",
23
+ "expect": "Hello zzz!",
24
+ },
25
+ {
26
+ "url": "/test/error",
27
+ "expect": "This is a error log",
28
+ }
29
+ ]
30
+ firstPageRequests.forEach((testRequest) => {
31
+ it(testRequest.url, (done) => {
32
+ chaiObj.request("http://localhost:8081").get(testRequest.url).end((err, res) => {
33
+ chaiObj.assert.equal(testRequest.expect, res.text);
34
+ return done();
35
+ });
36
+ });
37
+ });
38
+
39
+ });
40
+
41
+ export {};
package/test/hooks.ts ADDED
@@ -0,0 +1,10 @@
1
+ let appClose;
2
+ before(() => {
3
+ appClose = require("../app/src/main");
4
+ });
5
+
6
+ after(() => {
7
+ if(appClose != null){
8
+ appClose.default();
9
+ }
10
+ });
@@ -0,0 +1,34 @@
1
+ const chaiObj = require('chai');
2
+
3
+ chaiObj.use(require("chai-http"));
4
+
5
+ const expect = chaiObj.expect;
6
+
7
+ describe("Test RabbitMQ", () => {
8
+ it("/mq/listen", (done) => {
9
+ chaiObj.request("http://localhost:8081").get("/mq/listen").end((err, res) => {
10
+ expect(res.text).to.be.equal("ok");
11
+ done();
12
+ });
13
+ });
14
+ it("/mq/sendByMQClass", (done) => {
15
+ chaiObj.request("http://localhost:8081").get("/mq/sendByMQClass").end((err, res) => {
16
+ expect(res.text).to.be.equal("sent by MQClass");
17
+ done();
18
+ });
19
+ });
20
+ it("/mq/sendByQueue", (done) => {
21
+ chaiObj.request("http://localhost:8081").get("/mq/sendByQueue").end((err, res) => {
22
+ expect(res.text).to.be.equal("sent by queue");
23
+ done();
24
+ });
25
+ });
26
+ it("/mq/sendByExchange", (done) => {
27
+ chaiObj.request("http://localhost:8081").get("/mq/sendByExchange").end((err, res) => {
28
+ expect(res.text).to.be.equal("sent by exchange");
29
+ done();
30
+ });
31
+ });
32
+ });
33
+
34
+ export { };
@@ -0,0 +1,65 @@
1
+ const chaiObj = require('chai');
2
+ chaiObj.use(require("chai-http"));
3
+ const expect = chaiObj.expect;
4
+
5
+ describe("Test Request Paramters", () => {
6
+ it("/redis", (done) => {
7
+ chaiObj.request("http://localhost:8081").get("/redis").end((err, res) => {
8
+ expect(res.text).to.be.equal("get from redis: " + "Hello World");
9
+ done();
10
+ });
11
+ });
12
+ it("/orm/first", (done) => {
13
+ chaiObj.request("http://localhost:8081").get("/orm/first").end((err, res) => {
14
+ expect(res.text).to.be.equal("first test, to getUsers");
15
+ done();
16
+ });
17
+ });
18
+ it("/orm/one", (done) => {
19
+ chaiObj.request("http://localhost:8081").get("/orm/one?id=1").end((err, res) => {
20
+ expect(res.text).to.be.equal("find one test, to getUser");
21
+ done();
22
+ });
23
+ });
24
+ it("/orm/delete", (done) => {
25
+ chaiObj.request("http://localhost:8081").get("/orm/delete?id=0").end((err, res) => {
26
+ expect(res.text).to.be.equal("remove user, results: remove rows: 0");
27
+ done();
28
+ });
29
+ });
30
+ it("/orm/count", (done) => {
31
+ chaiObj.request("http://localhost:8081").get("/orm/count").end((err, res) => {
32
+ expect(JSON.parse(res.text)).to.have.property("count").which.is.a("number").above(0);
33
+ done();
34
+ });
35
+ });
36
+ it("/orm/new", (done) => {
37
+ chaiObj.request("http://localhost:8081").get("/orm/new").end((err, res) => {
38
+ expect(JSON.parse(res.text)).to.have.property("newId").which.is.a("number").above(0);
39
+ done();
40
+ });
41
+ });
42
+ it("/orm/page/calculate", (done) => {
43
+ chaiObj.request("http://localhost:8081").get("/orm/page/calculate").end((err, res) => {
44
+ expect(JSON.parse(res.text)).to.have.property("totalPage").which.is.a("number").equal(38);
45
+ done();
46
+ });
47
+ });
48
+ it("/orm/pages", (done) => {
49
+ chaiObj.request("http://localhost:8081").get("/orm/pages/1").end((err, res) => {
50
+ expect(JSON.parse(res.text)).is.a("array").lengthOf(3);
51
+ done();
52
+ });
53
+ });
54
+ it("/orm/edit", (done) => {
55
+ chaiObj.request("http://localhost:8081").post("/orm/edit")
56
+ .type("form")
57
+ .send({ id: 1, name: "new name" })
58
+ .end((err, res) => {
59
+ expect(JSON.parse(res.text)).to.have.property("effectRows").which.to.be.oneOf([0, 1]);
60
+ done();
61
+ });
62
+ });
63
+ });
64
+
65
+ export { };
@@ -0,0 +1,50 @@
1
+ import MutilUsers from "../app/src/entities/mutil-users.class";
2
+ import UserDto from "../app/src/entities/user-dto.class";
3
+ const chaiObj = require('chai');
4
+ chaiObj.use(require("chai-http"));
5
+ const expect = chaiObj.expect;
6
+
7
+ describe("Test Request Paramters", () => {
8
+ it("/request/res", (done) => {
9
+ chaiObj.request("http://localhost:8081").get("/request/res").end((err, res) => {
10
+ expect(res.text).to.be.equal("test res");
11
+ done();
12
+ });
13
+ });
14
+ it("/request/query", (done) => {
15
+ chaiObj.request("http://localhost:8081").get("/request/query?id=100").end((err, res) => {
16
+ expect(res.text).to.be.equal(JSON.stringify(
17
+ new MutilUsers("group", [new UserDto(1, "name"), new UserDto(2, "name")]
18
+ )));
19
+ done();
20
+ });
21
+ });
22
+ it("/request/body", (done) => {
23
+ const sendUser = new UserDto(100, "name100");
24
+ chaiObj.request("http://localhost:8081").post("/request/body")
25
+ .send(sendUser)
26
+ .end((err, res) => {
27
+ expect(res.text).to.be.equal(JSON.stringify(new MutilUsers("group", [sendUser])));
28
+ done();
29
+ });
30
+ });
31
+ it("/request/form", (done) => {
32
+ const sendName = "name200";
33
+ chaiObj.request("http://localhost:8081").post("/request/form")
34
+ .type("form")
35
+ .send({ name: sendName })
36
+ .end((err, res) => {
37
+ expect(res.text).to.be.equal("Got name: " + sendName);
38
+ done();
39
+ });
40
+ });
41
+ it("/request/param", (done) => {
42
+ const sendId = 200;
43
+ chaiObj.request("http://localhost:8081").get("/request/param/" + sendId).end((err, res) => {
44
+ expect(res.text).to.be.equal("test param: " + sendId);
45
+ done();
46
+ });
47
+ });
48
+ });
49
+
50
+ export {};
@@ -0,0 +1,51 @@
1
+ import * as jwttoken from "jsonwebtoken";
2
+ import * as fs from "fs";
3
+ const chaiObj = require('chai');
4
+
5
+ chaiObj.use(require("chai-http"));
6
+
7
+
8
+ describe("Test Sencond Page", () => {
9
+ it("/second/setCookie", (done) => {
10
+ chaiObj.request("http://localhost:8081").get("/second/setCookie").end((err, res) => {
11
+ chaiObj.assert.equal(res.headers["set-cookie"].includes("name=zzz; Path=/"), true);
12
+ done();
13
+ });
14
+ });
15
+ it("/second/getCookie", (done) => {
16
+ const cookieSet = "mycookie"
17
+ chaiObj.request("http://localhost:8081").get("/second/getCookie")
18
+ .set("Cookie", "name=" + cookieSet).end((err, res) => {
19
+ chaiObj.assert.equal(res.text, "getCookie: " + cookieSet);
20
+ done();
21
+ });
22
+ });
23
+ it("/second/testSession", (done) => {
24
+ chaiObj.request("http://localhost:8081").get("/second/testSession").end((err, res) => {
25
+ chaiObj.assert.equal(res.text, "testForSession: 1");
26
+ done();
27
+ });
28
+ });
29
+ it("/upload", (done) => {
30
+ const uploadfile = "./app/static/k.jpg";
31
+ chaiObj.request("http://localhost:8081").post("/upload")
32
+ .set('Content-Type', 'multipart/form-data')
33
+ .attach("file", uploadfile)
34
+ .end((err, res) => {
35
+ chaiObj.assert.equal(res.text, "upload success");
36
+ done();
37
+ });
38
+ });
39
+ it("/form", (done) => {
40
+ const token = jwttoken.sign({ foo: 'bar' }, 'shhhhhhared-secret');
41
+ const fileContents = fs.readFileSync("./app/src/views/upload.html", "utf8");
42
+ chaiObj.request("http://localhost:8081").post("/form")
43
+ .set({ "Authorization": `Bearer ${token}` })
44
+ .end((err, res) => {
45
+ chaiObj.assert.equal(res.text, fileContents);
46
+ done();
47
+ });
48
+ });
49
+ });
50
+
51
+ export { };