import Operation from "./artifacts/operation" ; import IRequest from "./IRequest" ; import IResponse from "./IResponse" ; export interface IHandlerParameters { [ key ] : any ; } export class export default class Context { public readonly context : any ; public readonly path : string ; param { Context } context memberof public constructor ( context ) ; param { Object } holder param { string } path param { IRequest } req param { IResponse } res memberof public constructor ( holder , path , req ? , res ? ) ; public constructor ( holderOrContext , path = "context" , req ? , res ? ) { if ( holderOrContext instanceof Context ) { this . context = holderOrContext . context ; this . path = holderOrContext . path ; } else { const context = holderOrContext as any ; this . path = path ; if ( context [ this . path ] === undefined ) { context [ this . path ] = { } ; } if ( typeof context [ this . path ] !== "object" ) { throw new TypeError ( `Initialize Context error because holder.${ this . path } is not an object.` ) ; } this . context = context [ this . path ] ; this . request = req ; this . response = res ; } } public get operation ( ) : Operation | undefined { return this . context . operation ; } public set operation ( operation ) { this . context . operation = operation ; } public set request ( request ) { this . context . request = request ; } public get request ( ) : IRequest | undefined { return this . context . request ; } public get dispatchPattern ( ) : string | undefined { return this . context . dispatchPattern ; } public set dispatchPattern ( path ) { this . context . dispatchPattern = path ; } public set response ( response ) { this . context . response = response ; } public get response ( ) : IResponse | undefined { return this . context . response ; } public get handlerParameters ( ) : IHandlerParameters | undefined { return this . context . handlerParameters ; } public set handlerParameters ( handlerParameters ) { this . context . handlerParameters = handlerParameters ; } public get handlerResponses ( ) : any { return this . context . handlerResponses ; } public set handlerResponses ( handlerResponses ) { this . context . handlerResponses = handlerResponses ; } public get contextID ( ) : string | undefined { return this . context . contextID ; } public set contextID ( contextID ) { this . context . contextID = contextID ; } public set startTime ( startTime ) { this . context . startTime = startTime ; } public get startTime ( ) : Date | undefined { return this . context . startTime ; } }