aury-boot 0.0.2__py3-none-any.whl → 0.0.4__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 +66 -0
- aury/boot/_version.py +2 -2
- aury/boot/application/__init__.py +120 -0
- aury/boot/application/app/__init__.py +39 -0
- aury/boot/application/app/base.py +511 -0
- aury/boot/application/app/components.py +434 -0
- aury/boot/application/app/middlewares.py +101 -0
- aury/boot/application/config/__init__.py +44 -0
- aury/boot/application/config/settings.py +663 -0
- aury/boot/application/constants/__init__.py +19 -0
- aury/boot/application/constants/components.py +50 -0
- aury/boot/application/constants/scheduler.py +28 -0
- aury/boot/application/constants/service.py +29 -0
- aury/boot/application/errors/__init__.py +55 -0
- aury/boot/application/errors/chain.py +80 -0
- aury/boot/application/errors/codes.py +67 -0
- aury/boot/application/errors/exceptions.py +238 -0
- aury/boot/application/errors/handlers.py +320 -0
- aury/boot/application/errors/response.py +120 -0
- aury/boot/application/interfaces/__init__.py +76 -0
- aury/boot/application/interfaces/egress.py +224 -0
- aury/boot/application/interfaces/ingress.py +98 -0
- aury/boot/application/middleware/__init__.py +22 -0
- aury/boot/application/middleware/logging.py +451 -0
- aury/boot/application/migrations/__init__.py +13 -0
- aury/boot/application/migrations/manager.py +685 -0
- aury/boot/application/migrations/setup.py +237 -0
- aury/boot/application/rpc/__init__.py +63 -0
- aury/boot/application/rpc/base.py +108 -0
- aury/boot/application/rpc/client.py +294 -0
- aury/boot/application/rpc/discovery.py +218 -0
- aury/boot/application/scheduler/__init__.py +13 -0
- aury/boot/application/scheduler/runner.py +123 -0
- aury/boot/application/server/__init__.py +296 -0
- aury/boot/commands/__init__.py +30 -0
- aury/boot/commands/add.py +76 -0
- aury/boot/commands/app.py +105 -0
- aury/boot/commands/config.py +177 -0
- aury/boot/commands/docker.py +367 -0
- aury/boot/commands/docs.py +284 -0
- aury/boot/commands/generate.py +1277 -0
- aury/boot/commands/init.py +892 -0
- aury/boot/commands/migrate/__init__.py +37 -0
- aury/boot/commands/migrate/app.py +54 -0
- aury/boot/commands/migrate/commands.py +303 -0
- aury/boot/commands/scheduler.py +124 -0
- aury/boot/commands/server/__init__.py +21 -0
- aury/boot/commands/server/app.py +541 -0
- aury/boot/commands/templates/generate/api.py.tpl +105 -0
- aury/boot/commands/templates/generate/model.py.tpl +17 -0
- aury/boot/commands/templates/generate/repository.py.tpl +19 -0
- aury/boot/commands/templates/generate/schema.py.tpl +29 -0
- aury/boot/commands/templates/generate/service.py.tpl +48 -0
- aury/boot/commands/templates/project/CLI.md.tpl +92 -0
- aury/boot/commands/templates/project/DEVELOPMENT.md.tpl +1397 -0
- aury/boot/commands/templates/project/README.md.tpl +111 -0
- aury/boot/commands/templates/project/admin_console_init.py.tpl +50 -0
- aury/boot/commands/templates/project/config.py.tpl +30 -0
- aury/boot/commands/templates/project/conftest.py.tpl +26 -0
- aury/boot/commands/templates/project/env.example.tpl +213 -0
- aury/boot/commands/templates/project/gitignore.tpl +128 -0
- aury/boot/commands/templates/project/main.py.tpl +41 -0
- aury/boot/commands/templates/project/modules/api.py.tpl +19 -0
- aury/boot/commands/templates/project/modules/exceptions.py.tpl +84 -0
- aury/boot/commands/templates/project/modules/schedules.py.tpl +18 -0
- aury/boot/commands/templates/project/modules/tasks.py.tpl +20 -0
- aury/boot/commands/worker.py +143 -0
- aury/boot/common/__init__.py +35 -0
- aury/boot/common/exceptions/__init__.py +114 -0
- aury/boot/common/i18n/__init__.py +16 -0
- aury/boot/common/i18n/translator.py +272 -0
- aury/boot/common/logging/__init__.py +716 -0
- aury/boot/contrib/__init__.py +10 -0
- aury/boot/contrib/admin_console/__init__.py +18 -0
- aury/boot/contrib/admin_console/auth.py +137 -0
- aury/boot/contrib/admin_console/discovery.py +69 -0
- aury/boot/contrib/admin_console/install.py +172 -0
- aury/boot/contrib/admin_console/utils.py +44 -0
- aury/boot/domain/__init__.py +79 -0
- aury/boot/domain/exceptions/__init__.py +132 -0
- aury/boot/domain/models/__init__.py +51 -0
- aury/boot/domain/models/base.py +69 -0
- aury/boot/domain/models/mixins.py +135 -0
- aury/boot/domain/models/models.py +96 -0
- aury/boot/domain/pagination/__init__.py +279 -0
- aury/boot/domain/repository/__init__.py +23 -0
- aury/boot/domain/repository/impl.py +423 -0
- aury/boot/domain/repository/interceptors.py +47 -0
- aury/boot/domain/repository/interface.py +106 -0
- aury/boot/domain/repository/query_builder.py +348 -0
- aury/boot/domain/service/__init__.py +11 -0
- aury/boot/domain/service/base.py +73 -0
- aury/boot/domain/transaction/__init__.py +404 -0
- aury/boot/infrastructure/__init__.py +104 -0
- aury/boot/infrastructure/cache/__init__.py +31 -0
- aury/boot/infrastructure/cache/backends.py +348 -0
- aury/boot/infrastructure/cache/base.py +68 -0
- aury/boot/infrastructure/cache/exceptions.py +37 -0
- aury/boot/infrastructure/cache/factory.py +94 -0
- aury/boot/infrastructure/cache/manager.py +274 -0
- aury/boot/infrastructure/database/__init__.py +39 -0
- aury/boot/infrastructure/database/config.py +71 -0
- aury/boot/infrastructure/database/exceptions.py +44 -0
- aury/boot/infrastructure/database/manager.py +317 -0
- aury/boot/infrastructure/database/query_tools/__init__.py +164 -0
- aury/boot/infrastructure/database/strategies/__init__.py +198 -0
- aury/boot/infrastructure/di/__init__.py +15 -0
- aury/boot/infrastructure/di/container.py +393 -0
- aury/boot/infrastructure/events/__init__.py +33 -0
- aury/boot/infrastructure/events/bus.py +362 -0
- aury/boot/infrastructure/events/config.py +52 -0
- aury/boot/infrastructure/events/consumer.py +134 -0
- aury/boot/infrastructure/events/middleware.py +51 -0
- aury/boot/infrastructure/events/models.py +63 -0
- aury/boot/infrastructure/monitoring/__init__.py +529 -0
- aury/boot/infrastructure/scheduler/__init__.py +19 -0
- aury/boot/infrastructure/scheduler/exceptions.py +37 -0
- aury/boot/infrastructure/scheduler/manager.py +478 -0
- aury/boot/infrastructure/storage/__init__.py +38 -0
- aury/boot/infrastructure/storage/base.py +164 -0
- aury/boot/infrastructure/storage/exceptions.py +37 -0
- aury/boot/infrastructure/storage/factory.py +88 -0
- aury/boot/infrastructure/tasks/__init__.py +24 -0
- aury/boot/infrastructure/tasks/config.py +45 -0
- aury/boot/infrastructure/tasks/constants.py +37 -0
- aury/boot/infrastructure/tasks/exceptions.py +37 -0
- aury/boot/infrastructure/tasks/manager.py +490 -0
- aury/boot/testing/__init__.py +24 -0
- aury/boot/testing/base.py +122 -0
- aury/boot/testing/client.py +163 -0
- aury/boot/testing/factory.py +154 -0
- aury/boot/toolkit/__init__.py +21 -0
- aury/boot/toolkit/http/__init__.py +367 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/METADATA +3 -2
- aury_boot-0.0.4.dist-info/RECORD +137 -0
- aury_boot-0.0.2.dist-info/RECORD +0 -5
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/WHEEL +0 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.4.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"""API 响应模型(Egress)。
|
|
2
|
+
|
|
3
|
+
提供所有服务通用的响应模型。
|
|
4
|
+
这些是基础架构层的接口模型。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from datetime import UTC, datetime
|
|
10
|
+
from typing import ClassVar
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BaseResponse[T](BaseModel):
|
|
16
|
+
"""基础响应模型。
|
|
17
|
+
|
|
18
|
+
所有API响应的统一格式。
|
|
19
|
+
|
|
20
|
+
Attributes:
|
|
21
|
+
code: 响应状态码,200表示成功
|
|
22
|
+
message: 响应消息
|
|
23
|
+
data: 响应数据
|
|
24
|
+
timestamp: 响应时间戳
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
code: int = Field(default=200, description="响应状态码")
|
|
28
|
+
message: str = Field(default="", description="响应消息")
|
|
29
|
+
data: T | None = Field(default=None, description="响应数据")
|
|
30
|
+
timestamp: datetime = Field(default_factory=lambda: datetime.now(UTC), description="响应时间戳")
|
|
31
|
+
|
|
32
|
+
model_config = ConfigDict(
|
|
33
|
+
ser_json_timedelta="float",
|
|
34
|
+
ser_json_bytes="utf8",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class ErrorResponse(BaseResponse[None]):
|
|
39
|
+
"""错误响应模型。
|
|
40
|
+
|
|
41
|
+
用于返回错误信息。
|
|
42
|
+
|
|
43
|
+
Attributes:
|
|
44
|
+
code: 错误状态码
|
|
45
|
+
message: 错误消息
|
|
46
|
+
error_code: 错误代码
|
|
47
|
+
details: 错误详情
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
error_code: str | None = Field(default=None, description="错误代码")
|
|
51
|
+
details: dict | None = Field(default=None, description="错误详情")
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def create(
|
|
55
|
+
cls,
|
|
56
|
+
code: int = 400,
|
|
57
|
+
message: str = "请求错误",
|
|
58
|
+
error_code: str | None = None,
|
|
59
|
+
details: dict | None = None,
|
|
60
|
+
) -> ErrorResponse:
|
|
61
|
+
"""创建错误响应。"""
|
|
62
|
+
return cls(
|
|
63
|
+
code=code,
|
|
64
|
+
message=message,
|
|
65
|
+
error_code=error_code,
|
|
66
|
+
details=details,
|
|
67
|
+
data=None,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Pagination[T](BaseModel):
|
|
72
|
+
"""分页数据模型。
|
|
73
|
+
|
|
74
|
+
Attributes:
|
|
75
|
+
total: 总记录数
|
|
76
|
+
items: 数据列表
|
|
77
|
+
page: 当前页码(从1开始)
|
|
78
|
+
size: 每页数量
|
|
79
|
+
pages: 总页数
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
total: int = Field(..., description="总记录数", ge=0)
|
|
83
|
+
items: list[T] = Field(default_factory=list, description="数据列表")
|
|
84
|
+
page: int = Field(default=1, description="当前页码", ge=1)
|
|
85
|
+
size: int = Field(default=20, description="每页数量", ge=1, le=100)
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def pages(self) -> int:
|
|
89
|
+
"""总页数。"""
|
|
90
|
+
if self.size == 0:
|
|
91
|
+
return 0
|
|
92
|
+
return (self.total + self.size - 1) // self.size
|
|
93
|
+
|
|
94
|
+
@property
|
|
95
|
+
def has_next(self) -> bool:
|
|
96
|
+
"""是否有下一页。"""
|
|
97
|
+
return self.page < self.pages
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def has_prev(self) -> bool:
|
|
101
|
+
"""是否有上一页。"""
|
|
102
|
+
return self.page > 1
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def skip(self) -> int:
|
|
106
|
+
"""跳过的记录数。"""
|
|
107
|
+
return (self.page - 1) * self.size
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class PaginationResponse[T](BaseResponse[Pagination[T]]):
|
|
111
|
+
"""分页响应模型。
|
|
112
|
+
|
|
113
|
+
用于返回分页数据。
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class SuccessResponse(BaseResponse[dict]):
|
|
120
|
+
"""成功响应模型。
|
|
121
|
+
|
|
122
|
+
用于返回简单的成功消息。
|
|
123
|
+
|
|
124
|
+
Attributes:
|
|
125
|
+
success: 是否成功
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
success: bool = Field(default=True, description="是否成功")
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def create(cls, message: str = "操作成功", data: dict | None = None) -> SuccessResponse:
|
|
132
|
+
"""创建成功响应。"""
|
|
133
|
+
return cls(
|
|
134
|
+
code=200,
|
|
135
|
+
message=message,
|
|
136
|
+
data=data or {},
|
|
137
|
+
success=True,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class IDResponse(BaseResponse[int]):
|
|
142
|
+
"""ID响应模型。
|
|
143
|
+
|
|
144
|
+
用于返回创建的资源ID。
|
|
145
|
+
"""
|
|
146
|
+
|
|
147
|
+
pass
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class CountResponse(BaseResponse[int]):
|
|
151
|
+
"""计数响应模型。
|
|
152
|
+
|
|
153
|
+
用于返回计数结果。
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
pass
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class ResponseBuilder:
|
|
160
|
+
"""响应构建器。
|
|
161
|
+
|
|
162
|
+
提供便捷的响应创建方法。
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
@staticmethod
|
|
166
|
+
def success[T](
|
|
167
|
+
message: str = "操作成功",
|
|
168
|
+
data: T | None = None,
|
|
169
|
+
code: int = 200,
|
|
170
|
+
) -> BaseResponse[T]:
|
|
171
|
+
"""创建成功响应。
|
|
172
|
+
|
|
173
|
+
Args:
|
|
174
|
+
message: 响应消息
|
|
175
|
+
data: 响应数据
|
|
176
|
+
code: 响应状态码
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
BaseResponse: 响应对象
|
|
180
|
+
"""
|
|
181
|
+
return BaseResponse(
|
|
182
|
+
code=code,
|
|
183
|
+
message=message,
|
|
184
|
+
data=data,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
@staticmethod
|
|
188
|
+
def fail(
|
|
189
|
+
message: str = "操作失败",
|
|
190
|
+
code: int = 400,
|
|
191
|
+
errors: list[dict] | None = None,
|
|
192
|
+
error_code: str | None = None,
|
|
193
|
+
) -> ErrorResponse:
|
|
194
|
+
"""创建失败响应。
|
|
195
|
+
|
|
196
|
+
Args:
|
|
197
|
+
message: 错误消息
|
|
198
|
+
code: 错误状态码
|
|
199
|
+
errors: 错误详情列表
|
|
200
|
+
error_code: 错误代码
|
|
201
|
+
|
|
202
|
+
Returns:
|
|
203
|
+
ErrorResponse: 错误响应对象
|
|
204
|
+
"""
|
|
205
|
+
return ErrorResponse(
|
|
206
|
+
code=code,
|
|
207
|
+
message=message,
|
|
208
|
+
error_code=error_code,
|
|
209
|
+
details={"errors": errors} if errors else None,
|
|
210
|
+
data=None,
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
__all__ = [
|
|
215
|
+
"BaseResponse",
|
|
216
|
+
"CountResponse",
|
|
217
|
+
"ErrorResponse",
|
|
218
|
+
"IDResponse",
|
|
219
|
+
"Pagination",
|
|
220
|
+
"PaginationResponse",
|
|
221
|
+
"ResponseBuilder",
|
|
222
|
+
"SuccessResponse",
|
|
223
|
+
]
|
|
224
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""API 请求模型(Ingress)。
|
|
2
|
+
|
|
3
|
+
提供所有服务通用的请求模型。
|
|
4
|
+
这些是基础架构层的接口模型。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
from pydantic import BaseModel, Field
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SortOrder(str, Enum):
|
|
15
|
+
"""排序方向枚举。"""
|
|
16
|
+
|
|
17
|
+
ASC = "asc"
|
|
18
|
+
DESC = "desc"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BaseRequest(BaseModel):
|
|
22
|
+
"""基础请求模型。
|
|
23
|
+
|
|
24
|
+
所有API请求的基类。
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
request_id: 请求ID(用于追踪)
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
request_id: str | None = Field(default=None, description="请求ID(用于追踪)")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class PaginationRequest(BaseRequest):
|
|
34
|
+
"""分页请求模型。
|
|
35
|
+
|
|
36
|
+
用于分页查询的请求参数。
|
|
37
|
+
|
|
38
|
+
Attributes:
|
|
39
|
+
page: 页码(从1开始)
|
|
40
|
+
size: 每页数量
|
|
41
|
+
sort: 排序字段
|
|
42
|
+
order: 排序方向(asc/desc)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
page: int = Field(default=1, ge=1, description="页码(从1开始)")
|
|
46
|
+
size: int = Field(default=20, ge=1, le=100, description="每页数量")
|
|
47
|
+
sort: str | None = Field(default=None, description="排序字段")
|
|
48
|
+
order: SortOrder = Field(default=SortOrder.ASC, description="排序方向(asc/desc)")
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def skip(self) -> int:
|
|
52
|
+
"""跳过的记录数。"""
|
|
53
|
+
return (self.page - 1) * self.size
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def limit(self) -> int:
|
|
57
|
+
"""限制的记录数。"""
|
|
58
|
+
return self.size
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ListRequest(BaseRequest):
|
|
62
|
+
"""列表请求模型。
|
|
63
|
+
|
|
64
|
+
用于列表查询的请求参数(不分页)。
|
|
65
|
+
|
|
66
|
+
Attributes:
|
|
67
|
+
limit: 限制返回数量
|
|
68
|
+
offset: 偏移量
|
|
69
|
+
sort: 排序字段
|
|
70
|
+
order: 排序方向(asc/desc)
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
limit: int | None = Field(default=None, ge=1, le=1000, description="限制返回数量")
|
|
74
|
+
offset: int = Field(default=0, ge=0, description="偏移量")
|
|
75
|
+
sort: str | None = Field(default=None, description="排序字段")
|
|
76
|
+
order: SortOrder = Field(default=SortOrder.ASC, description="排序方向(asc/desc)")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class FilterRequest(BaseRequest):
|
|
80
|
+
"""过滤请求模型。
|
|
81
|
+
|
|
82
|
+
用于带过滤条件的查询。
|
|
83
|
+
|
|
84
|
+
Attributes:
|
|
85
|
+
filters: 过滤条件字典
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
filters: dict | None = Field(default_factory=dict, description="过滤条件字典")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
__all__ = [
|
|
92
|
+
"BaseRequest",
|
|
93
|
+
"FilterRequest",
|
|
94
|
+
"ListRequest",
|
|
95
|
+
"PaginationRequest",
|
|
96
|
+
"SortOrder",
|
|
97
|
+
]
|
|
98
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""应用层中间件模块。
|
|
2
|
+
|
|
3
|
+
仅包含 FastAPI HTTP 中间件。
|
|
4
|
+
事件中间件请参考 infrastructure.events。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .logging import RequestLoggingMiddleware, log_request
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"RequestLoggingMiddleware",
|
|
11
|
+
"log_request",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|