@zowe/imperative
Version:
framework for building configurable CLIs
97 lines • 4.43 kB
TypeScript
import { EventTypes, EventCallback } from "./EventConstants";
import * as fs from "fs";
import { IEventDisposable } from "./doc";
import { Event } from "./Event";
import { EventProcessor } from "./EventProcessor";
/**
* A collection of helper functions related to event processing, including:
* - directory management
* - event type determination
* - subscription creation and setting callbacks
* - event writing
*/
export declare class EventUtils {
/**
* Retrieves a list of supported applications from configuration.
*
* @static
* @returns {string[]} List of application names.
* @throws If the extenders.json file cannot be created when it does not exist.
* @throws If the extenders.json file cannot be read.
*/
static getListOfApps(): string[];
/**
* Won't throw an error if user entered a valid appName
*
* @static
* @param {string} appName - The name of the application.
* @throws {ImperativeError} If the application name is not recognized.
*/
static validateAppName(appName: string): void;
/**
* Determines if the specified event name is associated with a user event.
*
* @param {string} eventName - The name of the event.
* @return {boolean} True if it is a user event, otherwise false.
*/
static isUserEvent(eventName: string): boolean;
/**
* Determines if the specified event name is associated with a shared event.
*
* @param {string} eventName - The name of the event.
* @return {boolean} True if it is a shared event, otherwise false.
*/
static isSharedEvent(eventName: string): boolean;
/**
* Determines the directory path for storing event files based on the event type and application name.
*
* @param {string} appName - The name of the application.
* @return {string} The directory path.
* @throws {ImperativeError} If the application name is not recognized.
*/
static getEventDir(appName: string): string;
/**
* Ensures that the specified directory for storing event files exists, creating it if necessary.
*
* @param {string} directoryPath - The path to the directory.
* @throws {ImperativeError} If we are unable to create the '.events' directory.
*/
static ensureEventsDirExists(directoryPath: string): void;
/**
* Ensures that the specified file path for storing event data exists, creating it if necessary.
*
* @param {string} filePath - The path to the file.
* @throws {ImperativeError} If we are unable to create the event file required for event emission.
*/
static ensureFileExists(filePath: string): void;
/**
* Creates and registers a new event subscription for a specific event processor.
*
* @param {EventProcessor} eeInst - The event processor instance.
* @param {string} eventName - The name of the event.
* @param {EventTypes} eventType - The type of event.
* @return {IEventDisposable} An interface for managing the subscription.
* @throws {ImperativeError} If the application name is not recognized.
* @throws {ImperativeError} If we are unable to create the '.events' directory.
* @throws {ImperativeError} If we are unable to create the event file required for event emission.
*/
static createSubscription(eeInst: EventProcessor, eventName: string, eventType: EventTypes): IEventDisposable;
/**
* Sets up a file watcher for a specific event, triggering callbacks when the event file is updated.
*
* @param {EventProcessor} eeInst - The event processor instance.
* @param {string} eventName - The name of the event.
* @param {EventCallback[] | EventCallback} callbacks - A single callback or an array of callbacks to execute.
* @return {fs.FSWatcher} A file system watcher.
* @throws {ImperativeError} If the event to be watched does not have an existing file to watch.
* @throws {ImperativeError} Callbacks will fail if the contents of the event cannot be retrieved.
*/
static setupWatcher(eeInst: EventProcessor, eventName: string, callbacks: EventCallback[] | EventCallback): fs.FSWatcher;
/**
* Writes event data to the corresponding event file in JSON format.
*
* @param {Event} event - The event object.
*/
static writeEvent(event: Event): void;
}
//# sourceMappingURL=EventUtils.d.ts.map