Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d3a274

Browse files
committed
build: inline rou3 related types
1 parent d833afb commit 5d3a274

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/h3.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import { toResponse, kNotFound } from "./response.ts";
44
import { callMiddleware, normalizeMiddleware } from "./middleware.ts";
55

66
import type { ServerRequest } from "srvx";
7-
import type { RouterContext, MatchedRoute } from "rou3";
8-
import type { H3Config, H3CoreConfig, H3Plugin } from "./types/h3.ts";
7+
import type {
8+
H3Config,
9+
H3CoreConfig,
10+
H3Plugin,
11+
MatchedRoute,
12+
RouterContext,
13+
} from "./types/h3.ts";
914
import type { H3EventContext } from "./types/context.ts";
1015
import type {
1116
EventHandler,
@@ -108,7 +113,7 @@ export class H3Core implements H3CoreType {
108113

109114
export const H3 = /* @__PURE__ */ (() => {
110115
class H3 extends H3Core {
111-
"~rou3": RouterContext<H3Route>;
116+
"~rou3": RouterContext;
112117

113118
constructor(config: H3Config = {}) {
114119
super(config);

src/types/h3.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@ import type { HTTPHandler, EventHandler, Middleware } from "./handler.ts";
33
import type { HTTPError } from "../error.ts";
44
import type { MaybePromise } from "./_utils.ts";
55
import type { FetchHandler, ServerRequest } from "srvx";
6-
import type { MatchedRoute, RouterContext } from "rou3";
6+
// import type { MatchedRoute, RouterContext } from "rou3";
77
import type { H3Event } from "../event.ts";
88

9+
// Inlined from rou3 for type portability
10+
export interface RouterContext {
11+
root: any;
12+
static: Record<string, any>;
13+
}
14+
15+
export type MatchedRoute<T = any> = {
16+
data: T;
17+
params?: Record<string, string>;
18+
};
19+
920
// --- Misc ---
1021

1122
// https://www.rfc-editor.org/rfc/rfc7231#section-4.1
@@ -120,7 +131,7 @@ export declare class H3Core {
120131

121132
export declare class H3 extends H3Core {
122133
/** @internal */
123-
"~rou3": RouterContext<H3Route>;
134+
"~rou3": RouterContext;
124135

125136
/**
126137
* A [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)-compatible API allowing to fetch app routes.

test/bench/bench.impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function h3(lib: typeof _h3src, compiled?: boolean): AppFetch {
2828
if (compiled) {
2929
const findRoute = compileRouter(app["~rou3"]);
3030
app["~findRoute"] = (event) =>
31-
findRoute(event.req.method, event.url.pathname);
31+
findRoute(event.req.method, event.url.pathname) as any;
3232
}
3333
return app.fetch;
3434
}

0 commit comments

Comments
 (0)