express-zod-safe 1.3.3 → 1.4.0

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.
Files changed (2) hide show
  1. package/dist/index.js +13 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -12,7 +21,7 @@ const emptyObjectSchema = zod_1.z.object({}).strict();
12
21
  * @returns Whether the provided schema is a ZodSchema.
13
22
  */
14
23
  function isZodSchema(schema) {
15
- return !!schema && typeof schema.safeParse === 'function';
24
+ return !!schema && typeof schema.safeParseAsync === 'function';
16
25
  }
17
26
  // Override express@^5 request.query getter to provider setter
18
27
  const descriptor = Object.getOwnPropertyDescriptor(express_1.default.request, 'query');
@@ -77,12 +86,12 @@ function validate(schemas) {
77
86
  query: isZodSchema(schemas.query) ? schemas.query : zod_1.z.object((_b = schemas.query) !== null && _b !== void 0 ? _b : {}).strict(),
78
87
  body: isZodSchema(schemas.body) ? schemas.body : zod_1.z.object((_c = schemas.body) !== null && _c !== void 0 ? _c : {}).strict()
79
88
  };
80
- return (req, res, next) => {
89
+ return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
81
90
  var _a;
82
91
  const errors = [];
83
92
  // Validate all types (params, query, body)
84
93
  for (const type of types) {
85
- const parsed = validation[type].safeParse((_a = req[type]) !== null && _a !== void 0 ? _a : {});
94
+ const parsed = yield validation[type].safeParseAsync((_a = req[type]) !== null && _a !== void 0 ? _a : {});
86
95
  if (parsed.success)
87
96
  req[type] = parsed.data;
88
97
  else
@@ -97,6 +106,6 @@ function validate(schemas) {
97
106
  return;
98
107
  }
99
108
  return next();
100
- };
109
+ });
101
110
  }
102
111
  module.exports = validate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-zod-safe",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
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": {