egg 4.0.9 → 4.1.0-beta.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 (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 +13 -0
  23. package/dist/config/config.default.js +257 -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} +40 -48
  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 +21 -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} +45 -94
  79. package/dist/lib/types.js +14 -0
  80. package/dist/lib/utils.d.ts +5 -0
  81. package/dist/lib/utils.js +14 -0
  82. package/dist/urllib.d.ts +2 -0
  83. package/dist/urllib.js +3 -0
  84. package/package.json +76 -97
  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/favicon.png +0 -0
  113. package/dist/commonjs/config/plugin.d.ts +0 -122
  114. package/dist/commonjs/config/plugin.js +0 -124
  115. package/dist/commonjs/index.d.ts +0 -69
  116. package/dist/commonjs/index.js +0 -83
  117. package/dist/commonjs/lib/agent.d.ts +0 -19
  118. package/dist/commonjs/lib/agent.js +0 -58
  119. package/dist/commonjs/lib/application.d.ts +0 -56
  120. package/dist/commonjs/lib/application.js +0 -266
  121. package/dist/commonjs/lib/core/base_context_class.d.ts +0 -17
  122. package/dist/commonjs/lib/core/base_context_class.js +0 -21
  123. package/dist/commonjs/lib/core/base_context_logger.d.ts +0 -36
  124. package/dist/commonjs/lib/core/base_context_logger.js +0 -64
  125. package/dist/commonjs/lib/core/base_hook_class.d.ts +0 -11
  126. package/dist/commonjs/lib/core/base_hook_class.js +0 -29
  127. package/dist/commonjs/lib/core/context_httpclient.d.ts +0 -16
  128. package/dist/commonjs/lib/core/context_httpclient.js +0 -30
  129. package/dist/commonjs/lib/core/httpclient.d.ts +0 -14
  130. package/dist/commonjs/lib/core/httpclient.js +0 -42
  131. package/dist/commonjs/lib/core/logger.d.ts +0 -3
  132. package/dist/commonjs/lib/core/logger.js +0 -40
  133. package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +0 -50
  134. package/dist/commonjs/lib/core/messenger/IMessenger.js +0 -3
  135. package/dist/commonjs/lib/core/messenger/base.d.ts +0 -8
  136. package/dist/commonjs/lib/core/messenger/base.js +0 -31
  137. package/dist/commonjs/lib/core/messenger/index.d.ts +0 -7
  138. package/dist/commonjs/lib/core/messenger/index.js +0 -15
  139. package/dist/commonjs/lib/core/messenger/ipc.d.ts +0 -58
  140. package/dist/commonjs/lib/core/messenger/ipc.js +0 -135
  141. package/dist/commonjs/lib/core/messenger/local.d.ts +0 -60
  142. package/dist/commonjs/lib/core/messenger/local.js +0 -132
  143. package/dist/commonjs/lib/core/utils.d.ts +0 -2
  144. package/dist/commonjs/lib/core/utils.js +0 -77
  145. package/dist/commonjs/lib/egg.d.ts +0 -305
  146. package/dist/commonjs/lib/egg.js +0 -628
  147. package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +0 -5
  148. package/dist/commonjs/lib/error/CookieLimitExceedError.js +0 -16
  149. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
  150. package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +0 -16
  151. package/dist/commonjs/lib/error/index.d.ts +0 -2
  152. package/dist/commonjs/lib/error/index.js +0 -19
  153. package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +0 -12
  154. package/dist/commonjs/lib/loader/AgentWorkerLoader.js +0 -24
  155. package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +0 -17
  156. package/dist/commonjs/lib/loader/AppWorkerLoader.js +0 -43
  157. package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +0 -4
  158. package/dist/commonjs/lib/loader/EggApplicationLoader.js +0 -8
  159. package/dist/commonjs/lib/loader/index.d.ts +0 -3
  160. package/dist/commonjs/lib/loader/index.js +0 -22
  161. package/dist/commonjs/lib/start.d.ts +0 -24
  162. package/dist/commonjs/lib/start.js +0 -49
  163. package/dist/commonjs/lib/types.d.ts +0 -257
  164. package/dist/commonjs/lib/types.js +0 -16
  165. package/dist/commonjs/lib/utils.d.ts +0 -2
  166. package/dist/commonjs/lib/utils.js +0 -21
  167. package/dist/commonjs/package.json +0 -3
  168. package/dist/commonjs/urllib.d.ts +0 -1
  169. package/dist/commonjs/urllib.js +0 -18
  170. package/dist/esm/agent.d.ts +0 -4
  171. package/dist/esm/agent.js +0 -7
  172. package/dist/esm/app/extend/context.d.ts +0 -204
  173. package/dist/esm/app/extend/context.js +0 -259
  174. package/dist/esm/app/extend/helper.d.ts +0 -37
  175. package/dist/esm/app/extend/helper.js +0 -43
  176. package/dist/esm/app/extend/request.d.ts +0 -141
  177. package/dist/esm/app/extend/request.js +0 -264
  178. package/dist/esm/app/extend/response.d.ts +0 -31
  179. package/dist/esm/app/extend/response.js +0 -34
  180. package/dist/esm/app/middleware/body_parser.d.ts +0 -2
  181. package/dist/esm/app/middleware/body_parser.js +0 -3
  182. package/dist/esm/app/middleware/meta.d.ts +0 -10
  183. package/dist/esm/app/middleware/meta.js +0 -20
  184. package/dist/esm/app/middleware/notfound.d.ts +0 -7
  185. package/dist/esm/app/middleware/notfound.js +0 -29
  186. package/dist/esm/app/middleware/override_method.d.ts +0 -2
  187. package/dist/esm/app/middleware/override_method.js +0 -3
  188. package/dist/esm/app/middleware/site_file.d.ts +0 -9
  189. package/dist/esm/app/middleware/site_file.js +0 -53
  190. package/dist/esm/config/config.default.d.ts +0 -9
  191. package/dist/esm/config/config.default.js +0 -374
  192. package/dist/esm/config/config.local.d.ts +0 -8
  193. package/dist/esm/config/config.local.js +0 -10
  194. package/dist/esm/config/config.unittest.d.ts +0 -7
  195. package/dist/esm/config/config.unittest.js +0 -9
  196. package/dist/esm/config/favicon.png +0 -0
  197. package/dist/esm/config/plugin.d.ts +0 -122
  198. package/dist/esm/config/plugin.js +0 -122
  199. package/dist/esm/index.d.ts +0 -69
  200. package/dist/esm/index.js +0 -73
  201. package/dist/esm/lib/agent.d.ts +0 -19
  202. package/dist/esm/lib/agent.js +0 -54
  203. package/dist/esm/lib/application.d.ts +0 -56
  204. package/dist/esm/lib/application.js +0 -259
  205. package/dist/esm/lib/core/base_context_class.d.ts +0 -17
  206. package/dist/esm/lib/core/base_context_class.js +0 -17
  207. package/dist/esm/lib/core/base_context_logger.d.ts +0 -36
  208. package/dist/esm/lib/core/base_context_logger.js +0 -60
  209. package/dist/esm/lib/core/base_hook_class.d.ts +0 -11
  210. package/dist/esm/lib/core/base_hook_class.js +0 -22
  211. package/dist/esm/lib/core/context_httpclient.d.ts +0 -16
  212. package/dist/esm/lib/core/context_httpclient.js +0 -26
  213. package/dist/esm/lib/core/httpclient.d.ts +0 -14
  214. package/dist/esm/lib/core/httpclient.js +0 -38
  215. package/dist/esm/lib/core/logger.d.ts +0 -3
  216. package/dist/esm/lib/core/logger.js +0 -37
  217. package/dist/esm/lib/core/messenger/IMessenger.d.ts +0 -50
  218. package/dist/esm/lib/core/messenger/IMessenger.js +0 -2
  219. package/dist/esm/lib/core/messenger/base.d.ts +0 -8
  220. package/dist/esm/lib/core/messenger/base.js +0 -27
  221. package/dist/esm/lib/core/messenger/index.d.ts +0 -7
  222. package/dist/esm/lib/core/messenger/index.js +0 -12
  223. package/dist/esm/lib/core/messenger/ipc.d.ts +0 -58
  224. package/dist/esm/lib/core/messenger/ipc.js +0 -128
  225. package/dist/esm/lib/core/messenger/local.d.ts +0 -60
  226. package/dist/esm/lib/core/messenger/local.js +0 -128
  227. package/dist/esm/lib/core/utils.d.ts +0 -2
  228. package/dist/esm/lib/core/utils.js +0 -70
  229. package/dist/esm/lib/egg.d.ts +0 -305
  230. package/dist/esm/lib/egg.js +0 -586
  231. package/dist/esm/lib/error/CookieLimitExceedError.d.ts +0 -5
  232. package/dist/esm/lib/error/CookieLimitExceedError.js +0 -12
  233. package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
  234. package/dist/esm/lib/error/MessageUnhandledRejectionError.js +0 -12
  235. package/dist/esm/lib/error/index.d.ts +0 -2
  236. package/dist/esm/lib/error/index.js +0 -3
  237. package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +0 -12
  238. package/dist/esm/lib/loader/AgentWorkerLoader.js +0 -20
  239. package/dist/esm/lib/loader/AppWorkerLoader.d.ts +0 -17
  240. package/dist/esm/lib/loader/AppWorkerLoader.js +0 -39
  241. package/dist/esm/lib/loader/EggApplicationLoader.d.ts +0 -4
  242. package/dist/esm/lib/loader/EggApplicationLoader.js +0 -4
  243. package/dist/esm/lib/loader/index.d.ts +0 -3
  244. package/dist/esm/lib/loader/index.js +0 -4
  245. package/dist/esm/lib/start.d.ts +0 -24
  246. package/dist/esm/lib/start.js +0 -43
  247. package/dist/esm/lib/types.d.ts +0 -257
  248. package/dist/esm/lib/types.js +0 -14
  249. package/dist/esm/lib/utils.d.ts +0 -2
  250. package/dist/esm/lib/utils.js +0 -14
  251. package/dist/esm/package.json +0 -3
  252. package/dist/esm/urllib.d.ts +0 -1
  253. package/dist/esm/urllib.js +0 -2
  254. package/dist/package.json +0 -4
  255. package/src/agent.ts +0 -7
  256. package/src/app/extend/context.ts +0 -332
  257. package/src/app/extend/request.ts +0 -300
  258. package/src/app/middleware/body_parser.ts +0 -3
  259. package/src/app/middleware/meta.ts +0 -27
  260. package/src/app/middleware/notfound.ts +0 -41
  261. package/src/app/middleware/override_method.ts +0 -3
  262. package/src/app/middleware/site_file.ts +0 -68
  263. package/src/config/config.default.ts +0 -404
  264. package/src/config/config.local.ts +0 -11
  265. package/src/config/config.unittest.ts +0 -10
  266. package/src/config/favicon.png +0 -0
  267. package/src/index.ts +0 -120
  268. package/src/lib/agent.ts +0 -66
  269. package/src/lib/application.ts +0 -296
  270. package/src/lib/core/base_context_class.ts +0 -24
  271. package/src/lib/core/base_context_logger.ts +0 -67
  272. package/src/lib/core/base_hook_class.ts +0 -30
  273. package/src/lib/core/context_httpclient.ts +0 -33
  274. package/src/lib/core/httpclient.ts +0 -64
  275. package/src/lib/core/logger.ts +0 -42
  276. package/src/lib/core/messenger/base.ts +0 -30
  277. package/src/lib/core/messenger/index.ts +0 -16
  278. package/src/lib/core/messenger/ipc.ts +0 -146
  279. package/src/lib/core/messenger/local.ts +0 -147
  280. package/src/lib/core/utils.ts +0 -77
  281. package/src/lib/egg.ts +0 -705
  282. package/src/lib/error/CookieLimitExceedError.ts +0 -12
  283. package/src/lib/error/MessageUnhandledRejectionError.ts +0 -12
  284. package/src/lib/error/index.ts +0 -2
  285. package/src/lib/loader/AgentWorkerLoader.ts +0 -21
  286. package/src/lib/loader/AppWorkerLoader.ts +0 -42
  287. package/src/lib/loader/EggApplicationLoader.ts +0 -5
  288. package/src/lib/loader/index.ts +0 -3
  289. package/src/lib/start.ts +0 -66
  290. package/src/lib/utils.ts +0 -15
  291. package/src/urllib.ts +0 -1
@@ -0,0 +1,145 @@
1
+ import { Application } from "../../lib/application.js";
2
+ import Response$1 from "./response.js";
3
+ import Context$1 from "./context.js";
4
+ import { Request as Request$1 } from "@eggjs/core";
5
+
6
+ //#region src/app/extend/request.d.ts
7
+ declare class Request extends Request$1 {
8
+ app: Application;
9
+ ctx: Context$1;
10
+ response: Response$1;
11
+ /**
12
+ * Request body, parsed from koa-bodyparser or @eggjs/multipart
13
+ */
14
+ body: any;
15
+ /**
16
+ * Parse the "Host" header field host
17
+ * and support X-Forwarded-Host when a
18
+ * proxy is enabled.
19
+ * @member {String} Request#host
20
+ * @example
21
+ * ip + port
22
+ * ```js
23
+ * this.request.host
24
+ * => '127.0.0.1:7001'
25
+ * ```
26
+ * or domain
27
+ * ```js
28
+ * this.request.host
29
+ * => 'demo.eggjs.org'
30
+ * ```
31
+ */
32
+ get host(): string;
33
+ /**
34
+ * @member {String} Request#protocol
35
+ * @example
36
+ * ```js
37
+ * this.request.protocol
38
+ * => 'https'
39
+ * ```
40
+ */
41
+ get protocol(): string;
42
+ /**
43
+ * Get all pass through ip addresses from the request.
44
+ * Enable only on `app.config.proxy = true`
45
+ *
46
+ * @member {Array} Request#ips
47
+ * @example
48
+ * ```js
49
+ * this.request.ips
50
+ * => ['100.23.1.2', '201.10.10.2']
51
+ * ```
52
+ */
53
+ get ips(): string[];
54
+ /**
55
+ * Get the request remote IPv4 address
56
+ * @member {String} Request#ip
57
+ * @return {String} IPv4 address
58
+ * @example
59
+ * ```js
60
+ * this.request.ip
61
+ * => '127.0.0.1'
62
+ * => '111.10.2.1'
63
+ * ```
64
+ */
65
+ get ip(): string;
66
+ /**
67
+ * Set the request remote IPv4 address
68
+ * @member {String} Request#ip
69
+ * @param {String} ip - IPv4 address
70
+ * @example
71
+ * ```js
72
+ * this.request.ip
73
+ * => '127.0.0.1'
74
+ * => '111.10.2.1'
75
+ * ```
76
+ */
77
+ set ip(ip: string);
78
+ /**
79
+ * detect if response should be json
80
+ * 1. url path ends with `.json`
81
+ * 2. response type is set to json
82
+ * 3. detect by request accept header
83
+ *
84
+ * @member {Boolean} Request#acceptJSON
85
+ * @since 1.0.0
86
+ */
87
+ get acceptJSON(): boolean;
88
+ _customQuery(cacheName: symbol, filter: (value: string | string[]) => string | string[]): Record<string, string | string[]>;
89
+ /**
90
+ * get params pass by querystring, all values are of string type.
91
+ * @member {Object} Request#query
92
+ * @example
93
+ * ```js
94
+ * GET http://127.0.0.1:7001?name=Foo&age=20&age=21
95
+ * this.query
96
+ * => { 'name': 'Foo', 'age': '20' }
97
+ *
98
+ * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
99
+ * this.query
100
+ * =>
101
+ * {
102
+ * "a": "b",
103
+ * "o[foo]": "bar",
104
+ * "b[]": "1",
105
+ * "e": "val"
106
+ * }
107
+ * ```
108
+ */
109
+ get query(): Record<string, string>;
110
+ /**
111
+ * get params pass by querystring, all value are Array type. {@link Request#query}
112
+ * @member {Array} Request#queries
113
+ * @example
114
+ * ```js
115
+ * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
116
+ * this.queries
117
+ * =>
118
+ * {
119
+ * "a": ["b", "c"],
120
+ * "o[foo]": ["bar"],
121
+ * "b[]": ["1", "2"],
122
+ * "e": ["val"]
123
+ * }
124
+ * ```
125
+ */
126
+ get queries(): Record<string, string[]>;
127
+ /**
128
+ * Set query-string as an object.
129
+ *
130
+ * @function Request#query
131
+ * @param {Object} obj set querystring and query object for request.
132
+ */
133
+ set query(obj: Record<string, string>);
134
+ }
135
+ declare module '@eggjs/core' {
136
+ interface Request {
137
+ body: any;
138
+ get acceptJSON(): boolean;
139
+ get query(): Record<string, string>;
140
+ set query(obj: Record<string, string>);
141
+ get queries(): Record<string, string[]>;
142
+ }
143
+ }
144
+ //#endregion
145
+ export { Request as default };
@@ -0,0 +1,226 @@
1
+ import "./response.js";
2
+ import { Request as Request$1 } from "@eggjs/core";
3
+ import querystring from "node:querystring";
4
+
5
+ //#region src/app/extend/request.ts
6
+ const QUERY_CACHE = Symbol("request query cache");
7
+ const QUERIES_CACHE = Symbol("request queries cache");
8
+ const PROTOCOL = Symbol("request protocol");
9
+ const HOST = Symbol("request host");
10
+ const IPS = Symbol("request ips");
11
+ const RE_ARRAY_KEY = /[^[\]]+\[\]$/;
12
+ var Request = class extends Request$1 {
13
+ /**
14
+ * Parse the "Host" header field host
15
+ * and support X-Forwarded-Host when a
16
+ * proxy is enabled.
17
+ * @member {String} Request#host
18
+ * @example
19
+ * ip + port
20
+ * ```js
21
+ * this.request.host
22
+ * => '127.0.0.1:7001'
23
+ * ```
24
+ * or domain
25
+ * ```js
26
+ * this.request.host
27
+ * => 'demo.eggjs.org'
28
+ * ```
29
+ */
30
+ get host() {
31
+ let host = this[HOST];
32
+ if (host) return host;
33
+ if (this.app.config.proxy) host = getFromHeaders(this, this.app.config.hostHeaders);
34
+ host = host || this.get("host") || "";
35
+ this[HOST] = host = host.split(",")[0].trim();
36
+ return host;
37
+ }
38
+ /**
39
+ * @member {String} Request#protocol
40
+ * @example
41
+ * ```js
42
+ * this.request.protocol
43
+ * => 'https'
44
+ * ```
45
+ */
46
+ get protocol() {
47
+ let protocol = this[PROTOCOL];
48
+ if (protocol) return protocol;
49
+ if (this.socket?.encrypted) {
50
+ this[PROTOCOL] = protocol = "https";
51
+ return protocol;
52
+ }
53
+ if (this.app.config.proxy) {
54
+ const proto = getFromHeaders(this, this.app.config.protocolHeaders);
55
+ if (proto) {
56
+ this[PROTOCOL] = protocol = proto.split(/\s*,\s*/)[0];
57
+ return protocol;
58
+ }
59
+ }
60
+ this[PROTOCOL] = protocol = this.app.config.protocol || "http";
61
+ return protocol;
62
+ }
63
+ /**
64
+ * Get all pass through ip addresses from the request.
65
+ * Enable only on `app.config.proxy = true`
66
+ *
67
+ * @member {Array} Request#ips
68
+ * @example
69
+ * ```js
70
+ * this.request.ips
71
+ * => ['100.23.1.2', '201.10.10.2']
72
+ * ```
73
+ */
74
+ get ips() {
75
+ let ips = this[IPS];
76
+ if (ips) return ips;
77
+ if (!this.app.config.proxy) {
78
+ this[IPS] = ips = [];
79
+ return ips;
80
+ }
81
+ const val = getFromHeaders(this, this.app.config.ipHeaders);
82
+ this[IPS] = ips = val ? val.split(/\s*,\s*/) : [];
83
+ let maxIpsCount = this.app.config.maxIpsCount;
84
+ if (!maxIpsCount && this.app.config.maxProxyCount) maxIpsCount = this.app.config.maxProxyCount + 1;
85
+ if (maxIpsCount > 0) this[IPS] = ips = ips.slice(-maxIpsCount);
86
+ return ips;
87
+ }
88
+ /**
89
+ * Get the request remote IPv4 address
90
+ * @member {String} Request#ip
91
+ * @return {String} IPv4 address
92
+ * @example
93
+ * ```js
94
+ * this.request.ip
95
+ * => '127.0.0.1'
96
+ * => '111.10.2.1'
97
+ * ```
98
+ */
99
+ get ip() {
100
+ if (this._ip) return this._ip;
101
+ const ip = this.ips[0] ?? this.socket.remoteAddress;
102
+ this._ip = ip && ip.startsWith("::ffff:") ? ip.substring(7) : ip;
103
+ return this._ip;
104
+ }
105
+ /**
106
+ * Set the request remote IPv4 address
107
+ * @member {String} Request#ip
108
+ * @param {String} ip - IPv4 address
109
+ * @example
110
+ * ```js
111
+ * this.request.ip
112
+ * => '127.0.0.1'
113
+ * => '111.10.2.1'
114
+ * ```
115
+ */
116
+ set ip(ip) {
117
+ this._ip = ip;
118
+ }
119
+ /**
120
+ * detect if response should be json
121
+ * 1. url path ends with `.json`
122
+ * 2. response type is set to json
123
+ * 3. detect by request accept header
124
+ *
125
+ * @member {Boolean} Request#acceptJSON
126
+ * @since 1.0.0
127
+ */
128
+ get acceptJSON() {
129
+ if (this.path.endsWith(".json")) return true;
130
+ if (this.response.type && this.response.type.indexOf("json") >= 0) return true;
131
+ if (this.accepts("html", "text", "json") === "json") return true;
132
+ return false;
133
+ }
134
+ _customQuery(cacheName, filter) {
135
+ const str = this.querystring || "";
136
+ let c = this[cacheName];
137
+ if (!c) c = this[cacheName] = {};
138
+ let cacheQuery = c[str];
139
+ if (!cacheQuery) {
140
+ cacheQuery = c[str] = {};
141
+ const isQueries = cacheName === QUERIES_CACHE;
142
+ const query = str ? querystring.parse(str) : {};
143
+ for (const key in query) {
144
+ if (!key) continue;
145
+ const value = filter(query[key]);
146
+ cacheQuery[key] = value;
147
+ if (isQueries && RE_ARRAY_KEY.test(key)) {
148
+ const subKey = key.substring(0, key.length - 2);
149
+ if (!cacheQuery[subKey]) cacheQuery[subKey] = value;
150
+ }
151
+ }
152
+ }
153
+ return cacheQuery;
154
+ }
155
+ /**
156
+ * get params pass by querystring, all values are of string type.
157
+ * @member {Object} Request#query
158
+ * @example
159
+ * ```js
160
+ * GET http://127.0.0.1:7001?name=Foo&age=20&age=21
161
+ * this.query
162
+ * => { 'name': 'Foo', 'age': '20' }
163
+ *
164
+ * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
165
+ * this.query
166
+ * =>
167
+ * {
168
+ * "a": "b",
169
+ * "o[foo]": "bar",
170
+ * "b[]": "1",
171
+ * "e": "val"
172
+ * }
173
+ * ```
174
+ */
175
+ get query() {
176
+ return this._customQuery(QUERY_CACHE, firstValue);
177
+ }
178
+ /**
179
+ * get params pass by querystring, all value are Array type. {@link Request#query}
180
+ * @member {Array} Request#queries
181
+ * @example
182
+ * ```js
183
+ * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
184
+ * this.queries
185
+ * =>
186
+ * {
187
+ * "a": ["b", "c"],
188
+ * "o[foo]": ["bar"],
189
+ * "b[]": ["1", "2"],
190
+ * "e": ["val"]
191
+ * }
192
+ * ```
193
+ */
194
+ get queries() {
195
+ return this._customQuery(QUERIES_CACHE, arrayValue);
196
+ }
197
+ /**
198
+ * Set query-string as an object.
199
+ *
200
+ * @function Request#query
201
+ * @param {Object} obj set querystring and query object for request.
202
+ */
203
+ set query(obj) {
204
+ this.querystring = querystring.stringify(obj);
205
+ }
206
+ };
207
+ function firstValue(value) {
208
+ if (Array.isArray(value)) value = value[0];
209
+ return value;
210
+ }
211
+ function arrayValue(value) {
212
+ if (!Array.isArray(value)) value = [value];
213
+ return value;
214
+ }
215
+ function getFromHeaders(request, names) {
216
+ if (!names) return "";
217
+ const fields = names.split(/\s*,\s*/);
218
+ for (const name of fields) {
219
+ const value = request.get(name);
220
+ if (value) return value;
221
+ }
222
+ return "";
223
+ }
224
+
225
+ //#endregion
226
+ export { Request as default };
@@ -1,8 +1,7 @@
1
- import { Response as KoaResponse } from '@eggjs/core';
1
+ import { Response as Response$1 } from "@eggjs/core";
2
2
 
