@mastra/fastify 1.3.24-alpha.5 → 1.3.24-alpha.9
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 +47 -0
- package/dist/index.cjs +46 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -85
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -4,6 +4,9 @@ import { RequestContext } from '@mastra/core/request-context';
|
|
|
4
4
|
import { coreAuthMiddleware } from '@mastra/server/auth';
|
|
5
5
|
|
|
6
6
|
// src/index.ts
|
|
7
|
+
|
|
8
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
9
|
+
var _a;
|
|
7
10
|
// @__NO_SIDE_EFFECTS__
|
|
8
11
|
function $constructor(name, initializer3, params) {
|
|
9
12
|
function init(inst, def) {
|
|
@@ -56,15 +59,16 @@ function $constructor(name, initializer3, params) {
|
|
|
56
59
|
Object.defineProperty(_, "name", { value: name });
|
|
57
60
|
return _;
|
|
58
61
|
}
|
|
62
|
+
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
59
63
|
|
|
60
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
64
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
61
65
|
function jsonStringifyReplacer(_, value) {
|
|
62
66
|
if (typeof value === "bigint")
|
|
63
67
|
return value.toString();
|
|
64
68
|
return value;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
71
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
68
72
|
var initializer = (inst, def) => {
|
|
69
73
|
inst.name = "$ZodError";
|
|
70
74
|
Object.defineProperty(inst, "_zod", {
|
|
@@ -82,7 +86,7 @@ var initializer = (inst, def) => {
|
|
|
82
86
|
});
|
|
83
87
|
};
|
|
84
88
|
var $ZodError = $constructor("$ZodError", initializer);
|
|
85
|
-
function flattenError(error, mapper = (
|
|
89
|
+
function flattenError(error, mapper = (issue) => issue.message) {
|
|
86
90
|
const fieldErrors = {};
|
|
87
91
|
const formErrors = [];
|
|
88
92
|
for (const sub of error.issues) {
|
|
@@ -95,32 +99,35 @@ function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
|
95
99
|
}
|
|
96
100
|
return { formErrors, fieldErrors };
|
|
97
101
|
}
|
|
98
|
-
function formatError(error, mapper = (
|
|
102
|
+
function formatError(error, mapper = (issue) => issue.message) {
|
|
99
103
|
const fieldErrors = { _errors: [] };
|
|
100
|
-
const processError = (error2) => {
|
|
101
|
-
for (const
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
} else if (
|
|
105
|
-
processError({ issues:
|
|
106
|
-
} else if (
|
|
107
|
-
processError({ issues:
|
|
108
|
-
} else if (issue2.path.length === 0) {
|
|
109
|
-
fieldErrors._errors.push(mapper(issue2));
|
|
104
|
+
const processError = (error2, path = []) => {
|
|
105
|
+
for (const issue of error2.issues) {
|
|
106
|
+
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
107
|
+
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
108
|
+
} else if (issue.code === "invalid_key") {
|
|
109
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
110
|
+
} else if (issue.code === "invalid_element") {
|
|
111
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
110
112
|
} else {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
113
|
+
const fullpath = [...path, ...issue.path];
|
|
114
|
+
if (fullpath.length === 0) {
|
|
115
|
+
fieldErrors._errors.push(mapper(issue));
|
|
116
|
+
} else {
|
|
117
|
+
let curr = fieldErrors;
|
|
118
|
+
let i = 0;
|
|
119
|
+
while (i < fullpath.length) {
|
|
120
|
+
const el = fullpath[i];
|
|
121
|
+
const terminal = i === fullpath.length - 1;
|
|
122
|
+
if (!terminal) {
|
|
123
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
124
|
+
} else {
|
|
125
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
126
|
+
curr[el]._errors.push(mapper(issue));
|
|
127
|
+
}
|
|
128
|
+
curr = curr[el];
|
|
129
|
+
i++;
|
|
121
130
|
}
|
|
122
|
-
curr = curr[el];
|
|
123
|
-
i++;
|
|
124
131
|
}
|
|
125
132
|
}
|
|
126
133
|
}
|
|
@@ -129,54 +136,7 @@ function formatError(error, mapper = (issue2) => issue2.message) {
|
|
|
129
136
|
return fieldErrors;
|
|
130
137
|
}
|
|
131
138
|
|
|
132
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
133
|
-
var _a;
|
|
134
|
-
var $ZodRegistry = class {
|
|
135
|
-
constructor() {
|
|
136
|
-
this._map = /* @__PURE__ */ new WeakMap();
|
|
137
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
138
|
-
}
|
|
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;
|
|
146
|
-
}
|
|
147
|
-
clear() {
|
|
148
|
-
this._map = /* @__PURE__ */ new WeakMap();
|
|
149
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
150
|
-
return this;
|
|
151
|
-
}
|
|
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;
|
|
159
|
-
}
|
|
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;
|
|
167
|
-
}
|
|
168
|
-
return this._map.get(schema);
|
|
169
|
-
}
|
|
170
|
-
has(schema) {
|
|
171
|
-
return this._map.has(schema);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
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
|
|
139
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
180
140
|
var initializer2 = (inst, issues) => {
|
|
181
141
|
$ZodError.init(inst, issues);
|
|
182
142
|
inst.name = "ZodError";
|
|
@@ -190,8 +150,8 @@ var initializer2 = (inst, issues) => {
|
|
|
190
150
|
// enumerable: false,
|
|
191
151
|
},
|
|
192
152
|
addIssue: {
|
|
193
|
-
value: (
|
|
194
|
-
inst.issues.push(
|
|
153
|
+
value: (issue) => {
|
|
154
|
+
inst.issues.push(issue);
|
|
195
155
|
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
196
156
|
}
|
|
197
157
|
// enumerable: false,
|
|
@@ -211,7 +171,7 @@ var initializer2 = (inst, issues) => {
|
|
|
211
171
|
}
|
|
212
172
|
});
|
|
213
173
|
};
|
|
214
|
-
var ZodError = $constructor("ZodError", initializer2);
|
|
174
|
+
var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
|
|
215
175
|
function toWebRequest(request) {
|
|
216
176
|
const protocol = request.protocol || "http";
|
|
217
177
|
const host = request.headers.host || "localhost";
|
|
@@ -775,7 +735,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
775
735
|
};
|
|
776
736
|
const shouldApplyBodyLimit = this.bodyLimitOptions && ["POST", "PUT", "PATCH"].includes(route.method.toUpperCase());
|
|
777
737
|
const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;
|
|
778
|
-
const
|
|
738
|
+
const config = shouldApplyBodyLimit && maxSize ? { bodyLimit: maxSize } : void 0;
|
|
779
739
|
if (route.method.toUpperCase() === "ALL") {
|
|
780
740
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
781
741
|
for (const method of methods) {
|
|
@@ -784,7 +744,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
784
744
|
method,
|
|
785
745
|
url: fastifyPath,
|
|
786
746
|
handler,
|
|
787
|
-
config
|
|
747
|
+
config
|
|
788
748
|
});
|
|
789
749
|
} catch (err) {
|
|
790
750
|
if (err instanceof Error && err.message.includes("already declared")) {
|
|
@@ -798,7 +758,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
798
758
|
method: route.method,
|
|
799
759
|
url: fastifyPath,
|
|
800
760
|
handler,
|
|
801
|
-
config
|
|
761
|
+
config
|
|
802
762
|
});
|
|
803
763
|
}
|
|
804
764
|
}
|
|
@@ -870,14 +830,15 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
870
830
|
request.method,
|
|
871
831
|
request.headers,
|
|
872
832
|
request.body,
|
|
873
|
-
request.requestContext
|
|
833
|
+
request.requestContext,
|
|
834
|
+
request.abortSignal
|
|
874
835
|
);
|
|
875
836
|
if (!response) {
|
|
876
837
|
reply.status(404).send({ error: "Not Found" });
|
|
877
838
|
return;
|
|
878
839
|
}
|
|
879
840
|
reply.hijack();
|
|
880
|
-
await this.writeCustomRouteResponse(response, reply.raw);
|
|
841
|
+
await this.writeCustomRouteResponse(response, reply.raw, request.abortSignal);
|
|
881
842
|
};
|
|
882
843
|
if (route.method === "ALL") {
|
|
883
844
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
@@ -927,14 +888,14 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
927
888
|
const method = request.method;
|
|
928
889
|
const path = urlPath;
|
|
929
890
|
reply.raw.once("finish", () => {
|
|
930
|
-
const
|
|
891
|
+
const duration = Date.now() - start;
|
|
931
892
|
const status = reply.statusCode;
|
|
932
893
|
const level = this.httpLoggingConfig?.level || "info";
|
|
933
894
|
const logData = {
|
|
934
895
|
method,
|
|
935
896
|
path,
|
|
936
897
|
status,
|
|
937
|
-
duration: `${
|
|
898
|
+
duration: `${duration}ms`
|
|
938
899
|
};
|
|
939
900
|
if (this.httpLoggingConfig?.includeQueryParams) {
|
|
940
901
|
logData.query = request.query;
|
|
@@ -950,7 +911,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
950
911
|
});
|
|
951
912
|
logData.headers = headers;
|
|
952
913
|
}
|
|
953
|
-
this.logger[level](`${method} ${path} ${status} ${
|
|
914
|
+
this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
|
|
954
915
|
});
|
|
955
916
|
});
|
|
956
917
|
}
|