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(deps): update dependency hono to v4 #8

Merged
merged 1 commit into from
Aug 3, 2024
Merged

Conversation

renovate[bot]
Copy link

@renovate renovate bot commented Feb 18, 2024

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
hono (source) ^3.11.12 -> ^4.0.0 age adoption passing confidence

Release Notes

honojs/hono (hono)

v4.5.1

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.5.0...v4.5.1

v4.5.0

Compare Source

v4.4.13

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.12...v4.4.13

v4.4.12

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.11...v4.4.12

v4.4.11

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.10...v4.4.11

v4.4.10

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.9...v4.4.10

v4.4.9

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.8...v4.4.9

v4.4.8

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.7...v4.4.8

v4.4.7

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.6...v4.4.7

v4.4.6

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.5...v4.4.6

v4.4.5

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.4...v4.4.5

v4.4.4

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.3...v4.4.4

v4.4.3

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.2...v4.4.3

v4.4.2

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.4.1...v4.4.2

v4.4.1

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.4.0...v4.4.1

v4.4.0

Compare Source

Hono v4.4.0 is now available! Let's take a look at the new features.

Support JSR

Now, Hono is available on JSR - a new JavaScript/TypeScript registry! You can install the Hono package from JSR right now. If you want to run your Hono app on Deno, you can install it with the following command:

deno add @​hono/hono

Then, use it in your code!

// main.ts
import { Hono } from '@​hono/hono'

const app = new Hono()

app.get('/', (c) => c.text('Hello JSR!'))

export default app

And run it:

deno serve main.ts

If you edit the deno.json and set the paths appropriately, the exact same code that you are familiar with will work in Deno, Cloudflare Workers, and Bun.

deno.json:

{
  "imports": {
    "hono": "jsr:@​hono/hono@^4.4.0"
  }
}
Area.mp4

JSR is not exclusive to Deno. You can use it with npm and Bun.

### npm
npx jsr add @​hono/hono

### bun
bunx jsr add @​hono/hono

And, removing "slow types" has improved the performance of TypeScript type inference.

With the introduction of JSR, the previous package publishing from deno.land/x will be obsolete.

Introduce ConnInfo Helper

The ConnInfo Helper is a helper helps you to get the connection information. For example, you can get the client's remote address easily.

import { Hono } from 'hono'
import { getConnInfo } from 'hono/deno' // For Deno

const app = new Hono()

app.get('/', (c) => {
  const info = getConnInfo(c) // info is `ConnInfo`
  return c.text(`Your remote address is ${info.remote.address}`)
})

export default app

Thank you for creating the feature, @​nakasyou!

Introduce Timeout Middleware

The Timeout Middleware is a middleware enables you to easily manage request timeouts in your application.

Here is a simple example:

import { Hono } from 'hono'
import { timeout } from 'hono/timeout'

const app = new Hono()

// Applying a 5-second timeout
app.use('/api', timeout(5000))

// Handling a route
app.get('/api/data', async (c) => {
  // Your route handler logic
  return c.json({ data: 'Your data here' })
})

Thank you for creating the feature, @​watany-dev!

Improving JSDoc

We are now trying to improve the JSDocs. In the PR, we've added the JSDocs for all middleware. Thank you, @​goisaki!

Other features

All Updates

New Contributors

Full Changelog: honojs/hono@v4.3.9...v4.4.0

v4.3.11

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.3.10...v4.3.11

v4.3.10

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.3.9...v4.3.10

v4.3.9

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.3.8...v4.3.9

v4.3.8

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.3.7...v4.3.8

v4.3.7

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.3.6...v4.3.7

v4.3.6

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.3.5...v4.3.6

v4.3.5

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.3.4...v4.3.5

v4.3.4

Compare Source

What's Changed

New Contributors

Full Changelog: honojs/hono@v4.3.3...v4.3.4

v4.3.3

Compare Source

What's Changed
New Contributors

Full Changelog: honojs/hono@v4.3.2...v4.3.3

v4.3.2

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.3.1...v4.3.2

v4.3.1

Compare Source

What's Changed

Full Changelog: honojs/hono@v4.3.0...v4.3.1

v4.3.0

Compare Source

Hono v4.3.0 is now available! Let's take a look at the new features.

Improve the RPC-mode

Thanks to @​kosei28, @​nakasyou, and @​NamesMT, the RPC mode has been improved!

c.text() is typed

The response of c.text() was just a Response object, not typed.

const routes = app.get('/about/me', (c) => {
  return c.text('Me!') // the response is not typed
})

With this release, it will be a TypedResponse and you can get the type within the client created by hc.

const client = hc<typeof routes>('http://localhost:8787')

const res = await client.about.me.$get()
const text = await res.text() // text is typed as "Me!"
const json = await res.json() // json is never!
Support all JSON primitives

We added the tests for the responses of c.json() to have the correct types and support inferring all primitives. The all tests below are passed!

