From dcfda58fdae939d8fb4f2f44c31d61f7d977159e Mon Sep 17 00:00:00 2001 From: Hage Yaapa Date: Mon, 24 Feb 2020 20:32:56 +0530 Subject: [PATCH] feat: add OperationHookContext interface Added OperationHookContext interface. Signed-off-by: Hage Yaapa --- types/observer-mixin.d.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/types/observer-mixin.d.ts b/types/observer-mixin.d.ts index 769a00bc..2c82721c 100644 --- a/types/observer-mixin.d.ts +++ b/types/observer-mixin.d.ts @@ -4,8 +4,22 @@ // License text available at https://opensource.org/licenses/MIT import {Callback, PromiseOrVoid} from './common'; +import {PersistedModel, PersistedModelClass} from './persisted-model'; -export type Listener = (ctx: object, next: (err?: any) => void) => void; +export interface OperationHookContext { + /** + * The constructor of the model that triggered the operation. + */ + Model: T; + + /** + * Additional context properties, not typed yet. + * See https://loopback.io/doc/en/lb3/Operation-hooks.html#hooks + */ + [property: string]: any; +} + +export type Listener = (ctx: Ctx, next: (err?: any) => void) => void; export interface ObserverMixin { /** @@ -36,7 +50,7 @@ export interface ObserverMixin { * `this` set to the model constructor, e.g. `User`. * @end */ - observe(operation: string, listener: Listener): void; + observe(operation: string, listener: Listener>): void; /** * Unregister an asynchronous observer for the given operation (event). @@ -54,7 +68,7 @@ export interface ObserverMixin { * @callback {function} listener The listener function. * @end */ - removeObserver(operation: string, listener: Listener): Listener | undefined; + removeObserver(operation: string, listener: Listener>): Listener> | undefined; /** * Unregister all asynchronous observers for the given operation (event).