koa-boot-runtime 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# koa-boot-runtime
|
|
2
|
+
|
|
3
|
+
基于 Koa 3 + Prisma + tsoa 的 AI 驱动全栈框架**运行时核心包**:预生成系统路由、Prisma 客户端工厂、认证/权限中间件、AI 工具注册表。
|
|
4
|
+
|
|
5
|
+
通常由脚手架 `create-koa-boot` 生成项目时自动引入,也可手动集成到现有 Koa 项目。
|
|
6
|
+
|
|
7
|
+
## 特性
|
|
8
|
+
|
|
9
|
+
- **预生成系统路由**:14 个系统模块(用户 / 角色 / 菜单 / 文件 / 消息 / 字典等)已编译为 CommonJS,开箱即用,无需 tsoa 扫描 node_modules
|
|
10
|
+
- **双文档分端点**:系统文档由 `registerRoutes` 挂载 `/api-docs/system`,业务文档由用户项目挂载 `/api-docs/business`
|
|
11
|
+
- **Prisma 客户端工厂**:统一创建客户端,开发环境自动启用 SQL 日志
|
|
12
|
+
- **认证与权限**:JWT + RBAC 角色权限(DB 表 `sys_permissions` 路径匹配),中间件即插即用
|
|
13
|
+
- **AI 工具注册表**:`aiToolRegistry` 供 AI 代理注册/发现工具
|
|
14
|
+
- **Schema 单一事实来源**:`templates/schema.system.prisma` 提供 15 个系统表定义,CLI 生成项目时合并业务片段
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install koa-boot-runtime
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import Koa from 'koa';
|
|
26
|
+
import Router from '@koa/router';
|
|
27
|
+
import { registerRoutes, createPrismaClient, middlewares } from 'koa-boot-runtime';
|
|
28
|
+
|
|
29
|
+
const app = new Koa();
|
|
30
|
+
const router = new Router();
|
|
31
|
+
|
|
32
|
+
// 挂载系统路由(含 /api-docs/system 文档端点)
|
|
33
|
+
registerRoutes(router);
|
|
34
|
+
|
|
35
|
+
app.use(middlewares.errorHandler);
|
|
36
|
+
app.use(middlewares.requestLogger);
|
|
37
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
38
|
+
|
|
39
|
+
// 全局共享 Prisma 客户端
|
|
40
|
+
app.context.db = createPrismaClient();
|
|
41
|
+
|
|
42
|
+
app.listen(3003);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Public API
|
|
46
|
+
|
|
47
|
+
包入口仅导出 6 个命名(其余内部模块不导出):
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { registerRoutes, createPrismaClient, systemServices, aiToolRegistry, middlewares, types } from 'koa-boot-runtime';
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| 导出 | 说明 |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `registerRoutes(router)` | 挂载系统路由(14 个系统模块)+ `/api-docs/system` 文档端点 |
|
|
56
|
+
| `createPrismaClient()` | Prisma 客户端工厂(开发环境启用 SQL 日志) |
|
|
57
|
+
| `systemServices` | 系统模块服务聚合(用户 / 角色 / 菜单 / 文件 / 消息 / 字典等) |
|
|
58
|
+
| `aiToolRegistry` | AI 工具注册表(`registerAiTool` / `listToolDefs` / `getAiTool`) |
|
|
59
|
+
| `middlewares` | `errorHandler` / `requestLogger` / `authMiddleware` / `permissionMiddleware` / `operationLogger` / `validateRequest` |
|
|
60
|
+
| `types` | 系统模块模型类型(命名空间式,业务侧以 `import type` 使用) |
|
|
61
|
+
|
|
62
|
+
另有白名单子路径可解:`koa-boot-runtime/common/*`、`koa-boot-runtime/utils/*`、`koa-boot-runtime/config/*`、`koa-boot-runtime/templates/*`(系统 Prisma schema 片段)。
|
|
63
|
+
|
|
64
|
+
## 环境要求
|
|
65
|
+
|
|
66
|
+
- Node.js >= 18.19
|
|
67
|
+
- MySQL 8.x(运行时数据)
|
|
68
|
+
- Redis(可选,缺失时自动降级)
|
|
69
|
+
|
|
70
|
+
## 相关
|
|
71
|
+
|
|
72
|
+
- 脚手架:`create-koa-boot`(`npx create-koa-boot` 交互式创建,或 `npx create-koa-boot my-app --example` 生成完整三端示例工程)
|
package/package.json
CHANGED