@dtdyq/restbase 1.0.1 → 2.1.0

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 CHANGED
@@ -21,17 +21,27 @@
21
21
  bun install -g @dtdyq/restbase
22
22
  ```
23
23
 
24
- 安装后直接在任意目录使用 `restbase` 命令:
24
+ 安装后在任意目录使用 `restbase` 命令。所有配置通过 `.env` 文件读取:
25
25
 
26
26
  ```bash
27
- # 默认 SQLite 内存模式启动
28
- restbase
27
+ # 交互式配置 .env(已存在则用当前值作为默认)
28
+ restbase env
29
29
 
30
- # 指定数据库和端口
31
- DB_URL=sqlite://./data.db SVR_PORT=8080 restbase
30
+ # 前台启动(读取当前目录 .env)
31
+ restbase run
32
32
 
33
- # 连接 MySQL
34
- DB_URL=mysql://user:pass@localhost/mydb restbase
33
+ # 后台启动(daemon 模式)
34
+ restbase start
35
+
36
+ # 查看运行中的实例(含健康状态)
37
+ restbase status
38
+
39
+ # 查看某个实例的实时日志(支持 PID 或 SVR_NAME)
40
+ restbase log <pid|name>
41
+
42
+ # 停止(支持 PID、SVR_NAME 或 all)
43
+ restbase stop <pid|name> # 停止指定实例
44
+ restbase stop all # 停止所有实例
35
45
  ```
36
46
 
37
47
  更新到最新版:
@@ -44,14 +54,15 @@ bun install -g @dtdyq/restbase@latest
44
54
 
45
55
  ```bash
46
56
  bun install
47
- bun run server.ts
57
+ bun run src/server.ts
48
58
  ```
49
59
 
50
60
  ### 验证
51
61
 
52
62
  ```bash
53
- # 健康检查
63
+ # 健康检查(返回实例状态 + 资源占用 + cwd + logFile)
54
64
  curl http://localhost:3333/api/health
65
+ # → { "code": "OK", "data": { "status": "healthy", "port": 3333, "pid": 12345, "cwd": "/path/to/dir", "uptime": 60, "memory": {...}, "cpu": {...} } }
55
66
 
56
67
  # Basic Auth 查询
57
68
  curl -u admin:admin http://localhost:3333/api/data/products
@@ -71,6 +82,10 @@ import RestBase, { gt } from "@dtdyq/restbase-client";
71
82
  const rb = new RestBase(); // 同源部署不传参
72
83
  await rb.auth.login("admin", "admin");
73
84
  const data = await rb.table("products").query().where(gt("price", 100)).data();
85
+
86
+ // 多节点负载均衡(所有节点连同一 DB)
87
+ const rb2 = new RestBase(["http://node1:3333", "http://node2:3333"]);
88
+ await rb2.auth.login("admin", "admin"); // 一次登录,token 共享
74
89
  ```
75
90
 
76
91
  详见 [client/README.md](client/README.md)。
@@ -78,12 +93,7 @@ const data = await rb.table("products").query().where(gt("price", 100)).data();
78
93
  ## 构建与部署
79
94
 
80
95
  ```bash
81
- bun run build # 当前平台
82
- bun run build:linux # Linux x64
83
- bun run build:linux-arm # Linux ARM64
84
- bun run build:mac # macOS x64
85
- bun run build:mac-arm # macOS ARM64
86
- bun run build:windows # Windows x64
96
+ bun run build # 编译为当前平台独立二进制
87
97
 
88
98
  # 运行二进制(无需 Bun 运行时)
89
99
  ./restbase
@@ -93,6 +103,7 @@ bun run build:windows # Windows x64
93
103
 
94
104
  | 变量 | 说明 | 默认值 |
95
105
  |:--------------------------|:---------------------------|:--------------------|
106
+ | `SVR_NAME` | 实例名称(`status` 中显示) | 空 |
96
107
  | `SVR_PORT` | 服务端口 | `3333` |
