From 26055d3f9aa21ea5d8712e83a28d97a7ee2b0c92 Mon Sep 17 00:00:00 2001 From: Jiu Liancheng Date: Wed, 12 Apr 2023 20:24:00 +0800 Subject: [PATCH] feat: add support for nested inputs --- packages/dev-app/src/router.ts | 17 +++++++++++++++++ packages/trpc-panel/src/parse/parseProcedure.ts | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/dev-app/src/router.ts b/packages/dev-app/src/router.ts index b7e8a8d..6f63b2f 100644 --- a/packages/dev-app/src/router.ts +++ b/packages/dev-app/src/router.ts @@ -31,6 +31,23 @@ const postsRouter = createTRPCRouter({ text: input.text, }; }), + createNestedPost: procedure + .input( + z.object({ + text: z.string(), + }) + ) + .input( + z.object({ + title: z.string(), + }) + ) + .mutation(({ input }) => { + return { + id: "aoisdjfoasidjfasodf", + text: input.text, + }; + }), }); export const appRouter = createTRPCRouter({ diff --git a/packages/trpc-panel/src/parse/parseProcedure.ts b/packages/trpc-panel/src/parse/parseProcedure.ts index 87748e9..2f41798 100644 --- a/packages/trpc-panel/src/parse/parseProcedure.ts +++ b/packages/trpc-panel/src/parse/parseProcedure.ts @@ -73,10 +73,11 @@ function nodeAndInputSchemaFromInputs( }), }; } + + let input = inputs[0]; if (inputs.length !== 1) { - return { parseInputResult: "failure" }; + input = inputs.reduce((acc, input) => (acc as any).merge(input), emptyZodObject); } - const input = inputs[0]; const iType = inputType(input); if (iType == "unsupported") { return { parseInputResult: "failure" };