(
link: ClientLink<InferClientContext<T>>,
options: createORPCClientOptions = {},
)
| 15 | * @see {@link https://orpc.dev/docs/client/client-side Client-side Client Docs} |
| 16 | */ |
| 17 | export function createORPCClient<T extends NestedClient<any>>( |
| 18 | link: ClientLink<InferClientContext<T>>, |
| 19 | options: createORPCClientOptions = {}, |
| 20 | ): T { |
| 21 | const path = options.path ?? [] |
| 22 | |
| 23 | const procedureClient: Client<InferClientContext<T>, unknown, unknown, Error> = async ( |
| 24 | ...[input, options = {} as FriendlyClientOptions<InferClientContext<T>>] |
| 25 | ) => { |
| 26 | return await link.call(path, input, resolveFriendlyClientOptions(options)) |
| 27 | } |
| 28 | |
| 29 | const recursive = new Proxy(procedureClient, { |
| 30 | get(target, key) { |
| 31 | if (typeof key !== 'string') { |
| 32 | return Reflect.get(target, key) |
| 33 | } |
| 34 | |
| 35 | return createORPCClient(link, { |
| 36 | ...options, |
| 37 | path: [...path, key], |
| 38 | }) |
| 39 | }, |
| 40 | }) |
| 41 | |
| 42 | return preventNativeAwait(recursive) as any |
| 43 | } |
no test coverage detected