(
router: Lazyable<T | undefined>,
...rest: MaybeOptionalOptions<
CreateProcedureClientOptions<
InferRouterInitialContext<T>,
Schema<unknown, unknown>,
ErrorMap,
Meta,
TClientContext
>
>
)
| 25 | * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs} |
| 26 | */ |
| 27 | export function createRouterClient<T extends AnyRouter, TClientContext extends ClientContext>( |
| 28 | router: Lazyable<T | undefined>, |
| 29 | ...rest: MaybeOptionalOptions< |
| 30 | CreateProcedureClientOptions< |
| 31 | InferRouterInitialContext<T>, |
| 32 | Schema<unknown, unknown>, |
| 33 | ErrorMap, |
| 34 | Meta, |
| 35 | TClientContext |
| 36 | > |
| 37 | > |
| 38 | ): RouterClient<T, TClientContext> { |
| 39 | const options = resolveMaybeOptionalOptions(rest) |
| 40 | |
| 41 | if (isProcedure(router)) { |
| 42 | const caller = createProcedureClient(router, options) |
| 43 | |
| 44 | return caller as any |
| 45 | } |
| 46 | |
| 47 | const procedureCaller = isLazy(router) |
| 48 | ? createProcedureClient(createAssertedLazyProcedure(router), options) |
| 49 | : {} |
| 50 | |
| 51 | const recursive = new Proxy(procedureCaller, { |
| 52 | get(target, key) { |
| 53 | if (typeof key !== 'string') { |
| 54 | return Reflect.get(target, key) |
| 55 | } |
| 56 | |
| 57 | const next = getRouter(router, [key]) |
| 58 | |
| 59 | if (!next) { |
| 60 | return Reflect.get(target, key) |
| 61 | } |
| 62 | |
| 63 | return createRouterClient(next, { |
| 64 | ...rest[0], |
| 65 | path: [...(rest[0]?.path ?? []), key], |
| 66 | } as any) |
| 67 | }, |
| 68 | }) |
| 69 | |
| 70 | return recursive as any |
| 71 | } |
no test coverage detected