Skip to content

Commit bcc8d81

Browse files
aidansunburylcjnildca123
authored
Fix merge inputs (#9)
Co-authored-by: Jiu Liancheng <[email protected]> Co-authored-by: Devinda Senanayaka <[email protected]>
1 parent 4ea2416 commit bcc8d81

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

packages/dev-app/src/router.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ const postsRouter = createTRPCRouter({
3131
text: input.text,
3232
};
3333
}),
34+
createNestedPost: procedure
35+
.input(
36+
z.object({
37+
text: z.string(),
38+
})
39+
)
40+
.input(
41+
z.object({
42+
title: z.string(),
43+
})
44+
)
45+
.mutation(({ input }) => {
46+
return {
47+
id: "aoisdjfoasidjfasodf",
48+
text: input.text,
49+
};
50+
}),
3451
});
3552

3653
export const appRouter = createTRPCRouter({

packages/trpc-panel/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"tslib": "^2.4.1",
8585
"typescript": "^5.4.5",
8686
"url": "^0.11.0",
87-
"zod": "^3.19.1",
8887
"zustand": "^4.1.5"
8988
},
9089
"dependencies": {

packages/trpc-panel/src/parse/parseProcedure.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,26 @@ function nodeAndInputSchemaFromInputs(
7676
}),
7777
};
7878
}
79-
if (inputs.length !== 1) {
79+
80+
let input = inputs[0];
81+
if (inputs.length < 1) {
8082
return { parseInputResult: "failure" };
8183
}
82-
const input = inputs[0];
84+
85+
if (inputs.length > 1) {
86+
const allInputsAreZodObjects = inputs.every(
87+
(input) => input instanceof z.ZodObject
88+
);
89+
if (!allInputsAreZodObjects) {
90+
return { parseInputResult: "failure" };
91+
}
92+
93+
input = inputs.reduce(
94+
(acc, input: z.AnyZodObject) => (acc as z.AnyZodObject).merge(input),
95+
emptyZodObject
96+
);
97+
}
98+
8399
const iType = inputType(input);
84100
if (iType == "unsupported") {
85101
return { parseInputResult: "failure" };

0 commit comments

Comments
 (0)