UNPKG

@ui-tars/electron-ipc

Version:

Type-safe Electron inter-process communication for UI-TARS

30 lines (27 loc) 939 B
import { WebContents } from 'electron'; type ZodSchema<TInput> = { parse: (input: any) => TInput; }; type HandleFunction<TInput = any, TResult = any> = (args: { context: HandleContext; input: TInput; }) => Promise<TResult>; type HandleContext = { sender: WebContents | null; }; type RouterType = Record<string, { handle: HandleFunction; }>; type ClientFromRouter<Router extends RouterType> = { [K in keyof Router]: Router[K]['handle'] extends (options: { context: any; input: infer P; }) => Promise<infer R> ? (input: P) => Promise<R> : never; }; type ServerFromRouter<Router extends RouterType> = { [K in keyof Router]: Router[K]['handle'] extends (options: { context: any; input: infer P; }) => Promise<infer R> ? (input: P) => Promise<R> : never; }; export type { ClientFromRouter as C, HandleFunction as H, RouterType as R, ServerFromRouter as S, ZodSchema as Z };