@mastra/fastify 1.3.24-alpha.4 → 1.3.24-alpha.8
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @mastra/fastify
|
|
2
2
|
|
|
3
|
+
## 1.3.24-alpha.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`c35b962`](https://github.com/mastra-ai/mastra/commit/c35b9625c7e854fcfdeee226a3338a750d0ff211), [`4084113`](https://github.com/mastra-ai/mastra/commit/408411370fc48a822e8b616b3b63f9409774e0e9), [`bc01b1b`](https://github.com/mastra-ai/mastra/commit/bc01b1bfafe381d90af909f8bce7eeb4eee779f2)]:
|
|
8
|
+
- @mastra/core@1.37.0-alpha.8
|
|
9
|
+
- @mastra/server@1.37.0-alpha.8
|
|
10
|
+
|
|
11
|
+
## 1.3.24-alpha.7
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`168fa09`](https://github.com/mastra-ai/mastra/commit/168fa09d6b39114cb8c13bd06f1dccb9bc81c6cd)]:
|
|
16
|
+
- @mastra/core@1.37.0-alpha.7
|
|
17
|
+
- @mastra/server@1.37.0-alpha.7
|
|
18
|
+
|
|
19
|
+
## 1.3.24-alpha.6
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Developers can now cancel long-running custom API route work when clients disconnect. Node-based adapters pass abort signals into custom route handlers, clean up response streams correctly, and still surface upstream response body errors. ([#16335](https://github.com/mastra-ai/mastra/pull/16335))
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
registerApiRoute('/stream', {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
handler: async c => {
|
|
29
|
+
const stream = await agent.stream(prompt, {
|
|
30
|
+
abortSignal: c.req.raw.signal,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return stream.toTextStreamResponse();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- Updated dependencies [[`fafed7a`](https://github.com/mastra-ai/mastra/commit/fafed7a24dc320f7c92ee872c347f4be087fd689), [`0cbece9`](https://github.com/mastra-ai/mastra/commit/0cbece9d832cb134a74cdbf3682d390a058215a4), [`7dfe1bc`](https://github.com/mastra-ai/mastra/commit/7dfe1bcfe71d261a6fd6bbf29b1dec49d78fb98f), [`70cb714`](https://github.com/mastra-ai/mastra/commit/70cb7149c8f16f478e15b58498254a53181750a4), [`7f9da22`](https://github.com/mastra-ai/mastra/commit/7f9da22efd5aa595e138a31de55a5f0f2f28b33d)]:
|
|
39
|
+
- @mastra/server@1.37.0-alpha.6
|
|
40
|
+
- @mastra/core@1.37.0-alpha.6
|
|
41
|
+
|
|
42
|
+
## 1.3.24-alpha.5
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [[`6096445`](https://github.com/mastra-ai/mastra/commit/60964459733f0ab384584d95e19c36607ffdf7b0), [`91cf0e0`](https://github.com/mastra-ai/mastra/commit/91cf0e027e511b871481a8576b56b7af83b15afd)]:
|
|
47
|
+
- @mastra/core@1.37.0-alpha.5
|
|
48
|
+
- @mastra/server@1.37.0-alpha.5
|
|
49
|
+
|
|
3
50
|
## 1.3.24-alpha.4
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,9 @@ var requestContext = require('@mastra/core/request-context');
|
|
|
6
6
|
var auth = require('@mastra/server/auth');
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
+
|
|
10
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
11
|
+
var _a;
|
|
9
12
|
// @__NO_SIDE_EFFECTS__
|
|
10
13
|
function $constructor(name, initializer3, params) {
|
|
11
14
|
function init(inst, def) {
|
|
@@ -58,15 +61,16 @@ function $constructor(name, initializer3, params) {
|
|
|
58
61
|
Object.defineProperty(_, "name", { value: name });
|
|
59
62
|
return _;
|
|
60
63
|
}
|
|
64
|
+
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
61
65
|
|
|
62
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
66
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
63
67
|
function jsonStringifyReplacer(_, value) {
|
|
64
68
|
if (typeof value === "bigint")
|
|
65
69
|
return value.toString();
|
|
66
70
|
return value;
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
73
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
70
74
|
var initializer = (inst, def) => {
|
|
71
75
|
inst.name = "$ZodError";
|
|
72
76
|
Object.defineProperty(inst, "_zod", {
|
|
@@ -84,7 +88,7 @@ var initializer = (inst, def) => {
|
|
|
84
88
|
});
|
|
85
89
|
};
|
|
86
90
|
var $ZodError = $constructor("$ZodError", initializer);
|
|
87
|
-
function flattenError(error, mapper = (
|
|
91
|
+
function flattenError(error, mapper = (issue) => issue.message) {
|
|
88
92
|
const fieldErrors = {};
|
|
89
93
|
const formErrors = [];
|
|
90
94
|
for (const sub of error.issues) {
|
|
@@ -97,32 +101,35 @@ function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
|
97
101
|
}
|
|
98
102
|
return { formErrors, fieldErrors };
|
|
99
103
|
}
|
|
100
|
-
function formatError(error, mapper = (
|
|
104
|
+
function formatError(error, mapper = (issue) => issue.message) {
|
|
101
105
|
const fieldErrors = { _errors: [] };
|
|
102
|
-
const processError = (error2) => {
|
|
103
|
-
for (const
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
} else if (
|
|
107
|
-
processError({ issues:
|
|
108
|
-
} else if (
|
|
109
|
-
processError({ issues:
|
|
110
|
-
} else if (issue2.path.length === 0) {
|
|
111
|
-
fieldErrors._errors.push(mapper(issue2));
|
|
106
|
+
const processError = (error2, path = []) => {
|
|
107
|
+
for (const issue of error2.issues) {
|
|
108
|
+
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
109
|
+
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
110
|
+
} else if (issue.code === "invalid_key") {
|
|
111
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
112
|
+
} else if (issue.code === "invalid_element") {
|
|
113
|
+
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
112
114
|
} else {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
const fullpath = [...path, ...issue.path];
|
|
116
|
+
if (fullpath.length === 0) {
|
|
117
|
+
fieldErrors._errors.push(mapper(issue));
|
|
118
|
+
} else {
|
|
119
|
+
let curr = fieldErrors;
|
|
120
|
+
let i = 0;
|
|
121
|
+
while (i < fullpath.length) {
|
|
122
|
+
const el = fullpath[i];
|
|
123
|
+
const terminal = i === fullpath.length - 1;
|
|
124
|
+
if (!terminal) {
|
|
125
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
126
|
+
} else {
|
|
127
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
128
|
+
curr[el]._errors.push(mapper(issue));
|
|
129
|
+
}
|
|
130
|
+
curr = curr[el];
|
|
131
|
+
i++;
|
|
123
132
|
}
|
|
124
|
-
curr = curr[el];
|
|
125
|
-
i++;
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
}
|
|
@@ -131,54 +138,7 @@ function formatError(error, mapper = (issue2) => issue2.message) {
|
|
|
131
138
|
return fieldErrors;
|
|
132
139
|
}
|
|
133
140
|
|
|
134
|
-
// ../../node_modules/.pnpm/zod@4.3
|
|
135
|
-
var _a;
|
|
136
|
-
var $ZodRegistry = class {
|
|
137
|
-
constructor() {
|
|
138
|
-
this._map = /* @__PURE__ */ new WeakMap();
|
|
139
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
140
|
-
}
|
|
141
|
-
add(schema, ..._meta) {
|
|
142
|
-
const meta = _meta[0];
|
|
143
|
-
this._map.set(schema, meta);
|
|
144
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
145
|
-
this._idmap.set(meta.id, schema);
|
|
146
|
-
}
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
clear() {
|
|
150
|
-
this._map = /* @__PURE__ */ new WeakMap();
|
|
151
|
-
this._idmap = /* @__PURE__ */ new Map();
|
|
152
|
-
return this;
|
|
153
|
-
}
|
|
154
|
-
remove(schema) {
|
|
155
|
-
const meta = this._map.get(schema);
|
|
156
|
-
if (meta && typeof meta === "object" && "id" in meta) {
|
|
157
|
-
this._idmap.delete(meta.id);
|
|
158
|
-
}
|
|
159
|
-
this._map.delete(schema);
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
get(schema) {
|
|
163
|
-
const p = schema._zod.parent;
|
|
164
|
-
if (p) {
|
|
165
|
-
const pm = { ...this.get(p) ?? {} };
|
|
166
|
-
delete pm.id;
|
|
167
|
-
const f = { ...pm, ...this._map.get(schema) };
|
|
168
|
-
return Object.keys(f).length ? f : void 0;
|
|
169
|
-
}
|
|
170
|
-
return this._map.get(schema);
|
|
171
|
-
}
|
|
172
|
-
has(schema) {
|
|
173
|
-
return this._map.has(schema);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
function registry() {
|
|
177
|
-
return new $ZodRegistry();
|
|
178
|
-
}
|
|
179
|
-
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
180
|
-
|
|
181
|
-
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
|
|
141
|
+
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
182
142
|
var initializer2 = (inst, issues) => {
|
|
183
143
|
$ZodError.init(inst, issues);
|
|
184
144
|
inst.name = "ZodError";
|
|
@@ -192,8 +152,8 @@ var initializer2 = (inst, issues) => {
|
|
|
192
152
|
// enumerable: false,
|
|
193
153
|
},
|
|
194
154
|
addIssue: {
|
|
195
|
-
value: (
|
|
196
|
-
inst.issues.push(
|
|
155
|
+
value: (issue) => {
|
|
156
|
+
inst.issues.push(issue);
|
|
197
157
|
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
198
158
|
}
|
|
199
159
|
// enumerable: false,
|
|
@@ -213,7 +173,7 @@ var initializer2 = (inst, issues) => {
|
|
|
213
173
|
}
|
|
214
174
|
});
|
|
215
175
|
};
|
|
216
|
-
var ZodError = $constructor("ZodError", initializer2);
|
|
176
|
+
var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
|
|
217
177
|
function toWebRequest(request) {
|
|
218
178
|
const protocol = request.protocol || "http";
|
|
219
179
|
const host = request.headers.host || "localhost";
|
|
@@ -777,7 +737,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
777
737
|
};
|
|
778
738
|
const shouldApplyBodyLimit = this.bodyLimitOptions && ["POST", "PUT", "PATCH"].includes(route.method.toUpperCase());
|
|
779
739
|
const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;
|
|
780
|
-
const
|
|
740
|
+
const config = shouldApplyBodyLimit && maxSize ? { bodyLimit: maxSize } : void 0;
|
|
781
741
|
if (route.method.toUpperCase() === "ALL") {
|
|
782
742
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
783
743
|
for (const method of methods) {
|
|
@@ -786,7 +746,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
786
746
|
method,
|
|
787
747
|
url: fastifyPath,
|
|
788
748
|
handler,
|
|
789
|
-
config
|
|
749
|
+
config
|
|
790
750
|
});
|
|
791
751
|
} catch (err) {
|
|
792
752
|
if (err instanceof Error && err.message.includes("already declared")) {
|
|
@@ -800,7 +760,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
800
760
|
method: route.method,
|
|
801
761
|
url: fastifyPath,
|
|
802
762
|
handler,
|
|
803
|
-
config
|
|
763
|
+
config
|
|
804
764
|
});
|
|
805
765
|
}
|
|
806
766
|
}
|
|
@@ -872,14 +832,15 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
872
832
|
request.method,
|
|
873
833
|
request.headers,
|
|
874
834
|
request.body,
|
|
875
|
-
request.requestContext
|
|
835
|
+
request.requestContext,
|
|
836
|
+
request.abortSignal
|
|
876
837
|
);
|
|
877
838
|
if (!response) {
|
|
878
839
|
reply.status(404).send({ error: "Not Found" });
|
|
879
840
|
return;
|
|
880
841
|
}
|
|
881
842
|
reply.hijack();
|
|
882
|
-
await this.writeCustomRouteResponse(response, reply.raw);
|
|
843
|
+
await this.writeCustomRouteResponse(response, reply.raw, request.abortSignal);
|
|
883
844
|
};
|
|
884
845
|
if (route.method === "ALL") {
|
|
885
846
|
const methods = ["GET", "POST", "PUT", "DELETE", "PATCH"];
|
|
@@ -929,14 +890,14 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
929
890
|
const method = request.method;
|
|
930
891
|
const path = urlPath;
|
|
931
892
|
reply.raw.once("finish", () => {
|
|
932
|
-
const
|
|
893
|
+
const duration = Date.now() - start;
|
|
933
894
|
const status = reply.statusCode;
|
|
934
895
|
const level = this.httpLoggingConfig?.level || "info";
|
|
935
896
|
const logData = {
|
|
936
897
|
method,
|
|
937
898
|
path,
|
|
938
899
|
status,
|
|
939
|
-
duration: `${
|
|
900
|
+
duration: `${duration}ms`
|
|
940
901
|
};
|
|
941
902
|
if (this.httpLoggingConfig?.includeQueryParams) {
|
|
942
903
|
logData.query = request.query;
|
|
@@ -952,7 +913,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
|
|
|
952
913
|
});
|
|
953
914
|
logData.headers = headers;
|
|
954
915
|
}
|
|
955
|
-
this.logger[level](`${method} ${path} ${status} ${
|
|
916
|
+
this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
|
|
956
917
|
});
|
|
957
918
|
});
|
|
958
919
|
}
|