test types
This commit is contained in:
80
index.d.ts
vendored
Normal file
80
index.d.ts
vendored
Normal file
@@ -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<IPCClientEvents> {
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user