express-zod-safe 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,7 +74,7 @@ By default, the `validate` middleware will send a 400 Bad Request response with
74
74
  // ... extending the previous example
75
75
 
76
76
  const handler = (errors, req, res, next) => {
77
- return res.status(400).json({
77
+ res.status(400).json({
78
78
  message: 'Invalid request data',
79
79
  errors: errors.map((error) => error.message),
80
80
  });
package/dist/index.js CHANGED
@@ -57,15 +57,19 @@ function validate(schemas) {
57
57
  body: isZodSchema(schemas.body) ? schemas.body : zod_1.z.object((_c = schemas.body) !== null && _c !== void 0 ? _c : {}).strict()
58
58
  };
59
59
  return (req, res, next) => {
60
- var _a;
60
+ var _a, _b;
61
61
  const errors = [];
62
62
  // Validate all types (params, query, body)
63
63
  for (const type of types) {
64
64
  const parsed = validation[type].safeParse((_a = req[type]) !== null && _a !== void 0 ? _a : {});
65
- if (parsed.success)
66
- req[type] = parsed.data;
67
- else
65
+ if (parsed.success) {
66
+ const writable = (_b = Object.getOwnPropertyDescriptor(req, type)) === null || _b === void 0 ? void 0 : _b.writable;
67
+ if (writable)
68
+ req[type] = parsed.data;
69
+ }
70
+ else {
68
71
  errors.push({ type, errors: parsed.error });
72
+ }
69
73
  }
70
74
  // Return all errors if there are any
71
75
  if (errors.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-zod-safe",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "TypeScript-friendly middleware designed for Express applications, leveraging the robustness of Zod schemas to validate incoming request bodies, parameters, and queries.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -24,9 +24,9 @@
24
24
  "devDependencies": {
25
25
  "@angablue/biome-config": "^1.0.1",
26
26
  "@biomejs/biome": "^1.9.4",
27
- "@types/node": "^22.10.2",
27
+ "@types/node": "^22.13.0",
28
28
  "rimraf": "^6.0.1",
29
- "typescript": "^5.7.2",
29
+ "typescript": "^5.7.3",
30
30
  "zod": "^3.24.1"
31
31
  },
32
32
  "peerDependencies": {