Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export type TRpcHandlers = {
- listDecks: (data: ListDecksRequest) => Promise<ListDecksResponse>;
- getDeckById: (data: GetDeckByIdRequest) => Promise<GetDeckByIdResponse>;
- scryfallBulkDataLoader: (data: object) => Promise<string[]>;
- createDeck: (data: CreateDeckRequest) => Promise<CreateDeckResponse>;
- };
- export type TRpcEvent = {
- reply: (channel: string, ...args: any[]) => void;
- };
- export type TRpcMain = {
- on: (
- channel: string,
- handler: (event: TRpcEvent, request: RpcRequest<any>) => void
- ) => void;
- };
- export type TRpcServer = {
- [key in keyof TRpcHandlers]: (
- event: TRpcEvent,
- data: RpcRequest<ArgumentTypes<TRpcHandlers[key]>[0]>
- ) => Promise<RPCResponseType<TRpcHandlers[key]>>;
- };
- export type ArgumentTypes<F extends Function> = F extends (
- ...args: infer A
- ) => any
- ? A
- : never;
- export type RPCResponseType<F extends Function> = F extends (
- ...args: any[]
- ) => Promise<infer R>
- ? R
- : never;
- export type RpcRequestType<R> = R extends RpcRequest<infer T> ? T : never;
- export type TRpcClient = {
- [key in keyof TRpcServer]: (
- data: RpcRequestType<ArgumentTypes<TRpcServer[key]>[1]>
- ) => ReturnType<TRpcServer[key]>;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement