UNPKG

1.76 kBTypeScriptView Raw
1import { Binding, BindingSpec, BindingTagFilter, Constructor, ValueOrPromise } from '@loopback/context';
2/**
3 * Observers to handle life cycle init/start/stop events
4 */
5export interface LifeCycleObserver {
6 /**
7 * The method to be invoked during `init`. It will only be called at most once
8 * for a given application instance.
9 */
10 init?(...injectedArgs: unknown[]): ValueOrPromise<void>;
11 /**
12 * The method to be invoked during `start`
13 */
14 start?(...injectedArgs: unknown[]): ValueOrPromise<void>;
15 /**
16 * The method to be invoked during `stop`
17 */
18 stop?(...injectedArgs: unknown[]): ValueOrPromise<void>;
19}
20/**
21 * Test if an object implements LifeCycleObserver
22 * @param obj - An object
23 */
24export declare function isLifeCycleObserver(obj: object): obj is LifeCycleObserver;
25/**
26 * Test if a class implements LifeCycleObserver
27 * @param ctor - A class
28 */
29export declare function isLifeCycleObserverClass(ctor: Constructor<unknown>): ctor is Constructor<LifeCycleObserver>;
30/**
31 * A `BindingTemplate` function to configure the binding as life cycle observer
32 * by tagging it with `CoreTags.LIFE_CYCLE_OBSERVER`.
33 *
34 * @param binding - Binding object
35 */
36export declare function asLifeCycleObserver<T = unknown>(binding: Binding<T>): Binding<T>;
37/**
38 * Find all life cycle observer bindings. By default, a binding tagged with
39 * `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
40 */
41export declare const lifeCycleObserverFilter: BindingTagFilter;
42/**
43 * Sugar decorator to mark a class as life cycle observer
44 * @param group - Optional observer group name
45 * @param specs - Optional bindings specs
46 */
47export declare function lifeCycleObserver(group?: string, ...specs: BindingSpec[]): ClassDecorator;