@basaltkit/hono 1.0.0 → 1.1.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/LICENSE +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +13 -0
- package/package.json +2 -2
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,20 @@ import { BasaltRoute, RequestEnricher, RouteGuard } from '@basaltkit/http';
|
|
|
5
5
|
import { Hono } from 'hono';
|
|
6
6
|
|
|
7
7
|
declare const HONO: _basaltkit_core.Token<Hono<any, hono_types.BlankSchema, "/">>;
|
|
8
|
+
/** Default maximum request body size (1 MiB) — override via honoPlugin({ bodyLimit }). */
|
|
9
|
+
declare const DEFAULT_BODY_LIMIT = 1048576;
|
|
8
10
|
/** Mounts Basalt routes on a Hono app (usable without the plugin). */
|
|
9
11
|
declare function registerRoutes(app: Hono<any>, routes: BasaltRoute[], container?: Container, enrichers?: RequestEnricher[], guards?: RouteGuard[]): void;
|
|
10
12
|
interface HonoPluginOptions {
|
|
11
13
|
routes?: BasaltRoute[];
|
|
12
14
|
/** Bring your own Hono app; otherwise a fresh one is created. */
|
|
13
15
|
app?: Hono<any>;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum request body size in bytes. A request whose `Content-Length`
|
|
18
|
+
* exceeds this is rejected with 413 before the body is read — Hono/edge has
|
|
19
|
+
* no default cap, so without this a large upload is unbounded. Default: 1 MiB.
|
|
20
|
+
*/
|
|
21
|
+
bodyLimit?: number;
|
|
14
22
|
}
|
|
15
23
|
/**
|
|
16
24
|
* Runs Basalt on Hono (Node, Bun, Deno, edge). The same routes, enrichers and
|
|
@@ -19,4 +27,4 @@ interface HonoPluginOptions {
|
|
|
19
27
|
*/
|
|
20
28
|
declare function honoPlugin(options?: HonoPluginOptions): _basaltkit_core.BasaltPlugin<unknown>;
|
|
21
29
|
|
|
22
|
-
export { HONO, type HonoPluginOptions, honoPlugin, registerRoutes };
|
|
30
|
+
export { DEFAULT_BODY_LIMIT, HONO, type HonoPluginOptions, honoPlugin, registerRoutes };
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "@basaltkit/http";
|
|
9
9
|
import { Hono } from "hono";
|
|
10
10
|
var HONO = createToken("hono");
|
|
11
|
+
var DEFAULT_BODY_LIMIT = 1048576;
|
|
11
12
|
async function parseBody(context) {
|
|
12
13
|
const method = context.req.method;
|
|
13
14
|
if (method === "GET" || method === "HEAD") return void 0;
|
|
@@ -119,7 +120,18 @@ function honoPlugin(options = {}) {
|
|
|
119
120
|
const metadata = ensureMetadata(container);
|
|
120
121
|
const enrichers = metadata.get("http:enrichers");
|
|
121
122
|
const guards = metadata.get("http:guards");
|
|
123
|
+
const bodyLimit = options.bodyLimit ?? DEFAULT_BODY_LIMIT;
|
|
122
124
|
hooks.on("app:booted", () => {
|
|
125
|
+
app.use(async (context, next) => {
|
|
126
|
+
const declared = Number(context.req.header("content-length") ?? "");
|
|
127
|
+
if (Number.isFinite(declared) && declared > bodyLimit) {
|
|
128
|
+
return context.json(
|
|
129
|
+
{ code: "PAYLOAD_TOO_LARGE", message: `Request body exceeds the ${bodyLimit}-byte limit.` },
|
|
130
|
+
413
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return next();
|
|
134
|
+
});
|
|
123
135
|
if (collector.afterHooks.length) {
|
|
124
136
|
app.use(async (context, next) => {
|
|
125
137
|
const start = Date.now();
|
|
@@ -157,6 +169,7 @@ function honoPlugin(options = {}) {
|
|
|
157
169
|
});
|
|
158
170
|
}
|
|
159
171
|
export {
|
|
172
|
+
DEFAULT_BODY_LIMIT,
|
|
160
173
|
HONO,
|
|
161
174
|
honoPlugin,
|
|
162
175
|
registerRoutes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basaltkit/hono",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Hono adapter for Basalt: run the same typed routes, enrichers and guards on Hono (Node, Bun, Deno, edge) as on Fastify or Express.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@basaltkit/core": "^1.0.0",
|
|
18
|
-
"@basaltkit/http": "^1.
|
|
18
|
+
"@basaltkit/http": "^1.3.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"hono": "^4.0.0"
|