egg 4.1.0-beta.9 → 4.1.1-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.
- package/dist/ajv.d.ts +1 -0
- package/dist/ajv.js +3 -0
- package/dist/aop.d.ts +1 -0
- package/dist/aop.js +3 -0
- package/dist/app/extend/context.d.ts +122 -146
- package/dist/app/extend/helper.d.ts +29 -29
- package/dist/app/extend/request.d.ts +103 -112
- package/dist/app/extend/response.d.ts +18 -24
- package/dist/app/middleware/meta.d.ts +2 -3
- package/dist/app/middleware/meta.js +3 -0
- package/dist/app/middleware/notfound.d.ts +2 -3
- package/dist/app/middleware/site_file.d.ts +2 -2
- package/dist/app/middleware/site_file.js +1 -1
- package/dist/config/config.default.d.ts +8 -8
- package/dist/config/config.default.js +16 -9
- package/dist/config/config.local.d.ts +4 -8
- package/dist/config/config.local.js +4 -3
- package/dist/config/config.unittest.d.ts +4 -7
- package/dist/config/config.unittest.js +7 -6
- package/dist/config/favicon.png +0 -0
- package/dist/config/plugin.d.ts +5 -122
- package/dist/config/plugin.js +63 -48
- package/dist/dal.d.ts +1 -0
- package/dist/dal.js +3 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/helper.d.ts +1 -0
- package/dist/helper.js +3 -0
- package/dist/index.d.ts +13 -8
- package/dist/index.js +9 -5
- package/dist/lib/agent.d.ts +10 -9
- package/dist/lib/agent.js +1 -2
- package/dist/lib/application.d.ts +32 -41
- package/dist/lib/application.js +8 -6
- package/dist/lib/core/base_context_class.d.ts +9 -7
- package/dist/lib/core/base_context_logger.d.ts +22 -22
- package/dist/lib/core/base_hook_class.d.ts +4 -3
- package/dist/lib/core/context_httpclient.d.ts +12 -12
- package/dist/lib/core/httpclient.d.ts +3 -4
- package/dist/lib/core/httpclient.js +3 -2
- package/dist/lib/core/messenger/IMessenger.d.ts +33 -33
- package/dist/lib/core/messenger/base.d.ts +2 -2
- package/dist/lib/core/messenger/base.js +2 -1
- package/dist/lib/core/messenger/index.d.ts +2 -2
- package/dist/lib/core/messenger/index.js +3 -3
- package/dist/lib/core/messenger/ipc.d.ts +36 -35
- package/dist/lib/core/messenger/ipc.js +9 -3
- package/dist/lib/core/messenger/local.d.ts +38 -38
- package/dist/lib/core/messenger/local.js +5 -3
- package/dist/lib/define.d.ts +81 -0
- package/dist/lib/define.js +60 -0
- package/dist/lib/egg.d.ts +197 -217
- package/dist/lib/egg.js +22 -16
- package/dist/lib/loader/AgentWorkerLoader.d.ts +5 -5
- package/dist/lib/loader/AppWorkerLoader.d.ts +9 -9
- package/dist/lib/start.d.ts +4 -4
- package/dist/lib/start.js +1 -1
- package/dist/lib/types.d.ts +154 -98
- package/dist/lib/types.js +1 -12
- package/dist/lib/types.plugin.d.ts +21 -0
- package/dist/lib/types.plugin.js +23 -0
- package/dist/orm.d.ts +1 -0
- package/dist/orm.js +3 -0
- package/dist/schedule.d.ts +2 -0
- package/dist/schedule.js +5 -0
- package/dist/transaction.d.ts +1 -0
- package/dist/transaction.js +3 -0
- package/package.json +73 -60
- package/dist/lib/utils.d.ts +0 -5
- package/dist/lib/utils.js +0 -14
package/dist/ajv.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@eggjs/tegg/ajv";
|
package/dist/ajv.js
ADDED
package/dist/aop.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@eggjs/tegg/aop";
|
package/dist/aop.js
ADDED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import Helper from "./helper.js";
|
|
2
|
-
import { Application } from "../../lib/application.js";
|
|
3
1
|
import { EggContextHttpClient as HttpClient, HttpClientRequestOptions, HttpClientRequestURL } from "../../lib/core/httpclient.js";
|
|
2
|
+
import { IService } from "../../lib/types.js";
|
|
4
3
|
import Response$1 from "./response.js";
|
|
5
4
|
import Request$1 from "./request.js";
|
|
6
|
-
import {
|
|
5
|
+
import { Application } from "../../lib/application.js";
|
|
6
|
+
import Helper from "./helper.js";
|
|
7
7
|
import { Context as Context$1, Router } from "@eggjs/core";
|
|
8
|
-
import { EggLogger } from "egg-logger";
|
|
9
8
|
import { Cookies } from "@eggjs/cookies";
|
|
9
|
+
import { EggLogger } from "egg-logger";
|
|
10
10
|
|
|
11
11
|
//#region src/app/extend/context.d.ts
|
|
12
12
|
interface Cookies$1 extends Cookies {
|
|
@@ -17,191 +17,167 @@ declare class Context extends Context$1 {
|
|
|
17
17
|
app: Application;
|
|
18
18
|
request: Request$1;
|
|
19
19
|
response: Response$1;
|
|
20
|
-
service:
|
|
20
|
+
service: IService;
|
|
21
21
|
proxy: any;
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
* Request start time
|
|
24
|
+
* @member {Number} Context#starttime
|
|
25
|
+
*/
|
|
26
26
|
starttime: number;
|
|
27
27
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
* Request start timer using `performance.now()`
|
|
29
|
+
* @member {Number} Context#performanceStarttime
|
|
30
|
+
*/
|
|
31
31
|
performanceStarttime: number;
|
|
32
32
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
* Get the current visitor's cookies.
|
|
34
|
+
*/
|
|
35
35
|
get cookies(): Cookies$1;
|
|
36
36
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
* Get a wrapper httpclient instance contain ctx in the hold request process
|
|
38
|
+
*
|
|
39
|
+
* @return {HttpClient} the wrapper httpclient instance
|
|
40
|
+
*/
|
|
41
41
|
get httpclient(): HttpClient;
|
|
42
42
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
* Alias to {@link Context#httpclient}
|
|
44
|
+
*/
|
|
45
45
|
get httpClient(): HttpClient;
|
|
46
46
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient[
|
|
55
|
-
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
47
|
+
* Shortcut for httpclient.curl
|
|
48
|
+
*
|
|
49
|
+
* @function Context#curl
|
|
50
|
+
* @param {String|Object} url - request url address.
|
|
51
|
+
* @param {Object} [options] - options for request.
|
|
52
|
+
* @return {Object} see {@link ContextHttpClient#curl}
|
|
53
|
+
*/
|
|
54
|
+
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient["request"]>;
|
|
55
|
+
/**
|
|
56
|
+
* Alias to {@link Application#router}
|
|
57
|
+
*
|
|
58
|
+
* @member {Router} Context#router
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* this.router.pathFor('post', { id: 12 });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
65
|
get router(): Router;
|
|
66
66
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
* Set router to Context, only use on EggRouter
|
|
68
|
+
* @param {Router} val router instance
|
|
69
|
+
*/
|
|
70
70
|
set router(val: Router);
|
|
71
71
|
/**
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
* Get helper instance from {@link Application#Helper}
|
|
73
|
+
*
|
|
74
|
+
* @member {Helper} Context#helper
|
|
75
|
+
* @since 1.0.0
|
|
76
|
+
*/
|
|
77
77
|
get helper(): Helper;
|
|
78
78
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
* Wrap app.loggers with context information,
|
|
80
|
+
* if a custom logger is defined by naming aLogger, then you can `ctx.getLogger('aLogger')`
|
|
81
|
+
*
|
|
82
|
+
* @param {String} name - logger name
|
|
83
|
+
*/
|
|
84
84
|
getLogger(name: string): EggLogger;
|
|
85
85
|
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
* Logger for Application
|
|
87
|
+
*
|
|
88
|
+
* @member {Logger} Context#logger
|
|
89
|
+
* @since 1.0.0
|
|
90
|
+
* @example
|
|
91
|
+
* ```js
|
|
92
|
+
* this.logger.info('some request data: %j', this.request.body);
|
|
93
|
+
* this.logger.warn('WARNING!!!!');
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
96
|
get logger(): EggLogger;
|
|
97
97
|
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
* Logger for frameworks and plugins
|
|
99
|
+
*
|
|
100
|
+
* @member {Logger} Context#coreLogger
|
|
101
|
+
* @since 1.0.0
|
|
102
|
+
*/
|
|
103
103
|
get coreLogger(): EggLogger;
|
|
104
104
|
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
105
|
+
* locals is an object for view, you can use `app.locals` and `ctx.locals` to set variables,
|
|
106
|
+
* which will be used as data when view is rendering.
|
|
107
|
+
* The difference between `app.locals` and `ctx.locals` is the context level, `app.locals` is global level, and `ctx.locals` is request level. when you get `ctx.locals`, it will merge `app.locals`.
|
|
108
|
+
*
|
|
109
|
+
* when you set locals, only object is available
|
|
110
|
+
*
|
|
111
|
+
* ```js
|
|
112
|
+
* this.locals = {
|
|
113
|
+
* a: 1
|
|
114
|
+
* };
|
|
115
|
+
* this.locals = {
|
|
116
|
+
* b: 1
|
|
117
|
+
* };
|
|
118
|
+
* this.locals.c = 1;
|
|
119
|
+
* console.log(this.locals);
|
|
120
|
+
* {
|
|
121
|
+
* a: 1,
|
|
122
|
+
* b: 1,
|
|
123
|
+
* c: 1,
|
|
124
|
+
* };
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* `ctx.locals` has cache, it only merges `app.locals` once in one request.
|
|
128
|
+
*
|
|
129
|
+
* @member {Object} Context#locals
|
|
130
|
+
*/
|
|
131
131
|
get locals(): Record<string, any>;
|
|
132
132
|
set locals(val: Record<string, any>);
|
|
133
133
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
* alias to {@link Context#locals}, compatible with koa that use this variable
|
|
135
|
+
* @member {Object} state
|
|
136
|
+
* @see Context#locals
|
|
137
|
+
*/
|
|
138
138
|
get state(): Record<string, any>;
|
|
139
139
|
set state(val: Record<string, any>);
|
|
140
140
|
/**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
141
|
+
* Run async function in the background
|
|
142
|
+
* @param {Function} scope - the first args is ctx
|
|
143
|
+
* ```js
|
|
144
|
+
* this.body = 'hi';
|
|
145
|
+
*
|
|
146
|
+
* this.runInBackground(async ctx => {
|
|
147
|
+
* await ctx.mysql.query(sql);
|
|
148
|
+
* await ctx.curl(url);
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
152
|
runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void;
|
|
153
153
|
_runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string): Promise<void>;
|
|
154
154
|
/**
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
* @member {Boolean} Context#acceptJSON
|
|
156
|
+
* @see Request#acceptJSON
|
|
157
|
+
* @since 1.0.0
|
|
158
|
+
*/
|
|
159
159
|
get acceptJSON(): boolean;
|
|
160
160
|
get query(): Record<string, string>;
|
|
161
161
|
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
* @member {Array} Context#queries
|
|
163
|
+
* @see Request#queries
|
|
164
|
+
* @since 1.0.0
|
|
165
|
+
*/
|
|
166
166
|
get queries(): Record<string, string[]>;
|
|
167
167
|
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
* @member {string} Context#ip
|
|
169
|
+
* @see Request#ip
|
|
170
|
+
* @since 1.0.0
|
|
171
|
+
*/
|
|
172
172
|
get ip(): string;
|
|
173
173
|
set ip(val: string);
|
|
174
174
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
175
|
+
* @member {Number} Context#realStatus
|
|
176
|
+
* @see Response#realStatus
|
|
177
|
+
* @since 1.0.0
|
|
178
|
+
*/
|
|
179
179
|
get realStatus(): number;
|
|
180
180
|
set realStatus(val: number);
|
|
181
181
|
}
|
|
182
|
-
declare module '@eggjs/core' {
|
|
183
|
-
interface Context {
|
|
184
|
-
proxy: any;
|
|
185
|
-
performanceStarttime: number;
|
|
186
|
-
starttime: number;
|
|
187
|
-
runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void;
|
|
188
|
-
_runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string): void;
|
|
189
|
-
get acceptJSON(): boolean;
|
|
190
|
-
get query(): Record<string, string>;
|
|
191
|
-
get queries(): Record<string, string[]>;
|
|
192
|
-
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
|
|
193
|
-
get router(): Router;
|
|
194
|
-
set router(val: Router);
|
|
195
|
-
get helper(): Helper;
|
|
196
|
-
get httpclient(): HttpClient;
|
|
197
|
-
get httpClient(): HttpClient;
|
|
198
|
-
getLogger(name: string): EggLogger;
|
|
199
|
-
get logger(): EggLogger;
|
|
200
|
-
get coreLogger(): EggLogger;
|
|
201
|
-
get locals(): Record<string, any>;
|
|
202
|
-
get realStatus(): number;
|
|
203
|
-
set realStatus(val: number);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
182
|
//#endregion
|
|
207
183
|
export { Context as default };
|
|
@@ -3,39 +3,39 @@ import { BaseContextClass } from "../../lib/core/base_context_class.js";
|
|
|
3
3
|
//#region src/app/extend/helper.d.ts
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
* The Helper class which can be used as utility function.
|
|
7
|
+
* We support developers to extend Helper through ${baseDir}/app/extend/helper.js ,
|
|
8
|
+
* then you can use all method on `ctx.helper` that is a instance of Helper.
|
|
9
|
+
*/
|
|
10
10
|
declare class Helper extends BaseContextClass {
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
* Generate URL path(without host) for route. Takes the route name and a map of named params.
|
|
13
|
+
* @function Helper#pathFor
|
|
14
|
+
* @param {String} name - Router Name
|
|
15
|
+
* @param {Object} params - Other params
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* app.get('home', '/index.htm', 'home.index');
|
|
20
|
+
* ctx.helper.pathFor('home', { by: 'recent', limit: 20 })
|
|
21
|
+
* => /index.htm?by=recent&limit=20
|
|
22
|
+
* ```
|
|
23
|
+
* @return {String} url path(without host)
|
|
24
|
+
*/
|
|
25
25
|
pathFor(name: string, params: Record<string, any>): string;
|
|
26
26
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
* Generate full URL(with host) for route. Takes the route name and a map of named params.
|
|
28
|
+
* @function Helper#urlFor
|
|
29
|
+
* @param {String} name - Router name
|
|
30
|
+
* @param {Object} params - Other params
|
|
31
|
+
* @example
|
|
32
|
+
* ```js
|
|
33
|
+
* app.get('home', '/index.htm', 'home.index');
|
|
34
|
+
* ctx.helper.urlFor('home', { by: 'recent', limit: 20 })
|
|
35
|
+
* => http://127.0.0.1:7001/index.htm?by=recent&limit=20
|
|
36
|
+
* ```
|
|
37
|
+
* @return {String} full url(with host)
|
|
38
|
+
*/
|
|
39
39
|
urlFor(name: string, params: Record<string, any>): string;
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Application } from "../../lib/application.js";
|
|
2
1
|
import Response$1 from "./response.js";
|
|
3
2
|
import Context$1 from "./context.js";
|
|
3
|
+
import { Application } from "../../lib/application.js";
|
|
4
4
|
import { Request as Request$1 } from "@eggjs/core";
|
|
5
5
|
|
|
6
6
|
//#region src/app/extend/request.d.ts
|
|
@@ -9,137 +9,128 @@ declare class Request extends Request$1 {
|
|
|
9
9
|
ctx: Context$1;
|
|
10
10
|
response: Response$1;
|
|
11
11
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
* Request body, parsed from koa-bodyparser or @eggjs/multipart
|
|
13
|
+
*/
|
|
14
14
|
body: any;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
* Parse the "Host" header field host
|
|
17
|
+
* and support X-Forwarded-Host when a
|
|
18
|
+
* proxy is enabled.
|
|
19
|
+
* @member {String} Request#host
|
|
20
|
+
* @example
|
|
21
|
+
* ip + port
|
|
22
|
+
* ```js
|
|
23
|
+
* this.request.host
|
|
24
|
+
* => '127.0.0.1:7001'
|
|
25
|
+
* ```
|
|
26
|
+
* or domain
|
|
27
|
+
* ```js
|
|
28
|
+
* this.request.host
|
|
29
|
+
* => 'demo.eggjs.org'
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
32
|
get host(): string;
|
|
33
33
|
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
* @member {String} Request#protocol
|
|
35
|
+
* @example
|
|
36
|
+
* ```js
|
|
37
|
+
* this.request.protocol
|
|
38
|
+
* => 'https'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
41
|
get protocol(): string;
|
|
42
42
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
* Get all pass through ip addresses from the request.
|
|
44
|
+
* Enable only on `app.config.proxy = true`
|
|
45
|
+
*
|
|
46
|
+
* @member {Array} Request#ips
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* this.request.ips
|
|
50
|
+
* => ['100.23.1.2', '201.10.10.2']
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
53
|
get ips(): string[];
|
|
54
54
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
* Get the request remote IPv4 address
|
|
56
|
+
* @member {String} Request#ip
|
|
57
|
+
* @return {String} IPv4 address
|
|
58
|
+
* @example
|
|
59
|
+
* ```js
|
|
60
|
+
* this.request.ip
|
|
61
|
+
* => '127.0.0.1'
|
|
62
|
+
* => '111.10.2.1'
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
65
|
get ip(): string;
|
|
66
66
|
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
* Set the request remote IPv4 address
|
|
68
|
+
* @member {String} Request#ip
|
|
69
|
+
* @param {String} ip - IPv4 address
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* this.request.ip
|
|
73
|
+
* => '127.0.0.1'
|
|
74
|
+
* => '111.10.2.1'
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
77
|
set ip(ip: string);
|
|
78
78
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
* detect if response should be json
|
|
80
|
+
* 1. url path ends with `.json`
|
|
81
|
+
* 2. response type is set to json
|
|
82
|
+
* 3. detect by request accept header
|
|
83
|
+
*
|
|
84
|
+
* @member {Boolean} Request#acceptJSON
|
|
85
|
+
* @since 1.0.0
|
|
86
|
+
*/
|
|
87
87
|
get acceptJSON(): boolean;
|
|
88
88
|
_customQuery(cacheName: symbol, filter: (value: string | string[]) => string | string[]): Record<string, string | string[]>;
|
|
89
89
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
90
|
+
* get params pass by querystring, all values are of string type.
|
|
91
|
+
* @member {Object} Request#query
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* GET http://127.0.0.1:7001?name=Foo&age=20&age=21
|
|
95
|
+
* this.query
|
|
96
|
+
* => { 'name': 'Foo', 'age': '20' }
|
|
97
|
+
*
|
|
98
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
99
|
+
* this.query
|
|
100
|
+
* =>
|
|
101
|
+
* {
|
|
102
|
+
* "a": "b",
|
|
103
|
+
* "o[foo]": "bar",
|
|
104
|
+
* "b[]": "1",
|
|
105
|
+
* "e": "val"
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
109
|
get query(): Record<string, string>;
|
|
110
110
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
111
|
+
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
112
|
+
* @member {Array} Request#queries
|
|
113
|
+
* @example
|
|
114
|
+
* ```js
|
|
115
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
116
|
+
* this.queries
|
|
117
|
+
* =>
|
|
118
|
+
* {
|
|
119
|
+
* "a": ["b", "c"],
|
|
120
|
+
* "o[foo]": ["bar"],
|
|
121
|
+
* "b[]": ["1", "2"],
|
|
122
|
+
* "e": ["val"]
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
126
|
get queries(): Record<string, string[]>;
|
|
127
127
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
* Set query-string as an object.
|
|
129
|
+
*
|
|
130
|
+
* @function Request#query
|
|
131
|
+
* @param {Object} obj set querystring and query object for request.
|
|
132
|
+
*/
|
|
133
133
|
set query(obj: Record<string, string>);
|
|
134
134
|
}
|
|
135
|
-
declare module '@eggjs/core' {
|
|
136
|
-
interface Request {
|
|
137
|
-
body: any;
|
|
138
|
-
get acceptJSON(): boolean;
|
|
139
|
-
get query(): Record<string, string>;
|
|
140
|
-
set query(obj: Record<string, string>);
|
|
141
|
-
get queries(): Record<string, string[]>;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
135
|
//#endregion
|
|
145
136
|
export { Request as default };
|