egg 3.29.0 → 4.0.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 (202) hide show
  1. package/README.md +2 -1
  2. package/README.zh-CN.md +7 -5
  3. package/dist/commonjs/agent.d.ts +4 -0
  4. package/dist/commonjs/agent.js +10 -0
  5. package/dist/commonjs/app/extend/context.d.ts +2 -0
  6. package/dist/commonjs/app/extend/context.js +263 -0
  7. package/dist/commonjs/app/middleware/body_parser.d.ts +2 -0
  8. package/dist/commonjs/app/middleware/body_parser.js +8 -0
  9. package/dist/commonjs/app/middleware/meta.d.ts +11 -0
  10. package/dist/commonjs/app/middleware/meta.js +22 -0
  11. package/dist/commonjs/app/middleware/notfound.d.ts +8 -0
  12. package/dist/commonjs/app/middleware/notfound.js +31 -0
  13. package/dist/commonjs/app/middleware/override_method.d.ts +2 -0
  14. package/dist/commonjs/app/middleware/override_method.js +8 -0
  15. package/dist/commonjs/app/middleware/site_file.d.ts +7 -0
  16. package/dist/commonjs/app/middleware/site_file.js +59 -0
  17. package/dist/commonjs/config/config.default.d.ts +9 -0
  18. package/dist/commonjs/config/config.default.js +378 -0
  19. package/dist/commonjs/config/config.local.d.ts +8 -0
  20. package/dist/commonjs/config/config.local.js +12 -0
  21. package/dist/commonjs/config/config.unittest.d.ts +7 -0
  22. package/dist/commonjs/config/config.unittest.js +11 -0
  23. package/dist/commonjs/config/plugin.d.ts +122 -0
  24. package/dist/commonjs/config/plugin.js +125 -0
  25. package/dist/commonjs/index.d.ts +61 -0
  26. package/dist/commonjs/index.js +89 -0
  27. package/dist/commonjs/lib/agent.d.ts +19 -0
  28. package/dist/commonjs/lib/agent.js +58 -0
  29. package/dist/commonjs/lib/application.d.ts +66 -0
  30. package/dist/commonjs/lib/application.js +281 -0
  31. package/dist/commonjs/lib/core/base_context_class.d.ts +14 -0
  32. package/dist/commonjs/lib/core/base_context_class.js +22 -0
  33. package/dist/commonjs/lib/core/base_context_logger.d.ts +36 -0
  34. package/dist/commonjs/lib/core/base_context_logger.js +64 -0
  35. package/dist/commonjs/lib/core/base_hook_class.d.ts +11 -0
  36. package/dist/commonjs/lib/core/base_hook_class.js +30 -0
  37. package/dist/commonjs/lib/core/context_httpclient.d.ts +16 -0
  38. package/dist/commonjs/lib/core/context_httpclient.js +30 -0
  39. package/dist/commonjs/lib/core/httpclient.d.ts +14 -0
  40. package/dist/commonjs/lib/core/httpclient.js +40 -0
  41. package/dist/commonjs/lib/core/logger.d.ts +3 -0
  42. package/dist/commonjs/lib/core/logger.js +40 -0
  43. package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +50 -0
  44. package/dist/commonjs/lib/core/messenger/IMessenger.js +3 -0
  45. package/dist/commonjs/lib/core/messenger/index.d.ts +7 -0
  46. package/dist/commonjs/lib/core/messenger/index.js +14 -0
  47. package/dist/commonjs/lib/core/messenger/ipc.d.ts +57 -0
  48. package/dist/commonjs/lib/core/messenger/ipc.js +126 -0
  49. package/dist/commonjs/lib/core/messenger/local.d.ts +61 -0
  50. package/dist/commonjs/lib/core/messenger/local.js +134 -0
  51. package/dist/commonjs/lib/core/singleton.d.ts +23 -0
  52. package/dist/commonjs/lib/core/singleton.js +120 -0
  53. package/dist/commonjs/lib/core/utils.d.ts +2 -0
  54. package/dist/commonjs/lib/core/utils.js +77 -0
  55. package/dist/commonjs/lib/egg.d.ts +271 -0
  56. package/dist/commonjs/lib/egg.js +613 -0
  57. package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +12 -0
  58. package/dist/commonjs/lib/loader/AgentWorkerLoader.js +24 -0
  59. package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +17 -0
  60. package/dist/commonjs/lib/loader/AppWorkerLoader.js +43 -0
  61. package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +4 -0
  62. package/dist/commonjs/lib/loader/EggApplicationLoader.js +8 -0
  63. package/dist/commonjs/lib/loader/index.d.ts +3 -0
  64. package/dist/commonjs/lib/loader/index.js +22 -0
  65. package/dist/commonjs/lib/start.d.ts +15 -0
  66. package/dist/commonjs/lib/start.js +49 -0
  67. package/dist/commonjs/lib/type.d.ts +296 -0
  68. package/dist/commonjs/lib/type.js +3 -0
  69. package/dist/commonjs/package.json +3 -0
  70. package/dist/esm/agent.d.ts +4 -0
  71. package/dist/esm/agent.js +7 -0
  72. package/dist/esm/app/extend/context.d.ts +2 -0
  73. package/dist/esm/app/extend/context.js +258 -0
  74. package/dist/esm/app/middleware/body_parser.d.ts +2 -0
  75. package/dist/esm/app/middleware/body_parser.js +3 -0
  76. package/dist/esm/app/middleware/meta.d.ts +11 -0
  77. package/dist/esm/app/middleware/meta.js +20 -0
  78. package/dist/esm/app/middleware/notfound.d.ts +8 -0
  79. package/dist/esm/app/middleware/notfound.js +29 -0
  80. package/dist/esm/app/middleware/override_method.d.ts +2 -0
  81. package/dist/esm/app/middleware/override_method.js +3 -0
  82. package/dist/esm/app/middleware/site_file.d.ts +7 -0
  83. package/dist/esm/app/middleware/site_file.js +54 -0
  84. package/dist/esm/config/config.default.d.ts +9 -0
  85. package/dist/esm/config/config.default.js +373 -0
  86. package/dist/esm/config/config.local.d.ts +8 -0
  87. package/dist/esm/config/config.local.js +10 -0
  88. package/dist/esm/config/config.unittest.d.ts +7 -0
  89. package/dist/esm/config/config.unittest.js +9 -0
  90. package/dist/esm/config/favicon.png +0 -0
  91. package/dist/esm/config/plugin.d.ts +122 -0
  92. package/dist/esm/config/plugin.js +123 -0
  93. package/dist/esm/index.d.ts +61 -0
  94. package/dist/esm/index.js +65 -0
  95. package/dist/esm/lib/agent.d.ts +19 -0
  96. package/dist/esm/lib/agent.js +54 -0
  97. package/dist/esm/lib/application.d.ts +66 -0
  98. package/dist/esm/lib/application.js +274 -0
  99. package/dist/esm/lib/core/base_context_class.d.ts +14 -0
  100. package/dist/esm/lib/core/base_context_class.js +18 -0
  101. package/dist/esm/lib/core/base_context_logger.d.ts +36 -0
  102. package/dist/esm/lib/core/base_context_logger.js +60 -0
  103. package/dist/esm/lib/core/base_hook_class.d.ts +11 -0
  104. package/dist/esm/lib/core/base_hook_class.js +23 -0
  105. package/dist/esm/lib/core/context_httpclient.d.ts +16 -0
  106. package/dist/esm/lib/core/context_httpclient.js +26 -0
  107. package/dist/esm/lib/core/httpclient.d.ts +14 -0
  108. package/dist/esm/lib/core/httpclient.js +33 -0
  109. package/dist/esm/lib/core/logger.d.ts +3 -0
  110. package/dist/esm/lib/core/logger.js +37 -0
  111. package/dist/esm/lib/core/messenger/IMessenger.d.ts +50 -0
  112. package/dist/esm/lib/core/messenger/IMessenger.js +2 -0
  113. package/dist/esm/lib/core/messenger/index.d.ts +7 -0
  114. package/dist/esm/lib/core/messenger/index.js +11 -0
  115. package/dist/esm/lib/core/messenger/ipc.d.ts +57 -0
  116. package/dist/esm/lib/core/messenger/ipc.js +119 -0
  117. package/dist/esm/lib/core/messenger/local.d.ts +61 -0
  118. package/dist/esm/lib/core/messenger/local.js +127 -0
  119. package/dist/esm/lib/core/singleton.d.ts +23 -0
  120. package/dist/esm/lib/core/singleton.js +113 -0
  121. package/dist/esm/lib/core/utils.d.ts +2 -0
  122. package/dist/esm/lib/core/utils.js +70 -0
  123. package/dist/esm/lib/egg.d.ts +271 -0
  124. package/dist/esm/lib/egg.js +573 -0
  125. package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +12 -0
  126. package/dist/esm/lib/loader/AgentWorkerLoader.js +20 -0
  127. package/dist/esm/lib/loader/AppWorkerLoader.d.ts +17 -0
  128. package/dist/esm/lib/loader/AppWorkerLoader.js +39 -0
  129. package/dist/esm/lib/loader/EggApplicationLoader.d.ts +4 -0
  130. package/dist/esm/lib/loader/EggApplicationLoader.js +4 -0
  131. package/dist/esm/lib/loader/index.d.ts +3 -0
  132. package/dist/esm/lib/loader/index.js +4 -0
  133. package/dist/esm/lib/start.d.ts +15 -0
  134. package/dist/esm/lib/start.js +43 -0
  135. package/dist/esm/lib/type.d.ts +296 -0
  136. package/dist/esm/lib/type.js +2 -0
  137. package/dist/esm/package.json +3 -0
  138. package/dist/package.json +4 -0
  139. package/package.json +87 -72
  140. package/src/agent.ts +7 -0
  141. package/{app/extend/context.js → src/app/extend/context.ts} +19 -23
  142. package/src/app/middleware/body_parser.ts +3 -0
  143. package/{app/middleware/meta.js → src/app/middleware/meta.ts} +12 -4
  144. package/{app/middleware/notfound.js → src/app/middleware/notfound.ts} +9 -3
  145. package/src/app/middleware/override_method.ts +3 -0
  146. package/src/app/middleware/site_file.ts +70 -0
  147. package/{config/config.default.js → src/config/config.default.ts} +24 -45
  148. package/src/config/config.local.ts +11 -0
  149. package/src/config/config.unittest.ts +10 -0
  150. package/src/config/favicon.png +0 -0
  151. package/{config/plugin.js → src/config/plugin.ts} +1 -3
  152. package/src/index.ts +78 -0
  153. package/src/lib/agent.ts +66 -0
  154. package/{lib/application.js → src/lib/application.ts} +79 -120
  155. package/src/lib/core/base_context_class.ts +21 -0
  156. package/src/lib/core/base_context_logger.ts +67 -0
  157. package/src/lib/core/base_hook_class.ts +30 -0
  158. package/src/lib/core/context_httpclient.ts +33 -0
  159. package/src/lib/core/httpclient.ts +52 -0
  160. package/src/lib/core/logger.ts +42 -0
  161. package/src/lib/core/messenger/IMessenger.ts +58 -0
  162. package/src/lib/core/messenger/index.ts +15 -0
  163. package/{lib/core/messenger/ipc.js → src/lib/core/messenger/ipc.ts} +24 -29
  164. package/{lib/core/messenger/local.js → src/lib/core/messenger/local.ts} +27 -21
  165. package/{lib/core/singleton.js → src/lib/core/singleton.ts} +56 -33
  166. package/src/lib/core/utils.ts +77 -0
  167. package/{lib/egg.js → src/lib/egg.ts} +262 -219
  168. package/src/lib/loader/AgentWorkerLoader.ts +21 -0
  169. package/src/lib/loader/AppWorkerLoader.ts +42 -0
  170. package/src/lib/loader/EggApplicationLoader.ts +5 -0
  171. package/src/lib/loader/index.ts +3 -0
  172. package/src/lib/start.ts +56 -0
  173. package/src/lib/type.ts +336 -0
  174. package/CHANGELOG.md +0 -2395
  175. package/History.md +0 -52
  176. package/agent.js +0 -11
  177. package/app/middleware/body_parser.js +0 -3
  178. package/app/middleware/override_method.js +0 -3
  179. package/app/middleware/site_file.js +0 -31
  180. package/config/config.local.js +0 -7
  181. package/config/config.unittest.js +0 -8
  182. package/index.d.ts +0 -1288
  183. package/index.js +0 -68
  184. package/lib/agent.js +0 -95
  185. package/lib/core/base_context_class.js +0 -20
  186. package/lib/core/base_context_logger.js +0 -64
  187. package/lib/core/base_hook_class.js +0 -31
  188. package/lib/core/context_httpclient.js +0 -26
  189. package/lib/core/dnscache_httpclient.js +0 -93
  190. package/lib/core/httpclient.js +0 -119
  191. package/lib/core/httpclient_next.js +0 -80
  192. package/lib/core/logger.js +0 -35
  193. package/lib/core/messenger/index.js +0 -14
  194. package/lib/core/utils.js +0 -73
  195. package/lib/loader/agent_worker_loader.js +0 -27
  196. package/lib/loader/app_worker_loader.js +0 -48
  197. package/lib/loader/index.js +0 -5
  198. package/lib/start.js +0 -39
  199. /package/{config → dist/commonjs/config}/favicon.png +0 -0
  200. /package/{app → src/app}/extend/helper.js +0 -0
  201. /package/{app → src/app}/extend/request.js +0 -0
  202. /package/{app → src/app}/extend/response.js +0 -0
