@mastra/fastify 1.1.9 → 1.2.0-alpha.1
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 +38 -0
- package/dist/index.cjs +208 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +196 -193
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @mastra/fastify
|
|
2
2
|
|
|
3
|
+
## 1.2.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`866cc2c`](https://github.com/mastra-ai/mastra/commit/866cc2cb1f0e3b314afab5194f69477fada745d1), [`6bcbf8a`](https://github.com/mastra-ai/mastra/commit/6bcbf8a6774d5a53b21d61db8a45ce2593ca1616), [`18c3a90`](https://github.com/mastra-ai/mastra/commit/18c3a90c9e48cf69500e308affeb8eba5860b2af), [`f35487b`](https://github.com/mastra-ai/mastra/commit/f35487bb2d46c636e22aa71d90025613ae38235a), [`6dc2192`](https://github.com/mastra-ai/mastra/commit/6dc21921aef0f0efab15cd0805fa3d18f277a76f), [`eeb3a3f`](https://github.com/mastra-ai/mastra/commit/eeb3a3f43aca10cf49479eed2a84b7d9ecea02ba), [`05f8d90`](https://github.com/mastra-ai/mastra/commit/05f8d9009290ce6aa03428b3add635268615db85), [`4b8da97`](https://github.com/mastra-ai/mastra/commit/4b8da97a5ce306e97869df6c39535d9069e563db), [`256df35`](https://github.com/mastra-ai/mastra/commit/256df3571d62beb3ad4971faa432927cc140e603)]:
|
|
8
|
+
- @mastra/core@1.11.0-alpha.1
|
|
9
|
+
- @mastra/server@1.11.0-alpha.1
|
|
10
|
+
|
|
11
|
+
## 1.2.0-alpha.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 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))
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const mastra = new Mastra({
|
|
19
|
+
server: {
|
|
20
|
+
onValidationError: (error, context) => ({
|
|
21
|
+
status: 422,
|
|
22
|
+
body: {
|
|
23
|
+
ok: false,
|
|
24
|
+
errors: error.issues.map(i => ({
|
|
25
|
+
path: i.path.join('.'),
|
|
26
|
+
message: i.message,
|
|
27
|
+
})),
|
|
28
|
+
source: context,
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- 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)]:
|
|
38
|
+
- @mastra/core@1.11.0-alpha.0
|
|
39
|
+
- @mastra/server@1.11.0-alpha.0
|
|
40
|
+
|
|
3
41
|
## 1.1.9
|
|
4
42
|
|
|
5
43
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,217 +1,217 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var busboy = require('@fastify/busboy');
|
|
4
|
-
var error = require('@mastra/server/handlers/error');
|
|
5
4
|
var serverAdapter = require('@mastra/server/server-adapter');
|
|
6
5
|
|
|
7
6
|
// src/index.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
util2.assertNever = assertNever;
|
|
21
|
-
util2.arrayToEnum = (items) => {
|
|
22
|
-
const obj = {};
|
|
23
|
-
for (const item of items) {
|
|
24
|
-
obj[item] = item;
|
|
7
|
+
// @__NO_SIDE_EFFECTS__
|
|
8
|
+
function $constructor(name, initializer3, params) {
|
|
9
|
+
function init(inst, def) {
|
|
10
|
+
if (!inst._zod) {
|
|
11
|
+
Object.defineProperty(inst, "_zod", {
|
|
12
|
+
value: {
|
|
13
|
+
def,
|
|
14
|
+
constr: _,
|
|
15
|
+
traits: /* @__PURE__ */ new Set()
|
|
16
|
+
},
|
|
17
|
+
enumerable: false
|
|
18
|
+
});
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
util2.getValidEnumValues = (obj) => {
|
|
29
|
-
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
30
|
-
const filtered = {};
|
|
31
|
-
for (const k of validKeys) {
|
|
32
|
-
filtered[k] = obj[k];
|
|
20
|
+
if (inst._zod.traits.has(name)) {
|
|
21
|
+
return;
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const keys = [];
|
|
43
|
-
for (const key in object) {
|
|
44
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
45
|
-
keys.push(key);
|
|
23
|
+
inst._zod.traits.add(name);
|
|
24
|
+
initializer3(inst, def);
|
|
25
|
+
const proto = _.prototype;
|
|
26
|
+
const keys = Object.keys(proto);
|
|
27
|
+
for (let i = 0; i < keys.length; i++) {
|
|
28
|
+
const k = keys[i];
|
|
29
|
+
if (!(k in inst)) {
|
|
30
|
+
inst[k] = proto[k].bind(inst);
|
|
46
31
|
}
|
|
47
32
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
}
|
|
34
|
+
const Parent = params?.Parent ?? Object;
|
|
35
|
+
class Definition extends Parent {
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
38
|
+
function _(def) {
|
|
39
|
+
var _a2;
|
|
40
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
41
|
+
init(inst, def);
|
|
42
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
43
|
+
for (const fn of inst._zod.deferred) {
|
|
44
|
+
fn();
|
|
54
45
|
}
|
|
55
|
-
return
|
|
56
|
-
};
|
|
57
|
-
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
58
|
-
function joinValues(array, separator = " | ") {
|
|
59
|
-
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
46
|
+
return inst;
|
|
60
47
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
Object.defineProperty(_, "init", { value: init });
|
|
49
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
50
|
+
value: (inst) => {
|
|
51
|
+
if (params?.Parent && inst instanceof params.Parent)
|
|
52
|
+
return true;
|
|
53
|
+
return inst?._zod?.traits?.has(name);
|
|
65
54
|
}
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
(function(objectUtil2) {
|
|
71
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
72
|
-
return {
|
|
73
|
-
...first,
|
|
74
|
-
...second
|
|
75
|
-
// second overwrites first
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
})(objectUtil || (objectUtil = {}));
|
|
79
|
-
util.arrayToEnum([
|
|
80
|
-
"string",
|
|
81
|
-
"nan",
|
|
82
|
-
"number",
|
|
83
|
-
"integer",
|
|
84
|
-
"float",
|
|
85
|
-
"boolean",
|
|
86
|
-
"date",
|
|
87
|
-
"bigint",
|
|
88
|
-
"symbol",
|
|
89
|
-
"function",
|
|
90
|
-
"undefined",
|
|
91
|
-
"null",
|
|
92
|
-
"array",
|
|
93
|
-
"object",
|
|
94
|
-
"unknown",
|
|
95
|
-
"promise",
|
|
96
|
-
"void",
|
|
97
|
-
"never",
|
|
98
|
-
"map",
|
|
99
|
-
"set"
|
|
100
|
-
]);
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(_, "name", { value: name });
|
|
57
|
+
return _;
|
|
58
|
+
}
|
|
101
59
|
|
|
102
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
103
|
-
|
|
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
|
-
const actualProto = new.target.prototype;
|
|
135
|
-
if (Object.setPrototypeOf) {
|
|
136
|
-
Object.setPrototypeOf(this, actualProto);
|
|
60
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js
|
|
61
|
+
function jsonStringifyReplacer(_, value) {
|
|
62
|
+
if (typeof value === "bigint")
|
|
63
|
+
return value.toString();
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js
|
|
68
|
+
var initializer = (inst, def) => {
|
|
69
|
+
inst.name = "$ZodError";
|
|
70
|
+
Object.defineProperty(inst, "_zod", {
|
|
71
|
+
value: inst._zod,
|
|
72
|
+
enumerable: false
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(inst, "issues", {
|
|
75
|
+
value: def,
|
|
76
|
+
enumerable: false
|
|
77
|
+
});
|
|
78
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
79
|
+
Object.defineProperty(inst, "toString", {
|
|
80
|
+
value: () => inst.message,
|
|
81
|
+
enumerable: false
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
var $ZodError = $constructor("$ZodError", initializer);
|
|
85
|
+
function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
86
|
+
const fieldErrors = {};
|
|
87
|
+
const formErrors = [];
|
|
88
|
+
for (const sub of error.issues) {
|
|
89
|
+
if (sub.path.length > 0) {
|
|
90
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
91
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
137
92
|
} else {
|
|
138
|
-
|
|
93
|
+
formErrors.push(mapper(sub));
|
|
139
94
|
}
|
|
140
|
-
this.name = "ZodError";
|
|
141
|
-
this.issues = issues;
|
|
142
95
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
curr[el]._errors.push(mapper(issue));
|
|
169
|
-
}
|
|
170
|
-
curr = curr[el];
|
|
171
|
-
i++;
|
|
96
|
+
return { formErrors, fieldErrors };
|
|
97
|
+
}
|
|
98
|
+
function formatError(error, mapper = (issue2) => issue2.message) {
|
|
99
|
+
const fieldErrors = { _errors: [] };
|
|
100
|
+
const processError = (error2) => {
|
|
101
|
+
for (const issue2 of error2.issues) {
|
|
102
|
+
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
103
|
+
issue2.errors.map((issues) => processError({ issues }));
|
|
104
|
+
} else if (issue2.code === "invalid_key") {
|
|
105
|
+
processError({ issues: issue2.issues });
|
|
106
|
+
} else if (issue2.code === "invalid_element") {
|
|
107
|
+
processError({ issues: issue2.issues });
|
|
108
|
+
} else if (issue2.path.length === 0) {
|
|
109
|
+
fieldErrors._errors.push(mapper(issue2));
|
|
110
|
+
} else {
|
|
111
|
+
let curr = fieldErrors;
|
|
112
|
+
let i = 0;
|
|
113
|
+
while (i < issue2.path.length) {
|
|
114
|
+
const el = issue2.path[i];
|
|
115
|
+
const terminal = i === issue2.path.length - 1;
|
|
116
|
+
if (!terminal) {
|
|
117
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
118
|
+
} else {
|
|
119
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
120
|
+
curr[el]._errors.push(mapper(issue2));
|
|
172
121
|
}
|
|
122
|
+
curr = curr[el];
|
|
123
|
+
i++;
|
|
173
124
|
}
|
|
174
125
|
}
|
|
175
|
-
};
|
|
176
|
-
processError(this);
|
|
177
|
-
return fieldErrors;
|
|
178
|
-
}
|
|
179
|
-
static assert(value) {
|
|
180
|
-
if (!(value instanceof _ZodError)) {
|
|
181
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
182
126
|
}
|
|
127
|
+
};
|
|
128
|
+
processError(error);
|
|
129
|
+
return fieldErrors;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js
|
|
133
|
+
var _a;
|
|
134
|
+
var $ZodRegistry = class {
|
|
135
|
+
constructor() {
|
|
136
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
137
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
183
138
|
}
|
|
184
|
-
|
|
185
|
-
|
|
139
|
+
add(schema, ..._meta) {
|
|
140
|
+
const meta = _meta[0];
|
|
141
|
+
this._map.set(schema, meta);
|
|
142
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
143
|
+
this._idmap.set(meta.id, schema);
|
|
144
|
+
}
|
|
145
|
+
return this;
|
|
186
146
|
}
|
|
187
|
-
|
|
188
|
-
|
|
147
|
+
clear() {
|
|
148
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
149
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
150
|
+
return this;
|
|
189
151
|
}
|
|
190
|
-
|
|
191
|
-
|
|
152
|
+
remove(schema) {
|
|
153
|
+
const meta = this._map.get(schema);
|
|
154
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
155
|
+
this._idmap.delete(meta.id);
|
|
156
|
+
}
|
|
157
|
+
this._map.delete(schema);
|
|
158
|
+
return this;
|
|
192
159
|
}
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
201
|
-
} else {
|
|
202
|
-
formErrors.push(mapper(sub));
|
|
203
|
-
}
|
|
160
|
+
get(schema) {
|
|
161
|
+
const p = schema._zod.parent;
|
|
162
|
+
if (p) {
|
|
163
|
+
const pm = { ...this.get(p) ?? {} };
|
|
164
|
+
delete pm.id;
|
|
165
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
166
|
+
return Object.keys(f).length ? f : void 0;
|
|
204
167
|
}
|
|
205
|
-
return
|
|
168
|
+
return this._map.get(schema);
|
|
206
169
|
}
|
|
207
|
-
|
|
208
|
-
return this.
|
|
170
|
+
has(schema) {
|
|
171
|
+
return this._map.has(schema);
|
|
209
172
|
}
|
|
210
173
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
174
|
+
function registry() {
|
|
175
|
+
return new $ZodRegistry();
|
|
176
|
+
}
|
|
177
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
178
|
+
|
|
179
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
|
|
180
|
+
var initializer2 = (inst, issues) => {
|
|
181
|
+
$ZodError.init(inst, issues);
|
|
182
|
+
inst.name = "ZodError";
|
|
183
|
+
Object.defineProperties(inst, {
|
|
184
|
+
format: {
|
|
185
|
+
value: (mapper) => formatError(inst, mapper)
|
|
186
|
+
// enumerable: false,
|
|
187
|
+
},
|
|
188
|
+
flatten: {
|
|
189
|
+
value: (mapper) => flattenError(inst, mapper)
|
|
190
|
+
// enumerable: false,
|
|
191
|
+
},
|
|
192
|
+
addIssue: {
|
|
193
|
+
value: (issue2) => {
|
|
194
|
+
inst.issues.push(issue2);
|
|
195
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
196
|
+
}
|
|
197
|
+
// enumerable: false,
|
|
198
|
+
},
|
|
199
|
+
addIssues: {
|
|
200
|
+
value: (issues2) => {
|
|
201
|
+
inst.issues.push(...issues2);
|
|
202
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
203
|
+
}
|
|
204
|
+
// enumerable: false,
|
|
205
|
+
},
|
|
206
|
+
isEmpty: {
|
|
207
|
+
get() {
|
|
208
|
+
return inst.issues.length === 0;
|
|
209
|
+
}
|
|
210
|
+
// enumerable: false,
|
|
211
|
+
}
|
|
212
|
+
});
|
|
214
213
|
};
|
|
214
|
+
var ZodError = $constructor("ZodError", initializer2);
|
|
215
215
|
|
|
216
216
|
// src/index.ts
|
|
217
217
|
var _hasPermissionPromise;
|
|
@@ -535,48 +535,51 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
535
535
|
if (params.queryParams) {
|
|
536
536
|
try {
|
|
537
537
|
params.queryParams = await this.parseQueryParams(route, params.queryParams);
|
|
538
|
-
} catch (error
|
|
538
|
+
} catch (error) {
|
|
539
539
|
this.mastra.getLogger()?.error("Error parsing query params", {
|
|
540
|
-
error: error
|
|
540
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
541
541
|
});
|
|
542
|
-
if (error
|
|
543
|
-
|
|
542
|
+
if (error instanceof ZodError) {
|
|
543
|
+
const { status, body } = this.resolveValidationError(route, error, "query");
|
|
544
|
+
return reply.status(status).send(body);
|
|
544
545
|
}
|
|
545
546
|
return reply.status(400).send({
|
|
546
547
|
error: "Invalid query parameters",
|
|
547
|
-
issues: [{ field: "unknown", message: error
|
|
548
|
+
issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
|
|
548
549
|
});
|
|
549
550
|
}
|
|
550
551
|
}
|
|
551
552
|
if (params.body) {
|
|
552
553
|
try {
|
|
553
554
|
params.body = await this.parseBody(route, params.body);
|
|
554
|
-
} catch (error
|
|
555
|
+
} catch (error) {
|
|
555
556
|
this.mastra.getLogger()?.error("Error parsing body", {
|
|
556
|
-
error: error
|
|
557
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
557
558
|
});
|
|
558
|
-
if (error
|
|
559
|
-
|
|
559
|
+
if (error instanceof ZodError) {
|
|
560
|
+
const { status, body } = this.resolveValidationError(route, error, "body");
|
|
561
|
+
return reply.status(status).send(body);
|
|
560
562
|
}
|
|
561
563
|
return reply.status(400).send({
|
|
562
564
|
error: "Invalid request body",
|
|
563
|
-
issues: [{ field: "unknown", message: error
|
|
565
|
+
issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
|
|
564
566
|
});
|
|
565
567
|
}
|
|
566
568
|
}
|
|
567
569
|
if (params.urlParams) {
|
|
568
570
|
try {
|
|
569
571
|
params.urlParams = await this.parsePathParams(route, params.urlParams);
|
|
570
|
-
} catch (error
|
|
572
|
+
} catch (error) {
|
|
571
573
|
this.mastra.getLogger()?.error("Error parsing path params", {
|
|
572
|
-
error: error
|
|
574
|
+
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
573
575
|
});
|
|
574
|
-
if (error
|
|
575
|
-
|
|
576
|
+
if (error instanceof ZodError) {
|
|
577
|
+
const { status, body } = this.resolveValidationError(route, error, "path");
|
|
578
|
+
return reply.status(status).send(body);
|
|
576
579
|
}
|
|
577
580
|
return reply.status(400).send({
|
|
578
581
|
error: "Invalid path parameters",
|
|
579
|
-
issues: [{ field: "unknown", message: error
|
|
582
|
+
issues: [{ field: "unknown", message: error instanceof Error ? error.message : "Unknown error" }]
|
|
580
583
|
});
|
|
581
584
|
}
|
|
582
585
|
}
|
|
@@ -627,7 +630,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
627
630
|
};
|
|
628
631
|
const shouldApplyBodyLimit = this.bodyLimitOptions && ["POST", "PUT", "PATCH"].includes(route.method.toUpperCase());
|
|
629
632
|
const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;
|
|
630
|
-
const
|
|
633
|
+
const config2 = shouldApplyBodyLimit && maxSize ? { bodyLimit: maxSize } : void 0;
|
|
631
634
|
if (route.method.toUpperCase() === "ALL") {
|
|
632
635
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
633
636
|
for (const method of methods) {
|
|
@@ -636,7 +639,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
636
639
|
method,
|
|
637
640
|
url: fastifyPath,
|
|
638
641
|
handler,
|
|
639
|
-
config
|
|
642
|
+
config: config2
|
|
640
643
|
});
|
|
641
644
|
} catch (err) {
|
|
642
645
|
if (err instanceof Error && err.message.includes("already declared")) {
|
|
@@ -650,7 +653,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
650
653
|
method: route.method,
|
|
651
654
|
url: fastifyPath,
|
|
652
655
|
handler,
|
|
653
|
-
config
|
|
656
|
+
config: config2
|
|
654
657
|
});
|
|
655
658
|
}
|
|
656
659
|
}
|
|
@@ -762,14 +765,14 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
762
765
|
const method = request.method;
|
|
763
766
|
const path = urlPath;
|
|
764
767
|
reply.raw.once("finish", () => {
|
|
765
|
-
const
|
|
768
|
+
const duration2 = Date.now() - start;
|
|
766
769
|
const status = reply.statusCode;
|
|
767
770
|
const level = this.httpLoggingConfig?.level || "info";
|
|
768
771
|
const logData = {
|
|
769
772
|
method,
|
|
770
773
|
path,
|
|
771
774
|
status,
|
|
772
|
-
duration: `${
|
|
775
|
+
duration: `${duration2}ms`
|
|
773
776
|
};
|
|
774
777
|
if (this.httpLoggingConfig?.includeQueryParams) {
|
|
775
778
|
logData.query = request.query;
|
|
@@ -785,7 +788,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
785
788
|
});
|
|
786
789
|
logData.headers = headers;
|
|
787
790
|
}
|
|
788
|
-
this.logger[level](`${method} ${path} ${status} ${
|
|
791
|
+
this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
|
|
789
792
|
});
|
|
790
793
|
});
|
|
791
794
|
}
|