egg 4.0.10 → 4.1.0-beta.11

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 (291) hide show
  1. package/README.md +4 -22
  2. package/dist/agent.d.ts +8 -0
  3. package/dist/agent.js +11 -0
  4. package/dist/app/extend/context.d.ts +207 -0
  5. package/dist/app/extend/context.js +244 -0
  6. package/{src/app/extend/helper.ts → dist/app/extend/helper.d.ts} +8 -10
  7. package/dist/app/extend/helper.js +47 -0
  8. package/dist/app/extend/request.d.ts +145 -0
  9. package/dist/app/extend/request.js +226 -0
  10. package/{src/app/extend/response.ts → dist/app/extend/response.d.ts} +7 -16
  11. package/dist/app/extend/response.js +36 -0
  12. package/dist/app/middleware/body_parser.d.ts +2 -0
  13. package/dist/app/middleware/body_parser.js +7 -0
  14. package/dist/app/middleware/meta.d.ts +11 -0
  15. package/dist/app/middleware/meta.js +14 -0
  16. package/dist/app/middleware/notfound.d.ts +11 -0
  17. package/dist/app/middleware/notfound.js +26 -0
  18. package/dist/app/middleware/override_method.d.ts +2 -0
  19. package/dist/app/middleware/override_method.js +7 -0
  20. package/dist/app/middleware/site_file.d.ts +13 -0
  21. package/dist/app/middleware/site_file.js +38 -0
  22. package/dist/config/config.default.d.ts +12 -0
  23. package/dist/config/config.default.js +260 -0
  24. package/dist/config/config.local.d.ts +10 -0
  25. package/dist/config/config.local.js +7 -0
  26. package/dist/config/config.unittest.d.ts +9 -0
  27. package/dist/config/config.unittest.js +10 -0
  28. package/{src/config/plugin.ts → dist/config/plugin.d.ts} +41 -49
  29. package/dist/config/plugin.js +54 -0
  30. package/dist/index.d.ts +19 -0
  31. package/dist/index.js +21 -0
  32. package/dist/lib/agent.d.ts +22 -0
  33. package/dist/lib/agent.js +56 -0
  34. package/dist/lib/application.d.ts +71 -0
  35. package/dist/lib/application.js +209 -0
  36. package/dist/lib/core/base_context_class.d.ts +23 -0
  37. package/dist/lib/core/base_context_class.js +19 -0
  38. package/dist/lib/core/base_context_logger.d.ts +40 -0
  39. package/dist/lib/core/base_context_logger.js +58 -0
  40. package/dist/lib/core/base_hook_class.d.ts +18 -0
  41. package/dist/lib/core/base_hook_class.js +26 -0
  42. package/dist/lib/core/context_httpclient.d.ts +22 -0
  43. package/dist/lib/core/context_httpclient.js +29 -0
  44. package/dist/lib/core/httpclient.d.ts +17 -0
  45. package/dist/lib/core/httpclient.js +36 -0
  46. package/dist/lib/core/logger.d.ts +7 -0
  47. package/dist/lib/core/logger.js +31 -0
  48. package/{src/lib/core/messenger/IMessenger.ts → dist/lib/core/messenger/IMessenger.d.ts} +6 -10
  49. package/dist/lib/core/messenger/IMessenger.js +1 -0
  50. package/dist/lib/core/messenger/base.d.ts +12 -0
  51. package/dist/lib/core/messenger/base.js +29 -0
  52. package/dist/lib/core/messenger/index.d.ts +11 -0
  53. package/dist/lib/core/messenger/index.js +13 -0
  54. package/dist/lib/core/messenger/ipc.d.ts +63 -0
  55. package/dist/lib/core/messenger/ipc.js +122 -0
  56. package/dist/lib/core/messenger/local.d.ts +65 -0
  57. package/dist/lib/core/messenger/local.js +126 -0
  58. package/dist/lib/core/utils.d.ts +5 -0
  59. package/dist/lib/core/utils.js +48 -0
  60. package/dist/lib/egg.d.ts +306 -0
  61. package/dist/lib/egg.js +512 -0
  62. package/dist/lib/error/CookieLimitExceedError.d.ts +8 -0
  63. package/dist/lib/error/CookieLimitExceedError.js +15 -0
  64. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +8 -0
  65. package/dist/lib/error/MessageUnhandledRejectionError.js +15 -0
  66. package/dist/lib/error/index.d.ts +3 -0
  67. package/dist/lib/error/index.js +4 -0
  68. package/dist/lib/loader/AgentWorkerLoader.d.ts +17 -0
  69. package/dist/lib/loader/AgentWorkerLoader.js +24 -0
  70. package/dist/lib/loader/AppWorkerLoader.d.ts +22 -0
  71. package/dist/lib/loader/AppWorkerLoader.js +37 -0
  72. package/dist/lib/loader/EggApplicationLoader.d.ts +8 -0
  73. package/dist/lib/loader/EggApplicationLoader.js +7 -0
  74. package/dist/lib/loader/index.d.ts +4 -0
  75. package/dist/lib/loader/index.js +5 -0
  76. package/dist/lib/start.d.ts +28 -0
  77. package/dist/lib/start.js +36 -0
  78. package/{src/lib/types.ts → dist/lib/types.d.ts} +73 -94
  79. package/dist/lib/types.js +36 -0
  80. package/dist/lib/utils.d.ts +5 -0
  81. package/dist/lib/utils.js +14 -0
  82. package/dist/urllib.d.ts +1 -0
  83. package/dist/urllib.js +3 -0
  84. package/package.json +81 -99
  85. package/README.zh-CN.md +0 -61
  86. package/dist/commonjs/agent.d.ts +0 -4
  87. package/dist/commonjs/agent.js +0 -10
  88. package/dist/commonjs/app/extend/context.d.ts +0 -204
  89. package/dist/commonjs/app/extend/context.js +0 -262
  90. package/dist/commonjs/app/extend/helper.d.ts +0 -37
  91. package/dist/commonjs/app/extend/helper.js +0 -49
  92. package/dist/commonjs/app/extend/request.d.ts +0 -141
  93. package/dist/commonjs/app/extend/request.js +0 -270
  94. package/dist/commonjs/app/extend/response.d.ts +0 -31
  95. package/dist/commonjs/app/extend/response.js +0 -37
  96. package/dist/commonjs/app/middleware/body_parser.d.ts +0 -2
  97. package/dist/commonjs/app/middleware/body_parser.js +0 -8
  98. package/dist/commonjs/app/middleware/meta.d.ts +0 -10
  99. package/dist/commonjs/app/middleware/meta.js +0 -22
  100. package/dist/commonjs/app/middleware/notfound.d.ts +0 -7
  101. package/dist/commonjs/app/middleware/notfound.js +0 -31
  102. package/dist/commonjs/app/middleware/override_method.d.ts +0 -2
  103. package/dist/commonjs/app/middleware/override_method.js +0 -8
  104. package/dist/commonjs/app/middleware/site_file.d.ts +0 -9
  105. package/dist/commonjs/app/middleware/site_file.js +0 -58
  106. package/dist/commonjs/config/config.default.d.ts +0 -9
  107. package/dist/commonjs/config/config.default.js +0 -379
  108. package/dist/commonjs/config/config.local.d.ts +0 -8
  109. package/dist/commonjs/config/config.local.js +0 -12
  110. package/dist/commonjs/config/config.unittest.d.ts +0 -7
  111. package/dist/commonjs/config/config.unittest.js +0 -11
  112. package/dist/commonjs/config/plugin.d.ts +0 -122
  113. package/dist/commonjs/config/plugin.js +0 -124
  114. package/dist/commonjs/index.d.ts +0 -69
  115. package/dist/commonjs/index.js +0 -83
  116. package/dist/commonjs/lib/agent.d.ts +0 -19
  117. package/dist/commonjs/lib/agent.js +0 -58
  118. package/dist/commonjs/lib/application.d.ts +0 -67
  119. package/dist/commonjs/lib/application.js +0 -266
  120. package/dist/commonjs/lib/core/base_context_class.d.ts +0 -17
  121. package/dist/commonjs/lib/core/base_context_class.js +0 -21
  122. package/dist/commonjs/lib/core/base_context_logger.d.ts +0 -36
  123. package/dist/commonjs/lib/core/base_context_logger.js +0 -64
  124. package/dist/commonjs/lib/core/base_hook_class.d.ts +0 -11
  125. package/dist/commonjs/lib/core/base_hook_class.js +0 -29
  126. package/dist/commonjs/lib/core/context_httpclient.d.ts +0 -16
  127. package/dist/commonjs/lib/core/context_httpclient.js +0 -30
  128. package/dist/commonjs/lib/core/httpclient.d.ts +0 -14
  129. package/dist/commonjs/lib/core/httpclient.js +0 -42
  130. package/dist/commonjs/lib/core/logger.d.ts +0 -3
  131. package/dist/commonjs/lib/core/logger.js +0 -40
  132. package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +0 -50
  133. package/dist/commonjs/lib/core/messenger/IMessenger.js +0 -3
  134. package/dist/commonjs/lib/core/messenger/base.d.ts +0 -8
  135. package/dist/commonjs/lib/core/messenger/base.js +0 -31
  136. package/dist/commonjs/lib/core/messenger/index.d.ts +0 -7
  137. package/dist/commonjs/lib/core/messenger/index.js +0 -15
  138. package/dist/commonjs/lib/core/messenger/ipc.d.ts +0 -58
  139. package/dist/commonjs/lib/core/messenger/ipc.js +0 -135
  140. package/dist/commonjs/lib/core/messenger/local.d.ts +0 -60
  141. package/dist/commonjs/lib/core/messenger/local.js +0 -132
  142. package/dist/commonjs/lib/core/utils.d.ts +0 -2
  143. package/dist/commonjs/lib/core/utils.js +0 -77
  144. package/dist/commonjs/lib/egg.d.ts +0 -305
  145. package/dist/commonjs/lib/egg.js +0 -628
  146. package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +0 -5
  147. package/dist/commonjs/lib/error/CookieLimitExceedError.js +0 -16
  148. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
  149. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +0 -16
  150. package/dist/commonjs/lib/error/index.d.ts +0 -2
  151. package/dist/commonjs/lib/error/index.js +0 -19
  152. package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +0 -12
  153. package/dist/commonjs/lib/loader/AgentWorkerLoader.js +0 -24
  154. package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +0 -17
  155. package/dist/commonjs/lib/loader/AppWorkerLoader.js +0 -43
  156. package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +0 -4
  157. package/dist/commonjs/lib/loader/EggApplicationLoader.js +0 -8
  158. package/dist/commonjs/lib/loader/index.d.ts +0 -3
  159. package/dist/commonjs/lib/loader/index.js +0 -22
  160. package/dist/commonjs/lib/start.d.ts +0 -24
  161. package/dist/commonjs/lib/start.js +0 -49
  162. package/dist/commonjs/lib/types.d.ts +0 -257
  163. package/dist/commonjs/lib/types.js +0 -16
  164. package/dist/commonjs/lib/utils.d.ts +0 -2
  165. package/dist/commonjs/lib/utils.js +0 -21
  166. package/dist/commonjs/package.json +0 -3
  167. package/dist/commonjs/urllib.d.ts +0 -1
  168. package/dist/commonjs/urllib.js +0 -18
  169. package/dist/esm/agent.d.ts +0 -4
  170. package/dist/esm/agent.js +0 -7
  171. package/dist/esm/app/extend/context.d.ts +0 -204
  172. package/dist/esm/app/extend/context.js +0 -259
  173. package/dist/esm/app/extend/helper.d.ts +0 -37
  174. package/dist/esm/app/extend/helper.js +0 -43
  175. package/dist/esm/app/extend/request.d.ts +0 -141
  176. package/dist/esm/app/extend/request.js +0 -264
  177. package/dist/esm/app/extend/response.d.ts +0 -31
  178. package/dist/esm/app/extend/response.js +0 -34
  179. package/dist/esm/app/middleware/body_parser.d.ts +0 -2
  180. package/dist/esm/app/middleware/body_parser.js +0 -3
  181. package/dist/esm/app/middleware/meta.d.ts +0 -10
  182. package/dist/esm/app/middleware/meta.js +0 -20
  183. package/dist/esm/app/middleware/notfound.d.ts +0 -7
  184. package/dist/esm/app/middleware/notfound.js +0 -29
  185. package/dist/esm/app/middleware/override_method.d.ts +0 -2
  186. package/dist/esm/app/middleware/override_method.js +0 -3
  187. package/dist/esm/app/middleware/site_file.d.ts +0 -9
  188. package/dist/esm/app/middleware/site_file.js +0 -53
  189. package/dist/esm/config/config.default.d.ts +0 -9
  190. package/dist/esm/config/config.default.js +0 -374
  191. package/dist/esm/config/config.local.d.ts +0 -8
  192. package/dist/esm/config/config.local.js +0 -10
  193. package/dist/esm/config/config.unittest.d.ts +0 -7
  194. package/dist/esm/config/config.unittest.js +0 -9
  195. package/dist/esm/config/favicon.png +0 -0
  196. package/dist/esm/config/plugin.d.ts +0 -122
  197. package/dist/esm/config/plugin.js +0 -122
  198. package/dist/esm/index.d.ts +0 -69
  199. package/dist/esm/index.js +0 -73
  200. package/dist/esm/lib/agent.d.ts +0 -19
  201. package/dist/esm/lib/agent.js +0 -54
  202. package/dist/esm/lib/application.d.ts +0 -67
  203. package/dist/esm/lib/application.js +0 -259
  204. package/dist/esm/lib/core/base_context_class.d.ts +0 -17
  205. package/dist/esm/lib/core/base_context_class.js +0 -17
  206. package/dist/esm/lib/core/base_context_logger.d.ts +0 -36
  207. package/dist/esm/lib/core/base_context_logger.js +0 -60
  208. package/dist/esm/lib/core/base_hook_class.d.ts +0 -11
  209. package/dist/esm/lib/core/base_hook_class.js +0 -22
  210. package/dist/esm/lib/core/context_httpclient.d.ts +0 -16
  211. package/dist/esm/lib/core/context_httpclient.js +0 -26
  212. package/dist/esm/lib/core/httpclient.d.ts +0 -14
  213. package/dist/esm/lib/core/httpclient.js +0 -38
  214. package/dist/esm/lib/core/logger.d.ts +0 -3
  215. package/dist/esm/lib/core/logger.js +0 -37
  216. package/dist/esm/lib/core/messenger/IMessenger.d.ts +0 -50
  217. package/dist/esm/lib/core/messenger/IMessenger.js +0 -2
  218. package/dist/esm/lib/core/messenger/base.d.ts +0 -8
  219. package/dist/esm/lib/core/messenger/base.js +0 -27
  220. package/dist/esm/lib/core/messenger/index.d.ts +0 -7
  221. package/dist/esm/lib/core/messenger/index.js +0 -12
  222. package/dist/esm/lib/core/messenger/ipc.d.ts +0 -58
  223. package/dist/esm/lib/core/messenger/ipc.js +0 -128
  224. package/dist/esm/lib/core/messenger/local.d.ts +0 -60
  225. package/dist/esm/lib/core/messenger/local.js +0 -128
  226. package/dist/esm/lib/core/utils.d.ts +0 -2
  227. package/dist/esm/lib/core/utils.js +0 -70
  228. package/dist/esm/lib/egg.d.ts +0 -305
  229. package/dist/esm/lib/egg.js +0 -586
  230. package/dist/esm/lib/error/CookieLimitExceedError.d.ts +0 -5
  231. package/dist/esm/lib/error/CookieLimitExceedError.js +0 -12
  232. package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
  233. package/dist/esm/lib/error/MessageUnhandledRejectionError.js +0 -12
  234. package/dist/esm/lib/error/index.d.ts +0 -2
  235. package/dist/esm/lib/error/index.js +0 -3
  236. package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +0 -12
  237. package/dist/esm/lib/loader/AgentWorkerLoader.js +0 -20
  238. package/dist/esm/lib/loader/AppWorkerLoader.d.ts +0 -17
  239. package/dist/esm/lib/loader/AppWorkerLoader.js +0 -39
  240. package/dist/esm/lib/loader/EggApplicationLoader.d.ts +0 -4
  241. package/dist/esm/lib/loader/EggApplicationLoader.js +0 -4
  242. package/dist/esm/lib/loader/index.d.ts +0 -3
  243. package/dist/esm/lib/loader/index.js +0 -4
  244. package/dist/esm/lib/start.d.ts +0 -24
  245. package/dist/esm/lib/start.js +0 -43
  246. package/dist/esm/lib/types.d.ts +0 -257
  247. package/dist/esm/lib/types.js +0 -14
  248. package/dist/esm/lib/utils.d.ts +0 -2
  249. package/dist/esm/lib/utils.js +0 -14
  250. package/dist/esm/package.json +0 -3
  251. package/dist/esm/urllib.d.ts +0 -1
  252. package/dist/esm/urllib.js +0 -2
  253. package/dist/package.json +0 -4
  254. package/src/agent.ts +0 -7
  255. package/src/app/extend/context.ts +0 -332
  256. package/src/app/extend/request.ts +0 -300
  257. package/src/app/middleware/body_parser.ts +0 -3
  258. package/src/app/middleware/meta.ts +0 -27
  259. package/src/app/middleware/notfound.ts +0 -41
  260. package/src/app/middleware/override_method.ts +0 -3
  261. package/src/app/middleware/site_file.ts +0 -68
  262. package/src/config/config.default.ts +0 -404
  263. package/src/config/config.local.ts +0 -11
  264. package/src/config/config.unittest.ts +0 -10
  265. package/src/config/favicon.png +0 -0
  266. package/src/index.ts +0 -120
  267. package/src/lib/agent.ts +0 -66
  268. package/src/lib/application.ts +0 -308
  269. package/src/lib/core/base_context_class.ts +0 -24
  270. package/src/lib/core/base_context_logger.ts +0 -67
  271. package/src/lib/core/base_hook_class.ts +0 -30
  272. package/src/lib/core/context_httpclient.ts +0 -33
  273. package/src/lib/core/httpclient.ts +0 -64
  274. package/src/lib/core/logger.ts +0 -42
  275. package/src/lib/core/messenger/base.ts +0 -30
  276. package/src/lib/core/messenger/index.ts +0 -16
  277. package/src/lib/core/messenger/ipc.ts +0 -146
  278. package/src/lib/core/messenger/local.ts +0 -147
  279. package/src/lib/core/utils.ts +0 -77
  280. package/src/lib/egg.ts +0 -705
  281. package/src/lib/error/CookieLimitExceedError.ts +0 -12
  282. package/src/lib/error/MessageUnhandledRejectionError.ts +0 -12
  283. package/src/lib/error/index.ts +0 -2
  284. package/src/lib/loader/AgentWorkerLoader.ts +0 -21
  285. package/src/lib/loader/AppWorkerLoader.ts +0 -42
  286. package/src/lib/loader/EggApplicationLoader.ts +0 -5
  287. package/src/lib/loader/index.ts +0 -3
  288. package/src/lib/start.ts +0 -66
  289. package/src/lib/utils.ts +0 -15
  290. package/src/urllib.ts +0 -1
  291. /package/dist/{commonjs/config → config}/favicon.png +0 -0
