egg 3.26.0 → 4.0.0-beta.0

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