Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): Added E env type argument to showRoutes & inspectRoutes hono parameter #1778

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deno_dist/helper/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Hono } from '../../hono.ts'
import type { RouterRoute } from '../../types.ts'
import type { Env, RouterRoute } from '../../types.ts'

interface ShowRoutesOptions {
verbose?: boolean
Expand All @@ -17,7 +17,7 @@ const handlerName = (handler: Function) => {
return handler.name || (isMiddleware(handler) ? '[middleware]' : '[handler]')
}

export const inspectRoutes = (hono: Hono): RouteData[] => {
export const inspectRoutes = <E extends Env>(hono: Hono<E>): RouteData[] => {
return hono.routes.map(({ path, method, handler }: RouterRoute) => ({
path,
method,
Expand All @@ -26,7 +26,7 @@ export const inspectRoutes = (hono: Hono): RouteData[] => {
}))
}

export const showRoutes = (hono: Hono, opts?: ShowRoutesOptions) => {
export const showRoutes = <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions) => {
const routeData: Record<string, RouteData[]> = {}
let maxMethodLength = 0
let maxPathLength = 0
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ class Hono<

/**
* @deprecated
* Use `showRoutes()` utility methods provided by 'hono/helper' instead of `app.showRoutes()`.
* Use `showRoutes()` utility methods provided by 'hono/dev' instead of `app.showRoutes()`.
* `app.showRoutes()` will be removed in v4.
* @example
* You could rewrite `app.showRoutes()` as follows
* import { showRoutes } from 'hono/helper'
* import { showRoutes } from 'hono/dev'
* showRoutes(app)
*/
showRoutes() {
Expand Down
6 changes: 3 additions & 3 deletions src/helper/dev/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Hono } from '../../hono'
import type { RouterRoute } from '../../types'
import type { Env, RouterRoute } from '../../types'

interface ShowRoutesOptions {
verbose?: boolean
Expand All @@ -17,7 +17,7 @@ const handlerName = (handler: Function) => {
return handler.name || (isMiddleware(handler) ? '[middleware]' : '[handler]')
}

export const inspectRoutes = (hono: Hono): RouteData[] => {
export const inspectRoutes = <E extends Env>(hono: Hono<E>): RouteData[] => {
return hono.routes.map(({ path, method, handler }: RouterRoute) => ({
path,
method,
Expand All @@ -26,7 +26,7 @@ export const inspectRoutes = (hono: Hono): RouteData[] => {
}))
}

export const showRoutes = (hono: Hono, opts?: ShowRoutesOptions) => {
export const showRoutes = <E extends Env>(hono: Hono<E>, opts?: ShowRoutesOptions) => {
const routeData: Record<string, RouteData[]> = {}
let maxMethodLength = 0
let maxPathLength = 0
Expand Down
4 changes: 2 additions & 2 deletions src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ class Hono<

/**
* @deprecated
* Use `showRoutes()` utility methods provided by 'hono/helper' instead of `app.showRoutes()`.
* Use `showRoutes()` utility methods provided by 'hono/dev' instead of `app.showRoutes()`.
* `app.showRoutes()` will be removed in v4.
* @example
* You could rewrite `app.showRoutes()` as follows
* import { showRoutes } from 'hono/helper'
* import { showRoutes } from 'hono/dev'
* showRoutes(app)
*/
showRoutes() {
Expand Down
Loading