Skip to content

Commit a810374

Browse files
chore: wip
1 parent 9b56d46 commit a810374

File tree

4 files changed

+249
-19
lines changed

4 files changed

+249
-19
lines changed

bun.lock

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"dependencies": {
1919
"@stacksjs/clapp": "^0.2.0",
2020
"better-dx": "^0.2.0",
21-
"bun-plugin-dtsx": "^0.9.5",
21+
"bun-plugin-dtsx": "^0.21.12",
2222
"bun-query-builder": "^0.1.5",
2323
"bunfig": "^0.15.0",
2424
"openapi-types": "^12.1.3",
@@ -29,25 +29,25 @@
2929
"name": "bun-router-dashboard",
3030
"version": "0.0.0",
3131
"dependencies": {
32-
"@unocss/reset": "^66.1.2",
33-
"axios": "^1.9.0",
32+
"@unocss/reset": "^66.5.4",
33+
"axios": "^1.12.2",
3434
"chart.js": "^4.5.1",
3535
"d3": "7.9.0",
36-
"pinia": "^3.0.2",
37-
"vue": "^3.5.14",
36+
"pinia": "^3.0.3",
37+
"vue": "^3.5.22",
3838
"vue-chartjs": "^5.3.2",
39-
"vue-router": "^4.5.1",
39+
"vue-router": "^4.6.3",
4040
},
4141
"devDependencies": {
42-
"@iconify-json/carbon": "^1.2.8",
42+
"@iconify-json/carbon": "^1.2.14",
4343
"@types/d3": "7.4.3",
44-
"@unocss/preset-icons": "^66.1.2",
45-
"@unocss/preset-uno": "^66.1.2",
46-
"@unocss/preset-web-fonts": "^66.1.2",
47-
"@unocss/transformer-directives": "^66.1.2",
44+
"@unocss/preset-icons": "^66.5.4",
45+
"@unocss/preset-uno": "^66.5.4",
46+
"@unocss/preset-web-fonts": "^66.5.4",
47+
"@unocss/transformer-directives": "^66.5.4",
4848
"@vitejs/plugin-vue": "^6.0.1",
49-
"unocss": "^66.1.2",
50-
"vite": "^7.1.11",
49+
"unocss": "^66.5.4",
50+
"vite": "^7.1.12",
5151
"vue-tsc": "^3.1.1",
5252
},
5353
},
@@ -552,7 +552,7 @@
552552

553553
"@stacksjs/docs": ["@stacksjs/[email protected]", "", { "dependencies": { "@iconify-json/carbon": "^1.2.8", "@shikijs/vitepress-twoslash": "^3.2.1", "@vite-pwa/assets-generator": "^1.0.0", "@vite-pwa/vitepress": "^1.0.0", "unocss": "^66.0.0", "unplugin-icons": "^22.1.0", "unplugin-vue-components": "^28.4.1", "vite-plugin-pwa": "^1.0.0", "vitepress": "1.6.3" } }, "sha512-kRk/aza/wQAAgF0fhUhG8bUHhqk3RnjBkZyoRW0fvYs3dLaAArJYX/uVquZixlQnqgizGeGZT986tEFjs5Ly+A=="],
554554

555-
"@stacksjs/dtsx": ["@stacksjs/dtsx@0.9.4", "", { "bin": { "dtsx": "dist/bin/cli.js" } }, "sha512-nvAnS/xtYfFTStFfKJXvnzv6IJSUvY4c/o7RltUvnQqIVyZjHX3a0R0Gp2J5m7gkYO+6sneQs1WcY7e9NQyAsg=="],
555+
"@stacksjs/dtsx": ["@stacksjs/dtsx@0.8.3", "", { "bin": { "dtsx": "dist/cli.js" } }, "sha512-+u/PEp478qHM8s7xT0AOZowd93mZ/5ptHFyiz0B/gcxmdrdNdM6bLIK5si5Uzy1cR5TOVN4oAB3+WMKDnJ3n1w=="],
556556

557557
"@stacksjs/error-handling": ["@stacksjs/[email protected]", "", {}, "sha512-rQcgyum8eZnVjaF+eb6ip/IHK4GuOidwy1GcbAOqXeDwbc7oUxWFlpT7pKMeYbYa+DWZjV1WdolLxSL/orQeCw=="],
558558

@@ -904,7 +904,7 @@
904904

905905
"bun-git-hooks": ["[email protected]", "", { "bin": { "git-hooks": "dist/bin/cli.js", "bun-git-hooks": "dist/bin/cli.js" } }, "sha512-Xs/QUqIYgBmLHSVr5VBLVbM5lZbUoAXKX2WZyoQDb2LlzcxC3BpBvMkMTQH75UuOJZwaRBq8yEe4IR6NckqdgQ=="],
906906

