@basaltkit/hono 1.4.1 → 1.5.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.d.ts +8 -2
- package/dist/index.js +12 -5
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Container } from '@basaltkit/core';
|
|
2
|
-
import { type BasaltRoute, type RequestEnricher, type RouteGuard } from '@basaltkit/http';
|
|
2
|
+
import { type HttpErrorReporter, type BasaltRoute, type RequestEnricher, type RouteGuard } from '@basaltkit/http';
|
|
3
3
|
import { Hono } from 'hono';
|
|
4
4
|
export declare const HONO: import("@basaltkit/core").Token<Hono<any, import("hono/types").BlankSchema, "/">>;
|
|
5
5
|
/** Default maximum request body size (1 MiB) — override via honoPlugin({ bodyLimit }). */
|
|
6
6
|
export declare const DEFAULT_BODY_LIMIT = 1048576;
|
|
7
7
|
/** Mounts Basalt routes on a Hono app (usable without the plugin). */
|
|
8
|
-
export declare function registerRoutes(app: Hono<any>, routes: BasaltRoute[], container?: Container, enrichers?: RequestEnricher[], guards?: RouteGuard[]): void;
|
|
8
|
+
export declare function registerRoutes(app: Hono<any>, routes: BasaltRoute[], container?: Container, enrichers?: RequestEnricher[], guards?: RouteGuard[], onError?: HttpErrorReporter): void;
|
|
9
9
|
export interface HonoPluginOptions {
|
|
10
10
|
routes?: BasaltRoute[];
|
|
11
11
|
/**
|
|
@@ -23,6 +23,12 @@ export interface HonoPluginOptions {
|
|
|
23
23
|
* text default. Default: true. An app calling `hono.notFound(…)` later
|
|
24
24
|
* still wins (Hono keeps the last handler); pass false to opt out entirely.
|
|
25
25
|
*/
|
|
26
|
+
/**
|
|
27
|
+
* Where failed requests are reported. Default: 5xx via `console.error` (with
|
|
28
|
+
* the stack) and 4xx via `console.warn`, prefixed `[basalt:http]`. Pass your
|
|
29
|
+
* own to route them into a real logger, or `() => {}` to silence them.
|
|
30
|
+
*/
|
|
31
|
+
onError?: HttpErrorReporter;
|
|
26
32
|
notFound?: boolean;
|
|
27
33
|
/**
|
|
28
34
|
* Maximum request body size in bytes. A request whose `Content-Length`
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Container, createToken, definePlugin, ensureMetadata } from '@basaltkit/core';
|
|
2
|
-
import { NOT_FOUND_RESPONSE, HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, GUARDED_META_BUCKET, assertRoutesGuarded, } from '@basaltkit/http';
|
|
2
|
+
import { NOT_FOUND_RESPONSE, HttpServerCollector, HTTP_SERVER, runRoute, toErrorResponse, reportHttpError, isSseResponse, sseProducerOf, driveSse, SSE_HEADERS, GUARDED_META_BUCKET, assertRoutesGuarded, } from '@basaltkit/http';
|
|
3
3
|
import { Hono } from 'hono';
|
|
4
4
|
export const HONO = createToken('hono');
|
|
5
5
|
/** Default maximum request body size (1 MiB) — override via honoPlugin({ bodyLimit }). */
|
|
@@ -109,7 +109,7 @@ function toResponse(reply, payload) {
|
|
|
109
109
|
}
|
|
110
110
|
return new Response(body, { status: reply.statusCode, headers });
|
|
111
111
|
}
|
|
112
|
-
function handlerFor(definition, container, enrichers, guards) {
|
|
112
|
+
function handlerFor(definition, container, enrichers, guards, onError) {
|
|
113
113
|
return async (context) => {
|
|
114
114
|
const reply = new HonoReply(context);
|
|
115
115
|
try {
|
|
@@ -124,6 +124,13 @@ function handlerFor(definition, container, enrichers, guards) {
|
|
|
124
124
|
}
|
|
125
125
|
catch (error) {
|
|
126
126
|
const { status, body } = toErrorResponse(error);
|
|
127
|
+
// This adapter previously reported nothing at all — a 500 reached the
|
|
128
|
+
// client and left no trace whatsoever on the server.
|
|
129
|
+
const entry = { error, status, code: body.error.code, method: context.req.method, url: context.req.url };
|
|
130
|
+
if (onError)
|
|
131
|
+
onError(entry);
|
|
132
|
+
else
|
|
133
|
+
reportHttpError(entry);
|
|
127
134
|
return new Response(JSON.stringify(body), {
|
|
128
135
|
status,
|
|
129
136
|
headers: { 'content-type': 'application/json' },
|
|
@@ -132,9 +139,9 @@ function handlerFor(definition, container, enrichers, guards) {
|
|
|
132
139
|
};
|
|
133
140
|
}
|
|
134
141
|
/** Mounts Basalt routes on a Hono app (usable without the plugin). */
|
|
135
|
-
export function registerRoutes(app, routes, container, enrichers = [], guards = []) {
|
|
142
|
+
export function registerRoutes(app, routes, container, enrichers = [], guards = [], onError) {
|
|
136
143
|
for (const definition of routes) {
|
|
137
|
-
app.on(definition.method, definition.url, handlerFor(definition, container, enrichers, guards));
|
|
144
|
+
app.on(definition.method, definition.url, handlerFor(definition, container, enrichers, guards, onError));
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
/**
|
|
@@ -184,7 +191,7 @@ export function honoPlugin(options = {}) {
|
|
|
184
191
|
await next();
|
|
185
192
|
return undefined;
|
|
186
193
|
});
|
|
187
|
-
registerRoutes(app, routes, container, enrichers, guards);
|
|
194
|
+
registerRoutes(app, routes, container, enrichers, guards, options.onError);
|
|
188
195
|
// Neutral JSON 404 (an app's own later `notFound` call replaces it).
|
|
189
196
|
if (options.notFound !== false) {
|
|
190
197
|
app.notFound((context) => context.json(NOT_FOUND_RESPONSE, 404));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basaltkit/hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22.5.0"
|
|
6
6
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@basaltkit/core": "^1.3.1",
|
|
22
|
-
"@basaltkit/http": "^1.
|
|
22
|
+
"@basaltkit/http": "^1.15.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"hono": "^4.0.0"
|