@superfunctions/http-hono 0.1.0 → 0.1.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 +14 -14
- package/dist/adapter.d.ts +7 -2
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +16 -21
- package/dist/adapter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install @superfunctions/http @superfunctions/http-hono hono
|
|
|
13
13
|
```typescript
|
|
14
14
|
import { Hono } from 'hono';
|
|
15
15
|
import { createRouter } from '@superfunctions/http';
|
|
16
|
-
import {
|
|
16
|
+
import { toHono } from '@superfunctions/http-hono';
|
|
17
17
|
|
|
18
18
|
// Define your router (framework-agnostic)
|
|
19
19
|
const apiRouter = createRouter({
|
|
@@ -30,14 +30,14 @@ const apiRouter = createRouter({
|
|
|
30
30
|
|
|
31
31
|
// Use with Hono
|
|
32
32
|
const app = new Hono();
|
|
33
|
-
app.route('/api',
|
|
33
|
+
app.route('/api', toHono(apiRouter));
|
|
34
34
|
|
|
35
35
|
export default app;
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
## API
|
|
39
39
|
|
|
40
|
-
### `
|
|
40
|
+
### `toHono(router)`
|
|
41
41
|
|
|
42
42
|
Converts a `@superfunctions/http` router to a Hono instance.
|
|
43
43
|
|
|
@@ -48,9 +48,9 @@ Converts a `@superfunctions/http` router to a Hono instance.
|
|
|
48
48
|
|
|
49
49
|
**Example:**
|
|
50
50
|
```typescript
|
|
51
|
-
import {
|
|
51
|
+
import { toHono } from '@superfunctions/http-hono';
|
|
52
52
|
|
|
53
|
-
const honoApp =
|
|
53
|
+
const honoApp = toHono(myRouter);
|
|
54
54
|
app.route('/api', honoApp);
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -61,7 +61,7 @@ app.route('/api', honoApp);
|
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
import { createRouter } from '@superfunctions/http';
|
|
64
|
-
import {
|
|
64
|
+
import { toHono } from '@superfunctions/http-hono';
|
|
65
65
|
|
|
66
66
|
const router = createRouter({
|
|
67
67
|
middleware: [
|
|
@@ -84,7 +84,7 @@ const router = createRouter({
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
const app = new Hono();
|
|
87
|
-
app.route('/api',
|
|
87
|
+
app.route('/api', toHono(router));
|
|
88
88
|
```
|
|
89
89
|
|
|
90
90
|
### With Custom Context
|
|
@@ -109,7 +109,7 @@ const router = createRouter<AppContext>({
|
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
const app = new Hono();
|
|
112
|
-
app.route('/api',
|
|
112
|
+
app.route('/api', toHono(router));
|
|
113
113
|
```
|
|
114
114
|
|
|
115
115
|
### Multiple Routers
|
|
@@ -119,8 +119,8 @@ const usersRouter = createRouter({ routes: [/* user routes */] });
|
|
|
119
119
|
const postsRouter = createRouter({ routes: [/* post routes */] });
|
|
120
120
|
|
|
121
121
|
const app = new Hono();
|
|
122
|
-
app.route('/api/users',
|
|
123
|
-
app.route('/api/posts',
|
|
122
|
+
app.route('/api/users', toHono(usersRouter));
|
|
123
|
+
app.route('/api/posts', toHono(postsRouter));
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
### Edge Runtime Example
|
|
@@ -128,7 +128,7 @@ app.route('/api/posts', toHonoHandler(postsRouter));
|
|
|
128
128
|
```typescript
|
|
129
129
|
// Cloudflare Workers
|
|
130
130
|
import { createRouter } from '@superfunctions/http';
|
|
131
|
-
import {
|
|
131
|
+
import { toHono } from '@superfunctions/http-hono';
|
|
132
132
|
|
|
133
133
|
const router = createRouter({
|
|
134
134
|
routes: [
|
|
@@ -137,7 +137,7 @@ const router = createRouter({
|
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
const app = new Hono();
|
|
140
|
-
app.route('/',
|
|
140
|
+
app.route('/', toHono(router));
|
|
141
141
|
|
|
142
142
|
export default app;
|
|
143
143
|
```
|
|
@@ -186,7 +186,7 @@ const router = createRouter({
|
|
|
186
186
|
});
|
|
187
187
|
|
|
188
188
|
// Route accessible at: /api/hello
|
|
189
|
-
app.route('/api',
|
|
189
|
+
app.route('/api', toHono(router));
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
### HEAD Requests
|
|
@@ -202,7 +202,7 @@ import type { Router } from '@superfunctions/http';
|
|
|
202
202
|
import type { Hono } from 'hono';
|
|
203
203
|
|
|
204
204
|
const myRouter: Router = createRouter({ routes: [...] });
|
|
205
|
-
const honoApp: Hono =
|
|
205
|
+
const honoApp: Hono = toHono(myRouter);
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
## Edge Runtime Support
|
package/dist/adapter.d.ts
CHANGED
|
@@ -6,8 +6,13 @@ import { Hono } from 'hono';
|
|
|
6
6
|
/**
|
|
7
7
|
* Convert a @superfunctions/http Router to a Hono instance
|
|
8
8
|
*
|
|
9
|
-
* This registers all routes from the router with their respective HTTP methods.
|
|
10
9
|
* Hono uses Web Standards natively, so translation is minimal.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const router = createRouter({ routes: [...] });
|
|
14
|
+
* app.route('/api', toHono(router));
|
|
15
|
+
* ```
|
|
11
16
|
*/
|
|
12
|
-
export declare function
|
|
17
|
+
export declare function toHono(router: Router): Hono;
|
|
13
18
|
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +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
|
|
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;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAgB3C"}
|
package/dist/adapter.js
CHANGED
|
@@ -5,30 +5,25 @@ import { Hono } from 'hono';
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert a @superfunctions/http Router to a Hono instance
|
|
7
7
|
*
|
|
8
|
-
* This registers all routes from the router with their respective HTTP methods.
|
|
9
8
|
* Hono uses Web Standards natively, so translation is minimal.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const router = createRouter({ routes: [...] });
|
|
13
|
+
* app.route('/api', toHono(router));
|
|
14
|
+
* ```
|
|
10
15
|
*/
|
|
11
|
-
export function
|
|
16
|
+
export function toHono(router) {
|
|
12
17
|
const app = new Hono();
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
}
|
|
18
|
+
// Use catch-all to delegate all routing to the router
|
|
19
|
+
app.all('*', async (c) => {
|
|
20
|
+
// Hono's c.req.raw is already a Web Standard Request
|
|
21
|
+
const webRequest = c.req.raw;
|
|
22
|
+
// Handle with router (router does all routing)
|
|
23
|
+
const webResponse = await router.handle(webRequest);
|
|
24
|
+
// Return Web Standard Response (Hono handles this natively)
|
|
25
|
+
return webResponse;
|
|
26
|
+
});
|
|
32
27
|
return app;
|
|
33
28
|
}
|
|
34
29
|
//# sourceMappingURL=adapter.js.map
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc;IACnC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IAEvB,sDAAsD;IACtD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACvB,qDAAqD;QACrD,MAAM,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;QAE7B,+CAA+C;QAC/C,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAEpD,4DAA4D;QAC5D,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"}
|