egg 4.1.0-beta.3 → 4.1.0-beta.30

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 (88) hide show
  1. package/dist/agent.d.ts +3 -7
  2. package/dist/agent.js +6 -10
  3. package/dist/app/extend/context.d.ts +166 -193
  4. package/dist/app/extend/context.js +259 -244
  5. package/dist/app/extend/helper.d.ts +31 -36
  6. package/dist/app/extend/helper.js +41 -45
  7. package/dist/app/extend/request.d.ts +127 -140
  8. package/dist/app/extend/request.js +258 -219
  9. package/dist/app/extend/response.d.ts +22 -32
  10. package/dist/app/extend/response.js +34 -36
  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 +9 -10
  14. package/dist/app/middleware/meta.js +19 -13
  15. package/dist/app/middleware/notfound.d.ts +6 -10
  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 +8 -12
  20. package/dist/app/middleware/site_file.js +52 -37
  21. package/dist/config/config.default.d.ts +3 -8
  22. package/dist/config/config.default.js +377 -256
  23. package/dist/config/config.local.d.ts +3 -10
  24. package/dist/config/config.local.js +7 -6
  25. package/dist/config/config.unittest.d.ts +3 -9
  26. package/dist/config/config.unittest.js +7 -9
  27. package/dist/config/favicon.png +0 -0
  28. package/dist/config/plugin.d.ts +3 -124
  29. package/dist/config/plugin.js +162 -53
  30. package/dist/index.d.ts +84 -19
  31. package/dist/index.js +87 -19
  32. package/dist/lib/agent.d.ts +12 -17
  33. package/dist/lib/agent.js +45 -54
  34. package/dist/lib/application.d.ts +47 -62
  35. package/dist/lib/application.js +249 -197
  36. package/dist/lib/core/base_context_class.d.ts +13 -17
  37. package/dist/lib/core/base_context_class.js +15 -17
  38. package/dist/lib/core/base_context_logger.d.ts +35 -39
  39. package/dist/lib/core/base_context_logger.js +60 -58
  40. package/dist/lib/core/base_hook_class.d.ts +11 -17
  41. package/dist/lib/core/base_hook_class.js +22 -26
  42. package/dist/lib/core/context_httpclient.d.ts +16 -20
  43. package/dist/lib/core/context_httpclient.js +26 -29
  44. package/dist/lib/core/httpclient.d.ts +12 -15
  45. package/dist/lib/core/httpclient.js +37 -34
  46. package/dist/lib/core/logger.d.ts +3 -7
  47. package/dist/lib/core/logger.js +36 -30
  48. package/dist/lib/core/messenger/IMessenger.d.ts +49 -53
  49. package/dist/lib/core/messenger/IMessenger.js +2 -1
  50. package/dist/lib/core/messenger/base.d.ts +7 -11
  51. package/dist/lib/core/messenger/base.js +29 -29
  52. package/dist/lib/core/messenger/index.d.ts +4 -8
  53. package/dist/lib/core/messenger/index.js +8 -11
  54. package/dist/lib/core/messenger/ipc.d.ts +55 -59
  55. package/dist/lib/core/messenger/ipc.js +138 -120
  56. package/dist/lib/core/messenger/local.d.ts +56 -61
  57. package/dist/lib/core/messenger/local.js +131 -124
  58. package/dist/lib/core/utils.d.ts +2 -5
  59. package/dist/lib/core/utils.js +66 -44
  60. package/dist/lib/egg.d.ts +272 -294
  61. package/dist/lib/egg.js +574 -507
  62. package/dist/lib/error/CookieLimitExceedError.d.ts +4 -7
  63. package/dist/lib/error/CookieLimitExceedError.js +12 -15
  64. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +4 -7
  65. package/dist/lib/error/MessageUnhandledRejectionError.js +12 -15
  66. package/dist/lib/error/index.d.ts +2 -3
  67. package/dist/lib/error/index.js +3 -4
  68. package/dist/lib/loader/AgentWorkerLoader.d.ts +7 -12
  69. package/dist/lib/loader/AgentWorkerLoader.js +18 -22
  70. package/dist/lib/loader/AppWorkerLoader.d.ts +12 -17
  71. package/dist/lib/loader/AppWorkerLoader.js +37 -35
  72. package/dist/lib/loader/EggApplicationLoader.d.ts +3 -7
  73. package/dist/lib/loader/EggApplicationLoader.js +4 -7
  74. package/dist/lib/loader/index.d.ts +3 -4
  75. package/dist/lib/loader/index.js +4 -5
  76. package/dist/lib/start.d.ts +18 -22
  77. package/dist/lib/start.js +42 -32
  78. package/dist/lib/types.d.ts +309 -230
  79. package/dist/lib/types.js +31 -14
  80. package/dist/lib/types.plugin.d.ts +21 -0
  81. package/dist/lib/types.plugin.js +24 -0
  82. package/dist/schedule.d.ts +2 -0
  83. package/dist/schedule.js +5 -0
  84. package/dist/urllib.d.ts +1 -1
  85. package/dist/urllib.js +2 -3
  86. package/package.json +42 -32
  87. package/dist/lib/utils.d.ts +0 -5
  88. package/dist/lib/utils.js +0 -14
