@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/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 version = typeof Bun !== "undefined" ? Bun.version : void 0;
177
- if (version === void 0) {
175
+ const version2 = typeof Bun !== "undefined" ? Bun.version : void 0;
176
+ if (version2 === void 0) {
178
177
  return false;
179
178
  }
180
- const result = version.startsWith("1.1") || version.startsWith("1.0") || version.startsWith("0.");
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
- // ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
215
- var util;
216
- (function(util2) {
217
- util2.assertEqual = (_) => {
218
- };
219
- function assertIs(_arg) {
220
- }
221
- util2.assertIs = assertIs;
222
- function assertNever(_x) {
223
- throw new Error();
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
- return obj;
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
- return util2.objectValues(filtered);
240
- };
241
- util2.objectValues = (obj) => {
242
- return util2.objectKeys(obj).map(function(e) {
243
- return obj[e];
244
- });
245
- };
246
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
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
- return keys;
254
- };
255
- util2.find = (arr, checker) => {
256
- for (const item of arr) {
257
- if (checker(item))
258
- return item;
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 void 0;
261
- };
262
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
263
- function joinValues(array, separator = " | ") {
264
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
265
- }
266
- util2.joinValues = joinValues;
267
- util2.jsonStringifyReplacer = (_, value) => {
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
- return value;
272
- };
273
- })(util || (util = {}));
274
- var objectUtil;
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.25.76/node_modules/zod/v3/ZodError.js
308
- util.arrayToEnum([
309
- "invalid_type",
310
- "invalid_literal",
311
- "custom",
312
- "invalid_union",
313
- "invalid_union_discriminator",
314
- "invalid_enum_value",
315
- "unrecognized_keys",
316
- "invalid_arguments",
317
- "invalid_return_type",
318
- "invalid_date",
319
- "invalid_string",
320
- "too_small",
321
- "too_big",
322
- "invalid_intersection_types",
323
- "not_multiple_of",
324
- "not_finite"
325
- ]);
326
- var ZodError = class _ZodError extends Error {
327
- get errors() {
328
- return this.issues;
329
- }
330
- constructor(issues) {
331
- super();
332
- this.issues = [];
333
- this.addIssue = (sub) => {
334
- this.issues = [...this.issues, sub];
335
- };
336
- this.addIssues = (subs = []) => {
337
- this.issues = [...this.issues, ...subs];
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
- this.__proto__ = actualProto;
298
+ formErrors.push(mapper(sub));
344
299
  }
345
- this.name = "ZodError";
346
- this.issues = issues;
347
300
  }
348
- format(_mapper) {
349
- const mapper = _mapper || function(issue) {
350
- return issue.message;
351
- };
352
- const fieldErrors = { _errors: [] };
353
- const processError = (error) => {
354
- for (const issue of error.issues) {
355
- if (issue.code === "invalid_union") {
356
- issue.unionErrors.map(processError);
357
- } else if (issue.code === "invalid_return_type") {
358
- processError(issue.returnTypeError);
359
- } else if (issue.code === "invalid_arguments") {
360
- processError(issue.argumentsError);
361
- } else if (issue.path.length === 0) {
362
- fieldErrors._errors.push(mapper(issue));
363
- } else {
364
- let curr = fieldErrors;
365
- let i = 0;
366
- while (i < issue.path.length) {
367
- const el = issue.path[i];
368
- const terminal = i === issue.path.length - 1;
369
- if (!terminal) {
370
- curr[el] = curr[el] || { _errors: [] };
371
- } else {
372
- curr[el] = curr[el] || { _errors: [] };
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
- toString() {
390
- return this.message;
391
- }
392
- get message() {
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
- get isEmpty() {
396
- return this.issues.length === 0;
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
- flatten(mapper = (issue) => issue.message) {
399
- const fieldErrors = {};
400
- const formErrors = [];
401
- for (const sub of this.issues) {
402
- if (sub.path.length > 0) {
403
- const firstEl = sub.path[0];
404
- fieldErrors[firstEl] = fieldErrors[firstEl] || [];
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 { formErrors, fieldErrors };
373
+ return this._map.get(schema);
411
374
  }
412
- get formErrors() {
413
- return this.flatten();
375
+ has(schema) {
376
+ return this._map.has(schema);
414
377
  }
415
378
  };
416
- ZodError.create = (issues) => {
417
- const error = new ZodError(issues);
418
- return error;
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
- return c.json(formatZodError(error, "query parameters"), 400);
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
- return c.json(formatZodError(error, "request body"), 400);
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
- return c.json(formatZodError(error, "path parameters"), 400);
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 duration = Date.now() - start;
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: `${duration}ms`
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} ${duration}ms`, logData);
916
+ this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
914
917
  });
915
918
  }
916
919
  };