Skip to content

Commit c62038f

Browse files
committed
refactor(ghoulscript): refactor rpc call
1 parent 0d0251d commit c62038f

File tree

1 file changed

+6
-2
lines changed
  • packages/ghoulscript/src/rpc

1 file changed

+6
-2
lines changed

packages/ghoulscript/src/rpc/call.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ export type CommandArgs<C extends Commands> = Parameters<Core[C]>
88

99
export type CommandResult<C extends Commands> = ReturnType<Core[C]>
1010

11+
const $core = new Map(Object.entries(core))
12+
1113
export async function callRPC<C extends Commands> (method: C, params: CommandArgs<C>): Promise<CommandResult<C>> {
12-
if (!Object.prototype.hasOwnProperty.call(core, method) || typeof core[method] !== 'function')
14+
const command: ((...args: any[]) => Promise<any>) | undefined = $core.get(method)
15+
16+
if (typeof command !== 'function')
1317
throw new TypeError(`Invalid action: "${method}"`)
1418

15-
return await (core[method] as (...args: any[]) => Promise<any>)(...params)
19+
return await command(...params)
1620
}

0 commit comments

Comments
 (0)