From 4c401fd6617edfe37f7048bea70c6f5daaa1b846 Mon Sep 17 00:00:00 2001 From: yasuaki640 Date: Wed, 10 Jul 2024 10:11:04 +0900 Subject: [PATCH 1/5] fix(jsx): redefine scope attribute as enum type (#3118) --- src/jsx/intrinsic-elements.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jsx/intrinsic-elements.ts b/src/jsx/intrinsic-elements.ts index 66e6a829..3db6e90b 100644 --- a/src/jsx/intrinsic-elements.ts +++ b/src/jsx/intrinsic-elements.ts @@ -580,7 +580,7 @@ export namespace JSX { colspan?: number | undefined headers?: string | undefined rowspan?: number | undefined - scope?: string | undefined + scope?: 'row' | 'col' | 'rowgroup' | 'colgroup' | string | undefined abbr?: string | undefined } From ec58511247d7b9c33fff92ea992c127c6363eec0 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Wed, 10 Jul 2024 10:23:07 +0900 Subject: [PATCH 2/5] fix(types): allow `string[] | File[]` for RPC form value (#3117) --- src/types.ts | 4 +++- src/validator/validator.test.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/types.ts b/src/types.ts index a81858de..3a539911 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1927,9 +1927,11 @@ type MergeTypedResponse = T extends Promise ////// ///// //////////////////////////////////////// +export type FormValue = string | File + export type ValidationTargets = { json: any - form: Record + form: Record query: Record param: Record | Record header: Record diff --git a/src/validator/validator.test.ts b/src/validator/validator.test.ts index 12028b93..2044a489 100644 --- a/src/validator/validator.test.ts +++ b/src/validator/validator.test.ts @@ -3,7 +3,13 @@ import type { ZodSchema } from 'zod' import { z } from 'zod' import { Hono } from '../hono' import { HTTPException } from '../http-exception' -import type { ErrorHandler, ExtractSchema, MiddlewareHandler, ValidationTargets } from '../types' +import type { + ErrorHandler, + ExtractSchema, + FormValue, + MiddlewareHandler, + ValidationTargets, +} from '../types' import type { StatusCode } from '../utils/http-status' import type { Equal, Expect } from '../utils/types' import type { ValidationFunction } from './validator' @@ -743,7 +749,7 @@ it('With path parameters', () => { $put: { input: { form: { - title: string | File + title: FormValue | FormValue[] } } & { param: { @@ -789,7 +795,7 @@ it('`on`', () => { $purge: { input: { form: { - tag: string | File + tag: FormValue | FormValue[] } } & { query: { From f1c7d312a8fb921ead3e45cc0b1c999fd4e1c34a Mon Sep 17 00:00:00 2001 From: Ame_x <121654029+EdamAme-x@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:34:36 +0900 Subject: [PATCH 3/5] fix(validator-types): type Alignment with Web Standards (#3120) * fix(validator-types): type Alignment with Web Standards * fix --- src/client/client.ts | 4 ++-- src/types.ts | 7 ++++--- src/validator/validator.test.ts | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index aa329265..a5c29602 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -1,5 +1,5 @@ import type { Hono } from '../hono' -import type { ValidationTargets } from '../types' +import type { FormValue, ValidationTargets } from '../types' import { serialize } from '../utils/cookie' import type { UnionToIntersection } from '../utils/types' import type { Callback, Client, ClientRequestOptions } from './types' @@ -42,7 +42,7 @@ class ClientRequestImpl { this.method = method } fetch = async ( - args?: ValidationTargets & { + args?: ValidationTargets & { param?: Record }, opt?: ClientRequestOptions diff --git a/src/types.ts b/src/types.ts index 3a539911..e6f3cdeb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1927,11 +1927,12 @@ type MergeTypedResponse = T extends Promise ////// ///// //////////////////////////////////////// -export type FormValue = string | File +export type FormValue = string | Blob +export type ParsedFormValue = string | File -export type ValidationTargets = { +export type ValidationTargets = { json: any - form: Record + form: Record query: Record param: Record | Record header: Record diff --git a/src/validator/validator.test.ts b/src/validator/validator.test.ts index 2044a489..b6bf19fc 100644 --- a/src/validator/validator.test.ts +++ b/src/validator/validator.test.ts @@ -8,6 +8,7 @@ import type { ExtractSchema, FormValue, MiddlewareHandler, + ParsedFormValue, ValidationTargets, } from '../types' import type { StatusCode } from '../utils/http-status' @@ -749,7 +750,7 @@ it('With path parameters', () => { $put: { input: { form: { - title: FormValue | FormValue[] + title: ParsedFormValue | ParsedFormValue[] } } & { param: { @@ -795,7 +796,7 @@ it('`on`', () => { $purge: { input: { form: { - tag: FormValue | FormValue[] + tag: ParsedFormValue | ParsedFormValue[] } } & { query: { From 642dd29666d866284e9c74ce7d57cf2a729e4543 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 11 Jul 2024 18:20:53 +0900 Subject: [PATCH 4/5] fix(types): `app.use(path, mw)` return correct schema type (#3128) Co-authored-by: Ame_x <121654029+EdamAme-x@users.noreply.github.com> --- src/helper/factory/index.ts | 6 +++++- src/types.test.ts | 15 +++++++++++++++ src/types.ts | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/helper/factory/index.ts b/src/helper/factory/index.ts index 42e702f7..041b6e24 100644 --- a/src/helper/factory/index.ts +++ b/src/helper/factory/index.ts @@ -241,6 +241,10 @@ export const createFactory = (init? initApp?: InitApp }): Factory => new Factory(init) -export const createMiddleware = ( +export const createMiddleware = < + E extends Env = any, + P extends string = string, + I extends Input = {} +>( middleware: MiddlewareHandler ): MiddlewareHandler => createFactory().createMiddleware(middleware) diff --git a/src/types.test.ts b/src/types.test.ts index eafd2683..c94d1b65 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -2225,3 +2225,18 @@ describe('Env types and a path type with `app.use(path, handler...)` - test only }) }) }) + +// https://github.com/honojs/hono/issues/3122 +describe('Returning type from `app.use(path, mw)`', () => { + const mw = createMiddleware(async (c, next) => { + await next() + }) + it('Should not mark `*` as never', () => { + const app = new Hono().use('*', mw) + type Actual = ExtractSchema + type Expected = { + '*': {} + } + type verify = Expect> + }) +}) diff --git a/src/types.ts b/src/types.ts index e6f3cdeb..d8b7ba4b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1804,7 +1804,7 @@ export type Schema = { } type ChangePathOfSchema = keyof S extends never - ? { [K in Path]: never } + ? { [K in Path]: {} } : { [K in keyof S as Path]: S[K] } export type Endpoint = { From 2d0135956c96e00fee48fb5faf287dbc9daf7f4f Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Thu, 11 Jul 2024 18:24:23 +0900 Subject: [PATCH 5/5] v4.4.13 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7041ad7..a025e26d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hono", - "version": "4.4.12", + "version": "4.4.13", "description": "Web framework built on Web Standards", "main": "dist/cjs/index.js", "type": "module",