@mastra/hono 1.4.8-alpha.0 → 1.4.8-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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @mastra/hono
2
2
 
3
+ ## 1.4.8-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Refactored Hono adapter's `registerCustomApiRoutes()` to use the shared `buildCustomRouteHandler()` from the base class instead of duplicating route/handler resolution logic. Added `forwardCustomRouteRequest()` to the base class for adapters that already have a raw `Request` object (avoiding unnecessary request reconstruction). ([#15793](https://github.com/mastra-ai/mastra/pull/15793))
8
+
9
+ - Updated dependencies [[`9e973b0`](https://github.com/mastra-ai/mastra/commit/9e973b010dacfa15ac82b0072897319f5234b90a), [`dd934a0`](https://github.com/mastra-ai/mastra/commit/dd934a0982ce0f78712fbd559e4f2410bf594b39), [`73f2809`](https://github.com/mastra-ai/mastra/commit/73f2809721db24e98cdf122539652a455211b450), [`f85ab4a`](https://github.com/mastra-ai/mastra/commit/f85ab4a3cce3d4376a4fc3c08feeb380cee2927c), [`aedeea4`](https://github.com/mastra-ai/mastra/commit/aedeea48a94f728323f040478775076b9574be50), [`a9a3463`](https://github.com/mastra-ai/mastra/commit/a9a34638b16d0956f35290a52ed0a44cd926110b), [`441670a`](https://github.com/mastra-ai/mastra/commit/441670a02c9dc7731c52674f55481e7848a84523), [`8126d86`](https://github.com/mastra-ai/mastra/commit/8126d8638411eacfafdc29036ac998e8757ea66f), [`ae97520`](https://github.com/mastra-ai/mastra/commit/ae975206fdb0f6ef03c4d5bf94f7dc7c3f706c02), [`441670a`](https://github.com/mastra-ai/mastra/commit/441670a02c9dc7731c52674f55481e7848a84523)]:
10
+ - @mastra/core@1.29.0-alpha.2
11
+ - @mastra/server@1.29.0-alpha.2
12
+
13
+ ## 1.4.8-alpha.1
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`7a7b313`](https://github.com/mastra-ai/mastra/commit/7a7b3138fb3bcf0b0c740eaea07971e43d330ef3), [`a6dac0a`](https://github.com/mastra-ai/mastra/commit/a6dac0a40c7181161b1add4e8534f962bcbc9aa7), [`9cef83b`](https://github.com/mastra-ai/mastra/commit/9cef83b8a642b8098747772921e3523b492bafbc), [`d30e215`](https://github.com/mastra-ai/mastra/commit/d30e2156c746bc9fd791745cec1cc24377b66789), [`73b45fa`](https://github.com/mastra-ai/mastra/commit/73b45facdef4fbcb8af710c50f0646f18619dbaa), [`7a7b313`](https://github.com/mastra-ai/mastra/commit/7a7b3138fb3bcf0b0c740eaea07971e43d330ef3)]:
18
+ - @mastra/core@1.29.0-alpha.1
19
+ - @mastra/server@1.29.0-alpha.1
20
+
3
21
  ## 1.4.8-alpha.0
4
22
 
5
23
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -945,12 +945,9 @@ var MastraServer = class extends serverAdapter.MastraServer {
945
945
  );
946
946
  }
947
947
  async registerCustomApiRoutes() {
948
- const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes;
949
- if (!routes || routes.length === 0) return;
948
+ if (!await this.buildCustomRouteHandler()) return;
949
+ const routes = this.customApiRoutes ?? this.mastra.getServer()?.apiRoutes ?? [];
950
950
  for (const route of routes) {
951
- const handler = "handler" in route && route.handler ? route.handler : "createHandler" in route ? await route.createHandler({ mastra: this.mastra }) : void 0;
952
- if (!handler) continue;
953
- const middlewares = [];
954
951
  const serverRoute = {
955
952
  method: route.method,
956
953
  path: route.path,
@@ -959,7 +956,7 @@ var MastraServer = class extends serverAdapter.MastraServer {
959
956
  },
960
957
  requiresAuth: route.requiresAuth
961
958
  };
962
- middlewares.push(async (c, next) => {
959
+ const routeHandler = async (c) => {
963
960
  const authError = await this.checkRouteAuth(serverRoute, {
964
961
  path: c.req.path,
965
962
  method: c.req.method,
@@ -986,14 +983,24 @@ var MastraServer = class extends serverAdapter.MastraServer {
986
983
  }
987
984
  }
988
985
  }
989
- return next();
990
- });
991
- if (route.middleware) {
992
- middlewares.push(...Array.isArray(route.middleware) ? route.middleware : [route.middleware]);
993
- }
994
- const allHandlers = [...middlewares, handler];
986
+ const reqHeaders = {};
987
+ c.req.raw.headers.forEach((v, k) => {
988
+ reqHeaders[k] = v;
989
+ });
990
+ const response = await this.handleCustomRouteRequest(
991
+ c.req.url,
992
+ c.req.method,
993
+ reqHeaders,
994
+ c.req.raw.body,
995
+ c.get("requestContext")
996
+ );
997
+ if (!response) {
998
+ return c.json({ error: "Not Found" }, 404);
999
+ }
1000
+ return response;
1001
+ };
995
1002
  const method = route.method.toLowerCase();
996
- this.app[method](route.path, allHandlers[0], ...allHandlers.slice(1));
1003
+ this.app[method](route.path, routeHandler);
997
1004
  }
998
1005
  }
999
1006
  registerContextMiddleware() {