parent
19fc874400
commit
e970536220
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/medley-router': patch
|
||||
---
|
||||
|
||||
initial release
|
|
@ -0,0 +1,25 @@
|
|||
name: ci-medley-router
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'packages/medley-router/**'
|
||||
pull_request:
|
||||
branches: ['*']
|
||||
paths:
|
||||
- 'packages/medley-router/**'
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./packages/medley-router
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: yarn install --frozen-lockfile
|
||||
- run: yarn build
|
||||
- run: yarn test
|
|
@ -14,6 +14,7 @@
|
|||
"build:firebase-auth": "yarn workspace @hono/firebase-auth build",
|
||||
"build:trpc-server": "yarn workspace @hono/trpc-server build",
|
||||
"build:typebox-validator": "yarn workspace @hono/typebox-validator build",
|
||||
"build:medley-router": "yarn workspace @hono/medley-router build",
|
||||
"build": "run-p build:*"
|
||||
},
|
||||
"license": "MIT",
|
||||
|
@ -45,4 +46,4 @@
|
|||
"ts-jest": "^29.0.5",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
# Router using @medley/router
|
||||
|
||||
Just a PoC.
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { Hono } from 'hono'
|
||||
import { MedleyRouter } from '@hono/medley-router'
|
||||
|
||||
const app = new Hono({ router: new MedleyRouter() })
|
||||
|
||||
app.get('/', (c) => c.text('Hello'))
|
||||
```
|
||||
|
||||
## Authors
|
||||
|
||||
Yusuke Wada <https://github.com/yusukebe>
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
|
@ -0,0 +1 @@
|
|||
module.exports = require('../../jest.config.js')
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "@hono/medley-router",
|
||||
"version": "0.0.0",
|
||||
"description": "Router using @medley/router",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"build": "rimraf dist && tsc",
|
||||
"prerelease": "yarn build && yarn test",
|
||||
"release": "yarn publish"
|
||||
},
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org",
|
||||
"access": "public"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/honojs/middleware.git"
|
||||
},
|
||||
"homepage": "https://github.com/honojs/middleware",
|
||||
"peerDependencies": {
|
||||
"hono": "*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hono": "^3.1.6"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medley/router": "^0.2.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import { Hono } from 'hono'
|
||||
import { MedleyRouter } from '../src'
|
||||
|
||||
describe('Basic', () => {
|
||||
const app = new Hono({ router: new MedleyRouter() })
|
||||
|
||||
app.get('/', (c) => c.text('Hello'))
|
||||
|
||||
it('Should return a 200 response', async () => {
|
||||
const res = await app.request('/')
|
||||
expect(res).not.toBeNull()
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
export { MedleyRouter } from './router'
|
|
@ -0,0 +1,31 @@
|
|||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
import OriginalRouter from '@medley/router'
|
||||
// Should be exported from `hono/router`
|
||||
import type { Result, Router } from 'hono/dist/types/router'
|
||||
|
||||
export class MedleyRouter<T> implements Router<T> {
|
||||
router: any
|
||||
|
||||
constructor() {
|
||||
this.router = new OriginalRouter()
|
||||
}
|
||||
|
||||
add(method: string, path: string, handler: T) {
|
||||
const store = this.router.register(path)
|
||||
store[method] = handler
|
||||
}
|
||||
|
||||
match(method: string, path: string): Result<T> | null {
|
||||
const route = this.router.find(path)
|
||||
|
||||
if (route) {
|
||||
return {
|
||||
handlers: [route['store'][method]],
|
||||
params: route['params'],
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
}
|
22
yarn.lock
22
yarn.lock
|
@ -1196,6 +1196,13 @@
|
|||
unist-util-visit "^4.0.0"
|
||||
vfile "^5.0.0"
|
||||
|
||||
"@medley/router@^0.2.1":
|
||||
version "0.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@medley/router/-/router-0.2.1.tgz#d8b8aad3fb1de710e9bd35e9e249545dc65945d0"
|
||||
integrity sha512-mdvS1spIxmZoUbTdYmWknHtwm72WwrGNoQCDd4RTvcXJ9G6XThxeC3g+cpOf6Fw6vIERHt50pYiJpsk5XTJQ5w==
|
||||
dependencies:
|
||||
object-treeify "^1.1.20"
|
||||
|
||||
"@miniflare/cache@2.12.2":
|
||||
version "2.12.2"
|
||||
resolved "https://registry.yarnpkg.com/@miniflare/cache/-/cache-2.12.2.tgz#402cbf67c9fc717b26c06516a166100d4b020870"
|
||||
|
@ -5369,16 +5376,16 @@ hono@3.1.5:
|
|||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.1.5.tgz#a1c5314bb1cf0fd8b72bd2b6b6698eee16fbc520"
|
||||
integrity sha512-ypFLhNYoXXtep4I9zJt3VpB5/Ze3p9BLU4dpnAp7fxHOmSg8lu/Wwjs5sTJnb2GwVdfjbt9KFB9alA4Zt/P0jw==
|
||||
|
||||
hono@^2.7.2:
|
||||
version "2.7.8"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-2.7.8.tgz#5f6916c7f6838fe1f909f6046b30e6a0900f3128"
|
||||
integrity sha512-LXLXw6LilE16QO0siFBDiNzmaRP6ca5ZyF0gDWcaiUqJJtE/d4lV/Hpst2O33AmJB5n0DQa5w53gZLUVf7uXNg==
|
||||
|
||||
hono@^3.0.0, hono@^3.0.2, hono@^3.0.3, hono@^3.1.0, hono@^3.1.2:
|
||||
version "3.1.2"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.1.2.tgz#896231b8940c201212bb3d440bebce637e68be26"
|
||||
integrity sha512-keNMGSlBX2VbwD5gF10Xu0zuUm9mTy1HWctIhuom8FJEJY6aKo1Bb/vQXTEjBupKDG7MJi2aG05YMo01GjkMQA==
|
||||
|
||||
hono@^3.1.6:
|
||||
version "3.1.6"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.1.6.tgz#7a7ca700fff69553a8c2a7a97d544f49bb8b1bd3"
|
||||
integrity sha512-ugC7YbuyATZChp+SxfstiavvTCqENjvSiTiDAkbAOP20pJ58N4kXcbDi93SwZrvMFA2VVx1veMYHrsvUY9hcVA==
|
||||
|
||||
hosted-git-info@^2.1.4:
|
||||
version "2.8.9"
|
||||
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"
|
||||
|
@ -8499,6 +8506,11 @@ object-keys@^1.1.1:
|
|||
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
|
||||
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
|
||||
|
||||
object-treeify@^1.1.20:
|
||||
version "1.1.33"
|
||||
resolved "https://registry.yarnpkg.com/object-treeify/-/object-treeify-1.1.33.tgz#f06fece986830a3cba78ddd32d4c11d1f76cdf40"
|
||||
integrity sha512-EFVjAYfzWqWsBMRHPMAXLCDIJnpMhdWAqR7xG6M6a2cs6PMFpl/+Z20w9zDW4vkxOFfddegBKq9Rehd0bxWE7A==
|
||||
|
||||
object.assign@^4.1.4:
|
||||
version "4.1.4"
|
||||
resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.4.tgz#9673c7c7c351ab8c4d0b516f4343ebf4dfb7799f"
|
||||
|
|
Loading…
Reference in New Issue