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:
2026-05-23 16:47:18 +08:00
parent 40f311796b
commit 8e4d5620b7
11 changed files with 207 additions and 99 deletions
+7 -75
View File
@@ -1,78 +1,10 @@
/**
* Shrimp Server — 公共 API
* 默认入口 = 核心 (0 重依赖)
*
* 内部实现细节(如 ShrimpEvent)未在此处导出,业务请只依赖本文件再导出的符号。
* - import ... from 'shrimp-server' => 这个文件 / src/core.ts(纯框架,无 peer)
* - import ... from 'shrimp-server/server' => src/server.ts(再带 ShrimpServer + Mongo)
*
* 该文件存在的意义是兼容不识别 `package.json#exports` 的旧工具链(npm < 7、
* 部分 bundler 的 legacy resolve),让 `main: src/index.ts` 也能正常工作。
*/
// ===== 类型 / 接口 / 枚举 =====
export {
ShrimpCode,
ShrimpError,
ShrimpFieldTypes,
ShrimpConfig,
isShrimpCondition,
} from "./IShrimpType"
export type {
ILabel,
IShrimpResponse,
IModuleInfo,
ILoginResult,
IMeResult,
IMenuItem,
ITableProto,
ITableCrudProto,
IUser,
IRole,
IOperationLog,
WithId,
IShrimpOperator,
IShrimpPowerData,
ShrimpRequestFn,
IShrimpClient,
ShrimpFieldType,
FieldEditable,
IFieldTypeHandler,
IFieldConfig,
IFieldRule,
IPageQuery,
IPageResult,
IShrimpCondition,
IShrimpPopulate,
IShrimpQuery,
IPowerItem,
IUserProto,
IRoleProto,
} from "./IShrimpType"
// ===== 框架核心 =====
export {
Shrimp,
ShrimpModule,
ShrimpTableModule,
ShrimpPower,
RootShrimpPower,
UserModule,
RoleModule,
defaultTypeHandlers,
} from "./Shrimp"
export type {
IShrimpModuleOptions,
ShrimpCrud,
} from "./Shrimp"
// ===== 服务端实现(Express + Mongoose + JWT) =====
export {
ShrimpServer,
UserSchema,
RoleSchema,
OperationLogSchema,
} from "./ShrimpServer"
// ===== 数据源 =====
export { MongoShrimpCrud } from "./MongoShrimpCrud"
export { MemoryShrimpCrud } from "./MemoryShrimpCrud"
// ===== 可选模块 =====
export { OperationLogModule } from "./OperationLogModule"
export * from "./core"