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.
- package/README.md +4 -22
- package/dist/agent.d.ts +8 -0
- package/dist/agent.js +11 -0
- package/dist/app/extend/context.d.ts +207 -0
- package/dist/app/extend/context.js +244 -0
- package/{src/app/extend/helper.ts → dist/app/extend/helper.d.ts} +8 -10
- package/dist/app/extend/helper.js +47 -0
- package/dist/app/extend/request.d.ts +145 -0
- package/dist/app/extend/request.js +226 -0
- package/{src/app/extend/response.ts → dist/app/extend/response.d.ts} +7 -16
- package/dist/app/extend/response.js +36 -0
- package/dist/app/middleware/body_parser.d.ts +2 -0
- package/dist/app/middleware/body_parser.js +7 -0
- package/dist/app/middleware/meta.d.ts +11 -0
- package/dist/app/middleware/meta.js +14 -0
- package/dist/app/middleware/notfound.d.ts +11 -0
- package/dist/app/middleware/notfound.js +26 -0
- package/dist/app/middleware/override_method.d.ts +2 -0
- package/dist/app/middleware/override_method.js +7 -0
- package/dist/app/middleware/site_file.d.ts +13 -0
- package/dist/app/middleware/site_file.js +38 -0
- package/dist/config/config.default.d.ts +13 -0
- package/dist/config/config.default.js +257 -0
- package/dist/config/config.local.d.ts +10 -0
- package/dist/config/config.local.js +7 -0
- package/dist/config/config.unittest.d.ts +9 -0
- package/dist/config/config.unittest.js +10 -0
- package/{src/config/plugin.ts → dist/config/plugin.d.ts} +40 -48
- package/dist/config/plugin.js +54 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +21 -0
- package/dist/lib/agent.d.ts +22 -0
- package/dist/lib/agent.js +56 -0
- package/dist/lib/application.d.ts +71 -0
- package/dist/lib/application.js +209 -0
- package/dist/lib/core/base_context_class.d.ts +23 -0
- package/dist/lib/core/base_context_class.js +19 -0
- package/dist/lib/core/base_context_logger.d.ts +40 -0
- package/dist/lib/core/base_context_logger.js +58 -0
- package/dist/lib/core/base_hook_class.d.ts +18 -0
- package/dist/lib/core/base_hook_class.js +26 -0
- package/dist/lib/core/context_httpclient.d.ts +21 -0
- package/dist/lib/core/context_httpclient.js +29 -0
- package/dist/lib/core/httpclient.d.ts +17 -0
- package/dist/lib/core/httpclient.js +36 -0
- package/dist/lib/core/logger.d.ts +7 -0
- package/dist/lib/core/logger.js +31 -0
- package/{src/lib/core/messenger/IMessenger.ts → dist/lib/core/messenger/IMessenger.d.ts} +6 -10
- package/dist/lib/core/messenger/IMessenger.js +1 -0
- package/dist/lib/core/messenger/base.d.ts +12 -0
- package/dist/lib/core/messenger/base.js +29 -0
- package/dist/lib/core/messenger/index.d.ts +11 -0
- package/dist/lib/core/messenger/index.js +13 -0
- package/dist/lib/core/messenger/ipc.d.ts +63 -0
- package/dist/lib/core/messenger/ipc.js +122 -0
- package/dist/lib/core/messenger/local.d.ts +65 -0
- package/dist/lib/core/messenger/local.js +126 -0
- package/dist/lib/core/utils.d.ts +5 -0
- package/dist/lib/core/utils.js +48 -0
- package/dist/lib/egg.d.ts +306 -0
- package/dist/lib/egg.js +512 -0
- package/dist/lib/error/CookieLimitExceedError.d.ts +8 -0
- package/dist/lib/error/CookieLimitExceedError.js +15 -0
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +8 -0
- package/dist/lib/error/MessageUnhandledRejectionError.js +15 -0
- package/dist/lib/error/index.d.ts +3 -0
- package/dist/lib/error/index.js +4 -0
- package/dist/lib/loader/AgentWorkerLoader.d.ts +17 -0
- package/dist/lib/loader/AgentWorkerLoader.js +24 -0
- package/dist/lib/loader/AppWorkerLoader.d.ts +22 -0
- package/dist/lib/loader/AppWorkerLoader.js +37 -0
- package/dist/lib/loader/EggApplicationLoader.d.ts +8 -0
- package/dist/lib/loader/EggApplicationLoader.js +7 -0
- package/dist/lib/loader/index.d.ts +4 -0
- package/dist/lib/loader/index.js +5 -0
- package/dist/lib/start.d.ts +28 -0
- package/dist/lib/start.js +36 -0
- package/{src/lib/types.ts → dist/lib/types.d.ts} +45 -94
- package/dist/lib/types.js +14 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +14 -0
- package/dist/urllib.d.ts +2 -0
- package/dist/urllib.js +3 -0
- package/package.json +76 -97
- package/README.zh-CN.md +0 -61
- package/dist/commonjs/agent.d.ts +0 -4
- package/dist/commonjs/agent.js +0 -10
- package/dist/commonjs/app/extend/context.d.ts +0 -204
- package/dist/commonjs/app/extend/context.js +0 -262
- package/dist/commonjs/app/extend/helper.d.ts +0 -37
- package/dist/commonjs/app/extend/helper.js +0 -49
- package/dist/commonjs/app/extend/request.d.ts +0 -141
- package/dist/commonjs/app/extend/request.js +0 -270
- package/dist/commonjs/app/extend/response.d.ts +0 -31
- package/dist/commonjs/app/extend/response.js +0 -37
- package/dist/commonjs/app/middleware/body_parser.d.ts +0 -2
- package/dist/commonjs/app/middleware/body_parser.js +0 -8
- package/dist/commonjs/app/middleware/meta.d.ts +0 -10
- package/dist/commonjs/app/middleware/meta.js +0 -22
- package/dist/commonjs/app/middleware/notfound.d.ts +0 -7
- package/dist/commonjs/app/middleware/notfound.js +0 -31
- package/dist/commonjs/app/middleware/override_method.d.ts +0 -2
- package/dist/commonjs/app/middleware/override_method.js +0 -8
- package/dist/commonjs/app/middleware/site_file.d.ts +0 -9
- package/dist/commonjs/app/middleware/site_file.js +0 -58
- package/dist/commonjs/config/config.default.d.ts +0 -9
- package/dist/commonjs/config/config.default.js +0 -379
- package/dist/commonjs/config/config.local.d.ts +0 -8
- package/dist/commonjs/config/config.local.js +0 -12
- package/dist/commonjs/config/config.unittest.d.ts +0 -7
- package/dist/commonjs/config/config.unittest.js +0 -11
- package/dist/commonjs/config/favicon.png +0 -0
- package/dist/commonjs/config/plugin.d.ts +0 -122
- package/dist/commonjs/config/plugin.js +0 -124
- package/dist/commonjs/index.d.ts +0 -69
- package/dist/commonjs/index.js +0 -83
- package/dist/commonjs/lib/agent.d.ts +0 -19
- package/dist/commonjs/lib/agent.js +0 -58
- package/dist/commonjs/lib/application.d.ts +0 -56
- package/dist/commonjs/lib/application.js +0 -266
- package/dist/commonjs/lib/core/base_context_class.d.ts +0 -17
- package/dist/commonjs/lib/core/base_context_class.js +0 -21
- package/dist/commonjs/lib/core/base_context_logger.d.ts +0 -36
- package/dist/commonjs/lib/core/base_context_logger.js +0 -64
- package/dist/commonjs/lib/core/base_hook_class.d.ts +0 -11
- package/dist/commonjs/lib/core/base_hook_class.js +0 -29
- package/dist/commonjs/lib/core/context_httpclient.d.ts +0 -16
- package/dist/commonjs/lib/core/context_httpclient.js +0 -30
- package/dist/commonjs/lib/core/httpclient.d.ts +0 -14
- package/dist/commonjs/lib/core/httpclient.js +0 -42
- package/dist/commonjs/lib/core/logger.d.ts +0 -3
- package/dist/commonjs/lib/core/logger.js +0 -40
- package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +0 -50
- package/dist/commonjs/lib/core/messenger/IMessenger.js +0 -3
- package/dist/commonjs/lib/core/messenger/base.d.ts +0 -8
- package/dist/commonjs/lib/core/messenger/base.js +0 -31
- package/dist/commonjs/lib/core/messenger/index.d.ts +0 -7
- package/dist/commonjs/lib/core/messenger/index.js +0 -15
- package/dist/commonjs/lib/core/messenger/ipc.d.ts +0 -58
- package/dist/commonjs/lib/core/messenger/ipc.js +0 -135
- package/dist/commonjs/lib/core/messenger/local.d.ts +0 -60
- package/dist/commonjs/lib/core/messenger/local.js +0 -132
- package/dist/commonjs/lib/core/utils.d.ts +0 -2
- package/dist/commonjs/lib/core/utils.js +0 -77
- package/dist/commonjs/lib/egg.d.ts +0 -305
- package/dist/commonjs/lib/egg.js +0 -628
- package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +0 -5
- package/dist/commonjs/lib/error/CookieLimitExceedError.js +0 -16
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +0 -16
- package/dist/commonjs/lib/error/index.d.ts +0 -2
- package/dist/commonjs/lib/error/index.js +0 -19
- package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +0 -12
- package/dist/commonjs/lib/loader/AgentWorkerLoader.js +0 -24
- package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +0 -17
- package/dist/commonjs/lib/loader/AppWorkerLoader.js +0 -43
- package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +0 -4
- package/dist/commonjs/lib/loader/EggApplicationLoader.js +0 -8
- package/dist/commonjs/lib/loader/index.d.ts +0 -3
- package/dist/commonjs/lib/loader/index.js +0 -22
- package/dist/commonjs/lib/start.d.ts +0 -24
- package/dist/commonjs/lib/start.js +0 -49
- package/dist/commonjs/lib/types.d.ts +0 -257
- package/dist/commonjs/lib/types.js +0 -16
- package/dist/commonjs/lib/utils.d.ts +0 -2
- package/dist/commonjs/lib/utils.js +0 -21
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/urllib.d.ts +0 -1
- package/dist/commonjs/urllib.js +0 -18
- package/dist/esm/agent.d.ts +0 -4
- package/dist/esm/agent.js +0 -7
- package/dist/esm/app/extend/context.d.ts +0 -204
- package/dist/esm/app/extend/context.js +0 -259
- package/dist/esm/app/extend/helper.d.ts +0 -37
- package/dist/esm/app/extend/helper.js +0 -43
- package/dist/esm/app/extend/request.d.ts +0 -141
- package/dist/esm/app/extend/request.js +0 -264
- package/dist/esm/app/extend/response.d.ts +0 -31
- package/dist/esm/app/extend/response.js +0 -34
- package/dist/esm/app/middleware/body_parser.d.ts +0 -2
- package/dist/esm/app/middleware/body_parser.js +0 -3
- package/dist/esm/app/middleware/meta.d.ts +0 -10
- package/dist/esm/app/middleware/meta.js +0 -20
- package/dist/esm/app/middleware/notfound.d.ts +0 -7
- package/dist/esm/app/middleware/notfound.js +0 -29
- package/dist/esm/app/middleware/override_method.d.ts +0 -2
- package/dist/esm/app/middleware/override_method.js +0 -3
- package/dist/esm/app/middleware/site_file.d.ts +0 -9
- package/dist/esm/app/middleware/site_file.js +0 -53
- package/dist/esm/config/config.default.d.ts +0 -9
- package/dist/esm/config/config.default.js +0 -374
- package/dist/esm/config/config.local.d.ts +0 -8
- package/dist/esm/config/config.local.js +0 -10
- package/dist/esm/config/config.unittest.d.ts +0 -7
- package/dist/esm/config/config.unittest.js +0 -9
- package/dist/esm/config/favicon.png +0 -0
- package/dist/esm/config/plugin.d.ts +0 -122
- package/dist/esm/config/plugin.js +0 -122
- package/dist/esm/index.d.ts +0 -69
- package/dist/esm/index.js +0 -73
- package/dist/esm/lib/agent.d.ts +0 -19
- package/dist/esm/lib/agent.js +0 -54
- package/dist/esm/lib/application.d.ts +0 -56
- package/dist/esm/lib/application.js +0 -259
- package/dist/esm/lib/core/base_context_class.d.ts +0 -17
- package/dist/esm/lib/core/base_context_class.js +0 -17
- package/dist/esm/lib/core/base_context_logger.d.ts +0 -36
- package/dist/esm/lib/core/base_context_logger.js +0 -60
- package/dist/esm/lib/core/base_hook_class.d.ts +0 -11
- package/dist/esm/lib/core/base_hook_class.js +0 -22
- package/dist/esm/lib/core/context_httpclient.d.ts +0 -16
- package/dist/esm/lib/core/context_httpclient.js +0 -26
- package/dist/esm/lib/core/httpclient.d.ts +0 -14
- package/dist/esm/lib/core/httpclient.js +0 -38
- package/dist/esm/lib/core/logger.d.ts +0 -3
- package/dist/esm/lib/core/logger.js +0 -37
- package/dist/esm/lib/core/messenger/IMessenger.d.ts +0 -50
- package/dist/esm/lib/core/messenger/IMessenger.js +0 -2
- package/dist/esm/lib/core/messenger/base.d.ts +0 -8
- package/dist/esm/lib/core/messenger/base.js +0 -27
- package/dist/esm/lib/core/messenger/index.d.ts +0 -7
- package/dist/esm/lib/core/messenger/index.js +0 -12
- package/dist/esm/lib/core/messenger/ipc.d.ts +0 -58
- package/dist/esm/lib/core/messenger/ipc.js +0 -128
- package/dist/esm/lib/core/messenger/local.d.ts +0 -60
- package/dist/esm/lib/core/messenger/local.js +0 -128
- package/dist/esm/lib/core/utils.d.ts +0 -2
- package/dist/esm/lib/core/utils.js +0 -70
- package/dist/esm/lib/egg.d.ts +0 -305
- package/dist/esm/lib/egg.js +0 -586
- package/dist/esm/lib/error/CookieLimitExceedError.d.ts +0 -5
- package/dist/esm/lib/error/CookieLimitExceedError.js +0 -12
- package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
- package/dist/esm/lib/error/MessageUnhandledRejectionError.js +0 -12
- package/dist/esm/lib/error/index.d.ts +0 -2
- package/dist/esm/lib/error/index.js +0 -3
- package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +0 -12
- package/dist/esm/lib/loader/AgentWorkerLoader.js +0 -20
- package/dist/esm/lib/loader/AppWorkerLoader.d.ts +0 -17
- package/dist/esm/lib/loader/AppWorkerLoader.js +0 -39
- package/dist/esm/lib/loader/EggApplicationLoader.d.ts +0 -4
- package/dist/esm/lib/loader/EggApplicationLoader.js +0 -4
- package/dist/esm/lib/loader/index.d.ts +0 -3
- package/dist/esm/lib/loader/index.js +0 -4
- package/dist/esm/lib/start.d.ts +0 -24
- package/dist/esm/lib/start.js +0 -43
- package/dist/esm/lib/types.d.ts +0 -257
- package/dist/esm/lib/types.js +0 -14
- package/dist/esm/lib/utils.d.ts +0 -2
- package/dist/esm/lib/utils.js +0 -14
- package/dist/esm/package.json +0 -3
- package/dist/esm/urllib.d.ts +0 -1
- package/dist/esm/urllib.js +0 -2
- package/dist/package.json +0 -4
- package/src/agent.ts +0 -7
- package/src/app/extend/context.ts +0 -332
- package/src/app/extend/request.ts +0 -300
- package/src/app/middleware/body_parser.ts +0 -3
- package/src/app/middleware/meta.ts +0 -27
- package/src/app/middleware/notfound.ts +0 -41
- package/src/app/middleware/override_method.ts +0 -3
- package/src/app/middleware/site_file.ts +0 -68
- package/src/config/config.default.ts +0 -404
- package/src/config/config.local.ts +0 -11
- package/src/config/config.unittest.ts +0 -10
- package/src/config/favicon.png +0 -0
- package/src/index.ts +0 -120
- package/src/lib/agent.ts +0 -66
- package/src/lib/application.ts +0 -296
- package/src/lib/core/base_context_class.ts +0 -24
- package/src/lib/core/base_context_logger.ts +0 -67
- package/src/lib/core/base_hook_class.ts +0 -30
- package/src/lib/core/context_httpclient.ts +0 -33
- package/src/lib/core/httpclient.ts +0 -64
- package/src/lib/core/logger.ts +0 -42
- package/src/lib/core/messenger/base.ts +0 -30
- package/src/lib/core/messenger/index.ts +0 -16
- package/src/lib/core/messenger/ipc.ts +0 -146
- package/src/lib/core/messenger/local.ts +0 -147
- package/src/lib/core/utils.ts +0 -77
- package/src/lib/egg.ts +0 -705
- package/src/lib/error/CookieLimitExceedError.ts +0 -12
- package/src/lib/error/MessageUnhandledRejectionError.ts +0 -12
- package/src/lib/error/index.ts +0 -2
- package/src/lib/loader/AgentWorkerLoader.ts +0 -21
- package/src/lib/loader/AppWorkerLoader.ts +0 -42
- package/src/lib/loader/EggApplicationLoader.ts +0 -5
- package/src/lib/loader/index.ts +0 -3
- package/src/lib/start.ts +0 -66
- package/src/lib/utils.ts +0 -15
- package/src/urllib.ts +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<div style="text-align:center">
|
|
4
|
-
<img src="site/public/assets/egg-banner.png" />
|
|
5
|
-
</div>
|
|
1
|
+
# egg
|
|
6
2
|
|
|
7
3
|
[](https://npmjs.org/package/egg)
|
|
8
4
|
[](http://packagequality.com/#?package=egg)
|
|
@@ -10,8 +6,6 @@ English | [简体中文](./README.zh-CN.md)
|
|
|
10
6
|
[](https://nodejs.org/en/download/)
|
|
11
7
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_shield)
|
|
12
8
|
|
|
13
|
-
[](https://github.com/eggjs/egg/actions?query=branch%3Amaster)
|
|
14
|
-
[](https://codecov.io/gh/eggjs/egg)
|
|
15
9
|
[](https://snyk.io/test/npm/egg)
|
|
16
10
|
[](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
|
-
$
|
|
33
|
-
$
|
|
26
|
+
$ pnpm install
|
|
27
|
+
$ pnpm run dev
|
|
34
28
|
$ open http://localhost:7001
|
|
35
29
|
```
|
|
36
30
|
|
|
37
|
-
> Node.js >=
|
|
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
|
-
[](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
|
[](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
|
-
[](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fegg?ref=badge_large)
|
package/dist/agent.d.ts
ADDED
package/dist/agent.js
ADDED
|
@@ -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
|
|
2
|
-
|
|
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
|
-
|
|
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 };
|