Skip to content
Myr

Use named import, add types by .d.ts file

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

authored by Yusuke Wada · committed by Yusuke Wada · parent 71aac69 · Browse files · 11 files+74 added−23 removed
This commit

State

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

Diff stats

11 files+74 added−23 removed

  • tests:+9 added−8 removed
  • other:+65 added−15 removed

11 files+74 added−23 removed

modified:benchmark/handleEvent/index.js+2 added-2 removed
modified:benchmark/webapp/hono/index.js+2 added-2 removed
modified:example/basic/index.js+2 added-2 removed
modified:example/basic/README.md+2 added-2 removed
modified:example/compute-at-edge/index.js+2 added-2 removed
1const Hono = require('hono')2const app = Hono()1const { Hono } = require('hono')2const app = new Hono()34app.use('*', (c, next) => {5 console.log(`[${c.req.method}] ${c.req.url}`)6 next()
11 unmodified lines
added:src/hono.d.ts+42 added
1declare class FetchEvent {}2declare class Request {}3declare class Response {}4declare class Context {}56declare class Node {}78declare class Router {9 tempPath: string10 node: Node1112 add(method: string, path: string, handlers: any[]): Node13 match(method: string, path: string): Node14}1516export class Hono {17 router: Router18 middlewareRouters: Router[]1920 getRouter(): Router21 addRoute(method: string, args: any[]): Hono22 matchRoute(method: string, path: string): Node23 createContext(req: Request, res: Response): Context24 dispatch(req: Request, res: Response): Response25 handleEvent(event: FetchEvent): Response26 fire(): void2728 notFound(): Response2930 route(path: string): Hono3132 use(path: string, middleware: any): void3334 all(path: string, handler: any): Hono35 get(path: string, handler: any): Hono36 post(path: string, handler: any): Hono37 put(path: string, handler: any): Hono38 head(path: string, handler: any): Hono39 delete(path: string, handler: any): Hono40}4142export class Middleware {}
modified:src/hono.js+8 added-3 removed
2 unmodified lines
3const Node = require('./node')4const compose = require('./compose')5const methods = require('./methods')6const defaultFilter = require('./middleware/defaultFilter')7const Middleware = require('./middleware')89const METHOD_NAME_OF_ALL = 'ALL'1011class Router {
120 unmodified lines
132 return new Response('Not Found', { status: 404 })133 }134}135135module.exports = () => {136 return new Hono()137}136// Default Export137module.exports = Hono138exports = module.exports139140// Named Export141exports.Hono = Hono142exports.Middleware = Middleware
modified:src/hono.test.js+5 added-4 removed
1const Hono = require('./hono')1const fetch = require('node-fetch')2const { Hono } = require('./hono')34describe('GET Request', () => {5 const app = Hono()5 const app = new Hono()67 app.get('/hello', () => {8 return new fetch.Response('hello', {9 status: 200,10 })
18 unmodified lines
29 })30})3132describe('params and query', () => {32 const app = Hono()33 const app = new Hono()3435 app.get('/entry/:id', async (c) => {36 const id = await c.req.params('id')37 return new fetch.Response(`id is ${id}`, {
22 unmodified lines
60 })61})6263describe('Middleware', () => {63 const app = Hono()64 const app = new Hono()6566 const logger = async (c, next) => {67 console.log(`${c.req.method} : ${c.req.url}`)68 next()
47 unmodified lines
added:src/middleware.js+3 added
1class Middleware {}23module.exports = Middleware
modified:src/router.test.js+4 added-4 removed
1const App = require('./hono')1const { Hono } = require('./hono')23describe('Basic Usage', () => {4 const router = App()4 const router = new Hono()56 it('get, post hello', async () => {7 router.get('/hello', 'get hello')8 router.post('/hello', 'post hello')
14 unmodified lines
23 })24})2526describe('Complex', () => {27 let router = App()27 let router = new Hono()2829 it('Named Param', async () => {30 router.get('/entry/:id', 'get entry')31 res = await router.matchRoute('GET', '/entry/123')
23 unmodified lines
55 })56})5758describe('Chained Route', () => {59 let router = App()59 let router = new Hono()6061 it('Return rooter object', async () => {62 router = router.patch('/hello', 'patch hello')63 expect(router).not.toBeNull()
25 unmodified lines
modified:README.md+2 added-2 removed
1 unmodified line
23Hono [炎] - Tiny web framework for Cloudflare Workers and others.45```js6const Hono = require('hono')7const app = Hono()6const { Hono } = require('hono')7const app = new Hono()89app.get('/', () => new Response('Hono!!'))1011app.fire()
166 unmodified lines