package/dist/agent.d.ts CHANGED
@@ -1,8 +1,4 @@
1
- import { BaseHookClass } from "./lib/core/base_hook_class.js";
2
-
3
- //#region src/agent.d.ts
4
- declare class EggAgentHook extends BaseHookClass {
5
- configDidLoad(): void;
1
+ import { BaseHookClass } from './lib/core/base_hook_class.ts';
2
+ export default class EggAgentHook extends BaseHookClass {
3
+ configDidLoad(): void;
6
4
  }
7
- //#endregion
8
- export { EggAgentHook as default };
package/dist/agent.js CHANGED
@@ -1,11 +1,7 @@
1
1
  import { BaseHookClass } from "./lib/core/base_hook_class.js";
2
-
3
- //#region src/agent.ts
4
- var EggAgentHook = class extends BaseHookClass {
5
- configDidLoad() {
6
- this.agent._wrapMessenger();
7
- }
8
- };
9
-
10
- //#endregion
11
- export { EggAgentHook as default };
2
+ export default class EggAgentHook extends BaseHookClass {
3
+ configDidLoad() {
4
+ this.agent._wrapMessenger();
5
+ }
6
+ }
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWdlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRTlELE1BQU0sQ0FBQyxPQUFPLE9BQU8sWUFBYSxTQUFRLGFBQWE7SUFDckQsYUFBYTtRQUNYLElBQUksQ0FBQyxLQUFLLENBQUMsY0FBYyxFQUFFLENBQUM7SUFDOUIsQ0FBQztDQUNGIn0=
@@ -1,207 +1,180 @@
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;
1
+ import { Context as EggCoreContext, Router } from '@eggjs/core';
2
+ import type { Cookies as ContextCookies } from '@eggjs/cookies';
3
+ import type { EggLogger } from 'egg-logger';
4
+ import type { Application } from '../../lib/application.ts';
5
+ import type { HttpClientRequestURL, HttpClientRequestOptions, HttpClient } from '../../lib/core/httpclient.ts';
6
+ import type { IService } from '../../lib/types.ts';
7
+ import type Request from './request.ts';
8
+ import type Response from './response.ts';
9
+ import type Helper from './helper.ts';
10
+ interface Cookies extends ContextCookies {
11
+ request: any;
12
+ response: any;
15
13
  }
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 {
14
+ export default class Context extends EggCoreContext {
15
+ app: Application;
16
+ request: Request;
17
+ response: Response;
18
+ service: IService;
184
19
  proxy: any;
185
- performanceStarttime: number;
20
+ /**
21
+ * Request start time
22
+ * @member {Number} Context#starttime
23
+ */
186
24
  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[]>;
25
+ /**
26
+ * Request start timer using `performance.now()`
27
+ * @member {Number} Context#performanceStarttime
28
+ */
29
+ performanceStarttime: number;
30
+ /**
31
+ * Get the current visitor's cookies.
32
+ */
33
+ get cookies(): Cookies;
34
+ /**
35
+ * Get a wrapper httpclient instance contain ctx in the hold request process
36
+ *
37
+ * @return {HttpClient} the wrapper httpclient instance
38
+ */
39
+ get httpclient(): HttpClient;
40
+ /**
41
+ * Alias to {@link Context#httpclient}
42
+ */
43
+ get httpClient(): HttpClient;
44
+ /**
45
+ * Shortcut for httpclient.curl
46
+ *
47
+ * @function Context#curl
48
+ * @param {String|Object} url - request url address.
49
+ * @param {Object} [options] - options for request.
50
+ * @return {Object} see {@link ContextHttpClient#curl}
51
+ */
192
52
  curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
53
+ /**
54
+ * Alias to {@link Application#router}
55
+ *
56
+ * @member {Router} Context#router
57
+ * @since 1.0.0
58
+ * @example
59
+ * ```js
60
+ * this.router.pathFor('post', { id: 12 });
61
+ * ```
62
+ */
193
63
  get router(): Router;
64
+ /**
65
+ * Set router to Context, only use on EggRouter
66
+ * @param {Router} val router instance
67
+ */
194
68
  set router(val: Router);
69
+ /**
70
+ * Get helper instance from {@link Application#Helper}
71
+ *
72
+ * @member {Helper} Context#helper
73
+ * @since 1.0.0
74
+ */
195
75
  get helper(): Helper;
196
- get httpclient(): HttpClient;
197
- get httpClient(): HttpClient;
76
+ /**
77
+ * Wrap app.loggers with context information,
78
+ * if a custom logger is defined by naming aLogger, then you can `ctx.getLogger('aLogger')`
79
+ *
80
+ * @param {String} name - logger name
81
+ */
198
82
  getLogger(name: string): EggLogger;
83
+ /**
84
+ * Logger for Application
85
+ *
86
+ * @member {Logger} Context#logger
87
+ * @since 1.0.0
88
+ * @example
89
+ * ```js
90
+ * this.logger.info('some request data: %j', this.request.body);
91
+ * this.logger.warn('WARNING!!!!');
92
+ * ```
93
+ */
199
94
  get logger(): EggLogger;
95
+ /**
96
+ * Logger for frameworks and plugins
97
+ *
98
+ * @member {Logger} Context#coreLogger
99
+ * @since 1.0.0
100
+ */
200
101
  get coreLogger(): EggLogger;
102
+ /**
103
+ * locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
104
+ * which will be used as data when view is rendering.
105
+ * 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`.
106
+ *
107
+ * when you set locals, only object is available
108
+ *
109
+ * ```js
110
+ * this.locals = {
111
+ * a: 1
112
+ * };
113
+ * this.locals = {
114
+ * b: 1
115
+ * };
116
+ * this.locals.c = 1;
117
+ * console.log(this.locals);
118
+ * {
119
+ * a: 1,
120
+ * b: 1,
121
+ * c: 1,
122
+ * };
123
+ * ```
124
+ *
125
+ * `ctx.locals` has cache, it only merges `app.locals` once in one request.
126
+ *
127
+ * @member {Object} Context#locals
128
+ */
201
129
  get locals(): Record<string, any>;
130
+ set locals(val: Record<string, any>);
131
+ /**
132
+ * alias to {@link Context#locals}, compatible with koa that use this variable
133
+ * @member {Object} state
134
+ * @see Context#locals
135
+ */
136
+ get state(): Record<string, any>;
137
+ set state(val: Record<string, any>);
138
+ /**
139
+ * Run async function in the background
140
+ * @param {Function} scope - the first args is ctx
141
+ * ```js
142
+ * this.body = 'hi';
143
+ *
144
+ * this.runInBackground(async ctx => {
145
+ * await ctx.mysql.query(sql);
146
+ * await ctx.curl(url);
147
+ * });
148
+ * ```
149
+ */
150
+ runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void;
151
+ _runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string): Promise<void>;
152
+ /**
153
+ * @member {Boolean} Context#acceptJSON
154
+ * @see Request#acceptJSON
155
+ * @since 1.0.0
156
+ */
157
+ get acceptJSON(): boolean;
158
+ get query(): Record<string, string>;
159
+ /**
160
+ * @member {Array} Context#queries
161
+ * @see Request#queries
162
+ * @since 1.0.0
163
+ */
164
+ get queries(): Record<string, string[]>;
165
+ /**
166
+ * @member {string} Context#ip
167
+ * @see Request#ip
168
+ * @since 1.0.0
169
+ */
170
+ get ip(): string;
171
+ set ip(val: string);
172
+ /**
173
+ * @member {Number} Context#realStatus
174
+ * @see Response#realStatus
175
+ * @since 1.0.0
176
+ */
202
177
  get realStatus(): number;
203
178
  set realStatus(val: number);
204
- }
205
179
  }
206
- //#endregion
207
- export { Context as default };
180
+ export {};