| 620 | ) => { |
| 621 | return createZenStackPromise(async (txClient?: ClientContract<any>) => { |
| 622 | let proceed = async (_args: unknown) => { |
| 623 | // prepare args for ext result: strip ext result field names from select/omit, |
| 624 | // inject needs fields into select (recursively handles nested relations) |
| 625 | const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has(operation); |
| 626 | const processedArgs = shouldApplyExtResult |
| 627 | ? prepareArgsForExtResult(_args, model, schema, plugins) |
| 628 | : _args; |
| 629 | |
| 630 | const _handler = txClient ? handler.withClient(txClient) : handler; |
| 631 | const r = await _handler.handle(operation, processedArgs); |
| 632 | if (!r && throwIfNoResult) { |
| 633 | throw createNotFoundError(model); |
| 634 | } |
| 635 | let result: unknown; |
| 636 | if (r && postProcess) { |
| 637 | result = resultProcessor.processResult(r, model, processedArgs); |
| 638 | } else { |
| 639 | result = r ?? null; |
| 640 | } |
| 641 | |
| 642 | // compute ext result fields (recursively handles nested relations) |
| 643 | if (result && shouldApplyExtResult) { |
| 644 | result = applyExtResult(result, model, _args, schema, plugins); |
| 645 | } |
| 646 | |
| 647 | return result; |
| 648 | }; |
| 649 | |
| 650 | // apply plugins |
| 651 | const plugins = [...(client.$options.plugins ?? [])]; |