907-
"bun-plugin-dtsx": ["bun-plugin-dtsx@0.9.5", "", { "dependencies": { "@stacksjs/dtsx": "0.9.4" } }, "sha512-PMGr8kna2C7rbN5NFKW+nqj8TyXjs05Yh2QM7Xjp9PN1/cJMyZML3JJAJT0Ne/6eOYCcubmLM91r+Rix/cqn8Q=="],
907+
"bun-plugin-dtsx": ["bun-plugin-dtsx@0.21.12", "", { "dependencies": { "@stacksjs/dtsx": "^0.8.1" } }, "sha512-VqGDRoTKEnkD508k9jRlcwFoEEJXtjqLMGN+brRP4/3vH0wfLZkZiWG5jc490roZOmphrQlo5NgfFB/j71+Qtg=="],
908908

909909
"bun-query-builder": ["[email protected]", "", { "dependencies": { "@stacksjs/ts-validation": "^0.4.7", "ts-mocker": "^0.1.3" }, "bin": { "query-builder": "dist/bin/cli.js", "qbx": "dist/bin/cli.js", "qb": "dist/bin/cli.js" } }, "sha512-z8LjF+T69Q+5C7YDt8lkijojFEy4YpV5Ync05WYnp4kw9/714z/NtRISBct8MlNAiZ0vmeq7saARByKUu1LlUg=="],
910910

@@ -962,7 +962,7 @@
962962

963963
"comma-separated-tokens": ["[email protected]", "", {}, "sha512-Fu4hJdvzeylCfQPp9SGWidpzrMs7tTrlu6Vb8XGaRGck8QSNZJJp538Wrb60Lax4fPwR64ViY468OIUTbRlGZg=="],
964964

965-
"commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="],
965+
"commander": ["commander@7.2.0", "", {}, "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="],
966966

967967
"comment-parser": ["[email protected]", "", {}, "sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg=="],
968968

@@ -1990,7 +1990,7 @@
19901990

19911991
"vfile-message": ["[email protected]", "", { "dependencies": { "@types/unist": "^3.0.0", "unist-util-stringify-position": "^4.0.0" } }, "sha512-QTHzsGd1EhbZs4AsQ20JX1rC3cOlt/IWJruk893DfLRr57lcnOeMaWG4K0JrRta4mIJZKth2Au3mM3u03/JWKw=="],
19921992

