Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jsr): reduce slow types #2369

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions deno_dist/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HonoRequest } from './request.ts'
import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types.ts'
import { resolveCallback, HtmlEscapedCallbackPhase } from './utils/html.ts'
import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types.ts'
import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html.ts'
import type { RedirectStatusCode, StatusCode } from './utils/http-status.ts'
import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types.ts'

Expand Down Expand Up @@ -224,7 +224,18 @@ export class Context<
*/
render: Renderer = (...args) => this.renderer(...args)

setLayout = (layout: Layout<PropsForRenderer & { Layout: Layout }>) => (this.layout = layout)
setLayout: (
layout: Layout<
PropsForRenderer & {
Layout: Layout
}
>
) => Layout<
PropsForRenderer & {
Layout: Layout
}
> = (layout) => (this.layout = layout)

getLayout = () => this.layout

/**
Expand Down
8 changes: 4 additions & 4 deletions deno_dist/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Hono<
* })
* ```
*/
onError = (handler: ErrorHandler<E>) => {
onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath> = (handler) => {
this.errorHandler = handler
return this
}
Expand All @@ -247,7 +247,7 @@ class Hono<
* ```
* @see https://hono.dev/api/hono#not-found
*/
notFound = (handler: NotFoundHandler<E>) => {
notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath> = (handler) => {
this.notFoundHandler = handler
return this
}
Expand Down Expand Up @@ -391,12 +391,12 @@ class Hono<
* ```
* @see https://hono.dev/api/hono#request
*/
request = (
request: (
input: RequestInfo | URL,
requestInit?: RequestInit,
Env?: E['Bindings'] | {},
executionCtx?: ExecutionContext
) => {
) => Response | Promise<Response> = (input, requestInit, Env, executionCtx) => {
if (input instanceof Request) {
if (requestInit !== undefined) {
input = new Request(input, requestInit)
Expand Down
4 changes: 2 additions & 2 deletions deno_dist/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
* ```
* @see https://hono.dev/api/request#url
*/
get url() {
get url(): string {
return this.raw.url
}

Expand All @@ -303,7 +303,7 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
* ```
* @see https://hono.dev/api/request#method
*/
get method() {
get method(): string {
return this.raw.method
}

Expand Down
2 changes: 1 addition & 1 deletion deno_dist/router/smart-router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class SmartRouter<T> implements Router<T> {
return res as Result<T>
}

get activeRouter() {
get activeRouter(): Router<T> {
if (this.routes || this.routers.length !== 1) {
throw new Error('No active router has been determined yet.')
}
Expand Down
5 changes: 4 additions & 1 deletion deno_dist/utils/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const bufferToString = (buffer: ArrayBuffer): string => {
return buffer
}

export const bufferToFormData = (arrayBuffer: ArrayBuffer, contentType: string) => {
export const bufferToFormData = (
arrayBuffer: ArrayBuffer,
contentType: string
): Promise<FormData> => {
const response = new Response(arrayBuffer, {
headers: {
'Content-Type': contentType,
Expand Down
17 changes: 14 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HonoRequest } from './request'
import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types'
import { resolveCallback, HtmlEscapedCallbackPhase } from './utils/html'
import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types'
import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html'
import type { RedirectStatusCode, StatusCode } from './utils/http-status'
import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types'

Expand Down Expand Up @@ -224,7 +224,18 @@ export class Context<
*/
render: Renderer = (...args) => this.renderer(...args)

setLayout = (layout: Layout<PropsForRenderer & { Layout: Layout }>) => (this.layout = layout)
setLayout: (
layout: Layout<
PropsForRenderer & {
Layout: Layout
}
>
) => Layout<
PropsForRenderer & {
Layout: Layout
}
> = (layout) => (this.layout = layout)

getLayout = () => this.layout

/**
Expand Down
8 changes: 4 additions & 4 deletions src/hono-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Hono<
* })
* ```
*/
onError = (handler: ErrorHandler<E>) => {
onError: (handler: ErrorHandler<E>) => Hono<E, S, BasePath> = (handler) => {
this.errorHandler = handler
return this
}
Expand All @@ -247,7 +247,7 @@ class Hono<
* ```
* @see https://hono.dev/api/hono#not-found
*/
notFound = (handler: NotFoundHandler<E>) => {
notFound: (handler: NotFoundHandler<E>) => Hono<E, S, BasePath> = (handler) => {
this.notFoundHandler = handler
return this
}
Expand Down Expand Up @@ -391,12 +391,12 @@ class Hono<
* ```
* @see https://hono.dev/api/hono#request
*/
request = (
request: (
input: RequestInfo | URL,
requestInit?: RequestInit,
Env?: E['Bindings'] | {},
executionCtx?: ExecutionContext
) => {
) => Response | Promise<Response> = (input, requestInit, Env, executionCtx) => {
if (input instanceof Request) {
if (requestInit !== undefined) {
input = new Request(input, requestInit)
Expand Down
4 changes: 2 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
* ```
* @see https://hono.dev/api/request#url
*/
get url() {
get url(): string {
return this.raw.url
}

Expand All @@ -303,7 +303,7 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
* ```
* @see https://hono.dev/api/request#method
*/
get method() {
get method(): string {
return this.raw.method
}

Expand Down
2 changes: 1 addition & 1 deletion src/router/smart-router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class SmartRouter<T> implements Router<T> {
return res as Result<T>
}

get activeRouter() {
get activeRouter(): Router<T> {
if (this.routes || this.routers.length !== 1) {
throw new Error('No active router has been determined yet.')
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export const bufferToString = (buffer: ArrayBuffer): string => {
return buffer
}

export const bufferToFormData = (arrayBuffer: ArrayBuffer, contentType: string) => {
export const bufferToFormData = (
arrayBuffer: ArrayBuffer,
contentType: string
): Promise<FormData> => {
const response = new Response(arrayBuffer, {
headers: {
'Content-Type': contentType,
Expand Down