Skip to content

Commit

Permalink
Merge pull request #12 from iway1/custom-errors
Browse files Browse the repository at this point in the history
Adds custom error messages to supported checks (string regex, etc)
  • Loading branch information
iway1 authored Dec 16, 2022
2 parents 40d8d33 + 8a31ad0 commit 03bce89
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 30 deletions.
8 changes: 7 additions & 1 deletion packages/test-app/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,13 @@ const router = t.router({
return "It's an input";
}),
emailTextInput: t.procedure
.input(z.object({ email: z.string().email("Bad email") }))
.input(
z.object({
email: z
.string()
.email("That's an invalid email (custom message)"),
})
)
.query(({ input }) => {
return "It's good";
}),
Expand Down
21 changes: 8 additions & 13 deletions packages/trpc-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"typings": "lib/src/index.d.ts",
"type": "module",
"scripts": {
"test": "jest",
"build": "npx rollup --config rollup.config.js",
"test": "Echo 'No test specified' && exit 1",
"build": "npx rollup --bundleConfigAsCjs --config rollup.config.js",
"dev": "rollup --config rollup.config.js --watch"
},
"author": "",
Expand Down Expand Up @@ -43,48 +43,43 @@
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-terser": "^0.2.0",
"@rollup/plugin-typescript": "^10.0.1",
"@tanstack/react-query": "^4.18.0",
"@trpc/client": "^10.4.2",
"@trpc/react-query": "^10.4.2",
"@trpc/server": "^10.0.0",
"@types/jest": "^29.2.4",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"ajv": "^8.11.2",
"ajv-formats": "^2.1.1",
"autoprefixer": "^10.4.13",
"devalue": "^4.2.0",
"gulp": "^4.0.2",
"gulp-inline-source": "^4.0.0",
"gulp-replace": "^1.1.3",
"jest": "^29.3.1",
"postcss": "^8.4.19",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.39.5",
"react-hot-toast": "^2.4.0",
"rollup": "^3.6.0",
"rollup": "^3.7.4",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-livereload": "^2.0.5",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-serve": "^2.0.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.8.3",
"superjson": "^1.12.0",
"tailwindcss": "^3.2.4",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"url": "^0.11.0",
"zod": "^3.19.1",
"zod-to-json-schema": "^3.19.1"
"zod": "^3.19.1"
},
"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",
"url": "^0.11.0",
"zod-to-json-schema": "^3.19.3"
"zod-to-json-schema": "^3.20.0"
}
}
11 changes: 5 additions & 6 deletions packages/trpc-panel/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import pkg from "./package.json" assert { type: "json" };
import typescript from "@rollup/plugin-typescript";
import json from "@rollup/plugin-json";
import babel from "@rollup/plugin-babel";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
import replace from "@rollup/plugin-replace";
import { terser } from "rollup-plugin-terser";
import terser from "@rollup/plugin-terser";
import postcss from "rollup-plugin-postcss";
import path from "path";
const isWatching =
process.argv.includes("-w") || process.argv.includes("--watch");
const isWatching = process.env.ROLLUP_WATCH;

export default [
{
input: "src/index.ts",
Expand All @@ -25,8 +24,8 @@ export default [
// commonjs(),
],
output: [
{ file: pkg.main, format: "cjs", sourcemap: true },
{ file: pkg.module, format: "es" },
{ file: "lib/index.js", format: "cjs", sourcemap: true },
{ file: "lib/index.mjs", format: "es" },
],
},
{
Expand Down
9 changes: 2 additions & 7 deletions packages/trpc-panel/src/parse/parse-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ const inputParserMap = {
},
};

const jsonSchemaParserMap = {
zod: zodToJsonSchema,
};

function inputType(_: unknown): SupportedInputType | "unsupported" {
return "zod";
}
Expand Down Expand Up @@ -111,7 +107,7 @@ function nodeAndInputSchemaFromInputs(
if (!inputs.length) {
return {
parseInputResult: "success",
schema: zodToJsonSchema<undefined>(emptyZodObject),
schema: zodToJsonSchema(emptyZodObject, { errorMessages: true }),
node: inputParserMap["zod"](emptyZodObject, {
path: [],
optional: false,
Expand All @@ -127,11 +123,10 @@ function nodeAndInputSchemaFromInputs(
if (iType == "unsupported") {
return { parseInputResult: "failure" };
}
const jsonSchemaParser = jsonSchemaParserMap[iType];

return {
parseInputResult: "success",
schema: jsonSchemaParser(input as any), //
schema: zodToJsonSchema(input as any, { errorMessages: true }), //
node: zodSelectorFunction((input as any)._def, {
path: [],
options,
Expand Down

This file was deleted.

0 comments on commit 03bce89

Please sign in to comment.