@mastra/express 1.3.24-alpha.5 → 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/dist/index.js CHANGED
@@ -4,6 +4,9 @@ import { MastraServer as MastraServer$1, redactStreamChunk, normalizeQueryParams
4
4
  import { RequestContext } from '@mastra/core/request-context';
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.6/node_modules/zod/v4/core/util.js
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.6/node_modules/zod/v4/core/errors.js
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 = (issue2) => issue2.message) {
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 = (issue2) => issue2.message) {
102
+ function formatError(error, mapper = (issue) => issue.message) {
99
103
  const fieldErrors = { _errors: [] };
100
- const processError = (error2) => {
101
- for (const issue2 of error2.issues) {
102
- if (issue2.code === "invalid_union" && issue2.errors.length) {
103
- issue2.errors.map((issues) => processError({ issues }));
104
- } else if (issue2.code === "invalid_key") {
105
- processError({ issues: issue2.issues });
106
- } else if (issue2.code === "invalid_element") {
107
- processError({ issues: issue2.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
- let curr = fieldErrors;
112
- let i = 0;
113
- while (i < issue2.path.length) {
114
- const el = issue2.path[i];
115
- const terminal = i === issue2.path.length - 1;
116
- if (!terminal) {
117
- curr[el] = curr[el] || { _errors: [] };
118
- } else {
119
- curr[el] = curr[el] || { _errors: [] };
120
- curr[el]._errors.push(mapper(issue2));
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.6/node_modules/zod/v4/core/registries.js
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: (issue2) => {
194
- inst.issues.push(issue2);
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(req) {
216
176
  const protocol = req.protocol || "http";
217
177
  const host = req.get("host") || "localhost";
@@ -379,6 +339,10 @@ var MastraServer = class extends MastraServer$1 {
379
339
  const { done, value } = await reader.read();
380
340
  if (done) break;
381
341
  if (value) {
342
+ if (streamFormat === "sse" && typeof value === "string" && value.startsWith(":")) {
343
+ res.write(value);
344
+ continue;
345
+ }
382
346
  const shouldRedact = this.streamOptions?.redact ?? true;
383
347
  const outputValue = shouldRedact ? redactStreamChunk(value) : value;
384
348
  if (streamFormat === "sse") {
@@ -794,10 +758,11 @@ var MastraServer = class extends MastraServer$1 {
794
758
  req.method,
795
759
  req.headers,
796
760
  req.body,
797
- res.locals.requestContext
761
+ res.locals.requestContext,
762
+ res.locals.abortSignal
798
763
  );
799
764
  if (!response) return next();
800
- await this.writeCustomRouteResponse(response, res);
765
+ await this.writeCustomRouteResponse(response, res, res.locals.abortSignal);
801
766
  });
802
767
  }
803
768
  registerContextMiddleware() {
@@ -817,14 +782,14 @@ var MastraServer = class extends MastraServer$1 {
817
782
  const method = req.method;
818
783
  const path = req.path;
819
784
  res.on("finish", () => {
820
- const duration2 = Date.now() - start;
785
+ const duration = Date.now() - start;
821
786
  const status = res.statusCode;
822
787
  const level = this.httpLoggingConfig?.level || "info";
823
788
  const logData = {
824
789
  method,
825
790
  path,
826
791
  status,
827
- duration: `${duration2}ms`
792
+ duration: `${duration}ms`
828
793
  };
829
794
  if (this.httpLoggingConfig?.includeQueryParams) {
830
795
  logData.query = req.query;
@@ -840,7 +805,7 @@ var MastraServer = class extends MastraServer$1 {
840
805
  });
841
806
  logData.headers = headers;
842
807
  }
843
- this.logger[level](`${method} ${path} ${status} ${duration2}ms`, logData);
808
+ this.logger[level](`${method} ${path} ${status} ${duration}ms`, logData);
844
809
  });
845
810
  next();
846
811
  });