Skip to content

Commit

Permalink
Merge pull request #6 from iway1/enhancement/string-formats-email-etc
Browse files Browse the repository at this point in the history
Adds format support for strings (url, uuid, email)
  • Loading branch information
iway1 authored Dec 10, 2022
2 parents 519600d + be1840d commit b16088a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/test-app/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ const router = t.router({
.query(() => {
return "It's an input";
}),
emailTextInput: t.procedure
.input(z.object({ email: z.string().email("Bad email") }))
.query(({ input }) => {
return "It's good";
}),
}),

anErrorThrowingRoute: t.procedure
Expand Down
1 change: 1 addition & 0 deletions packages/trpc-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
},
"dependencies": {
"@rollup/plugin-terser": "^0.2.0",
"ajv-formats": "^2.1.1",
"fs": "^0.0.1-security",
"path": "^0.12.7",
"rollup-plugin-terser": "^7.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { RequestResult } from "./RequestResult";
import { CollapsableSection } from "src/react-app/components/CollapsableSection";
import { CloseIcon } from "src/react-app/components/icons/CloseIcon";
import { ObjectField } from "src/react-app/components/form/fields/ObjectField";
import { fullFormats } from "ajv-formats/dist/formats";

const TRPCErrorSchema = z.object({
shape: z.object({
Expand Down Expand Up @@ -90,7 +91,9 @@ export function ProcedureForm({
reset: resetForm,
handleSubmit,
} = useForm({
resolver: ajvResolver(procedure.inputSchema as any),
resolver: ajvResolver(procedure.inputSchema as any, {
formats: fullFormats,
}),
defaultValues: defaultFormValuesForNode(procedure.node),
});

Expand Down

0 comments on commit b16088a

Please sign in to comment.