@mastra/hono 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 +210 -207
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +198 -195
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { formatZodError } from '@mastra/server/handlers/error';
|
|
2
1
|
import { MastraServer as MastraServer$1, normalizeQueryParams, redactStreamChunk } from '@mastra/server/server-adapter';
|
|
3
2
|
import { toReqRes, toFetchResponse } from 'fetch-to-node';
|
|
4
3
|
|
|
@@ -173,11 +172,11 @@ var StreamingApi = class {
|
|
|
173
172
|
|
|
174
173
|
// ../../node_modules/.pnpm/hono@4.11.9/node_modules/hono/dist/helper/streaming/utils.js
|
|
175
174
|
var isOldBunVersion = () => {
|
|
176
|
-
const
|
|
177
|
-
if (
|
|
175
|
+
const version2 = typeof Bun !== "undefined" ? Bun.version : void 0;
|
|
176
|
+
if (version2 === void 0) {
|
|
178
177
|
return false;
|
|
179
178
|
}
|
|
180
|
-
const result =
|
|
179
|
+
const result = version2.startsWith("1.1") || version2.startsWith("1.0") || version2.startsWith("0.");
|
|
181
180
|
isOldBunVersion = () => result;
|
|
182
181
|
return result;
|
|
183
182
|
};
|
|
@@ -210,213 +209,214 @@ var stream = (c, cb, onError) => {
|
|
|
210
209
|
})();
|
|
211
210
|
return c.newResponse(stream2.responseReadable);
|
|
212
211
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
util2.assertNever = assertNever;
|
|
226
|
-
util2.arrayToEnum = (items) => {
|
|
227
|
-
const obj = {};
|
|
228
|
-
for (const item of items) {
|
|
229
|
-
obj[item] = item;
|
|
212
|
+
// @__NO_SIDE_EFFECTS__
|
|
213
|
+
function $constructor(name, initializer3, params) {
|
|
214
|
+
function init(inst, def) {
|
|
215
|
+
if (!inst._zod) {
|
|
216
|
+
Object.defineProperty(inst, "_zod", {
|
|
217
|
+
value: {
|
|
218
|
+
def,
|
|
219
|
+
constr: _,
|
|
220
|
+
traits: /* @__PURE__ */ new Set()
|
|
221
|
+
},
|
|
222
|
+
enumerable: false
|
|
223
|
+
});
|
|
230
224
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
util2.getValidEnumValues = (obj) => {
|
|
234
|
-
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
235
|
-
const filtered = {};
|
|
236
|
-
for (const k of validKeys) {
|
|
237
|
-
filtered[k] = obj[k];
|
|
225
|
+
if (inst._zod.traits.has(name)) {
|
|
226
|
+
return;
|
|
238
227
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const keys = [];
|
|
248
|
-
for (const key in object) {
|
|
249
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
250
|
-
keys.push(key);
|
|
228
|
+
inst._zod.traits.add(name);
|
|
229
|
+
initializer3(inst, def);
|
|
230
|
+
const proto = _.prototype;
|
|
231
|
+
const keys = Object.keys(proto);
|
|
232
|
+
for (let i = 0; i < keys.length; i++) {
|
|
233
|
+
const k = keys[i];
|
|
234
|
+
if (!(k in inst)) {
|
|
235
|
+
inst[k] = proto[k].bind(inst);
|
|
251
236
|
}
|
|
252
237
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
238
|
+
}
|
|
239
|
+
const Parent = params?.Parent ?? Object;
|
|
240
|
+
class Definition extends Parent {
|
|
241
|
+
}
|
|
242
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
243
|
+
function _(def) {
|
|
244
|
+
var _a2;
|
|
245
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
246
|
+
init(inst, def);
|
|
247
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
248
|
+
for (const fn of inst._zod.deferred) {
|
|
249
|
+
fn();
|
|
259
250
|
}
|
|
260
|
-
return
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (typeof value === "bigint") {
|
|
269
|
-
return value.toString();
|
|
251
|
+
return inst;
|
|
252
|
+
}
|
|
253
|
+
Object.defineProperty(_, "init", { value: init });
|
|
254
|
+
Object.defineProperty(_, Symbol.hasInstance, {
|
|
255
|
+
value: (inst) => {
|
|
256
|
+
if (params?.Parent && inst instanceof params.Parent)
|
|
257
|
+
return true;
|
|
258
|
+
return inst?._zod?.traits?.has(name);
|
|
270
259
|
}
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
(function(objectUtil2) {
|
|
276
|
-
objectUtil2.mergeShapes = (first, second) => {
|
|
277
|
-
return {
|
|
278
|
-
...first,
|
|
279
|
-
...second
|
|
280
|
-
// second overwrites first
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
})(objectUtil || (objectUtil = {}));
|
|
284
|
-
util.arrayToEnum([
|
|
285
|
-
"string",
|
|
286
|
-
"nan",
|
|
287
|
-
"number",
|
|
288
|
-
"integer",
|
|
289
|
-
"float",
|
|
290
|
-
"boolean",
|
|
291
|
-
"date",
|
|
292
|
-
"bigint",
|
|
293
|
-
"symbol",
|
|
294
|
-
"function",
|
|
295
|
-
"undefined",
|
|
296
|
-
"null",
|
|
297
|
-
"array",
|
|
298
|
-
"object",
|
|
299
|
-
"unknown",
|
|
300
|
-
"promise",
|
|
301
|
-
"void",
|
|
302
|
-
"never",
|
|
303
|
-
"map",
|
|
304
|
-
"set"
|
|
305
|
-
]);
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(_, "name", { value: name });
|
|
262
|
+
return _;
|
|
263
|
+
}
|
|
306
264
|
|
|
307
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
308
|
-
|
|
309
|
-
"
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
"
|
|
317
|
-
"
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
"
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
const actualProto = new.target.prototype;
|
|
340
|
-
if (Object.setPrototypeOf) {
|
|
341
|
-
Object.setPrototypeOf(this, actualProto);
|
|
265
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js
|
|
266
|
+
function jsonStringifyReplacer(_, value) {
|
|
267
|
+
if (typeof value === "bigint")
|
|
268
|
+
return value.toString();
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js
|
|
273
|
+
var initializer = (inst, def) => {
|
|
274
|
+
inst.name = "$ZodError";
|
|
275
|
+
Object.defineProperty(inst, "_zod", {
|
|
276
|
+
value: inst._zod,
|
|
277
|
+
enumerable: false
|
|
278
|
+
});
|
|
279
|
+
Object.defineProperty(inst, "issues", {
|
|
280
|
+
value: def,
|
|
281
|
+
enumerable: false
|
|
282
|
+
});
|
|
283
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
284
|
+
Object.defineProperty(inst, "toString", {
|
|
285
|
+
value: () => inst.message,
|
|
286
|
+
enumerable: false
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
var $ZodError = $constructor("$ZodError", initializer);
|
|
290
|
+
function flattenError(error, mapper = (issue2) => issue2.message) {
|
|
291
|
+
const fieldErrors = {};
|
|
292
|
+
const formErrors = [];
|
|
293
|
+
for (const sub of error.issues) {
|
|
294
|
+
if (sub.path.length > 0) {
|
|
295
|
+
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
296
|
+
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
342
297
|
} else {
|
|
343
|
-
|
|
298
|
+
formErrors.push(mapper(sub));
|
|
344
299
|
}
|
|
345
|
-
this.name = "ZodError";
|
|
346
|
-
this.issues = issues;
|
|
347
300
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
curr[el]._errors.push(mapper(issue));
|
|
374
|
-
}
|
|
375
|
-
curr = curr[el];
|
|
376
|
-
i++;
|
|
301
|
+
return { formErrors, fieldErrors };
|
|
302
|
+
}
|
|
303
|
+
function formatError(error, mapper = (issue2) => issue2.message) {
|
|
304
|
+
const fieldErrors = { _errors: [] };
|
|
305
|
+
const processError = (error2) => {
|
|
306
|
+
for (const issue2 of error2.issues) {
|
|
307
|
+
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
308
|
+
issue2.errors.map((issues) => processError({ issues }));
|
|
309
|
+
} else if (issue2.code === "invalid_key") {
|
|
310
|
+
processError({ issues: issue2.issues });
|
|
311
|
+
} else if (issue2.code === "invalid_element") {
|
|
312
|
+
processError({ issues: issue2.issues });
|
|
313
|
+
} else if (issue2.path.length === 0) {
|
|
314
|
+
fieldErrors._errors.push(mapper(issue2));
|
|
315
|
+
} else {
|
|
316
|
+
let curr = fieldErrors;
|
|
317
|
+
let i = 0;
|
|
318
|
+
while (i < issue2.path.length) {
|
|
319
|
+
const el = issue2.path[i];
|
|
320
|
+
const terminal = i === issue2.path.length - 1;
|
|
321
|
+
if (!terminal) {
|
|
322
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
323
|
+
} else {
|
|
324
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
325
|
+
curr[el]._errors.push(mapper(issue2));
|
|
377
326
|
}
|
|
327
|
+
curr = curr[el];
|
|
328
|
+
i++;
|
|
378
329
|
}
|
|
379
330
|
}
|
|
380
|
-
};
|
|
381
|
-
processError(this);
|
|
382
|
-
return fieldErrors;
|
|
383
|
-
}
|
|
384
|
-
static assert(value) {
|
|
385
|
-
if (!(value instanceof _ZodError)) {
|
|
386
|
-
throw new Error(`Not a ZodError: ${value}`);
|
|
387
331
|
}
|
|
332
|
+
};
|
|
333
|
+
processError(error);
|
|
334
|
+
return fieldErrors;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js
|
|
338
|
+
var _a;
|
|
339
|
+
var $ZodRegistry = class {
|
|
340
|
+
constructor() {
|
|
341
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
342
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
343
|
+
}
|
|
344
|
+
add(schema, ..._meta) {
|
|
345
|
+
const meta = _meta[0];
|
|
346
|
+
this._map.set(schema, meta);
|
|
347
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
348
|
+
this._idmap.set(meta.id, schema);
|
|
349
|
+
}
|
|
350
|
+
return this;
|
|
388
351
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
352
|
+
clear() {
|
|
353
|
+
this._map = /* @__PURE__ */ new WeakMap();
|
|
354
|
+
this._idmap = /* @__PURE__ */ new Map();
|
|
355
|
+
return this;
|
|
394
356
|
}
|
|
395
|
-
|
|
396
|
-
|
|
357
|
+
remove(schema) {
|
|
358
|
+
const meta = this._map.get(schema);
|
|
359
|
+
if (meta && typeof meta === "object" && "id" in meta) {
|
|
360
|
+
this._idmap.delete(meta.id);
|
|
361
|
+
}
|
|
362
|
+
this._map.delete(schema);
|
|
363
|
+
return this;
|
|
397
364
|
}
|
|
398
|
-
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
fieldErrors[firstEl].push(mapper(sub));
|
|
406
|
-
} else {
|
|
407
|
-
formErrors.push(mapper(sub));
|
|
408
|
-
}
|
|
365
|
+
get(schema) {
|
|
366
|
+
const p = schema._zod.parent;
|
|
367
|
+
if (p) {
|
|
368
|
+
const pm = { ...this.get(p) ?? {} };
|
|
369
|
+
delete pm.id;
|
|
370
|
+
const f = { ...pm, ...this._map.get(schema) };
|
|
371
|
+
return Object.keys(f).length ? f : void 0;
|
|
409
372
|
}
|
|
410
|
-
return
|
|
373
|
+
return this._map.get(schema);
|
|
411
374
|
}
|
|
412
|
-
|
|
413
|
-
return this.
|
|
375
|
+
has(schema) {
|
|
376
|
+
return this._map.has(schema);
|
|
414
377
|
}
|
|
415
378
|
};
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
379
|
+
function registry() {
|
|
380
|
+
return new $ZodRegistry();
|
|
381
|
+
}
|
|
382
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
383
|
+
|
|
384
|
+
// ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js
|
|
385
|
+
var initializer2 = (inst, issues) => {
|
|
386
|
+
$ZodError.init(inst, issues);
|
|
387
|
+
inst.name = "ZodError";
|
|
388
|
+
Object.defineProperties(inst, {
|
|
389
|
+
format: {
|
|
390
|
+
value: (mapper) => formatError(inst, mapper)
|
|
391
|
+
// enumerable: false,
|
|
392
|
+
},
|
|
393
|
+
flatten: {
|
|
394
|
+
value: (mapper) => flattenError(inst, mapper)
|
|
395
|
+
// enumerable: false,
|
|
396
|
+
},
|
|
397
|
+
addIssue: {
|
|
398
|
+
value: (issue2) => {
|
|
399
|
+
inst.issues.push(issue2);
|
|
400
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
401
|
+
}
|
|
402
|
+
// enumerable: false,
|
|
403
|
+
},
|
|
404
|
+
addIssues: {
|
|
405
|
+
value: (issues2) => {
|
|
406
|
+
inst.issues.push(...issues2);
|
|
407
|
+
inst.message = JSON.stringify(inst.issues, jsonStringifyReplacer, 2);
|
|
408
|
+
}
|
|
409
|
+
// enumerable: false,
|
|
410
|
+
},
|
|
411
|
+
isEmpty: {
|
|
412
|
+
get() {
|
|
413
|
+
return inst.issues.length === 0;
|
|
414
|
+
}
|
|
415
|
+
// enumerable: false,
|
|
416
|
+
}
|
|
417
|
+
});
|
|
419
418
|
};
|
|
419
|
+
var ZodError = $constructor("ZodError", initializer2);
|
|
420
420
|
|
|
421
421
|
// src/index.ts
|
|
422
422
|
var _hasPermissionPromise;
|
|
@@ -701,7 +701,8 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
701
701
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
702
702
|
});
|
|
703
703
|
if (error instanceof ZodError) {
|
|
704
|
-
|
|
704
|
+
const { status, body } = this.resolveValidationError(route, error, "query");
|
|
705
|
+
return c.json(body, status);
|
|
705
706
|
}
|
|
706
707
|
return c.json(
|
|
707
708
|
{
|
|
@@ -720,7 +721,8 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
720
721
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
721
722
|
});
|
|
722
723
|
if (error instanceof ZodError) {
|
|
723
|
-
|
|
724
|
+
const { status, body } = this.resolveValidationError(route, error, "body");
|
|
725
|
+
return c.json(body, status);
|
|
724
726
|
}
|
|
725
727
|
return c.json(
|
|
726
728
|
{
|
|
@@ -739,7 +741,8 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
739
741
|
error: error instanceof Error ? { message: error.message, stack: error.stack } : error
|
|
740
742
|
});
|
|
741
743
|
if (error instanceof ZodError) {
|
|
742
|
-
|
|
744
|
+
const { status, body } = this.resolveValidationError(route, error, "path");
|
|
745
|
+
return c.json(body, status);
|
|
743
746
|
}
|
|
744
747
|
return c.json(
|
|
745
748
|
{
|
|
@@ -887,14 +890,14 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
887
890
|
const method = c.req.method;
|
|
888
891
|
const path = c.req.path;
|
|
889
892
|
await next();
|
|
890
|
-
const
|
|
893
|
+
const duration2 = Date.now() - start;
|
|
891
894
|
const status = c.res.status;
|
|
892
895
|
const level = this.httpLoggingConfig?.level || "info";
|
|
893
896
|
const logData = {
|
|
894
897
|
method,
|
|
895
898
|
path,
|
|
896
899
|
status,
|
|
897
|
-
duration: `${
|
|
900
|
+
duration: `${duration2}ms`
|
|
898
901
|
};
|
|
899
902
|
if (this.httpLoggingConfig?.includeQueryParams) {
|
|
900
903
|
logData.query = c.req.query();
|
|
@@ -910,7 +913,7 @@ var MastraServer = class extends MastraServer$1 {
|
|
|
910
913
|
});
|
|
911
914
|
logData.headers = headers;
|
|
912
915
|
}
|
|
913
|
-
this.logger[level](`${method} ${path} ${status} ${
|
|
916
|
+
this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
|
|
914
917
|
});
|
|
915
918
|
}
|
|
916
919
|
};
|