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

Function createJsonifiedRouterClient

packages/openapi/src/router-client.ts:9–49  ·  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

7import { resolveMaybeOptionalOptions } from '@orpc/shared'
8
9export function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(
10 router: Lazyable<T | undefined>,
11 ...rest: MaybeOptionalOptions<
12 CreateProcedureClientOptions<
13 InferRouterInitialContext<T>,
14 Schema<unknown, unknown>,
15 ErrorMap,
16 Meta,
17 TClientContext
18 >
19 >
20): JsonifiedClient<RouterClient<T, TClientContext>> {
21 const options = resolveMaybeOptionalOptions(rest)
22
23 const serializer = new StandardOpenAPISerializer(new StandardOpenAPIJsonSerializer(), new StandardBracketNotationSerializer())
24
25 options.interceptors ??= []
26 options.interceptors.unshift(async (options) => {
27 try {
28 return serializer.deserialize(
29 serializer.serialize(
30 await options.next(),
31 ),
32 )
33 }
34 catch (e) {
35 if (e instanceof ORPCError) {
36 throw createORPCErrorFromJson(serializer.deserialize(
37 serializer.serialize(
38 e.toJSON(),
39 { outputFormat: 'plain' },
40 ),
41 ) as any)
42 }
43
44 throw e
45 }
46 })
47
48 return createRouterClient(router, options) as any
49}

Callers 1

Calls 7

deserializeMethod · 0.95
serializeMethod · 0.95
createORPCErrorFromJsonFunction · 0.90
createRouterClientFunction · 0.90
toJSONMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected