(
lazyableProcedure: Lazyable<Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>>,
...rest: MaybeOptionalOptions<
CreateProcedureClientOptions<
TInitialContext,
TOutputSchema,
TErrorMap,
TMeta,
TClientContext
>
>
)
| 70 | * @see {@link https://orpc.dev/docs/client/server-side Server-side Client Docs} |
| 71 | */ |
| 72 | export 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 | ) |
no test coverage detected