UNPKG

nano-invoke

Version:

Simple IPC client for Nano Framework applications

121 lines 2.96 kB
/** * Nano Framework IPC Client * * Simple, clean invoke function for calling nano backend functions * * @package nano-invoke * @author Imperium Industries * @version 1.0.0 */ export interface IpcRequest { cmd: string; args: Record<string, any>; id?: string; } export interface IpcResponse<T = any> { result?: T; error?: string; code?: string; id?: string; } export interface InvokeConfig { baseUrl?: string; debug?: boolean; timeout?: number; } /** * Configure the invoke client * * @param newConfig - Configuration options */ export declare function configure(newConfig: Partial<InvokeConfig>): void; /** * Simple invoke function for calling nano functions * * @param cmd - Function name to invoke * @param args - Arguments to pass to the function * @returns Promise resolving to the function result */ export declare function invoke<T = any>(cmd: string, args?: Record<string, any>): Promise<T>; export type EventListener<T = any> = (data: T) => void; export declare class EventManager { private ws; private listeners; private reconnectAttempts; private maxReconnectAttempts; private reconnectDelay; /** * Connect to the WebSocket server */ connect(wsUrl?: string): Promise<void>; /** * Disconnect from WebSocket */ disconnect(): void; /** * Subscribe to an event */ on<T = any>(event: string, listener: EventListener<T>): void; /** * Unsubscribe from an event */ off<T = any>(event: string, listener: EventListener<T>): void; /** * Send a message through the WebSocket */ send(message: any): void; private emit; private attemptReconnect; } export declare const events: EventManager; export declare namespace Utils { /** * Ping the nano server */ function ping(): Promise<string>; /** * Get system information */ function getSystemInfo(): Promise<any>; /** * Check if the nano server is accessible */ function isServerRunning(): Promise<boolean>; } export declare namespace Commands { interface SystemInfo { os: string; arch: string; hostname: string; username: string; version: string; } interface FileInfo { path: string; size: number; modified: string; is_directory: boolean; } interface UserInfo { name: string; age: number; email: string; } interface CalculationRequest { operation: 'add' | 'subtract' | 'multiply' | 'divide'; values: number[]; } interface CalculationResult { result: number; operation: string; } } declare const _default: { invoke: typeof invoke; configure: typeof configure; events: EventManager; EventManager: typeof EventManager; Utils: typeof Utils; }; export default _default; //# sourceMappingURL=index.d.ts.map