From c0cf93941c2fd2467429dd366f2bea1de486748e Mon Sep 17 00:00:00 2001 From: skullbite Date: Sun, 7 Sep 2025 04:10:07 +0200 Subject: [PATCH] test types --- index.d.ts | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..f6859da --- /dev/null +++ b/index.d.ts @@ -0,0 +1,80 @@ +import IPCModule from 'node-ipc'; +import { EventEmitter } from 'tseep'; + +/** + * Represents a message sent over IPC. + */ +export interface IPCMessage { + from: string; + to: string; + payload: unknown; +} + +/** + * Events emitted by the IPC client. + */ +export interface IPCClientEvents { + connect: () => void; + disconnect: () => void; + message: (message: IPCMessage) => void; +} + +/** + * IPC client for inter-process communication using `node-ipc`. + */ +export default class IPC extends EventEmitter { + /** + * The name/ID of this IPC client. + */ + name: string; + + /** + * Whether the client is connected and ready. + */ + ready: boolean; + + /** + * Reference to the node-ipc module. + */ + ipc: typeof IPCModule; + + /** + * Creates a new IPC client instance. + * @param name The ID/name of this process. + * @param debug Enable debug logging. + */ + constructor(name: string, debug?: boolean); + + /** + * Connects to the IPC server. + */ + connect(): void; + + /** + * Sends a message to another IPC client. + * @param to The recipient's name. + * @param data The message payload. + */ + send(to: string, data: unknown): void; + + /** + * Internal: Called when connection is established. + */ + private onConnect(): void; + + /** + * Internal: Called when disconnected. + */ + private onDisconnect(): void; + + /** + * Internal: Called when the connection is ready. + */ + private onReady(): void; + + /** + * Internal: Called when a message is received. + * @param raw The raw message from IPC. + */ + private onMessage(raw: IPCMessage): void; +} \ No newline at end of file