(router: AnyRouter)
| 9 | * Help RPCLink automatically send requests using the specified HTTP method in the router. |
| 10 | */ |
| 11 | export 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 | } |
no test coverage detected