1 | import { AnyJson } from '@salesforce/ts-types';
|
2 | export type callback = (data: any) => Promise<void>;
|
3 | type ListenerMap = Map<string, callback>;
|
4 | export type UniqueListenerMap = Map<string, ListenerMap>;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export declare class Lifecycle {
|
27 | private readonly listeners;
|
28 | private readonly uniqueListeners;
|
29 | static readonly telemetryEventName = "telemetry";
|
30 | static readonly warningEventName = "warning";
|
31 | private logger?;
|
32 | private constructor();
|
33 | /**
|
34 | * return the package.json version of the sfdx-core library.
|
35 | */
|
36 | static staticVersion(): string;
|
37 | /**
|
38 | * Retrieve the singleton instance of this class so that all listeners and emitters can interact from any library or tool
|
39 | */
|
40 | static getInstance(): Lifecycle;
|
41 | /**
|
42 | * return the package.json version of the sfdx-core library.
|
43 | */
|
44 | version(): string;
|
45 | /**
|
46 | * Remove all listeners for a given event
|
47 | *
|
48 | * @param eventName The name of the event to remove listeners of
|
49 | */
|
50 | removeAllListeners(eventName: string): void;
|
51 | /**
|
52 | * Get an array of listeners (callback functions) for a given event
|
53 | *
|
54 | * @param eventName The name of the event to get listeners of
|
55 | */
|
56 | getListeners(eventName: string): callback[];
|
57 | /**
|
58 | * Create a listener for the `telemetry` event
|
59 | *
|
60 | * @param cb The callback function to run when the event is emitted
|
61 | */
|
62 | onTelemetry(cb: (data: Record<string, unknown>) => Promise<void>): void;
|
63 | /**
|
64 | * Create a listener for the `warning` event
|
65 | *
|
66 | * @param cb The callback function to run when the event is emitted
|
67 | */
|
68 | onWarning(cb: (warning: string) => Promise<void>): void;
|
69 | /**
|
70 | * Create a new listener for a given event
|
71 | *
|
72 | * @param eventName The name of the event that is being listened for
|
73 | * @param cb The callback function to run when the event is emitted
|
74 | * @param uniqueListenerIdentifier A unique identifier for the listener. If a listener with the same identifier is already registered, a new one will not be added
|
75 | */
|
76 | on<T = AnyJson>(eventName: string, cb: (data: T) => Promise<void>, uniqueListenerIdentifier?: string): void;
|
77 | /**
|
78 | * Emit a `telemetry` event, causing all callback functions to be run in the order they were registered
|
79 | *
|
80 | * @param data The data to emit
|
81 | */
|
82 | emitTelemetry(data: AnyJson): Promise<void>;
|
83 | /**
|
84 | * Emit a `warning` event, causing all callback functions to be run in the order they were registered
|
85 | *
|
86 | * @param data The warning (string) to emit
|
87 | */
|
88 | emitWarning(warning: string): Promise<void>;
|
89 | /**
|
90 | * Emit a given event, causing all callback functions to be run in the order they were registered
|
91 | *
|
92 | * @param eventName The name of the event to emit
|
93 | * @param data The argument to be passed to the callback function
|
94 | */
|
95 | emit<T = AnyJson>(eventName: string, data: T): Promise<void>;
|
96 | }
|
97 | export declare const cloneUniqueListeners: (uniqueListeners: UniqueListenerMap | undefined) => UniqueListenerMap;
|
98 | export {};
|