3
- const REAL_STATUS = Symbol('response realStatus');
4
-
5
- export default class Response extends KoaResponse {
3
+ //#region src/app/extend/response.d.ts
4
+ declare class Response extends Response$1 {
6
5
  /**
7
6
  * Get or set a real status code.
8
7
  *
@@ -13,13 +12,7 @@ export default class Response extends KoaResponse {
13
12
  * @member {Number} Response#realStatus
14
13
  * @return {Number} The status code to be set.
15
14
  */
16
- get realStatus(): number {
17
- if (this[REAL_STATUS]) {
18
- return this[REAL_STATUS] as number;
19
- }
20
- return this.status;
21
- }
22
-
15
+ get realStatus(): number;
23
16
  /**
24
17
  * Set a real status code.
25
18
  *
@@ -30,15 +23,13 @@ export default class Response extends KoaResponse {
30
23
  * @member {Number} Response#realStatus
31
24
  * @param {Number} status The status code to be set.
32
25
  */
33
- set realStatus(status: number) {
34
- this[REAL_STATUS] = status;
35
- }
26
+ set realStatus(status: number);
36
27
  }
37
-
38
28
  declare module '@eggjs/core' {
39
- // add Response overrides types
40
29
  interface Response {
41
30
  get realStatus(): number;
42
31
  set realStatus(status: number);
43
32
  }
44
33
  }
34
+ //#endregion
35
+ export { Response as default };
@@ -0,0 +1,36 @@
1
+ import { Response as Response$1 } from "@eggjs/core";
2
+
3
+ //#region src/app/extend/response.ts
4
+ const REAL_STATUS = Symbol("response realStatus");
5
+ var Response = class extends Response$1 {
6
+ /**
7
+ * Get or set a real status code.
8
+ *
9
+ * e.g.: Using 302 status redirect to the global error page
10
+ * instead of show current 500 status page.
11
+ * And access log should save 500 not 302,
12
+ * then the `realStatus` can help us find out the real status code.
13
+ * @member {Number} Response#realStatus
14
+ * @return {Number} The status code to be set.
15
+ */
16
+ get realStatus() {
17
+ if (this[REAL_STATUS]) return this[REAL_STATUS];
18
+ return this.status;
19
+ }
20
+ /**
21
+ * Set a real status code.
22
+ *
23
+ * e.g.: Using 302 status redirect to the global error page
24
+ * instead of show current 500 status page.
25
+ * And access log should save 500 not 302,
26
+ * then the `realStatus` can help us find out the real status code.
27
+ * @member {Number} Response#realStatus
28
+ * @param {Number} status The status code to be set.
29
+ */
30
+ set realStatus(status) {
31
+ this[REAL_STATUS] = status;
32
+ }
33
+ };
34
+
35
+ //#endregion
36
+ export { Response as default };
@@ -0,0 +1,2 @@
1
+ import bodyparser from "koa-bodyparser";
2
+ export { bodyparser as default };
@@ -0,0 +1,7 @@
1
+ import bodyparser from "koa-bodyparser";
2
+
3
+ //#region src/app/middleware/body_parser.ts
4
+ var body_parser_default = bodyparser;
5
+
6
+ //#endregion
7
+ export { body_parser_default as default };
@@ -0,0 +1,11 @@
1
+ import Context from "../extend/context.js";
2
+ import { Next } from "../../lib/egg.js";
3
+
4
+ //#region src/app/middleware/meta.d.ts
5
+ interface MetaMiddlewareOptions {
6
+ enable: boolean;
7
+ logging: boolean;
8
+ }
9
+ declare const _default: (options: MetaMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
10
+ //#endregion
11
+ export { MetaMiddlewareOptions, _default as default };
@@ -0,0 +1,14 @@
1
+ import { performance } from "node:perf_hooks";
2
+
3
+ //#region src/app/middleware/meta.ts
4
+ var meta_default = (options) => {
5
+ return async function meta(ctx, next) {
6
+ if (options.logging) ctx.coreLogger.info("[meta] request started, host: %s, user-agent: %s", ctx.host, ctx.header["user-agent"]);
7
+ await next();
8
+ if (ctx.performanceStarttime) ctx.set("x-readtime", Math.floor((performance.now() - ctx.performanceStarttime) * 1e3) / 1e3);
9
+ else ctx.set("x-readtime", Date.now() - ctx.starttime);
10
+ };
11
+ };
12
+
13
+ //#endregion
14
+ export { meta_default as default };
@@ -0,0 +1,11 @@
1
+ import Context from "../extend/context.js";
2
+ import { Next } from "../../lib/egg.js";
3
+
4
+ //#region src/app/middleware/notfound.d.ts
5
+ interface NotFoundMiddlewareOptions {
6
+ enable: boolean;
7
+ pageUrl: string;
8
+ }
9
+ declare const _default: (options: NotFoundMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
10
+ //#endregion
11
+ export { NotFoundMiddlewareOptions, _default as default };
@@ -0,0 +1,26 @@
1
+ //#region src/app/middleware/notfound.ts
2
+ var notfound_default = (options) => {
3
+ return async function notfound(ctx, next) {
4
+ await next();
5
+ if (ctx.status !== 404 || ctx.body) return;
6
+ ctx.status = 404;
7
+ if (ctx.acceptJSON) {
8
+ ctx.body = { message: "Not Found" };
9
+ return;
10
+ }
11
+ const notFoundHtml = "<h1>404 Not Found</h1>";
12
+ if (options.pageUrl && ctx.path === options.pageUrl) {
13
+ ctx.body = `${notFoundHtml}<p><pre><code>config.notfound.pageUrl(${options.pageUrl})</code></pre> is unimplemented</p>`;
14
+ return;
15
+ }
16
+ if (options.pageUrl) {
17
+ ctx.realStatus = 404;
18
+ ctx.redirect(options.pageUrl);
19
+ return;
20
+ }
21
+ ctx.body = notFoundHtml;
22
+ };
23
+ };
24
+
25
+ //#endregion
26
+ export { notfound_default as default };
@@ -0,0 +1,2 @@
1
+ import override from "koa-override";
2
+ export { override as default };
@@ -0,0 +1,7 @@
1
+ import override from "koa-override";
2
+
3
+ //#region src/app/middleware/override_method.ts
4
+ var override_method_default = override;
5
+
6
+ //#endregion
7
+ export { override_method_default as default };
@@ -0,0 +1,13 @@
1
+ import Context from "../extend/context.js";
2
+ import { Next } from "../../lib/egg.js";
3
+
4
+ //#region src/app/middleware/site_file.d.ts
5
+ type SiteFileContentFun = (ctx: Context) => Promise<Buffer | string>;
6
+ interface SiteFileMiddlewareOptions {
7
+ enable: boolean;
8
+ cacheControl: string;
9
+ [key: string]: string | Buffer | boolean | SiteFileContentFun | URL;
10
+ }
11
+ declare const _default: (options: SiteFileMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
12
+ //#endregion
13
+ export { SiteFileContentFun, SiteFileMiddlewareOptions, _default as default };
@@ -0,0 +1,38 @@
1
+ import path from "node:path";
2
+ import { fileURLToPath } from "node:url";
3
+ import { readFile } from "node:fs/promises";
4
+
5
+ //#region src/app/middleware/site_file.ts
6
+ const BUFFER_CACHE = Symbol("siteFile URL buffer cache");
7
+ var site_file_default = (options) => {
8
+ return async function siteFile(ctx, next) {
9
+ if (ctx.method !== "HEAD" && ctx.method !== "GET") return next();
10
+ if (ctx.path[0] !== "/") return next();
11
+ let content = options[ctx.path];
12
+ if (!content) return next();
13
+ if (typeof content === "function") content = await content(ctx);
14
+ if (typeof content === "string") return ctx.redirect(content);
15
+ if (content instanceof URL) {
16
+ if (content.protocol !== "file:") return ctx.redirect(content.href);
17
+ let buffer = Reflect.get(content, BUFFER_CACHE);
18
+ if (!buffer) {
19
+ buffer = await readFile(fileURLToPath(content));
20
+ Reflect.set(content, BUFFER_CACHE, buffer);
21
+ }
22
+ ctx.set("cache-control", options.cacheControl);
23
+ ctx.body = content;
24
+ ctx.type = path.extname(ctx.path);
25
+ return;
26
+ }
27
+ if (Buffer.isBuffer(content)) {
28
+ ctx.set("cache-control", options.cacheControl);
29
+ ctx.body = content;
30
+ ctx.type = path.extname(ctx.path);
31
+ return;
32
+ }
33
+ return next();
34
+ };
35
+ };
36
+
37
+ //#endregion
38
+ export { site_file_default as default };
@@ -0,0 +1,13 @@
1
+ import { EggAppConfig as EggAppConfig$1, PowerPartial } from "../lib/types.js";
2
+ import { EggAppInfo } from "@eggjs/core";
3
+
4
+ //#region src/config/config.default.d.ts
5
+
6
+ /**
7
+ * The configuration of egg application, can be access by `app.config`
8
+ * @class Config
9
+ * @since 1.0.0
10
+ */
11
+ declare const _default: (appInfo: EggAppInfo) => PowerPartial<EggAppConfig$1>;
12
+ //#endregion
13
+ export { _default as default };