@ts-rest/express
Advanced tools
Comparing version 2.0.1 to 2.1.0
# @ts-rest/express | ||
## 2.1.0 | ||
### Minor Changes | ||
- 75f157a: Add Zod validation to @ts-rest/next | ||
## 2.0.1 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@ts-rest/express", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"type": "commonjs", | ||
@@ -11,5 +11,5 @@ "main": "./src/index.js", | ||
"zod": "^3.18.0", | ||
"@ts-rest/core": "2.0.1", | ||
"@swc/helpers": "~0.4.3" | ||
"@ts-rest/core": "2.1.0", | ||
"@swc/helpers": "~0.4.11" | ||
} | ||
} |
@@ -37,3 +37,3 @@ "use strict"; | ||
app.get(path, async (req, res)=>{ | ||
const zodQueryIssues = returnZodErrorsIfZodSchema(schema.query, req.query); | ||
const zodQueryIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.query, req.query); | ||
if (zodQueryIssues.length > 0) { | ||
@@ -58,3 +58,3 @@ return res.status(400).json({ | ||
try { | ||
const zodBodyIssues = returnZodErrorsIfZodSchema(schema.body, req.body); | ||
const zodBodyIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.body, req.body); | ||
if (zodBodyIssues.length > 0) { | ||
@@ -65,3 +65,3 @@ return res.status(400).json({ | ||
} | ||
const zodQueryIssues = returnZodErrorsIfZodSchema(schema.query, req.query); | ||
const zodQueryIssues = (0, _core.returnZodErrorsIfZodSchema)(schema.query, req.query); | ||
if (zodQueryIssues.length > 0) { | ||
@@ -101,13 +101,2 @@ return res.status(400).json({ | ||
}; | ||
const returnZodErrorsIfZodSchema = (schema, body)=>{ | ||
const bodySchema = schema; | ||
if (bodySchema && bodySchema._def && bodySchema._def.typeName === 'ZodObject') { | ||
// Check body schema | ||
const parsed = bodySchema.safeParse(body); | ||
if (parsed.success === false) { | ||
return parsed.error.issues; | ||
} | ||
} | ||
return []; | ||
}; | ||
const createExpressEndpoints = (schema, router, app)=>{ | ||
@@ -114,0 +103,0 @@ recursivelyApplyExpressRouter(router, [], (route, path)=>{ |
Sorry, the diff of this file is not supported yet
17982
146