1- import delegate from 'delegates' ;
21import { assign } from 'utility' ;
32import { now , diff } from 'performance-ms' ;
43import {
54 utils , Context as EggCoreContext , Router ,
6- type ContextDelegation as EggCoreContextDelegation ,
75} from '@eggjs/core' ;
86import type { Cookies as ContextCookies } from '@eggjs/cookies' ;
97import { EggLogger } from 'egg-logger' ;
@@ -12,8 +10,8 @@ import type {
1210 HttpClientRequestURL , HttpClientRequestOptions , HttpClient ,
1311} from '../../lib/core/httpclient.js' ;
1412import type { BaseContextClass } from '../../lib//core/base_context_class.js' ;
15- import Request from './request.js' ;
16- import Response from './response.js' ;
13+ import type Request from './request.js' ;
14+ import type Response from './response.js' ;
1715import type Helper from './helper.js' ;
1816
1917import './context.types.js' ;
@@ -33,7 +31,9 @@ interface Cookies extends ContextCookies {
3331export default class Context extends EggCoreContext {
3432 declare app : Application ;
3533 declare request : Request ;
34+ declare response : Response ;
3635 declare service : BaseContextClass ;
36+ declare proxy : any ;
3737
3838 /**
3939 * Request start time
@@ -230,7 +230,7 @@ export default class Context extends EggCoreContext {
230230 * });
231231 * ```
232232 */
233- runInBackground ( scope : ( ctx : ContextDelegation ) => Promise < void > , taskName ?: string ) : void {
233+ runInBackground ( scope : ( ctx : Context ) => Promise < void > , taskName ?: string ) : void {
234234 // try to use custom function name first
235235 if ( ! taskName ) {
236236 taskName = Reflect . get ( scope , '_name' ) || scope . name || utils . getCalleeFromStack ( true ) ;
@@ -243,7 +243,7 @@ export default class Context extends EggCoreContext {
243243
244244 // let plugins or frameworks to reuse _runInBackground in some cases.
245245 // e.g.: https://github.com/eggjs/egg-mock/pull/78
246- async _runInBackground ( scope : ( ctx : ContextDelegation ) => Promise < void > , taskName : string ) {
246+ async _runInBackground ( scope : ( ctx : Context ) => Promise < void > , taskName : string ) {
247247 const startTime = now ( ) ;
248248 try {
249249 await scope ( this as any ) ;
@@ -257,46 +257,52 @@ export default class Context extends EggCoreContext {
257257 this . app . emit ( 'error' , err , this ) ;
258258 }
259259 }
260- }
261-
262- /**
263- * Context delegation.
264- */
265260
266- delegate ( Context . prototype , 'request' )
267261 /**
268262 * @member {Boolean} Context#acceptJSON
269263 * @see Request#acceptJSON
270264 * @since 1.0.0
271265 */
272- . getter ( 'acceptJSON' )
266+ get acceptJSON ( ) : boolean {
267+ return this . request . acceptJSON ;
268+ }
269+
270+ get query ( ) : Record < string , string > {
271+ return this . request . query ;
272+ }
273+
273274 /**
274275 * @member {Array} Context#queries
275276 * @see Request#queries
276277 * @since 1.0.0
277278 */
278- . getter ( 'queries' )
279- /**
280- * @member {Boolean} Context#accept
281- * @see Request#accept
282- * @since 1.0.0
283- */
284- . getter ( 'accept' )
279+ get queries ( ) : Record < string , string [ ] > {
280+ return this . request . queries ;
281+ }
282+
285283 /**
286284 * @member {string} Context#ip
287285 * @see Request#ip
288286 * @since 1.0.0
289287 */
290- . access ( 'ip' ) ;
288+ get ip ( ) : string {
289+ return this . request . ip ;
290+ }
291+
292+ set ip ( val : string ) {
293+ this . request . ip = val ;
294+ }
291295
292- delegate ( Context . prototype , 'response' )
293296 /**
294297 * @member {Number} Context#realStatus
295298 * @see Response#realStatus
296299 * @since 1.0.0
297300 */
298- . access ( 'realStatus' ) ;
301+ get realStatus ( ) : number {
302+ return this . response . realStatus ;
303+ }
299304
300- export type ContextDelegation = EggCoreContextDelegation & Context
301- & Pick < Request , 'acceptJSON' | 'queries' | 'accept' | 'ip' >
302- & Pick < Response , 'realStatus' > ;
305+ set realStatus ( val : number ) {
306+ this . response . realStatus = val ;
307+ }
308+ }
0 commit comments