@mastra/express 1.1.9 → 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 +30 -0
- package/dist/index.cjs +205 -202
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +193 -190
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
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
|
+
|
|
3
33
|
## 1.1.9
|
|
4
34
|
|
|
5
35
|
### 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
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
|
|
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.
|
|
104
|
-
|
|
105
|
-
"
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
94
|
+
formErrors.push(mapper(sub));
|
|
140
95
|
}
|
|
141
|
-
this.name = "ZodError";
|
|
142
|
-
this.issues = issues;
|
|
143
96
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
186
|
-
|
|
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
|
-
|
|
189
|
-
|
|
148
|
+
clear() {
|
|
149
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
150
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
151
|
+
return this;
|
|
190
152
|
}
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
|
169
|
+
return this._map.get(schema);
|
|
207
170
|
}
|
|
208
|
-
|
|
209
|
-
return this.
|
|
171
|
+
has(schema) {
|
|
172
|
+
return this._map.has(schema);
|
|
210
173
|
}
|
|
211
174
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
|
528
|
+
} catch (error) {
|
|
529
529
|
this.mastra.getLogger()?.error("Error parsing query params", {
|
|
530
|
-
error: error
|
|
530
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
531
531
|
});
|
|
532
|
-
if (error
|
|
533
|
-
|
|
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
|
|
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
|
|
545
|
+
} catch (error) {
|
|
545
546
|
this.mastra.getLogger()?.error("Error parsing body", {
|
|
546
|
-
error: error
|
|
547
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
547
548
|
});
|
|
548
|
-
if (error
|
|
549
|
-
|
|
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
|
|
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
|
|
562
|
+
} catch (error) {
|
|
561
563
|
this.mastra.getLogger()?.error("Error parsing path params", {
|
|
562
|
-
error: error
|
|
564
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
563
565
|
});
|
|
564
|
-
if (error
|
|
565
|
-
|
|
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
|
|
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
|
|
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: `${
|
|
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} ${
|
|
714
|
+
this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
|
|
712
715
|
});
|
|
713
716
|
next();
|
|
714
717
|
});
|