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

Function createSafeClient

packages/client/src/client-safe.ts:24–42  ·  view source on GitHub ↗
(client: T)

Source from the content-addressed store, hash-verified

22 * @see {@link https://orpc.dev/docs/client/error-handling#using-createsafeclient Safe Client Docs}
23 */
24export function createSafeClient<T extends NestedClient<any>>(client: T): SafeClient<T> {
25 const proxy = new Proxy((...args: any[]) => safe((client as any)(...args)), {
26 get(_, prop, receiver) {
27 const value = Reflect.get(client, prop, receiver)
28
29 if (typeof prop !== 'string') {
30 return value
31 }
32
33 if (!isTypescriptObject(value)) {
34 return value
35 }
36
37 return createSafeClient(value as NestedClient<any>)
38 },
39 })
40
41 return proxy as SafeClient<T>
42}

Callers 2

getFunction · 0.85

Calls 1

safeFunction · 0.90

Tested by

no test coverage detected