import { Binding , BindingSpec , BindingTagFilter , Constructor , filterByTag , injectable , ValueOrPromise , } from '@loopback/context' ; import { CoreTags } from './keys' ; /**
 * Observers to handle life cycle init/start/stop events
 */ export interface LifeCycleObserver { /**
     * The method to be invoked during `init`. It will only be called at most once
     * for a given application instance.
     */ init ? ( ... injectedArgs ) : ValueOrPromise < void > ; /**
     * The method to be invoked during `start`
     */ start ? ( ... injectedArgs ) : ValueOrPromise < void > ; /**
     * The method to be invoked during `stop`
     */ stop ? ( ... injectedArgs ) : ValueOrPromise < void > ; } const lifeCycleMethods = [ 'init' , 'start' , 'stop' ] ; param obj export function isLifeCycleObserver ( obj ) { const candidate = obj as Partial < LifeCycleObserver > ; return lifeCycleMethods . some ( m => typeof candidate [ m ] === 'function' ) ; } param ctor export function isLifeCycleObserverClass ( ctor ) { return ctor . prototype && isLifeCycleObserver ( ctor . prototype ) ; } param binding export function asLifeCycleObserver < T = unknown > ( binding ) { return binding . tag ( CoreTags . LIFE_CYCLE_OBSERVER ) ; } /**
 * Find all life cycle observer bindings. By default, a binding tagged with
 * `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
 */ export const lifeCycleObserverFilter = filterByTag ( CoreTags . LIFE_CYCLE_OBSERVER ) ; param group param specs export function lifeCycleObserver ( group = '' , ... specs ) { return injectable ( asLifeCycleObserver , { tags : { [ CoreTags . LIFE_CYCLE_OBSERVER_GROUP ] : group , } , } , ... specs ) ; }