@mastra/hono 1.4.20 → 1.4.21-alpha.2
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 +4 -172
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -173
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MastraServer as MastraServer$1, redactStreamChunk, normalizeQueryParams, checkRouteFGA } from '@mastra/server/server-adapter';
|
|
1
|
+
import { MastraServer as MastraServer$1, redactStreamChunk, normalizeQueryParams, isZodError, checkRouteFGA } from '@mastra/server/server-adapter';
|
|
2
2
|
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
3
3
|
import { bodyLimit } from 'hono/body-limit';
|
|
4
4
|
import { stream } from 'hono/streaming';
|
|
@@ -7,174 +7,6 @@ import { coreAuthMiddleware } from '@mastra/server/auth';
|
|
|
7
7
|
import { ViewerRegistry, handleInputMessage } from '@mastra/server/browser-stream';
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
|
-
|
|
11
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/core.js
|
|
12
|
-
var _a;
|
|
13
|
-
// @__NO_SIDE_EFFECTS__
|
|
14
|
-
function $constructor(name, initializer3, params) {
|
|
15
|
-
function init(inst, def) {
|
|
16
|
-
if (!inst._zod) {
|
|
17
|
-
Object.defineProperty(inst, "_zod", {
|
|
18
|
-
value: {
|
|
19
|
-
def,
|
|
20
|
-
constr: _,
|
|
21
|
-
traits: /* @__PURE__ */ new Set()
|
|
22
|
-
},
|
|
23
|
-
enumerable: false
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
if (inst._zod.traits.has(name)) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
inst._zod.traits.add(name);
|
|
30
|
-
initializer3(inst, def);
|
|
31
|
-
const proto = _.prototype;
|
|
32
|
-
const keys = Object.keys(proto);
|
|
33
|
-
for (let i = 0; i < keys.length; i++) {
|
|
34
|
-
const k = keys[i];
|
|
35
|
-
if (!(k in inst)) {
|
|
36
|
-
inst[k] = proto[k].bind(inst);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const Parent = params?.Parent ?? Object;
|
|
41
|
-
class Definition extends Parent {
|
|
42
|
-
}
|
|
43
|
-
Object.defineProperty(Definition, "name", { value: name });
|
|
44
|
-
function _(def) {
|
|
45
|
-
var _a2;
|
|
46
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
47
|
-
init(inst, def);
|
|
48
|
-
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
49
|
-
for (const fn of inst._zod.deferred) {
|
|
50
|
-
fn();
|
|
51
|
-
}
|
|
52
|
-
return inst;
|
|
53
|
-
}
|
|
54
|
-
Object.defineProperty(_, "init", { value: init });
|
|
55
|
-
Object.defineProperty(_, Symbol.hasInstance, {
|
|
56
|
-
value: (inst) => {
|
|
57
|
-
if (params?.Parent && inst instanceof params.Parent)
|
|
58
|
-
return true;
|
|
59
|
-
return inst?._zod?.traits?.has(name);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(_, "name", { value: name });
|
|
63
|
-
return _;
|
|
64
|
-
}
|
|
65
|
-
(_a = globalThis).__zod_globalConfig ?? (_a.__zod_globalConfig = {});
|
|
66
|
-
|
|
67
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/util.js
|
|
68
|
-
function jsonStringifyReplacer(_, value) {
|
|
69
|
-
if (typeof value === "bigint")
|
|
70
|
-
return value.toString();
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/core/errors.js
|
|
75
|
-
var initializer = (inst, def) => {
|
|
76
|
-
inst.name = "$ZodError";
|
|
77
|
-
Object.defineProperty(inst, "_zod", {
|
|
78
|
-
value: inst._zod,
|
|
79
|
-
enumerable: false
|
|
80
|
-
});
|
|
81
|
-
Object.defineProperty(inst, "issues", {
|
|
82
|
-
value: def,
|
|
83
|
-
enumerable: false
|
|
84
|
-
});
|
|
85
|
-
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
86
|
-
Object.defineProperty(inst, "toString", {
|
|
87
|
-
value: () => inst.message,
|
|
88
|
-
enumerable: false
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
var $ZodError = $constructor("$ZodError", initializer);
|
|
92
|
-
function flattenError(error, mapper = (issue) => issue.message) {
|
|
93
|
-
const fieldErrors = {};
|
|
94
|
-
const formErrors = [];
|
|
95
|
-
for (const sub of error.issues) {
|
|
96
|
-
if (sub.path.length > 0) {
|
|
97
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
98
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
99
|
-
} else {
|
|
100
|
-
formErrors.push(mapper(sub));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { formErrors, fieldErrors };
|
|
104
|
-
}
|
|
105
|
-
function formatError(error, mapper = (issue) => issue.message) {
|
|
106
|
-
const fieldErrors = { _errors: [] };
|
|
107
|
-
const processError = (error2, path = []) => {
|
|
108
|
-
for (const issue of error2.issues) {
|
|
109
|
-
if (issue.code === "invalid_union" && issue.errors.length) {
|
|
110
|
-
issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
111
|
-
} else if (issue.code === "invalid_key") {
|
|
112
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
113
|
-
} else if (issue.code === "invalid_element") {
|
|
114
|
-
processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
115
|
-
} else {
|
|
116
|
-
const fullpath = [...path, ...issue.path];
|
|
117
|
-
if (fullpath.length === 0) {
|
|
118
|
-
fieldErrors._errors.push(mapper(issue));
|
|
119
|
-
} else {
|
|
120
|
-
let curr = fieldErrors;
|
|
121
|
-
let i = 0;
|
|
122
|
-
while (i < fullpath.length) {
|
|
123
|
-
const el = fullpath[i];
|
|
124
|
-
const terminal = i === fullpath.length - 1;
|
|
125
|
-
if (!terminal) {
|
|
126
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
127
|
-
} else {
|
|
128
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
129
|
-
curr[el]._errors.push(mapper(issue));
|
|
130
|
-
}
|
|
131
|
-
curr = curr[el];
|
|
132
|
-
i++;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
processError(error);
|
|
139
|
-
return fieldErrors;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/errors.js
|
|
143
|
-
var initializer2 = (inst, issues) => {
|
|
144
|
-
$ZodError.init(inst, issues);
|
|
145
|
-
inst.name = "ZodError";
|
|
146
|
-
Object.defineProperties(inst, {
|
|
147
|
-
format: {
|
|
148
|
-
value: (mapper) => formatError(inst, mapper)
|
|
149
|
-
// enumerable: false,
|
|
150
|
-
},
|
|
151
|
-
flatten: {
|
|
152
|
-
value: (mapper) => flattenError(inst, mapper)
|
|
153
|
-
// enumerable: false,
|
|
154
|
-
},
|
|
155
|
-
addIssue: {
|
|
156
|
-
value: (issue) => {
|
|
157
|
-
inst.issues.push(issue);
|
|
158
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
159
|
-
}
|
|
160
|
-
// enumerable: false,
|
|
161
|
-
},
|
|
162
|
-
addIssues: {
|
|
163
|
-
value: (issues2) => {
|
|
164
|
-
inst.issues.push(...issues2);
|
|
165
|
-
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
166
|
-
}
|
|
167
|
-
// enumerable: false,
|
|
168
|
-
},
|
|
169
|
-
isEmpty: {
|
|
170
|
-
get() {
|
|
171
|
-
return inst.issues.length === 0;
|
|
172
|
-
}
|
|
173
|
-
// enumerable: false,
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
var ZodError = /* @__PURE__ */ $constructor("ZodError", initializer2);
|
|
178
10
|
function createAuthMiddleware({ mastra, requiresAuth = true }) {
|
|
179
11
|
return async (c, next) => {
|
|
180
12
|
if (!requiresAuth) {
|
|
@@ -395,7 +227,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
395
227
|
return stream(
|
|
396
228
|
res,
|
|
397
229
|
async (stream2) => {
|
|
398
|
-
if (streamFormat === "sse") {
|
|
230
|
+
if (streamFormat === "sse" && route.sseFlushOnConnect) {
|
|
399
231
|
await stream2.write(": connected\n\n");
|
|
400
232
|
}
|
|
401
233
|
const readableStream = result instanceof ReadableStream ? result : result.fullStream;
|
|
@@ -617,7 +449,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
617
449
|
this.mastra.getLogger()?.error("Error parsing query params", {
|
|
618
450
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
619
451
|
});
|
|
620
|
-
if (error
|
|
452
|
+
if (isZodError(error)) {
|
|
621
453
|
const { status, body } = this.resolveValidationError(route, error, "query");
|
|
622
454
|
return c.json(body, status);
|
|
623
455
|
}
|
|
@@ -637,7 +469,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
637
469
|
this.mastra.getLogger()?.error("Error parsing body", {
|
|
638
470
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
639
471
|
});
|
|
640
|
-
if (error
|
|
472
|
+
if (isZodError(error)) {
|
|
641
473
|
const { status, body } = this.resolveValidationError(route, error, "body");
|
|
642
474
|
return c.json(body, status);
|
|
643
475
|
}
|
|
@@ -657,7 +489,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
657
489
|
this.mastra.getLogger()?.error("Error parsing path params", {
|
|
658
490
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
659
491
|
});
|
|
660
|
-
if (error
|
|
492
|
+
if (isZodError(error)) {
|
|
661
493
|
const { status, body } = this.resolveValidationError(route, error, "path");
|
|
662
494
|
return c.json(body, status);
|
|
663
495
|
}
|