Files
tspm/ts/ipc.types.ts

199 lines
4.0 KiB
TypeScript

import type { IProcessConfig, IProcessInfo } from './classes.tspm.js';
import type { IProcessLog } from './classes.processwrapper.js';
// Base message types
export interface IpcRequest<T = any> {
id: string;
method: string;
params: T;
}
export interface IpcResponse<T = any> {
id: string;
success: boolean;
result?: T;
error?: {
code: number;
message: string;
data?: any;
};
}
// Request/Response pairs for each operation
// Start command
export interface StartRequest {
config: IProcessConfig;
}
export interface StartResponse {
processId: string;
pid?: number;
status: 'online' | 'stopped' | 'errored';
}
// Stop command
export interface StopRequest {
id: string;
}
export interface StopResponse {
success: boolean;
message?: string;
}
// Restart command
export interface RestartRequest {
id: string;
}
export interface RestartResponse {
processId: string;
pid?: number;
status: 'online' | 'stopped' | 'errored';
}
// Delete command
export interface DeleteRequest {
id: string;
}
export interface DeleteResponse {
success: boolean;
message?: string;
}
// List command
export interface ListRequest {
// No parameters needed
}
export interface ListResponse {
processes: IProcessInfo[];
}
// Describe command
export interface DescribeRequest {
id: string;
}
export interface DescribeResponse {
processInfo: IProcessInfo;
config: IProcessConfig;
}
// Get logs command
export interface GetLogsRequest {
id: string;
lines?: number;
}
export interface GetLogsResponse {
logs: IProcessLog[];
}
// Start all command
export interface StartAllRequest {
// No parameters needed
}
export interface StartAllResponse {
started: string[];
failed: Array<{
id: string;
error: string;
}>;
}
// Stop all command
export interface StopAllRequest {
// No parameters needed
}
export interface StopAllResponse {
stopped: string[];
failed: Array<{
id: string;
error: string;
}>;
}
// Restart all command
export interface RestartAllRequest {
// No parameters needed
}
export interface RestartAllResponse {
restarted: string[];
failed: Array<{
id: string;
error: string;
}>;
}
// Daemon status command
export interface DaemonStatusRequest {
// No parameters needed
}
export interface DaemonStatusResponse {
status: 'running' | 'stopped';
pid?: number;
uptime?: number;
processCount: number;
memoryUsage?: number;
cpuUsage?: number;
}
// Daemon shutdown command
export interface DaemonShutdownRequest {
graceful?: boolean;
timeout?: number; // milliseconds
}
export interface DaemonShutdownResponse {
success: boolean;
message?: string;
}
// Heartbeat command
export interface HeartbeatRequest {
// No parameters needed
}
export interface HeartbeatResponse {
timestamp: number;
status: 'healthy' | 'degraded';
}
// Type mappings for methods
export type IpcMethodMap = {
start: { request: StartRequest; response: StartResponse };
stop: { request: StopRequest; response: StopResponse };
restart: { request: RestartRequest; response: RestartResponse };
delete: { request: DeleteRequest; response: DeleteResponse };
list: { request: ListRequest; response: ListResponse };
describe: { request: DescribeRequest; response: DescribeResponse };
getLogs: { request: GetLogsRequest; response: GetLogsResponse };
startAll: { request: StartAllRequest; response: StartAllResponse };
stopAll: { request: StopAllRequest; response: StopAllResponse };
restartAll: { request: RestartAllRequest; response: RestartAllResponse };
'daemon:status': {
request: DaemonStatusRequest;
response: DaemonStatusResponse;
};
'daemon:shutdown': {
request: DaemonShutdownRequest;
response: DaemonShutdownResponse;
};
heartbeat: { request: HeartbeatRequest; response: HeartbeatResponse };
};
// Helper type to extract request type for a method
export type RequestForMethod<M extends keyof IpcMethodMap> =
IpcMethodMap[M]['request'];
// Helper type to extract response type for a method
export type ResponseForMethod<M extends keyof IpcMethodMap> =
IpcMethodMap[M]['response'];