本次提交包含多项代码优化与规范修正: 1. 文档与注释优化:修正注释术语、补充注解与FR编号 2. 代码格式调整:统一空格、换行与缩进规范 3. 类型与接口完善:补充__all__导出、修正返回类型注解 4. 错误处理增强:新增领域错误类与校验逻辑 5. 依赖与导入调整:修复路径引用、统一时区导入 6. 协议与契约更新:完善接口文档与一致性注解
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""IdentityResolverAdapter:实现 IdentityResolverPort,默认降级实现。
|
||
|
||
- 默认降级实现,由插件可覆盖
|
||
- resolve 返回 None(触发降级至 DB 查询)
|
||
- getConfidence 返回 0.0
|
||
|
||
依赖边界:只依赖 yuxi.channels.contract(端口 + DTO)。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from yuxi.channels.contract.dtos.identity import (
|
||
IdentityResolveCmd,
|
||
IdentityResolveResult,
|
||
)
|
||
from yuxi.channels.contract.ports.driven.identity_resolver_port import IdentityResolverPort
|
||
|
||
__all__ = ["IdentityResolverAdapter"]
|
||
|
||
|
||
class IdentityResolverAdapter(IdentityResolverPort):
|
||
"""身份解析被驱动适配器(默认降级实现)。
|
||
|
||
默认实现不接入外部身份源,``resolve`` 返回 ``None`` 触发降级至 DB
|
||
查询,``getConfidence`` 返回 ``0.0``。实际身份解析逻辑由插件注册时
|
||
注入。
|
||
"""
|
||
|
||
async def resolve(self, cmd: IdentityResolveCmd) -> IdentityResolveResult | None:
|
||
"""解析身份(默认降级,返回 None)。
|
||
|
||
默认不接入外部身份源,返回 None 触发降级至 DB 查询。
|
||
实际解析逻辑由插件覆盖。
|
||
|
||
Args:
|
||
cmd: 身份解析命令,携带渠道类型、对端 ID 与账户 ID。
|
||
|
||
Returns:
|
||
None(默认降级)。
|
||
"""
|
||
return None
|
||
|
||
async def getConfidence(self, identity_id: str) -> float:
|
||
"""查询身份置信度(默认降级,返回 0.0)。
|
||
|
||
默认返回 ``0.0``,实际置信度由插件覆盖。
|
||
|
||
Args:
|
||
identity_id: 统一身份 ID。
|
||
|
||
Returns:
|
||
0.0(默认降级)。
|
||
"""
|
||
return 0.0
|