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

Function createRouterClient

packages/server/src/router-client.ts:27–71  ·  view source on GitHub ↗
(
  router: Lazyable<T | undefined>,
  ...rest: MaybeOptionalOptions<
    CreateProcedureClientOptions<
      InferRouterInitialContext<T>,
      Schema<unknown, unknown>,
      ErrorMap,
      Meta,
      TClientContext
    >
  >
)

Source from the content-addressed store, hash-verified

25 * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
26 */
27export 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}

Callers 8

orpc.server.tsFile · 0.90
orpc.tsFile · 0.90
orpc.server.tsFile · 0.90
orpc.server.tsFile · 0.90
getFunction · 0.85

Calls 5

isProcedureFunction · 0.90
createProcedureClientFunction · 0.90
isLazyFunction · 0.90

Tested by

no test coverage detected