MCPcopy Create free account
hub / github.com/middleapi/orpc / inferRPCMethodFromRouter

Function inferRPCMethodFromRouter

packages/server/src/link-utils.ts:11–26  ·  view source on GitHub ↗
(router: AnyRouter)

Source from the content-addressed store, hash-verified

9 * Help RPCLink automatically send requests using the specified HTTP method in the router.
10 */
11export function inferRPCMethodFromRouter(router: AnyRouter): (options: unknown, path: readonly string[]) => Promise<Exclude<HTTPMethod, 'HEAD'>> {
12 return async (_, path) => {
13 const { default: procedure } = await unlazy(getRouter(router, path))
14
15 if (!isProcedure(procedure)) {
16 throw new Error(
17 `[inferRPCMethodFromRouter] No valid procedure found at path "${path.join('.')}". `
18 + `This may happen when the router is not properly configured.`,
19 )
20 }
21
22 const method = fallbackContractConfig('defaultMethod', procedure['~orpc'].route.method)
23
24 return method === 'HEAD' ? 'GET' : method
25 }
26}

Callers 2

link-utils.test.tsFile · 0.90

Calls 4

unlazyFunction · 0.90
getRouterFunction · 0.90
isProcedureFunction · 0.90
fallbackContractConfigFunction · 0.90

Tested by

no test coverage detected