Skip to content
Myr

refactor: do some refactoring (#104)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent d7fe0b0 · Browse files · 5 files+27 added−18 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+27 added−18 removed

  • other:+27 added−18 removed

5 files+27 added−18 removed

modified:src/middleware/body-parse/body-parse.ts+2 added-1 removed
modified:src/middleware/mustache/mustache.ts+12 added-6 removed
modified:src/context.ts+5 added-2 removed
1import { isAbsoluteURL } from './utils/url'2import { getStatusText } from './utils/http-status'34type Headers = { [key: string]: string }4type Headers = Record<string, string>5type Data = string | ArrayBuffer | ReadableStream67export interface Env {}8
7 unmodified lines
16 private _statusText: string1718 render: (template: string, params?: object, options?: object) => Promise<Response>1920 constructor(req: Request<RequestParamKeyType>, opts?: { res: Response; env: Env; event: FetchEvent }) {20 constructor(21 req: Request<RequestParamKeyType>,22 opts?: { res: Response; env: Env; event: FetchEvent }23 ) {24 this.req = req25 if (opts) {26 this.res = opts.res27 this.env = opts.env
98 unmodified lines
modified:src/hono.ts+2 added-3 removed
1import type { Result } from './node'2import { Node } from './node'2import { Node, METHOD_NAME_OF_ALL } from './node'3import { compose } from './compose'4import { getPathFromURL } from './utils/url'5import { Context } from './context'6import type { Env } from './context'78const METHOD_NAME_OF_ALL = 'ALL'98declare global {9 interface Request<ParamKeyType = string> {10 param: (key: ParamKeyType) => string11 query: (key: string) => string12 header: (name: string) => string13 // TODO: do not use `any`14 parsedBody: any15 }16}17
238 unmodified lines
modified:src/node.ts+6 added-6 removed
1import { splitPath, getPattern } from './utils/url'23const METHOD_NAME_OF_ALL = 'ALL'3export const METHOD_NAME_OF_ALL = 'ALL'45export class Result<T> {6 handler: T7 params: { [key: string]: string }8 constructor(handler: T, params: { [key: string]: string }) {7 params: Record<string, string>8 constructor(handler: T, params: Record<string, string>) {9 this.handler = handler10 this.params = params11 }12}
2 unmodified lines
15 return null16}1718export class Node<T> {19 method: { [key: string]: T }19 method: Record<string, T>20 handler: T21 children: { [key: string]: Node<T> }21 children: Record<string, Node<T>>22 middlewares: []2324 constructor(method?: string, handler?: T, children?: { [key: string]: Node<T> }) {24 constructor(method?: string, handler?: T, children?: Record<string, Node<T>>) {25 this.children = children || {}26 this.method = {}27 if (method && handler) {28 this.method[method] = handler
98 unmodified lines