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'。
This commit is contained in:
@@ -61,16 +61,10 @@ const superAdmin: IShrimpOperator = {
|
||||
async function bootstrap() {
|
||||
const shrimp = new Shrimp()
|
||||
|
||||
// TODO(70→90): ShrimpTableModule 当前只在 dataSource.model 存在时自动登记 crudRegistry,
|
||||
// 这里需要手动 wire 让 MemoryShrimpCrud 的 populate 也能查到关联表
|
||||
const tagCrud = new MemoryShrimpCrud<WithId<ITag>>()
|
||||
tagCrud.getRelatedCrud = (k) => shrimp.crudRegistry.get(k)
|
||||
shrimp.crudRegistry.set("tag", tagCrud)
|
||||
new ShrimpTableModule(shrimp, "tag", tagCrud, tagFields, "标签管理").initCrud()
|
||||
|
||||
const productCrud = new MemoryShrimpCrud<WithId<IProduct>>()
|
||||
productCrud.getRelatedCrud = (k) => shrimp.crudRegistry.get(k)
|
||||
shrimp.crudRegistry.set("product", productCrud)
|
||||
new ShrimpTableModule(shrimp, "product", productCrud, productFields, "商品管理").initCrud()
|
||||
|
||||
// 种子数据
|
||||
|
||||
Reference in New Issue
Block a user