egg 4.1.0-beta.19 → 4.1.0-beta.20

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 (105) hide show
  1. package/dist/AgentWorkerLoader-DG_hAClt.d.ts +17 -0
  2. package/dist/AgentWorkerLoader-D_hceBRW.js +24 -0
  3. package/dist/AppWorkerLoader-CAtxJvGl.js +37 -0
  4. package/dist/AppWorkerLoader-CT875rYM.d.ts +22 -0
  5. package/dist/CookieLimitExceedError-CAW0HYJw.d.ts +8 -0
  6. package/dist/CookieLimitExceedError-DLGakbeu.js +15 -0
  7. package/dist/EggApplicationLoader-CMe1VQt1.js +7 -0
  8. package/dist/EggApplicationLoader-PnIvd5oV.d.ts +8 -0
  9. package/dist/IMessenger-C9g6ypSI.d.ts +54 -0
  10. package/dist/MessageUnhandledRejectionError-Lq5fWw24.d.ts +8 -0
  11. package/dist/MessageUnhandledRejectionError-oD_E1Ewl.js +15 -0
  12. package/dist/agent-BfFWeJj4.js +55 -0
  13. package/dist/agent.d.ts +11 -1
  14. package/dist/agent.js +1 -1
  15. package/dist/app/extend/context.d.ts +11 -182
  16. package/dist/app/extend/context.js +1 -242
  17. package/dist/app/extend/helper.d.ts +11 -41
  18. package/dist/app/extend/helper.js +3 -45
  19. package/dist/app/extend/request.d.ts +11 -135
  20. package/dist/app/extend/request.js +2 -224
  21. package/dist/app/extend/response.d.ts +1 -28
  22. package/dist/app/extend/response.js +1 -34
  23. package/dist/app/middleware/meta.d.ts +11 -10
  24. package/dist/app/middleware/notfound.d.ts +11 -10
  25. package/dist/app/middleware/site_file.d.ts +11 -12
  26. package/dist/application-DVwFQSa9.js +208 -0
  27. package/dist/base-KLVtlzUD.d.ts +12 -0
  28. package/dist/base_context_class-Xc1OZql9.js +19 -0
  29. package/dist/base_context_logger-CZU59PGA.js +58 -0
  30. package/dist/base_hook_class-D0Gu2p8r.js +26 -0
  31. package/dist/base_hook_class-R8A8gm1s.d.ts +1109 -0
  32. package/dist/config/config.default.d.ts +11 -2
  33. package/dist/config/config.default.js +26 -2
  34. package/dist/context-D1Wg7CXs.js +244 -0
  35. package/dist/context_httpclient-BpRMdJhf.js +29 -0
  36. package/dist/egg-DVo5e_lr.js +800 -0
  37. package/dist/error-BYo_LRnd.js +1 -0
  38. package/dist/helper-B3PKMPXq.js +47 -0
  39. package/dist/httpclient-C1QPc_R7.js +36 -0
  40. package/dist/index-CUPkUUOR.d.ts +1 -0
  41. package/dist/index-CkgLZdB4.d.ts +1 -0
  42. package/dist/index.d.ts +12 -20
  43. package/dist/index.js +26 -19
  44. package/dist/lib/agent.d.ts +11 -21
  45. package/dist/lib/agent.js +20 -54
  46. package/dist/lib/application.d.ts +11 -59
  47. package/dist/lib/application.js +21 -207
  48. package/dist/lib/core/base_context_class.d.ts +11 -22
  49. package/dist/lib/core/base_context_class.js +2 -17
  50. package/dist/lib/core/base_context_logger.d.ts +11 -39
  51. package/dist/lib/core/base_context_logger.js +1 -56
  52. package/dist/lib/core/base_hook_class.d.ts +11 -17
  53. package/dist/lib/core/base_hook_class.js +1 -24
  54. package/dist/lib/core/context_httpclient.d.ts +11 -21
  55. package/dist/lib/core/context_httpclient.js +1 -27
  56. package/dist/lib/core/httpclient.d.ts +12 -17
  57. package/dist/lib/core/httpclient.js +1 -34
  58. package/dist/lib/core/logger.d.ts +11 -1
  59. package/dist/lib/core/logger.js +1 -29
  60. package/dist/lib/core/messenger/IMessenger.d.ts +1 -53
  61. package/dist/lib/core/messenger/base.d.ts +12 -11
  62. package/dist/lib/core/messenger/base.js +15 -27
  63. package/dist/lib/core/messenger/index.d.ts +12 -11
  64. package/dist/lib/core/messenger/index.js +15 -11
  65. package/dist/lib/core/messenger/ipc.d.ts +12 -4
  66. package/dist/lib/core/messenger/ipc.js +15 -128
  67. package/dist/lib/core/messenger/local.d.ts +12 -4
  68. package/dist/lib/core/messenger/local.js +15 -124
  69. package/dist/lib/core/utils.js +1 -46
  70. package/dist/lib/egg.d.ts +12 -285
  71. package/dist/lib/egg.js +15 -518
  72. package/dist/lib/error/CookieLimitExceedError.d.ts +1 -7
  73. package/dist/lib/error/CookieLimitExceedError.js +1 -13
  74. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +1 -7
  75. package/dist/lib/error/MessageUnhandledRejectionError.js +1 -13
  76. package/dist/lib/error/index.d.ts +3 -2
  77. package/dist/lib/error/index.js +3 -2
  78. package/dist/lib/loader/AgentWorkerLoader.d.ts +2 -16
  79. package/dist/lib/loader/AgentWorkerLoader.js +2 -22
  80. package/dist/lib/loader/AppWorkerLoader.d.ts +2 -21
  81. package/dist/lib/loader/AppWorkerLoader.js +2 -35
  82. package/dist/lib/loader/EggApplicationLoader.d.ts +1 -7
  83. package/dist/lib/loader/EggApplicationLoader.js +1 -5
  84. package/dist/lib/loader/index.d.ts +4 -3
  85. package/dist/lib/loader/index.js +4 -3
  86. package/dist/lib/start.d.ts +11 -27
  87. package/dist/lib/start.js +25 -34
  88. package/dist/lib/types.d.ts +12 -283
  89. package/dist/lib/types.js +2 -32
  90. package/dist/lib/types.plugin.d.ts +1 -12
  91. package/dist/lib/types.plugin.js +1 -12
  92. package/dist/lib/utils.js +1 -12
  93. package/dist/loader-3myZ-rpm.js +1 -0
  94. package/dist/logger-C4tIcO3S.js +31 -0
  95. package/dist/request-Cy_1DlaX.js +225 -0
  96. package/dist/response-CDeQ9Sx2.js +36 -0
  97. package/dist/response-DlNYDj00.d.ts +29 -0
  98. package/dist/src-BuOjXSrB.js +3 -0
  99. package/dist/start-4E84z796.js +35 -0
  100. package/dist/types-dKSyDnVp.js +32 -0
  101. package/dist/types.plugin-B2v0K0I8.js +14 -0
  102. package/dist/types.plugin-C3D5I7VD.d.ts +12 -0
  103. package/dist/utils-B1Rjsoi9.js +48 -0
  104. package/dist/utils-BDoYg6z6.js +14 -0
  105. package/package.json +22 -22
