@mastra/express 1.1.9-alpha.0 → 1.2.0-alpha.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @mastra/express
2
2
 
3
+ ## 1.2.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `onValidationError` hook to `ServerConfig` and `createRoute()`. When a request fails Zod schema validation (query parameters, request body, or path parameters), this hook lets you customize the error response — including the HTTP status code and response body — instead of the default 400 response. Set it on the server config to apply globally, or on individual routes to override per-route. All server adapters (Hono, Express, Fastify, Koa) support this hook. ([#13477](https://github.com/mastra-ai/mastra/pull/13477))
8
+
9
+ ```ts
10
+ const mastra = new Mastra({
11
+ server: {
12
+ onValidationError: (error, context) => ({
13
+ status: 422,
14
+ body: {
15
+ ok: false,
16
+ errors: error.issues.map(i => ({
17
+ path: i.path.join('.'),
18
+ message: i.message,
19
+ })),
20
+ source: context,
21
+ },
22
+ }),
23
+ },
24
+ });
25
+ ```
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [[`4f71b43`](https://github.com/mastra-ai/mastra/commit/4f71b436a4a6b8839842d8da47b57b84509af56c), [`a070277`](https://github.com/mastra-ai/mastra/commit/a07027766ce195ba74d0783116d894cbab25d44c), [`b628b91`](https://github.com/mastra-ai/mastra/commit/b628b9128b372c0f54214d902b07279f03443900), [`332c014`](https://github.com/mastra-ai/mastra/commit/332c014e076b81edf7fe45b58205882726415e90), [`6b63153`](https://github.com/mastra-ai/mastra/commit/6b63153878ea841c0f4ce632ba66bb33e57e9c1b), [`4246e34`](https://github.com/mastra-ai/mastra/commit/4246e34cec9c26636d0965942268e6d07c346671), [`b8837ee`](https://github.com/mastra-ai/mastra/commit/b8837ee77e2e84197609762bfabd8b3da326d30c), [`5d950f7`](https://github.com/mastra-ai/mastra/commit/5d950f7bf426a215a1808f0abef7de5c8336ba1c), [`28c85b1`](https://github.com/mastra-ai/mastra/commit/28c85b184fc32b40f7f160483c982da6d388ecbd), [`e9a08fb`](https://github.com/mastra-ai/mastra/commit/e9a08fbef1ada7e50e961e2f54f55e8c10b4a45c), [`631ffd8`](https://github.com/mastra-ai/mastra/commit/631ffd82fed108648b448b28e6a90e38c5f53bf5), [`aae2295`](https://github.com/mastra-ai/mastra/commit/aae2295838a2d329ad6640829e87934790ffe5b8), [`aa61f29`](https://github.com/mastra-ai/mastra/commit/aa61f29ff8095ce46a4ae16e46c4d8c79b2b685b), [`7ff3714`](https://github.com/mastra-ai/mastra/commit/7ff37148515439bb3be009a60e02c3e363299760), [`41d79a1`](https://github.com/mastra-ai/mastra/commit/41d79a14bd8cb6de1e2565fd0a04786bae2f211b), [`0c57b8b`](https://github.com/mastra-ai/mastra/commit/0c57b8b0a69a97b5a4ae3f79be6c610f29f3cf7b), [`e673376`](https://github.com/mastra-ai/mastra/commit/e6733763ad1321aa7e5ae15096b9c2104f93b1f3), [`b2204c9`](https://github.com/mastra-ai/mastra/commit/b2204c98a42848bbfb6f0440f005dc2b6354f1cd), [`a1bf1e3`](https://github.com/mastra-ai/mastra/commit/a1bf1e385ed4c0ef6f11b56c5887442970d127f2), [`b6f647a`](https://github.com/mastra-ai/mastra/commit/b6f647ae2388e091f366581595feb957e37d5b40), [`0c57b8b`](https://github.com/mastra-ai/mastra/commit/0c57b8b0a69a97b5a4ae3f79be6c610f29f3cf7b), [`b081f27`](https://github.com/mastra-ai/mastra/commit/b081f272cf411716e1d6bd72ceac4bcee2657b19), [`0c09eac`](https://github.com/mastra-ai/mastra/commit/0c09eacb1926f64cfdc9ae5c6d63385cf8c9f72c), [`6b9b93d`](https://github.com/mastra-ai/mastra/commit/6b9b93d6f459d1ba6e36f163abf62a085ddb3d64), [`31b6067`](https://github.com/mastra-ai/mastra/commit/31b6067d0cc3ab10e1b29c36147f3b5266bc714a), [`797ac42`](https://github.com/mastra-ai/mastra/commit/797ac4276de231ad2d694d9aeca75980f6cd0419), [`0bc289e`](https://github.com/mastra-ai/mastra/commit/0bc289e2d476bf46c5b91c21969e8d0c6864691c), [`9b75a06`](https://github.com/mastra-ai/mastra/commit/9b75a06e53ebb0b950ba7c1e83a0142047185f46), [`4c3a1b1`](https://github.com/mastra-ai/mastra/commit/4c3a1b122ea083e003d71092f30f3b31680b01c0), [`85cc3b3`](https://github.com/mastra-ai/mastra/commit/85cc3b3b6f32ae4b083c26498f50d5b250ba944b), [`c2afbbc`](https://github.com/mastra-ai/mastra/commit/c2afbbccada13af07cad6742456f3f067ccd6519), [`97ea28c`](https://github.com/mastra-ai/mastra/commit/97ea28c746e9e4147d56047bbb1c4a92417a3fec), [`d567299`](https://github.com/mastra-ai/mastra/commit/d567299cf81e02bd9d5221d4bc05967d6c224161), [`716ffe6`](https://github.com/mastra-ai/mastra/commit/716ffe68bed81f7c2690bc8581b9e140f7bf1c3d), [`8296332`](https://github.com/mastra-ai/mastra/commit/8296332de21c16e3dfc3d0b2d615720a6dc88f2f), [`4df2116`](https://github.com/mastra-ai/mastra/commit/4df211619dd922c047d396ca41cd7027c8c4c8e7), [`2219c1a`](https://github.com/mastra-ai/mastra/commit/2219c1acbd21da116da877f0036ffb985a9dd5a3), [`17c4145`](https://github.com/mastra-ai/mastra/commit/17c4145166099354545582335b5252bdfdfd908b)]:
30
+ - @mastra/core@1.11.0-alpha.0
31
+ - @mastra/server@1.11.0-alpha.0
32
+
33
+ ## 1.1.9
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [[`41e48c1`](https://github.com/mastra-ai/mastra/commit/41e48c198eee846478e60c02ec432c19d322a517), [`82469d3`](https://github.com/mastra-ai/mastra/commit/82469d3135d5a49dd8dc8feec0ff398b4e0225a0), [`33e2fd5`](https://github.com/mastra-ai/mastra/commit/33e2fd5088f83666df17401e2da68c943dbc0448), [`7ef6e2c`](https://github.com/mastra-ai/mastra/commit/7ef6e2c61be5a42e26f55d15b5902866fc76634f), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`fa37d39`](https://github.com/mastra-ai/mastra/commit/fa37d39910421feaf8847716292e3d65dd4f30c2), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`71c38bf`](https://github.com/mastra-ai/mastra/commit/71c38bf905905148ecd0e75c07c1f9825d299b76), [`f993c38`](https://github.com/mastra-ai/mastra/commit/f993c3848c97479b813231be872443bedeced6ab), [`f51849a`](https://github.com/mastra-ai/mastra/commit/f51849a568935122b5100b7ee69704e6d680cf7b), [`9bf3a0d`](https://github.com/mastra-ai/mastra/commit/9bf3a0dac602787925f1762f1f0387d7b4a59620), [`cafa045`](https://github.com/mastra-ai/mastra/commit/cafa0453c9de141ad50c09a13894622dffdd9978), [`1fd9ddb`](https://github.com/mastra-ai/mastra/commit/1fd9ddbb3fe83b281b12bd2e27e426ae86288266), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443), [`b12d2a5`](https://github.com/mastra-ai/mastra/commit/b12d2a59a48be0477cabae66eb6cf0fc94a7d40d), [`d9d228c`](https://github.com/mastra-ai/mastra/commit/d9d228c0c6ae82ae6ce3b540a3a56b2b1c2b8d98), [`5576507`](https://github.com/mastra-ai/mastra/commit/55765071e360fb97e443aa0a91ccf7e1cd8d92aa), [`79d69c9`](https://github.com/mastra-ai/mastra/commit/79d69c9d5f842ff1c31352fb6026f04c1f6190f3), [`9fb4c06`](https://github.com/mastra-ai/mastra/commit/9fb4c06ccab62a1940845fc6eed7f944e5ccd951), [`94f44b8`](https://github.com/mastra-ai/mastra/commit/94f44b827ce57b179e50f4916a84c0fa6e7f3b8c), [`13187db`](https://github.com/mastra-ai/mastra/commit/13187dbac880174232dedc5a501ff6c5d0fe59bc), [`2ae5311`](https://github.com/mastra-ai/mastra/commit/2ae531185fff66a80fa165c0999e3d801900e89d), [`b5a8ea5`](https://github.com/mastra-ai/mastra/commit/b5a8ea50d3718c31efca271b45498c8485c67b42), [`6135ef4`](https://github.com/mastra-ai/mastra/commit/6135ef4f5288652bf45f616ec590607e4c95f443)]:
38
+ - @mastra/core@1.10.0
39
+ - @mastra/server@1.10.0
40
+
3
41
  ## 1.1.9-alpha.0
4
42
 
5
43
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2,217 +2,217 @@
2
2
 
3
3
  var busboy = require('@fastify/busboy');
4
4
  var auth = require('@mastra/server/auth');
5
- var error = require('@mastra/server/handlers/error');
6
5
  var serverAdapter = require('@mastra/server/server-adapter');
7
6
 
8
7
  // src/index.ts
9
-
10
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
11
- var util;
12
- (function(util2) {
13
- util2.assertEqual = (_) => {
14
- };
15
- function assertIs(_arg) {
16
- }
17
- util2.assertIs = assertIs;
18
- function assertNever(_x) {
19
- throw new Error();
20
- }
21
- util2.assertNever = assertNever;
22
- util2.arrayToEnum = (items) => {
23
- const obj = {};
24
- for (const item of items) {
25
- obj[item] = item;
8
+ // @__NO_SIDE_EFFECTS__
9
+ function $constructor(name, initializer3, params) {
10
+ function init(inst, def) {
11
+ if (!inst._zod) {
12
+ Object.defineProperty(inst, "_zod", {
13
+ value: {
14
+ def,
15
+ constr: _,
16
+ traits: /* @__PURE__ */ new Set()
17
+ },
18
+ enumerable: false
19
+ });
26
20
  }
27
- return obj;
28
- };
29
- util2.getValidEnumValues = (obj) => {
30
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
31
- const filtered = {};
32
- for (const k of validKeys) {
33
- filtered[k] = obj[k];
21
+ if (inst._zod.traits.has(name)) {
22
+ return;
34
23
  }
35
- return util2.objectValues(filtered);
36
- };
37
- util2.objectValues = (obj) => {
38
- return util2.objectKeys(obj).map(function(e) {
39
- return obj[e];
40
- });
41
- };
42
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
43
- const keys = [];
44
- for (const key in object) {
45
- if (Object.prototype.hasOwnProperty.call(object, key)) {
46
- keys.push(key);
24
+ inst._zod.traits.add(name);
25
+ initializer3(inst, def);
26
+ const proto = _.prototype;
27
+ const keys = Object.keys(proto);
28
+ for (let i = 0; i < keys.length; i++) {
29
+ const k = keys[i];
30
+ if (!(k in inst)) {
31
+ inst[k] = proto[k].bind(inst);
47
32
  }
48
33
  }
49
- return keys;
50
- };
51
- util2.find = (arr, checker) => {
52
- for (const item of arr) {
53
- if (checker(item))
54
- return item;
34
+ }
35
+ const Parent = params?.Parent ?? Object;
36
+ class Definition extends Parent {
37
+ }
38
+ Object.defineProperty(Definition, "name", { value: name });
39
+ function _(def) {
40
+ var _a2;
41
+ const inst = params?.Parent ? new Definition() : this;
42
+ init(inst, def);
43
+ (_a2 = inst._zod).deferred ?? (_a2.deferred = []);
44
+ for (const fn of inst._zod.deferred) {
45
+ fn();
55
46
  }
56
- return void 0;
57
- };
58
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
59
- function joinValues(array, separator = " | ") {
60
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
47
+ return inst;
61
48
  }
62
- util2.joinValues = joinValues;
63
- util2.jsonStringifyReplacer = (_, value) => {
64
- if (typeof value === "bigint") {
65
- return value.toString();
49
+ Object.defineProperty(_, "init", { value: init });
50
+ Object.defineProperty(_, Symbol.hasInstance, {
51
+ value: (inst) => {
52
+ if (params?.Parent && inst instanceof params.Parent)
53
+ return true;
54
+ return inst?._zod?.traits?.has(name);
66
55
  }
67
- return value;
68
- };
69
- })(util || (util = {}));
70
- var objectUtil;
71
- (function(objectUtil2) {
72
- objectUtil2.mergeShapes = (first, second) => {
73
- return {
74
- ...first,
75
- ...second
76
- // second overwrites first
77
- };
78
- };
79
- })(objectUtil || (objectUtil = {}));
80
- util.arrayToEnum([
81
- "string",
82
- "nan",
83
- "number",
84
- "integer",
85
- "float",
86
- "boolean",
87
- "date",
88
- "bigint",
89
- "symbol",
90
- "function",
91
- "undefined",
92
- "null",
93
- "array",
94
- "object",
95
- "unknown",
96
- "promise",
97
- "void",
98
- "never",
99
- "map",
100
- "set"
101
- ]);
56
+ });
57
+ Object.defineProperty(_, "name", { value: name });
58
+ return _;
59
+ }
102
60
 
103
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
104
- util.arrayToEnum([
105
- "invalid_type",
106
- "invalid_literal",
107
- "custom",
108
- "invalid_union",
109
- "invalid_union_discriminator",
110
- "invalid_enum_value",
111
- "unrecognized_keys",
112
- "invalid_arguments",
113
- "invalid_return_type",
114
- "invalid_date",
115
- "invalid_string",
116
- "too_small",
117
- "too_big",
118
- "invalid_intersection_types",
119
- "not_multiple_of",
120
- "not_finite"
121
- ]);
122
- var ZodError = class _ZodError extends Error {
123
- get errors() {
124
- return this.issues;
125
- }
126
- constructor(issues) {
127
- super();
128
- this.issues = [];
129
- this.addIssue = (sub) => {
130
- this.issues = [...this.issues, sub];
131
- };
132
- this.addIssues = (subs = []) => {
133
- this.issues = [...this.issues, ...subs];
134
- };
135
- const actualProto = new.target.prototype;
136
- if (Object.setPrototypeOf) {
137
- Object.setPrototypeOf(this, actualProto);
61
+ // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js
62
+ function jsonStringifyReplacer(_, value) {
63
+ if (typeof value === "bigint")
64
+ return value.toString();
65
+ return value;
66
+ }
67
+
68
+ // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js
69
+ var initializer = (inst, def) => {
70
+ inst.name = "$ZodError";
71
+ Object.defineProperty(inst, "_zod", {
72
+ value: inst._zod,
73
+ enumerable: false
74
+ });
75
+ Object.defineProperty(inst, "issues", {
76
+ value: def,
77
+ enumerable: false
78
+ });
79
+ inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
80
+ Object.defineProperty(inst, "toString", {
81
+ value: () => inst.message,
82
+ enumerable: false
83
+ });
84
+ };
85
+ var $ZodError = $constructor("$ZodError", initializer);
86
+ function flattenError(error, mapper = (issue2) => issue2.message) {
87
+ const fieldErrors = {};
88
+ const formErrors = [];
89
+ for (const sub of error.issues) {
90
+ if (sub.path.length > 0) {
91
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
92
+ fieldErrors[sub.path[0]].push(mapper(sub));
138
93
  } else {
139
- this.__proto__ = actualProto;
94
+ formErrors.push(mapper(sub));
140
95
  }
141
- this.name = "ZodError";
142
- this.issues = issues;
143
96
  }
144
- format(_mapper) {
145
- const mapper = _mapper || function(issue) {
146
- return issue.message;
147
- };
148
- const fieldErrors = { _errors: [] };
149
- const processError = (error) => {
150
- for (const issue of error.issues) {
151
- if (issue.code === "invalid_union") {
152
- issue.unionErrors.map(processError);
153
- } else if (issue.code === "invalid_return_type") {
154
- processError(issue.returnTypeError);
155
- } else if (issue.code === "invalid_arguments") {
156
- processError(issue.argumentsError);
157
- } else if (issue.path.length === 0) {
158
- fieldErrors._errors.push(mapper(issue));
159
- } else {
160
- let curr = fieldErrors;
161
- let i = 0;
162
- while (i < issue.path.length) {
163
- const el = issue.path[i];
164
- const terminal = i === issue.path.length - 1;
165
- if (!terminal) {
166
- curr[el] = curr[el] || { _errors: [] };
167
- } else {
168
- curr[el] = curr[el] || { _errors: [] };
169
- curr[el]._errors.push(mapper(issue));
170
- }
171
- curr = curr[el];
172
- i++;
97
+ return { formErrors, fieldErrors };
98
+ }
99
+ function formatError(error, mapper = (issue2) => issue2.message) {
100
+ const fieldErrors = { _errors: [] };
101
+ const processError = (error2) => {
102
+ for (const issue2 of error2.issues) {
103
+ if (issue2.code === "invalid_union" && issue2.errors.length) {
104
+ issue2.errors.map((issues) => processError({ issues }));
105
+ } else if (issue2.code === "invalid_key") {
106
+ processError({ issues: issue2.issues });
107
+ } else if (issue2.code === "invalid_element") {
108
+ processError({ issues: issue2.issues });
109
+ } else if (issue2.path.length === 0) {
110
+ fieldErrors._errors.push(mapper(issue2));
111
+ } else {
112
+ let curr = fieldErrors;
113
+ let i = 0;
114
+ while (i < issue2.path.length) {
115
+ const el = issue2.path[i];
116
+ const terminal = i === issue2.path.length - 1;
117
+ if (!terminal) {
118
+ curr[el] = curr[el] || { _errors: [] };
119
+ } else {
120
+ curr[el] = curr[el] || { _errors: [] };
121
+ curr[el]._errors.push(mapper(issue2));
173
122
  }
123
+ curr = curr[el];
124
+ i++;
174
125
  }
175
126
  }
176
- };
177
- processError(this);
178
- return fieldErrors;
179
- }
180
- static assert(value) {
181
- if (!(value instanceof _ZodError)) {
182
- throw new Error(`Not a ZodError: ${value}`);
183
127
  }
128
+ };
129
+ processError(error);
130
+ return fieldErrors;
131
+ }
132
+
133
+ // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js
134
+ var _a;
135
+ var $ZodRegistry = class {
136
+ constructor() {
137
+ this._map = /* @__PURE__ */ new WeakMap();
138
+ this._idmap = /* @__PURE__ */ new Map();
184
139
  }
185
- toString() {
186
- return this.message;
140
+ add(schema, ..._meta) {
141
+ const meta = _meta[0];
142
+ this._map.set(schema, meta);
143
+ if (meta && typeof meta === "object" && "id" in meta) {
144
+ this._idmap.set(meta.id, schema);
145
+ }
146
+ return this;
187
147
  }
188
- get message() {
189
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
148
+ clear() {
149
+ this._map = /* @__PURE__ */ new WeakMap();
150
+ this._idmap = /* @__PURE__ */ new Map();
151
+ return this;
190
152
  }
191
- get isEmpty() {
192
- return this.issues.length === 0;
153
+ remove(schema) {
154
+ const meta = this._map.get(schema);
155
+ if (meta && typeof meta === "object" && "id" in meta) {
156
+ this._idmap.delete(meta.id);
157
+ }
158
+ this._map.delete(schema);
159
+ return this;
193
160
  }
194
- flatten(mapper = (issue) => issue.message) {
195
- const fieldErrors = {};
196
- const formErrors = [];
197
- for (const sub of this.issues) {
198
- if (sub.path.length > 0) {
199
- const firstEl = sub.path[0];
200
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
201
- fieldErrors[firstEl].push(mapper(sub));
202
- } else {
203
- formErrors.push(mapper(sub));
204
- }
161
+ get(schema) {
162
+ const p = schema._zod.parent;
163
+ if (p) {
164
+ const pm = { ...this.get(p) ?? {} };
165
+ delete pm.id;
166
+ const f = { ...pm, ...this._map.get(schema) };
167
+ return Object.keys(f).length ? f : void 0;
205
168
  }
206
- return { formErrors, fieldErrors };
169
+ return this._map.get(schema);
207
170
  }
208
- get formErrors() {
209
- return this.flatten();
171
+ has(schema) {
172
+ return this._map.has(schema);
210
173
  }
211
174
  };
212
- ZodError.create = (issues) => {
213
- const error = new ZodError(issues);
214
- return error;
175
+ function registry() {
176
+ return new $ZodRegistry();
177
+ }
178
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
179
+
180
+ // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
181
+ var initializer2 = (inst, issues) => {
182
+ $ZodError.init(inst, issues);
183
+ inst.name = "ZodError";
184
+ Object.defineProperties(inst, {
185
+ format: {
186
+ value: (mapper) => formatError(inst, mapper)
187
+ // enumerable: false,
188
+ },
189
+ flatten: {
190
+ value: (mapper) => flattenError(inst, mapper)
191
+ // enumerable: false,
192
+ },
193
+ addIssue: {
194
+ value: (issue2) => {
195
+ inst.issues.push(issue2);
196
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
197
+ }
198
+ // enumerable: false,
199
+ },
200
+ addIssues: {
201
+ value: (issues2) => {
202
+ inst.issues.push(...issues2);
203
+ inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
204
+ }
205
+ // enumerable: false,
206
+ },
207
+ isEmpty: {
208
+ get() {
209
+ return inst.issues.length === 0;
210
+ }
211
+ // enumerable: false,
212
+ }
213
+ });
215
214
  };
215
+ var ZodError = $constructor("ZodError", initializer2);
216
216
 
217
217
  // src/index.ts
218
218
  var _hasPermissionPromise;
@@ -525,48 +525,51 @@ var MastraServer = class extends serverAdapter.MastraServer {
525
525
  if (params.queryParams) {
526
526
  try {
527
527
  params.queryParams = await this.parseQueryParams(route, params.queryParams);
528
- } catch (error$1) {
528
+ } catch (error) {
529
529
  this.mastra.getLogger()?.error("Error parsing query params", {
530
- error: error$1 instanceof Error ? { message: error$1.message, stack: error$1.stack } : error$1
530
+ error: error instanceof Error ? { message: error.message, stack: error.stack } : error
531
531
  });
532
- if (error$1 instanceof ZodError) {
533
- return res.status(400).json(error.formatZodError(error$1, "query parameters"));
532
+ if (error instanceof ZodError) {
533
+ const { status, body } = this.resolveValidationError(route, error, "query");
534
+ return res.status(status).json(body);
534
535
  }
535
536
  return res.status(400).json({
536
537
  error: "Invalid query parameters",
537
- issues: [{ field: "unknown", message: error$1 instanceof Error ? error$1.message : "Unknown error" }]
538
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
538
539
  });
539
540
  }
540
541
  }
541
542
  if (params.body) {
542
543
  try {
543
544
  params.body = await this.parseBody(route, params.body);
544
- } catch (error$1) {
545
+ } catch (error) {
545
546
  this.mastra.getLogger()?.error("Error parsing body", {
546
- error: error$1 instanceof Error ? { message: error$1.message, stack: error$1.stack } : error$1
547
+ error: error instanceof Error ? { message: error.message, stack: error.stack } : error
547
548
  });
548
- if (error$1 instanceof ZodError) {
549
- return res.status(400).json(error.formatZodError(error$1, "request body"));
549
+ if (error instanceof ZodError) {
550
+ const { status, body } = this.resolveValidationError(route, error, "body");
551
+ return res.status(status).json(body);
550
552
  }
551
553
  return res.status(400).json({
552
554
  error: "Invalid request body",
553
- issues: [{ field: "unknown", message: error$1 instanceof Error ? error$1.message : "Unknown error" }]
555
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
554
556
  });
555
557
  }
556
558
  }
557
559
  if (params.urlParams) {
558
560
  try {
559
561
  params.urlParams = await this.parsePathParams(route, params.urlParams);
560
- } catch (error$1) {
562
+ } catch (error) {
561
563
  this.mastra.getLogger()?.error("Error parsing path params", {
562
- error: error$1 instanceof Error ? { message: error$1.message, stack: error$1.stack } : error$1
564
+ error: error instanceof Error ? { message: error.message, stack: error.stack } : error
563
565
  });
564
- if (error$1 instanceof ZodError) {
565
- return res.status(400).json(error.formatZodError(error$1, "path parameters"));
566
+ if (error instanceof ZodError) {
567
+ const { status, body } = this.resolveValidationError(route, error, "path");
568
+ return res.status(status).json(body);
566
569
  }
567
570
  return res.status(400).json({
568
571
  error: "Invalid path parameters",
569
- issues: [{ field: "unknown", message: error$1 instanceof Error ? error$1.message : "Unknown error" }]
572
+ issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
570
573
  });
571
574
  }
572
575
  }
@@ -685,14 +688,14 @@ var MastraServer = class extends serverAdapter.MastraServer {
685
688
  const method = req.method;
686
689
  const path = req.path;
687
690
  res.on("finish", () => {
688
- const duration = Date.now() - start;
691
+ const duration2 = Date.now() - start;
689
692
  const status = res.statusCode;
690
693
  const level = this.httpLoggingConfig?.level || "info";
691
694
  const logData = {
692
695
  method,
693
696
  path,
694
697
  status,
695
- duration: `${duration}ms`
698
+ duration: `${duration2}ms`
696
699
  };
697
700
  if (this.httpLoggingConfig?.includeQueryParams) {
698
701
  logData.query = req.query;
@@ -708,7 +711,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
708
711
  });
709
712
  logData.headers = headers;
710
713
  }
711
- this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
714
+ this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
712
715
  });
713
716
  next();
714
717
  });