import { TinyPluginCore, TinyPlugin, TinyPluginLayer } from '../../plugin/TinyPlugin.mjs'; export type MessagePayload = any; export type MessageApiReply = (type: string, data?: MessagePayload, timeout?: number) => Promise; export type ApiHandlerOptions = { /** * - The payload received from the main thread. */ data?: MessagePayload; /** * - The request ID. */ correlationId: string; }; export type ApiHandlerCallback = (options: ApiHandlerOptions) => Promise | (MessagePayload | undefined); export type MessageObj = { /** * - The identifier for the message type. */ type: string; /** * - The original message event. */ event: MessageEvent; /** * - The payload sent within the message. */ data?: MessagePayload; }; export type MessageCallback = (msg: MessageObj) => any; export type SwPluginInstaller = import('../../plugin/TinyPlugin.mjs').TinyPluginInstaller; export type TinyServiceWorkerPlugin = TinyPlugin; /** * A function used to install a plugin into the engine. * @template {TinyPluginLayer} Layer * @template {string} IdString * @template {string} VersionString * @template {any[]} Options * @typedef {import('../../plugin/TinyPlugin.mjs').TinyPluginInstaller} SwPluginInstaller */ /** * Represents a plugin instance designed to be integrated into a TinyWebWorkerEngine. * @template {TinyPluginLayer} Layer * @template {string} IdString * @template {string} VersionString * @template {any[]} Options * @typedef {TinyPlugin} TinyServiceWorkerPlugin */ /** * Manages the lifecycle and execution of modules inside a Dedicated Web Worker. */ declare class TinyWebWorkerEngine extends TinyPluginCore { #private; /** * Indicates if the engine has been initialized. * @returns {boolean} True if started, false otherwise. */ get started(): boolean; /** * Initializes a new instance of the TinyWebWorkerEngine. * @param {Object} [lgConfig] - Configuration options for the instance. * @param {boolean} [lgConfig.debugMode=false] - Whether to enable internal debug logging. * @param {boolean} [lgConfig.useLogColors=false] - Whether to enable log color support. * @param {Partial} [lgConfig.logger=console] - A custom logger object. */ constructor(lgConfig?: { debugMode?: boolean; useLogColors?: boolean; logger?: Partial; }); /** * Registers a handler for API calls coming from the main thread. * @param {string} type - The identifier for the call. * @param {ApiHandlerCallback} callback - Function that processes the request and returns a payload. * @throws {TypeError} If callback is not a function. */ onApi(type: string, callback: ApiHandlerCallback): void; /** * Removes a registered API handler. * @param {string} type - The identifier for the call. * @returns {boolean} True if the handler was removed. */ offApi(type: string): boolean; /** * Adds a message listener for unidirectional messages. * @param {string} type - The identifier for the message type. * @param {MessageCallback} callback - The callback to execute. * @throws {TypeError} If callback is not a function. */ addMessageListener(type: string, callback: MessageCallback): void; /** * Removes a message listener. * @param {string} type - The identifier for the message type. * @returns {boolean} True if the listener was removed. */ removeMessageListener(type: string): boolean; /** * Sends a unidirectional message to the main thread. * * Note: this intentionally reuses the `emit` name with a message-oriented * signature. The rest parameter keeps it assignable to the inherited * `EventEmitter.emit` contract. * * @override * @param {string} type - The identifier for the message type. * @param {...any} args - The data content (only the first argument is used). * @returns {boolean} Always true when the message is dispatched. * @throws {TypeError} If type is not a string or data is invalid. */ emit(type: string, ...args: any[]): boolean; /** * Sends a request to the main thread and waits for a response. * @param {string} type - The identifier for the call. * @param {MessagePayload} [data] - The request payload. * @param {number} [timeout=10000] - Maximum waiting time in milliseconds. * @returns {Promise} A promise that resolves with the result object. * @throws {Error} If the timeout is reached. */ emitApi(type: string, data?: MessagePayload, timeout?: number): Promise; /** * Initializes the Web Worker event listeners. * @returns {void} * @throws {Error} If the engine has already been started. */ init(): void; } export default TinyWebWorkerEngine; //# sourceMappingURL=TinyWebWorkerEngine.d.mts.map