autotel-adapters 3.0.0 → 3.0.1

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/README.md CHANGED
@@ -139,6 +139,11 @@ workspace package's dependency in a monorepo. `withAutotelConfig` fails the
139
139
  build instead. `autotel-adapters/next-config` has no runtime dependency, so
140
140
  `next.config.ts` can import it.
141
141
 
142
+ Hono inside Next follows the same rule: keep `autotel-adapters` and `hono` on
143
+ the same side of that line. Bundle both with the app, or list both in
144
+ `serverExternalPackages`. When they resolve different copies, the Hono adapter
145
+ names the route through the request instead and warns once.
146
+
142
147
  ## Nitro
143
148
 
144
149
  ```ts
package/dist/hono.cjs CHANGED
@@ -45,9 +45,9 @@ function autotelMiddleware(options = {}) {
45
45
  }
46
46
  require_integration.applyLoggerEnrichment(handle.logger, enrichFromContext(c), options.enrichRequest?.(c));
47
47
  const matchedRoute = () => {
48
- const routes = (0, hono_route.matchedRoutes)(c);
48
+ const routes = routesOf(c);
49
49
  const ran = c.req.routeIndex;
50
- const path = (routes.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes[ran] ?? routes.at(-1))?.path;
50
+ const path = (routes?.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes?.[ran] ?? routes?.at(-1))?.path;
51
51
  return !path || path === "*" ? "/*" : path;
52
52
  };
53
53
  try {
@@ -67,6 +67,31 @@ function autotelMiddleware(options = {}) {
67
67
  });
68
68
  };
69
69
  }
70
+ let warnedOtherHono = false;
71
+ /**
72
+ * The routes the request matched. `hono/route` reads them through a symbol
73
+ * private to the copy of Hono this module loaded, so when the app runs another
74
+ * copy (a bundled app beside an externalised adapter) it finds nothing. The
75
+ * request's own getter is the app's copy answering, so it is the fallback.
76
+ * Naming a span is best effort: a lookup that fails names it `/*` and never
77
+ * fails the request.
78
+ */
79
+ function routesOf(c) {
80
+ try {
81
+ return (0, hono_route.matchedRoutes)(c);
82
+ } catch {
83
+ if (!warnedOtherHono) {
84
+ warnedOtherHono = true;
85
+ console.warn("[autotel-adapters/hono] Could not read the matched route through hono/route, most likely because the app and autotel-adapters loaded different copies of Hono. Bundle autotel-adapters with the app, or externalise hono too.");
86
+ }
87
+ }
88
+ try {
89
+ const routes = c.req.matchedRoutes;
90
+ return Array.isArray(routes) ? routes : void 0;
91
+ } catch {
92
+ return;
93
+ }
94
+ }
70
95
  /** Alias for {@link useLogger} inside autotelMiddleware. */
71
96
  const useLoggerFromContext = useLogger;
72
97
 
package/dist/hono.js CHANGED
@@ -44,9 +44,9 @@ function autotelMiddleware(options = {}) {
44
44
  }
45
45
  applyLoggerEnrichment(handle.logger, enrichFromContext(c), options.enrichRequest?.(c));
46
46
  const matchedRoute = () => {
47
- const routes = matchedRoutes(c);
47
+ const routes = routesOf(c);
48
48
  const ran = c.req.routeIndex;
49
- const path = (routes.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes[ran] ?? routes.at(-1))?.path;
49
+ const path = (routes?.slice(ran + 1).findLast((route) => !route.path.endsWith("*")) ?? routes?.[ran] ?? routes?.at(-1))?.path;
50
50
  return !path || path === "*" ? "/*" : path;
51
51
  };
52
52
  try {
@@ -66,6 +66,31 @@ function autotelMiddleware(options = {}) {
66
66
  });
67
67
  };
68
68
  }
69
+ let warnedOtherHono = false;
70
+ /**
71
+ * The routes the request matched. `hono/route` reads them through a symbol
72
+ * private to the copy of Hono this module loaded, so when the app runs another
73
+ * copy (a bundled app beside an externalised adapter) it finds nothing. The
74
+ * request's own getter is the app's copy answering, so it is the fallback.
75
+ * Naming a span is best effort: a lookup that fails names it `/*` and never
76
+ * fails the request.
77
+ */
78
+ function routesOf(c) {
79
+ try {
80
+ return matchedRoutes(c);
81
+ } catch {
82
+ if (!warnedOtherHono) {
83
+ warnedOtherHono = true;
84
+ console.warn("[autotel-adapters/hono] Could not read the matched route through hono/route, most likely because the app and autotel-adapters loaded different copies of Hono. Bundle autotel-adapters with the app, or externalise hono too.");
85
+ }
86
+ }
87
+ try {
88
+ const routes = c.req.matchedRoutes;
89
+ return Array.isArray(routes) ? routes : void 0;
90
+ } catch {
91
+ return;
92
+ }
93
+ }
69
94
  /** Alias for {@link useLogger} inside autotelMiddleware. */
70
95
  const useLoggerFromContext = useLogger;
71
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel-adapters",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Framework adapters and composable DX helpers for autotel",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -91,7 +91,7 @@
91
91
  "NOTICE"
92
92
  ],
93
93
  "dependencies": {
94
- "autotel": "8.5.0",
94
+ "autotel": "8.6.0",
95
95
  "autotel-edge": "6.1.3"
96
96
  },
97
97
  "peerDependencies": {