Co-Pilot / 辅助式
更新于 25 days ago

bun-elysia-skill

Yymc182
0.0k
ymc182/bun-elysia-skill
80
Agent 评分

💡 摘要

该技能使得使用 Bun.js 和 Elysia.js 及各种原生 API 构建全栈应用成为可能。

🎯 适合人群

全栈开发者从 Fastify 迁移的后端工程师使用 Bun.js 的开发者软件架构师技术教育工作者

🤖 AI 吐槽:看起来很能打,但别让配置把人劝退。

安全分析中风险

风险:Medium。建议检查:是否执行 shell/命令行指令;是否发起外网请求(SSRF/数据外发);API Key/Token 的获取、存储与泄露风险。以最小权限运行,并在生产环境启用前审计代码与依赖。


name: bun-elysia description: Build full-stack applications with Bun.js and Elysia.js. Use this skill when working with Bun runtime, Bun native APIs (SQL databases, Redis, S3), Bun workspaces/monorepos, Elysia.js web framework, or migrating from Fastify to Elysia. Covers setup, routing, validation, authentication, WebSocket, and end-to-end type safety with Eden.

Bun + Elysia.js Development

Build high-performance full-stack applications with Bun runtime and Elysia.js framework.

Quick Start

New Elysia Project

bun create elysia my-app cd my-app bun run dev

Basic Server

import { Elysia, t } from "elysia"; const app = new Elysia() .get("/", () => "Hello, World!") .get("/users/:id", ({ params }) => ({ id: params.id }), { params: t.Object({ id: t.Number() }) }) .post("/users", ({ body }) => ({ created: body }), { body: t.Object({ name: t.String(), email: t.String({ format: "email" }) }) }) .listen(3000);

With Bun Native APIs

import { Elysia } from "elysia"; import { sql } from "bun"; import { redis } from "bun"; const app = new Elysia() .decorate("sql", sql) .decorate("redis", redis) .get("/users", async ({ sql }) => { return sql`SELECT * FROM users`; }) .get("/cache/:key", async ({ redis, params }) => { return redis.get(params.key); }) .listen(3000);

Reference Navigation

What do you want to do?

Set up a project:

Use Bun native APIs:

Build with Elysia:

Migrate from Fastify:


Common Patterns

Authentication Middleware

import { Elysia } from "elysia"; import { jwt } from "@elysiajs/jwt"; const app = new Elysia() .use(jwt({ secret: process.env.JWT_SECRET! })) .derive(async ({ headers, jwt }) => { const token = headers.authorization?.replace("Bearer ", ""); const user = token ? await jwt.verify(token) : null; return { user }; }) .get("/profile", ({ user, error }) => { if (!user) return error(401); return user; });

Database with Validation

import { Elysia, t } from "elysia"; import { sql } from "bun"; const app = new Elysia() .post("/users", async ({ body }) => { const [user] = await sql` INSERT INTO users (name, email) VALUES (${body.name}, ${body.email}) RETURNING * `; return user; }, { body: t.Object({ name: t.String({ minLength: 1 }), email: t.String({ format: "email" }) }) });

Grouped Routes with Guard

app.group("/api", (app) => app .guard({ headers: t.Object({ authorization: t.String() }), beforeHandle: ({ headers, error }) => { if (!isValidToken(headers.authorization)) { return error(401); } } }, (app) => app .get("/users", getUsers) .post("/users", createUser) ) );

WebSocket Chat

app.ws("/chat", { body: t.Object({ room: t.String(), message: t.String() }), open(ws) { ws.subscribe("general"); }, message(ws, { room, message }) { ws.publish(room, { from: ws.id, message }); } });

Key Differences: Fastify vs Elysia

| Fastify | Elysia | |---------|--------| | request.params | { params } | | request.query | { query } | | request.body | { body } | | reply.code(n).send(x) | set.status = n; return x | | reply.header(k, v) | set.headers[k] = v | | JSON Schema | TypeBox (t.*) | | preHandler hook | beforeHandle | | fastify.decorate() | .decorate() | | fastify.register(plugin) | .use(plugin) |


Installation

# Elysia and plugins bun add elysia @elysiajs/swagger @elysiajs/jwt @elysiajs/cors @elysiajs/static @elysiajs/eden # Types bun add -d @types/bun typescript
五维分析
清晰度8/10
创新性8/10
实用性9/10
完整性8/10
可维护性7/10
优缺点分析

优点

  • 支持高性能应用
  • 与 Bun 原生 API 无缝集成
  • 使用 Eden 进行类型安全开发

缺点

  • 与更成熟的框架相比,社区支持有限
  • 对不熟悉 Bun.js 的人有学习曲线
  • 插件兼容性可能存在问题

相关技能

nuxt-skills

S
toolCo-Pilot / 辅助式
90/ 100

“这本质上是一份组织良好的小抄,能把你的 AI 助手变成一只 Nuxt 框架的复读机。”

mcp-builder

S
toolCode Lib / 代码库
90/ 100

“这份指南详尽到可能教会 AI 自己编写 MCP 服务器,从而让你失业。”

claude-mods

A
toolCo-Pilot / 辅助式
86/ 100

“看起来很能打,但别让配置把人劝退。”

免责声明:本内容来源于 GitHub 开源项目,仅供展示和评分分析使用。

版权归原作者所有 ymc182.