package/README.md CHANGED
@@ -1,8 +1,4 @@
1
- English | [简体中文](./README.zh-CN.md)
2
-
3
- <div style="text-align:center">
4
- <img src="site/public/assets/egg-banner.png" />
5
- </div>
1
+ # egg
6
2
 
7
3
  [![NPM version](https://img.shields.io/npm/v/egg.svg?style=flat-square)](https://npmjs.org/package/egg)
8
4
  [![NPM quality](http://npm.packagequality.com/shield/egg.svg?style=flat-square)](http://packagequality.com/#?package=egg)
@@ -10,8 +6,6 @@ English | [简体中文](./README.zh-CN.md)
10
6
  [![Node.js Version](https://img.shields.io/node/v/egg.svg?style=flat)](https://nodejs.org/en/download/)
11
7
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Feggjs%2Fegg.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_shield)
12
8
 
13
- [![Continuous Integration](https://github.com/eggjs/egg/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/egg/actions?query=branch%3Amaster)
14
- [![Test coverage](https://img.shields.io/codecov/c/github/eggjs/egg.svg?style=flat-square)](https://codecov.io/gh/eggjs/egg)
15
9
  [![Known Vulnerabilities](https://snyk.io/test/npm/egg/badge.svg?style=flat-square)](https://snyk.io/test/npm/egg)
16
10
  [![Open Collective backers and sponsors](https://img.shields.io/opencollective/all/eggjs?style=flat-square)](https://opencollective.com/eggjs)
17
11
 
@@ -29,12 +23,12 @@ Follow the commands listed below.
29
23
  ```bash
30
24
  $ mkdir showcase && cd showcase
31
25
  $ npm init egg --type=simple # Optionally pnpm create egg --type=simple
32
- $ npm install
33
- $ npm run dev
26
+ $ pnpm install
27
+ $ pnpm run dev
34
28
  $ open http://localhost:7001
35
29
  ```
36
30
 
37
- > Node.js >= 14.20.0 required.
31
+ > Node.js >= 20.19.0 required, [supports `require(esm)` by default](https://nodejs.org/en/blog/release/v20.19.0).
38
32
 
39
33
  ## Documentations
40
34
 
@@ -43,16 +37,6 @@ $ open http://localhost:7001
43
37
  - [Frameworks](https://github.com/search?q=topic%3Aegg-framework&type=Repositories)
44
38
  - [Examples](https://github.com/eggjs/examples)
45
39
 
46
- ## Contributors
47
-
48
- [![contributors](https://contrib.rocks/image?repo=eggjs/egg&max=240&columns=26)](https://github.com/eggjs/egg/graphs/contributors)
49
-
50
- ## How to Contribute
51
-
52
- Please let us know how can we help. Do check out [issues](https://github.com/eggjs/egg/issues) for bug reports or suggestions first.
53
-
54
- To become a contributor, please follow our [contributing guide](CONTRIBUTING.md).
55
-
56
40
  ## Sponsors and Backers
57
41
 
58
42
  [![sponsors](https://opencollective.com/eggjs/tiers/sponsors.svg?avatarHeight=48)](https://opencollective.com/eggjs#support)
@@ -61,5 +45,3 @@ To become a contributor, please follow our [contributing guide](CONTRIBUTING.md)
61
45
  ## License
62
46
 
63
47
  [MIT](LICENSE)
64
-
65
- [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Feggjs%2Fegg.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_large)
@@ -0,0 +1,8 @@
1
+ import { BaseHookClass } from "./lib/core/base_hook_class.js";
2
+
3
+ //#region src/agent.d.ts
4
+ declare class EggAgentHook extends BaseHookClass {
5
+ configDidLoad(): void;
6
+ }
7
+ //#endregion
8
+ export { EggAgentHook as default };
package/dist/agent.js ADDED
@@ -0,0 +1,11 @@
1
+ import { BaseHookClass } from "./lib/core/base_hook_class.js";
2
+
3
+ //#region src/agent.ts
4
+ var EggAgentHook = class extends BaseHookClass {
5
+ configDidLoad() {
6
+ this.agent._wrapMessenger();
7
+ }
8
+ };
9
+
10
+ //#endregion
11
+ export { EggAgentHook as default };
@@ -0,0 +1,207 @@
1
+ import Helper from "./helper.js";
2
+ import { Application } from "../../lib/application.js";
3
+ import { EggContextHttpClient as HttpClient, HttpClientRequestOptions, HttpClientRequestURL } from "../../lib/core/httpclient.js";
4
+ import Response$1 from "./response.js";
5
+ import Request$1 from "./request.js";
6
+ import { BaseContextClass as BaseContextClass$1 } from "../../lib/core/base_context_class.js";
7
+ import { Context as Context$1, Router } from "@eggjs/core";
8
+ import { EggLogger } from "egg-logger";
9
+ import { Cookies } from "@eggjs/cookies";
10
+
11
+ //#region src/app/extend/context.d.ts
12
+ interface Cookies$1 extends Cookies {
13
+ request: any;
14
+ response: any;
15
+ }
16
+ declare class Context extends Context$1 {
17
+ app: Application;
18
+ request: Request$1;
19
+ response: Response$1;
20
+ service: BaseContextClass$1;
21
+ proxy: any;
22
+ /**
23
+ * Request start time
24
+ * @member {Number} Context#starttime
25
+ */
26
+ starttime: number;
27
+ /**
28
+ * Request start timer using `performance.now()`
29
+ * @member {Number} Context#performanceStarttime
30
+ */
31
+ performanceStarttime: number;
32
+ /**
33
+ * Get the current visitor's cookies.
34
+ */
35
+ get cookies(): Cookies$1;
36
+ /**
37
+ * Get a wrapper httpclient instance contain ctx in the hold request process
38
+ *
39
+ * @return {HttpClient} the wrapper httpclient instance
40
+ */
41
+ get httpclient(): HttpClient;
42
+ /**
43
+ * Alias to {@link Context#httpclient}
44
+ */
45
+ get httpClient(): HttpClient;
46
+ /**
47
+ * Shortcut for httpclient.curl
48
+ *
49
+ * @function Context#curl
50
+ * @param {String|Object} url - request url address.
51
+ * @param {Object} [options] - options for request.
52
+ * @return {Object} see {@link ContextHttpClient#curl}
53
+ */
54
+ curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
55
+ /**
56
+ * Alias to {@link Application#router}
57
+ *
58
+ * @member {Router} Context#router
59
+ * @since 1.0.0
60
+ * @example
61
+ * ```js
62
+ * this.router.pathFor('post', { id: 12 });
63
+ * ```
64
+ */
65
+ get router(): Router;
66
+ /**
67
+ * Set router to Context, only use on EggRouter
68
+ * @param {Router} val router instance
69
+ */
70
+ set router(val: Router);
71
+ /**
72
+ * Get helper instance from {@link Application#Helper}
73
+ *
74
+ * @member {Helper} Context#helper
75
+ * @since 1.0.0
76
+ */
77
+ get helper(): Helper;
78
+ /**
79
+ * Wrap app.loggers with context information,
80
+ * if a custom logger is defined by naming aLogger, then you can `ctx.getLogger('aLogger')`
81
+ *
82
+ * @param {String} name - logger name
83
+ */
84
+ getLogger(name: string): EggLogger;
85
+ /**
86
+ * Logger for Application
87
+ *
88
+ * @member {Logger} Context#logger
89
+ * @since 1.0.0
90
+ * @example
91
+ * ```js
92
+ * this.logger.info('some request data: %j', this.request.body);
93
+ * this.logger.warn('WARNING!!!!');
94
+ * ```
95
+ */
96
+ get logger(): EggLogger;
97
+ /**
98
+ * Logger for frameworks and plugins
99
+ *
100
+ * @member {Logger} Context#coreLogger
101
+ * @since 1.0.0
102
+ */
103
+ get coreLogger(): EggLogger;
104
+ /**
105
+ * locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
106
+ * which will be used as data when view is rendering.
107
+ * The difference between `app.locals` and `ctx.locals` is the context level, `app.locals` is global level, and `ctx.locals` is request level. when you get `ctx.locals`, it will merge `app.locals`.
108
+ *
109
+ * when you set locals, only object is available
110
+ *
111
+ * ```js
112
+ * this.locals = {
113
+ * a: 1
114
+ * };
115
+ * this.locals = {
116
+ * b: 1
117
+ * };
118
+ * this.locals.c = 1;
119
+ * console.log(this.locals);
120
+ * {
121
+ * a: 1,
122
+ * b: 1,
123
+ * c: 1,
124
+ * };
125
+ * ```
126
+ *
127
+ * `ctx.locals` has cache, it only merges `app.locals` once in one request.
128
+ *
129
+ * @member {Object} Context#locals
130
+ */
131
+ get locals(): Record<string, any>;
132
+ set locals(val: Record<string, any>);
133
+ /**
134
+ * alias to {@link Context#locals}, compatible with koa that use this variable
135
+ * @member {Object} state
136
+ * @see Context#locals
137
+ */
138
+ get state(): Record<string, any>;
139
+ set state(val: Record<string, any>);
140
+ /**
141
+ * Run async function in the background
142
+ * @param {Function} scope - the first args is ctx
143
+ * ```js
144
+ * this.body = 'hi';
145
+ *
146
+ * this.runInBackground(async ctx => {
147
+ * await ctx.mysql.query(sql);
148
+ * await ctx.curl(url);
149
+ * });
150
+ * ```
151
+ */
152
+ runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void;
153
+ _runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string): Promise<void>;
154
+ /**
155
+ * @member {Boolean} Context#acceptJSON
156
+ * @see Request#acceptJSON
157
+ * @since 1.0.0
158
+ */
159
+ get acceptJSON(): boolean;
160
+ get query(): Record<string, string>;
161
+ /**
162
+ * @member {Array} Context#queries
163
+ * @see Request#queries
164
+ * @since 1.0.0
165
+ */
166
+ get queries(): Record<string, string[]>;
167
+ /**
168
+ * @member {string} Context#ip
169
+ * @see Request#ip
170
+ * @since 1.0.0
171
+ */
172
+ get ip(): string;
173
+ set ip(val: string);
174
+ /**
175
+ * @member {Number} Context#realStatus
176
+ * @see Response#realStatus
177
+ * @since 1.0.0
178
+ */
179
+ get realStatus(): number;
180
+ set realStatus(val: number);
181
+ }
182
+ declare module '@eggjs/core' {
183
+ interface Context {
184
+ proxy: any;
185
+ performanceStarttime: number;
186
+ starttime: number;
187
+ runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void;
188
+ _runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string): void;
189
+ get acceptJSON(): boolean;
190
+ get query(): Record<string, string>;
191
+ get queries(): Record<string, string[]>;
192
+ curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
193
+ get router(): Router;
194
+ set router(val: Router);
195
+ get helper(): Helper;
196
+ get httpclient(): HttpClient;
197
+ get httpClient(): HttpClient;
198
+ getLogger(name: string): EggLogger;
199
+ get logger(): EggLogger;
200
+ get coreLogger(): EggLogger;
201
+ get locals(): Record<string, any>;
202
+ get realStatus(): number;
203
+ set realStatus(val: number);
204
+ }
205
+ }
206
+ //#endregion
207
+ export { Context as default };
@@ -0,0 +1,244 @@
1
+ import { Context as Context$1, Router, utils } from "@eggjs/core";
2
+ import { assign } from "utility";
3
+ import { diff, now } from "performance-ms";
4
+
5
+ //#region src/app/extend/context.ts
6
+ const HELPER = Symbol("ctx helper");
7
+ const LOCALS = Symbol("ctx locals");
8
+ const LOCALS_LIST = Symbol("ctx localsList");
9
+ const COOKIES = Symbol("ctx cookies");
10
+ const CONTEXT_HTTPCLIENT = Symbol("ctx httpclient");
11
+ const CONTEXT_ROUTER = Symbol("ctx router");
12
+ var Context = class extends Context$1 {
13
+ /**
14
+ * Request start time
15
+ * @member {Number} Context#starttime
16
+ */
17
+ starttime;
18
+ /**
19
+ * Request start timer using `performance.now()`
20
+ * @member {Number} Context#performanceStarttime
21
+ */
22
+ performanceStarttime;
23
+ /**
24
+ * Get the current visitor's cookies.
25
+ */
26
+ get cookies() {
27
+ let cookies = this[COOKIES];
28
+ if (!cookies) this[COOKIES] = cookies = new this.app.ContextCookies(this, this.app.keys, this.app.config.cookies);
29
+ return cookies;
30
+ }
31
+ /**
32
+ * Get a wrapper httpclient instance contain ctx in the hold request process
33
+ *
34
+ * @return {HttpClient} the wrapper httpclient instance
35
+ */
36
+ get httpclient() {
37
+ if (!this[CONTEXT_HTTPCLIENT]) this[CONTEXT_HTTPCLIENT] = new this.app.ContextHttpClient(this);
38
+ return this[CONTEXT_HTTPCLIENT];
39
+ }
40
+ /**
41
+ * Alias to {@link Context#httpclient}
42
+ */
43
+ get httpClient() {
44
+ return this.httpclient;
45
+ }
46
+ /**
47
+ * Shortcut for httpclient.curl
48
+ *
49
+ * @function Context#curl
50
+ * @param {String|Object} url - request url address.
51
+ * @param {Object} [options] - options for request.
52
+ * @return {Object} see {@link ContextHttpClient#curl}
53
+ */
54
+ async curl(url, options) {
55
+ return await this.httpclient.curl(url, options);
56
+ }
57
+ /**
58
+ * Alias to {@link Application#router}
59
+ *
60
+ * @member {Router} Context#router
61
+ * @since 1.0.0
62
+ * @example
63
+ * ```js
64
+ * this.router.pathFor('post', { id: 12 });
65
+ * ```
66
+ */
67
+ get router() {
68
+ if (this[CONTEXT_ROUTER]) return this[CONTEXT_ROUTER];
69
+ return this.app.router;
70
+ }
71
+ /**
72
+ * Set router to Context, only use on EggRouter
73
+ * @param {Router} val router instance
74
+ */
75
+ set router(val) {
76
+ this[CONTEXT_ROUTER] = val;
77
+ }
78
+ /**
79
+ * Get helper instance from {@link Application#Helper}
80
+ *
81
+ * @member {Helper} Context#helper
82
+ * @since 1.0.0
83
+ */
84
+ get helper() {
85
+ if (!this[HELPER]) this[HELPER] = new this.app.Helper(this);
86
+ return this[HELPER];
87
+ }
88
+ /**
89
+ * Wrap app.loggers with context information,
90
+ * if a custom logger is defined by naming aLogger, then you can `ctx.getLogger('aLogger')`
91
+ *
92
+ * @param {String} name - logger name
93
+ */
94
+ getLogger(name) {
95
+ return this.app.getLogger(name);
96
+ }
97
+ /**
98
+ * Logger for Application
99
+ *
100
+ * @member {Logger} Context#logger
101
+ * @since 1.0.0
102
+ * @example
103
+ * ```js
104
+ * this.logger.info('some request data: %j', this.request.body);
105
+ * this.logger.warn('WARNING!!!!');
106
+ * ```
107
+ */
108
+ get logger() {
109
+ return this.getLogger("logger");
110
+ }
111
+ /**
112
+ * Logger for frameworks and plugins
113
+ *
114
+ * @member {Logger} Context#coreLogger
115
+ * @since 1.0.0
116
+ */
117
+ get coreLogger() {
118
+ return this.getLogger("coreLogger");
119
+ }
120
+ /**
121
+ * locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
122
+ * which will be used as data when view is rendering.
123
+ * The difference between `app.locals` and `ctx.locals` is the context level, `app.locals` is global level, and `ctx.locals` is request level. when you get `ctx.locals`, it will merge `app.locals`.
124
+ *
125
+ * when you set locals, only object is available
126
+ *
127
+ * ```js
128
+ * this.locals = {
129
+ * a: 1
130
+ * };
131
+ * this.locals = {
132
+ * b: 1
133
+ * };
134
+ * this.locals.c = 1;
135
+ * console.log(this.locals);
136
+ * {
137
+ * a: 1,
138
+ * b: 1,
139
+ * c: 1,
140
+ * };
141
+ * ```
142
+ *
143
+ * `ctx.locals` has cache, it only merges `app.locals` once in one request.
144
+ *
145
+ * @member {Object} Context#locals
146
+ */
147
+ get locals() {
148
+ if (!this[LOCALS]) this[LOCALS] = assign({}, this.app.locals);
149
+ if (Array.isArray(this[LOCALS_LIST]) && this[LOCALS_LIST].length > 0) {
150
+ assign(this[LOCALS], this[LOCALS_LIST]);
151
+ this[LOCALS_LIST] = null;
152
+ }
153
+ return this[LOCALS];
154
+ }
155
+ set locals(val) {
156
+ const localsList = this[LOCALS_LIST] ?? [];
157
+ localsList.push(val);
158
+ this[LOCALS_LIST] = localsList;
159
+ }
160
+ /**
161
+ * alias to {@link Context#locals}, compatible with koa that use this variable
162
+ * @member {Object} state
163
+ * @see Context#locals
164
+ */
165
+ get state() {
166
+ return this.locals;
167
+ }
168
+ set state(val) {
169
+ this.locals = val;
170
+ }
171
+ /**
172
+ * Run async function in the background
173
+ * @param {Function} scope - the first args is ctx
174
+ * ```js
175
+ * this.body = 'hi';
176
+ *
177
+ * this.runInBackground(async ctx => {
178
+ * await ctx.mysql.query(sql);
179
+ * await ctx.curl(url);
180
+ * });
181
+ * ```
182
+ */
183
+ runInBackground(scope, taskName) {
184
+ if (!taskName) taskName = Reflect.get(scope, "_name") || scope.name || utils.getCalleeFromStack(true);
185
+ setImmediate(() => {
186
+ this._runInBackground(scope, taskName);
187
+ });
188
+ }
189
+ async _runInBackground(scope, taskName) {
190
+ const startTime = now();
191
+ try {
192
+ await scope(this);
193
+ this.coreLogger.info("[egg:background] task:%s success (%dms)", taskName, diff(startTime));
194
+ } catch (err) {
195
+ this.coreLogger.info("[egg:background] task:%s fail (%dms)", taskName, diff(startTime));
196
+ err.runInBackground = true;
197
+ this.app.emit("error", err, this);
198
+ }
199
+ }
200
+ /**
201
+ * @member {Boolean} Context#acceptJSON
202
+ * @see Request#acceptJSON
203
+ * @since 1.0.0
204
+ */
205
+ get acceptJSON() {
206
+ return this.request.acceptJSON;
207
+ }
208
+ get query() {
209
+ return this.request.query;
210
+ }
211
+ /**
212
+ * @member {Array} Context#queries
213
+ * @see Request#queries
214
+ * @since 1.0.0
215
+ */
216
+ get queries() {
217
+ return this.request.queries;
218
+ }
219
+ /**
220
+ * @member {string} Context#ip
221
+ * @see Request#ip
222
+ * @since 1.0.0
223
+ */
224
+ get ip() {
225
+ return this.request.ip;
226
+ }
227
+ set ip(val) {
228
+ this.request.ip = val;
229
+ }
230
+ /**
231
+ * @member {Number} Context#realStatus
232
+ * @see Response#realStatus
233
+ * @since 1.0.0
234
+ */
235
+ get realStatus() {
236
+ return this.response.realStatus;
237
+ }
238
+ set realStatus(val) {
239
+ this.response.realStatus = val;
240
+ }
241
+ };
242
+
243
+ //#endregion
244
+ export { Context as default };
@@ -1,12 +1,13 @@
1
- import url from 'node:url';
2
- import { BaseContextClass } from '../../lib/core/base_context_class.js';
1
+ import { BaseContextClass } from "../../lib/core/base_context_class.js";
2
+
3
+ //#region src/app/extend/helper.d.ts
3
4
 
4
5
  /**
5
6
  * The Helper class which can be used as utility function.
6
7
  * We support developers to extend Helper through ${baseDir}/app/extend/helper.js ,
7
8
  * then you can use all method on `ctx.helper` that is a instance of Helper.
8
9
  */
9
- export default class Helper extends BaseContextClass {
10
+ declare class Helper extends BaseContextClass {
10
11
  /**
11
12
  * Generate URL path(without host) for route. Takes the route name and a map of named params.
12
13
  * @function Helper#pathFor
@@ -21,10 +22,7 @@ export default class Helper extends BaseContextClass {
21
22
  * ```
22
23
  * @return {String} url path(without host)
23
24
  */
24
- pathFor(name: string, params: Record<string, any>): string {
25
- return this.app.router.url(name, params);
26
- }
27
-
25
+ pathFor(name: string, params: Record<string, any>): string;
28
26
  /**
29
27
  * Generate full URL(with host) for route. Takes the route name and a map of named params.
30
28
  * @function Helper#urlFor
@@ -38,7 +36,7 @@ export default class Helper extends BaseContextClass {
38
36
  * ```
39
37
  * @return {String} full url(with host)
40
38
  */
41
- urlFor(name: string, params: Record<string, any>): string {
42
- return this.ctx.protocol + '://' + this.ctx.host + url.resolve('/', this.pathFor(name, params));
43
- }
39
+ urlFor(name: string, params: Record<string, any>): string;
44
40
  }
41
+ //#endregion
42
+ export { Helper as default };
@@ -0,0 +1,47 @@
1
+ import { BaseContextClass } from "../../lib/core/base_context_class.js";
2
+ import url from "node:url";
3
+
4
+ //#region src/app/extend/helper.ts
5
+ /**
6
+ * The Helper class which can be used as utility function.
7
+ * We support developers to extend Helper through ${baseDir}/app/extend/helper.js ,
8
+ * then you can use all method on `ctx.helper` that is a instance of Helper.
9
+ */
10
+ var Helper = class extends BaseContextClass {
11
+ /**
12
+ * Generate URL path(without host) for route. Takes the route name and a map of named params.
13
+ * @function Helper#pathFor
14
+ * @param {String} name - Router Name
15
+ * @param {Object} params - Other params
16
+ *
17
+ * @example
18
+ * ```js
19
+ * app.get('home', '/index.htm', 'home.index');
20
+ * ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
21
+ * => /index.htm?by=recent&limit=20
22
+ * ```
23
+ * @return {String} url path(without host)
24
+ */
25
+ pathFor(name, params) {
26
+ return this.app.router.url(name, params);
27
+ }
28
+ /**
29
+ * Generate full URL(with host) for route. Takes the route name and a map of named params.
30
+ * @function Helper#urlFor
31
+ * @param {String} name - Router name
32
+ * @param {Object} params - Other params
33
+ * @example
34
+ * ```js
35
+ * app.get('home', '/index.htm', 'home.index');
36
+ * ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
37
+ * => http://127.0.0.1:7001/index.htm?by=recent&limit=20
38
+ * ```
39
+ * @return {String} full url(with host)
40
+ */
41
+ urlFor(name, params) {
42
+ return this.ctx.protocol + "://" + this.ctx.host + url.resolve("/", this.pathFor(name, params));
43
+ }
44
+ };
45
+
46
+ //#endregion
47
+ export { Helper as default };