Releases: honojs/hono
v2.2.2
Summary
Bug fixes, friendly error messages, and performance tuning. It will be about 16% faster!! on Bun with a single handler that does not use async such as "Hello World".
What's Changed
- perf: remove
async
from dispatch; will be 16% faster by @yusukebe in #550 - fix(types): enable types for
c.env
when using validator by @yusukebe in #553 - use console.trace to improve error handler by @mishra-prabhakar in #556
- fix(validator): make
isOptional
rule works correctly by @yusukebe in #555 - refactor(serve-static): use context/next instead of MiddlewareHandler by @yusukebe in #559
New Contributors
- @mishra-prabhakar made their first contribution in #556
Full Changelog: v2.2.1...v2.2.2
v2.2.1
v2.2.0
This release includes ES Module support, innovative new features, and some bug fixes. You will like it.
Summary
Support ES Module
We have distributed only CommonJS, but now we will distribute ES Module. ES Module is used when the library is imported using the import
keyword. ESModule may improve performance and reduces bundle size.
StaticRouter and SmartRouter
Now we have a really smart router.
Added a simple router named "StaticRouter" that does not support dynamic routes. Now, we have there router: "TrieRouter", "RegExpRouter", and "StaticRouter".
And we introduce "SmartRouter".
SmartRouter picks the optimal router from three routers the first time it is accessed. Users can use the fastest router without explicitly specifying a router.
// Before this release.
// If we wanted to use optimal router, we have to specify it.
const app = new Hono({ router: new RegExpRouter() })
// This release.
// SmartRouter selects the fastest router automatically.
const app = new Hono()
StaticRouter is used for having only static routes. Otherwise, RegExpRouter will be used, but it has routing that RegExpRouter does not support, TrieRouter will be used.
Validator Middleware
New Validator Middleware as builtin middleware. This validator is magic.
app.post(
'/posts',
validator((v) => ({
post: {
id: v.json('post.id').asNumber().isRequired(),
title: v.json('post.title').isRequired().isLength({ max: 100 }),
published: v.json('post.published').asBoolean(),
body: v.json('post.body').isOptional(),
},
})),
(c) => {
const res = c.req.valid()
const post = res.post
return c.text(`Post: ${post.id} is ${post.title}`)
}
)
They will have "Types"! The value validated with asNumber()
keyword will have "Type".
Not only that.
- Easy to understand the result data because "declaring property name first".
- Easy to writing rules.
v.isLength(400)
is better thanv.isLength, 400
. - Getting only "declared properties". Additional properties are always ignored. It's safe.
For more information: https://honojs.dev/docs/builtin-middleware/validator/
Validator Middleware was provided as third party Middleware: https://github.com/honojs/validator, it will be deprecated.
All changes are below:
What's Changed
- fix(types): correct types for
app.notFound
/app.onError
by @yusukebe in #512 - fix(middleware): support multiple middleware on bearer/basic auth middleware by @yusukebe in #513
- Introduce StaticRouter and SmartRouter by @usualoma in #501
- feat(middleware): introduce "built-in" Validator Middleware by @yusukebe in #505
- Lightweight RegExpRouter reborn by @usualoma in #519
- fix(types): add types to middleware correctly by @yusukebe in #521
- feat(validator): add
isFalsy
andisNotFalsy
by @yusukebe in #523 - docs(readme): update discord invite url by @OnurGvnc in #527
- feat: support ES modules!! by @yusukebe in #526
- feat(validator): add
isBoolean
andisNumber
by @yusukebe in #530 - feat(cors): allow multiple origins by @yusukebe in #531
- Check in Origin header instead of Referer by @usualoma in #532
- feat(cors): Enable to check origin header by a function. by @usualoma in #533
- fix(deno): serve static middleware returns 404 correctly by @yusukebe in #537
- fix(bun): serve static middleware returns 404 correctly by @yusukebe in #538
- feat: another idea of Validator Middleware by @yusukebe in #535
- fix(redirect): don't have to make relative url to absolute one by @yusukebe in #541
- feat: support appending values with
c.header
by @yusukebe in #539 - feat:
c.req.body
andc.req.json
accept generics by @yusukebe in #529 - fix(validator): make "Types" work well by @yusukebe in #545
- feat(validator): Enable verification results to be retrieved as structured data. by @usualoma in #547
New Contributors
Full Changelog: v2.1.4...v2.2.0
v2.1.4
Summary
Performance tuning!
This release includes performance improvement. "Hello World" will be 11% faster and c.req.query
25% faster on Bun. Of course, it becomes faster on Deno.
What's Changed
- perf: do not
compose
if it has only one handler by @yusukebe in #493 - fix: fixed the issue logger called twice by @yusukebe in #494
- perf(compose): Remove
await composed()
from hono.ts. by @usualoma in #495 - perf(compose): Always return a Promise without async. by @usualoma in #496
- perf(req): improve
c.req.query
performance by @yusukebe in #498 - Fix regexp ambigous route by @usualoma in #499
Full Changelog: v2.1.3...v2.1.4
v2.1.3
Summary
This is a patch release including minor bug fixes.
What's Changed
- fix app.HTTP_METHOD type by @azukiazusa1 in #490
- fix(compose): do not handle the error in
compose
by @yusukebe in #491
New Contributors
- @azukiazusa1 made their first contribution in #490
Full Changelog: v2.1.2...v2.1.3
v2.1.2
v2.1.1
v2.1.0
BREAKING CHANGES
This release has the breaking changes. Please see the migration guide for more detail:
Summary
- TrieRouter is 9~10% faster.
- Enable adding types to
c.set
/c.get
by passing the Generics tonew Hono
. #472 c.req.parseBody
parses only FormData. Does not parse JSON, text, or ArrayBuffer. #487
Types for c.set/c.get
Now, we can add the types to the variables used in c.set
and c.get
. new Hono
receive the Generics for the variables and bindings which is for environment variables for Cloudflare Workers.
type Bindings = {
KV: KVNamespace
Storage: R2Bucket
}
type WebClient = {
user: string
pass: string
}
type Variables = {
client: WebClient
}
const app = new Hono<{ Variables: Variables; Bindings: Bindings }>()
app.get('/foo', (c) => {
const client = c.get('client') // client is WebClient
const kv = c.env.KV // kv is KVNamespace
//...
})
c.req.parseBody
Now, c.req.parseBody
has become only for parsing FormData. We have to parse the request body explicitly.
// `multipart/form` or `application/x-www-form-urlencoded`
const data = await c.req.parseBody()
const jsonData = await c.req.json() // for JSON body
const text = await c.req.text() // for text body
const arrayBuffer = await c.req.arrayBuffer() // for ArrayBuffer
What's Changed
- perf(trie-router): fine tuning, 9~10% faster by @yusukebe in #473
- fix(context): export
ContextVariableMap
correctly by @yusukebe in #476 - feat(types): enable adding Types for variables used in
c.set
/c.get
by @yusukebe in #478 - fix: enable passing Generics to c.req.parseBody, default is any by @yusukebe in #481
- docs(readme): add discord and twitter links by @yusukebe in #485
- [BREAKING] fix: make that
c.req.parseBody
parses onlyFormData
by @yusukebe in #487
Full Changelog: v2.0.9...v2.1.0
v2.0.9
Summary
Performance improvement - We have revised the await/async process so that it is faster in some situations.
It has been 8-9% faster in the benchmark:
hono - trie-router(default) x 393,919 ops/sec ±4.52% (86 runs sampled)
hono - regexp-router x 478,140 ops/sec ±2.85% (83 runs sampled)
hono optimized - trie-router(default) x 427,940 ops/sec ±4.32% (81 runs sampled)
hono optimized - regexp-router x 512,488 ops/sec ±5.28% (75 runs sampled)
Fastest is hono optimized - regexp-router
✨ Done in 28.36s.
On Bun, it has been 15% faster.
Before: Requests/sec: 57043.0018
After: Requests/sec: 65658.9860
What's Changed
- fix(context): fixed
ContextVariableMap
is not enabled in built code by @yusukebe in #465 - perf(compose): optimize
await
by @yusukebe in #466 - docs(readme): update benchmark results by @yusukebe in #467
- chore: add
FUNDING.yml
by @yusukebe in #468 - fix(compose): Support a handler that non-async and returning a promise. by @usualoma in #469
Full Changelog: v2.0.8...v2.0.9
v2.0.8
Summary
Mostly bug fixes:
- Fixed errors for ETag Middleware. There was a bug returning a server error when the file size is too large.
- Fixed Context header values "shifting". Sometimes, the values were not correct.
What's Changed
- refactor(compose): cache length by @yusukebe in #460
- fix(ETag): fixed an error when the file size is too large. by @yusukebe in #461
- refactor(mime): made
.ico
file's extension toimage/x-icon
by @yusukebe in #462 - fix(context): fix header values shifting by @yusukebe in #463
Full Changelog: v2.0.7...v2.0.8