export interface AdviceContext { that: T; method: PropertyKey; args: any[]; adviceParams?: K; } /** * execute order: * 1. beforeCall * 1. around * 1. afterReturn/afterThrow * 1. afterFinally */ export interface IAdvice { /** * call before function * @param ctx */ beforeCall?(ctx: AdviceContext): Promise; /** * call after function succeed */ afterReturn?(ctx: AdviceContext, result: any): Promise; /** * call after function throw error */ afterThrow?(ctx: AdviceContext, error: Error): Promise; /** * always call after function done */ afterFinally?(ctx: AdviceContext): Promise; /** * execute the function * the only one can modify the function return value */ around?(ctx: AdviceContext, next: () => Promise): Promise; }