import { CoreEvents, MetricEvents, PluginTable, Status } from "./types.cjs"; import { EventEmitter, Listener } from "@figliolia/event-emitter"; //#region src/Metrics/Metric.d.ts /** * Metric * * An interface for tracking performance in your application * * ```typescript * const metric = new Metric("My Metric", { ...plugins }); * * metric.start(); // Records the start time of your metric * metric.stop(); // Records the stop time and duration of your metric * metric.reset(); // Resets your metric * metric.on("start" | "stop" | "reset", async (metric) => { * // Adds an event listener to your Metric's events * await fetch({ * url: "/analytics-service", * data: JSON.stringify(metric) * }); * }); * ``` */ declare class Metric extends EventEmitter { name: string; stopTime: number; startTime: number; duration: number; plugins: P; status: Status; private readonly tracker; constructor(name: string, plugins?: P); /** * Start * * Records a start time for your metric and moves the status * to `inProgress`. Emits the Metric's `start` event */ start(time?: number): void; /** * Stop * * Records a stop time, duration, and moves your metric's status * to `complete`. Emits the Metric's `stop` event */ stop(time?: number, status?: Status): void; /** * Reset * * Resets the Metric's `startTime`, `stopTime`, `duration`, and `status` * back to their original state. Emits the Metric's `reset` event */ reset(): void; /** * Has Pending Tasks * * Returns true if any listeners on the metric have not yet complete */ get hasPendingTasks(): boolean; /** * Await Pending Tasks * * Polls pending plugin tasks and returns a promise that'll resolve once complete */ awaitPendingTasks(pollInterval?: number): Promise; /** * Register Plugins * * Instantiates each plugin specified */ private registerPlugins; /** * To JSON * * Returns all public mutable properties when passed into calls * to `JSON.stringify` */ toJSON(): { name: string; startTime: number; stopTime: number; duration: number; plugins: P; status: Status; }; /** * Events * * Returns each of the Metric's enumerated events. To extend * the default available metrics, override this method in * extending classes */ get events(): typeof CoreEvents; on(event: K, listener: Listener): string; } //#endregion export { Metric };