egg 4.1.0-beta.20 → 4.1.0-beta.21

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 (123) hide show
  1. package/dist/agent.d.ts +3 -17
  2. package/dist/agent.js +7 -11
  3. package/dist/app/extend/context.d.ts +180 -12
  4. package/dist/app/extend/context.js +259 -3
  5. package/dist/app/extend/helper.d.ts +37 -12
  6. package/dist/app/extend/helper.js +43 -5
  7. package/dist/app/extend/request.d.ts +132 -12
  8. package/dist/app/extend/request.js +265 -4
  9. package/dist/app/extend/response.d.ts +25 -2
  10. package/dist/app/extend/response.js +34 -3
  11. package/dist/app/middleware/body_parser.d.ts +2 -2
  12. package/dist/app/middleware/body_parser.js +3 -7
  13. package/dist/app/middleware/meta.d.ts +10 -12
  14. package/dist/app/middleware/meta.js +19 -13
  15. package/dist/app/middleware/notfound.d.ts +7 -12
  16. package/dist/app/middleware/notfound.js +28 -25
  17. package/dist/app/middleware/override_method.d.ts +2 -2
  18. package/dist/app/middleware/override_method.js +3 -7
  19. package/dist/app/middleware/site_file.d.ts +9 -12
  20. package/dist/app/middleware/site_file.js +52 -37
  21. package/dist/config/config.default.d.ts +2 -16
  22. package/dist/config/config.default.js +375 -282
  23. package/dist/config/config.local.d.ts +5 -7
  24. package/dist/config/config.local.js +9 -6
  25. package/dist/config/config.unittest.d.ts +5 -7
  26. package/dist/config/config.unittest.js +8 -9
  27. package/dist/config/plugin.d.ts +120 -122
  28. package/dist/config/plugin.js +121 -53
  29. package/dist/index.d.ts +66 -13
  30. package/dist/index.js +70 -30
  31. package/dist/lib/agent.d.ts +19 -12
  32. package/dist/lib/agent.js +48 -22
  33. package/dist/lib/application.d.ts +56 -12
  34. package/dist/lib/application.js +261 -23
  35. package/dist/lib/core/base_context_class.d.ts +18 -12
  36. package/dist/lib/core/base_context_class.js +17 -4
  37. package/dist/lib/core/base_context_logger.d.ts +36 -12
  38. package/dist/lib/core/base_context_logger.js +60 -3
  39. package/dist/lib/core/base_hook_class.d.ts +11 -12
  40. package/dist/lib/core/base_hook_class.js +22 -3
  41. package/dist/lib/core/context_httpclient.d.ts +17 -12
  42. package/dist/lib/core/context_httpclient.js +26 -3
  43. package/dist/lib/core/httpclient.d.ts +14 -12
  44. package/dist/lib/core/httpclient.js +39 -3
  45. package/dist/lib/core/logger.d.ts +3 -17
  46. package/dist/lib/core/logger.js +37 -3
  47. package/dist/lib/core/messenger/IMessenger.d.ts +50 -2
  48. package/dist/lib/core/messenger/IMessenger.js +2 -1
  49. package/dist/lib/core/messenger/base.d.ts +8 -13
  50. package/dist/lib/core/messenger/base.js +28 -17
  51. package/dist/lib/core/messenger/index.d.ts +7 -12
  52. package/dist/lib/core/messenger/index.js +10 -17
  53. package/dist/lib/core/messenger/ipc.d.ts +55 -68
  54. package/dist/lib/core/messenger/ipc.js +151 -17
  55. package/dist/lib/core/messenger/local.d.ts +56 -69
  56. package/dist/lib/core/messenger/local.js +128 -17
  57. package/dist/lib/core/utils.d.ts +2 -5
  58. package/dist/lib/core/utils.js +70 -3
  59. package/dist/lib/egg.d.ts +285 -12
  60. package/dist/lib/egg.js +582 -17
  61. package/dist/lib/error/CookieLimitExceedError.d.ts +5 -2
  62. package/dist/lib/error/CookieLimitExceedError.js +12 -3
  63. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +5 -2
  64. package/dist/lib/error/MessageUnhandledRejectionError.js +12 -3
  65. package/dist/lib/error/index.d.ts +2 -4
  66. package/dist/lib/error/index.js +3 -5
  67. package/dist/lib/loader/AgentWorkerLoader.d.ts +12 -3
  68. package/dist/lib/loader/AgentWorkerLoader.js +20 -4
  69. package/dist/lib/loader/AppWorkerLoader.d.ts +17 -3
  70. package/dist/lib/loader/AppWorkerLoader.js +39 -4
  71. package/dist/lib/loader/EggApplicationLoader.d.ts +4 -2
  72. package/dist/lib/loader/EggApplicationLoader.js +4 -3
  73. package/dist/lib/loader/index.d.ts +3 -5
  74. package/dist/lib/loader/index.js +4 -6
  75. package/dist/lib/start.d.ts +24 -12
  76. package/dist/lib/start.js +46 -27
  77. package/dist/lib/types.d.ts +281 -12
  78. package/dist/lib/types.js +31 -4
  79. package/dist/lib/types.plugin.d.ts +12 -1
  80. package/dist/lib/types.plugin.js +14 -3
  81. package/dist/lib/utils.d.ts +2 -5
  82. package/dist/lib/utils.js +14 -3
  83. package/dist/urllib.d.ts +1 -1
  84. package/dist/urllib.js +2 -3
  85. package/package.json +23 -23
  86. package/dist/AgentWorkerLoader-DG_hAClt.d.ts +0 -17
  87. package/dist/AgentWorkerLoader-D_hceBRW.js +0 -24
  88. package/dist/AppWorkerLoader-CAtxJvGl.js +0 -37
  89. package/dist/AppWorkerLoader-CT875rYM.d.ts +0 -22
  90. package/dist/CookieLimitExceedError-CAW0HYJw.d.ts +0 -8
  91. package/dist/CookieLimitExceedError-DLGakbeu.js +0 -15
  92. package/dist/EggApplicationLoader-CMe1VQt1.js +0 -7
  93. package/dist/EggApplicationLoader-PnIvd5oV.d.ts +0 -8
  94. package/dist/IMessenger-C9g6ypSI.d.ts +0 -54
  95. package/dist/MessageUnhandledRejectionError-Lq5fWw24.d.ts +0 -8
  96. package/dist/MessageUnhandledRejectionError-oD_E1Ewl.js +0 -15
  97. package/dist/agent-BfFWeJj4.js +0 -55
  98. package/dist/application-DVwFQSa9.js +0 -208
  99. package/dist/base-KLVtlzUD.d.ts +0 -12
  100. package/dist/base_context_class-Xc1OZql9.js +0 -19
  101. package/dist/base_context_logger-CZU59PGA.js +0 -58
  102. package/dist/base_hook_class-D0Gu2p8r.js +0 -26
  103. package/dist/base_hook_class-R8A8gm1s.d.ts +0 -1109
  104. package/dist/context-D1Wg7CXs.js +0 -244
  105. package/dist/context_httpclient-BpRMdJhf.js +0 -29
  106. package/dist/egg-DVo5e_lr.js +0 -800
  107. package/dist/error-BYo_LRnd.js +0 -1
  108. package/dist/helper-B3PKMPXq.js +0 -47
  109. package/dist/httpclient-C1QPc_R7.js +0 -36
  110. package/dist/index-CUPkUUOR.d.ts +0 -1
  111. package/dist/index-CkgLZdB4.d.ts +0 -1
  112. package/dist/loader-3myZ-rpm.js +0 -1
  113. package/dist/logger-C4tIcO3S.js +0 -31
  114. package/dist/request-Cy_1DlaX.js +0 -225
  115. package/dist/response-CDeQ9Sx2.js +0 -36
  116. package/dist/response-DlNYDj00.d.ts +0 -29
  117. package/dist/src-BuOjXSrB.js +0 -3
  118. package/dist/start-4E84z796.js +0 -35
  119. package/dist/types-dKSyDnVp.js +0 -32
  120. package/dist/types.plugin-B2v0K0I8.js +0 -14
  121. package/dist/types.plugin-C3D5I7VD.d.ts +0 -12
  122. package/dist/utils-B1Rjsoi9.js +0 -48
  123. package/dist/utils-BDoYg6z6.js +0 -14
@@ -1,244 +0,0 @@
1
- import { Context, 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$1 = class extends Context {
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$1 as Context };
@@ -1,29 +0,0 @@
1
- //#region src/lib/core/context_httpclient.ts
2
- var ContextHttpClient = class {
3
- ctx;
4
- app;
5
- constructor(ctx) {
6
- this.ctx = ctx;
7
- this.app = ctx.app;
8
- }
9
- /**
10
- * http request helper base on {@link HttpClient}, it will auto save httpclient log.
11
- * Keep the same api with {@link Application#curl}.
12
- *
13
- * @param {String|Object} url - request url address.
14
- * @param {Object} [options] - options for request.
15
- */
16
- async curl(url, options) {
17
- options = {
18
- ...options,
19
- ctx: this.ctx
20
- };
21
- return await this.app.curl(url, options);
22
- }
23
- async request(url, options) {
24
- return await this.curl(url, options);
25
- }
26
- };
27
-
28
- //#endregion
29
- export { ContextHttpClient };