UNPKG

@manuth/interceptor

Version:

Provides a convenient way to intercept method- property- and accessor-calls of an object.

94 lines (93 loc) 2.4 kB
import { IInterception } from "./IInterception.js"; import { MethodInterception } from "./MethodInterception.js"; /** * Provides the functionality to intercept methods of an object. * * @template T * The type of the target of the {@linkcode Interceptor}. */ export declare class Interceptor<T extends {}> { /** * The target of the interceptor. */ private target; /** * The proxy that invokes the interceptions. */ private proxy; /** * The interceptions. */ private interceptions; /** * A value indicating whether the interceptor is disposed. */ private disposed; /** * Initializes a new instance of the {@linkcode Interceptor} class. * * @param target * The target of the interceptor. * * @param freeze * A value indicating whether the interceptor should ignore future changes made to the {@linkcode target}. */ constructor(target: T, freeze?: boolean); /** * Gets the target of the interceptor. */ get Target(): T; /** * Gets the installed interceptions. */ get Interceptions(): ReadonlyMap<keyof T, IInterception<T, keyof T>>; /** * Gets the proxy for intercepting calls. */ get Proxy(): T; /** * Gets a value indicating whether the interceptor is disposed. */ get Disposed(): boolean; /** * Adds a new property-interception. * * @template TKey * The type of the specified {@linkcode key}. * * @param key * The key of the interception to add. * * @param interception * The interception to add. */ AddProperty<TKey extends keyof T>(key: TKey, interception: IInterception<T, TKey>): void; /** * Adds a new interception. * * @template TKey * The type of the specified {@linkcode key}. * * @param key * The key of the interception to add. * * @param interception * The interception to add. */ AddMethod<TKey extends keyof T>(key: TKey, interception: MethodInterception<T, TKey>): void; /** * Deletes an interception. * * @param key * The key of the interception to delete. */ Delete(key: keyof T): void; /** * Clears all interceptions. */ Clear(): void; /** * Disposes the interceptor. */ Dispose(): void; }