Skip to content

Commit

Permalink
Merge branch 'main' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Jul 16, 2024
2 parents 9a6e52d + 2d01359 commit 9987b59
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/client/client.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -42,7 +42,7 @@ class ClientRequestImpl {
this.method = method
}
fetch = async (
args?: ValidationTargets & {
args?: ValidationTargets<FormValue> & {
param?: Record<string, string>
},
opt?: ClientRequestOptions
Expand Down
6 changes: 5 additions & 1 deletion src/helper/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ export const createFactory = <E extends Env = any, P extends string = any>(init?
initApp?: InitApp<E>
}): Factory<E, P> => new Factory<E, P>(init)

export const createMiddleware = <E extends Env = any, P extends string = any, I extends Input = {}>(
export const createMiddleware = <
E extends Env = any,
P extends string = string,
I extends Input = {}
>(
middleware: MiddlewareHandler<E, P, I>
): MiddlewareHandler<E, P, I> => createFactory<E, P>().createMiddleware<I>(middleware)
2 changes: 1 addition & 1 deletion src/jsx/intrinsic-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,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
}

Expand Down
15 changes: 15 additions & 0 deletions src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof app>
type Expected = {
'*': {}
}
type verify = Expect<Equal<Expected, Actual>>
})
})
9 changes: 6 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ export type Schema = {
}

type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends never
? { [K in Path]: never }
? { [K in Path]: {} }
: { [K in keyof S as Path]: S[K] }

export type Endpoint = {
Expand Down Expand Up @@ -1927,9 +1927,12 @@ type MergeTypedResponse<T> = T extends Promise<infer T2>
////// /////
////////////////////////////////////////

export type ValidationTargets = {
export type FormValue = string | Blob
export type ParsedFormValue = string | File

export type ValidationTargets<T extends FormValue = ParsedFormValue> = {
json: any
form: Record<string, string | File>
form: Record<string, T | T[]>
query: Record<string, string | string[]>
param: Record<string, string> | Record<string, string | undefined>
header: Record<string, string>
Expand Down
13 changes: 10 additions & 3 deletions src/validator/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ 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,
ParsedFormValue,
ValidationTargets,
} from '../types'
import type { StatusCode } from '../utils/http-status'
import type { Equal, Expect } from '../utils/types'
import type { ValidationFunction } from './validator'
Expand Down Expand Up @@ -743,7 +750,7 @@ it('With path parameters', () => {
$put: {
input: {
form: {
title: string | File
title: ParsedFormValue | ParsedFormValue[]
}
} & {
param: {
Expand Down Expand Up @@ -789,7 +796,7 @@ it('`on`', () => {
$purge: {
input: {
form: {
tag: string | File
tag: ParsedFormValue | ParsedFormValue[]
}
} & {
query: {
Expand Down

0 comments on commit 9987b59

Please sign in to comment.