(
router: Lazyable<T | undefined>,
...rest: MaybeOptionalOptions<
CreateProcedureClientOptions<
InferRouterInitialContext<T>,
Schema<unknown, unknown>,
ErrorMap,
Meta,
TClientContext
>
>
)
| 7 | import { resolveMaybeOptionalOptions } from '@orpc/shared' |
| 8 | |
| 9 | export 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 | } |
no test coverage detected