@@ -1,244 +1,3 @@
1
- import { Context as Context$1, Router, utils } from "@eggjs/core";
2
- import { assign } from "utility";
3
- import { diff, now } from "performance-ms";
1
+ import { Context } from "../../context-D1Wg7CXs.js";
4
2
 
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
3
  export { Context as default };
@@ -1,42 +1,12 @@
1
- import { BaseContextClass } from "../../lib/core/base_context_class.js";
2
-
3
- //#region src/app/extend/helper.d.ts
4
-
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
- declare class Helper 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: string, params: Record<string, any>): string;
26
- /**
27
- * Generate full URL(with host) for route. Takes the route name and a map of named params.
28
- * @function Helper#urlFor
29
- * @param {String} name - Router name
30
- * @param {Object} params - Other params
31
- * @example
32
- * ```js
33
- * app.get('home', '/index.htm', 'home.index');
34
- * ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
35
- * => http://127.0.0.1:7001/index.htm?by=recent&limit=20
36
- * ```
37
- * @return {String} full url(with host)
38
- */
39
- urlFor(name: string, params: Record<string, any>): string;
40
- }
41
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { Helper } from "../../base_hook_class-R8A8gm1s.js";
6
+ import "../../response-DlNYDj00.js";
7
+ import "../../types.plugin-C3D5I7VD.js";
8
+ import "../../IMessenger-C9g6ypSI.js";
9
+ import "../../CookieLimitExceedError-CAW0HYJw.js";
10
+ import "../../MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "../../index-CkgLZdB4.js";
42
12
  export { Helper as default };
@@ -1,47 +1,5 @@
1
- import { BaseContextClass } from "../../lib/core/base_context_class.js";
2
- import url from "node:url";
1
+ import "../../base_context_logger-CZU59PGA.js";
2
+ import "../../base_context_class-Xc1OZql9.js";
3
+ import { Helper } from "../../helper-B3PKMPXq.js";
3
4
 
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
5
  export { Helper as default };
@@ -1,136 +1,12 @@
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
- //#endregion
1
+ import "../../EggApplicationLoader-PnIvd5oV.js";
2
+ import "../../AppWorkerLoader-CT875rYM.js";
3
+ import "../../AgentWorkerLoader-DG_hAClt.js";
4
+ import "../../index-CUPkUUOR.js";
5
+ import { Request } from "../../base_hook_class-R8A8gm1s.js";
6
+ import "../../response-DlNYDj00.js";
7
+ import "../../types.plugin-C3D5I7VD.js";
8
+ import "../../IMessenger-C9g6ypSI.js";
9
+ import "../../CookieLimitExceedError-CAW0HYJw.js";
10
+ import "../../MessageUnhandledRejectionError-Lq5fWw24.js";
11
+ import "../../index-CkgLZdB4.js";
136
12
  export { Request as default };