SuperAPI AI 工具集

forze-domain-aggregates

办公与效率

查看项目

更新于 10-16 01:19

技能介绍

用途:在 Forze 框架中定义领域模型与文档聚合、命令、只读投影,以及内核级 DocumentSpec/SearchSpec。物理表、集合、Redis 命名空间、桶和队列属于集成配置,应放在 forze-specs-infrastructure 与 specs-and-wiring 文档中,不写入规格。

主要能力:每个文档聚合通常定义四类模型——领域模型 Document、创建命令 CreateDocumentCmd、更新命令 BaseDTO、只读模型 ReadDocument。Document 基础字段有 id、rev、created_at、last_update_at,ReadDocument 携带相同核心字段。可用 mixin:SoftDeletionMixin 加 is_deleted、NumberMixin 加 number_id、CreatorMixin 加 creator_id、NameMixin 加 name/display_name。用 update_validator 装饰器在 Document.update() 期间对字段执行校验。

规格:DocumentSpec 绑定模型类型与逻辑名,字段含 name、read、write(domain、create_cmd、可选 update_cmd)、history_enabled、cache,并可用 supports_soft_delete()/supports_update()/supports_number_id() 分支。SearchSpec 单独定义 name、model_type、fields、default_weights。数据库列名需与 Pydantic 字段名一致,核心列 id、rev、created_at、last_update_at。使用 build_document_registry 和 FastAPI 路由时用 DocumentDTOs 组合。

用法与限制:DepsPlan 注册文档适配器后,用例通过 ctx.doc_query(project_spec) / ctx.doc_command(project_spec) 获取 DocumentQueryPort / DocumentCommandPort。避免反模式:领域层不要导入端口或适配器;更新命令用可选字段和 None 默认值做局部修改;ReadDocument 冻结,不要用可变默认值;物理源名不放在 DocumentSpec;spec 名集中到共享 StrEnum。详细内容见 aggregate-specification.md 与 specs-and-wiring.md。