Skip to content

Commit

Permalink
Fix merge inputs (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiu Liancheng <[email protected]>
Co-authored-by: Devinda Senanayaka <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 4ea2416 commit bcc8d81
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
17 changes: 17 additions & 0 deletions packages/dev-app/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 0 additions & 1 deletion packages/trpc-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
"tslib": "^2.4.1",
"typescript": "^5.4.5",
"url": "^0.11.0",
"zod": "^3.19.1",
"zustand": "^4.1.5"
},
"dependencies": {
Expand Down
20 changes: 18 additions & 2 deletions packages/trpc-panel/src/parse/parseProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,26 @@ function nodeAndInputSchemaFromInputs(
}),
};
}
if (inputs.length !== 1) {

let input = inputs[0];
if (inputs.length < 1) {
return { parseInputResult: "failure" };
}
const input = inputs[0];

if (inputs.length > 1) {
const allInputsAreZodObjects = inputs.every(
(input) => input instanceof z.ZodObject
);
if (!allInputsAreZodObjects) {
return { parseInputResult: "failure" };
}

input = inputs.reduce(
(acc, input: z.AnyZodObject) => (acc as z.AnyZodObject).merge(input),
emptyZodObject
);
}

const iType = inputType(input);
if (iType == "unsupported") {
return { parseInputResult: "failure" };
Expand Down

0 comments on commit bcc8d81

Please sign in to comment.