const app = new Hono()
const route = app
  .get('/api/string', (c) => c.json('a-string'))
  .get('/api/number', (c) => c.json(37))
  .get('/api/boolean', (c) => c.json(true))
  .get('/api/generic', (c) => c.json(Math.random() > 0.5 ? Boolean(Math.random()) : Math.random()))
type AppType = typeof route

const client = hc<AppType>('http://localhost')

const stringFetch = await client.api.string.$get()
const stringRes = await stringFetch.json()
const numberFetch = await client.api.number.$get()
const numberRes = await numberFetch.json()
const booleanFetch = await client.api.boolean.$get()
const booleanRes = await booleanFetch.json()
const genericFetch = await client.api.generic.$get()
const genericRes = await genericFetch.json()

type stringVerify = Expect<Equal<'a-string', typeof stringRes>>
expect(stringRes).toBe('a-string')
type numberVerify = Expect<Equal<37, typeof numberRes>>
expect(numberRes).toBe(37)
type booleanVerify = Expect<Equal<true, typeof booleanRes>>
expect(booleanRes).toBe(true)
type genericVerify = Expect<Equal<number | boolean, typeof genericRes>>
expect(typeof genericRes === 'number' || typeof genericRes === 'boolean').toBe(true)

// using .text() on json endpoint should return string
type textTest = Expect<Equal<Promise<string>, ReturnType<typeof genericFetch.text>>>
Status code type

If you explicitly specify the status code, such as 200 or 404, in c.json(). It will be added as a type for passing to the client.

// server.ts
const app = new Hono().get(
  '/posts',
  zValidator(
    'query',
    z.object({
      id: z.string()
    })
  ),
  async (c) => {
    const { id } = c.req.valid('query')
    const post: Post | undefined = await getPost(id)

    if (post === undefined) {
      return c.json({ error: 'not found' }, 404) // Specify 404
    }

    return c.json({ post }, 200) // Specify 200
  }
)

export type AppType = typeof app

You can get the data by the status code.

// client.ts
const client = hc<AppType>('http://localhost:8787/')

const res = await client.posts.$get({
  query: {
    id: '123'
  }
})

if (res.status === 404) {
  const data: { error: string } = await res.json()
  console.log(data.error)
}

if (res.ok) {
  const data: { post: Post } = await res.json()
  console.log(data.post)
}

// { post: Post } | { error: string }
type ResponseType = InferResponseType<typeof client.posts.$get>

// { post: Post }
type ResponseType200 = InferResponseType<typeof client.posts.$get, 200>
Improve compatibility with React

The compatibility of hono/jsx/dom has been improved. Now, these React libraries work with hono/jsx/dom!

The below demo is working with hono/jsx/dom, not React.

Google Chrome

If you want to use React libraries with hono/jsx/dom, set-up tsconfig.json and vite.config.ts like the followings:

tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "react": ["./node_modules/hono/dist/jsx/dom"],
      "react-dom": ["./node_modules/hono/dist/jsx/dom"]
    }
  }
}

vite.config.ts:

import { defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    alias: {
      react: 'hono/jsx/dom',
      'react-dom': 'hono/jsx/dom'
    }
  }
})

Thanks @​usualoma!

createApp() in Factory Helper

createApp() method is added to Factory Helper. If you use this method with createFactory(), you can avoid redundancy in the definition of the Env type.

If your application is like this, you have to set the Env in two places:

import { createMiddleware } from 'hono/factory'

type Env = {
  Variables: {
    myVar: string
  }
}

// 1. Set the `Env` to `new Hono()`
const app = new Hono<Env>()

// 2. Set the `Env` to `createMiddleware()`
const mw = createMiddleware<Env>(async (c, next) => {
  await next()
})

app.use(mw)

By using createFactory() and createApp(), you can set the Env only in one place.

import { createFactory } from 'hono/factory'

// ...

// Set the `Env` to `createFactory()`
const factory = createFactory<Env>()

const app = factory.createApp()

// factory also has `createMiddleware()`
const mw = factory.createMiddleware(async (c, next) => {
  await next()
})
Deprecate serveStatic for Cloudflare Workers

serveStatic exported by hono/cloudflare-workers has been deprecated. If you create an application which serves static asset files, use Cloudflare Pages instead.

Other features
All Updates

Configuration

📅 Schedule: Branch creation - "on the first day of the week" in timezone Asia/Tokyo, Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot requested a review from MikuroXina February 18, 2024 07:20
@renovate renovate bot force-pushed the renovate/hono-4.x branch from 49da084 to b4645b1 Compare April 28, 2024 20:43
@renovate renovate bot force-pushed the renovate/hono-4.x branch from b4645b1 to 84db827 Compare August 3, 2024 18:13
@MikuroXina MikuroXina merged commit 59bc708 into main Aug 3, 2024
2 checks passed
@MikuroXina MikuroXina deleted the renovate/hono-4.x branch August 3, 2024 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant