-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathutils.ts
More file actions
28 lines (26 loc) · 777 Bytes
/
Copy pathutils.ts
File metadata and controls
28 lines (26 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import type { RpcContext, RpcFunctionDefinition, RpcFunctionType } from './types'
export function defineRpcFunction<
NAME extends string,
TYPE extends RpcFunctionType,
ARGS extends any[],
RETURN = void,
>(
definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN>,
): RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN> {
return definition
}
export async function getRpcHandler<
NAME extends string,
TYPE extends RpcFunctionType,
ARGS extends any[],
RETURN = void,
>(
definition: RpcFunctionDefinition<NAME, TYPE, ARGS, RETURN>,
context: RpcContext,
): Promise<(...args: ARGS) => RETURN> {
if (definition.handler) {
return definition.handler
}
const result = definition.__resolved ??= await definition.setup(context)
return result.handler
}