97
108
  | `SVR_STATIC` | 静态文件目录(前端托管) | 空 |
98
109
  | `SVR_API_LIMIT` | API 限流(每秒每接口请求数) | `100` |
@@ -112,7 +123,7 @@ bun run build:windows # Windows x64
112
123
  ## 测试
113
124
 
114
125
  ```bash
115
- bun test rest.test.ts # 137+ 用例
126
+ bun test src/rest.test.ts # 137+ 用例
116
127
  ```
117
128
 
118
129
  ## 文档
@@ -124,30 +135,52 @@ bun test rest.test.ts # 137+ 用例
124
135
  | [documents/db_design.md](documents/db_design.md) | 数据库设计指南 — 表结构规范、约束、索引、设计模式与检查清单 |
125
136
  | [documents/design.md](documents/design.md) | 需求与设计文档 — 架构设计、技术规格、完整接口定义 |
126
137
 
138
+ ## CLI 命令
139
+
140
+ ```
141
+ restbase <command> [arguments]
142
+
143
+ Commands:
144
+ run 前台启动服务(读取当前目录 .env)
145
+ start 后台启动(daemon 模式)
146
+ stop <pid|name|all> 停止后台实例(支持 PID、SVR_NAME 或 all)
147
+ status 查看运行中的实例(含健康检查)
148
+ log <pid|name> 实时查看实例日志(支持 PID 或 SVR_NAME)
149
+ env 交互式 .env 配置(创建或重新配置)
150
+ version 显示版本号
151
+ help 显示帮助
152
+ ```
153
+
154
+ 所有配置通过 `.env` 文件管理,可在 `.env` 中设置 `SVR_NAME` 为实例命名。
155
+
156
+ 实例管理完全无状态:通过 `ps` 自动发现运行中的实例,通过 `/api/health` 获取实例详情。
157
+ daemon 模式默认日志存放在 `~/.restbase/logs/`。
158
+
127
159
  ## 文件结构
128
160
 
129
161
  ```
130
162
  restbase/
131
163
  ├── bin/
132
- │ └── restbase.ts # 全局命令入口(bun install -g
133
- ├── server.ts # 服务入口
134
- ├── types.ts # 配置 + 类型 + Zod Schema
135
- ├── db.ts # 数据库
136
- ├── auth.ts # 鉴权
137
- ├── crud.ts # CRUD 路由
138
- ├── query.ts # SQL 生成
139
- ├── logger.ts # 日志
164
+ │ └── restbase.ts # CLI 入口(run/start/stop/status
165
+ ├── src/
166
+ ├── server.ts # 服务启动
167
+ ├── types.ts # 配置 + 类型 + Zod Schema
168
+ ├── db.ts # 数据库
169
+ ├── auth.ts # 鉴权
170
+ ├── crud.ts # CRUD 路由
171
+ ├── query.ts # SQL 生成
172
+ │ ├── logger.ts # 日志
173
+ │ └── rest.test.ts # 集成测试
140
174
  ├── client/
141
- │ ├── restbase-client.ts # 前端客户端(独立 npm 包 @dtdyq/restbase-client)
142
- │ ├── README.md # 客户端文档
175
+ │ ├── restbase-client.ts # 前端客户端(独立 npm 包 @dtdyq/restbase-client)
176
+ │ ├── README.md # 客户端文档
143
177
  │ └── package.json
144
178
  ├── documents/
145
- │ ├── design.md # 需求设计文档
146
- │ ├── server.md # 服务端文档
147
- │ └── db_design.md # 数据库设计指南
148
- ├── init.sql # 初始化 SQL
149
- ├── rest.test.ts # 集成测试
150
- ├── .env / .env.test # 环境配置
179
+ │ ├── design.md # 需求设计文档
180
+ │ ├── server.md # 服务端文档
181
+ │ └── db_design.md # 数据库设计指南
182
+ ├── init.sql # 初始化 SQL
183
+ ├── .env / .env.test # 环境配置
151
184
  └── package.json
152
185
  ```
153
186