aury-boot 0.0.4__py3-none-any.whl → 0.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aury/boot/__init__.py +2 -2
- aury/boot/_version.py +2 -2
- aury/boot/application/__init__.py +60 -36
- aury/boot/application/adapter/__init__.py +112 -0
- aury/boot/application/adapter/base.py +511 -0
- aury/boot/application/adapter/config.py +242 -0
- aury/boot/application/adapter/decorators.py +259 -0
- aury/boot/application/adapter/exceptions.py +202 -0
- aury/boot/application/adapter/http.py +325 -0
- aury/boot/application/app/__init__.py +12 -8
- aury/boot/application/app/base.py +12 -0
- aury/boot/application/app/components.py +137 -44
- aury/boot/application/app/middlewares.py +9 -4
- aury/boot/application/app/startup.py +249 -0
- aury/boot/application/config/__init__.py +36 -1
- aury/boot/application/config/multi_instance.py +216 -0
- aury/boot/application/config/settings.py +398 -149
- aury/boot/application/constants/components.py +6 -0
- aury/boot/application/errors/handlers.py +17 -3
- aury/boot/application/middleware/logging.py +21 -120
- aury/boot/application/rpc/__init__.py +2 -2
- aury/boot/commands/__init__.py +30 -10
- aury/boot/commands/app.py +131 -1
- aury/boot/commands/docs.py +104 -17
- aury/boot/commands/generate.py +22 -22
- aury/boot/commands/init.py +68 -17
- aury/boot/commands/server/app.py +2 -3
- aury/boot/commands/templates/project/AGENTS.md.tpl +221 -0
- aury/boot/commands/templates/project/README.md.tpl +2 -2
- aury/boot/commands/templates/project/aury_docs/00-overview.md.tpl +59 -0
- aury/boot/commands/templates/project/aury_docs/01-model.md.tpl +184 -0
- aury/boot/commands/templates/project/aury_docs/02-repository.md.tpl +206 -0
- aury/boot/commands/templates/project/aury_docs/03-service.md.tpl +398 -0
- aury/boot/commands/templates/project/aury_docs/04-schema.md.tpl +95 -0
- aury/boot/commands/templates/project/aury_docs/05-api.md.tpl +116 -0
- aury/boot/commands/templates/project/aury_docs/06-exception.md.tpl +118 -0
- aury/boot/commands/templates/project/aury_docs/07-cache.md.tpl +122 -0
- aury/boot/commands/templates/project/aury_docs/08-scheduler.md.tpl +32 -0
- aury/boot/commands/templates/project/aury_docs/09-tasks.md.tpl +38 -0
- aury/boot/commands/templates/project/aury_docs/10-storage.md.tpl +115 -0
- aury/boot/commands/templates/project/aury_docs/11-logging.md.tpl +131 -0
- aury/boot/commands/templates/project/aury_docs/12-admin.md.tpl +56 -0
- aury/boot/commands/templates/project/aury_docs/13-channel.md.tpl +104 -0
- aury/boot/commands/templates/project/aury_docs/14-mq.md.tpl +102 -0
- aury/boot/commands/templates/project/aury_docs/15-events.md.tpl +147 -0
- aury/boot/commands/templates/project/aury_docs/16-adapter.md.tpl +403 -0
- aury/boot/commands/templates/project/{CLI.md.tpl → aury_docs/99-cli.md.tpl} +19 -19
- aury/boot/commands/templates/project/config.py.tpl +10 -10
- aury/boot/commands/templates/project/env_templates/_header.tpl +10 -0
- aury/boot/commands/templates/project/env_templates/admin.tpl +49 -0
- aury/boot/commands/templates/project/env_templates/cache.tpl +14 -0
- aury/boot/commands/templates/project/env_templates/database.tpl +22 -0
- aury/boot/commands/templates/project/env_templates/log.tpl +18 -0
- aury/boot/commands/templates/project/env_templates/messaging.tpl +46 -0
- aury/boot/commands/templates/project/env_templates/rpc.tpl +28 -0
- aury/boot/commands/templates/project/env_templates/scheduler.tpl +18 -0
- aury/boot/commands/templates/project/env_templates/service.tpl +18 -0
- aury/boot/commands/templates/project/env_templates/storage.tpl +38 -0
- aury/boot/commands/templates/project/env_templates/third_party.tpl +43 -0
- aury/boot/commands/templates/project/modules/tasks.py.tpl +1 -1
- aury/boot/common/logging/__init__.py +26 -674
- aury/boot/common/logging/context.py +132 -0
- aury/boot/common/logging/decorators.py +118 -0
- aury/boot/common/logging/format.py +315 -0
- aury/boot/common/logging/setup.py +214 -0
- aury/boot/contrib/admin_console/auth.py +2 -3
- aury/boot/contrib/admin_console/install.py +1 -1
- aury/boot/domain/models/mixins.py +48 -1
- aury/boot/domain/pagination/__init__.py +94 -0
- aury/boot/domain/repository/impl.py +1 -1
- aury/boot/domain/repository/interface.py +1 -1
- aury/boot/domain/transaction/__init__.py +8 -9
- aury/boot/infrastructure/__init__.py +86 -29
- aury/boot/infrastructure/cache/backends.py +102 -18
- aury/boot/infrastructure/cache/base.py +12 -0
- aury/boot/infrastructure/cache/manager.py +153 -91
- aury/boot/infrastructure/channel/__init__.py +24 -0
- aury/boot/infrastructure/channel/backends/__init__.py +9 -0
- aury/boot/infrastructure/channel/backends/memory.py +83 -0
- aury/boot/infrastructure/channel/backends/redis.py +88 -0
- aury/boot/infrastructure/channel/base.py +92 -0
- aury/boot/infrastructure/channel/manager.py +203 -0
- aury/boot/infrastructure/clients/__init__.py +22 -0
- aury/boot/infrastructure/clients/rabbitmq/__init__.py +9 -0
- aury/boot/infrastructure/clients/rabbitmq/config.py +46 -0
- aury/boot/infrastructure/clients/rabbitmq/manager.py +288 -0
- aury/boot/infrastructure/clients/redis/__init__.py +28 -0
- aury/boot/infrastructure/clients/redis/config.py +51 -0
- aury/boot/infrastructure/clients/redis/manager.py +264 -0
- aury/boot/infrastructure/database/config.py +7 -16
- aury/boot/infrastructure/database/manager.py +16 -38
- aury/boot/infrastructure/events/__init__.py +18 -21
- aury/boot/infrastructure/events/backends/__init__.py +11 -0
- aury/boot/infrastructure/events/backends/memory.py +86 -0
- aury/boot/infrastructure/events/backends/rabbitmq.py +193 -0
- aury/boot/infrastructure/events/backends/redis.py +162 -0
- aury/boot/infrastructure/events/base.py +127 -0
- aury/boot/infrastructure/events/manager.py +224 -0
- aury/boot/infrastructure/mq/__init__.py +24 -0
- aury/boot/infrastructure/mq/backends/__init__.py +9 -0
- aury/boot/infrastructure/mq/backends/rabbitmq.py +179 -0
- aury/boot/infrastructure/mq/backends/redis.py +167 -0
- aury/boot/infrastructure/mq/base.py +143 -0
- aury/boot/infrastructure/mq/manager.py +239 -0
- aury/boot/infrastructure/scheduler/manager.py +7 -3
- aury/boot/infrastructure/storage/__init__.py +9 -9
- aury/boot/infrastructure/storage/base.py +17 -5
- aury/boot/infrastructure/storage/factory.py +0 -1
- aury/boot/infrastructure/tasks/__init__.py +2 -2
- aury/boot/infrastructure/tasks/config.py +5 -13
- aury/boot/infrastructure/tasks/manager.py +55 -33
- {aury_boot-0.0.4.dist-info → aury_boot-0.0.7.dist-info}/METADATA +20 -2
- aury_boot-0.0.7.dist-info/RECORD +197 -0
- aury/boot/commands/templates/project/DEVELOPMENT.md.tpl +0 -1397
- aury/boot/commands/templates/project/env.example.tpl +0 -213
- aury/boot/infrastructure/events/bus.py +0 -362
- aury/boot/infrastructure/events/config.py +0 -52
- aury/boot/infrastructure/events/consumer.py +0 -134
- aury/boot/infrastructure/events/models.py +0 -63
- aury_boot-0.0.4.dist-info/RECORD +0 -137
- {aury_boot-0.0.4.dist-info → aury_boot-0.0.7.dist-info}/WHEEL +0 -0
- {aury_boot-0.0.4.dist-info → aury_boot-0.0.7.dist-info}/entry_points.txt +0 -0
aury/boot/__init__.py
CHANGED
|
@@ -52,7 +52,7 @@ def __getattr__(name: str):
|
|
|
52
52
|
|
|
53
53
|
def __dir__():
|
|
54
54
|
"""返回可用属性列表。"""
|
|
55
|
-
return list(_SUBMODULES)
|
|
55
|
+
return [*list(_SUBMODULES), "__version__"]
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
__all__ = [
|
|
@@ -61,6 +61,6 @@ __all__ = [
|
|
|
61
61
|
"common",
|
|
62
62
|
"domain",
|
|
63
63
|
"infrastructure",
|
|
64
|
-
"toolkit",
|
|
65
64
|
"testing",
|
|
65
|
+
"toolkit",
|
|
66
66
|
]
|
aury/boot/_version.py
CHANGED
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.0.
|
|
32
|
-
__version_tuple__ = version_tuple = (0, 0,
|
|
31
|
+
__version__ = version = '0.0.7'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 0, 7)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
# 事件系统(从 infrastructure 导入 - Event 定义在最底层)
|
|
7
7
|
# 事务管理(从 domain 导入)
|
|
8
|
+
# 第三方适配器
|
|
9
|
+
from aury.boot.application.adapter import (
|
|
10
|
+
AdapterError,
|
|
11
|
+
AdapterSettings,
|
|
12
|
+
BaseAdapter,
|
|
13
|
+
HttpAdapter,
|
|
14
|
+
adapter_method,
|
|
15
|
+
)
|
|
8
16
|
from aury.boot.domain.transaction import (
|
|
9
17
|
TransactionManager,
|
|
10
18
|
TransactionRequiredError,
|
|
@@ -17,10 +25,15 @@ from aury.boot.domain.transaction import (
|
|
|
17
25
|
from aury.boot.infrastructure.di import Container, Lifetime, Scope, ServiceDescriptor
|
|
18
26
|
from aury.boot.infrastructure.events import (
|
|
19
27
|
Event,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
EventBackend,
|
|
29
|
+
EventBusManager,
|
|
30
|
+
EventHandler,
|
|
31
|
+
EventType,
|
|
32
|
+
IEventBus,
|
|
33
|
+
# 后端实现
|
|
34
|
+
MemoryEventBus,
|
|
35
|
+
RabbitMQEventBus,
|
|
36
|
+
RedisEventBus,
|
|
24
37
|
)
|
|
25
38
|
|
|
26
39
|
from . import interfaces, rpc
|
|
@@ -62,59 +75,70 @@ from .scheduler import run_scheduler, run_scheduler_sync
|
|
|
62
75
|
from .server import ApplicationServer, run_app
|
|
63
76
|
|
|
64
77
|
__all__ = [
|
|
78
|
+
# 第三方适配器
|
|
79
|
+
"AdapterError",
|
|
80
|
+
"AdapterSettings",
|
|
81
|
+
# 服务器集成
|
|
82
|
+
"ApplicationServer",
|
|
83
|
+
"BaseAdapter",
|
|
65
84
|
# 配置
|
|
66
85
|
"BaseConfig",
|
|
86
|
+
# 中间件
|
|
87
|
+
"CORSMiddleware",
|
|
67
88
|
"CORSSettings",
|
|
89
|
+
# 组件
|
|
90
|
+
"CacheComponent",
|
|
68
91
|
"CacheSettings",
|
|
69
|
-
|
|
70
|
-
"
|
|
92
|
+
# 基类
|
|
93
|
+
"Component",
|
|
71
94
|
# 常量
|
|
72
95
|
"ComponentName",
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
96
|
+
# 依赖注入容器
|
|
97
|
+
"Container",
|
|
98
|
+
"DatabaseComponent",
|
|
99
|
+
# 事件系统
|
|
100
|
+
"Event",
|
|
101
|
+
"EventBackend",
|
|
102
|
+
"EventBusManager",
|
|
103
|
+
"EventHandler",
|
|
104
|
+
"EventType",
|
|
76
105
|
# 应用框架
|
|
77
106
|
"FoundationApp",
|
|
78
|
-
|
|
79
|
-
"
|
|
107
|
+
"HttpAdapter",
|
|
108
|
+
"IEventBus",
|
|
109
|
+
"Lifetime",
|
|
110
|
+
"LogSettings",
|
|
111
|
+
"MemoryEventBus",
|
|
80
112
|
"Middleware",
|
|
81
|
-
|
|
82
|
-
"CORSMiddleware",
|
|
83
|
-
"RequestLoggingMiddleware",
|
|
84
|
-
# 组件
|
|
85
|
-
"CacheComponent",
|
|
86
|
-
"DatabaseComponent",
|
|
113
|
+
"MiddlewareName",
|
|
87
114
|
"MigrationComponent",
|
|
115
|
+
# 迁移
|
|
116
|
+
"MigrationManager",
|
|
117
|
+
"RabbitMQEventBus",
|
|
118
|
+
"RedisEventBus",
|
|
119
|
+
"RequestLoggingMiddleware",
|
|
88
120
|
"SchedulerComponent",
|
|
89
|
-
"
|
|
90
|
-
# 依赖注入容器
|
|
91
|
-
"Container",
|
|
92
|
-
"Lifetime",
|
|
121
|
+
"SchedulerMode",
|
|
93
122
|
"Scope",
|
|
123
|
+
"ServerSettings",
|
|
94
124
|
"ServiceDescriptor",
|
|
95
|
-
|
|
96
|
-
"
|
|
97
|
-
"EventBus",
|
|
98
|
-
"EventConsumer",
|
|
99
|
-
"EventLoggingMiddleware",
|
|
100
|
-
"EventMiddleware",
|
|
101
|
-
# 迁移
|
|
102
|
-
"MigrationManager",
|
|
103
|
-
# HTTP 中间件装饰器
|
|
104
|
-
"log_request",
|
|
125
|
+
"ServiceType",
|
|
126
|
+
"TaskComponent",
|
|
105
127
|
# 事务管理
|
|
106
128
|
"TransactionManager",
|
|
107
129
|
"TransactionRequiredError",
|
|
130
|
+
# 第三方适配器装饰器
|
|
131
|
+
"adapter_method",
|
|
108
132
|
"ensure_transaction",
|
|
109
|
-
|
|
110
|
-
"
|
|
133
|
+
# HTTP 中间件装饰器
|
|
134
|
+
"log_request",
|
|
111
135
|
# RPC通信
|
|
112
136
|
"rpc",
|
|
137
|
+
"run_app",
|
|
113
138
|
# 调度器启动器
|
|
114
139
|
"run_scheduler",
|
|
115
140
|
"run_scheduler_sync",
|
|
116
|
-
|
|
117
|
-
"
|
|
118
|
-
"run_app",
|
|
141
|
+
"transactional",
|
|
142
|
+
"transactional_context",
|
|
119
143
|
]
|
|
120
144
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""第三方接口适配器模块。
|
|
2
|
+
|
|
3
|
+
本模块用于封装第三方接口(如支付、短信、微信、云存储等外部服务)的调用,
|
|
4
|
+
解决测试环境中第三方接口不可用的问题,通过配置切换真实调用与挡板(Mock)实现。
|
|
5
|
+
|
|
6
|
+
核心特性:
|
|
7
|
+
- 多模式切换:real(真实)/sandbox(沙箱)/mock(挡板)/disabled(禁用)
|
|
8
|
+
- 按方法级别的模式覆盖:同一 Adapter 不同方法可用不同模式
|
|
9
|
+
- 装饰器声明式定义:@adapter_method + .mock 链式定义挡板逻辑
|
|
10
|
+
- HTTP 类第三方的便捷基类:HttpAdapter 封装请求/认证/错误处理
|
|
11
|
+
- 调用历史记录:便于测试断言,验证调用参数和结果
|
|
12
|
+
|
|
13
|
+
模式说明:
|
|
14
|
+
- real: 调用真实第三方接口(生产环境)
|
|
15
|
+
- sandbox: 调用第三方提供的沙箱环境(如果有)
|
|
16
|
+
- mock: 使用本地挡板实现,不发出真实请求(测试/开发环境)
|
|
17
|
+
- disabled: 禁用该接口,调用时抛出 AdapterDisabledError
|
|
18
|
+
|
|
19
|
+
设计原则:
|
|
20
|
+
- 最小约束:只约束"模式怎么切换",不限制具体调用方式
|
|
21
|
+
- 最大自由:HTTP/SDK/gRPC/任意协议都能用
|
|
22
|
+
- 可组合:Adapter 可以组合其他 Adapter
|
|
23
|
+
|
|
24
|
+
典型使用场景:
|
|
25
|
+
1. 测试环境:第三方接口不可用,使用 mock 模式运行测试
|
|
26
|
+
2. 开发环境:避免消耗真实资源(如短信费用),使用 mock
|
|
27
|
+
3. 部分挡板:查询接口走真实,写入接口走 mock
|
|
28
|
+
4. 功能开关:禁用某些危险操作(如退款)在测试环境
|
|
29
|
+
|
|
30
|
+
使用示例:
|
|
31
|
+
from aury.boot.application.adapter import (
|
|
32
|
+
HttpAdapter, adapter_method, AdapterSettings
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
class PaymentAdapter(HttpAdapter):
|
|
36
|
+
'''支付第三方接口适配器。'''
|
|
37
|
+
|
|
38
|
+
@adapter_method("create")
|
|
39
|
+
async def create_order(self, amount: int, order_id: str) -> dict:
|
|
40
|
+
'''创建支付订单(真实实现)。'''
|
|
41
|
+
return await self._request("POST", "/charge", json={"amount": amount, "order_id": order_id})
|
|
42
|
+
|
|
43
|
+
@create_order.mock
|
|
44
|
+
async def create_order_mock(self, amount: int, order_id: str) -> dict:
|
|
45
|
+
'''创建支付订单(挡板实现)。
|
|
46
|
+
|
|
47
|
+
挡板可以包含业务逻辑,模拟各种场景(成功、失败、边界情况)。
|
|
48
|
+
'''
|
|
49
|
+
if amount > 10000:
|
|
50
|
+
return {"success": False, "error": "金额超限"}
|
|
51
|
+
return {"success": True, "mock": True, "order_id": order_id}
|
|
52
|
+
|
|
53
|
+
# 配置:测试环境使用挡板,但 query 走真实接口
|
|
54
|
+
settings = AdapterSettings(
|
|
55
|
+
mode="mock", # 默认走挡板
|
|
56
|
+
method_modes={"query": "real"}, # query 走真实
|
|
57
|
+
base_url="https://api.payment.com",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
adapter = PaymentAdapter("payment", settings)
|
|
61
|
+
result = await adapter.create_order(100, "order-1") # 走挡板
|
|
62
|
+
|
|
63
|
+
环境变量配置:
|
|
64
|
+
# 全局模式
|
|
65
|
+
THIRD_PARTY_PAYMENT_MODE=mock
|
|
66
|
+
|
|
67
|
+
# 连接配置
|
|
68
|
+
THIRD_PARTY_PAYMENT_BASE_URL=https://api.payment.com
|
|
69
|
+
THIRD_PARTY_PAYMENT_SANDBOX_URL=https://sandbox.payment.com
|
|
70
|
+
THIRD_PARTY_PAYMENT_API_KEY=sk_test_xxx
|
|
71
|
+
THIRD_PARTY_PAYMENT_TIMEOUT=30
|
|
72
|
+
|
|
73
|
+
# 方法级模式覆盖(JSON 格式)
|
|
74
|
+
THIRD_PARTY_PAYMENT_METHOD_MODES={"query": "real", "refund": "disabled"}
|
|
75
|
+
|
|
76
|
+
# 挡板配置
|
|
77
|
+
THIRD_PARTY_PAYMENT_MOCK_DELAY=0.1 # 模拟网络延迟
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
from .base import BaseAdapter, CallRecord
|
|
81
|
+
from .config import (
|
|
82
|
+
AdapterMode,
|
|
83
|
+
AdapterSettings,
|
|
84
|
+
MockStrategy,
|
|
85
|
+
ThirdPartySettings,
|
|
86
|
+
)
|
|
87
|
+
from .decorators import adapter_method
|
|
88
|
+
from .exceptions import (
|
|
89
|
+
AdapterDisabledError,
|
|
90
|
+
AdapterError,
|
|
91
|
+
AdapterTimeoutError,
|
|
92
|
+
)
|
|
93
|
+
from .http import HttpAdapter
|
|
94
|
+
|
|
95
|
+
__all__ = [
|
|
96
|
+
# 基类
|
|
97
|
+
"BaseAdapter",
|
|
98
|
+
"HttpAdapter",
|
|
99
|
+
# 配置
|
|
100
|
+
"AdapterSettings",
|
|
101
|
+
"AdapterMode",
|
|
102
|
+
"MockStrategy",
|
|
103
|
+
"ThirdPartySettings",
|
|
104
|
+
# 装饰器
|
|
105
|
+
"adapter_method",
|
|
106
|
+
# 异常
|
|
107
|
+
"AdapterError",
|
|
108
|
+
"AdapterDisabledError",
|
|
109
|
+
"AdapterTimeoutError",
|
|
110
|
+
# 数据类
|
|
111
|
+
"CallRecord",
|
|
112
|
+
]
|