mirror of
https://github.com/honojs/hono.git
synced 2024-11-21 18:18:57 +01:00
Merge branch 'main' into next
This commit is contained in:
commit
9987b5908f
@ -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<FormValue> & {
|
||||
param?: Record<string, string>
|
||||
},
|
||||
opt?: ClientRequestOptions
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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>>
|
||||
})
|
||||
})
|
||||
|
@ -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 = {
|
||||
@ -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>
|
||||
|
@ -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'
|
||||
@ -743,7 +750,7 @@ it('With path parameters', () => {
|
||||
$put: {
|
||||
input: {
|
||||
form: {
|
||||
title: string | File
|
||||
title: ParsedFormValue | ParsedFormValue[]
|
||||
}
|
||||
} & {
|
||||
param: {
|
||||
@ -789,7 +796,7 @@ it('`on`', () => {
|
||||
$purge: {
|
||||
input: {
|
||||
form: {
|
||||
tag: string | File
|
||||
tag: ParsedFormValue | ParsedFormValue[]
|
||||
}
|
||||
} & {
|
||||
query: {
|
||||
|
Loading…
Reference in New Issue
Block a user