@superfunctions/http-hono 0.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/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # @superfunctions/http-hono
2
+
3
+ Hono adapter for [@superfunctions/http](../http) - Use framework-agnostic routers with Hono.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @superfunctions/http @superfunctions/http-hono hono
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Hono } from 'hono';
15
+ import { createRouter } from '@superfunctions/http';
16
+ import { toHonoHandler } from '@superfunctions/http-hono';
17
+
18
+ // Define your router (framework-agnostic)
19
+ const apiRouter = createRouter({
20
+ routes: [
21
+ {
22
+ method: 'GET',
23
+ path: '/users/:id',
24
+ handler: async (req, ctx) => {
25
+ return Response.json({ id: ctx.params.id });
26
+ },
27
+ },
28
+ ],
29
+ });
30
+
31
+ // Use with Hono
32
+ const app = new Hono();
33
+ app.route('/api', toHonoHandler(apiRouter));
34
+
35
+ export default app;
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### `toHonoHandler(router)`
41
+
42
+ Converts a `@superfunctions/http` router to a Hono instance.
43
+
44
+ **Parameters:**
45
+ - `router`: Router instance from `@superfunctions/http`
46
+
47
+ **Returns:** `Hono`
48
+
49
+ **Example:**
50
+ ```typescript
51
+ import { toHonoHandler } from '@superfunctions/http-hono';
52
+
53
+ const honoApp = toHonoHandler(myRouter);
54
+ app.route('/api', honoApp);
55
+ ```
56
+
57
+
58
+ ## Usage Examples
59
+
60
+ ### With Middleware
61
+
62
+ ```typescript
63
+ import { createRouter } from '@superfunctions/http';
64
+ import { toHonoHandler } from '@superfunctions/http-hono';
65
+
66
+ const router = createRouter({
67
+ middleware: [
68
+ async (req, ctx, next) => {
69
+ // Auth middleware
70
+ const token = req.headers.get('Authorization');
71
+ if (!token) {
72
+ return Response.json({ error: 'Unauthorized' }, { status: 401 });
73
+ }
74
+ return next();
75
+ },
76
+ ],
77
+ routes: [
78
+ {
79
+ method: 'GET',
80
+ path: '/protected',
81
+ handler: async () => Response.json({ data: 'secret' }),
82
+ },
83
+ ],
84
+ });
85
+
86
+ const app = new Hono();
87
+ app.route('/api', toHonoHandler(router));
88
+ ```
89
+
90
+ ### With Custom Context
91
+
92
+ ```typescript
93
+ interface AppContext {
94
+ db: Database;
95
+ }
96
+
97
+ const router = createRouter<AppContext>({
98
+ context: { db: myDatabase },
99
+ routes: [
100
+ {
101
+ method: 'GET',
102
+ path: '/users',
103
+ handler: async (req, ctx) => {
104
+ const users = await ctx.db.findMany({ model: 'users' });
105
+ return Response.json(users);
106
+ },
107
+ },
108
+ ],
109
+ });
110
+
111
+ const app = new Hono();
112
+ app.route('/api', toHonoHandler(router));
113
+ ```
114
+
115
+ ### Multiple Routers
116
+
117
+ ```typescript
118
+ const usersRouter = createRouter({ routes: [/* user routes */] });
119
+ const postsRouter = createRouter({ routes: [/* post routes */] });
120
+
121
+ const app = new Hono();
122
+ app.route('/api/users', toHonoHandler(usersRouter));
123
+ app.route('/api/posts', toHonoHandler(postsRouter));
124
+ ```
125
+
126
+ ### Edge Runtime Example
127
+
128
+ ```typescript
129
+ // Cloudflare Workers
130
+ import { createRouter } from '@superfunctions/http';
131
+ import { toHonoHandler } from '@superfunctions/http-hono';
132
+
133
+ const router = createRouter({
134
+ routes: [
135
+ { method: 'GET', path: '/', handler: async () => Response.json({ ok: true }) }
136
+ ]
137
+ });
138
+
139
+ const app = new Hono();
140
+ app.route('/', toHonoHandler(router));
141
+
142
+ export default app;
143
+ ```
144
+
145
+ ## Alternative: Universal Handler
146
+
147
+ Since Hono uses Web Standards natively, you can also use the router directly without the adapter:
148
+
149
+ ```typescript
150
+ import { Hono } from 'hono';
151
+ import { createRouter } from '@superfunctions/http';
152
+
153
+ const router = createRouter({
154
+ routes: [/* routes */]
155
+ });
156
+
157
+ const app = new Hono();
158
+ app.all('/*', (c) => router.handler(c.req.raw));
159
+ ```
160
+
161
+ **When to use the adapter:**
162
+ - ✅ Full per-route registration
163
+ - ✅ Framework-native patterns
164
+ - ✅ Better integration with Hono middleware
165
+
166
+ **When to use universal handler:**
167
+ - ✅ Simpler setup
168
+ - ✅ Single catch-all route
169
+ - ✅ Minimal code
170
+
171
+ ## Important Notes
172
+
173
+ ### Web Standards
174
+
175
+ Hono uses Web Standard `Request` and `Response` natively, making this adapter very lightweight with near-zero overhead.
176
+
177
+ ### Route Paths
178
+
179
+ Routes are registered relative to the mount point:
180
+
181
+ ```typescript
182
+ const router = createRouter({
183
+ routes: [
184
+ { method: 'GET', path: '/hello', handler: () => Response.json({ msg: 'hi' }) }
185
+ ]
186
+ });
187
+
188
+ // Route accessible at: /api/hello
189
+ app.route('/api', toHonoHandler(router));
190
+ ```
191
+
192
+ ### HEAD Requests
193
+
194
+ Hono doesn't have a built-in `head` method, so HEAD requests in your router are automatically skipped. Most frameworks handle HEAD automatically from GET routes.
195
+
196
+ ## TypeScript
197
+
198
+ Full TypeScript support with proper types:
199
+
200
+ ```typescript
201
+ import type { Router } from '@superfunctions/http';
202
+ import type { Hono } from 'hono';
203
+
204
+ const myRouter: Router = createRouter({ routes: [...] });
205
+ const honoApp: Hono = toHonoHandler(myRouter);
206
+ ```
207
+
208
+ ## Edge Runtime Support
209
+
210
+ Works seamlessly with:
211
+ - ✅ Cloudflare Workers
212
+ - ✅ Deno Deploy
213
+ - ✅ Vercel Edge Functions
214
+ - ✅ Bun
215
+
216
+ ## Compatibility
217
+
218
+ - Hono 4.x ✅
219
+
220
+ ## License
221
+
222
+ MIT
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hono adapter for @superfunctions/http
3
+ */
4
+ import type { Router } from '@superfunctions/http';
5
+ import { Hono } from 'hono';
6
+ /**
7
+ * Convert a @superfunctions/http Router to a Hono instance
8
+ *
9
+ * This registers all routes from the router with their respective HTTP methods.
10
+ * Hono uses Web Standards natively, so translation is minimal.
11
+ */
12
+ export declare function toHonoHandler(router: Router): Hono;
13
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA6BlD"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Hono adapter for @superfunctions/http
3
+ */
4
+ import { Hono } from 'hono';
5
+ /**
6
+ * Convert a @superfunctions/http Router to a Hono instance
7
+ *
8
+ * This registers all routes from the router with their respective HTTP methods.
9
+ * Hono uses Web Standards natively, so translation is minimal.
10
+ */
11
+ export function toHonoHandler(router) {
12
+ const app = new Hono();
13
+ // Get all routes from the router
14
+ const routes = router.getRoutes();
15
+ // Register each route with Hono
16
+ for (const route of routes) {
17
+ const method = route.method.toLowerCase();
18
+ // Hono doesn't have a 'head' method, so we'll skip HEAD requests
19
+ // or treat them as GET (HEAD is rare and usually handled automatically)
20
+ if (method === 'head') {
21
+ continue;
22
+ }
23
+ app[method](route.path, async (c) => {
24
+ // Hono's c.req.raw is already a Web Standard Request
25
+ const webRequest = c.req.raw;
26
+ // Handle with router
27
+ const webResponse = await router.handle(webRequest);
28
+ // Return Web Standard Response (Hono handles this natively)
29
+ return webResponse;
30
+ });
31
+ }
32
+ return app;
33
+ }
34
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,iCAAiC;IACjC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAElC,gCAAgC;IAChC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,WAAW,EAAoC,CAAC;QAE5E,iEAAiE;QACjE,wEAAwE;QACxE,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QAED,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAClC,qDAAqD;YACrD,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;YAE7B,qBAAqB;YACrB,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAEpD,4DAA4D;YAC5D,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @superfunctions/http-hono - Hono adapter
3
+ */
4
+ export { toHonoHandler } from './adapter.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @superfunctions/http-hono - Hono adapter
3
+ */
4
+ export { toHonoHandler } from './adapter.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@superfunctions/http-hono",
3
+ "version": "0.1.0",
4
+ "description": "Hono adapter for @superfunctions/http",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest",
20
+ "test:watch": "vitest --watch",
21
+ "lint": "echo 'lint not configured'",
22
+ "typecheck": "tsc --noEmit",
23
+ "clean": "rm -rf dist"
24
+ },
25
+ "peerDependencies": {
26
+ "@superfunctions/http": "^0.1.0",
27
+ "hono": "^4.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@superfunctions/http": "^0.1.0",
31
+ "@types/node": "^22.0.0",
32
+ "hono": "^4.6.16",
33
+ "typescript": "^5.6.0",
34
+ "vitest": "^3.2.4"
35
+ },
36
+ "keywords": [
37
+ "http",
38
+ "hono",
39
+ "adapter",
40
+ "router",
41
+ "superfunctions"
42
+ ],
43
+ "author": "21n",
44
+ "license": "MIT",
45
+ "bugs": {
46
+ "url": "https://github.com/21nCo/super-functions/issues"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/21nCo/super-functions.git",
51
+ "directory": "packages/http-hono"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }