Skip to content

Commit df236e4

Browse files
committed
refactor: unstable_hono (#935)
just separating files
1 parent 639bca0 commit df236e4

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

packages/waku/src/lib/hono/ctx.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Context, Env } from 'hono';
2+
3+
import { unstable_getCustomContext } from '../../server.js';
4+
5+
// Internal context key
6+
const HONO_CONTEXT = '__hono_context';
7+
8+
export const getHonoContext = <E extends Env = Env>() => {
9+
const c = unstable_getCustomContext()[HONO_CONTEXT];
10+
if (!c) {
11+
throw new Error('Hono context is not available');
12+
}
13+
return c as Context<E>;
14+
};

packages/waku/src/lib/hono/engine.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { Context, Env, MiddlewareHandler } from 'hono';
1+
import type { MiddlewareHandler } from 'hono';
22

3-
import { unstable_getCustomContext } from '../../server.js';
43
import { resolveConfig } from '../config.js';
54
import type { HandlerContext, MiddlewareOptions } from '../middleware/types.js';
65

@@ -70,11 +69,3 @@ export const serverEngine = (options: MiddlewareOptions): MiddlewareHandler => {
7069
await next();
7170
};
7271
};
73-
74-
export const getHonoContext = <E extends Env = Env>() => {
75-
const c = unstable_getCustomContext()[HONO_CONTEXT];
76-
if (!c) {
77-
throw new Error('Hono context is not available');
78-
}
79-
return c as Context<E>;
80-
};

packages/waku/src/unstable_hono.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// These exports are for internal use only and subject to change without notice.
22

3-
export { serverEngine, getHonoContext } from './lib/hono/engine.js';
3+
export { serverEngine } from './lib/hono/engine.js';
4+
export { getHonoContext } from './lib/hono/ctx.js';
45

56
export const importHono = () => import('hono');
67
export const importHonoNodeServer: any = () => import('@hono/node-server');

0 commit comments

Comments
 (0)