1 | import { Binding, Context, ContextView } from '@loopback/context';
|
2 | import { LifeCycleObserver } from './lifecycle';
|
3 |
|
4 |
|
5 |
|
6 | export type LifeCycleObserverGroup = {
|
7 | |
8 |
|
9 |
|
10 | group: string;
|
11 | |
12 |
|
13 |
|
14 | bindings: Readonly<Binding<LifeCycleObserver>>[];
|
15 | };
|
16 | export type LifeCycleObserverOptions = {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | orderedGroups: string[];
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 | disabledGroups?: string[];
|
30 | |
31 |
|
32 |
|
33 | parallel?: boolean;
|
34 | };
|
35 | export declare const DEFAULT_ORDERED_GROUPS: string[];
|
36 |
|
37 |
|
38 |
|
39 | export declare class LifeCycleObserverRegistry implements LifeCycleObserver {
|
40 | protected readonly context: Context;
|
41 | protected readonly observersView: ContextView<LifeCycleObserver>;
|
42 | protected readonly options: LifeCycleObserverOptions;
|
43 | constructor(context: Context, observersView: ContextView<LifeCycleObserver>, options?: LifeCycleObserverOptions);
|
44 | setOrderedGroups(groups: string[]): void;
|
45 | /**
|
46 | * Get observer groups ordered by the group
|
47 | */
|
48 | getObserverGroupsByOrder(): LifeCycleObserverGroup[];
|
49 | /**
|
50 | * Get the group for a given life cycle observer binding
|
51 | * @param binding - Life cycle observer binding
|
52 | */
|
53 | protected getObserverGroup(binding: Readonly<Binding<LifeCycleObserver>>): string;
|
54 | /**
|
55 | * Sort the life cycle observer bindings so that we can start/stop them
|
56 | * in the right order. By default, we can start other observers before servers
|
57 | * and stop them in the reverse order
|
58 | * @param bindings - Life cycle observer bindings
|
59 | */
|
60 | protected sortObserverBindingsByGroup(bindings: Readonly<Binding<LifeCycleObserver>>[]): LifeCycleObserverGroup[];
|
61 | /**
|
62 | * Notify an observer group of the given event
|
63 | * @param group - A group of bindings for life cycle observers
|
64 | * @param event - Event name
|
65 | */
|
66 | protected notifyObservers(observers: LifeCycleObserver[], bindings: Readonly<Binding<LifeCycleObserver>>[], event: keyof LifeCycleObserver): Promise<void>;
|
67 | /**
|
68 | * Invoke an observer for the given event
|
69 | * @param observer - A life cycle observer
|
70 | * @param event - Event name
|
71 | */
|
72 | protected invokeObserver(observer: LifeCycleObserver, event: keyof LifeCycleObserver): Promise<void>;
|
73 | /**
|
74 | * Emit events to the observer groups
|
75 | * @param events - Event names
|
76 | * @param groups - Observer groups
|
77 | */
|
78 | protected notifyGroups(events: (keyof LifeCycleObserver)[], groups: LifeCycleObserverGroup[], reverse?: boolean): Promise<void>;
|
79 | /**
|
80 | * Notify all life cycle observers by group of `init`
|
81 | */
|
82 | init(): Promise<void>;
|
83 | /**
|
84 | * Notify all life cycle observers by group of `start`
|
85 | */
|
86 | start(): Promise<void>;
|
87 | /**
|
88 | * Notify all life cycle observers by group of `stop`
|
89 | */
|
90 | stop(): Promise<void>;
|
91 | }
|