egg 4.1.0-beta.19 → 4.1.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgentWorkerLoader-DG_hAClt.d.ts +17 -0
- package/dist/AgentWorkerLoader-D_hceBRW.js +24 -0
- package/dist/AppWorkerLoader-CAtxJvGl.js +37 -0
- package/dist/AppWorkerLoader-CT875rYM.d.ts +22 -0
- package/dist/CookieLimitExceedError-CAW0HYJw.d.ts +8 -0
- package/dist/CookieLimitExceedError-DLGakbeu.js +15 -0
- package/dist/EggApplicationLoader-CMe1VQt1.js +7 -0
- package/dist/EggApplicationLoader-PnIvd5oV.d.ts +8 -0
- package/dist/IMessenger-C9g6ypSI.d.ts +54 -0
- package/dist/MessageUnhandledRejectionError-Lq5fWw24.d.ts +8 -0
- package/dist/MessageUnhandledRejectionError-oD_E1Ewl.js +15 -0
- package/dist/agent-BfFWeJj4.js +55 -0
- package/dist/agent.d.ts +11 -1
- package/dist/agent.js +1 -1
- package/dist/app/extend/context.d.ts +11 -182
- package/dist/app/extend/context.js +1 -242
- package/dist/app/extend/helper.d.ts +11 -41
- package/dist/app/extend/helper.js +3 -45
- package/dist/app/extend/request.d.ts +11 -135
- package/dist/app/extend/request.js +2 -224
- package/dist/app/extend/response.d.ts +1 -28
- package/dist/app/extend/response.js +1 -34
- package/dist/app/middleware/meta.d.ts +11 -10
- package/dist/app/middleware/notfound.d.ts +11 -10
- package/dist/app/middleware/site_file.d.ts +11 -12
- package/dist/application-DVwFQSa9.js +208 -0
- package/dist/base-KLVtlzUD.d.ts +12 -0
- package/dist/base_context_class-Xc1OZql9.js +19 -0
- package/dist/base_context_logger-CZU59PGA.js +58 -0
- package/dist/base_hook_class-D0Gu2p8r.js +26 -0
- package/dist/base_hook_class-R8A8gm1s.d.ts +1109 -0
- package/dist/config/config.default.d.ts +11 -2
- package/dist/config/config.default.js +26 -2
- package/dist/context-D1Wg7CXs.js +244 -0
- package/dist/context_httpclient-BpRMdJhf.js +29 -0
- package/dist/egg-DVo5e_lr.js +800 -0
- package/dist/error-BYo_LRnd.js +1 -0
- package/dist/helper-B3PKMPXq.js +47 -0
- package/dist/httpclient-C1QPc_R7.js +36 -0
- package/dist/index-CUPkUUOR.d.ts +1 -0
- package/dist/index-CkgLZdB4.d.ts +1 -0
- package/dist/index.d.ts +12 -20
- package/dist/index.js +26 -19
- package/dist/lib/agent.d.ts +11 -21
- package/dist/lib/agent.js +20 -54
- package/dist/lib/application.d.ts +11 -59
- package/dist/lib/application.js +21 -207
- package/dist/lib/core/base_context_class.d.ts +11 -22
- package/dist/lib/core/base_context_class.js +2 -17
- package/dist/lib/core/base_context_logger.d.ts +11 -39
- package/dist/lib/core/base_context_logger.js +1 -56
- package/dist/lib/core/base_hook_class.d.ts +11 -17
- package/dist/lib/core/base_hook_class.js +1 -24
- package/dist/lib/core/context_httpclient.d.ts +11 -21
- package/dist/lib/core/context_httpclient.js +1 -27
- package/dist/lib/core/httpclient.d.ts +12 -17
- package/dist/lib/core/httpclient.js +1 -34
- package/dist/lib/core/logger.d.ts +11 -1
- package/dist/lib/core/logger.js +1 -29
- package/dist/lib/core/messenger/IMessenger.d.ts +1 -53
- package/dist/lib/core/messenger/base.d.ts +12 -11
- package/dist/lib/core/messenger/base.js +15 -27
- package/dist/lib/core/messenger/index.d.ts +12 -11
- package/dist/lib/core/messenger/index.js +15 -11
- package/dist/lib/core/messenger/ipc.d.ts +12 -4
- package/dist/lib/core/messenger/ipc.js +15 -128
- package/dist/lib/core/messenger/local.d.ts +12 -4
- package/dist/lib/core/messenger/local.js +15 -124
- package/dist/lib/core/utils.js +1 -46
- package/dist/lib/egg.d.ts +12 -285
- package/dist/lib/egg.js +15 -518
- package/dist/lib/error/CookieLimitExceedError.d.ts +1 -7
- package/dist/lib/error/CookieLimitExceedError.js +1 -13
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +1 -7
- package/dist/lib/error/MessageUnhandledRejectionError.js +1 -13
- package/dist/lib/error/index.d.ts +3 -2
- package/dist/lib/error/index.js +3 -2
- package/dist/lib/loader/AgentWorkerLoader.d.ts +2 -16
- package/dist/lib/loader/AgentWorkerLoader.js +2 -22
- package/dist/lib/loader/AppWorkerLoader.d.ts +2 -21
- package/dist/lib/loader/AppWorkerLoader.js +2 -35
- package/dist/lib/loader/EggApplicationLoader.d.ts +1 -7
- package/dist/lib/loader/EggApplicationLoader.js +1 -5
- package/dist/lib/loader/index.d.ts +4 -3
- package/dist/lib/loader/index.js +4 -3
- package/dist/lib/start.d.ts +11 -27
- package/dist/lib/start.js +25 -34
- package/dist/lib/types.d.ts +12 -283
- package/dist/lib/types.js +2 -32
- package/dist/lib/types.plugin.d.ts +1 -12
- package/dist/lib/types.plugin.js +1 -12
- package/dist/lib/utils.js +1 -12
- package/dist/loader-3myZ-rpm.js +1 -0
- package/dist/logger-C4tIcO3S.js +31 -0
- package/dist/request-Cy_1DlaX.js +225 -0
- package/dist/response-CDeQ9Sx2.js +36 -0
- package/dist/response-DlNYDj00.d.ts +29 -0
- package/dist/src-BuOjXSrB.js +3 -0
- package/dist/start-4E84z796.js +35 -0
- package/dist/types-dKSyDnVp.js +32 -0
- package/dist/types.plugin-B2v0K0I8.js +14 -0
- package/dist/types.plugin-C3D5I7VD.d.ts +12 -0
- package/dist/utils-B1Rjsoi9.js +48 -0
- package/dist/utils-BDoYg6z6.js +14 -0
- package/package.json +22 -22
|
@@ -0,0 +1,1109 @@
|
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader-PnIvd5oV.js";
|
|
2
|
+
import { AppWorkerLoader } from "./AppWorkerLoader-CT875rYM.js";
|
|
3
|
+
import { AgentWorkerLoader } from "./AgentWorkerLoader-DG_hAClt.js";
|
|
4
|
+
import { Response as Response$1 } from "./response-DlNYDj00.js";
|
|
5
|
+
import { IMessenger } from "./IMessenger-C9g6ypSI.js";
|
|
6
|
+
import { BaseContextClass, Context, EggAppConfig, EggAppInfo, EggCore, EggCoreOptions, FileLoaderOptions, ILifecycleBoot, ILifecycleBoot as ILifecycleBoot$1, MiddlewareFunc, Next, Request, Router, Router as Router$1, Singleton, SingletonCreateMethod, SingletonOptions } from "@eggjs/core";
|
|
7
|
+
import http, { IncomingMessage, ServerResponse } from "node:http";
|
|
8
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
+
import * as egg_logger0 from "egg-logger";
|
|
10
|
+
import { EggContextLogger, EggLogger, EggLogger as EggLogger$1, EggLoggerOptions, EggLoggers, EggLoggersOptions, LoggerLevel } from "egg-logger";
|
|
11
|
+
import { Cookies } from "@eggjs/cookies";
|
|
12
|
+
import * as urllib0 from "urllib";
|
|
13
|
+
import { ClientOptions, ClientOptions as HttpClientOptions, HttpClient, HttpClientResponse, RequestOptions, RequestURL, RequestURL as HttpClientRequestURL } from "urllib";
|
|
14
|
+
import { Socket } from "node:net";
|
|
15
|
+
import { PartialDeep } from "type-fest";
|
|
16
|
+
import * as node_modules_urllib_dist_esm_Response_js0 from "node_modules/urllib/dist/esm/Response.js";
|
|
17
|
+
|
|
18
|
+
//#region src/lib/agent.d.ts
|
|
19
|
+
declare const EGG_LOADER$1: unique symbol;
|
|
20
|
+
/**
|
|
21
|
+
* Singleton instance in Agent Worker, extend {@link EggApplicationCore}
|
|
22
|
+
* @augments EggApplicationCore
|
|
23
|
+
*/
|
|
24
|
+
declare class Agent extends EggApplicationCore {
|
|
25
|
+
#private;
|
|
26
|
+
/**
|
|
27
|
+
* @class
|
|
28
|
+
* @param {Object} options - see {@link EggApplicationCore}
|
|
29
|
+
*/
|
|
30
|
+
constructor(options?: Omit<EggApplicationCoreOptions, 'type'>);
|
|
31
|
+
get [EGG_LOADER$1](): typeof AgentWorkerLoader;
|
|
32
|
+
_wrapMessenger(): void;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/app/extend/helper.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* The Helper class which can be used as utility function.
|
|
39
|
+
* We support developers to extend Helper through ${baseDir}/app/extend/helper.js ,
|
|
40
|
+
* then you can use all method on `ctx.helper` that is a instance of Helper.
|
|
41
|
+
*/
|
|
42
|
+
declare class Helper extends BaseContextClass$1 {
|
|
43
|
+
/**
|
|
44
|
+
* Generate URL path(without host) for route. Takes the route name and a map of named params.
|
|
45
|
+
* @function Helper#pathFor
|
|
46
|
+
* @param {String} name - Router Name
|
|
47
|
+
* @param {Object} params - Other params
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* app.get('home', '/index.htm', 'home.index');
|
|
52
|
+
* ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
|
|
53
|
+
* => /index.htm?by=recent&limit=20
|
|
54
|
+
* ```
|
|
55
|
+
* @return {String} url path(without host)
|
|
56
|
+
*/
|
|
57
|
+
pathFor(name: string, params: Record<string, any>): string;
|
|
58
|
+
/**
|
|
59
|
+
* Generate full URL(with host) for route. Takes the route name and a map of named params.
|
|
60
|
+
* @function Helper#urlFor
|
|
61
|
+
* @param {String} name - Router name
|
|
62
|
+
* @param {Object} params - Other params
|
|
63
|
+
* @example
|
|
64
|
+
* ```js
|
|
65
|
+
* app.get('home', '/index.htm', 'home.index');
|
|
66
|
+
* ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
|
|
67
|
+
* => http://127.0.0.1:7001/index.htm?by=recent&limit=20
|
|
68
|
+
* ```
|
|
69
|
+
* @return {String} full url(with host)
|
|
70
|
+
*/
|
|
71
|
+
urlFor(name: string, params: Record<string, any>): string;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/lib/application.d.ts
|
|
75
|
+
declare const EGG_LOADER: unique symbol;
|
|
76
|
+
/**
|
|
77
|
+
* Singleton instance in App Worker, extend {@link EggApplicationCore}
|
|
78
|
+
* @augments EggApplicationCore
|
|
79
|
+
*/
|
|
80
|
+
declare class Application extends EggApplicationCore {
|
|
81
|
+
#private;
|
|
82
|
+
server?: http.Server;
|
|
83
|
+
/**
|
|
84
|
+
* reference to {@link Helper}
|
|
85
|
+
* @member {Helper} Application#Helper
|
|
86
|
+
*/
|
|
87
|
+
Helper: typeof Helper;
|
|
88
|
+
/**
|
|
89
|
+
* @class
|
|
90
|
+
* @param {Object} options - see {@link EggApplicationCore}
|
|
91
|
+
*/
|
|
92
|
+
constructor(options?: Omit<EggApplicationCoreOptions, 'type'>);
|
|
93
|
+
protected load(): Promise<void>;
|
|
94
|
+
get [EGG_LOADER](): typeof AppWorkerLoader;
|
|
95
|
+
onClientError(err: any, socket: Socket): void;
|
|
96
|
+
onServer(server: http.Server): void;
|
|
97
|
+
/**
|
|
98
|
+
* global locals for view
|
|
99
|
+
* @member {Object} Application#locals
|
|
100
|
+
* @see Context#locals
|
|
101
|
+
*/
|
|
102
|
+
get locals(): Record<string, any>;
|
|
103
|
+
set locals(val: Record<string, any>);
|
|
104
|
+
/**
|
|
105
|
+
* save routers to `run/router.json`
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
dumpConfig(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Run async function in the background
|
|
111
|
+
* @see Context#runInBackground
|
|
112
|
+
* @param {Function} scope - the first args is an anonymous ctx
|
|
113
|
+
*/
|
|
114
|
+
runInBackground(scope: (ctx: Context$1) => Promise<void>, req?: unknown): void;
|
|
115
|
+
/**
|
|
116
|
+
* secret key for Application
|
|
117
|
+
* @member {String} Application#keys
|
|
118
|
+
*/
|
|
119
|
+
get keys(): string[];
|
|
120
|
+
/**
|
|
121
|
+
* @deprecated keep compatible with egg 3.x
|
|
122
|
+
*/
|
|
123
|
+
toAsyncFunction(fn: (...args: any[]) => any): (...args: any[]) => any;
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/lib/core/httpclient.d.ts
|
|
127
|
+
interface HttpClientRequestOptions extends RequestOptions {
|
|
128
|
+
ctx?: any;
|
|
129
|
+
tracer?: any;
|
|
130
|
+
}
|
|
131
|
+
declare class HttpClient$1 extends HttpClient {
|
|
132
|
+
#private;
|
|
133
|
+
constructor(app: EggApplicationCore, options?: ClientOptions);
|
|
134
|
+
request<T = any>(url: RequestURL, options?: HttpClientRequestOptions): Promise<urllib0.HttpClientResponse<T>>;
|
|
135
|
+
curl<T = any>(url: RequestURL, options?: HttpClientRequestOptions): Promise<urllib0.HttpClientResponse<T>>;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/app/extend/request.d.ts
|
|
139
|
+
declare class Request$1 extends Request {
|
|
140
|
+
app: Application;
|
|
141
|
+
ctx: Context$1;
|
|
142
|
+
response: Response$1;
|
|
143
|
+
/**
|
|
144
|
+
* Request body, parsed from koa-bodyparser or @eggjs/multipart
|
|
145
|
+
*/
|
|
146
|
+
body: any;
|
|
147
|
+
/**
|
|
148
|
+
* Parse the "Host" header field host
|
|
149
|
+
* and support X-Forwarded-Host when a
|
|
150
|
+
* proxy is enabled.
|
|
151
|
+
* @member {String} Request#host
|
|
152
|
+
* @example
|
|
153
|
+
* ip + port
|
|
154
|
+
* ```js
|
|
155
|
+
* this.request.host
|
|
156
|
+
* => '127.0.0.1:7001'
|
|
157
|
+
* ```
|
|
158
|
+
* or domain
|
|
159
|
+
* ```js
|
|
160
|
+
* this.request.host
|
|
161
|
+
* => 'demo.eggjs.org'
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
get host(): string;
|
|
165
|
+
/**
|
|
166
|
+
* @member {String} Request#protocol
|
|
167
|
+
* @example
|
|
168
|
+
* ```js
|
|
169
|
+
* this.request.protocol
|
|
170
|
+
* => 'https'
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
get protocol(): string;
|
|
174
|
+
/**
|
|
175
|
+
* Get all pass through ip addresses from the request.
|
|
176
|
+
* Enable only on `app.config.proxy = true`
|
|
177
|
+
*
|
|
178
|
+
* @member {Array} Request#ips
|
|
179
|
+
* @example
|
|
180
|
+
* ```js
|
|
181
|
+
* this.request.ips
|
|
182
|
+
* => ['100.23.1.2', '201.10.10.2']
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
get ips(): string[];
|
|
186
|
+
/**
|
|
187
|
+
* Get the request remote IPv4 address
|
|
188
|
+
* @member {String} Request#ip
|
|
189
|
+
* @return {String} IPv4 address
|
|
190
|
+
* @example
|
|
191
|
+
* ```js
|
|
192
|
+
* this.request.ip
|
|
193
|
+
* => '127.0.0.1'
|
|
194
|
+
* => '111.10.2.1'
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
get ip(): string;
|
|
198
|
+
/**
|
|
199
|
+
* Set the request remote IPv4 address
|
|
200
|
+
* @member {String} Request#ip
|
|
201
|
+
* @param {String} ip - IPv4 address
|
|
202
|
+
* @example
|
|
203
|
+
* ```js
|
|
204
|
+
* this.request.ip
|
|
205
|
+
* => '127.0.0.1'
|
|
206
|
+
* => '111.10.2.1'
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
set ip(ip: string);
|
|
210
|
+
/**
|
|
211
|
+
* detect if response should be json
|
|
212
|
+
* 1. url path ends with `.json`
|
|
213
|
+
* 2. response type is set to json
|
|
214
|
+
* 3. detect by request accept header
|
|
215
|
+
*
|
|
216
|
+
* @member {Boolean} Request#acceptJSON
|
|
217
|
+
* @since 1.0.0
|
|
218
|
+
*/
|
|
219
|
+
get acceptJSON(): boolean;
|
|
220
|
+
_customQuery(cacheName: symbol, filter: (value: string | string[]) => string | string[]): Record<string, string | string[]>;
|
|
221
|
+
/**
|
|
222
|
+
* get params pass by querystring, all values are of string type.
|
|
223
|
+
* @member {Object} Request#query
|
|
224
|
+
* @example
|
|
225
|
+
* ```js
|
|
226
|
+
* GET http://127.0.0.1:7001?name=Foo&age=20&age=21
|
|
227
|
+
* this.query
|
|
228
|
+
* => { 'name': 'Foo', 'age': '20' }
|
|
229
|
+
*
|
|
230
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
231
|
+
* this.query
|
|
232
|
+
* =>
|
|
233
|
+
* {
|
|
234
|
+
* "a": "b",
|
|
235
|
+
* "o[foo]": "bar",
|
|
236
|
+
* "b[]": "1",
|
|
237
|
+
* "e": "val"
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
get query(): Record<string, string>;
|
|
242
|
+
/**
|
|
243
|
+
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
244
|
+
* @member {Array} Request#queries
|
|
245
|
+
* @example
|
|
246
|
+
* ```js
|
|
247
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
248
|
+
* this.queries
|
|
249
|
+
* =>
|
|
250
|
+
* {
|
|
251
|
+
* "a": ["b", "c"],
|
|
252
|
+
* "o[foo]": ["bar"],
|
|
253
|
+
* "b[]": ["1", "2"],
|
|
254
|
+
* "e": ["val"]
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
get queries(): Record<string, string[]>;
|
|
259
|
+
/**
|
|
260
|
+
* Set query-string as an object.
|
|
261
|
+
*
|
|
262
|
+
* @function Request#query
|
|
263
|
+
* @param {Object} obj set querystring and query object for request.
|
|
264
|
+
*/
|
|
265
|
+
set query(obj: Record<string, string>);
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
//#region src/app/extend/context.d.ts
|
|
269
|
+
interface Cookies$1 extends Cookies {
|
|
270
|
+
request: any;
|
|
271
|
+
response: any;
|
|
272
|
+
}
|
|
273
|
+
declare class Context$1 extends Context {
|
|
274
|
+
app: Application;
|
|
275
|
+
request: Request$1;
|
|
276
|
+
response: Response$1;
|
|
277
|
+
service: BaseContextClass$1;
|
|
278
|
+
proxy: any;
|
|
279
|
+
/**
|
|
280
|
+
* Request start time
|
|
281
|
+
* @member {Number} Context#starttime
|
|
282
|
+
*/
|
|
283
|
+
starttime: number;
|
|
284
|
+
/**
|
|
285
|
+
* Request start timer using `performance.now()`
|
|
286
|
+
* @member {Number} Context#performanceStarttime
|
|
287
|
+
*/
|
|
288
|
+
performanceStarttime: number;
|
|
289
|
+
/**
|
|
290
|
+
* Get the current visitor's cookies.
|
|
291
|
+
*/
|
|
292
|
+
get cookies(): Cookies$1;
|
|
293
|
+
/**
|
|
294
|
+
* Get a wrapper httpclient instance contain ctx in the hold request process
|
|
295
|
+
*
|
|
296
|
+
* @return {HttpClient} the wrapper httpclient instance
|
|
297
|
+
*/
|
|
298
|
+
get httpclient(): HttpClient$1;
|
|
299
|
+
/**
|
|
300
|
+
* Alias to {@link Context#httpclient}
|
|
301
|
+
*/
|
|
302
|
+
get httpClient(): HttpClient$1;
|
|
303
|
+
/**
|
|
304
|
+
* Shortcut for httpclient.curl
|
|
305
|
+
*
|
|
306
|
+
* @function Context#curl
|
|
307
|
+
* @param {String|Object} url - request url address.
|
|
308
|
+
* @param {Object} [options] - options for request.
|
|
309
|
+
* @return {Object} see {@link ContextHttpClient#curl}
|
|
310
|
+
*/
|
|
311
|
+
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient$1['request']>;
|
|
312
|
+
/**
|
|
313
|
+
* Alias to {@link Application#router}
|
|
314
|
+
*
|
|
315
|
+
* @member {Router} Context#router
|
|
316
|
+
* @since 1.0.0
|
|
317
|
+
* @example
|
|
318
|
+
* ```js
|
|
319
|
+
* this.router.pathFor('post', { id: 12 });
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
get router(): Router;
|
|
323
|
+
/**
|
|
324
|
+
* Set router to Context, only use on EggRouter
|
|
325
|
+
* @param {Router} val router instance
|
|
326
|
+
*/
|
|
327
|
+
set router(val: Router);
|
|
328
|
+
/**
|
|
329
|
+
* Get helper instance from {@link Application#Helper}
|
|
330
|
+
*
|
|
331
|
+
* @member {Helper} Context#helper
|
|
332
|
+
* @since 1.0.0
|
|
333
|
+
*/
|
|
334
|
+
get helper(): Helper;
|
|
335
|
+
/**
|
|
336
|
+
* Wrap app.loggers with context information,
|
|
337
|
+
* if a custom logger is defined by naming aLogger, then you can `ctx.getLogger('aLogger')`
|
|
338
|
+
*
|
|
339
|
+
* @param {String} name - logger name
|
|
340
|
+
*/
|
|
341
|
+
getLogger(name: string): EggLogger;
|
|
342
|
+
/**
|
|
343
|
+
* Logger for Application
|
|
344
|
+
*
|
|
345
|
+
* @member {Logger} Context#logger
|
|
346
|
+
* @since 1.0.0
|
|
347
|
+
* @example
|
|
348
|
+
* ```js
|
|
349
|
+
* this.logger.info('some request data: %j', this.request.body);
|
|
350
|
+
* this.logger.warn('WARNING!!!!');
|
|
351
|
+
* ```
|
|
352
|
+
*/
|
|
353
|
+
get logger(): EggLogger;
|
|
354
|
+
/**
|
|
355
|
+
* Logger for frameworks and plugins
|
|
356
|
+
*
|
|
357
|
+
* @member {Logger} Context#coreLogger
|
|
358
|
+
* @since 1.0.0
|
|
359
|
+
*/
|
|
360
|
+
get coreLogger(): EggLogger;
|
|
361
|
+
/**
|
|
362
|
+
* locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
|
|
363
|
+
* which will be used as data when view is rendering.
|
|
364
|
+
* 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`.
|
|
365
|
+
*
|
|
366
|
+
* when you set locals, only object is available
|
|
367
|
+
*
|
|
368
|
+
* ```js
|
|
369
|
+
* this.locals = {
|
|
370
|
+
* a: 1
|
|
371
|
+
* };
|
|
372
|
+
* this.locals = {
|
|
373
|
+
* b: 1
|
|
374
|
+
* };
|
|
375
|
+
* this.locals.c = 1;
|
|
376
|
+
* console.log(this.locals);
|
|
377
|
+
* {
|
|
378
|
+
* a: 1,
|
|
379
|
+
* b: 1,
|
|
380
|
+
* c: 1,
|
|
381
|
+
* };
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* `ctx.locals` has cache, it only merges `app.locals` once in one request.
|
|
385
|
+
*
|
|
386
|
+
* @member {Object} Context#locals
|
|
387
|
+
*/
|
|
388
|
+
get locals(): Record<string, any>;
|
|
389
|
+
set locals(val: Record<string, any>);
|
|
390
|
+
/**
|
|
391
|
+
* alias to {@link Context#locals}, compatible with koa that use this variable
|
|
392
|
+
* @member {Object} state
|
|
393
|
+
* @see Context#locals
|
|
394
|
+
*/
|
|
395
|
+
get state(): Record<string, any>;
|
|
396
|
+
set state(val: Record<string, any>);
|
|
397
|
+
/**
|
|
398
|
+
* Run async function in the background
|
|
399
|
+
* @param {Function} scope - the first args is ctx
|
|
400
|
+
* ```js
|
|
401
|
+
* this.body = 'hi';
|
|
402
|
+
*
|
|
403
|
+
* this.runInBackground(async ctx => {
|
|
404
|
+
* await ctx.mysql.query(sql);
|
|
405
|
+
* await ctx.curl(url);
|
|
406
|
+
* });
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
runInBackground(scope: (ctx: Context$1) => Promise<void>, taskName?: string): void;
|
|
410
|
+
_runInBackground(scope: (ctx: Context$1) => Promise<void>, taskName: string): Promise<void>;
|
|
411
|
+
/**
|
|
412
|
+
* @member {Boolean} Context#acceptJSON
|
|
413
|
+
* @see Request#acceptJSON
|
|
414
|
+
* @since 1.0.0
|
|
415
|
+
*/
|
|
416
|
+
get acceptJSON(): boolean;
|
|
417
|
+
get query(): Record<string, string>;
|
|
418
|
+
/**
|
|
419
|
+
* @member {Array} Context#queries
|
|
420
|
+
* @see Request#queries
|
|
421
|
+
* @since 1.0.0
|
|
422
|
+
*/
|
|
423
|
+
get queries(): Record<string, string[]>;
|
|
424
|
+
/**
|
|
425
|
+
* @member {string} Context#ip
|
|
426
|
+
* @see Request#ip
|
|
427
|
+
* @since 1.0.0
|
|
428
|
+
*/
|
|
429
|
+
get ip(): string;
|
|
430
|
+
set ip(val: string);
|
|
431
|
+
/**
|
|
432
|
+
* @member {Number} Context#realStatus
|
|
433
|
+
* @see Response#realStatus
|
|
434
|
+
* @since 1.0.0
|
|
435
|
+
*/
|
|
436
|
+
get realStatus(): number;
|
|
437
|
+
set realStatus(val: number);
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/app/middleware/meta.d.ts
|
|
441
|
+
interface MetaMiddlewareOptions {
|
|
442
|
+
enable: boolean;
|
|
443
|
+
logging: boolean;
|
|
444
|
+
}
|
|
445
|
+
declare const _default$2: (options: MetaMiddlewareOptions) => (ctx: Context$1, next: Next) => Promise<void>;
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region src/app/middleware/notfound.d.ts
|
|
448
|
+
interface NotFoundMiddlewareOptions {
|
|
449
|
+
enable: boolean;
|
|
450
|
+
pageUrl: string;
|
|
451
|
+
}
|
|
452
|
+
declare const _default$1: (options: NotFoundMiddlewareOptions) => (ctx: Context$1, next: Next) => Promise<void>;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/app/middleware/site_file.d.ts
|
|
455
|
+
type SiteFileContentFun = (ctx: Context$1) => Promise<Buffer | string>;
|
|
456
|
+
interface SiteFileMiddlewareOptions {
|
|
457
|
+
enable: boolean;
|
|
458
|
+
cacheControl: string;
|
|
459
|
+
[key: string]: string | Buffer | boolean | SiteFileContentFun | URL;
|
|
460
|
+
}
|
|
461
|
+
declare const _default: (options: SiteFileMiddlewareOptions) => (ctx: Context$1, next: Next) => Promise<void>;
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/lib/types.d.ts
|
|
464
|
+
type IgnoreItem = string | RegExp | ((ctx: Context$1) => boolean);
|
|
465
|
+
type IgnoreOrMatch = IgnoreItem | IgnoreItem[];
|
|
466
|
+
interface ClientErrorResponse {
|
|
467
|
+
body: string | Buffer;
|
|
468
|
+
status: number;
|
|
469
|
+
headers: {
|
|
470
|
+
[key: string]: string;
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/** egg env type */
|
|
474
|
+
type EggEnvType = 'local' | 'unittest' | 'prod' | string;
|
|
475
|
+
/** logger config of egg */
|
|
476
|
+
interface EggLoggerConfig extends Omit<EggLoggersOptions, 'type'> {
|
|
477
|
+
/** custom config of coreLogger */
|
|
478
|
+
coreLogger?: Partial<EggLoggerOptions>;
|
|
479
|
+
/** allow debug log at prod, defaults to `false` */
|
|
480
|
+
allowDebugAtProd?: boolean;
|
|
481
|
+
/** disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`. */
|
|
482
|
+
disableConsoleAfterReady?: boolean;
|
|
483
|
+
/** [deprecated] Defaults to `true`. */
|
|
484
|
+
enablePerformanceTimer?: boolean;
|
|
485
|
+
/** using the app logger instead of EggContextLogger, defaults to `false` */
|
|
486
|
+
enableFastContextLogger?: boolean;
|
|
487
|
+
}
|
|
488
|
+
/** Custom Loader Configuration */
|
|
489
|
+
interface CustomLoaderConfig extends Omit<FileLoaderOptions, 'inject' | 'target'> {
|
|
490
|
+
/**
|
|
491
|
+
* an object you wanner load to, value can only be 'ctx' or 'app'. default to app
|
|
492
|
+
*/
|
|
493
|
+
inject?: 'ctx' | 'app';
|
|
494
|
+
/**
|
|
495
|
+
* whether need to load files in plugins or framework, default to false
|
|
496
|
+
*/
|
|
497
|
+
loadunit?: boolean;
|
|
498
|
+
}
|
|
499
|
+
interface HttpClientConfig {
|
|
500
|
+
/** Request timeout */
|
|
501
|
+
timeout?: number;
|
|
502
|
+
/** Default request args for httpclient */
|
|
503
|
+
request?: RequestOptions;
|
|
504
|
+
/**
|
|
505
|
+
* @deprecated keep compatible with egg 3.x, no more used
|
|
506
|
+
*/
|
|
507
|
+
useHttpClientNext?: boolean;
|
|
508
|
+
/**
|
|
509
|
+
* Allow http2
|
|
510
|
+
*/
|
|
511
|
+
allowH2?: boolean;
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Powerful Partial, Support adding ? modifier to a mapped property in deep level
|
|
515
|
+
* @example
|
|
516
|
+
* import { PowerPartial, EggAppConfig } from 'egg';
|
|
517
|
+
*
|
|
518
|
+
* // { view: { defaultEngines: string } } => { view?: { defaultEngines?: string } }
|
|
519
|
+
* type EggConfig = PowerPartial<EggAppConfig>
|
|
520
|
+
*
|
|
521
|
+
* @deprecated use `PartialDeep` instead
|
|
522
|
+
*/
|
|
523
|
+
type PowerPartial<T> = PartialDeep<T>;
|
|
524
|
+
/**
|
|
525
|
+
* Partial EggAppConfig
|
|
526
|
+
*/
|
|
527
|
+
type PartialEggConfig = PartialDeep<EggAppConfig$1>;
|
|
528
|
+
/**
|
|
529
|
+
* Configuration factory function return type
|
|
530
|
+
*/
|
|
531
|
+
type EggConfigFactory = (appInfo: EggAppInfo) => PartialEggConfig;
|
|
532
|
+
/**
|
|
533
|
+
* Define configuration with type safety
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* import { defineConfig } from 'egg';
|
|
537
|
+
*
|
|
538
|
+
* export default defineConfig({
|
|
539
|
+
* keys: 'my-keys',
|
|
540
|
+
* middleware: []
|
|
541
|
+
* });
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
declare function defineConfig(config: PartialEggConfig): PartialEggConfig;
|
|
545
|
+
/**
|
|
546
|
+
* Define configuration factory function with type safety
|
|
547
|
+
* @example
|
|
548
|
+
* ```ts
|
|
549
|
+
* export default defineConfigFactory((appInfo): PartialEggConfig => ({
|
|
550
|
+
* keys: appInfo.name + '_keys',
|
|
551
|
+
* middleware: []
|
|
552
|
+
* }));
|
|
553
|
+
* ```
|
|
554
|
+
*/
|
|
555
|
+
declare function defineConfigFactory(configFactory: EggConfigFactory): EggConfigFactory;
|
|
556
|
+
interface EggAppConfig$1 extends EggAppConfig {
|
|
557
|
+
workerStartTimeout: number;
|
|
558
|
+
baseDir: string;
|
|
559
|
+
middleware: string[];
|
|
560
|
+
coreMiddleware: string[];
|
|
561
|
+
/**
|
|
562
|
+
* The option of `bodyParser` middleware
|
|
563
|
+
*
|
|
564
|
+
* @member Config#bodyParser
|
|
565
|
+
* @property {Boolean} enable - enable bodyParser or not, default to true
|
|
566
|
+
* @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
|
|
567
|
+
* @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
|
|
568
|
+
* @property {String} encoding - body encoding config, default utf8
|
|
569
|
+
* @property {String} formLimit - form body size limit, default 1mb
|
|
570
|
+
* @property {String} jsonLimit - json body size limit, default 1mb
|
|
571
|
+
* @property {String} textLimit - json body size limit, default 1mb
|
|
572
|
+
* @property {Boolean} strict - json body strict mode, if set strict value true, then only receive object and array json body
|
|
573
|
+
* @property {Number} queryString.arrayLimit - from item array length limit, default 100
|
|
574
|
+
* @property {Number} queryString.depth - json value deep length, default 5
|
|
575
|
+
* @property {Number} queryString.parameterLimit - parameter number limit, default 1000
|
|
576
|
+
* @property {String[]} enableTypes - parser will only parse when request type hits enableTypes, default is ['json', 'form']
|
|
577
|
+
* @property {Object} extendTypes - support extend types
|
|
578
|
+
* @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.
|
|
579
|
+
*/
|
|
580
|
+
bodyParser: {
|
|
581
|
+
enable: boolean;
|
|
582
|
+
encoding: string;
|
|
583
|
+
formLimit: string;
|
|
584
|
+
jsonLimit: string;
|
|
585
|
+
textLimit: string;
|
|
586
|
+
strict: boolean;
|
|
587
|
+
queryString: {
|
|
588
|
+
arrayLimit: number;
|
|
589
|
+
depth: number;
|
|
590
|
+
parameterLimit: number;
|
|
591
|
+
};
|
|
592
|
+
ignore?: IgnoreOrMatch;
|
|
593
|
+
match?: IgnoreOrMatch;
|
|
594
|
+
enableTypes?: string[];
|
|
595
|
+
extendTypes?: {
|
|
596
|
+
json: string[];
|
|
597
|
+
form: string[];
|
|
598
|
+
text: string[];
|
|
599
|
+
};
|
|
600
|
+
/** Default is `'error'`, it will return `400` response when `Prototype-Poisoning` happen. */
|
|
601
|
+
onProtoPoisoning: 'error' | 'remove' | 'ignore';
|
|
602
|
+
onerror(err: any, ctx: Context$1): void;
|
|
603
|
+
};
|
|
604
|
+
/**
|
|
605
|
+
* logger options
|
|
606
|
+
* @member Config#logger
|
|
607
|
+
* @property {String} dir - directory of log files
|
|
608
|
+
* @property {String} encoding - log file encoding, defaults to utf8
|
|
609
|
+
* @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
|
|
610
|
+
* @property {String} consoleLevel - log level of stdout, defaults to `INFO` in local serverEnv, defaults to `WARN` in unittest, others is `NONE`
|
|
611
|
+
* @property {Boolean} disableConsoleAfterReady - disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`.
|
|
612
|
+
* @property {Boolean} outputJSON - log as JSON or not, defaults to `false`
|
|
613
|
+
* @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
|
|
614
|
+
* @property {String} errorLogName - file name of errorLogger
|
|
615
|
+
* @property {String} coreLogName - file name of coreLogger
|
|
616
|
+
* @property {String} agentLogName - file name of agent worker log
|
|
617
|
+
* @property {Object} coreLogger - custom config of coreLogger
|
|
618
|
+
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
|
|
619
|
+
* @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to false
|
|
620
|
+
*/
|
|
621
|
+
logger: EggLoggerConfig;
|
|
622
|
+
/** custom logger of egg */
|
|
623
|
+
customLogger: {
|
|
624
|
+
[key: string]: EggLoggerOptions;
|
|
625
|
+
};
|
|
626
|
+
/** Configuration of httpclient in egg. */
|
|
627
|
+
httpclient: HttpClientConfig;
|
|
628
|
+
/**
|
|
629
|
+
* customLoader config
|
|
630
|
+
*/
|
|
631
|
+
/**
|
|
632
|
+
* It will ignore special keys when dumpConfig
|
|
633
|
+
*/
|
|
634
|
+
dump: {
|
|
635
|
+
ignore: Set<string | RegExp>;
|
|
636
|
+
timing: {
|
|
637
|
+
slowBootActionMinDuration: number;
|
|
638
|
+
};
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* The environment of egg
|
|
642
|
+
*/
|
|
643
|
+
env: EggEnvType;
|
|
644
|
+
/**
|
|
645
|
+
* The current HOME directory
|
|
646
|
+
*/
|
|
647
|
+
HOME: string;
|
|
648
|
+
hostHeaders: string;
|
|
649
|
+
/**
|
|
650
|
+
* Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.
|
|
651
|
+
*/
|
|
652
|
+
ipHeaders: string;
|
|
653
|
+
protocolHeaders: string;
|
|
654
|
+
maxProxyCount: number;
|
|
655
|
+
maxIpsCount: number;
|
|
656
|
+
proxy: boolean;
|
|
657
|
+
cookies: {
|
|
658
|
+
sameSite?: string;
|
|
659
|
+
httpOnly?: boolean;
|
|
660
|
+
};
|
|
661
|
+
/**
|
|
662
|
+
* The key that signing cookies. It can contain multiple keys separated by `.`
|
|
663
|
+
* @requires Cookie secret key to sign and encrypt, see https://eggjs.org/core/cookie-and-session#cookie-secret-key
|
|
664
|
+
*/
|
|
665
|
+
keys: string;
|
|
666
|
+
/**
|
|
667
|
+
* The name of the application
|
|
668
|
+
*/
|
|
669
|
+
name: string;
|
|
670
|
+
/**
|
|
671
|
+
* package.json
|
|
672
|
+
*/
|
|
673
|
+
pkg: Record<string, any>;
|
|
674
|
+
rundir: string;
|
|
675
|
+
siteFile: SiteFileMiddlewareOptions;
|
|
676
|
+
meta: MetaMiddlewareOptions;
|
|
677
|
+
notfound: NotFoundMiddlewareOptions;
|
|
678
|
+
overrideMethod: {
|
|
679
|
+
enable: boolean;
|
|
680
|
+
allowedMethods: string[];
|
|
681
|
+
};
|
|
682
|
+
onClientError?(err: Error, socket: Socket, app: Application): ClientErrorResponse | Promise<ClientErrorResponse>;
|
|
683
|
+
/**
|
|
684
|
+
* server timeout in milliseconds, default to 0 (no timeout).
|
|
685
|
+
*
|
|
686
|
+
* for special request, just use `ctx.req.setTimeout(ms)`
|
|
687
|
+
*
|
|
688
|
+
* @see https://nodejs.org/api/http.html#http_server_timeout
|
|
689
|
+
*/
|
|
690
|
+
serverTimeout: number | null;
|
|
691
|
+
cluster: {
|
|
692
|
+
listen: {
|
|
693
|
+
path: string;
|
|
694
|
+
port: number;
|
|
695
|
+
hostname: string;
|
|
696
|
+
};
|
|
697
|
+
};
|
|
698
|
+
clusterClient: {
|
|
699
|
+
maxWaitTime: number;
|
|
700
|
+
responseTimeout: number;
|
|
701
|
+
};
|
|
702
|
+
[prop: string]: any;
|
|
703
|
+
}
|
|
704
|
+
type RequestObjectBody = Record<string, any>;
|
|
705
|
+
/**
|
|
706
|
+
* plugin config item interface
|
|
707
|
+
*/
|
|
708
|
+
interface IEggPluginItem {
|
|
709
|
+
env?: EggEnvType[];
|
|
710
|
+
path?: string;
|
|
711
|
+
package?: string;
|
|
712
|
+
enable?: boolean;
|
|
713
|
+
}
|
|
714
|
+
type EggPluginItem = IEggPluginItem | boolean;
|
|
715
|
+
/**
|
|
716
|
+
* build-in plugin list
|
|
717
|
+
*/
|
|
718
|
+
interface EggPlugin {
|
|
719
|
+
[key: string]: EggPluginItem | undefined;
|
|
720
|
+
onerror?: EggPluginItem;
|
|
721
|
+
session?: EggPluginItem;
|
|
722
|
+
i18n?: EggPluginItem;
|
|
723
|
+
watcher?: EggPluginItem;
|
|
724
|
+
multipart?: EggPluginItem;
|
|
725
|
+
security?: EggPluginItem;
|
|
726
|
+
development?: EggPluginItem;
|
|
727
|
+
logrotator?: EggPluginItem;
|
|
728
|
+
schedule?: EggPluginItem;
|
|
729
|
+
static?: EggPluginItem;
|
|
730
|
+
jsonp?: EggPluginItem;
|
|
731
|
+
view?: EggPluginItem;
|
|
732
|
+
}
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region src/lib/core/messenger/index.d.ts
|
|
735
|
+
/**
|
|
736
|
+
* @class Messenger
|
|
737
|
+
*/
|
|
738
|
+
declare function create(egg: EggApplicationCore): IMessenger;
|
|
739
|
+
//#endregion
|
|
740
|
+
//#region src/lib/core/context_httpclient.d.ts
|
|
741
|
+
declare class ContextHttpClient {
|
|
742
|
+
ctx: Context$1;
|
|
743
|
+
app: Application;
|
|
744
|
+
constructor(ctx: Context$1);
|
|
745
|
+
/**
|
|
746
|
+
* http request helper base on {@link HttpClient}, it will auto save httpclient log.
|
|
747
|
+
* Keep the same api with {@link Application#curl}.
|
|
748
|
+
*
|
|
749
|
+
* @param {String|Object} url - request url address.
|
|
750
|
+
* @param {Object} [options] - options for request.
|
|
751
|
+
*/
|
|
752
|
+
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<node_modules_urllib_dist_esm_Response_js0.HttpClientResponse<T>>;
|
|
753
|
+
request<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<node_modules_urllib_dist_esm_Response_js0.HttpClientResponse<T>>;
|
|
754
|
+
}
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region src/lib/egg.d.ts
|
|
757
|
+
declare const EGG_PATH: unique symbol;
|
|
758
|
+
interface EggApplicationCoreOptions extends Omit<EggCoreOptions, 'baseDir'> {
|
|
759
|
+
mode?: 'cluster' | 'single' | 'all-in-one-process';
|
|
760
|
+
clusterPort?: number;
|
|
761
|
+
baseDir?: string;
|
|
762
|
+
}
|
|
763
|
+
type EggContext = Context$1;
|
|
764
|
+
type MiddlewareFunc$1<T extends Context$1 = Context$1> = MiddlewareFunc<T>;
|
|
765
|
+
/**
|
|
766
|
+
* Based on koa's Application
|
|
767
|
+
* @see https://github.com/eggjs/egg-core
|
|
768
|
+
* @see https://github.com/eggjs/koa/blob/master/src/application.ts
|
|
769
|
+
* @augments EggCore
|
|
770
|
+
*/
|
|
771
|
+
declare class EggApplicationCore extends EggCore {
|
|
772
|
+
#private;
|
|
773
|
+
ctxStorage: AsyncLocalStorage<Context$1>;
|
|
774
|
+
/**
|
|
775
|
+
* Get the current request context from AsyncLocalStorage.
|
|
776
|
+
* This provides access to the context object for the current request lifecycle.
|
|
777
|
+
* @returns {Context | undefined} The current request context, or undefined if not in a request scope.
|
|
778
|
+
*/
|
|
779
|
+
get currentContext(): Context$1 | undefined;
|
|
780
|
+
ContextCookies: typeof Cookies;
|
|
781
|
+
ContextLogger: typeof EggContextLogger;
|
|
782
|
+
ContextHttpClient: typeof ContextHttpClient;
|
|
783
|
+
HttpClient: typeof HttpClient$1;
|
|
784
|
+
HttpClientNext: typeof HttpClient$1;
|
|
785
|
+
/**
|
|
786
|
+
* Retrieve base context class
|
|
787
|
+
* @member {BaseContextClass} BaseContextClass
|
|
788
|
+
* @since 1.0.0
|
|
789
|
+
*/
|
|
790
|
+
BaseContextClass: typeof BaseContextClass$1;
|
|
791
|
+
/**
|
|
792
|
+
* Retrieve base controller
|
|
793
|
+
* @member {Controller} Controller
|
|
794
|
+
* @since 1.0.0
|
|
795
|
+
*/
|
|
796
|
+
Controller: typeof BaseContextClass$1;
|
|
797
|
+
/**
|
|
798
|
+
* Retrieve base service
|
|
799
|
+
* @member {Service} Service
|
|
800
|
+
* @since 1.0.0
|
|
801
|
+
*/
|
|
802
|
+
Service: typeof BaseContextClass$1;
|
|
803
|
+
/**
|
|
804
|
+
* Retrieve base subscription
|
|
805
|
+
* @member {Subscription} Subscription
|
|
806
|
+
* @since 2.12.0
|
|
807
|
+
*/
|
|
808
|
+
Subscription: typeof BaseContextClass$1;
|
|
809
|
+
/**
|
|
810
|
+
* Retrieve base context class
|
|
811
|
+
* @member {BaseHookClass} BaseHookClass
|
|
812
|
+
*/
|
|
813
|
+
BaseHookClass: typeof BaseHookClass;
|
|
814
|
+
/**
|
|
815
|
+
* Retrieve base boot
|
|
816
|
+
* @member {Boot}
|
|
817
|
+
* @alias BaseHookClass
|
|
818
|
+
*/
|
|
819
|
+
Boot: typeof BaseHookClass;
|
|
820
|
+
options: Required<EggApplicationCoreOptions>;
|
|
821
|
+
readonly messenger: IMessenger;
|
|
822
|
+
agent?: Agent;
|
|
823
|
+
application?: Application;
|
|
824
|
+
loader: EggApplicationLoader;
|
|
825
|
+
/**
|
|
826
|
+
* @class
|
|
827
|
+
* @param {Object} options
|
|
828
|
+
* - {Object} [type] - type of instance, Agent and Application both extend koa, type can determine what it is.
|
|
829
|
+
* - {String} [baseDir] - app root dir, default is `process.cwd()`
|
|
830
|
+
* - {Object} [plugins] - custom plugin config, use it in unittest
|
|
831
|
+
* - {String} [mode] - process mode, can be cluster / single, default is `cluster`
|
|
832
|
+
*/
|
|
833
|
+
constructor(options?: EggApplicationCoreOptions);
|
|
834
|
+
/**
|
|
835
|
+
* @deprecated please use `options` property instead
|
|
836
|
+
*/
|
|
837
|
+
get _options(): Required<EggApplicationCoreOptions>;
|
|
838
|
+
protected loadConfig(): Promise<void>;
|
|
839
|
+
protected load(): Promise<void>;
|
|
840
|
+
/**
|
|
841
|
+
* Usage: new ApiClient({ cluster: app.cluster })
|
|
842
|
+
*/
|
|
843
|
+
get cluster(): (clientClass: unknown, options?: object) => any;
|
|
844
|
+
/**
|
|
845
|
+
* Wrap the Client with Leader/Follower Pattern
|
|
846
|
+
*
|
|
847
|
+
* @description almost the same as Agent.cluster API, the only different is that this method create Follower.
|
|
848
|
+
*
|
|
849
|
+
* @see https://github.com/node-modules/cluster-client
|
|
850
|
+
* @param {Function} clientClass - client class function
|
|
851
|
+
* @param {Object} [options]
|
|
852
|
+
* - {Boolean} [autoGenerate] - whether generate delegate rule automatically, default is true
|
|
853
|
+
* - {Function} [formatKey] - a method to transform the subscription info into a string,default is JSON.stringify
|
|
854
|
+
* - {Object} [transcode|JSON.stringify/parse]
|
|
855
|
+
* - {Function} encode - custom serialize method
|
|
856
|
+
* - {Function} decode - custom deserialize method
|
|
857
|
+
* - {Boolean} [isBroadcast] - whether broadcast subscription result to all followers or just one, default is true
|
|
858
|
+
* - {Number} [responseTimeout] - response timeout, default is 3 seconds
|
|
859
|
+
* - {Number} [maxWaitTime|30000] - leader startup max time, default is 30 seconds
|
|
860
|
+
* @return {ClientWrapper} wrapper
|
|
861
|
+
*/
|
|
862
|
+
clusterWrapper(clientClass: unknown, options?: object): any;
|
|
863
|
+
/**
|
|
864
|
+
* print the information when console.log(app)
|
|
865
|
+
* @return {Object} inspected app.
|
|
866
|
+
* @since 1.0.0
|
|
867
|
+
* @example
|
|
868
|
+
* ```js
|
|
869
|
+
* console.log(app);
|
|
870
|
+
* =>
|
|
871
|
+
* {
|
|
872
|
+
* name: 'mock-app',
|
|
873
|
+
* env: 'test',
|
|
874
|
+
* subdomainOffset: 2,
|
|
875
|
+
* config: '<egg config>',
|
|
876
|
+
* controller: '<egg controller>',
|
|
877
|
+
* service: '<egg service>',
|
|
878
|
+
* middlewares: '<egg middlewares>',
|
|
879
|
+
* urllib: '<egg urllib>',
|
|
880
|
+
* loggers: '<egg loggers>'
|
|
881
|
+
* }
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
inspect(): any;
|
|
885
|
+
toJSON(): any;
|
|
886
|
+
/**
|
|
887
|
+
* http request helper base on {@link httpclient}, it will auto save httpclient log.
|
|
888
|
+
* Keep the same api with `httpclient.request(url, args)`.
|
|
889
|
+
*
|
|
890
|
+
* See https://github.com/node-modules/urllib#api-doc for more details.
|
|
891
|
+
*
|
|
892
|
+
* @param {String} url request url address.
|
|
893
|
+
* @param {Object} options
|
|
894
|
+
* - method {String} - Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'.
|
|
895
|
+
* - data {Object} - Data to be sent. Will be stringify automatically.
|
|
896
|
+
* - dataType {String} - String - Type of response data. Could be `text` or `json`.
|
|
897
|
+
* If it's `text`, the callback data would be a String.
|
|
898
|
+
* If it's `json`, the data of callback would be a parsed JSON Object.
|
|
899
|
+
* Default callback data would be a Buffer.
|
|
900
|
+
* - headers {Object} - Request headers.
|
|
901
|
+
* - timeout {Number} - Request timeout in milliseconds. Defaults to exports.TIMEOUT.
|
|
902
|
+
* Include remote server connecting timeout and response timeout.
|
|
903
|
+
* When timeout happen, will return ConnectionTimeout or ResponseTimeout.
|
|
904
|
+
* - auth {String} - `username:password` used in HTTP Basic Authorization.
|
|
905
|
+
* - followRedirect {Boolean} - follow HTTP 3xx responses as redirects. defaults to false.
|
|
906
|
+
* - gzip {Boolean} - let you get the res object when request connected, default false. alias customResponse
|
|
907
|
+
* - nestedQuerystring {Boolean} - urllib default use querystring to stringify form data which don't
|
|
908
|
+
* support nested object, will use qs instead of querystring to support nested object by set this option to true.
|
|
909
|
+
* - more options see https://github.com/node-modules/urllib
|
|
910
|
+
* @return {Object}
|
|
911
|
+
* - status {Number} - HTTP response status
|
|
912
|
+
* - headers {Object} - HTTP response headers
|
|
913
|
+
* - res {Object} - HTTP response meta
|
|
914
|
+
* - data {Object} - HTTP response body
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```js
|
|
918
|
+
* const result = await app.curl('http://example.com/foo.json', {
|
|
919
|
+
* method: 'GET',
|
|
920
|
+
* dataType: 'json',
|
|
921
|
+
* });
|
|
922
|
+
* console.log(result.status, result.headers, result.data);
|
|
923
|
+
* ```
|
|
924
|
+
*/
|
|
925
|
+
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<HttpClientResponse<T>>;
|
|
926
|
+
/**
|
|
927
|
+
* Create a new HttpClient instance with custom options
|
|
928
|
+
* @param {Object} [options] HttpClient init options
|
|
929
|
+
*/
|
|
930
|
+
createHttpClient(options?: HttpClientOptions): HttpClient$1;
|
|
931
|
+
/**
|
|
932
|
+
* HttpClient instance
|
|
933
|
+
* @see https://github.com/node-modules/urllib
|
|
934
|
+
* @member {HttpClient}
|
|
935
|
+
*/
|
|
936
|
+
get httpClient(): HttpClient$1;
|
|
937
|
+
/**
|
|
938
|
+
* @deprecated please use httpClient instead
|
|
939
|
+
* @alias httpClient
|
|
940
|
+
* @member {HttpClient}
|
|
941
|
+
*/
|
|
942
|
+
get httpclient(): HttpClient$1;
|
|
943
|
+
/**
|
|
944
|
+
* All loggers contain logger, coreLogger and customLogger
|
|
945
|
+
* @member {Object}
|
|
946
|
+
* @since 1.0.0
|
|
947
|
+
*/
|
|
948
|
+
get loggers(): EggLoggers;
|
|
949
|
+
/**
|
|
950
|
+
* Get logger by name, it's equal to app.loggers['name'],
|
|
951
|
+
* but you can extend it with your own logical.
|
|
952
|
+
* @param {String} name - logger name
|
|
953
|
+
* @return {Logger} logger
|
|
954
|
+
*/
|
|
955
|
+
getLogger(name: string): EggLogger;
|
|
956
|
+
/**
|
|
957
|
+
* application logger, log file is `$HOME/logs/{appname}/{appname}-web`
|
|
958
|
+
* @member {Logger}
|
|
959
|
+
* @since 1.0.0
|
|
960
|
+
*/
|
|
961
|
+
get logger(): EggLogger;
|
|
962
|
+
/**
|
|
963
|
+
* core logger for framework and plugins, log file is `$HOME/logs/{appname}/egg-web`
|
|
964
|
+
* @member {Logger}
|
|
965
|
+
* @since 1.0.0
|
|
966
|
+
*/
|
|
967
|
+
get coreLogger(): EggLogger;
|
|
968
|
+
_unhandledRejectionHandler(err: any): void;
|
|
969
|
+
/**
|
|
970
|
+
* dump out the config and meta object
|
|
971
|
+
* @private
|
|
972
|
+
*/
|
|
973
|
+
dumpConfigToObject(): {
|
|
974
|
+
config: Record<string, any>;
|
|
975
|
+
meta: Record<string, any>;
|
|
976
|
+
};
|
|
977
|
+
/**
|
|
978
|
+
* save app.config to `run/${type}_config.json`
|
|
979
|
+
* @private
|
|
980
|
+
*/
|
|
981
|
+
dumpConfig(): void;
|
|
982
|
+
dumpTiming(): void;
|
|
983
|
+
get [EGG_PATH](): string;
|
|
984
|
+
get config(): EggAppConfig$1;
|
|
985
|
+
/**
|
|
986
|
+
* app.env delegate app.config.env
|
|
987
|
+
* @deprecated
|
|
988
|
+
*/
|
|
989
|
+
get env(): string;
|
|
990
|
+
set env(_: string);
|
|
991
|
+
/**
|
|
992
|
+
* app.proxy delegate app.config.proxy
|
|
993
|
+
* @deprecated
|
|
994
|
+
*/
|
|
995
|
+
get proxy(): boolean;
|
|
996
|
+
set proxy(_: boolean);
|
|
997
|
+
/**
|
|
998
|
+
* Create an anonymous context, the context isn't request level, so the request is mocked.
|
|
999
|
+
* then you can use context level API like `ctx.service`
|
|
1000
|
+
* @member {String} EggApplication#createAnonymousContext
|
|
1001
|
+
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
1002
|
+
* @return {Context} context
|
|
1003
|
+
*/
|
|
1004
|
+
createAnonymousContext(req?: any): EggContext;
|
|
1005
|
+
/**
|
|
1006
|
+
* Run async function in the anonymous context scope
|
|
1007
|
+
* @see Context#runInAnonymousContextScope
|
|
1008
|
+
* @param {Function} scope - the first args is an anonymous ctx, scope should be async function
|
|
1009
|
+
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
1010
|
+
*/
|
|
1011
|
+
runInAnonymousContextScope(scope: (ctx: Context$1) => Promise<void>, req?: unknown): Promise<void>;
|
|
1012
|
+
/**
|
|
1013
|
+
* Create egg context
|
|
1014
|
+
* @function EggApplication#createContext
|
|
1015
|
+
* @param {Req} req - node native Request object
|
|
1016
|
+
* @param {Res} res - node native Response object
|
|
1017
|
+
* @return {Context} context object
|
|
1018
|
+
*/
|
|
1019
|
+
createContext(req: IncomingMessage, res: ServerResponse): Context$1;
|
|
1020
|
+
}
|
|
1021
|
+
//#endregion
|
|
1022
|
+
//#region src/lib/core/base_context_logger.d.ts
|
|
1023
|
+
declare class BaseContextLogger {
|
|
1024
|
+
#private;
|
|
1025
|
+
/**
|
|
1026
|
+
* @class
|
|
1027
|
+
* @param {Context} ctx - context instance
|
|
1028
|
+
* @param {String} pathName - class path name
|
|
1029
|
+
* @since 1.0.0
|
|
1030
|
+
*/
|
|
1031
|
+
constructor(ctx: EggContext, pathName?: string);
|
|
1032
|
+
protected _log(method: 'info' | 'warn' | 'error' | 'debug', args: any[]): void;
|
|
1033
|
+
/**
|
|
1034
|
+
* @member {Function} BaseContextLogger#debug
|
|
1035
|
+
* @param {...any} args - log msg
|
|
1036
|
+
* @since 1.2.0
|
|
1037
|
+
*/
|
|
1038
|
+
debug(...args: any[]): void;
|
|
1039
|
+
/**
|
|
1040
|
+
* @member {Function} BaseContextLogger#info
|
|
1041
|
+
* @param {...any} args - log msg
|
|
1042
|
+
* @since 1.2.0
|
|
1043
|
+
*/
|
|
1044
|
+
info(...args: any[]): void;
|
|
1045
|
+
/**
|
|
1046
|
+
* @member {Function} BaseContextLogger#warn
|
|
1047
|
+
* @param {...any} args - log msg
|
|
1048
|
+
* @since 1.2.0
|
|
1049
|
+
*/
|
|
1050
|
+
warn(...args: any[]): void;
|
|
1051
|
+
/**
|
|
1052
|
+
* @member {Function} BaseContextLogger#error
|
|
1053
|
+
* @param {...any} args - log msg
|
|
1054
|
+
* @since 1.2.0
|
|
1055
|
+
*/
|
|
1056
|
+
error(...args: any[]): void;
|
|
1057
|
+
}
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region src/lib/core/base_context_class.d.ts
|
|
1060
|
+
/**
|
|
1061
|
+
* BaseContextClass is a base class that can be extended,
|
|
1062
|
+
* it's instantiated in context level,
|
|
1063
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
1064
|
+
*/
|
|
1065
|
+
declare class BaseContextClass$1 extends BaseContextClass {
|
|
1066
|
+
#private;
|
|
1067
|
+
[key: string | symbol]: any;
|
|
1068
|
+
ctx: Context$1;
|
|
1069
|
+
pathName?: string;
|
|
1070
|
+
app: Application;
|
|
1071
|
+
service: BaseContextClass$1;
|
|
1072
|
+
get logger(): BaseContextLogger;
|
|
1073
|
+
}
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/lib/start.d.ts
|
|
1076
|
+
interface StartEggOptions {
|
|
1077
|
+
/** specify framework that can be absolute path or npm package */
|
|
1078
|
+
framework?: string;
|
|
1079
|
+
/** directory of application, default to `process.cwd()` */
|
|
1080
|
+
baseDir?: string;
|
|
1081
|
+
/** ignore single process mode warning */
|
|
1082
|
+
ignoreWarning?: boolean;
|
|
1083
|
+
mode?: 'single';
|
|
1084
|
+
env?: string;
|
|
1085
|
+
plugins?: EggPlugin;
|
|
1086
|
+
}
|
|
1087
|
+
interface SingleModeApplication extends Application {
|
|
1088
|
+
agent: SingleModeAgent;
|
|
1089
|
+
}
|
|
1090
|
+
interface SingleModeAgent extends Agent {
|
|
1091
|
+
app: SingleModeApplication;
|
|
1092
|
+
}
|
|
1093
|
+
/**
|
|
1094
|
+
* Start egg with single process
|
|
1095
|
+
*/
|
|
1096
|
+
declare function startEgg(options?: StartEggOptions): Promise<SingleModeApplication>;
|
|
1097
|
+
//#endregion
|
|
1098
|
+
//#region src/lib/core/base_hook_class.d.ts
|
|
1099
|
+
declare class BaseHookClass implements ILifecycleBoot {
|
|
1100
|
+
#private;
|
|
1101
|
+
fullPath?: string;
|
|
1102
|
+
constructor(instance: Application | Agent);
|
|
1103
|
+
get logger(): egg_logger0.EggLogger;
|
|
1104
|
+
get config(): EggAppConfig$1;
|
|
1105
|
+
get app(): Application;
|
|
1106
|
+
get agent(): Agent;
|
|
1107
|
+
}
|
|
1108
|
+
//#endregion
|
|
1109
|
+
export { Agent, Application, BaseContextClass$1 as BaseContextClass, BaseContextLogger, BaseHookClass, ClientErrorResponse, Context$1 as Context, ContextHttpClient, CustomLoaderConfig, EggAppConfig$1 as EggAppConfig, type EggAppInfo, EggApplicationCore, EggApplicationCoreOptions, EggConfigFactory, EggContext, EggEnvType, type EggLogger$1 as EggLogger, EggLoggerConfig, EggPlugin, EggPluginItem, Helper, HttpClient$1 as HttpClient, HttpClientConfig, type HttpClientOptions, HttpClientRequestOptions, type HttpClientRequestURL, type HttpClientResponse, IEggPluginItem, type ILifecycleBoot$1 as ILifecycleBoot, type LoggerLevel, MetaMiddlewareOptions, MiddlewareFunc$1 as MiddlewareFunc, type Next, NotFoundMiddlewareOptions, type PartialDeep, PartialEggConfig, PowerPartial, Request$1 as Request, RequestObjectBody, Router$1 as Router, type SingleModeAgent, type SingleModeApplication, Singleton, type SingletonCreateMethod, type SingletonOptions, SiteFileContentFun, SiteFileMiddlewareOptions, StartEggOptions, _default, _default$1, _default$2, create, defineConfig, defineConfigFactory, startEgg };
|