Files
shrimp-server/examples/basic-admin
wc24 8e4d5620b7 feat!: 拆分 core / server 入口,peer deps 全部 optional
让只用 Shrimp 核心(RPC + 模块声明 + 内存 CRUD)的项目不必装
express / mongoose / bcrypt / jsonwebtoken,显著降低 install 时间。

- src/core.ts:0 重依赖入口(Shrimp / MemoryShrimpCrud / 类型)
- src/server.ts:在 core 之上再导出 ShrimpServer + MongoShrimpCrud
- package.json:加 exports 字段 + peerDependenciesMeta.optional
- Shrimp.ts:bcrypt 改 lazy import,只有走 Password 字段才触发
- MemoryShrimpCrud.populateItems:接 crudRegistry 参数(对齐 Mongo)
- ShrimpTableModule 构造时自动登记 crudRegistry,业务无需手动 wire
- 新增 test/crudRegistry.test.ts 验证自动登记 + relation 自动 populate

BREAKING: import { ShrimpServer } from 'shrimp-server' 不再可用,
请改为 'shrimp-server/server'。
2026-05-23 16:47:18 +08:00
..

basic-admin demo

零外部依赖的 Shrimp demo,只用内存 CRUD,不依赖 MongoDB。

证明:Shrimp 的核心(模块注册 / RPC dispatch / 字段配置)在没有 mongoose、没有 JWT、没有用户表的情况下也能跑。

起服务

从 demo 目录起(本地链 shrimp-server):

cd examples/basic-admin
npm install
npm start

或者从仓库根目录直接 npm run demo(由根 package.json 提供)。

服务起在 http://localhost:3100。

试一下

# 列商品
curl -s -X POST http://localhost:3100/api/product/list \
  -H 'content-type: application/json' -d '[{}]' | jq

# 列标签
curl -s -X POST http://localhost:3100/api/tag/list \
  -H 'content-type: application/json' -d '[{}]' | jq

# 新增商品
curl -s -X POST http://localhost:3100/api/product/add \
  -H 'content-type: application/json' \
  -d '[{"code":"P003","name":"橙子","price":4,"tagIds":[]}]' | jq

# 改某个商品
curl -s -X POST http://localhost:3100/api/product/edit \
  -H 'content-type: application/json' -d '["1",{"price":99}]' | jq

# 删除商品
curl -s -X POST http://localhost:3100/api/product/delete \
  -H 'content-type: application/json' -d '["1"]' | jq

请求体永远是参数数组,按位置传给事件 handler。

这个 demo 暴露了哪些 70→90 的问题

  • Shrimp.ts:322 的 if ((dataSource as any).model) 让 MemoryShrimpCrud 不能注册到 crudRegistry,relation populate 自动联表对内存数据源不生效
  • 没有现成的 RPC mount helper — 这段 app.post("/api/*splat", ...) 应该是框架提供的,而不是 demo 里手写
  • 要登录 / 鉴权要么自己写,要么用 ShrimpServer 强吃 Mongo+JWT,中间没有"我只想要 RPC + 模块,自己接 auth"这条路径