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

wip: perf(types): replace to interface #3886

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/remove-private-fields-worker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from 'typescript'

export type WorkerInput = {
export interface WorkerInput {
file: string
taskId: number
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/cloudflare-workers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
declare const __STATIC_CONTENT: unknown
declare const __STATIC_CONTENT_MANIFEST: string

export type KVAssetOptions = {
export interface KVAssetOptions {
manifest?: object | string
// namespace is KVNamespace
namespace?: unknown
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/lambda-edge/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface CloudFrontEdgeEvent {
Records: CloudFrontEvent[]
}

type CloudFrontContext = {}
interface CloudFrontContext {}

export interface Callback {
(err: Error | null, result?: CloudFrontRequest | CloudFrontResult): void
Expand Down
2 changes: 1 addition & 1 deletion src/helper/css/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const keyframesCommon = (
}
}

type ViewTransitionType = {
interface ViewTransitionType {
(strings: TemplateStringsArray, values: CssVariableType[]): CssClassName
(content: CssClassName): CssClassName
(): CssClassName
Expand Down
2 changes: 1 addition & 1 deletion src/http-exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { ContentfulStatusCode } from './utils/http-status'
* @property message - Optional custom error message.
* @property cause - Optional cause of the error.
*/
type HTTPExceptionOptions = {
interface HTTPExceptionOptions {
res?: Response
message?: string
cause?: unknown
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/body-limit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { MiddlewareHandler } from '../../types'
const ERROR_MESSAGE = 'Payload Too Large'

type OnError = (c: Context) => Response | Promise<Response>
type BodyLimitOptions = {
interface BodyLimitOptions {
maxSize: number
onError?: OnError
}
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/cors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import type { Context } from '../../context'
import type { MiddlewareHandler } from '../../types'

type CORSOptions = {
interface CORSOptions {
origin: string | string[] | ((origin: string, c: Context) => string | undefined | null)
allowMethods?: string[]
allowHeaders?: string[]
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/etag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import type { MiddlewareHandler } from '../../types'
import { generateDigest } from './digest'

type ETagOptions = {
interface ETagOptions {
retainedHeaders?: string[]
weak?: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/jsx-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { HtmlEscapedString } from '../../utils/html'
export const RequestContext: JSXContext<Context<any, any, {}> | null> =
createContext<Context | null>(null)

type RendererOptions = {
interface RendererOptions {
docType?: boolean | string
stream?: boolean | Record<string, string>
}
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/powered-by/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import type { MiddlewareHandler } from '../../types'

type PoweredByOptions = {
interface PoweredByOptions {
/**
* The value for X-Powered-By header.
* @default Hono
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/request-id/request-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import type { Context } from '../../context'
import type { MiddlewareHandler } from '../../types'

export type RequestIdVariables = {
export interface RequestIdVariables {
requestId: string
}

export type RequestIdOptions = {
export interface RequestIdOptions {
limitLength?: number
headerName?: string
generator?: (c: Context) => string
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/secure-headers/secure-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { MiddlewareHandler } from '../../types'
import { encodeBase64 } from '../../utils/encode'
import type { PermissionsPolicyDirective } from './permissions-policy'

export type SecureHeadersVariables = {
export interface SecureHeadersVariables {
secureHeadersNonce?: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/timing/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Context } from '../../context'
import type { MiddlewareHandler } from '../../types'
import '../../context'

export type TimingVariables = {
export interface TimingVariables {
metric?: {
headers: string[]
timers: Map<string, Timer>
Expand Down
9 changes: 7 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ import type { CustomHeader, RequestHeader } from './utils/headers'
import type { Simplify, UnionToIntersection } from './utils/types'
import { decodeURIComponent_, getQueryParam, getQueryParams, tryDecode } from './utils/url'

type Body = {
interface Body {
json: any
text: string
arrayBuffer: ArrayBuffer
blob: Blob
formData: FormData
}
type BodyCache = Partial<Body & { parsedBody: BodyData }>

interface BodyWithParsedBody extends Body {
parsedBody: BodyData
}

type BodyCache = Partial<BodyWithParsedBody>

const tryDecodeURIComponent = (str: string) => tryDecode(str, decodeURIComponent_)

Expand Down
8 changes: 5 additions & 3 deletions src/utils/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

import { HonoRequest } from '../request'

type BodyDataValueDot = { [x: string]: string | File | BodyDataValueDot }
type BodyDataValueDotAll = {
interface BodyDataValueDot {
[x: string]: string | File | BodyDataValueDot
}
interface BodyDataValueDotAll {
[x: string]: string | File | (string | File)[] | BodyDataValueDotAll
}
type SimplifyBodyData<T> = {
Expand Down Expand Up @@ -39,7 +41,7 @@ export type BodyData<T extends Partial<ParseBodyOptions> = {}> = SimplifyBodyDat
Record<string, BodyDataValue<T>>
>

export type ParseBodyOptions = {
export interface ParseBodyOptions {
/**
* Determines whether all fields with multiple values should be parsed as arrays.
* @default false
Expand Down
10 changes: 8 additions & 2 deletions src/utils/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ export type SignedCookie = Record<string, string | false>
type PartitionedCookieConstraint =
| { partitioned: true; secure: true }
| { partitioned?: boolean; secure?: boolean } // reset to default
type SecureCookieConstraint = { secure: true }
type HostCookieConstraint = { secure: true; path: '/'; domain?: undefined }
interface SecureCookieConstraint {
secure: true
}
interface HostCookieConstraint {
secure: true
path: '/'
domain?: undefined
}

export type CookieOptions = {
domain?: string
Expand Down
2 changes: 1 addition & 1 deletion src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { JSONValue } from './types'

type Algorithm = {
interface Algorithm {
name: string
alias: string
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/filepath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* FilePath utility.
*/

type FilePathOptions = {
interface FilePathOptions {
filename: string
root?: string
defaultDocument?: string
Expand Down
4 changes: 2 additions & 2 deletions src/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const HtmlEscapedCallbackPhase = {
BeforeStream: 2,
Stream: 3,
} as const
type HtmlEscapedCallbackOpts = {
interface HtmlEscapedCallbackOpts {
buffer?: [string]
phase: (typeof HtmlEscapedCallbackPhase)[keyof typeof HtmlEscapedCallbackPhase]
context: Readonly<object> // An object unique to each JSX tree. This object is used as the WeakMap key.
}
export type HtmlEscapedCallback = (opts: HtmlEscapedCallbackOpts) => Promise<string> | undefined
export type HtmlEscaped = {
export interface HtmlEscaped {
isEscaped: true
callbacks?: HtmlEscapedCallback[]
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/jwt/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export enum CryptoKeyUsage {
/**
* JWT Payload
*/
export type JWTPayload = {
export interface JWTPayload {
[key: string]: unknown
/**
* The token is checked to ensure it has not expired.
Expand Down
Loading