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

Function createProcedureClient

packages/server/src/procedure-client.ts:72–165  ·  view source on GitHub ↗
(
  lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>,
  ...rest: MaybeOptionalOptions<
    CreateProcedureClientOptions<
      TInitialContext,
      TOutputSchema,
      TErrorMap,
      TMeta,
      TClientContext
    >
  >
)

Source from the content-addressed store, hash-verified

70 * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs}
71 */
72export function createProcedureClient<
73 TInitialContext extends Context,
74 TInputSchema extends AnySchema,
75 TOutputSchema extends AnySchema,
76 TErrorMap extends ErrorMap,
77 TMeta extends Meta,
78 TClientContext extends ClientContext,
79>(
80 lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>,
81 ...rest: MaybeOptionalOptions<
82 CreateProcedureClientOptions<
83 TInitialContext,
84 TOutputSchema,
85 TErrorMap,
86 TMeta,
87 TClientContext
88 >
89 >
90): ProcedureClient<TClientContext, TInputSchema, TOutputSchema, TErrorMap> {
91 const options = resolveMaybeOptionalOptions(rest)
92
93 return async (...[input, callerOptions]) => {
94 const path = toArray(options.path)
95 const { default: procedure } = await unlazy(lazyableProcedure)
96
97 const clientContext = callerOptions?.context ?? {} as TClientContext // callerOptions.context can be undefined when all field is optional
98 const context = await value(options.context ?? {} as TInitialContext, clientContext)
99 const errors = createORPCErrorConstructorMap(procedure['~orpc'].errorMap)
100
101 const validateError = async (e: unknown) => {
102 if (e instanceof ORPCError) {
103 return await validateORPCError(procedure['~orpc'].errorMap, e)
104 }
105
106 return e
107 }
108
109 try {
110 const output = await runWithSpan(
111 { name: 'call_procedure', signal: callerOptions?.signal },
112 (span) => {
113 span?.setAttribute('procedure.path', [...path])
114
115 return intercept(
116 toArray(options.interceptors),
117 {
118 context,
119 input: input as InferSchemaInput<TInputSchema>, // input only optional when it undefinable so we can safely cast it
120 errors,
121 path,
122 procedure: procedure as AnyProcedure,
123 signal: callerOptions?.signal,
124 lastEventId: callerOptions?.lastEventId,
125 },
126 interceptorOptions => executeProcedureInternal(interceptorOptions.procedure, interceptorOptions),
127 )
128 },
129 )

Callers 8

createFormActionFunction · 0.90
callableMethod · 0.90
actionableMethod · 0.90
callFunction · 0.90
createRouterClientFunction · 0.90
handleMethod · 0.90

Calls 14

toArrayFunction · 0.90
unlazyFunction · 0.90
valueFunction · 0.90
runWithSpanFunction · 0.90
interceptFunction · 0.90
isAsyncIteratorObjectFunction · 0.90
overlayProxyFunction · 0.90
mapEventIteratorFunction · 0.90
asyncIteratorWithSpanFunction · 0.90
executeProcedureInternalFunction · 0.85

Tested by

no test coverage detected