| 338 | const handler = procOptions[name] as Function; |
| 339 | |
| 340 | const invokeWithClient = async (client: any, _input: unknown) => { |
| 341 | let proceed = async (nextInput: unknown) => { |
| 342 | const sanitizedNextInput = |
| 343 | nextInput && typeof nextInput === 'object' && !Array.isArray(nextInput) ? nextInput : {}; |
| 344 | |
| 345 | return handler({ client, ...sanitizedNextInput }); |
| 346 | }; |
| 347 | |
| 348 | // apply plugins |
| 349 | const plugins = [...(client.$options?.plugins ?? [])]; |
| 350 | for (const plugin of plugins) { |
| 351 | const onProcedure = plugin.onProcedure; |
| 352 | if (onProcedure) { |
| 353 | const _proceed = proceed; |
| 354 | proceed = (nextInput: unknown) => |
| 355 | onProcedure({ |
| 356 | client, |
| 357 | name, |
| 358 | mutation: !!procDef.mutation, |
| 359 | input: nextInput, |
| 360 | proceed: (finalInput: unknown) => _proceed(finalInput), |
| 361 | }) as Promise<unknown>; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | return proceed(_input); |
| 366 | }; |
| 367 | |
| 368 | return invokeWithClient(this as any, validatedInput); |
| 369 | } |