import { TinyPluginCore } from '../../plugin/TinyPlugin.mjs'; export type MessagePayload = any; export type ApiHandlerOptions = { /** * - The payload received from the worker. */ data?: MessagePayload; /** * - The request ID. */ correlationId: string; }; export type ApiHandlerCallback = (options: ApiHandlerOptions) => Promise | (MessagePayload | undefined); /** * The data payload contained within the message. * @typedef {any} MessagePayload */ /** * @typedef {Object} ApiHandlerOptions * @property {MessagePayload} [data] - The payload received from the worker. * @property {string} correlationId - The request ID. */ /** * @callback ApiHandlerCallback * @param {ApiHandlerOptions} options - Options for the API handler. * @returns {Promise | (MessagePayload|undefined)} The response payload. */ /** * Manages Web Worker initialization, lifecycle, and strictly typed messaging. */ declare class TinyWebWorker extends TinyPluginCore { #private; /** @returns {boolean} True if the worker is ready. */ get isReady(): boolean; /** @returns {boolean} True if the instance has been destroyed. */ get isDestroyed(): boolean; /** @returns {Worker | null} The native worker instance. */ get worker(): Worker | null; /** * @param {Object} options - Configuration options for the instance. * @param {string} options.id - The unique identifier for this manager instance. * @param {string | URL} options.workerUrl - The path to the web worker file. * @param {WorkerOptions} [options.workerOptions={}] - Native worker options. * @param {boolean} [options.debugMode=false] - Whether to enable internal debug logging. * @param {boolean} [options.useLogColors=false] - Whether to enable log color support. * @param {Partial} [options.logger=console] - A custom logger object. * @throws {TypeError} If parameters are not the correct types. */ constructor({ id, workerUrl, workerOptions, logger, debugMode, useLogColors }: { id: string; workerUrl: string | URL; workerOptions?: WorkerOptions; debugMode?: boolean; useLogColors?: boolean; logger?: Partial; }); /** * Initializes the Web Worker and sets up the message bridges. * @returns {Promise} Resolves when the engine inside the worker signals readiness. */ init(): Promise; /** * Sends a message to the active Web Worker. * @param {string} type * @param {MessagePayload} [data] */ emitMessage(type: string, data?: MessagePayload): void; /** * Registers a handler for API calls coming from the Worker. * @param {string} type * @param {ApiHandlerCallback} callback */ onApi(type: string, callback: ApiHandlerCallback): void; /** * Removes a registered API handler. * @param {string} type */ offApi(type: string): boolean; /** * Sends an API request to the Web Worker and waits for the response. * @param {string} type - The API call identifier. * @param {MessagePayload} [data] - The request payload. * @param {number} [timeout=10000] - Maximum waiting time in milliseconds. * @returns {Promise} */ emitApi(type: string, data?: MessagePayload, timeout?: number): Promise; /** * Terminates the Web Worker immediately and cleans up listeners. */ terminate(): void; /** * Hard destroys the instance, clearing all references to avoid memory leaks. */ destroy(): void; } export default TinyWebWorker; //# sourceMappingURL=TinyWebWorker.d.mts.map