1993-
"vite": ["[email protected].11", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-uzcxnSDVjAopEUjljkWh8EIrg6tlzrjFUfMcR1EVsRDGwf/ccef0qQPRyOrROwhrTDaApueq+ja+KLPlzR/zdg=="],
1993+
"vite": ["[email protected].12", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-ZWyE8YXEXqJrrSLvYgrRP7p62OziLW7xI5HYGWFzOvupfAlrLvURSzv/FyGyy0eidogEM3ujU+kUG1zuHgb6Ug=="],
19941994

19951995
"vite-plugin-pwa": ["[email protected]", "", { "dependencies": { "debug": "^4.3.6", "pretty-bytes": "^6.1.1", "tinyglobby": "^0.2.10", "workbox-build": "^7.3.0", "workbox-window": "^7.3.0" }, "peerDependencies": { "@vite-pwa/assets-generator": "^1.0.0", "vite": "^3.1.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0" }, "optionalPeers": ["@vite-pwa/assets-generator"] }, "sha512-VsSpdubPzXhHWVINcSx6uHRMpOHVHQcHsef1QgkOlEoaIDAlssFEW88LBq1a59BuokAhsh2kUDJbaX1bZv4Bjw=="],
19961996

@@ -2220,12 +2220,12 @@
22202220

22212221
"babel-plugin-polyfill-corejs2/semver": ["[email protected]", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
22222222

2223+
"better-dx/bun-plugin-dtsx": ["[email protected]", "", { "dependencies": { "@stacksjs/dtsx": "0.9.4" } }, "sha512-PMGr8kna2C7rbN5NFKW+nqj8TyXjs05Yh2QM7Xjp9PN1/cJMyZML3JJAJT0Ne/6eOYCcubmLM91r+Rix/cqn8Q=="],
2224+
22232225
"chalk/ansi-styles": ["[email protected]", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
22242226

22252227
"clean-regexp/escape-string-regexp": ["[email protected]", "", {}, "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg=="],
22262228

2227-
"d3-dsv/commander": ["[email protected]", "", {}, "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="],
2228-
22292229
"eslint/@eslint/core": ["@eslint/[email protected]", "", { "dependencies": { "@types/json-schema": "^7.0.15" } }, "sha512-nmC8/totwobIiFcGkDza3GIKfAw1+hLiYVrh3I1nIomQ8PEr5cxg34jnkmGawul/ep52wGRAcyeDCNtWKSOj4Q=="],
22302230

22312231
"eslint/@eslint/plugin-kit": ["@eslint/[email protected]", "", { "dependencies": { "@eslint/core": "^0.16.0", "levn": "^0.4.1" } }, "sha512-sB5uyeq+dwCWyPi31B2gQlVlo+j5brPlWx4yZBrEaRo/nhdDE8Xke1gsGgtiBdaBTxuTkceLVuVt/pclrasb0A=="],
@@ -2286,6 +2286,8 @@
22862286

22872287
"tempy/type-fest": ["[email protected]", "", {}, "sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg=="],
22882288

2289+
"terser/commander": ["[email protected]", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="],
2290+
22892291
"toml-eslint-parser/eslint-visitor-keys": ["[email protected]", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
22902292

22912293
"unconfig/@antfu/utils": ["@antfu/[email protected]", "", {}, "sha512-+562v9k4aI80m1+VuMHehNJWLOFjBnXn3tdOitzD0il5b7smkSBal4+a3oKiQTbrwMmN/TBUMDvbdoWDehgOww=="],
@@ -2344,6 +2346,8 @@
23442346

23452347
"@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["[email protected]", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="],
23462348

2349+
"better-dx/bun-plugin-dtsx/@stacksjs/dtsx": ["@stacksjs/[email protected]", "", { "bin": { "dtsx": "dist/bin/cli.js" } }, "sha512-nvAnS/xtYfFTStFfKJXvnzv6IJSUvY4c/o7RltUvnQqIVyZjHX3a0R0Gp2J5m7gkYO+6sneQs1WcY7e9NQyAsg=="],
2350+
23472351
"eslint-plugin-vuejs-accessibility/vue-eslint-parser/eslint-scope": ["[email protected]", "", { "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg=="],
23482352

23492353
"eslint-plugin-vuejs-accessibility/vue-eslint-parser/eslint-visitor-keys": ["[email protected]", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],

playground/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Bun Router Playground
2+
3+
This playground contains examples and demos for the bun-router framework.
4+
5+
## Files
6+
7+
- `basic-di-demo.ts` - Basic router usage with simple routes and named routes
8+
- `storage/framework/core/advanced-di-demo.ts` - Advanced router features including middleware, route groups, and error handling
9+
10+
## Running the Demos
11+
12+
```bash
13+
# Run basic router demo
14+
bun run playground/basic-di-demo.ts
15+
16+
# Run advanced router demo
17+
bun run playground/storage/framework/core/advanced-di-demo.ts
18+
```
19+
20+
## Features Demonstrated
21+
22+
### Basic Demo
23+
24+
- Simple route definitions (GET, POST)
25+
- Path parameters (`/users/{id}`)
26+
- Named routes with URL generation
27+
- Basic request/response handling
28+
29+
### Advanced Demo
30+
31+
- Middleware (auth, logging)
32+
- Route groups (`/api`, `/admin`)
33+
- Advanced route parameters
34+
- Query parameter handling
35+
- Error handling
36+
- Static file serving
37+
38+
## Cleanup
39+
40+
To clean up node_modules directories (as requested):
41+
42+
```bash
43+
find . -name "node_modules" -type d -prune -exec rm -rf {} +
44+
```
45+
46+
This command will remove all node_modules directories from the project.

playground/basic-di-demo.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Basic Router Usage Demo
3+
*
4+
* Simple examples of using the bun-router
5+
*/
6+
7+
import { Router } from '../packages/bun-router/src/router'
8+
9+
console.log('🚀 Basic Router Usage Demo\n')
10+
11+
// Create a router
12+
const router = new Router()
13+
14+
// Basic route handlers
15+
const homeHandler = () => new Response('Hello, World!')
16+
17+
async function createUserHandler(req: Request) {
18+
const data = await req.json()
19+
return Response.json({ message: 'User created', data })
20+
}
21+
22+
function getUserHandler(req: Request) {
23+
const { id } = req.params
24+
return Response.json({ id, name: `User ${id}` })
25+
}
26+
27+
// Define routes
28+
router.get('/', homeHandler)
29+
router.post('/users', createUserHandler)
30+
router.get('/users/{id}', getUserHandler)
31+
32+
// Named routes
33+
router.get('/users/{id}', getUserHandler, 'api', 'users.show')
34+
router.get('/users', () => Response.json({ users: [] }), 'api', 'users.index')
35+
36+
// Generate URL for named route
37+
const url = router.route('users.show', { id: '123' })
38+
console.log('Generated URL:', url)
39+
40+
// Start the server (commented out for demo)
41+
console.log('Router configured with routes:')
42+
console.log(' GET /')
43+
console.log(' POST /users')
44+
console.log(' GET /users/{id}')
45+
console.log(' Named routes: users.show, users.index')
46+
47+
// Uncomment to start the server:
48+
// router.serve({
49+
// port: 3000,
50+
// })
51+
52+
console.log('\n✅ Router demo completed!')
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
* Advanced Router Usage Demo
3+
*
4+
* More complex examples with available router features
5+
*/
6+
7+
import { Router } from '../../../../packages/bun-router/src/router'
8+
9+
console.log('🔧 Advanced Router Usage Demo\n')
10+
11+
// Create a router
12+
const router = new Router()
13+
14+
// Example 1: Multiple HTTP Methods
15+
console.log('1. Multiple HTTP Methods:')
16+
17+
// GET route
18+
router.get('/users', () => {
19+
return Response.json({ users: [] })
20+
})
21+
22+
// POST route
23+
router.post('/users', async (req) => {
24+
const data = await req.json()
25+
return Response.json({ message: 'User created', data })
26+
})
27+
28+
// PUT route
29+
router.put('/users/{id}', async (req) => {
30+
const { id } = req.params
31+
const data = await req.json()
32+
return Response.json({ message: `User ${id} updated`, data })
33+
})
34+
35+
// DELETE route
36+
router.delete('/users/{id}', (req) => {
37+
const { id } = req.params
38+
return Response.json({ message: `User ${id} deleted` })
39+
})
40+
41+
// Example 2: Advanced Route Parameters
42+
console.log('\n2. Advanced Route Parameters:')
43+
44+
// Route with multiple parameters
45+
router.get('/posts/{category}/{slug}', (req) => {
46+
const { category, slug } = req.params
47+
return Response.json({ category, slug, title: `${category} - ${slug}` })
48+
})
49+
50+
// Route with query parameters
51+
router.get('/search', (req) => {
52+
const url = new URL(req.url)
53+
const query = url.searchParams.get('q')
54+
const page = url.searchParams.get('page') || '1'
55+
return Response.json({ query, page, results: [] })
56+
})
57+
58+
// Example 3: Named Routes
59+
console.log('\n3. Named Routes:')
60+
61+
// Named routes with parameters
62+
router.get('/posts/{id}', (req) => {
63+
const { id } = req.params
64+
return Response.json({ id, title: `Post ${id}` })
65+
}, 'blog', 'posts.show')
66+
67+
router.get('/posts', () => {
68+
return Response.json({ posts: [] })
69+
}, 'blog', 'posts.index')
70+
71+
// Generate URLs for named routes
72+
const postUrl = router.route('posts.show', { id: '123' })
73+
const postsIndexUrl = router.route('posts.index')
74+
console.log(' Generated post URL:', postUrl)
75+
console.log(' Generated posts index URL:', postsIndexUrl)
76+
77+
// Example 4: Complex Route Patterns
78+
console.log('\n4. Complex Route Patterns:')
79+
80+
// Nested resource routes
81+
router.get('/api/v1/users/{id}/posts', (req) => {
82+
const { id } = req.params
83+
return Response.json({ userId: id, posts: [] })
84+
})
85+
86+
router.get('/api/v1/users/{userId}/posts/{postId}', (req) => {
87+
const { userId, postId } = req.params
88+
return Response.json({ userId, postId, title: `Post ${postId} by user ${userId}` })
89+
})
90+
91+
// Example 5: Route with Different Response Types
92+
console.log('\n5. Different Response Types:')
93+
94+
// JSON response
95+
router.get('/api/data', () => {
96+
return Response.json({ data: 'JSON response' })
97+
})
98+
99+
// Text response
100+
router.get('/api/text', () => {
101+
return new Response('Plain text response')
102+
})
103+
104+
// HTML response
105+
router.get('/api/html', () => {
106+
return new Response('<h1>HTML Response</h1>', {
107+
headers: { 'Content-Type': 'text/html' },
108+
})
109+
})
110+
111+
// Redirect response
112+
router.get('/api/redirect', () => {
113+
return Response.redirect('/api/data', 302)
114+
})
115+
116+
console.log('Router configured with advanced features:')
117+
console.log(' - Multiple HTTP methods (GET, POST, PUT, DELETE)')
118+
console.log(' - Advanced route parameters')
119+
console.log(' - Named routes with URL generation')
120+
console.log(' - Complex nested routes')
121+
console.log(' - Different response types')
122+
123+
// Uncomment to start the server:
124+
// router.serve({
125+
// port: 3000,
126+
// })
127+
128+
console.log('\n✅ Advanced router demo completed!')

0 commit comments

Comments
 (0)