Skip to content

Commit

Permalink
chore: denoify
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed May 23, 2024
1 parent 0deb075 commit e6aa84e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions deno_dist/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
options?: Options
): Promise<T>
async parseBody<T extends BodyData>(options?: Partial<ParseBodyOptions>): Promise<T>
async parseBody<T extends BodyData = BodyData>(options?: Partial<ParseBodyOptions>): Promise<T> {
async parseBody(options?: Partial<ParseBodyOptions>) {
if (this.bodyCache.parsedBody) {
return this.bodyCache.parsedBody as T
return this.bodyCache.parsedBody
}
const parsedBody = await parseBody<T>(this, options)
const parsedBody = await parseBody(this, options)
this.bodyCache.parsedBody = parsedBody
return parsedBody
}
Expand Down
18 changes: 17 additions & 1 deletion deno_dist/utils/body.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { HonoRequest } from '../request.ts'

type BodyDataValueDot = { [x: string]: string | File | BodyDataValueDot } & {}
type BodyDataValueDotAll = {
[x: string]: string | File | (string | File)[] | BodyDataValueDotAll
} & {}
type Simplify<T> = {
[K in keyof T]: string | File | (string | File)[] | BodyDataValueDotAll extends T[K]
? string | File | (string | File)[] | BodyDataValueDotAll
: string | File | BodyDataValueDot extends T[K]
? string | File | BodyDataValueDot
: string | File | (string | File)[] extends T[K]
? string | File | (string | File)[]
: string | File
} & {}

type BodyDataValueComponent<T> =
| string
| File
Expand All @@ -16,7 +30,9 @@ type BodyDataValue<T> =
: T extends { dot: true } | { dot: boolean }
? BodyDataValueObject<T> // use dot option
: never) // without options
export type BodyData<T extends Partial<ParseBodyOptions> = {}> = Record<string, BodyDataValue<T>>
export type BodyData<T extends Partial<ParseBodyOptions> = {}> = Simplify<
Record<string, BodyDataValue<T>>
>

export type ParseBodyOptions = {
/**
Expand Down

0 comments on commit e6aa84e

Please sign in to comment.