/**
* Describes a method invocation that is processed by an interceptor-chain.
* @see MethodInterceptor
*/
export interface IInvocation {
/**
* The object that was originally invoked.
* Unlike IInvocation.this, IInvocation.target can not
* be changed by the interceptor-chain.
* Note also that this is the proxy-version of the invoked object.
*/
readonly target: any;
/**
* The name of the method that was invoked. This cannot
* be changed by the interceptor-chain
*/
readonly member: string;
readonly persistentContext: any;
/**
* Arguments supplied with the method invocation.
* This array can be replaced or modified by the interceptor-chain.
*/
args: any[];
/**
* this context of the method invocation. This can be changed by the interceptor-chain.
*/
this: any;
/**
* Invoke the next handler of this method or the original method if this is the
* end of the chain.
* @returns the result of the method invocation
*/
next(): any;
}
/**
* Describes a property access that is processed by an interceptor-chain.
*/
export interface IAccess {
/**
* The object on which the property originally was accessed.
* Unlike IInvocation.this, IInvocation.target can not
* be changed by the interceptor-chain.
* Note also that this is the proxy-version of the invoked object.
*/
readonly target: any;
/**
* The name of the property that was accessed. This cannot
* be changed by the interceptor-chain.
*/
readonly member: string;
readonly persistentContext: any;
/**
* If this is a setter call, this denotes the value the property is to be set to.
* If this is a getter call, the value is ignored.
*/
value: any;
/**
* true if this is setter-call, false otherwise. This cannot be changed
* by the interceptor-chain.
*/
readonly setter: boolean;
/**
* this context of the property-access. This can be changed by the interceptor-chain.
*/
this: any;
/**
* Invoke the next handler of this property-access or access the original property if this is the
* end of the chain.
* @returns the value of the property for getters, true/false for setters
*/
next(): any;
}
/**
* Interceptor for method invocations. It is used with the @around-decorator.
* @param {IInvocation} invocation provide information about the invocation and allows the
* interceptor to forward the call to the next handler.
* @returns {any} The result of the method invocation
* @example
* ```ts
*
* invocation => {
* // Access and modify argument
* invocation.args = ["Modified", "Arguments"];
*
* // Access and modify 'this'-context of the called method
* invocation.this = that;
*
* // Delegate call
* let result: any = invocation.next();
*
* // Modify result
* result += 1;
* return result;
* }
* ```
* @see around
* @see AfterInterceptor
* @see BeforeInterceptor
*/
export declare type MethodInterceptor = (invocation: IInvocation) => any;
/**
* Interceptor for property-access. It is used with the access-decorator.
* @param {IAccess} access provide information about the property-access and allows the
* interceptor to forward the call to the next handler.
* @returns {any} For getters (access.setter === false), this is the value of the property,
* for setters true or false
* @example
* ```ts
*
* access => {
* if(access.setter) {
* // Overwrite the value the property is to be set to
* access.value = "Hello"
* return access.next();
* }
* // getter
* let value = access.next();
*
* // Modify result
* value += 1;
* return value;
* }
* ```
* @see access
* @see GetterInterceptor
* @see SetterInterceptor
*/
export declare type AccessInterceptor = (access: IAccess) => any;
/**
* Interceptor for a property getter. It is used with the @getter-decorator.
* @param {any} value of the property. This is (the potentially modified) value of the
* property.
* @returns {any} Modified value of the property.
* @example
* ```ts
*
* value => {
* // Modify result
* value += 1;
* return value;
* }
* ```
* @see getter
* @see AccessInterceptor
*/
export declare type GetterInterceptor = (value: any) => any;
/**
* Interceptor for a property setter. It is used with the @setter-decorator.
* @param {any} value to be assigned to the property (this has potentially already been
* modified by previous interceptor)
* @returns {any} Modified value to be assigned to the property.
* @example
* ```ts
*
* value => {
* // Modify assigned value
* value += 1;
* return value;
* }
* ```
* @see setter
* @see AccessInterceptor
*/
export declare type SetterInterceptor = (value: any) => any;
/**
* Interceptor that is invoked after a invocation has completed. It is used
* with the @after-decorator.
* @param {any} result of the invocation
* @returns {any} Modified result of the invocation
* @example
* ```ts
*
* result => {
* // Modify method result
* result += 1;
* return result;
* }
* ```
* @see after
* @see MethodInterceptor
*/
export declare type AfterInterceptor = (result: any) => any;
/**
* Interceptor that is invoked before a method invocation. It is used
* with the @before-decorator.
* @param {any[]} args Arguments of the method invocation
* @returns {any[]} Modified arguments
* @example
* ```ts
*
* args => {
* // Modify method arguments
* args.push("Additional argument");
* // Or swap them
* return ["Replacement", "Argument"];
* }
* ```
* @see after
* @see MethodInterceptor
*/
export declare type BeforeInterceptor = (args: any[]) => any[];
/**
* Root decorator for classes. This is required on classes that use interceptors.
*
* @see around
* @see after
* @see before
* @see access
* @see getter
* @see setter
* @example
* ```ts
*
* args => {
* // Modify method arguments
* args.push("Additional argument");
* // Or swap them
* return ["Replacement", "Argument"];
* }
* ```
*/
export declare function proxy(): (targetClass: any) => any;
/**
* Decorator for intercepting a method.
* @param {MethodInterceptor[]} interceptors To apply to this method or property
* @see MethodInterceptor
*/
export declare function around(...interceptors: MethodInterceptor[]): MethodDecorator & PropertyDecorator;
/**
* Decorator for intercepting a read/write property-access.
* @param {AccessInterceptor[]} interceptors To apply to this method or property
* @see AccessInterceptor
*/
export declare function access(...interceptors: AccessInterceptor[]): MethodDecorator & PropertyDecorator;
/**
* Decorator for intercepting after a method invocation.
* @param {AfterInterceptor[]} interceptors To apply to this method or property
* @see AfterInterceptor
*/
export declare function after(...interceptors: AfterInterceptor[]): MethodDecorator & PropertyDecorator;
/**
* Decorator for intercepting before a method invocation.
* @param {BeforeInterceptor[]} interceptors To apply to this method or property
* @see BeforeInterceptor
*/
export declare function before(...interceptors: BeforeInterceptor[]): MethodDecorator & PropertyDecorator;
/**
* Decorator for intercepting a property read-access.
* @param {GetterInterceptor[]} interceptors To apply to this method or property
* @see GetterInterceptor
*/
export declare function getter(...interceptors: GetterInterceptor[]): MethodDecorator & PropertyDecorator;
/**
* Decorator for intercepting a property write-access.
* @param {SetterInterceptor[]} interceptors To apply to this method or property
* @see SetterInterceptor
*/
export declare function setter(...interceptors: SetterInterceptor[]): MethodDecorator & PropertyDecorator;