package/index.d.ts DELETED
@@ -1,1288 +0,0 @@
1
- import accepts = require('accepts');
2
- import { AsyncLocalStorage } from 'async_hooks';
3
- import { EventEmitter } from 'events'
4
- import { Readable } from 'stream';
5
- import { Socket } from 'net';
6
- import { IncomingMessage, ServerResponse } from 'http';
7
- import KoaApplication = require('koa');
8
- import KoaRouter = require('koa-router');
9
- import {
10
- EggLogger as Logger,
11
- EggLoggers,
12
- LoggerLevel as EggLoggerLevel,
13
- EggLoggersOptions,
14
- EggLoggerOptions,
15
- EggContextLogger,
16
- } from 'egg-logger';
17
- import {
18
- RequestOptions2 as RequestOptionsOld,
19
- HttpClientResponse as HttpClientResponseOld,
20
- } from 'urllib';
21
- import {
22
- RequestURL as HttpClientRequestURL,
23
- RequestOptions as HttpClientRequestOptions,
24
- HttpClientResponse,
25
- } from 'urllib-next';
26
- import {
27
- EggCoreBase,
28
- FileLoaderOption,
29
- EggLoader as CoreLoader,
30
- EggCoreOptions as CoreOptions,
31
- EggLoaderOptions as CoreLoaderOptions,
32
- BaseContextClass as CoreBaseContextClass,
33
- } from 'egg-core';
34
- import EggCookies = require('egg-cookies');
35
- import 'egg-onerror';
36
- import 'egg-session';
37
- import 'egg-i18n';
38
- import 'egg-watcher';
39
- import 'egg-multipart';
40
- import 'egg-security';
41
- import 'egg-development';
42
- import 'egg-logrotator';
43
- import 'egg-schedule';
44
- import 'egg-static';
45
- import 'egg-jsonp';
46
- import 'egg-view';
47
-
48
- declare module 'egg' {
49
- export type EggLogger = Logger;
50
- // plain object
51
- type PlainObject<T = any> = { [key: string]: T };
52
-
53
- // Remove specific property from the specific class
54
- type RemoveSpecProp<T, P> = Pick<T, Exclude<keyof T, P>>;
55
-
56
- // Usage:
57
- // ```ts
58
- // import { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse } from 'egg';
59
- // async function request(url: HttpClientRequestURL, options: HttpClientRequestOptions): Promise<HttpClientResponse> {
60
- // return await app.httpclient.request(url, options);
61
- // }
62
- // ```
63
- export { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse };
64
- // Compatible with both urllib@2 and urllib@3 RequestOptions to request
65
- export interface EggHttpClient extends EventEmitter {
66
- request<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
67
- request<T = any>(url: HttpClientRequestURL, options: RequestOptionsOld | HttpClientRequestOptions):
68
- Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
69
- curl<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
70
- curl<T = any>(url: HttpClientRequestURL, options: RequestOptionsOld | HttpClientRequestOptions):
71
- Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
72
- safeCurl<T = any>(url: HttpClientRequestURL): Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
73
- safeCurl<T = any>(url: HttpClientRequestURL, options: RequestOptionsOld | HttpClientRequestOptions):
74
- Promise<HttpClientResponseOld<T> | HttpClientResponse<T>>;
75
- }
76
-
77
- interface EggHttpConstructor {
78
- new(app: Application): EggHttpClient;
79
- }
80
-
81
- export interface EggContextHttpClient extends EggHttpClient { }
82
- interface EggContextHttpClientConstructor {
83
- new(ctx: Context): EggContextHttpClient;
84
- }
85
-
86
- /**
87
- * BaseContextClass is a base class that can be extended,
88
- * it's instantiated in context level,
89
- * {@link Helper}, {@link Service} is extending it.
90
- */
91
- export class BaseContextClass extends CoreBaseContextClass<Context, Application, EggAppConfig, IService> { // tslint:disable-line
92
- /**
93
- * logger
94
- */
95
- protected logger: EggLogger;
96
- }
97
-
98
- export class Boot {
99
- /**
100
- * logger
101
- * @member {EggLogger}
102
- */
103
- protected logger: EggLogger;
104
-
105
- /**
106
- * The configuration of application
107
- * @member {EggAppConfig}
108
- */
109
- protected config: EggAppConfig;
110
-
111
- /**
112
- * The instance of agent
113
- * @member {Agent}
114
- */
115
- protected agent: Agent;
116
-
117
- /**
118
- * The instance of app
119
- * @member {Application}
120
- */
121
- protected app: Application;
122
- }
123
-
124
- export type RequestArrayBody = any[];
125
- export type RequestObjectBody = PlainObject;
126
- export interface Request extends KoaApplication.Request { // tslint:disable-line
127
- /**
128
- * detect if response should be json
129
- * 1. url path ends with `.json`
130
- * 2. response type is set to json
131
- * 3. detect by request accept header
132
- *
133
- * @member {Boolean} Request#acceptJSON
134
- * @since 1.0.0
135
- */
136
- acceptJSON: boolean;
137
-
138
- /**
139
- * Request remote IPv4 address
140
- * @member {String} Request#ip
141
- * @example
142
- * ```js
143
- * this.request.ip
144
- * => '127.0.0.1'
145
- * => '111.10.2.1'
146
- * ```
147
- */
148
- ip: string;
149
-
150
- /**
151
- * Get all pass through ip addresses from the request.
152
- * Enable only on `app.config.proxy = true`
153
- *
154
- * @member {Array} Request#ips
155
- * @example
156
- * ```js
157
- * this.request.ips
158
- * => ['100.23.1.2', '201.10.10.2']
159
- * ```
160
- */
161
- ips: string[];
162
-
163
- protocol: string;
164
-
165
- /**
166
- * get params pass by querystring, all value are Array type. {@link Request#query}
167
- * @member {Array} Request#queries
168
- * @example
169
- * ```js
170
- * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
171
- * this.queries
172
- * =>
173
- * {
174
- * "a": ["b", "c"],
175
- * "o[foo]": ["bar"],
176
- * "b[]": ["1", "2"],
177
- * "e": ["val"]
178
- * }
179
- * ```
180
- */
181
- queries: PlainObject<string[]>;
182
-
183
- /**
184
- * get params pass by querystring, all value are String type.
185
- * @member {Object} Request#query
186
- * @example
187
- * ```js
188
- * GET http://127.0.0.1:7001?name=Foo&age=20&age=21
189
- * this.query
190
- * => { 'name': 'Foo', 'age': 20 }
191
- *
192
- * GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
193
- * this.query
194
- * =>
195
- * {
196
- * "a": "b",
197
- * "o[foo]": "bar",
198
- * "b[]": "1",
199
- * "e": "val"
200
- * }
201
- * ```
202
- */
203
- query: PlainObject<string>;
204
-
205
- body: any;
206
- }
207
-
208
- export interface Response<ResponseBodyT = any> extends KoaApplication.Response { // tslint:disable-line
209
- /**
210
- * read response real status code.
211
- *
212
- * e.g.: Using 302 status redirect to the global error page
213
- * instead of show current 500 status page.
214
- * And access log should save 500 not 302,
215
- * then the `realStatus` can help us find out the real status code.
216
- * @member {Number} Context#realStatus
217
- */
218
- realStatus: number;
219
- body: ResponseBodyT;
220
- }
221
-
222
- export type LoggerLevel = EggLoggerLevel;
223
-
224
-
225
- /**
226
- * egg app info
227
- * @example
228
- * ```js
229
- * // config/config.default.ts
230
- * import { EggAppInfo } from 'egg';
231
- *
232
- * export default (appInfo: EggAppInfo) => {
233
- * return {
234
- * keys: appInfo.name + '123456',
235
- * };
236
- * }
237
- * ```
238
- */
239
- export interface EggAppInfo {
240
- pkg: any; // package.json
241
- name: string; // the application name from package.json
242
- baseDir: string; // current directory of application
243
- env: EggEnvType; // equals to serverEnv
244
- HOME: string; // home directory of the OS
245
- root: string; // baseDir when local and unittest, HOME when other environment
246
- }
247
-
248
- type IgnoreItem = string | RegExp | ((ctx: Context) => boolean);
249
- type IgnoreOrMatch = IgnoreItem | IgnoreItem[];
250
-
251
- /** logger config of egg */
252
- export interface EggLoggerConfig extends RemoveSpecProp<EggLoggersOptions, 'type'> {
253
- /** custom config of coreLogger */
254
- coreLogger?: Partial<EggLoggerOptions>;
255
- /** allow debug log at prod, defaults to `false` */
256
- allowDebugAtProd?: boolean;
257
- /** disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`. */
258
- disableConsoleAfterReady?: boolean;
259
- /** using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to `false`. e.g.: logger will set 1.456ms instead of 1ms. */
260
- enablePerformanceTimer?: boolean;
261
- /** using the app logger instead of EggContextLogger, defaults to `false` */
262
- enableFastContextLogger?: boolean;
263
- }
264
-
265
- /** Custom Loader Configuration */
266
- export interface CustomLoaderConfig extends RemoveSpecProp<FileLoaderOption, 'inject' | 'target'> {
267
- /**
268
- * an object you wanner load to, value can only be 'ctx' or 'app'. default to app
269
- */
270
- inject?: 'ctx' | 'app';
271
- /**
272
- * whether need to load files in plugins or framework, default to false
273
- */
274
- loadunit?: boolean;
275
- }
276
-
277
- export interface HttpClientBaseConfig {
278
- /** Whether use http keepalive */
279
- keepAlive?: boolean;
280
- /** Free socket after keepalive timeout */
281
- freeSocketKeepAliveTimeout?: number;
282
- /** Free socket after request timeout */
283
- freeSocketTimeout?: number;
284
- /** Request timeout */
285
- timeout?: number;
286
- /** Determines how many concurrent sockets the agent can have open per origin */
287
- maxSockets?: number;
288
- /** The maximum number of sockets that will be left open in the free state */
289
- maxFreeSockets?: number;
290
- }
291
-
292
- /** HttpClient config */
293
- export interface HttpClientConfig extends HttpClientBaseConfig {
294
- /** http.Agent */
295
- httpAgent?: HttpClientBaseConfig;
296
- /** https.Agent */
297
- httpsAgent?: HttpClientBaseConfig;
298
- /** Default request args for httpclient */
299
- request?: HttpClientRequestOptions | RequestOptionsOld;
300
- /** Whether enable dns cache */
301
- enableDNSCache?: boolean;
302
- /** Enable proxy request. Default is `false`. */
303
- enableProxy?: boolean;
304
- /** proxy agent uri or options. Default is `null`. */
305
- proxy?: string | { [key: string]: any };
306
- /** DNS cache lookup interval */
307
- dnsCacheLookupInterval?: number;
308
- /** DNS cache max age */
309
- dnsCacheMaxLength?: number;
310
- /** use urllib@3 HttpClient. Default is `false` */
311
- useHttpClientNext?: boolean;
312
- /** Allow to use HTTP2 first, only work on `useHttpClientNext = true`. Default is `false` */
313
- allowH2?: boolean;
314
- }
315
-
316
- export interface EggAppConfig {
317
- workerStartTimeout: number;
318
- baseDir: string;
319
- middleware: string[];
320
-
321
- /**
322
- * The option of `bodyParser` middleware
323
- *
324
- * @member Config#bodyParser
325
- * @property {Boolean} enable - enable bodyParser or not, default to true
326
- * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
327
- * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
328
- * @property {String} encoding - body encoding config, default utf8
329
- * @property {String} formLimit - form body size limit, default 1mb
330
- * @property {String} jsonLimit - json body size limit, default 1mb
331
- * @property {String} textLimit - json body size limit, default 1mb
332
- * @property {Boolean} strict - json body strict mode, if set strict value true, then only receive object and array json body
333
- * @property {Number} queryString.arrayLimit - from item array length limit, default 100
334
- * @property {Number} queryString.depth - json value deep length, default 5
335
- * @property {Number} queryString.parameterLimit - parameter number limit, default 1000
336
- * @property {String[]} enableTypes - parser will only parse when request type hits enableTypes, default is ['json', 'form']
337
- * @property {Object} extendTypes - support extend types
338
- * @property {String} onProtoPoisoning - Defines what action must take when parsing a JSON object with `__proto__`. Possible values are `'error'`, `'remove'` and `'ignore'`. Default is `'error'`, it will return `400` response when `Prototype-Poisoning` happen.
339
- */
340
- bodyParser: {
341
- enable: boolean;
342
- encoding: string;
343
- formLimit: string;
344
- jsonLimit: string;
345
- textLimit: string;
346
- strict: boolean;
347
- queryString: {
348
- arrayLimit: number;
349
- depth: number;
350
- parameterLimit: number;
351
- };
352
- ignore: IgnoreOrMatch;
353
- match: IgnoreOrMatch;
354
- enableTypes: string[];
355
- extendTypes: {
356
- json: string[];
357
- form: string[];
358
- text: string[];
359
- };
360
- /** Default is `'error'`, it will return `400` response when `Prototype-Poisoning` happen. */
361
- onProtoPoisoning: 'error' | 'remove' | 'ignore';
362
- };
363
-
364
- /**
365
- * logger options
366
- * @member Config#logger
367
- * @property {String} dir - directory of log files
368
- * @property {String} encoding - log file encloding, defaults to utf8
369
- * @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
370
- * @property {String} consoleLevel - log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise
371
- * @property {Boolean} disableConsoleAfterReady - disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`.
372
- * @property {Boolean} outputJSON - log as JSON or not, defaults to false
373
- * @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
374
- * @property {String} errorLogName - file name of errorLogger
375
- * @property {String} coreLogName - file name of coreLogger
376
- * @property {String} agentLogName - file name of agent worker log
377
- * @property {Object} coreLogger - custom config of coreLogger
378
- * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
379
- * @property {Boolean} enablePerformanceTimer - using performance.now() timer instead of Date.now() for more more precise milliseconds, defaults to false. e.g.: logger will set 1.456ms instead of 1ms.
380
- * @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to false
381
- */
382
- logger: EggLoggerConfig;
383
-
384
- /** custom logger of egg */
385
- customLogger: {
386
- [key: string]: EggLoggerOptions;
387
- };
388
-
389
- /** Configuration of httpclient in egg. */
390
- httpclient: HttpClientConfig;
391
-
392
- development: {
393
- /**
394
- * dirs needed watch, when files under these change, application will reload, use relative path
395
- */
396
- watchDirs: string[];
397
- /**
398
- * dirs don't need watch, including subdirectories, use relative path
399
- */
400
- ignoreDirs: string[];
401
- /**
402
- * don't wait all plugins ready, default is true.
403
- */
404
- fastReady: boolean;
405
- /**
406
- * whether reload on debug, default is true.
407
- */
408
- reloadOnDebug: boolean;
409
- /**
410
- * whether override default watchDirs, default is false.
411
- */
412
- overrideDefault: boolean;
413
- /**
414
- * whether override default ignoreDirs, default is false.
415
- */
416
- overrideIgnore: boolean;
417
- /**
418
- * whether to reload, use https://github.com/sindresorhus/multimatch
419
- */
420
- reloadPattern: string[] | string;
421
- };
422
-
423
- /**
424
- * customLoader config
425
- */
426
- customLoader: {
427
- [key: string]: CustomLoaderConfig;
428
- };
429
-
430
- /**
431
- * It will ignore special keys when dumpConfig
432
- */
433
- dump: {
434
- ignore: Set<string>;
435
- };
436
-
437
- /**
438
- * The environment of egg
439
- */
440
- env: EggEnvType;
441
-
442
- /**
443
- * The current HOME directory
444
- */
445
- HOME: string;
446
-
447
- hostHeaders: string;
448
-
449
- /**
450
- * I18n options
451
- */
452
- i18n: {
453
- /**
454
- * default value EN_US
455
- */
456
- defaultLocale: string;
457
- /**
458
- * i18n resource file dir, not recommend to change default value
459
- */
460
- dirs: string[];
461
- /**
462
- * custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang`
463
- */
464
- queryField: string;
465
- /**
466
- * The locale value key in the cookie, default is locale.
467
- */
468
- cookieField: string;
469
- /**
470
- * Locale cookie expire time, default `1y`, If pass number value, the unit will be ms
471
- */
472
- cookieMaxAge: string | number;
473
- };
474
-
475
- /**
476
- * Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.
477
- */
478
- ipHeaders: string;
479
-
480
- /**
481
- * jsonp options
482
- * @member Config#jsonp
483
- * @property {String} callback - jsonp callback method key, default to `_callback`
484
- * @property {Number} limit - callback method name's max length, default to `50`
485
- * @property {Boolean} csrf - enable csrf check or not. default to false
486
- * @property {String|RegExp|Array} whiteList - referrer white list
487
- */
488
- jsonp: {
489
- limit: number;
490
- callback: string;
491
- csrf: boolean;
492
- whiteList: string | RegExp | Array<string | RegExp>;
493
- };
494
-
495
- /**
496
- * The key that signing cookies. It can contain multiple keys seperated by .
497
- */
498
- keys: string;
499
-
500
- /**
501
- * The name of the application
502
- */
503
- name: string;
504
-
505
- /**
506
- * package.json
507
- */
508
- pkg: any;
509
-
510
- rundir: string;
511
-
512
- security: {
513
- domainWhiteList: string[];
514
- protocolWhiteList: string[];
515
- defaultMiddleware: string;
516
- csrf: any;
517
- ssrf: {
518
- ipBlackList: string[];
519
- ipExceptionList: string[];
520
- checkAddress?(ip: string): boolean;
521
- };
522
- xframe: {
523
- enable: boolean;
524
- value: 'SAMEORIGIN' | 'DENY' | string;
525
- };
526
- hsts: any;
527
- methodnoallow: { enable: boolean };
528
- noopen: { enable: boolean; }
529
- xssProtection: any;
530
- csp: any;
531
- };
532
-
533
- siteFile: PlainObject<string | Buffer>;
534
-
535
- watcher: PlainObject;
536
-
537
- onClientError(err: Error, socket: Socket, app: EggApplication): ClientErrorResponse | Promise<ClientErrorResponse>;
538
-
539
- /**
540
- * server timeout in milliseconds, default to 0 (no timeout).
541
- *
542
- * for special request, just use `ctx.req.setTimeout(ms)`
543
- *
544
- * @see https://nodejs.org/api/http.html#http_server_timeout
545
- */
546
- serverTimeout: number | null;
547
-
548
- [prop: string]: any;
549
- }
550
-
551
- export interface ClientErrorResponse {
552
- body: string | Buffer;
553
- status: number;
554
- headers: { [key: string]: string };
555
- }
556
-
557
- export interface Router extends Omit<KoaRouter<any, Context>, 'url'> {
558
- /**
559
- * restful router api
560
- */
561
- resources(name: string, prefix: string, ...middleware: any[]): Router;
562
-
563
- /**
564
- * @param {String} name - Router name
565
- * @param {Object} [params] - more parameters
566
- * @example
567
- * ```js
568
- * router.url('edit_post', { id: 1, name: 'foo', page: 2 })
569
- * => /posts/1/edit?name=foo&page=2
570
- * router.url('posts', { name: 'foo&1', page: 2 })
571
- * => /posts?name=foo%261&page=2
572
- * ```
573
- * @return {String} url by path name and query params.
574
- * @since 1.0.0
575
- */
576
- url(name: string, params?: any): string;
577
- /**
578
- * Alias for the url method
579
- */
580
- pathFor(name: string, params?: any): string;
581
- methods: string[];
582
- }
583
-
584
- export interface EggApplication extends Omit<EggCoreBase<EggAppConfig>, 'ctxStorage' | 'currentContext'> {
585
- /**
586
- * HttpClient instance
587
- */
588
- httpclient: EggHttpClient;
589
-
590
- /**
591
- * Logger for Application, wrapping app.coreLogger with context infomation
592
- *
593
- * @member {ContextLogger} Context#logger
594
- * @since 1.0.0
595
- * @example
596
- * ```js
597
- * this.logger.info('some request data: %j', this.request.body);
598
- * this.logger.warn('WARNING!!!!');
599
- * ```
600
- */
601
- logger: EggLogger;
602
-
603
- /**
604
- * core logger for framework and plugins, log file is $HOME/logs/{appname}/egg-web
605
- */
606
- coreLogger: EggLogger;
607
-
608
- /**
609
- * All loggers contain logger, coreLogger and customLogger
610
- */
611
- loggers: EggLoggers;
612
-
613
- /**
614
- * messenger instance
615
- */
616
- messenger: Messenger;
617
-
618
- /**
619
- * get router
620
- */
621
- router: Router;
622
-
623
- /**
624
- * create a singleton instance
625
- */
626
- addSingleton(name: string, create: any): void;
627
-
628
- runSchedule(schedulePath: string, ...args: any[]): Promise<any>;
629
-
630
- /**
631
- * http request helper base on httpclient, it will auto save httpclient log.
632
- * Keep the same api with httpclient.request(url, args).
633
- * See https://github.com/node-modules/urllib#api-doc for more details.
634
- */
635
- curl: EggHttpClient['request'];
636
-
637
- /**
638
- * Get logger by name, it's equal to app.loggers['name'], but you can extend it with your own logical
639
- */
640
- getLogger(name: string): EggLogger;
641
-
642
- /**
643
- * print the infomation when console.log(app)
644
- */
645
- inspect(): any;
646
-
647
- /**
648
- * Alias to Router#url
649
- */
650
- url(name: string, params: any): any;
651
-
652
- /**
653
- * Create an anonymous context, the context isn't request level, so the request is mocked.
654
- * then you can use context level API like `ctx.service`
655
- * @member {String} EggApplication#createAnonymousContext
656
- * @param {Request} req - if you want to mock request like querystring, you can pass an object to this function.
657
- * @return {Context} context
658
- */
659
- createAnonymousContext(req?: Request): Context;
660
-
661
- /**
662
- * export context base classes, let framework can impl sub class and over context extend easily.
663
- */
664
- ContextCookies: typeof EggCookies;
665
- ContextLogger: typeof EggContextLogger;
666
- ContextHttpClient: EggContextHttpClientConstructor;
667
- HttpClient: EggHttpConstructor;
668
- Subscription: typeof Subscription;
669
- Controller: typeof Controller;
670
- Service: typeof Service;
671
- }
672
-
673
- // compatible
674
- export class EggApplication {
675
- constructor(options?: CoreOptions);
676
- }
677
-
678
- export type RouterPath = string | RegExp;
679
-
680
- export class Application extends EggApplication {
681
- /**
682
- * global locals for view
683
- * @see Context#locals
684
- */
685
- locals: IApplicationLocals;
686
-
687
- /**
688
- * HTTP get method
689
- */
690
- get(path: RouterPath, fn: string): void;
691
- get(path: RouterPath, ...middleware: any[]): void;
692
-
693
- /**
694
- * HTTP post method
695
- */
696
- post(path: RouterPath, fn: string): void;
697
- post(path: RouterPath, ...middleware: any[]): void;
698
-
699
- /**
700
- * HTTP put method
701
- */
702
- put(path: RouterPath, fn: string): void;
703
- put(path: RouterPath, ...middleware: any[]): void;
704
-
705
- /**
706
- * HTTP patch method
707
- */
708
- patch(path: RouterPath, fn: string): void;
709
- patch(path: RouterPath, ...middleware: any[]): void;
710
-
711
- /**
712
- * HTTP delete method
713
- */
714
- delete(path: RouterPath, fn: string): void;
715
- delete(path: RouterPath, ...middleware: any[]): void;
716
-
717
- /**
718
- * restful router api
719
- */
720
- resources(name: string, prefix: string, fn: string): Router;
721
- resources(path: string, prefix: string, ...middleware: any[]): Router;
722
-
723
- redirect(path: string, redirectPath: string): void;
724
-
725
- controller: IController;
726
-
727
- middleware: KoaApplication.Middleware[] & IMiddleware;
728
-
729
- /**
730
- * Run async function in the background
731
- * @see Context#runInBackground
732
- * @param {Function} scope - the first args is an anonymous ctx
733
- */
734
- runInBackground(scope: (ctx: Context) => void): void;
735
-
736
- /**
737
- * Run async function in the anonymous context scope
738
- * @see Context#runInAnonymousContextScope
739
- * @param {Function} scope - the first args is an anonymous ctx, scope should be async function
740
- * @param {Request} req - if you want to mock request like querystring, you can pass an object to this function.
741
- */
742
- runInAnonymousContextScope<R>(scope: (ctx: Context) => Promise<R>, req?: Request): Promise<R>;
743
-
744
- /**
745
- * Get current execute ctx async local storage
746
- * @returns {AsyncLocalStorage} localStorage - store current execute Context
747
- */
748
- get ctxStorage(): AsyncLocalStorage<Context>;
749
-
750
- /**
751
- * Get current execute ctx, maybe undefined
752
- * @returns {Context} ctx - current execute Context
753
- */
754
- get currentContext(): Context;
755
- }
756
-
757
- export interface IApplicationLocals extends PlainObject { }
758
-
759
- export interface FileStream extends Readable { // tslint:disable-line
760
- fields: any;
761
-
762
- filename: string;
763
-
764
- fieldname: string;
765
-
766
- mime: string;
767
-
768
- mimeType: string;
769
-
770
- transferEncoding: string;
771
-
772
- encoding: string;
773
-
774
- truncated: boolean;
775
- }
776
-
777
- interface GetFileStreamOptions {
778
- requireFile?: boolean; // required file submit, default is true
779
- defCharset?: string;
780
- limits?: {
781
- fieldNameSize?: number;
782
- fieldSize?: number;
783
- fields?: number;
784
- fileSize?: number;
785
- files?: number;
786
- parts?: number;
787
- headerPairs?: number;
788
- };
789
- checkFile?(
790
- fieldname: string,
791
- file: any,
792
- filename: string,
793
- encoding: string,
794
- mimetype: string
795
- ): void | Error;
796
- }
797
-
798
- /**
799
- * KoaApplication's Context will carry the default 'cookie' property in
800
- * the egg's Context interface, which is wrong here because we have our own
801
- * special properties (e.g: encrypted). So we must remove this property and
802
- * create our own with the same name.
803
- * @see https://github.com/eggjs/egg/pull/2958
804
- *
805
- * However, the latest version of Koa has "[key: string]: any" on the
806
- * context, and there'll be a type error for "keyof koa.Context".
807
- * So we have to directly inherit from "KoaApplication.BaseContext" and
808
- * rewrite all the properties to be compatible with types in Koa.
809
- * @see https://github.com/eggjs/egg/pull/3329
810
- */
811
- export interface Context<ResponseBodyT = any> extends KoaApplication.BaseContext {
812
- [key: string]: any;
813
- body: ResponseBodyT;
814
-
815
- app: Application;
816
-
817
- // properties of koa.Context
818
- req: IncomingMessage;
819
- res: ServerResponse;
820
- originalUrl: string;
821
- respond?: boolean;
822
-
823
- service: IService;
824
-
825
- request: Request;
826
-
827
- response: Response<ResponseBodyT>;
828
-
829
- // The new 'cookies' instead of Koa's.
830
- cookies: EggCookies;
831
-
832
- helper: IHelper;
833
-
834
- /**
835
- * Resource Parameters
836
- * @example
837
- * ##### ctx.params.id {string}
838
- *
839
- * `GET /api/users/1` => `'1'`
840
- *
841
- * ##### ctx.params.ids {Array<String>}
842
- *
843
- * `GET /api/users/1,2,3` => `['1', '2', '3']`
844
- *
845
- * ##### ctx.params.fields {Array<String>}
846
- *
847
- * Expect request return data fields, for example
848
- * `GET /api/users/1?fields=name,title` => `['name', 'title']`.
849
- *
850
- * ##### ctx.params.data {Object}
851
- *
852
- * Tht request data object
853
- *
854
- * ##### ctx.params.page {Number}
855
- *
856
- * Page number, `GET /api/users?page=10` => `10`
857
- *
858
- * ##### ctx.params.per_page {Number}
859
- *
860
- * The number of every page, `GET /api/users?per_page=20` => `20`
861
- */
862
- params: any;
863
-
864
- /**
865
- * @see Request#query
866
- */
867
- query: PlainObject<string>;
868
-
869
- /**
870
- * @see Request#queries
871
- */
872
- queries: PlainObject<string[]>;
873
-
874
- /**
875
- * @see Request#accept
876
- */
877
- accept: accepts.Accepts;
878
-
879
- /**
880
- * @see Request#acceptJSON
881
- */
882
- acceptJSON: boolean;
883
-
884
- /**
885
- * @see Request#ip
886
- */
887
- ip: string;
888
-
889
- /**
890
- * @see Response#realStatus
891
- */
892
- realStatus: number;
893
-
894
- /**
895
- * Set the ctx.body.data value
896
- *
897
- * @member {Object} Context#data=
898
- * @example
899
- * ```js
900
- * ctx.data = {
901
- * id: 1,
902
- * name: 'fengmk2'
903
- * };
904
- * ```
905
- *
906
- * will get responce
907
- *
908
- * ```js
909
- * HTTP/1.1 200 OK
910
- *
911
- * {
912
- * "data": {
913
- * "id": 1,
914
- * "name": "fengmk2"
915
- * }
916
- * }
917
- * ```
918
- */
919
- data: any;
920
-
921
- /**
922
- * set ctx.body.meta value
923
- *
924
- * @example
925
- * ```js
926
- * ctx.meta = {
927
- * count: 100
928
- * };
929
- * ```
930
- * will get responce
931
- *
932
- * ```js
933
- * HTTP/1.1 200 OK
934
- *
935
- * {
936
- * "meta": {
937
- * "count": 100
938
- * }
939
- * }
940
- * ```
941
- */
942
- meta: any;
943
-
944
- /**
945
- * locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
946
- * which will be used as data when view is rendering.
947
- * 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`.
948
- *
949
- * when you set locals, only object is available
950
- *
951
- * ```js
952
- * this.locals = {
953
- * a: 1
954
- * };
955
- * this.locals = {
956
- * b: 1
957
- * };
958
- * this.locals.c = 1;
959
- * console.log(this.locals);
960
- * {
961
- * a: 1,
962
- * b: 1,
963
- * c: 1,
964
- * };
965
- * ```
966
- *
967
- * `ctx.locals` has cache, it only merges `app.locals` once in one request.
968
- *
969
- * @member {Object} Context#locals
970
- */
971
- locals: IApplicationLocals & IContextLocals;
972
-
973
- /**
974
- * alias to {@link locals}, compatible with koa that use this variable
975
- */
976
- state: any;
977
-
978
- /**
979
- * Logger for Application, wrapping app.coreLogger with context infomation
980
- *
981
- * @member {ContextLogger} Context#logger
982
- * @since 1.0.0
983
- * @example
984
- * ```js
985
- * this.logger.info('some request data: %j', this.request.body);
986
- * this.logger.warn('WARNING!!!!');
987
- * ```
988
- */
989
- logger: EggLogger;
990
-
991
- /**
992
- * Get logger by name, it's equal to app.loggers['name'], but you can extend it with your own logical
993
- */
994
- getLogger(name: string): EggLogger;
995
-
996
- /**
997
- * Request start time
998
- */
999
- starttime: number;
1000
-
1001
- /**
1002
- * Request start timer using `performance.now()`
1003
- */
1004
- performanceStarttime?: number;
1005
-
1006
- /**
1007
- * http request helper base on httpclient, it will auto save httpclient log.
1008
- * Keep the same api with httpclient.request(url, args).
1009
- * See https://github.com/node-modules/urllib#api-doc for more details.
1010
- */
1011
- curl: EggHttpClient['request'];
1012
-
1013
- __(key: string, ...values: string[]): string;
1014
- gettext(key: string, ...values: string[]): string;
1015
-
1016
- /**
1017
- * get upload file stream
1018
- * @example
1019
- * ```js
1020
- * const stream = await this.getFileStream();
1021
- * // get other fields
1022
- * console.log(stream.fields);
1023
- * ```
1024
- * @method Context#getFileStream
1025
- * @param {Object} options
1026
- * @return {ReadStream} stream
1027
- * @since 1.0.0
1028
- */
1029
- getFileStream(options?: GetFileStreamOptions): Promise<FileStream>;
1030
-
1031
- /**
1032
- * @see Responce.redirect
1033
- */
1034
- redirect(url: string, alt?: string): void;
1035
-
1036
- httpclient: EggContextHttpClient;
1037
- }
1038
-
1039
- export interface IContextLocals extends PlainObject { }
1040
-
1041
- export class Controller extends BaseContextClass { }
1042
-
1043
- export class Service extends BaseContextClass { }
1044
-
1045
- export class Subscription extends BaseContextClass { }
1046
-
1047
- /**
1048
- * The empty interface `IService` is a placeholder, for egg
1049
- * to auto injection service to ctx.service
1050
- *
1051
- * @example
1052
- *
1053
- * import { Service } from 'egg';
1054
- * class FooService extends Service {
1055
- * async bar() {}
1056
- * }
1057
- *
1058
- * declare module 'egg' {
1059
- * export interface IService {
1060
- * foo: FooService;
1061
- * }
1062
- * }
1063
- *
1064
- * Now I can get ctx.service.foo at controller and other service file.
1065
- */
1066
- export interface IService extends PlainObject { } // tslint:disable-line
1067
-
1068
- export interface IController extends PlainObject { } // tslint:disable-line
1069
-
1070
- export interface IMiddleware extends PlainObject { } // tslint:disable-line
1071
-
1072
- export interface IHelper extends PlainObject, BaseContextClass {
1073
- /**
1074
- * Generate URL path(without host) for route. Takes the route name and a map of named params.
1075
- * @method Helper#pathFor
1076
- * @param {String} name - Router Name
1077
- * @param {Object} params - Other params
1078
- *
1079
- * @example
1080
- * ```js
1081
- * app.get('home', '/index.htm', 'home.index');
1082
- * ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
1083
- * => /index.htm?by=recent&limit=20
1084
- * ```
1085
- * @return {String} url path(without host)
1086
- */
1087
- pathFor(name: string, params?: PlainObject): string;
1088
-
1089
- /**
1090
- * Generate full URL(with host) for route. Takes the route name and a map of named params.
1091
- * @method Helper#urlFor
1092
- * @param {String} name - Router name
1093
- * @param {Object} params - Other params
1094
- * @example
1095
- * ```js
1096
- * app.get('home', '/index.htm', 'home.index');
1097
- * ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
1098
- * => http://127.0.0.1:7001/index.htm?by=recent&limit=20
1099
- * ```
1100
- * @return {String} full url(with host)
1101
- */
1102
- urlFor(name: string, params?: PlainObject): string;
1103
- }
1104
-
1105
- // egg env type
1106
- export type EggEnvType = 'local' | 'unittest' | 'prod' | string;
1107
-
1108
- /**
1109
- * plugin config item interface
1110
- */
1111
- export interface IEggPluginItem {
1112
- env?: EggEnvType[];
1113
- path?: string;
1114
- package?: string;
1115
- enable?: boolean;
1116
- }
1117
-
1118
- export type EggPluginItem = IEggPluginItem | boolean;
1119
-
1120
- /**
1121
- * build-in plugin list
1122
- */
1123
- export interface EggPlugin {
1124
- [key: string]: EggPluginItem | undefined;
1125
- onerror?: EggPluginItem;
1126
- session?: EggPluginItem;
1127
- i18n?: EggPluginItem;
1128
- watcher?: EggPluginItem;
1129
- multipart?: EggPluginItem;
1130
- security?: EggPluginItem;
1131
- development?: EggPluginItem;
1132
- logrotator?: EggPluginItem;
1133
- schedule?: EggPluginItem;
1134
- static?: EggPluginItem;
1135
- jsonp?: EggPluginItem;
1136
- view?: EggPluginItem;
1137
- }
1138
-
1139
- /**
1140
- * Singleton instance in Agent Worker, extend {@link EggApplication}
1141
- */
1142
- export class Agent extends EggApplication {
1143
- }
1144
-
1145
- export interface ClusterOptions {
1146
- /** specify framework that can be absolute path or npm package */
1147
- framework?: string;
1148
- /** directory of application, default to `process.cwd()` */
1149
- baseDir?: string;
1150
- /** customized plugins, for unittest */
1151
- plugins?: object | null;
1152
- /** numbers of app workers, default to `os.cpus().length` */
1153
- workers?: number;
1154
- /** listening port, default to 7001(http) or 8443(https) */
1155
- port?: number;
1156
- /** https or not */
1157
- https?: boolean;
1158
- /** ssl key */
1159
- key?: string;
1160
- /** ssl cert */
1161
- cert?: string;
1162
- [prop: string]: any;
1163
- }
1164
-
1165
- export function startCluster(options: ClusterOptions, callback: (...args: any[]) => any): void;
1166
-
1167
- export interface StartOptions {
1168
- /** specify framework that can be absolute path or npm package */
1169
- framework?: string;
1170
- /** directory of application, default to `process.cwd()` */
1171
- baseDir?: string;
1172
- /** ignore single process mode warning */
1173
- ignoreWarning?: boolean;
1174
- }
1175
-
1176
- export function start(options?: StartOptions): Promise<Application>
1177
-
1178
- /**
1179
- * Powerful Partial, Support adding ? modifier to a mapped property in deep level
1180
- * @example
1181
- * import { PowerPartial, EggAppConfig } from 'egg';
1182
- *
1183
- * // { view: { defaultEngines: string } } => { view?: { defaultEngines?: string } }
1184
- * type EggConfig = PowerPartial<EggAppConfig>
1185
- */
1186
- export type PowerPartial<T> = {
1187
- [U in keyof T]?: T[U] extends object
1188
- ? PowerPartial<T[U]>
1189
- : T[U]
1190
- };
1191
-
1192
- // send data can be number|string|boolean|object but not Set|Map
1193
- export interface Messenger extends EventEmitter {
1194
- /**
1195
- * broadcast to all agent/app processes including itself
1196
- */
1197
- broadcast(action: string, data: any): void;
1198
-
1199
- /**
1200
- * send to agent from the app,
1201
- * send to an random app from the agent
1202
- */
1203
- sendRandom(action: string, data: any): void;
1204
-
1205
- /**
1206
- * send to specified process
1207
- */
1208
- sendTo(pid: number, action: string, data: any): void;
1209
-
1210
- /**
1211
- * send to agent from the app,
1212
- * send to itself from the agent
1213
- */
1214
- sendToAgent(action: string, data: any): void;
1215
-
1216
- /**
1217
- * send to all app including itself from the app,
1218
- * send to all app from the agent
1219
- */
1220
- sendToApp(action: string, data: any): void;
1221
- }
1222
-
1223
- // compatible
1224
- export interface EggLoaderOptions extends CoreLoaderOptions { }
1225
- export interface EggLoader extends CoreLoader { }
1226
-
1227
- /**
1228
- * App worker process Loader, will load plugins
1229
- * @see https://github.com/eggjs/egg-core
1230
- */
1231
- export class AppWorkerLoader extends CoreLoader {
1232
- loadConfig(): void;
1233
- load(): void;
1234
- }
1235
-
1236
- /**
1237
- * Agent worker process loader
1238
- * @see https://github.com/eggjs/egg-loader
1239
- */
1240
- export class AgentWorkerLoader extends CoreLoader {
1241
- loadConfig(): void;
1242
- load(): void;
1243
- }
1244
-
1245
- export interface IBoot {
1246
- /**
1247
- * Ready to call configDidLoad,
1248
- * Config, plugin files are referred,
1249
- * this is the last chance to modify the config.
1250
- */
1251
- configWillLoad?(): void;
1252
-
1253
- /**
1254
- * Config, plugin files have loaded
1255
- */
1256
- configDidLoad?(): void;
1257
-
1258
- /**
1259
- * All files have loaded, start plugin here
1260
- */
1261
- didLoad?(): Promise<void>;
1262
-
1263
- /**
1264
- * All plugins have started, can do some thing before app ready
1265
- */
1266
- willReady?(): Promise<void>;
1267
-
1268
- /**
1269
- * Worker is ready, can do some things,
1270
- * don't need to block the app boot
1271
- */
1272
- didReady?(): Promise<void>;
1273
-
1274
- /**
1275
- * Server is listening
1276
- */
1277
- serverDidReady?(): Promise<void>;
1278
-
1279
- /**
1280
- * Do some thing before app close
1281
- */
1282
- beforeClose?(): Promise<void>;
1283
- }
1284
-
1285
- export interface Singleton<T> {
1286
- get(id: string): T;
1287
- }
1288
- }