@mastra/koa 1.5.2-alpha.10 → 1.5.2-alpha.14

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,59 @@
1
1
  # @mastra/koa
2
2
 
3
+ ## 1.5.2-alpha.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`05dab92`](https://github.com/mastra-ai/mastra/commit/05dab92b3373306a4791c3a035a3100dd9a76b7f)]:
8
+ - @mastra/server@1.33.0-alpha.14
9
+ - @mastra/core@1.33.0-alpha.14
10
+
11
+ ## 1.5.2-alpha.13
12
+
13
+ ### Patch Changes
14
+
15
+ - Fixed `TypeError: Cannot read properties of undefined (reading 'length')` thrown during `MastraServer.init()` when a subclass forwards a non-Koa app-like object (for example a `koa-router` instance, a mounted sub-app, or a custom wrapper) to `super.registerRoute(app, route, opts)`. The dispatcher-reuse optimization introduced in 1.5.0 now requires the target to expose an `app.middleware` array; otherwise it falls back to registering a fresh dispatcher per route via `app.use`, matching the pre-1.5.0 per-route behavior. ([#16484](https://github.com/mastra-ai/mastra/pull/16484))
16
+
17
+ **Example (subclass that previously crashed):**
18
+
19
+ ```ts
20
+ import { MastraServer } from '@mastra/koa';
21
+ import Router from 'koa-router';
22
+
23
+ class CustomKoaMastraServer extends MastraServer {
24
+ private router = new Router();
25
+
26
+ async registerCustomApiRoutes() {
27
+ const routes = this.mastra.getServer()?.apiRoutes ?? [];
28
+ for (const route of routes) {
29
+ // The router has no `middleware` array — this used to throw at init.
30
+ await super.registerRoute(this.router as any, route, { prefix: this.prefix });
31
+ }
32
+ this.app.use(this.router.routes());
33
+ }
34
+ }
35
+ ```
36
+
37
+ - Updated dependencies [[`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e)]:
38
+ - @mastra/core@1.33.0-alpha.13
39
+ - @mastra/server@1.33.0-alpha.13
40
+
41
+ ## 1.5.2-alpha.12
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [[`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a)]:
46
+ - @mastra/core@1.33.0-alpha.12
47
+ - @mastra/server@1.33.0-alpha.12
48
+
49
+ ## 1.5.2-alpha.11
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [[`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f)]:
54
+ - @mastra/core@1.33.0-alpha.11
55
+ - @mastra/server@1.33.0-alpha.11
56
+
3
57
  ## 1.5.2-alpha.10
4
58
 
5
59
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -449,17 +449,23 @@ var MastraServer = class extends serverAdapter.MastraServer {
449
449
  };
450
450
  }
451
451
  getRouteDispatcherGroup(app) {
452
- const activeGroup = this.activeRouteDispatchers.get(app);
453
- if (activeGroup && app.middleware.length === activeGroup.stackLengthAfterRegistration) {
454
- return activeGroup;
452
+ const middlewareStack = app.middleware;
453
+ const supportsReuse = Array.isArray(middlewareStack);
454
+ if (supportsReuse) {
455
+ const activeGroup = this.activeRouteDispatchers.get(app);
456
+ if (activeGroup && middlewareStack.length === activeGroup.stackLengthAfterRegistration) {
457
+ return activeGroup;
458
+ }
455
459
  }
456
460
  const group = {
457
461
  routes: [],
458
462
  stackLengthAfterRegistration: 0
459
463
  };
460
464
  app.use(this.createRouteDispatcherMiddleware(group));
461
- group.stackLengthAfterRegistration = app.middleware.length;
462
- this.activeRouteDispatchers.set(app, group);
465
+ if (supportsReuse) {
466
+ group.stackLengthAfterRegistration = app.middleware.length;
467
+ this.activeRouteDispatchers.set(app, group);
468
+ }
463
469
  return group;
464
470
  }
465
471
  createRouteDispatcherMiddleware(group) {